You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: projects/igniteui-angular/migrations/README.md
+26-36Lines changed: 26 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,45 +4,43 @@ This directory hosts the migration schematics that run when consumers execute
4
4
`ng update igniteui-angular`. Each `update-*` folder is a versioned migration
5
5
listed in [`migration-collection.json`](./migration-collection.json) and
6
6
implemented in `update-*/index.ts`. Shared helpers live in
7
-
[`common/`](./common). The collection has `"encapsulation": true` so every
8
-
migration is loaded in its own isolated CommonJS context by the Angular
9
-
schematics tooling.
7
+
[`common/`](./common).
10
8
11
-
## Dynamic `@angular/compiler` import via `nativeImport`
9
+
See [Wiki pages under Migrations & Schematics](https://github.com/IgniteUI/igniteui-angular/wiki#migrations--schematics)
10
+
for authoring and testing guidance.
12
11
13
-
`@angular/compiler` is an ES module. The migrations themselves are emitted as
14
-
CommonJS, so they cannot statically `import` it; they have to use a runtime
15
-
dynamic `import()`. To avoid TypeScript downleveling that dynamic call into a
16
-
synchronous `require()` (which would crash on an ESM target), the call is
17
-
routed through a tiny `.cjs` helper:
12
+
## Encapsulation and external ESM like `@angular/compiler`
13
+
The collection has `"encapsulation": true` so every
14
+
migration is loaded in its own isolated VM context by the Angular
15
+
schematics tooling. That also restricts some API access/functionality.
16
+
17
+
See the description of [#13712 — fix(migrations,ng-add): turn on encapsulation for devkit/schematics deps](https://github.com/IgniteUI/igniteui-angular/pull/13712) when encapsulation was first enabled for mechanism details.
18
+
19
+
### Dynamic `@angular/compiler` import via `nativeImport`
20
+
21
+
`@angular/compiler` is an ES module. The migrations themselves are emitted and consumed
22
+
(`require()`-d) by the Angular schematics as CommonJS, so they cannot statically `import` it;
23
+
they have to use a runtime dynamic `import()`.
18
24
19
25
-[`common/import-helper.cts`](./common/import-helper.cts) — authored as
20
-
a TypeScript CJS module. The dynamic `import()` is preserved in the emitted
21
-
[`common/import-helper.cjs`](./common/import-helper.cjs) because the file's
22
-
forced `.cjs` extension prevents the compiler from rewriting it.
26
+
a TypeScript CJS module. The dynamic `import()` is preserved in the emitted.
Schematics encapsulation (`"encapsulation": true` in
35
-
[`migration-collection.json`](./migration-collection.json)) wraps every
36
-
migration in a sandboxed module loader. Relative requires (`../common/...`)
37
-
go through that wrapper and the dynamic `import()` ends up being intercepted
38
-
and converted by the wrapper, defeating the purpose of the helper. A **bare
39
-
package specifier** bypasses the wrapper because the wrapper only encapsulates
40
-
the migration's own files, not requires that resolve to a real package.
36
+
Schematics encapsulation being a VM execution is affected by the
37
+
[Support of dynamic import() in compilation APIs](https://nodejs.org/api/vm.html#support-of-dynamic-import-in-compilation-apis)
38
+
and at this time Angular schematics do not implement [importModuleDynamically](https://github.com/angular/angular-cli/blob/e5eb3e37c9756669b3b91b5b681a73cc9b616cb9/packages/angular/cli/src/command-builder/utilities/schematic-engine-host.ts#L50).
41
39
42
-
This is the trick PR
43
-
[#13712 — fix(migrations,ng-add): turn on encapsulation for devkit/schematics deps](https://github.com/IgniteUI/igniteui-angular/pull/13712)
44
-
introduced when encapsulation was first enabled. Every migration that needs
45
-
`@angular/compiler` follows the same pattern.
40
+
A **bare package specifier** effectively passes through the schematics host encapsulation again and escapes [the relative wrapping ](https://github.com/angular/angular-cli/blob/e5eb3e37c9756669b3b91b5b681a73cc9b616cb9/packages/angular/cli/src/command-builder/utilities/schematic-engine-host.ts#L177-L178) out into [the original schematic require](https://github.com/angular/angular-cli/blob/e5eb3e37c9756669b3b91b5b681a73cc9b616cb9/packages/angular/cli/src/command-builder/utilities/schematic-engine-host.ts#L203-L204).
41
+
This means just the `import-helper.cjs` script is ran outside of encapsulation and as such can perform dynamic imports.
42
+
43
+
Every migration that needs `@angular/compiler` follows the same pattern.
46
44
47
45
To keep TypeScript happy with the bare specifier at compile time,
48
46
[`tsconfig.json`](./tsconfig.json) maps it back to the source:
@@ -57,7 +55,7 @@ To keep TypeScript happy with the bare specifier at compile time,
57
55
At consumer install time the specifier resolves naturally through their
0 commit comments