Skip to content

Commit 458ba75

Browse files
clydinalexeagle
authored andcommitted
fix(@schematics/angular): migrate TS module type to esnext
1 parent 96fe768 commit 458ba75

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

packages/schematics/angular/migrations/update-8/differential-loading.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,26 @@ export function updateES5Projects(): Rule {
5353
return host;
5454
}
5555

56-
const scriptTarget = findPropertyInAstObject(compilerOptions, 'target');
57-
if (scriptTarget && scriptTarget.value === 'es2015') {
58-
return host;
59-
}
60-
6156
const recorder = host.beginUpdate(tsConfigPath);
62-
if (scriptTarget) {
57+
58+
const scriptTarget = findPropertyInAstObject(compilerOptions, 'target');
59+
if (!scriptTarget) {
60+
insertPropertyInAstObjectInOrder(recorder, compilerOptions, 'target', 'es2015', 4);
61+
} else if (scriptTarget.value !== 'es2015') {
6362
const { start, end } = scriptTarget;
6463
recorder.remove(start.offset, end.offset - start.offset);
6564
recorder.insertLeft(start.offset, '"es2015"');
66-
} else {
67-
insertPropertyInAstObjectInOrder(recorder, compilerOptions, 'target', 'es2015', 4);
6865
}
66+
67+
const scriptModule = findPropertyInAstObject(compilerOptions, 'module');
68+
if (!scriptModule) {
69+
insertPropertyInAstObjectInOrder(recorder, compilerOptions, 'module', 'esnext', 4);
70+
} else if (scriptModule.value !== 'esnext') {
71+
const { start, end } = scriptModule;
72+
recorder.remove(start.offset, end.offset - start.offset);
73+
recorder.insertLeft(start.offset, '"esnext"');
74+
}
75+
6976
host.commitUpdate(recorder);
7077

7178
return updateBrowserlist;

packages/schematics/angular/migrations/update-8/differential-loading_spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ describe('Migration to version 8', () => {
6262
expect(target).toBe('es2015');
6363
});
6464

65+
it(`should update 'module' to esnext when property exists`, () => {
66+
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
67+
const { module } = JSON.parse(tree2.readContent(tsConfigPath)).compilerOptions;
68+
expect(module).toBe('esnext');
69+
});
70+
71+
it(`should create 'module' property when doesn't exists`, () => {
72+
const compilerOptions = {
73+
...oldTsConfig.compilerOptions,
74+
module: undefined,
75+
};
76+
77+
tree.overwrite(tsConfigPath, JSON.stringify({ compilerOptions }, null, 2));
78+
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
79+
const { module } = JSON.parse(tree2.readContent(tsConfigPath)).compilerOptions;
80+
expect(module).toBe('esnext');
81+
});
82+
6583
it(`should update browserslist file to add an non evergreen browser`, () => {
6684
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
6785
expect(tree2.readContent('/browserslist')).toContain('Chrome 41');

0 commit comments

Comments
 (0)