Skip to content

Commit a182d01

Browse files
committed
refactor(migrations): restore dynamic import helper as cjs
This partially reverts commit 69dda0b
1 parent 4568ddd commit a182d01

13 files changed

Lines changed: 51 additions & 23 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** Explicit module map, as generic T can't be resolved to a direct string literal via inference */
2+
type ModuleMap = {
3+
'@angular/compiler': typeof import('@angular/compiler', { with: { "resolution-mode": "import" }});
4+
};
5+
6+
/**
7+
* Native Node dynamic import helper
8+
* @remarks
9+
* NB: Import this via a bare specifier (igniteui-angular/migrations/common/import-helper.cjs)
10+
* to escape the schematics encapsulation for this file and thus the dynamic import inside.
11+
* This allows to dynamically import ESM modules from outside the schematics host context.
12+
*/
13+
export function nativeImport<T extends keyof ModuleMap>(name: T): Promise<ModuleMap[T]> {
14+
return import(name);
15+
};

projects/igniteui-angular/migrations/update-11_0_0/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import type { Element } from '@angular/compiler' with { "resolution-mode": "impo
22
import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
33
import { UpdateChanges } from '../common/UpdateChanges';
44
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile, serializeNodes } from '../common/util';
5+
// use bare specifier to escape the schematics encapsulation for the dynamic import:
6+
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.cjs';
57

68
const version = '11.0.0';
79

