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:
parent
804cb95dff
commit
71fd015f3d
@ -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": []
|
||||
|
||||
@ -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', () => {
|
||||
|
||||
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -10,4 +10,5 @@ export interface Schema {
|
||||
style?: Styles;
|
||||
linter?: Linter;
|
||||
skipPackageJson?: boolean;
|
||||
rootProject?: boolean;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -10,4 +10,5 @@ export interface Schema {
|
||||
style?: Styles;
|
||||
linter?: Linter;
|
||||
skipPackageJson?: boolean;
|
||||
rootProject?: boolean;
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
1
packages/js/src/generators/init/schema.d.ts
vendored
1
packages/js/src/generators/init/schema.d.ts
vendored
@ -1,4 +1,5 @@
|
||||
export interface InitSchema {
|
||||
js?: boolean;
|
||||
skipFormat?: boolean;
|
||||
tsConfigName?: string;
|
||||
}
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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: {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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,
|
||||
});
|
||||
|
||||
@ -2,4 +2,5 @@ export interface Schema {
|
||||
unitTestRunner?: 'jest' | 'none';
|
||||
skipFormat?: boolean;
|
||||
js?: boolean;
|
||||
rootProject?: boolean;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
});
|
||||
|
||||
@ -6,4 +6,6 @@ export interface InitSchema {
|
||||
skipPackageJson?: boolean;
|
||||
skipHelperLibs?: boolean;
|
||||
js?: boolean;
|
||||
|
||||
rootProject?: boolean;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user