fix(misc): ensure all project generators add project to workspaces config (#29582)
- Update project generators to add the project to the workspaces setup in the new TS solution setup - Update some library generators that were not running package installation <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
d30a84f49c
commit
0d5bfe3700
@ -28,21 +28,6 @@ describe('Node Applications', () => {
|
|||||||
packages: ['@nx/node', '@nx/express', '@nx/nest', '@nx/webpack'],
|
packages: ['@nx/node', '@nx/express', '@nx/nest', '@nx/webpack'],
|
||||||
preset: 'ts',
|
preset: 'ts',
|
||||||
});
|
});
|
||||||
if (pm === 'pnpm') {
|
|
||||||
updateFile(
|
|
||||||
'pnpm-workspace.yaml',
|
|
||||||
`
|
|
||||||
packages:
|
|
||||||
- 'apps/*'
|
|
||||||
- 'packages/*'
|
|
||||||
`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
updateJson('package.json', (json) => {
|
|
||||||
json.workspaces = ['apps/*', 'packages/*'];
|
|
||||||
return json;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
|||||||
@ -18,21 +18,6 @@ describe('Vue Plugin', () => {
|
|||||||
packages: ['@nx/vue'],
|
packages: ['@nx/vue'],
|
||||||
preset: 'ts',
|
preset: 'ts',
|
||||||
});
|
});
|
||||||
if (pm === 'pnpm') {
|
|
||||||
updateFile(
|
|
||||||
'pnpm-workspace.yaml',
|
|
||||||
`
|
|
||||||
packages:
|
|
||||||
- 'apps/*'
|
|
||||||
- 'packages/*'
|
|
||||||
`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
updateJson('package.json', (json) => {
|
|
||||||
json.workspaces = ['apps/*', 'packages/*'];
|
|
||||||
return json;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => cleanupProject());
|
afterAll(() => cleanupProject());
|
||||||
|
|||||||
@ -1633,6 +1633,50 @@ describe('lib', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each`
|
||||||
|
directory | expected
|
||||||
|
${'my-ts-lib'} | ${'my-ts-lib'}
|
||||||
|
${'libs/my-ts-lib'} | ${'libs/*'}
|
||||||
|
${'libs/shared/my-ts-lib'} | ${'libs/shared/*'}
|
||||||
|
`(
|
||||||
|
'should add "$expected" to the workspace when creating a library in "$directory" using pnpm',
|
||||||
|
async ({ directory, expected }) => {
|
||||||
|
tree.write('pnpm-workspace.yaml', '');
|
||||||
|
|
||||||
|
await libraryGenerator(tree, {
|
||||||
|
...defaultOptions,
|
||||||
|
directory,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(tree.read('pnpm-workspace.yaml', 'utf-8'))
|
||||||
|
.toMatchInlineSnapshot(`
|
||||||
|
"packages:
|
||||||
|
- '${expected}'
|
||||||
|
"
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
it.each`
|
||||||
|
directory | expected
|
||||||
|
${'my-ts-lib'} | ${'my-ts-lib'}
|
||||||
|
${'libs/my-ts-lib'} | ${'libs/*'}
|
||||||
|
${'libs/shared/my-ts-lib'} | ${'libs/shared/*'}
|
||||||
|
`(
|
||||||
|
'should add "$expected" to the workspace when creating a library in "$directory" using npm or yarn',
|
||||||
|
async ({ directory, expected }) => {
|
||||||
|
// ensure there's no pnpm-workspace.yaml, so it uses the package.json workspaces
|
||||||
|
tree.delete('pnpm-workspace.yaml');
|
||||||
|
|
||||||
|
await libraryGenerator(tree, {
|
||||||
|
...defaultOptions,
|
||||||
|
directory,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(readJson(tree, 'package.json').workspaces).toContain(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
it('should map non-buildable libraries to source', async () => {
|
it('should map non-buildable libraries to source', async () => {
|
||||||
await libraryGenerator(tree, {
|
await libraryGenerator(tree, {
|
||||||
...defaultOptions,
|
...defaultOptions,
|
||||||
|
|||||||
@ -36,10 +36,6 @@ import { join } from 'path';
|
|||||||
import type { CompilerOptions } from 'typescript';
|
import type { CompilerOptions } from 'typescript';
|
||||||
import { normalizeLinterOption } from '../../utils/generator-prompts';
|
import { normalizeLinterOption } from '../../utils/generator-prompts';
|
||||||
import { getUpdatedPackageJsonContent } from '../../utils/package-json/update-package-json';
|
import { getUpdatedPackageJsonContent } from '../../utils/package-json/update-package-json';
|
||||||
import {
|
|
||||||
getProjectPackageManagerWorkspaceState,
|
|
||||||
getProjectPackageManagerWorkspaceStateWarningTask,
|
|
||||||
} from '../../utils/package-manager-workspaces';
|
|
||||||
import { addSwcConfig } from '../../utils/swc/add-swc-config';
|
import { addSwcConfig } from '../../utils/swc/add-swc-config';
|
||||||
import { getSwcDependencies } from '../../utils/swc/add-swc-dependencies';
|
import { getSwcDependencies } from '../../utils/swc/add-swc-dependencies';
|
||||||
import { getNeededCompilerOptionOverrides } from '../../utils/typescript/configuration';
|
import { getNeededCompilerOptionOverrides } from '../../utils/typescript/configuration';
|
||||||
@ -53,6 +49,7 @@ import {
|
|||||||
readTsConfigFromTree,
|
readTsConfigFromTree,
|
||||||
} from '../../utils/typescript/ts-config';
|
} from '../../utils/typescript/ts-config';
|
||||||
import {
|
import {
|
||||||
|
addProjectToTsSolutionWorkspace,
|
||||||
isUsingTsSolutionSetup,
|
isUsingTsSolutionSetup,
|
||||||
isUsingTypeScriptPlugin,
|
isUsingTypeScriptPlugin,
|
||||||
} from '../../utils/typescript/ts-solution-setup';
|
} from '../../utils/typescript/ts-solution-setup';
|
||||||
@ -218,21 +215,14 @@ export async function libraryGeneratorInternal(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipFormat) {
|
// If we are using the new TS solution
|
||||||
await formatFiles(tree);
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
||||||
|
if (options.isUsingTsSolutionConfig) {
|
||||||
|
addProjectToTsSolutionWorkspace(tree, options.projectRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!options.skipFormat) {
|
||||||
!options.skipWorkspacesWarning &&
|
await formatFiles(tree);
|
||||||
options.isUsingTsSolutionConfig &&
|
|
||||||
options.projectPackageManagerWorkspaceState !== 'included'
|
|
||||||
) {
|
|
||||||
tasks.push(
|
|
||||||
getProjectPackageManagerWorkspaceStateWarningTask(
|
|
||||||
options.projectPackageManagerWorkspaceState,
|
|
||||||
tree.root
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.publishable) {
|
if (options.publishable) {
|
||||||
@ -872,9 +862,6 @@ async function normalizeOptions(
|
|||||||
|
|
||||||
options.minimal ??= false;
|
options.minimal ??= false;
|
||||||
|
|
||||||
const projectPackageManagerWorkspaceState =
|
|
||||||
getProjectPackageManagerWorkspaceState(tree, projectRoot);
|
|
||||||
|
|
||||||
// We default to generate a project.json file if the new setup is not being used
|
// We default to generate a project.json file if the new setup is not being used
|
||||||
options.useProjectJson ??= !isUsingTsSolutionConfig;
|
options.useProjectJson ??= !isUsingTsSolutionConfig;
|
||||||
|
|
||||||
@ -888,7 +875,6 @@ async function normalizeOptions(
|
|||||||
importPath,
|
importPath,
|
||||||
hasPlugin,
|
hasPlugin,
|
||||||
isUsingTsSolutionConfig,
|
isUsingTsSolutionConfig,
|
||||||
projectPackageManagerWorkspaceState,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,6 @@ export interface LibraryGeneratorSchema {
|
|||||||
simpleName?: boolean;
|
simpleName?: boolean;
|
||||||
addPlugin?: boolean;
|
addPlugin?: boolean;
|
||||||
useProjectJson?: boolean;
|
useProjectJson?: boolean;
|
||||||
skipWorkspacesWarning?: boolean;
|
|
||||||
useTscExecutor?: boolean;
|
useTscExecutor?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,5 +46,4 @@ export interface NormalizedLibraryGeneratorOptions
|
|||||||
importPath?: string;
|
importPath?: string;
|
||||||
hasPlugin: boolean;
|
hasPlugin: boolean;
|
||||||
isUsingTsSolutionConfig: boolean;
|
isUsingTsSolutionConfig: boolean;
|
||||||
projectPackageManagerWorkspaceState: ProjectPackageManagerWorkspaceState;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -206,11 +206,8 @@ export function addProjectToTsSolutionWorkspace(
|
|||||||
if (tree.exists('pnpm-workspace.yaml')) {
|
if (tree.exists('pnpm-workspace.yaml')) {
|
||||||
const { load, dump } = require('@zkochan/js-yaml');
|
const { load, dump } = require('@zkochan/js-yaml');
|
||||||
const workspaceFile = tree.read('pnpm-workspace.yaml', 'utf-8');
|
const workspaceFile = tree.read('pnpm-workspace.yaml', 'utf-8');
|
||||||
const yamlData = load(workspaceFile);
|
const yamlData = load(workspaceFile) ?? {};
|
||||||
|
yamlData.packages ??= [];
|
||||||
if (!yamlData?.packages) {
|
|
||||||
yamlData.packages = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!yamlData.packages.includes(pattern)) {
|
if (!yamlData.packages.includes(pattern)) {
|
||||||
yamlData.packages.push(pattern);
|
yamlData.packages.push(pattern);
|
||||||
|
|||||||
@ -30,7 +30,10 @@ export async function libraryGeneratorInternal(
|
|||||||
rawOptions: LibraryGeneratorOptions
|
rawOptions: LibraryGeneratorOptions
|
||||||
): Promise<GeneratorCallback> {
|
): Promise<GeneratorCallback> {
|
||||||
const options = await normalizeOptions(tree, rawOptions);
|
const options = await normalizeOptions(tree, rawOptions);
|
||||||
await jsLibraryGenerator(tree, toJsLibraryGeneratorOptions(options));
|
const jsLibraryTask = await jsLibraryGenerator(
|
||||||
|
tree,
|
||||||
|
toJsLibraryGeneratorOptions(options)
|
||||||
|
);
|
||||||
const initTask = await initGenerator(tree, rawOptions);
|
const initTask = await initGenerator(tree, rawOptions);
|
||||||
const depsTask = ensureDependencies(tree);
|
const depsTask = ensureDependencies(tree);
|
||||||
deleteFiles(tree, options);
|
deleteFiles(tree, options);
|
||||||
@ -45,6 +48,7 @@ export async function libraryGeneratorInternal(
|
|||||||
|
|
||||||
return runTasksInSerial(
|
return runTasksInSerial(
|
||||||
...[
|
...[
|
||||||
|
jsLibraryTask,
|
||||||
initTask,
|
initTask,
|
||||||
depsTask,
|
depsTask,
|
||||||
() => {
|
() => {
|
||||||
|
|||||||
@ -56,6 +56,7 @@ import { hasWebpackPlugin } from '../../utils/has-webpack-plugin';
|
|||||||
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';
|
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';
|
||||||
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
||||||
import {
|
import {
|
||||||
|
addProjectToTsSolutionWorkspace,
|
||||||
isUsingTsSolutionSetup,
|
isUsingTsSolutionSetup,
|
||||||
updateTsconfigFiles,
|
updateTsconfigFiles,
|
||||||
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
||||||
@ -572,10 +573,6 @@ export async function applicationGeneratorInternal(tree: Tree, schema: Schema) {
|
|||||||
tasks.push(dockerTask);
|
tasks.push(dockerTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipFormat) {
|
|
||||||
await formatFiles(tree);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.isUsingTsSolutionConfig) {
|
if (options.isUsingTsSolutionConfig) {
|
||||||
updateTsconfigFiles(
|
updateTsconfigFiles(
|
||||||
tree,
|
tree,
|
||||||
@ -591,6 +588,16 @@ export async function applicationGeneratorInternal(tree: Tree, schema: Schema) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are using the new TS solution
|
||||||
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
||||||
|
if (options.isUsingTsSolutionConfig) {
|
||||||
|
addProjectToTsSolutionWorkspace(tree, options.appProjectRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.skipFormat) {
|
||||||
|
await formatFiles(tree);
|
||||||
|
}
|
||||||
|
|
||||||
tasks.push(() => {
|
tasks.push(() => {
|
||||||
logShowProjectCommand(options.name);
|
logShowProjectCommand(options.name);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -30,7 +30,10 @@ import {
|
|||||||
} from '@nx/eslint/src/generators/utils/eslint-file';
|
} from '@nx/eslint/src/generators/utils/eslint-file';
|
||||||
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
||||||
import { findRootJestPreset } from '@nx/jest/src/utils/config/config-file';
|
import { findRootJestPreset } from '@nx/jest/src/utils/config/config-file';
|
||||||
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
import {
|
||||||
|
addProjectToTsSolutionWorkspace,
|
||||||
|
isUsingTsSolutionSetup,
|
||||||
|
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
||||||
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
||||||
import { relative } from 'node:path/posix';
|
import { relative } from 'node:path/posix';
|
||||||
|
|
||||||
@ -230,10 +233,6 @@ export async function e2eProjectGeneratorInternal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipFormat) {
|
|
||||||
await formatFiles(host);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isUsingTsSolutionConfig) {
|
if (isUsingTsSolutionConfig) {
|
||||||
updateJson(host, 'tsconfig.json', (json) => {
|
updateJson(host, 'tsconfig.json', (json) => {
|
||||||
json.references ??= [];
|
json.references ??= [];
|
||||||
@ -245,6 +244,16 @@ export async function e2eProjectGeneratorInternal(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are using the new TS solution
|
||||||
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
||||||
|
if (isUsingTsSolutionConfig) {
|
||||||
|
addProjectToTsSolutionWorkspace(host, options.e2eProjectRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.skipFormat) {
|
||||||
|
await formatFiles(host);
|
||||||
|
}
|
||||||
|
|
||||||
tasks.push(() => {
|
tasks.push(() => {
|
||||||
logShowProjectCommand(options.e2eProjectName);
|
logShowProjectCommand(options.e2eProjectName);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -29,7 +29,10 @@ import { tslibVersion, typesNodeVersion } from '../../utils/versions';
|
|||||||
import { initGenerator } from '../init/init';
|
import { initGenerator } from '../init/init';
|
||||||
import { Schema } from './schema';
|
import { Schema } from './schema';
|
||||||
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';
|
import { addBuildTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';
|
||||||
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
import {
|
||||||
|
addProjectToTsSolutionWorkspace,
|
||||||
|
isUsingTsSolutionSetup,
|
||||||
|
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
||||||
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
||||||
|
|
||||||
export interface NormalizedSchema extends Schema {
|
export interface NormalizedSchema extends Schema {
|
||||||
@ -108,6 +111,12 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
|
|||||||
tasks.push(() => installPackagesTask(tree, true));
|
tasks.push(() => installPackagesTask(tree, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are using the new TS solution
|
||||||
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
||||||
|
if (options.isUsingTsSolutionConfig) {
|
||||||
|
addProjectToTsSolutionWorkspace(tree, options.projectRoot);
|
||||||
|
}
|
||||||
|
|
||||||
if (!schema.skipFormat) {
|
if (!schema.skipFormat) {
|
||||||
await formatFiles(tree);
|
await formatFiles(tree);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,10 @@ import {
|
|||||||
createNxCloudOnboardingURLForWelcomeApp,
|
createNxCloudOnboardingURLForWelcomeApp,
|
||||||
} from 'nx/src/nx-cloud/utilities/onboarding';
|
} from 'nx/src/nx-cloud/utilities/onboarding';
|
||||||
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
||||||
import { updateTsconfigFiles } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
import {
|
||||||
|
addProjectToTsSolutionWorkspace,
|
||||||
|
updateTsconfigFiles,
|
||||||
|
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
||||||
|
|
||||||
export async function applicationGenerator(tree: Tree, schema: Schema) {
|
export async function applicationGenerator(tree: Tree, schema: Schema) {
|
||||||
const tasks: GeneratorCallback[] = [];
|
const tasks: GeneratorCallback[] = [];
|
||||||
@ -170,22 +173,6 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
|
|||||||
|
|
||||||
if (options.js) toJS(tree);
|
if (options.js) toJS(tree);
|
||||||
|
|
||||||
if (!options.skipFormat) await formatFiles(tree);
|
|
||||||
|
|
||||||
tasks.push(() => {
|
|
||||||
try {
|
|
||||||
execSync(`npx -y nuxi prepare`, {
|
|
||||||
cwd: options.appProjectRoot,
|
|
||||||
|
|
||||||
windowsHide: false,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error(
|
|
||||||
`Failed to run \`nuxi prepare\` in "${options.appProjectRoot}". Please run the command manually.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (options.isUsingTsSolutionConfig) {
|
if (options.isUsingTsSolutionConfig) {
|
||||||
updateTsconfigFiles(
|
updateTsconfigFiles(
|
||||||
tree,
|
tree,
|
||||||
@ -204,6 +191,28 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are using the new TS solution
|
||||||
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
||||||
|
if (options.isUsingTsSolutionConfig) {
|
||||||
|
addProjectToTsSolutionWorkspace(tree, options.appProjectRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.skipFormat) await formatFiles(tree);
|
||||||
|
|
||||||
|
tasks.push(() => {
|
||||||
|
try {
|
||||||
|
execSync(`npx -y nuxi prepare`, {
|
||||||
|
cwd: options.appProjectRoot,
|
||||||
|
|
||||||
|
windowsHide: false,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(
|
||||||
|
`Failed to run \`nuxi prepare\` in "${options.appProjectRoot}". Please run the command manually.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
tasks.push(() => {
|
tasks.push(() => {
|
||||||
logShowProjectCommand(options.projectName);
|
logShowProjectCommand(options.projectName);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -13,10 +13,6 @@ import {
|
|||||||
updateProjectConfiguration,
|
updateProjectConfiguration,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { libraryGenerator as jsLibraryGenerator } from '@nx/js';
|
import { libraryGenerator as jsLibraryGenerator } from '@nx/js';
|
||||||
import {
|
|
||||||
getProjectPackageManagerWorkspaceState,
|
|
||||||
getProjectPackageManagerWorkspaceStateWarningTask,
|
|
||||||
} from '@nx/js/src/utils/package-manager-workspaces';
|
|
||||||
import { addTsLibDependencies } from '@nx/js/src/utils/typescript/add-tslib-dependencies';
|
import { addTsLibDependencies } from '@nx/js/src/utils/typescript/add-tslib-dependencies';
|
||||||
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
||||||
import { tsLibVersion } from '@nx/js/src/utils/versions';
|
import { tsLibVersion } from '@nx/js/src/utils/versions';
|
||||||
@ -61,7 +57,13 @@ export async function createPackageGeneratorInternal(
|
|||||||
);
|
);
|
||||||
tasks.push(installTask);
|
tasks.push(installTask);
|
||||||
|
|
||||||
await createCliPackage(host, options, pluginPackageName);
|
const cliPackageTask = await createCliPackage(
|
||||||
|
host,
|
||||||
|
options,
|
||||||
|
pluginPackageName
|
||||||
|
);
|
||||||
|
tasks.push(cliPackageTask);
|
||||||
|
|
||||||
if (options.e2eProject) {
|
if (options.e2eProject) {
|
||||||
addE2eProject(host, options);
|
addE2eProject(host, options);
|
||||||
}
|
}
|
||||||
@ -70,20 +72,6 @@ export async function createPackageGeneratorInternal(
|
|||||||
await formatFiles(host);
|
await formatFiles(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.isTsSolutionSetup) {
|
|
||||||
const projectPackageManagerWorkspaceState =
|
|
||||||
getProjectPackageManagerWorkspaceState(host, options.projectRoot);
|
|
||||||
|
|
||||||
if (projectPackageManagerWorkspaceState !== 'included') {
|
|
||||||
tasks.push(
|
|
||||||
getProjectPackageManagerWorkspaceStateWarningTask(
|
|
||||||
projectPackageManagerWorkspaceState,
|
|
||||||
host.root
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return runTasksInSerial(...tasks);
|
return runTasksInSerial(...tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +104,7 @@ async function createCliPackage(
|
|||||||
options: NormalizedSchema,
|
options: NormalizedSchema,
|
||||||
pluginPackageName: string
|
pluginPackageName: string
|
||||||
) {
|
) {
|
||||||
await jsLibraryGenerator(host, {
|
const jsLibraryTask = await jsLibraryGenerator(host, {
|
||||||
...options,
|
...options,
|
||||||
directory: options.directory,
|
directory: options.directory,
|
||||||
rootProject: false,
|
rootProject: false,
|
||||||
@ -127,7 +115,6 @@ async function createCliPackage(
|
|||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
skipTsConfig: true,
|
skipTsConfig: true,
|
||||||
useTscExecutor: true,
|
useTscExecutor: true,
|
||||||
skipWorkspacesWarning: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
host.delete(joinPathFragments(options.projectRoot, 'src'));
|
host.delete(joinPathFragments(options.projectRoot, 'src'));
|
||||||
@ -203,6 +190,8 @@ async function createCliPackage(
|
|||||||
tmpl: '',
|
tmpl: '',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return jsLibraryTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -28,10 +28,9 @@ import { setupVerdaccio } from '@nx/js/src/generators/setup-verdaccio/generator'
|
|||||||
import { addLocalRegistryScripts } from '@nx/js/src/utils/add-local-registry-scripts';
|
import { addLocalRegistryScripts } from '@nx/js/src/utils/add-local-registry-scripts';
|
||||||
import { normalizeLinterOption } from '@nx/js/src/utils/generator-prompts';
|
import { normalizeLinterOption } from '@nx/js/src/utils/generator-prompts';
|
||||||
import {
|
import {
|
||||||
getProjectPackageManagerWorkspaceState,
|
addProjectToTsSolutionWorkspace,
|
||||||
getProjectPackageManagerWorkspaceStateWarningTask,
|
isUsingTsSolutionSetup,
|
||||||
} from '@nx/js/src/utils/package-manager-workspaces';
|
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
||||||
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
|
||||||
import type { PackageJson } from 'nx/src/utils/package-json';
|
import type { PackageJson } from 'nx/src/utils/package-json';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import type { Schema } from './schema';
|
import type { Schema } from './schema';
|
||||||
@ -256,22 +255,14 @@ export async function e2eProjectGeneratorInternal(host: Tree, schema: Schema) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipFormat) {
|
// If we are using the new TS solution
|
||||||
await formatFiles(host);
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
||||||
|
if (options.isTsSolutionSetup) {
|
||||||
|
addProjectToTsSolutionWorkspace(host, options.projectRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.isTsSolutionSetup && !options.skipWorkspacesWarning) {
|
if (!options.skipFormat) {
|
||||||
const projectPackageManagerWorkspaceState =
|
await formatFiles(host);
|
||||||
getProjectPackageManagerWorkspaceState(host, options.projectRoot);
|
|
||||||
|
|
||||||
if (projectPackageManagerWorkspaceState !== 'included') {
|
|
||||||
tasks.push(
|
|
||||||
getProjectPackageManagerWorkspaceStateWarningTask(
|
|
||||||
projectPackageManagerWorkspaceState,
|
|
||||||
host.root
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return runTasksInSerial(...tasks);
|
return runTasksInSerial(...tasks);
|
||||||
|
|||||||
@ -11,5 +11,4 @@ export interface Schema {
|
|||||||
rootProject?: boolean;
|
rootProject?: boolean;
|
||||||
useProjectJson?: boolean;
|
useProjectJson?: boolean;
|
||||||
addPlugin?: boolean;
|
addPlugin?: boolean;
|
||||||
skipWorkspacesWarning?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,10 +12,6 @@ import {
|
|||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { Linter } from '@nx/eslint';
|
import { Linter } from '@nx/eslint';
|
||||||
import { libraryGenerator as jsLibraryGenerator } from '@nx/js';
|
import { libraryGenerator as jsLibraryGenerator } from '@nx/js';
|
||||||
import {
|
|
||||||
getProjectPackageManagerWorkspaceState,
|
|
||||||
getProjectPackageManagerWorkspaceStateWarningTask,
|
|
||||||
} from '@nx/js/src/utils/package-manager-workspaces';
|
|
||||||
import {
|
import {
|
||||||
addSwcDependencies,
|
addSwcDependencies,
|
||||||
addSwcRegisterDependencies,
|
addSwcRegisterDependencies,
|
||||||
@ -102,7 +98,6 @@ export async function pluginGeneratorInternal(host: Tree, schema: Schema) {
|
|||||||
useProjectJson: options.useProjectJson,
|
useProjectJson: options.useProjectJson,
|
||||||
addPlugin: options.addPlugin,
|
addPlugin: options.addPlugin,
|
||||||
skipFormat: true,
|
skipFormat: true,
|
||||||
skipWorkspacesWarning: true,
|
|
||||||
useTscExecutor: true,
|
useTscExecutor: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -149,7 +144,6 @@ export async function pluginGeneratorInternal(host: Tree, schema: Schema) {
|
|||||||
linter: options.linter,
|
linter: options.linter,
|
||||||
useProjectJson: options.useProjectJson,
|
useProjectJson: options.useProjectJson,
|
||||||
addPlugin: options.addPlugin,
|
addPlugin: options.addPlugin,
|
||||||
skipWorkspacesWarning: true,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -162,20 +156,6 @@ export async function pluginGeneratorInternal(host: Tree, schema: Schema) {
|
|||||||
await formatFiles(host);
|
await formatFiles(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.isTsSolutionSetup) {
|
|
||||||
const projectPackageManagerWorkspaceState =
|
|
||||||
getProjectPackageManagerWorkspaceState(host, options.projectRoot);
|
|
||||||
|
|
||||||
if (projectPackageManagerWorkspaceState !== 'included') {
|
|
||||||
tasks.push(
|
|
||||||
getProjectPackageManagerWorkspaceStateWarningTask(
|
|
||||||
projectPackageManagerWorkspaceState,
|
|
||||||
host.root
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return runTasksInSerial(...tasks);
|
return runTasksInSerial(...tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -310,9 +310,6 @@ export default {...nxPreset};
|
|||||||
tasks.push(await addE2E(tree, options));
|
tasks.push(await addE2E(tree, options));
|
||||||
|
|
||||||
addViteTempFilesToGitIgnore(tree);
|
addViteTempFilesToGitIgnore(tree);
|
||||||
if (!options.skipFormat) {
|
|
||||||
await formatFiles(tree);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTsconfigFiles(
|
updateTsconfigFiles(
|
||||||
tree,
|
tree,
|
||||||
@ -335,6 +332,10 @@ export default {...nxPreset};
|
|||||||
addProjectToTsSolutionWorkspace(tree, options.projectRoot);
|
addProjectToTsSolutionWorkspace(tree, options.projectRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!options.skipFormat) {
|
||||||
|
await formatFiles(tree);
|
||||||
|
}
|
||||||
|
|
||||||
tasks.push(() => {
|
tasks.push(() => {
|
||||||
logShowProjectCommand(options.projectName);
|
logShowProjectCommand(options.projectName);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -23,7 +23,10 @@ import { extractTsConfigBase } from '../../utils/create-ts-config';
|
|||||||
import { ensureDependencies } from '../../utils/ensure-dependencies';
|
import { ensureDependencies } from '../../utils/ensure-dependencies';
|
||||||
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
|
||||||
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
||||||
import { updateTsconfigFiles } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
import {
|
||||||
|
addProjectToTsSolutionWorkspace,
|
||||||
|
updateTsconfigFiles,
|
||||||
|
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
||||||
|
|
||||||
export function applicationGenerator(tree: Tree, options: Schema) {
|
export function applicationGenerator(tree: Tree, options: Schema) {
|
||||||
return applicationGeneratorInternal(tree, { addPlugin: false, ...options });
|
return applicationGeneratorInternal(tree, { addPlugin: false, ...options });
|
||||||
@ -123,8 +126,6 @@ export async function applicationGeneratorInternal(
|
|||||||
|
|
||||||
if (options.js) toJS(tree);
|
if (options.js) toJS(tree);
|
||||||
|
|
||||||
if (!options.skipFormat) await formatFiles(tree);
|
|
||||||
|
|
||||||
if (options.isUsingTsSolutionConfig) {
|
if (options.isUsingTsSolutionConfig) {
|
||||||
updateTsconfigFiles(
|
updateTsconfigFiles(
|
||||||
tree,
|
tree,
|
||||||
@ -143,6 +144,14 @@ export async function applicationGeneratorInternal(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are using the new TS solution
|
||||||
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
||||||
|
if (options.isUsingTsSolutionConfig) {
|
||||||
|
addProjectToTsSolutionWorkspace(tree, options.appProjectRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.skipFormat) await formatFiles(tree);
|
||||||
|
|
||||||
tasks.push(() => {
|
tasks.push(() => {
|
||||||
logShowProjectCommand(options.projectName);
|
logShowProjectCommand(options.projectName);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -26,7 +26,10 @@ import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-com
|
|||||||
import { getRelativeCwd } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
import { getRelativeCwd } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
||||||
import { relative } from 'path';
|
import { relative } from 'path';
|
||||||
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
import { getImportPath } from '@nx/js/src/utils/get-import-path';
|
||||||
import { updateTsconfigFiles } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
import {
|
||||||
|
addProjectToTsSolutionWorkspace,
|
||||||
|
updateTsconfigFiles,
|
||||||
|
} from '@nx/js/src/utils/typescript/ts-solution-setup';
|
||||||
|
|
||||||
export function libraryGenerator(tree: Tree, schema: Schema) {
|
export function libraryGenerator(tree: Tree, schema: Schema) {
|
||||||
return libraryGeneratorInternal(tree, { addPlugin: false, ...schema });
|
return libraryGeneratorInternal(tree, { addPlugin: false, ...schema });
|
||||||
@ -141,8 +144,6 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
|
|||||||
|
|
||||||
if (options.js) toJS(tree);
|
if (options.js) toJS(tree);
|
||||||
|
|
||||||
if (!options.skipFormat) await formatFiles(tree);
|
|
||||||
|
|
||||||
if (options.isUsingTsSolutionConfig) {
|
if (options.isUsingTsSolutionConfig) {
|
||||||
updateTsconfigFiles(
|
updateTsconfigFiles(
|
||||||
tree,
|
tree,
|
||||||
@ -161,6 +162,14 @@ export async function libraryGeneratorInternal(tree: Tree, schema: Schema) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are using the new TS solution
|
||||||
|
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
||||||
|
if (options.isUsingTsSolutionConfig) {
|
||||||
|
addProjectToTsSolutionWorkspace(tree, options.projectRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.skipFormat) await formatFiles(tree);
|
||||||
|
|
||||||
// Always run install to link packages.
|
// Always run install to link packages.
|
||||||
if (options.isUsingTsSolutionConfig) {
|
if (options.isUsingTsSolutionConfig) {
|
||||||
tasks.push(() => installPackagesTask(tree, true));
|
tasks.push(() => installPackagesTask(tree, true));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user