Skip to content

Commit aad8a06

Browse files
committed
fix(@schematics/angular): do not set esModuleInterop and moduleResolution when module is preserve
1 parent 61a027d commit aad8a06

File tree

1 file changed

+14
-2
lines changed
  • packages/schematics/angular/migrations/use-application-builder

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
hasPostcssConfiguration,
3636
updateStyleImports,
3737
} from './stylesheet-updates';
38+
import { JsonObject } from '@angular-devkit/core';
3839

3940
function* updateBuildTarget(
4041
projectName: string,
@@ -362,10 +363,21 @@ export default function (): Rule {
362363
),
363364
// Update main tsconfig
364365
updateJsonFile('tsconfig.json', (rootJson) => {
365-
rootJson.modify(['compilerOptions', 'esModuleInterop'], true);
366+
let hasPreserveModule = false;
367+
const compilerOptions = rootJson.get(['compilerOptions']);
368+
369+
if (compilerOptions && typeof compilerOptions === 'object') {
370+
const { module } = compilerOptions as JsonObject;
371+
hasPreserveModule = typeof module === 'string' && module.toLowerCase() === 'preserve';
372+
}
373+
374+
if (!hasPreserveModule) {
375+
rootJson.modify(['compilerOptions', 'esModuleInterop'], true);
376+
rootJson.modify(['compilerOptions', 'moduleResolution'], 'bundler');
377+
}
378+
366379
rootJson.modify(['compilerOptions', 'downlevelIteration'], undefined);
367380
rootJson.modify(['compilerOptions', 'allowSyntheticDefaultImports'], undefined);
368-
rootJson.modify(['compilerOptions', 'moduleResolution'], 'bundler');
369381
}),
370382
]);
371383
}

0 commit comments

Comments
 (0)