Commit c4c4ad1
authored
fix(schematics): restore ng deploy under the CommonJS schematics bundle (#3729)
* fix(schematics): restore ng deploy under the CommonJS schematics bundle
`ng deploy` threw at module load in 21.0.0-rc.0, before any user code ran:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type
string or an instance of URL. Received undefined
at fileURLToPath (node:internal/url)
The schematics are bundled by esbuild with `format: "cjs"`, and esbuild
rewrites `import.meta` to an empty object in CommonJS output. The shipped
bundle therefore read `undefined.url`, so both `deploy/actions.js` and
`deploy/builder.js` failed to load. Every other shipped entry point (ng add,
both ng update migrations, the setup schematic) was unaffected.
The shim was introduced when `versions.json` moved from a compile-time import
to a runtime read. That move fixed a real bug of its own: because esbuild
bundles before the build copies and rewrites `versions.json`, the compile-time
import inlined the unreplaced `0.0.0` placeholders, and 20.0.1 generates a
Cloud Functions manifest pinning `0.0.0` that cannot install. So the runtime
read has to stay.
`typeof` on an undeclared identifier is the one form that does not throw under
ESM, so a single expression works under both loaders, and the CommonJS branch
comes first because `import.meta` is the substituted empty object there. The
alternatives were built and run, not assumed:
- plain `__dirname` breaks `npm run test:node-esm`, which genuinely loads
the compiled specs as ESM
- `require('../versions.json')` reintroduces the `0.0.0` bug above
- an esbuild define/banner works today but fails with "require is not
defined in ES module scope" the moment `format: "esm"` is enabled, which
tools/build.ts already has staged in a comment
Verified against the built package: all seven shipped entry points now load
via both `require()` and `await import()`, the builder exposes the Architect
builder symbols, and the runtime `versions.json` read resolves correctly.
`ng lint` also drops its only warning, which sat on the replaced line.
This is v21-only. v20 has no `import.meta` shim and must not take this change.
* 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.
* build: derive schematic entry points from a single list
compileSchematics and loadCompiledSchematics each carried their own
hardcoded copy of the seven entry points. An entry point added to the
esbuild list alone would compile but never be load-checked, which is
the exact failure the load check exists to catch.
Both now map one schematicEntryPoints array, to .ts for esbuild and to
.js for the require check. Emitted paths and failure strings are
unchanged: a build with a deliberate top-level throw added to
deploy/actions.ts still fails, and still names deploy/actions.js and
deploy/builder.js in the same format.1 parent a99f09b commit c4c4ad1
2 files changed
Lines changed: 36 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
131 | | - | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
316 | 328 | | |
317 | 329 | | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
| 330 | + | |
327 | 331 | | |
328 | 332 | | |
329 | 333 | | |
| |||
357 | 361 | | |
358 | 362 | | |
359 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
360 | 383 | | |
361 | 384 | | |
362 | 385 | | |
| |||
0 commit comments