mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-21 14:02:43 +08:00
fix(@schematics/angular): migrate TS module type to esnext
This commit is contained in:
parent
96fe7686aa
commit
458ba75e37
@ -53,19 +53,26 @@ export function updateES5Projects(): Rule {
|
||||
return host;
|
||||
}
|
||||
|
||||
const scriptTarget = findPropertyInAstObject(compilerOptions, 'target');
|
||||
if (scriptTarget && scriptTarget.value === 'es2015') {
|
||||
return host;
|
||||
}
|
||||
|
||||
const recorder = host.beginUpdate(tsConfigPath);
|
||||
if (scriptTarget) {
|
||||
|
||||
const scriptTarget = findPropertyInAstObject(compilerOptions, 'target');
|
||||
if (!scriptTarget) {
|
||||
insertPropertyInAstObjectInOrder(recorder, compilerOptions, 'target', 'es2015', 4);
|
||||
} else if (scriptTarget.value !== 'es2015') {
|
||||
const { start, end } = scriptTarget;
|
||||
recorder.remove(start.offset, end.offset - start.offset);
|
||||
recorder.insertLeft(start.offset, '"es2015"');
|
||||
} else {
|
||||
insertPropertyInAstObjectInOrder(recorder, compilerOptions, 'target', 'es2015', 4);
|
||||
}
|
||||
|
||||
const scriptModule = findPropertyInAstObject(compilerOptions, 'module');
|
||||
if (!scriptModule) {
|
||||
insertPropertyInAstObjectInOrder(recorder, compilerOptions, 'module', 'esnext', 4);
|
||||
} else if (scriptModule.value !== 'esnext') {
|
||||
const { start, end } = scriptModule;
|
||||
recorder.remove(start.offset, end.offset - start.offset);
|
||||
recorder.insertLeft(start.offset, '"esnext"');
|
||||
}
|
||||
|
||||
host.commitUpdate(recorder);
|
||||
|
||||
return updateBrowserlist;
|
||||
|
@ -62,6 +62,24 @@ describe('Migration to version 8', () => {
|
||||
expect(target).toBe('es2015');
|
||||
});
|
||||
|
||||
it(`should update 'module' to esnext when property exists`, () => {
|
||||
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
|
||||
const { module } = JSON.parse(tree2.readContent(tsConfigPath)).compilerOptions;
|
||||
expect(module).toBe('esnext');
|
||||
});
|
||||
|
||||
it(`should create 'module' property when doesn't exists`, () => {
|
||||
const compilerOptions = {
|
||||
...oldTsConfig.compilerOptions,
|
||||
module: undefined,
|
||||
};
|
||||
|
||||
tree.overwrite(tsConfigPath, JSON.stringify({ compilerOptions }, null, 2));
|
||||
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
|
||||
const { module } = JSON.parse(tree2.readContent(tsConfigPath)).compilerOptions;
|
||||
expect(module).toBe('esnext');
|
||||
});
|
||||
|
||||
it(`should update browserslist file to add an non evergreen browser`, () => {
|
||||
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
|
||||
expect(tree2.readContent('/browserslist')).toContain('Chrome 41');
|
||||
|
Loading…
x
Reference in New Issue
Block a user