810
export default (): Rule => async (host: Tree, context: SchematicContext) => {
911
context.logger.info(
1012
`Applying migration for Ignite UI for Angular to version ${version}`
1113
);
12-
// bare specifier escapes schematics encapsulation for the compiler dynamic import:
13-
const { HtmlParser, getHtmlTagDefinition } = await import('@angular/compiler');
14+
const { HtmlParser, getHtmlTagDefinition } = await nativeImport('@angular/compiler');
1415

1516
const update = new UpdateChanges(__dirname, host, context);
1617

projects/igniteui-angular/migrations/update-12_0_0/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { Element } from '@angular/compiler' with { "resolution-mode": "impo
22
import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
33
import { UpdateChanges } from '../common/UpdateChanges';
44
import { FileChange, getAttribute, findElementNodes, getSourceOffset, hasAttribute, parseFile } from '../common/util';
5+
// use bare specifier to escape the schematics encapsulation for the dynamic import:
6+
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.cjs';
57
import type { Options } from '../../schematics/interfaces/options';
68

79
const version = '12.0.0';
@@ -12,8 +14,7 @@ export default (options: Options): Rule =>
1214
`Applying migration for Ignite UI for Angular to version ${version}`
1315
);
1416

15-
// bare specifier escapes schematics encapsulation for the compiler dynamic import:
16-
const { HtmlParser } = await import('@angular/compiler');
17+
const { HtmlParser } = await nativeImport('@angular/compiler');
1718

1819
// eslint-disable-next-line max-len
1920
const UPDATE_NOTE = `<!--NOTE: This component has been updated by Infragistics migration: v${version}\nPlease check your template whether all bindings/event handlers are correct.-->\n`;

projects/igniteui-angular/migrations/update-12_1_0/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import {
55
FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile,
66
serializeNodes, makeNgIf, stringifyAttributes
77
} from '../common/util';
8+
// use bare specifier to escape the schematics encapsulation for the dynamic import:
9+
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.cjs';
810

911
const version = '12.1.0';
1012

1113
export default (): Rule => async (host: Tree, context: SchematicContext) => {
1214
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
1315

14-
// bare specifier escapes schematics encapsulation for the compiler dynamic import:
15-
const { HtmlParser, getHtmlTagDefinition } = await import('@angular/compiler');
16+
const { HtmlParser, getHtmlTagDefinition } = await nativeImport('@angular/compiler');
1617

1718
const update = new UpdateChanges(__dirname, host, context);
1819
const TAGS = ['igx-grid', 'igx-tree-grid', 'igx-hierarchical-grid'];

projects/igniteui-angular/migrations/update-13_0_0/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import type {
77
import type { Options } from '../../schematics/interfaces/options';
88
import { UpdateChanges } from '../common/UpdateChanges';
99
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
10+
// use bare specifier to escape the schematics encapsulation for the dynamic import:
11+
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.cjs';
1012

1113
const version = '13.0.0';
1214

@@ -25,8 +27,7 @@ export default (options: Options): Rule =>
2527
'[exportExcel]', 'exportExcel', '[exportExcelText]', 'exportExcelText',
2628
'[exportCsv]', 'exportCsv', '[exportCsvText]', 'exportCsvText', '[exportText]', 'exportText'];
2729
const actionsLeft = ['igx-grid-toolbar-advanced-filtering'];
28-
// bare specifier escapes schematics encapsulation for the compiler dynamic import:
29-
const { HtmlParser } = await import('@angular/compiler');
30+
const { HtmlParser } = await nativeImport('@angular/compiler');
3031

3132
const moduleTsFiles = tsFiles.filter(x => x.endsWith('.module.ts'));
3233
for (const path of moduleTsFiles) {

projects/igniteui-angular/migrations/update-13_1_0/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import type {
44
Tree
55
} from '@angular-devkit/schematics';
66
import type { Element } from '@angular/compiler' with { "resolution-mode": "import" };
7+
// use bare specifier to escape the schematics encapsulation for the dynamic import:
8+
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.cjs';
79
import { UpdateChanges } from '../common/UpdateChanges';
810
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
911

1012
const version = '13.1.0';
1113

1214
export default (): Rule => async (host: Tree, context: SchematicContext) => {
1315
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
14-
// bare specifier escapes schematics encapsulation for the compiler dynamic import:
15-
const { HtmlParser } = await import('@angular/compiler');
16+
const { HtmlParser } = await nativeImport('@angular/compiler');
1617

1718
const update = new UpdateChanges(__dirname, host, context);
1819
const GRID_TAGS = ['igx-grid', 'igx-tree-grid', 'igx-hierarchical-grid', 'igx-row-island'];

projects/igniteui-angular/migrations/update-15_1_0/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type {
44
Tree
55
} from '@angular-devkit/schematics';
66
import type { Element } from '@angular/compiler' with { "resolution-mode": "import" };
7+
// use bare specifier to escape the schematics encapsulation for the dynamic import:
8+
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.cjs';
79
import type { Options } from '../../schematics/interfaces/options';
810
import { BoundPropertyObject, InputPropertyType, UpdateChanges } from '../common/UpdateChanges';
911
import { FileChange, findElementNodes, getAttribute, getSourceOffset, parseFile, hasAttribute } from '../common/util';
@@ -13,8 +15,7 @@ const version = '15.1.0';
1315
export default (options: Options): Rule => async (host: Tree, context: SchematicContext) => {
1416
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
1517

16-
// bare specifier escapes schematics encapsulation for the compiler dynamic import:
17-
const { HtmlParser } = await import('@angular/compiler');
18+
const { HtmlParser } = await nativeImport('@angular/compiler');
1819
const update = new UpdateChanges(__dirname, host, context);
1920
const cardsToMigrate = new Set<any>();
2021
const CARD_ACTIONS = ['igx-card-actions'];

projects/igniteui-angular/migrations/update-16_1_0/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import type {
55
} from '@angular-devkit/schematics';
66
import { UpdateChanges } from '../common/UpdateChanges';
77
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
8+
// use bare specifier to escape the schematics encapsulation for the dynamic import:
9+
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.cjs';
810
import type { Element } from '@angular/compiler' with { "resolution-mode": "import" };
911

1012
const version = '16.1.0';
1113

1214
export default (): Rule => async (host: Tree, context: SchematicContext) => {
1315
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
14-
// bare specifier escapes schematics encapsulation for the compiler dynamic import:
15-
const { HtmlParser } = await import('@angular/compiler');
16+
const { HtmlParser } = await nativeImport('@angular/compiler');
1617
const update = new UpdateChanges(__dirname, host, context);
1718
update.applyChanges();
1819

projects/igniteui-angular/migrations/update-17_0_0/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import type {
66
import type { Element } from '@angular/compiler' with { "resolution-mode": "import" };
77
import * as ts from 'typescript';
88
import { UpdateChanges } from '../common/UpdateChanges';
9+
// use bare specifier to escape the schematics encapsulation for the dynamic import:
10+
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.cjs';
911
import { igNamedImportFilter } from '../common/tsUtils';
1012
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
1113

1214
const version = '17.0.0';
1315

1416
export default (): Rule => async (host: Tree, context: SchematicContext) => {
1517
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
16-
// bare specifier escapes schematics encapsulation for the compiler dynamic import:
17-
const { HtmlParser } = await import('@angular/compiler');
18+
const { HtmlParser } = await nativeImport('@angular/compiler');
1819
const update = new UpdateChanges(__dirname, host, context);
1920
const changes = new Map<string, FileChange[]>();
2021
const prop = ['type'];

projects/igniteui-angular/migrations/update-17_1_0/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import {
55
} from '@angular-devkit/schematics';
66
import { UpdateChanges } from '../common/UpdateChanges';
77
import { FileChange, findElementNodes, getAttribute, getSourceOffset, hasAttribute, parseFile } from '../common/util';
8+
// use bare specifier to escape the schematics encapsulation for the dynamic import:
9+
import { nativeImport } from 'igniteui-angular/migrations/common/import-helper.cjs';
810
import type { Element } from '@angular/compiler' with { "resolution-mode": "import" };
911

1012
const version = '17.1.0';
1113

1214
export default (): Rule => async (host: Tree, context: SchematicContext) => {
1315
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
14-
// bare specifier escapes schematics encapsulation for the compiler dynamic import:
15-
const { HtmlParser } = await import('@angular/compiler');
16+
const { HtmlParser } = await nativeImport('@angular/compiler');
1617
const update = new UpdateChanges(__dirname, host, context);
1718
const changes = new Map<string, FileChange[]>();
1819
const tags = ['button', 'span', 'a', 'div', 'igx-prefix', 'igx-suffix']

0 commit comments

Comments
 (0)