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.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);
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ export function newProject({
|
||||
|
||||
if (!directoryExists(tmpBackupProjPath())) {
|
||||
runCreateWorkspace(projScope, {
|
||||
preset: 'empty',
|
||||
preset: 'apps',
|
||||
packageManager,
|
||||
});
|
||||
|
||||
|
||||
@ -171,7 +171,14 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
|
||||
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`)
|
||||
.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.
|
||||
* It would:
|
||||
@ -336,8 +365,6 @@ async function determineStack(
|
||||
case Preset.NodeStandalone:
|
||||
case Preset.Express:
|
||||
return 'node';
|
||||
case Preset.Core:
|
||||
case Preset.Empty:
|
||||
case Preset.Apps:
|
||||
case Preset.NPM:
|
||||
case Preset.TS:
|
||||
@ -782,6 +809,7 @@ async function determinePackageBasedOrIntegratedOrStandalone(): Promise<
|
||||
|
||||
return workspaceType;
|
||||
}
|
||||
|
||||
async function determineStandaloneOrMonorepo(): Promise<
|
||||
'integrated' | 'standalone'
|
||||
> {
|
||||
|
||||
@ -4,10 +4,8 @@ import { Preset } from './preset';
|
||||
export function pointToTutorialAndCourse(preset: Preset) {
|
||||
const title = `First time using Nx? Check out this interactive Nx tutorial.`;
|
||||
switch (preset) {
|
||||
case Preset.Empty:
|
||||
case Preset.NPM:
|
||||
case Preset.Apps:
|
||||
case Preset.Core:
|
||||
output.addVerticalSeparator();
|
||||
output.note({
|
||||
title,
|
||||
|
||||
@ -4,6 +4,7 @@ exports[`new --preset should generate necessary npm dependencies for empty prese
|
||||
{
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@nx/js": "0.0.1",
|
||||
"@nx/workspace": "0.0.1",
|
||||
"nx": "0.0.1",
|
||||
},
|
||||
|
||||
@ -16,14 +16,6 @@ import * as yargsParser from 'yargs-parser';
|
||||
import { spawn, SpawnOptions } from 'child_process';
|
||||
|
||||
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);
|
||||
return addDependenciesToPackageJson(
|
||||
host,
|
||||
@ -98,6 +90,8 @@ function getPresetDependencies({
|
||||
e2eTestRunner,
|
||||
}: NormalizedSchema) {
|
||||
switch (preset) {
|
||||
case Preset.Apps:
|
||||
case Preset.NPM:
|
||||
case Preset.TS:
|
||||
case Preset.TsStandalone:
|
||||
return { dependencies: {}, dev: { '@nx/js': nxVersion } };
|
||||
|
||||
@ -19,7 +19,7 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
||||
await generateWorkspaceFiles(tree, {
|
||||
name: 'proj',
|
||||
directory: 'proj',
|
||||
preset: Preset.Empty,
|
||||
preset: Preset.Apps,
|
||||
defaultBase: 'main',
|
||||
isCustomPreset: false,
|
||||
});
|
||||
@ -80,7 +80,7 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
||||
await generateWorkspaceFiles(tree, {
|
||||
name: 'proj',
|
||||
directory: 'proj',
|
||||
preset: Preset.Empty,
|
||||
preset: Preset.Apps,
|
||||
defaultBase: 'main',
|
||||
isCustomPreset: false,
|
||||
});
|
||||
@ -88,11 +88,25 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
||||
expect(nxJson).toMatchInlineSnapshot(`
|
||||
{
|
||||
"$schema": "./node_modules/nx/schemas/nx-schema.json",
|
||||
"namedInputs": {
|
||||
"default": [
|
||||
"{projectRoot}/**/*",
|
||||
"sharedGlobals",
|
||||
],
|
||||
"production": [
|
||||
"default",
|
||||
],
|
||||
"sharedGlobals": [],
|
||||
},
|
||||
"targetDefaults": {
|
||||
"build": {
|
||||
"dependsOn": [
|
||||
"^build",
|
||||
],
|
||||
"inputs": [
|
||||
"production",
|
||||
"^production",
|
||||
],
|
||||
},
|
||||
},
|
||||
"tasksRunnerOptions": {
|
||||
@ -168,7 +182,7 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
||||
await generateWorkspaceFiles(tree, {
|
||||
name: 'proj',
|
||||
directory: 'proj',
|
||||
preset: Preset.Empty,
|
||||
preset: Preset.Apps,
|
||||
defaultBase: 'main',
|
||||
isCustomPreset: false,
|
||||
});
|
||||
@ -184,7 +198,7 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
||||
await generateWorkspaceFiles(tree, {
|
||||
name: 'proj',
|
||||
directory: 'proj',
|
||||
preset: Preset.Empty,
|
||||
preset: Preset.Apps,
|
||||
defaultBase: 'main',
|
||||
isCustomPreset: false,
|
||||
});
|
||||
|
||||
@ -53,7 +53,7 @@ export async function generateWorkspaceFiles(
|
||||
|
||||
function setPresetProperty(tree: Tree, options: NormalizedSchema) {
|
||||
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');
|
||||
delete json.implicitDependencies;
|
||||
delete json.targetDefaults;
|
||||
@ -64,11 +64,7 @@ function setPresetProperty(tree: Tree, options: NormalizedSchema) {
|
||||
}
|
||||
|
||||
function createAppsAndLibsFolders(tree: Tree, options: NormalizedSchema) {
|
||||
if (
|
||||
options.preset === Preset.Core ||
|
||||
options.preset === Preset.TS ||
|
||||
options.preset === Preset.NPM
|
||||
) {
|
||||
if (options.preset === Preset.TS || options.preset === Preset.NPM) {
|
||||
tree.write(join(options.directory, 'packages/.gitkeep'), '');
|
||||
} else if (
|
||||
options.preset === Preset.AngularStandalone ||
|
||||
@ -113,11 +109,7 @@ function createNxJson(
|
||||
if (defaultBase === 'main') {
|
||||
delete nxJson.affected;
|
||||
}
|
||||
if (
|
||||
preset !== Preset.Core &&
|
||||
preset !== Preset.NPM &&
|
||||
preset !== Preset.Empty
|
||||
) {
|
||||
if (preset !== Preset.NPM) {
|
||||
nxJson.namedInputs = {
|
||||
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
||||
production: ['default'],
|
||||
@ -138,7 +130,7 @@ function createFiles(tree: Tree, options: NormalizedSchema) {
|
||||
options.preset === Preset.NextJsStandalone ||
|
||||
options.preset === Preset.TsStandalone
|
||||
? './files-root-app'
|
||||
: options.preset === Preset.NPM || options.preset === Preset.Core
|
||||
: options.preset === Preset.NPM
|
||||
? './files-package-based-repo'
|
||||
: './files-integrated-repo';
|
||||
generateFiles(tree, join(__dirname, filesDirName), options.directory, {
|
||||
@ -233,7 +225,7 @@ function normalizeOptions(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') {
|
||||
tree.write(
|
||||
join(options.directory, 'pnpm-workspace.yaml'),
|
||||
|
||||
@ -53,7 +53,7 @@ describe('new', () => {
|
||||
name: 'my-workspace',
|
||||
directory: 'my-workspace',
|
||||
appName: 'app',
|
||||
preset: Preset.Empty,
|
||||
preset: Preset.Apps,
|
||||
});
|
||||
|
||||
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);
|
||||
// TODO: move all of these into create-nx-workspace
|
||||
if (
|
||||
options.preset !== Preset.NPM &&
|
||||
options.preset !== Preset.Core &&
|
||||
!options.isCustomPreset
|
||||
) {
|
||||
if (options.preset !== Preset.NPM && !options.isCustomPreset) {
|
||||
await generatePreset(host, options);
|
||||
}
|
||||
};
|
||||
@ -76,9 +72,7 @@ function validateOptions(options: Schema, host: Tree) {
|
||||
if (
|
||||
options.skipInstall &&
|
||||
options.preset !== Preset.Apps &&
|
||||
options.preset !== Preset.Core &&
|
||||
options.preset !== Preset.TS &&
|
||||
options.preset !== Preset.Empty &&
|
||||
options.preset !== Preset.NPM
|
||||
) {
|
||||
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;
|
||||
|
||||
async function createPreset(tree: Tree, options: Schema) {
|
||||
if (options.preset === Preset.Empty || options.preset === Preset.Apps) {
|
||||
if (options.preset === Preset.Apps) {
|
||||
return;
|
||||
} else if (options.preset === Preset.AngularMonorepo) {
|
||||
const {
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
export enum Preset {
|
||||
Apps = 'apps',
|
||||
Empty = 'empty', // same as apps, deprecated
|
||||
Core = 'core', // same as npm, deprecated
|
||||
// TODO(v18): Remove Empty and Core presets
|
||||
/** @deprecated Use Apps instead
|
||||
*/
|
||||
Empty = 'empty',
|
||||
/** @deprecated Use NPM instead
|
||||
*/
|
||||
Core = 'core',
|
||||
NPM = 'npm',
|
||||
TS = 'ts',
|
||||
WebComponents = 'web-components',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user