feat(core): ensure @nx/js plugin is installed for all JS workspaces (#18919)
This commit is contained in:
parent
99c44f9e88
commit
c9ea9e076f
@ -759,7 +759,7 @@ describe('Workspace Tests', () => {
|
|||||||
|
|
||||||
expect(error).toBeDefined();
|
expect(error).toBeDefined();
|
||||||
expect(error.stdout.toString()).toContain(
|
expect(error.stdout.toString()).toContain(
|
||||||
`${lib1} is still depended on by the following projects`
|
`${lib1} is still a dependency of the following projects`
|
||||||
);
|
);
|
||||||
expect(error.stdout.toString()).toContain(lib2);
|
expect(error.stdout.toString()).toContain(lib2);
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ export function newProject({
|
|||||||
|
|
||||||
if (!directoryExists(tmpBackupProjPath())) {
|
if (!directoryExists(tmpBackupProjPath())) {
|
||||||
runCreateWorkspace(projScope, {
|
runCreateWorkspace(projScope, {
|
||||||
preset: 'empty',
|
preset: 'apps',
|
||||||
packageManager,
|
packageManager,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -171,7 +171,14 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
|
|||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[normalizeArgsMiddleware as yargs.MiddlewareFunction<{}>]
|
[
|
||||||
|
normalizeArgsMiddleware,
|
||||||
|
normalizeAndWarnOnDeprecatedPreset({
|
||||||
|
// TODO(v18): Remove Empty and Core presets
|
||||||
|
[Preset.Core]: Preset.NPM,
|
||||||
|
[Preset.Empty]: Preset.Apps,
|
||||||
|
}),
|
||||||
|
] as yargs.MiddlewareFunction<{}>[]
|
||||||
)
|
)
|
||||||
.help('help', chalk.dim`Show help`)
|
.help('help', chalk.dim`Show help`)
|
||||||
.updateLocale(yargsDecorator)
|
.updateLocale(yargsDecorator)
|
||||||
@ -217,6 +224,28 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeAndWarnOnDeprecatedPreset(
|
||||||
|
deprecatedPresets: Partial<Record<Preset, Preset>>
|
||||||
|
): (argv: yargs.Arguments<Arguments>) => Promise<void> {
|
||||||
|
return async (args: yargs.Arguments<Arguments>): Promise<void> => {
|
||||||
|
if (!args.preset) return;
|
||||||
|
if (deprecatedPresets[args.preset]) {
|
||||||
|
args.preset = deprecatedPresets[args.preset] as Preset;
|
||||||
|
output.addVerticalSeparator();
|
||||||
|
output.note({
|
||||||
|
title: `The "${args.preset}" preset is deprecated.`,
|
||||||
|
bodyLines: [
|
||||||
|
`The "${
|
||||||
|
args.preset
|
||||||
|
}" preset will be removed in a future Nx release. Use the "${
|
||||||
|
deprecatedPresets[args.preset]
|
||||||
|
}" preset instead.`,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used to normalize the arguments passed to the command.
|
* This function is used to normalize the arguments passed to the command.
|
||||||
* It would:
|
* It would:
|
||||||
@ -336,8 +365,6 @@ async function determineStack(
|
|||||||
case Preset.NodeStandalone:
|
case Preset.NodeStandalone:
|
||||||
case Preset.Express:
|
case Preset.Express:
|
||||||
return 'node';
|
return 'node';
|
||||||
case Preset.Core:
|
|
||||||
case Preset.Empty:
|
|
||||||
case Preset.Apps:
|
case Preset.Apps:
|
||||||
case Preset.NPM:
|
case Preset.NPM:
|
||||||
case Preset.TS:
|
case Preset.TS:
|
||||||
@ -782,6 +809,7 @@ async function determinePackageBasedOrIntegratedOrStandalone(): Promise<
|
|||||||
|
|
||||||
return workspaceType;
|
return workspaceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function determineStandaloneOrMonorepo(): Promise<
|
async function determineStandaloneOrMonorepo(): Promise<
|
||||||
'integrated' | 'standalone'
|
'integrated' | 'standalone'
|
||||||
> {
|
> {
|
||||||
|
|||||||
@ -4,10 +4,8 @@ import { Preset } from './preset';
|
|||||||
export function pointToTutorialAndCourse(preset: Preset) {
|
export function pointToTutorialAndCourse(preset: Preset) {
|
||||||
const title = `First time using Nx? Check out this interactive Nx tutorial.`;
|
const title = `First time using Nx? Check out this interactive Nx tutorial.`;
|
||||||
switch (preset) {
|
switch (preset) {
|
||||||
case Preset.Empty:
|
|
||||||
case Preset.NPM:
|
case Preset.NPM:
|
||||||
case Preset.Apps:
|
case Preset.Apps:
|
||||||
case Preset.Core:
|
|
||||||
output.addVerticalSeparator();
|
output.addVerticalSeparator();
|
||||||
output.note({
|
output.note({
|
||||||
title,
|
title,
|
||||||
|
|||||||
@ -4,6 +4,7 @@ exports[`new --preset should generate necessary npm dependencies for empty prese
|
|||||||
{
|
{
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@nx/js": "0.0.1",
|
||||||
"@nx/workspace": "0.0.1",
|
"@nx/workspace": "0.0.1",
|
||||||
"nx": "0.0.1",
|
"nx": "0.0.1",
|
||||||
},
|
},
|
||||||
|
|||||||
@ -16,14 +16,6 @@ import * as yargsParser from 'yargs-parser';
|
|||||||
import { spawn, SpawnOptions } from 'child_process';
|
import { spawn, SpawnOptions } from 'child_process';
|
||||||
|
|
||||||
export function addPresetDependencies(host: Tree, options: NormalizedSchema) {
|
export function addPresetDependencies(host: Tree, options: NormalizedSchema) {
|
||||||
if (
|
|
||||||
options.preset === Preset.Apps ||
|
|
||||||
options.preset === Preset.Core ||
|
|
||||||
options.preset === Preset.Empty ||
|
|
||||||
options.preset === Preset.NPM
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { dependencies, dev } = getPresetDependencies(options);
|
const { dependencies, dev } = getPresetDependencies(options);
|
||||||
return addDependenciesToPackageJson(
|
return addDependenciesToPackageJson(
|
||||||
host,
|
host,
|
||||||
@ -98,6 +90,8 @@ function getPresetDependencies({
|
|||||||
e2eTestRunner,
|
e2eTestRunner,
|
||||||
}: NormalizedSchema) {
|
}: NormalizedSchema) {
|
||||||
switch (preset) {
|
switch (preset) {
|
||||||
|
case Preset.Apps:
|
||||||
|
case Preset.NPM:
|
||||||
case Preset.TS:
|
case Preset.TS:
|
||||||
case Preset.TsStandalone:
|
case Preset.TsStandalone:
|
||||||
return { dependencies: {}, dev: { '@nx/js': nxVersion } };
|
return { dependencies: {}, dev: { '@nx/js': nxVersion } };
|
||||||
|
|||||||
@ -19,7 +19,7 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
|||||||
await generateWorkspaceFiles(tree, {
|
await generateWorkspaceFiles(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
preset: Preset.Empty,
|
preset: Preset.Apps,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
isCustomPreset: false,
|
isCustomPreset: false,
|
||||||
});
|
});
|
||||||
@ -80,7 +80,7 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
|||||||
await generateWorkspaceFiles(tree, {
|
await generateWorkspaceFiles(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
preset: Preset.Empty,
|
preset: Preset.Apps,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
isCustomPreset: false,
|
isCustomPreset: false,
|
||||||
});
|
});
|
||||||
@ -88,11 +88,25 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
|||||||
expect(nxJson).toMatchInlineSnapshot(`
|
expect(nxJson).toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"$schema": "./node_modules/nx/schemas/nx-schema.json",
|
"$schema": "./node_modules/nx/schemas/nx-schema.json",
|
||||||
|
"namedInputs": {
|
||||||
|
"default": [
|
||||||
|
"{projectRoot}/**/*",
|
||||||
|
"sharedGlobals",
|
||||||
|
],
|
||||||
|
"production": [
|
||||||
|
"default",
|
||||||
|
],
|
||||||
|
"sharedGlobals": [],
|
||||||
|
},
|
||||||
"targetDefaults": {
|
"targetDefaults": {
|
||||||
"build": {
|
"build": {
|
||||||
"dependsOn": [
|
"dependsOn": [
|
||||||
"^build",
|
"^build",
|
||||||
],
|
],
|
||||||
|
"inputs": [
|
||||||
|
"production",
|
||||||
|
"^production",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"tasksRunnerOptions": {
|
"tasksRunnerOptions": {
|
||||||
@ -168,7 +182,7 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
|||||||
await generateWorkspaceFiles(tree, {
|
await generateWorkspaceFiles(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
preset: Preset.Empty,
|
preset: Preset.Apps,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
isCustomPreset: false,
|
isCustomPreset: false,
|
||||||
});
|
});
|
||||||
@ -184,7 +198,7 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
|||||||
await generateWorkspaceFiles(tree, {
|
await generateWorkspaceFiles(tree, {
|
||||||
name: 'proj',
|
name: 'proj',
|
||||||
directory: 'proj',
|
directory: 'proj',
|
||||||
preset: Preset.Empty,
|
preset: Preset.Apps,
|
||||||
defaultBase: 'main',
|
defaultBase: 'main',
|
||||||
isCustomPreset: false,
|
isCustomPreset: false,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -53,7 +53,7 @@ export async function generateWorkspaceFiles(
|
|||||||
|
|
||||||
function setPresetProperty(tree: Tree, options: NormalizedSchema) {
|
function setPresetProperty(tree: Tree, options: NormalizedSchema) {
|
||||||
updateJson(tree, join(options.directory, 'nx.json'), (json) => {
|
updateJson(tree, join(options.directory, 'nx.json'), (json) => {
|
||||||
if (options.preset === Preset.Core || options.preset === Preset.NPM) {
|
if (options.preset === Preset.NPM) {
|
||||||
addPropertyWithStableKeys(json, 'extends', 'nx/presets/npm.json');
|
addPropertyWithStableKeys(json, 'extends', 'nx/presets/npm.json');
|
||||||
delete json.implicitDependencies;
|
delete json.implicitDependencies;
|
||||||
delete json.targetDefaults;
|
delete json.targetDefaults;
|
||||||
@ -64,11 +64,7 @@ function setPresetProperty(tree: Tree, options: NormalizedSchema) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createAppsAndLibsFolders(tree: Tree, options: NormalizedSchema) {
|
function createAppsAndLibsFolders(tree: Tree, options: NormalizedSchema) {
|
||||||
if (
|
if (options.preset === Preset.TS || options.preset === Preset.NPM) {
|
||||||
options.preset === Preset.Core ||
|
|
||||||
options.preset === Preset.TS ||
|
|
||||||
options.preset === Preset.NPM
|
|
||||||
) {
|
|
||||||
tree.write(join(options.directory, 'packages/.gitkeep'), '');
|
tree.write(join(options.directory, 'packages/.gitkeep'), '');
|
||||||
} else if (
|
} else if (
|
||||||
options.preset === Preset.AngularStandalone ||
|
options.preset === Preset.AngularStandalone ||
|
||||||
@ -113,11 +109,7 @@ function createNxJson(
|
|||||||
if (defaultBase === 'main') {
|
if (defaultBase === 'main') {
|
||||||
delete nxJson.affected;
|
delete nxJson.affected;
|
||||||
}
|
}
|
||||||
if (
|
if (preset !== Preset.NPM) {
|
||||||
preset !== Preset.Core &&
|
|
||||||
preset !== Preset.NPM &&
|
|
||||||
preset !== Preset.Empty
|
|
||||||
) {
|
|
||||||
nxJson.namedInputs = {
|
nxJson.namedInputs = {
|
||||||
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
||||||
production: ['default'],
|
production: ['default'],
|
||||||
@ -138,7 +130,7 @@ function createFiles(tree: Tree, options: NormalizedSchema) {
|
|||||||
options.preset === Preset.NextJsStandalone ||
|
options.preset === Preset.NextJsStandalone ||
|
||||||
options.preset === Preset.TsStandalone
|
options.preset === Preset.TsStandalone
|
||||||
? './files-root-app'
|
? './files-root-app'
|
||||||
: options.preset === Preset.NPM || options.preset === Preset.Core
|
: options.preset === Preset.NPM
|
||||||
? './files-package-based-repo'
|
? './files-package-based-repo'
|
||||||
: './files-integrated-repo';
|
: './files-integrated-repo';
|
||||||
generateFiles(tree, join(__dirname, filesDirName), options.directory, {
|
generateFiles(tree, join(__dirname, filesDirName), options.directory, {
|
||||||
@ -233,7 +225,7 @@ function normalizeOptions(options: NormalizedSchema) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setUpWorkspacesInPackageJson(tree: Tree, options: NormalizedSchema) {
|
function setUpWorkspacesInPackageJson(tree: Tree, options: NormalizedSchema) {
|
||||||
if (options.preset === Preset.NPM || options.preset === Preset.Core) {
|
if (options.preset === Preset.NPM) {
|
||||||
if (options.packageManager === 'pnpm') {
|
if (options.packageManager === 'pnpm') {
|
||||||
tree.write(
|
tree.write(
|
||||||
join(options.directory, 'pnpm-workspace.yaml'),
|
join(options.directory, 'pnpm-workspace.yaml'),
|
||||||
|
|||||||
@ -53,7 +53,7 @@ describe('new', () => {
|
|||||||
name: 'my-workspace',
|
name: 'my-workspace',
|
||||||
directory: 'my-workspace',
|
directory: 'my-workspace',
|
||||||
appName: 'app',
|
appName: 'app',
|
||||||
preset: Preset.Empty,
|
preset: Preset.Apps,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(readJson(tree, 'my-workspace/package.json')).toMatchSnapshot();
|
expect(readJson(tree, 'my-workspace/package.json')).toMatchSnapshot();
|
||||||
|
|||||||
@ -60,11 +60,7 @@ export async function newGenerator(host: Tree, opts: Schema) {
|
|||||||
}
|
}
|
||||||
installPackagesTask(host, false, options.directory, options.packageManager);
|
installPackagesTask(host, false, options.directory, options.packageManager);
|
||||||
// TODO: move all of these into create-nx-workspace
|
// TODO: move all of these into create-nx-workspace
|
||||||
if (
|
if (options.preset !== Preset.NPM && !options.isCustomPreset) {
|
||||||
options.preset !== Preset.NPM &&
|
|
||||||
options.preset !== Preset.Core &&
|
|
||||||
!options.isCustomPreset
|
|
||||||
) {
|
|
||||||
await generatePreset(host, options);
|
await generatePreset(host, options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -76,9 +72,7 @@ function validateOptions(options: Schema, host: Tree) {
|
|||||||
if (
|
if (
|
||||||
options.skipInstall &&
|
options.skipInstall &&
|
||||||
options.preset !== Preset.Apps &&
|
options.preset !== Preset.Apps &&
|
||||||
options.preset !== Preset.Core &&
|
|
||||||
options.preset !== Preset.TS &&
|
options.preset !== Preset.TS &&
|
||||||
options.preset !== Preset.Empty &&
|
|
||||||
options.preset !== Preset.NPM
|
options.preset !== Preset.NPM
|
||||||
) {
|
) {
|
||||||
throw new Error(`Cannot select a preset when skipInstall is set to true.`);
|
throw new Error(`Cannot select a preset when skipInstall is set to true.`);
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export async function presetGenerator(tree: Tree, options: Schema) {
|
|||||||
export default presetGenerator;
|
export default presetGenerator;
|
||||||
|
|
||||||
async function createPreset(tree: Tree, options: Schema) {
|
async function createPreset(tree: Tree, options: Schema) {
|
||||||
if (options.preset === Preset.Empty || options.preset === Preset.Apps) {
|
if (options.preset === Preset.Apps) {
|
||||||
return;
|
return;
|
||||||
} else if (options.preset === Preset.AngularMonorepo) {
|
} else if (options.preset === Preset.AngularMonorepo) {
|
||||||
const {
|
const {
|
||||||
|
|||||||
@ -1,7 +1,12 @@
|
|||||||
export enum Preset {
|
export enum Preset {
|
||||||
Apps = 'apps',
|
Apps = 'apps',
|
||||||
Empty = 'empty', // same as apps, deprecated
|
// TODO(v18): Remove Empty and Core presets
|
||||||
Core = 'core', // same as npm, deprecated
|
/** @deprecated Use Apps instead
|
||||||
|
*/
|
||||||
|
Empty = 'empty',
|
||||||
|
/** @deprecated Use NPM instead
|
||||||
|
*/
|
||||||
|
Core = 'core',
|
||||||
NPM = 'npm',
|
NPM = 'npm',
|
||||||
TS = 'ts',
|
TS = 'ts',
|
||||||
WebComponents = 'web-components',
|
WebComponents = 'web-components',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user