fix(js): do not generate tsconfig.base.json when creating standalone projects (#15099)

Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
This commit is contained in:
Jack Hsu 2023-02-17 20:43:03 -05:00 committed by GitHub
parent 804cb95dff
commit 71fd015f3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 36 additions and 12 deletions

View File

@ -19,6 +19,11 @@
"description": "Skip formatting files.",
"default": true,
"x-priority": "internal"
},
"tsConfigName": {
"type": "string",
"description": "Customize the generated tsconfig file name.",
"x-priority": "internal"
}
},
"presets": []

View File

@ -32,6 +32,7 @@ describe('create-nx-workspace', () => {
checkFilesExist('package.json');
checkFilesExist('src/app/app.routes.ts');
checkFilesDoNotExist('tsconfig.base.json');
checkFilesExist('project.json');
});
@ -83,6 +84,7 @@ describe('create-nx-workspace', () => {
checkFilesExist('package.json');
checkFilesExist('project.json');
checkFilesExist('vite.config.ts');
checkFilesDoNotExist('tsconfig.base.json');
});
it('should create a workspace with a single react app with webpack at the root', () => {
@ -99,6 +101,7 @@ describe('create-nx-workspace', () => {
checkFilesExist('package.json');
checkFilesExist('project.json');
checkFilesExist('webpack.config.js');
checkFilesDoNotExist('tsconfig.base.json');
});
it('should be able to create an empty workspace built for apps', () => {

View File

@ -28,6 +28,8 @@ export async function angularInitGenerator(
const options = normalizeOptions(rawOptions);
setDefaults(host, options);
await jsInitGenerator(host, {
...options,
tsConfigName: options.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
js: false,
skipFormat: true,
});
@ -78,6 +80,7 @@ function normalizeOptions(options: Schema): Required<Schema> {
skipPackageJson: options.skipPackageJson ?? false,
style: options.style ?? 'css',
unitTestRunner: options.unitTestRunner ?? UnitTestRunner.Jest,
rootProject: options.rootProject,
};
}

View File

@ -10,4 +10,5 @@ export interface Schema {
style?: Styles;
linter?: Linter;
skipPackageJson?: boolean;
rootProject?: boolean;
}

View File

@ -70,6 +70,8 @@ export async function angularInitGenerator(
const options = normalizeOptions(rawOptions);
setDefaults(tree, options);
await jsInitGenerator(tree, {
...options,
tsConfigName: options.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
js: false,
skipFormat: true,
});
@ -102,6 +104,7 @@ function normalizeOptions(options: Schema): Required<Schema> {
skipPackageJson: options.skipPackageJson ?? false,
style: options.style ?? 'css',
unitTestRunner: options.unitTestRunner ?? UnitTestRunner.Jest,
rootProject: options.rootProject,
};
}

View File

@ -10,4 +10,5 @@ export interface Schema {
style?: Styles;
linter?: Linter;
skipPackageJson?: boolean;
rootProject?: boolean;
}

View File

@ -19,8 +19,10 @@ export async function initGenerator(
}
// add tsconfig.base.json
if (!getRootTsConfigFileName()) {
generateFiles(host, joinPathFragments(__dirname, './files'), '.', {});
if (!getRootTsConfigFileName(host)) {
generateFiles(host, joinPathFragments(__dirname, './files'), '.', {
fileName: schema.tsConfigName ?? 'tsconfig.base.json',
});
}
if (!schema.skipFormat) {

View File

@ -1,4 +1,5 @@
export interface InitSchema {
js?: boolean;
skipFormat?: boolean;
tsConfigName?: string;
}

View File

@ -16,6 +16,11 @@
"description": "Skip formatting files.",
"default": true,
"x-priority": "internal"
},
"tsConfigName": {
"type": "string",
"description": "Customize the generated tsconfig file name.",
"x-priority": "internal"
}
}
}

View File

@ -42,10 +42,9 @@ export function getRelativePathToRootTsConfig(
return offsetFromRoot(targetPath) + getRootTsConfigPathInTree(tree);
}
export function getRootTsConfigFileName(): string | null {
export function getRootTsConfigFileName(tree: Tree): string | null {
for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) {
const tsConfigPath = join(workspaceRoot, tsConfigName);
if (existsSync(tsConfigPath)) {
if (tree.exists(tsConfigName)) {
return tsConfigName;
}
}
@ -53,12 +52,6 @@ export function getRootTsConfigFileName(): string | null {
return null;
}
export function getRootTsConfigPath(): string | null {
const tsConfigFileName = getRootTsConfigFileName();
return tsConfigFileName ? join(workspaceRoot, tsConfigFileName) : null;
}
export function updateRootTsConfig(
host: Tree,
options: {

View File

@ -335,7 +335,7 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
const tasks: GeneratorCallback[] = [];
const initTask = await initGenerator(tree, {
...options,
...schema,
skipFormat: true,
});
tasks.push(initTask);

View File

@ -38,6 +38,8 @@ function normalizeOptions(schema: Schema) {
export async function initGenerator(tree: Tree, schema: Schema) {
const options = normalizeOptions(schema);
await jsInitGenerator(tree, {
...schema,
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
js: schema.js,
skipFormat: true,
});

View File

@ -2,4 +2,5 @@ export interface Schema {
unitTestRunner?: 'jest' | 'none';
skipFormat?: boolean;
js?: boolean;
rootProject?: boolean;
}

View File

@ -87,6 +87,8 @@ function initRootBabelConfig(tree: Tree, schema: InitSchema) {
export async function reactInitGenerator(host: Tree, schema: InitSchema) {
await jsInitGenerator(host, {
...schema,
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
js: schema.js,
skipFormat: true,
});

View File

@ -6,4 +6,6 @@ export interface InitSchema {
skipPackageJson?: boolean;
skipHelperLibs?: boolean;
js?: boolean;
rootProject?: boolean;
}