Commit 274c44f
committed
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. 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.1 parent b551b5f commit 274c44f
1 file changed
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
128 | 132 | | |
129 | 133 | | |
130 | 134 | | |
131 | | - | |
| 135 | + | |
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
| |||
0 commit comments