@@ -313,17 +313,21 @@ function spawnPromise(command: string, args: string[]) {
313313 . on ( 'error' , reject ) ) ;
314314}
315315
316+ // Path segments of each schematic entry point, relative to `schematics/` and without the file
317+ // extension: esbuild compiles the `.ts` and loadCompiledSchematics requires the emitted `.js`.
318+ const schematicEntryPoints = [
319+ [ 'update' , 'index' ] ,
320+ [ 'deploy' , 'actions' ] ,
321+ [ 'deploy' , 'builder' ] ,
322+ [ 'add' , 'index' ] ,
323+ [ 'setup' , 'index' ] ,
324+ [ 'update' , 'v7' , 'index' ] ,
325+ [ 'update' , 'v21' , 'index' ] ,
326+ ] ;
327+
316328async function compileSchematics ( ) {
317329 await esbuild . build ( {
318- entryPoints : [
319- src ( 'schematics' , "update" , "index.ts" ) ,
320- src ( 'schematics' , "deploy" , "actions.ts" ) ,
321- src ( 'schematics' , "deploy" , "builder.ts" ) ,
322- src ( 'schematics' , "add" , "index.ts" ) ,
323- src ( 'schematics' , "setup" , "index.ts" ) ,
324- src ( 'schematics' , "update" , "v7" , "index.ts" ) ,
325- src ( 'schematics' , "update" , "v21" , "index.ts" ) ,
326- ] ,
330+ entryPoints : schematicEntryPoints . map ( segments => `${ src ( 'schematics' , ...segments ) } .ts` ) ,
327331 format : "cjs" ,
328332 // turns out schematics don't support ESM, need to use webpack or shim these
329333 // format: "esm",
@@ -357,6 +361,25 @@ async function compileSchematics() {
357361 copy ( src ( 'schematics' , 'setup' , 'schema.json' ) , dest ( 'schematics' , 'setup' , 'schema.json' ) ) ,
358362 ] ) ;
359363 await replaceSchematicVersions ( ) ;
364+ await loadCompiledSchematics ( ) ;
365+ }
366+
367+ /**
368+ * Loads every compiled schematic entry point, so a bundle that cannot even be required fails the
369+ * build instead of shipping.
370+ */
371+ async function loadCompiledSchematics ( ) {
372+ const failures : string [ ] = [ ] ;
373+ for ( const segments of schematicEntryPoints ) {
374+ try {
375+ require ( `${ dest ( 'schematics' , ...segments ) } .js` ) ;
376+ } catch ( error ) {
377+ failures . push ( ` ${ join ( ...segments ) } .js: ${ error } ` ) ;
378+ }
379+ }
380+ if ( failures . length ) {
381+ throw new Error ( `Compiled schematics failed to load:\n${ failures . join ( '\n' ) } ` ) ;
382+ }
360383}
361384
362385async function buildLibrary ( ) {
0 commit comments