Skip to content

Commit 796ff8d

Browse files
build: load every compiled schematic before publishing
The load failure fixed in the previous commit reached a published release because nothing in the build or the test suite ever loads what actually ships. The jasmine suite runs against the TypeScript output, which is a different module format from the CommonJS bundle in the package, so a bundle can be completely unloadable while every test passes. Requiring each compiled entry point at the end of the schematics build closes that gap. Reverting the previous commit now fails the build with the real error: Compiled schematics failed to load: deploy/actions.js: TypeError [ERR_INVALID_ARG_TYPE] ... deploy/builder.js: TypeError [ERR_INVALID_ARG_TYPE] ... It catches the whole class, not just this instance: an unresolvable import, a bad top-level require, or anything else that throws at module load.
1 parent 274c44f commit 796ff8d

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tools/build.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,41 @@ async function compileSchematics() {
357357
copy(src('schematics', 'setup', 'schema.json'), dest('schematics', 'setup', 'schema.json')),
358358
]);
359359
await replaceSchematicVersions();
360+
await loadCompiledSchematics();
361+
}
362+
363+
/**
364+
* Loads every compiled schematic entry point, so a bundle that cannot even be required fails the
365+
* build instead of shipping.
366+
*
367+
* The jasmine suite exercises the TypeScript output, which is a different module format from the
368+
* CommonJS bundle that actually ships, so nothing else here ever loads the published files. That
369+
* gap let `ng deploy` ship broken: esbuild rewrites `import.meta` to an empty object in CommonJS
370+
* output, and the resulting `fileURLToPath(undefined)` threw the moment either deploy bundle was
371+
* required.
372+
*/
373+
async function loadCompiledSchematics() {
374+
const entryPoints = [
375+
join('update', 'index.js'),
376+
join('deploy', 'actions.js'),
377+
join('deploy', 'builder.js'),
378+
join('add', 'index.js'),
379+
join('setup', 'index.js'),
380+
join('update', 'v7', 'index.js'),
381+
join('update', 'v21', 'index.js'),
382+
];
383+
const failures: string[] = [];
384+
for (const entryPoint of entryPoints) {
385+
const path = dest('schematics', entryPoint);
386+
try {
387+
require(path);
388+
} catch (error) {
389+
failures.push(` ${entryPoint}: ${error}`);
390+
}
391+
}
392+
if (failures.length) {
393+
throw new Error(`Compiled schematics failed to load:\n${failures.join('\n')}`);
394+
}
360395
}
361396

362397
async function buildLibrary() {

0 commit comments

Comments
 (0)