@@ -9,6 +9,7 @@ import process from 'node:process'
99import { pathToFileURL } from 'node:url'
1010import { promisify } from 'node:util'
1111import { gzipSync } from 'node:zlib'
12+ import { readDocumentationSnippets } from './documentation-snippets.mjs'
1213
1314const execFileAsync = promisify ( execFile )
1415const repositoryRoot = path . resolve ( import . meta. dirname , '..' )
@@ -54,7 +55,14 @@ const lifecycleScripts = [
5455 'postinstall' ,
5556 'prepublish' ,
5657 'prepublishOnly' ,
58+ 'preprepare' ,
5759 'prepare' ,
60+ 'postprepare' ,
61+ 'dependencies' ,
62+ 'prepack' ,
63+ 'postpack' ,
64+ 'publish' ,
65+ 'postpublish' ,
5866]
5967
6068export function validatePackedFiles ( actualFiles , expectedFiles ) {
@@ -200,9 +208,10 @@ export async function verifyTarballConsumers(tarballPath) {
200208 await verifyModulesAndSsr ( consumer )
201209 await verifyTypes ( consumer )
202210 await verifyExamples ( consumer )
211+ await verifyDocumentationExamples ( consumer )
203212 await verifyStylesAndManifest ( consumer , sourceManifest )
204213 console . log (
205- `${ lane . label } : ESM, CJS, types, CSS, examples, and SSR passed` ,
214+ `${ lane . label } : ESM, CJS, types, CSS, examples, docs, and SSR passed` ,
206215 )
207216 }
208217 } finally {
@@ -229,8 +238,8 @@ export async function verifyPackage() {
229238 await readFile ( path . join ( repositoryRoot , 'package.json' ) , 'utf8' ) ,
230239 )
231240 const { stdout } = await runNpm (
232- [ 'pack' , '--json' , '--pack-destination' , packDirectory ] ,
233- repositoryRoot ,
241+ [ 'pack' , repositoryRoot , '--json' , '--pack-destination' , packDirectory ] ,
242+ npmPaths . workspace ,
234243 npmPaths ,
235244 )
236245 const [ pack ] = JSON . parse ( stdout )
@@ -430,6 +439,52 @@ async function verifyExamples(consumer) {
430439 )
431440}
432441
442+ async function verifyDocumentationExamples ( consumer ) {
443+ const directory = path . join ( consumer , 'documentation' )
444+ await mkdir ( directory )
445+ for ( const { filename, code } of await readDocumentationSnippets (
446+ repositoryRoot ,
447+ ) )
448+ await writeFile ( path . join ( directory , filename ) , code )
449+ await writeFile (
450+ path . join ( directory , 'environment.d.ts' ) ,
451+ "declare module '*.css'\n" ,
452+ )
453+
454+ await writeFile (
455+ path . join ( consumer , 'tsconfig.documentation.json' ) ,
456+ `${ JSON . stringify (
457+ {
458+ compilerOptions : {
459+ target : 'ES2022' ,
460+ lib : [ 'ES2022' , 'DOM' , 'DOM.Iterable' ] ,
461+ module : 'ESNext' ,
462+ moduleResolution : 'Bundler' ,
463+ jsx : 'react-jsx' ,
464+ strict : true ,
465+ exactOptionalPropertyTypes : true ,
466+ noUncheckedIndexedAccess : true ,
467+ noEmit : true ,
468+ skipLibCheck : false ,
469+ types : [ ] ,
470+ } ,
471+ include : [ 'documentation/**/*.tsx' , 'documentation/**/*.d.ts' ] ,
472+ } ,
473+ null ,
474+ 2 ,
475+ ) } \n`,
476+ )
477+ await run (
478+ process . execPath ,
479+ [
480+ 'node_modules/typescript/bin/tsc' ,
481+ '--project' ,
482+ 'tsconfig.documentation.json' ,
483+ ] ,
484+ consumer ,
485+ )
486+ }
487+
433488async function verifyStylesAndManifest ( consumer , sourceManifest ) {
434489 const require = createRequire ( path . join ( consumer , 'package.json' ) )
435490 const stylesheetPath = require . resolve ( `${ packageName } /styles.css` )
@@ -446,21 +501,23 @@ async function verifyStylesAndManifest(consumer, sourceManifest) {
446501 } )
447502}
448503
449- async function createNpmPaths ( temporaryRoot ) {
504+ export async function createNpmPaths ( temporaryRoot ) {
450505 const paths = {
451506 userConfig : path . join ( temporaryRoot , 'user.npmrc' ) ,
452507 globalConfig : path . join ( temporaryRoot , 'global.npmrc' ) ,
453508 cache : path . join ( temporaryRoot , 'npm-cache' ) ,
509+ workspace : path . join ( temporaryRoot , 'npm-workspace' ) ,
454510 }
455511 await Promise . all ( [
456512 writeFile ( paths . userConfig , '' ) ,
457513 writeFile ( paths . globalConfig , '' ) ,
458514 mkdir ( paths . cache ) ,
515+ mkdir ( paths . workspace ) ,
459516 ] )
460517 return paths
461518}
462519
463- function runNpm ( args , cwd , npmPaths ) {
520+ export function runNpm ( args , cwd , npmPaths ) {
464521 return execFileAsync ( 'npm' , args , {
465522 cwd,
466523 env : sanitizeNpmEnvironment ( process . env , npmPaths ) ,
0 commit comments