fix(angular): update tsconfig files generation to better support angular v20 (#31357)
- Remove TS project reference to non-existent `tsconfig.editor.json` file - Ensure the `tsconfig.spec.json` file for Jest has the correct `module`/`moduleResolution` compiler options
This commit is contained in:
parent
e0ea5be3f6
commit
fc0aeb5a4b
@ -599,9 +599,6 @@ exports[`app --strict should enable strict type checking: app tsconfig.json 1`]
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.editor.json",
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.app.json",
|
||||
},
|
||||
@ -1162,9 +1159,6 @@ exports[`app not nested should generate files: tsconfig.json 1`] = `
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.editor.json",
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.app.json",
|
||||
},
|
||||
|
||||
@ -9,7 +9,6 @@ import {
|
||||
Tree,
|
||||
updateJson,
|
||||
updateNxJson,
|
||||
updateProjectConfiguration,
|
||||
} from '@nx/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
||||
import * as enquirer from 'enquirer';
|
||||
|
||||
@ -6,10 +6,10 @@
|
||||
},
|
||||
"files": [],
|
||||
"include": [],
|
||||
"references": [
|
||||
"references": [<% if (angularMajorVersion < 20) { %>
|
||||
{
|
||||
"path": "./tsconfig.editor.json"
|
||||
},
|
||||
},<% } %>
|
||||
{
|
||||
"path": "./tsconfig.app.json"
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ import {
|
||||
} from '@nx/devkit';
|
||||
import { getRootTsConfigFileName } from '@nx/js';
|
||||
import { getNeededCompilerOptionOverrides } from '@nx/js/src/utils/typescript/configuration';
|
||||
import { gte, lt } from 'semver';
|
||||
import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript';
|
||||
import { gte, lt } from 'semver';
|
||||
import { updateAppEditorTsConfigExcludedFiles } from '../../utils/update-app-editor-tsconfig-excluded-files';
|
||||
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
|
||||
import { enableStrictTypeChecking } from './enable-strict-type-checking';
|
||||
@ -59,7 +59,11 @@ export function updateTsconfigFiles(tree: Tree, options: NormalizedSchema) {
|
||||
}
|
||||
}
|
||||
|
||||
updateJson(tree, `${options.appProjectRoot}/tsconfig.json`, (json) => {
|
||||
const tsconfigPath = joinPathFragments(
|
||||
options.appProjectRoot,
|
||||
'tsconfig.json'
|
||||
);
|
||||
updateJson(tree, tsconfigPath, (json) => {
|
||||
json.compilerOptions = {
|
||||
...json.compilerOptions,
|
||||
...compilerOptions,
|
||||
@ -71,9 +75,37 @@ export function updateTsconfigFiles(tree: Tree, options: NormalizedSchema) {
|
||||
);
|
||||
return json;
|
||||
});
|
||||
|
||||
if (options.unitTestRunner === 'jest') {
|
||||
const tsconfigSpecPath = joinPathFragments(
|
||||
options.appProjectRoot,
|
||||
'tsconfig.spec.json'
|
||||
);
|
||||
updateJson(tree, tsconfigSpecPath, (json) => {
|
||||
json.compilerOptions = {
|
||||
...json.compilerOptions,
|
||||
module: 'commonjs',
|
||||
moduleResolution: 'node10',
|
||||
};
|
||||
json.compilerOptions = getNeededCompilerOptionOverrides(
|
||||
tree,
|
||||
json.compilerOptions,
|
||||
tsconfigPath
|
||||
);
|
||||
return json;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function updateEditorTsConfig(tree: Tree, options: NormalizedSchema) {
|
||||
const tsconfigEditorPath = joinPathFragments(
|
||||
options.appProjectRoot,
|
||||
'tsconfig.editor.json'
|
||||
);
|
||||
if (!tree.exists(tsconfigEditorPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const appTsConfig = readJson<TsConfig>(
|
||||
tree,
|
||||
joinPathFragments(options.appProjectRoot, 'tsconfig.app.json')
|
||||
|
||||
@ -27,6 +27,7 @@ export function updateTsConfigFiles(
|
||||
experimentalDecorators: true,
|
||||
importHelpers: true,
|
||||
target: 'es2022',
|
||||
moduleResolution: 'bundler',
|
||||
...(options.strict
|
||||
? {
|
||||
strict: true,
|
||||
@ -46,11 +47,11 @@ export function updateTsConfigFiles(
|
||||
if (angularMajorVersion >= 20) {
|
||||
compilerOptions.module = 'preserve';
|
||||
} else {
|
||||
compilerOptions.moduleResolution = 'bundler';
|
||||
compilerOptions.module = 'es2022';
|
||||
}
|
||||
|
||||
updateJson(tree, `${options.projectRoot}/tsconfig.json`, (json) => {
|
||||
const tsconfigPath = joinPathFragments(options.projectRoot, 'tsconfig.json');
|
||||
updateJson(tree, tsconfigPath, (json) => {
|
||||
json.compilerOptions = {
|
||||
...json.compilerOptions,
|
||||
...compilerOptions,
|
||||
@ -73,6 +74,26 @@ export function updateTsConfigFiles(
|
||||
|
||||
return json;
|
||||
});
|
||||
|
||||
if (options.unitTestRunner === 'jest') {
|
||||
const tsconfigSpecPath = joinPathFragments(
|
||||
options.projectRoot,
|
||||
'tsconfig.spec.json'
|
||||
);
|
||||
updateJson(tree, tsconfigSpecPath, (json) => {
|
||||
json.compilerOptions = {
|
||||
...json.compilerOptions,
|
||||
module: 'commonjs',
|
||||
moduleResolution: 'node10',
|
||||
};
|
||||
json.compilerOptions = getNeededCompilerOptionOverrides(
|
||||
tree,
|
||||
json.compilerOptions,
|
||||
tsconfigPath
|
||||
);
|
||||
return json;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function updateProjectConfig(
|
||||
|
||||
@ -316,6 +316,7 @@ describe('lib', () => {
|
||||
experimentalDecorators: true,
|
||||
importHelpers: true,
|
||||
module: 'preserve',
|
||||
moduleResolution: 'bundler',
|
||||
skipLibCheck: true,
|
||||
noFallthroughCasesInSwitch: true,
|
||||
noPropertyAccessFromIndexSignature: true,
|
||||
|
||||
@ -72,8 +72,8 @@ export async function libraryGenerator(
|
||||
const project = await addProject(tree, libraryOptions);
|
||||
|
||||
createFiles(tree, options, project);
|
||||
updateTsConfigFiles(tree, libraryOptions);
|
||||
await addUnitTestRunner(tree, libraryOptions);
|
||||
updateTsConfigFiles(tree, libraryOptions);
|
||||
updateNpmScopeIfBuildableOrPublishable(tree, libraryOptions);
|
||||
setGeneratorDefaults(tree, options);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user