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.", "description": "Skip formatting files.",
"default": true, "default": true,
"x-priority": "internal" "x-priority": "internal"
},
"tsConfigName": {
"type": "string",
"description": "Customize the generated tsconfig file name.",
"x-priority": "internal"
} }
}, },
"presets": [] "presets": []

View File

@ -32,6 +32,7 @@ describe('create-nx-workspace', () => {
checkFilesExist('package.json'); checkFilesExist('package.json');
checkFilesExist('src/app/app.routes.ts'); checkFilesExist('src/app/app.routes.ts');
checkFilesDoNotExist('tsconfig.base.json');
checkFilesExist('project.json'); checkFilesExist('project.json');
}); });
@ -83,6 +84,7 @@ describe('create-nx-workspace', () => {
checkFilesExist('package.json'); checkFilesExist('package.json');
checkFilesExist('project.json'); checkFilesExist('project.json');
checkFilesExist('vite.config.ts'); checkFilesExist('vite.config.ts');
checkFilesDoNotExist('tsconfig.base.json');
}); });
it('should create a workspace with a single react app with webpack at the root', () => { 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('package.json');
checkFilesExist('project.json'); checkFilesExist('project.json');
checkFilesExist('webpack.config.js'); checkFilesExist('webpack.config.js');
checkFilesDoNotExist('tsconfig.base.json');
}); });
it('should be able to create an empty workspace built for apps', () => { 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); const options = normalizeOptions(rawOptions);
setDefaults(host, options); setDefaults(host, options);
await jsInitGenerator(host, { await jsInitGenerator(host, {
...options,
tsConfigName: options.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
js: false, js: false,
skipFormat: true, skipFormat: true,
}); });
@ -78,6 +80,7 @@ function normalizeOptions(options: Schema): Required<Schema> {
skipPackageJson: options.skipPackageJson ?? false, skipPackageJson: options.skipPackageJson ?? false,
style: options.style ?? 'css', style: options.style ?? 'css',
unitTestRunner: options.unitTestRunner ?? UnitTestRunner.Jest, unitTestRunner: options.unitTestRunner ?? UnitTestRunner.Jest,
rootProject: options.rootProject,
}; };
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,6 +16,11 @@
"description": "Skip formatting files.", "description": "Skip formatting files.",
"default": true, "default": true,
"x-priority": "internal" "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); 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']) { for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) {
const tsConfigPath = join(workspaceRoot, tsConfigName); if (tree.exists(tsConfigName)) {
if (existsSync(tsConfigPath)) {
return tsConfigName; return tsConfigName;
} }
} }
@ -53,12 +52,6 @@ export function getRootTsConfigFileName(): string | null {
return null; return null;
} }
export function getRootTsConfigPath(): string | null {
const tsConfigFileName = getRootTsConfigFileName();
return tsConfigFileName ? join(workspaceRoot, tsConfigFileName) : null;
}
export function updateRootTsConfig( export function updateRootTsConfig(
host: Tree, host: Tree,
options: { options: {

View File

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

View File

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

View File

@ -2,4 +2,5 @@ export interface Schema {
unitTestRunner?: 'jest' | 'none'; unitTestRunner?: 'jest' | 'none';
skipFormat?: boolean; skipFormat?: boolean;
js?: 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) { export async function reactInitGenerator(host: Tree, schema: InitSchema) {
await jsInitGenerator(host, { await jsInitGenerator(host, {
...schema,
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
js: schema.js, js: schema.js,
skipFormat: true, skipFormat: true,
}); });

View File

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