File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
packages/schematics/angular/migrations/use-application-builder Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9+ import { JsonObject } from '@angular-devkit/core';
910import { EmptyTree } from '@angular-devkit/schematics';
1011import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
1112import { 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});
You can’t perform that action at this time.
0 commit comments