Skip to content

Commit 50d9c0e

Browse files
Deku-nattsudgp1130
authored andcommitted
fix(@schematics/angular): do not set esModuleInterop and moduleResolution when module is preserve
1 parent 18cf6c5 commit 50d9c0e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/schematics/angular/migrations/use-application-builder/migration.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,16 @@ export default function (): Rule {
362362
),
363363
// Update main tsconfig
364364
updateJsonFile('tsconfig.json', (rootJson) => {
365-
rootJson.modify(['compilerOptions', 'esModuleInterop'], true);
365+
const module = rootJson.get(['compilerOptions', 'module']);
366+
const hasPreserveModule = typeof module === 'string' && module.toLowerCase() === 'preserve';
367+
368+
if (!hasPreserveModule) {
369+
rootJson.modify(['compilerOptions', 'esModuleInterop'], true);
370+
rootJson.modify(['compilerOptions', 'moduleResolution'], 'bundler');
371+
}
372+
366373
rootJson.modify(['compilerOptions', 'downlevelIteration'], undefined);
367374
rootJson.modify(['compilerOptions', 'allowSyntheticDefaultImports'], undefined);
368-
rootJson.modify(['compilerOptions', 'moduleResolution'], 'bundler');
369375
}),
370376
]);
371377
}

packages/schematics/angular/migrations/use-application-builder/migration_spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import { JsonObject } from '@angular-devkit/core';
910
import { EmptyTree } from '@angular-devkit/schematics';
1011
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
1112
import { Builders, ProjectType, WorkspaceSchema } from '../../utility/workspace-models';
@@ -448,4 +449,16 @@ describe(`Migration to use the application builder`, () => {
448449

449450
expect(devDependencies['postcss']).toBeUndefined();
450451
});
452+
453+
it('it should not add esModuleInterop and moduleResolution when module is preserve', async () => {
454+
tree.overwrite(
455+
'tsconfig.json',
456+
JSON.stringify({
457+
compilerOptions: { module: 'preserve' },
458+
}),
459+
);
460+
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);
461+
const { compilerOptions } = newTree.readJson('tsconfig.json') as JsonObject;
462+
expect(compilerOptions).toEqual({ module: 'preserve' });
463+
});
451464
});

0 commit comments

Comments
 (0)