Skip to content

Commit 5c7aba4

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 4bc59ef commit 5c7aba4

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tools/build.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,35 @@ 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+
async function loadCompiledSchematics() {
368+
const entryPoints = [
369+
join('update', 'index.js'),
370+
join('deploy', 'actions.js'),
371+
join('deploy', 'builder.js'),
372+
join('add', 'index.js'),
373+
join('setup', 'index.js'),
374+
join('update', 'v7', 'index.js'),
375+
join('update', 'v21', 'index.js'),
376+
];
377+
const failures: string[] = [];
378+
for (const entryPoint of entryPoints) {
379+
const path = dest('schematics', entryPoint);
380+
try {
381+
require(path);
382+
} catch (error) {
383+
failures.push(` ${entryPoint}: ${error}`);
384+
}
385+
}
386+
if (failures.length) {
387+
throw new Error(`Compiled schematics failed to load:\n${failures.join('\n')}`);
388+
}
360389
}
361390

362391
async function buildLibrary() {

0 commit comments

Comments
 (0)