@nx/plugin 24.0.0-pr.37405.acdaf31 → 24.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/generators/create-package/create-package.js +8 -1
- package/dist/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__ +65 -2
- package/dist/src/generators/create-package/schema.d.ts +0 -1
- package/dist/src/generators/create-package/utils/normalize-schema.d.ts +0 -1
- package/dist/src/generators/create-package/utils/normalize-schema.js +1 -9
- package/dist/src/generators/e2e-project/e2e.js +31 -38
- package/dist/src/generators/e2e-project/files/src/__simplePluginName__.spec.ts__tmpl__ +1 -1
- package/dist/src/generators/e2e-project/schema.d.ts +2 -1
- package/dist/src/generators/e2e-project/schema.json +5 -0
- package/dist/src/generators/lint-checks/generator.d.ts +1 -3
- package/dist/src/generators/lint-checks/generator.js +0 -69
- package/dist/src/generators/plugin/plugin.js +8 -3
- package/dist/src/generators/plugin/schema.d.ts +0 -5
- package/dist/src/generators/plugin/schema.json +0 -6
- package/dist/src/generators/plugin/utils/normalize-schema.d.ts +1 -2
- package/dist/src/generators/plugin/utils/normalize-schema.js +1 -9
- package/dist/src/generators/preset/generator.js +0 -3
- package/dist/src/generators/preset/schema.d.ts +0 -1
- package/package.json +7 -7
|
@@ -5,6 +5,7 @@ exports.createPackageGeneratorInternal = createPackageGeneratorInternal;
|
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const js_1 = require("@nx/js");
|
|
7
7
|
const internal_1 = require("@nx/js/internal");
|
|
8
|
+
const jest_1 = require("@nx/jest");
|
|
8
9
|
const path_1 = require("path");
|
|
9
10
|
const has_generator_1 = require("../../utils/has-generator");
|
|
10
11
|
const generator_1 = require("../generator/generator");
|
|
@@ -13,7 +14,6 @@ const internal_2 = require("@nx/devkit/internal");
|
|
|
13
14
|
async function createPackageGenerator(host, schema) {
|
|
14
15
|
return await createPackageGeneratorInternal(host, {
|
|
15
16
|
useProjectJson: true,
|
|
16
|
-
addPlugin: false,
|
|
17
17
|
...schema,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -73,6 +73,13 @@ async function createCliPackage(host, options, pluginPackageName) {
|
|
|
73
73
|
useTscExecutor: true,
|
|
74
74
|
});
|
|
75
75
|
host.delete((0, devkit_1.joinPathFragments)(options.projectRoot, 'src'));
|
|
76
|
+
if (options.unitTestRunner === 'jest') {
|
|
77
|
+
// src and its spec are removed above, so the package has no tests yet.
|
|
78
|
+
const jestConfig = (0, jest_1.findJestConfig)(host, options.projectRoot);
|
|
79
|
+
if (jestConfig) {
|
|
80
|
+
(0, jest_1.addPropertyToJestConfig)(host, jestConfig, 'passWithNoTests', true);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
76
83
|
const isTsSolutionSetup = (0, internal_1.isUsingTsSolutionSetup)(host);
|
|
77
84
|
// Add the bin entry to the package.json
|
|
78
85
|
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), (packageJson) => {
|
package/dist/src/generators/create-package/files/create-framework-package/bin/index.ts__tmpl__
CHANGED
|
@@ -1,9 +1,72 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { sep } from 'node:path';
|
|
3
4
|
import { createWorkspace } from 'create-nx-workspace';
|
|
4
5
|
|
|
6
|
+
const packageManagers = ['pnpm', 'yarn', 'npm', 'bun'] as const;
|
|
7
|
+
type PackageManager = (typeof packageManagers)[number];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Mirrors `create-nx-workspace`: an explicit `--packageManager` wins, otherwise
|
|
11
|
+
* the manager that invoked this CLI, otherwise npm. Choosing at run time keeps
|
|
12
|
+
* the published CLI usable under whichever manager the consumer actually has
|
|
13
|
+
* installed, rather than the one the plugin author generated it from.
|
|
14
|
+
*/
|
|
15
|
+
function determinePackageManager(explicit: string | undefined): PackageManager {
|
|
16
|
+
if (explicit) {
|
|
17
|
+
if (!(packageManagers as readonly string[]).includes(explicit)) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`Package manager must be one of ${packageManagers.join(', ')}`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return explicit as PackageManager;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
26
|
+
if (userAgent) {
|
|
27
|
+
const invoked = packageManagers.find((pm) =>
|
|
28
|
+
userAgent.startsWith(`${pm}/`)
|
|
29
|
+
);
|
|
30
|
+
if (invoked) {
|
|
31
|
+
return invoked;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const execPath = process.env.npm_execpath;
|
|
36
|
+
if (execPath) {
|
|
37
|
+
const segments = execPath.split(sep);
|
|
38
|
+
const invoked = packageManagers.find((pm) => segments.includes(pm));
|
|
39
|
+
if (invoked) {
|
|
40
|
+
return invoked;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return 'npm';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Reads the workspace name and `--packageManager`/`--pm` out of the argv tail. */
|
|
48
|
+
function parseArgs(argv: string[]): {
|
|
49
|
+
name: string | undefined;
|
|
50
|
+
packageManager: string | undefined;
|
|
51
|
+
} {
|
|
52
|
+
let name: string | undefined;
|
|
53
|
+
let packageManager: string | undefined;
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < argv.length; i++) {
|
|
56
|
+
const match = /^--(?:packageManager|pm)(?:=(.*))?$/.exec(argv[i]);
|
|
57
|
+
if (match) {
|
|
58
|
+
packageManager = match[1] ?? argv[++i];
|
|
59
|
+
} else if (name === undefined && !argv[i].startsWith('-')) {
|
|
60
|
+
name = argv[i];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { name, packageManager };
|
|
65
|
+
}
|
|
66
|
+
|
|
5
67
|
async function main() {
|
|
6
|
-
|
|
68
|
+
// TODO: use libraries like yargs, <%= unitTestRunner === 'jest' ? 'enquirer' : '@clack/prompts' %>, or another prompting library to set your workspace name
|
|
69
|
+
const { name, packageManager } = parseArgs(process.argv.slice(2));
|
|
7
70
|
if (!name) {
|
|
8
71
|
throw new Error('Please provide a name for the workspace');
|
|
9
72
|
}
|
|
@@ -21,7 +84,7 @@ async function main() {
|
|
|
21
84
|
{
|
|
22
85
|
name,
|
|
23
86
|
nxCloud: 'skip',
|
|
24
|
-
packageManager:
|
|
87
|
+
packageManager: determinePackageManager(packageManager),
|
|
25
88
|
}
|
|
26
89
|
);
|
|
27
90
|
|
|
@@ -8,7 +8,6 @@ export interface NormalizedSchema extends CreatePackageSchema {
|
|
|
8
8
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
9
9
|
linter: LinterType;
|
|
10
10
|
useProjectJson: boolean;
|
|
11
|
-
addPlugin: boolean;
|
|
12
11
|
isTsSolutionSetup: boolean;
|
|
13
12
|
}
|
|
14
13
|
export declare function normalizeSchema(host: Tree, schema: CreatePackageSchema): Promise<NormalizedSchema>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeSchema = normalizeSchema;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
4
|
const internal_1 = require("@nx/devkit/internal");
|
|
6
5
|
const internal_2 = require("@nx/js/internal");
|
|
7
6
|
async function normalizeSchema(host, schema) {
|
|
@@ -19,13 +18,7 @@ async function normalizeSchema(host, schema) {
|
|
|
19
18
|
// jsLibraryGenerator, so, if the TS solution setup is not configured, we
|
|
20
19
|
// additionally check if the TS solution setup will be configured by the
|
|
21
20
|
// jsLibraryGenerator
|
|
22
|
-
const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)(host) ||
|
|
23
|
-
(0, internal_2.shouldConfigureTsSolutionSetup)(host, schema.addPlugin);
|
|
24
|
-
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
25
|
-
const addPlugin = schema.addPlugin ??
|
|
26
|
-
(isTsSolutionSetup &&
|
|
27
|
-
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
28
|
-
nxJson.useInferencePlugins !== false);
|
|
21
|
+
const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)(host) || (0, internal_2.shouldConfigureTsSolutionSetup)(host);
|
|
29
22
|
return {
|
|
30
23
|
...schema,
|
|
31
24
|
bundler: schema.compiler ?? 'tsc',
|
|
@@ -36,7 +29,6 @@ async function normalizeSchema(host, schema) {
|
|
|
36
29
|
unitTestRunner,
|
|
37
30
|
// We default to generate a project.json file if the new setup is not being used
|
|
38
31
|
useProjectJson: schema.useProjectJson ?? !isTsSolutionSetup,
|
|
39
|
-
addPlugin,
|
|
40
32
|
isTsSolutionSetup,
|
|
41
33
|
};
|
|
42
34
|
}
|
|
@@ -12,10 +12,6 @@ const versions_1 = require("../../utils/versions");
|
|
|
12
12
|
async function normalizeOptions(host, options) {
|
|
13
13
|
const linter = await (0, internal_2.normalizeLinterOption)(host, options.linter);
|
|
14
14
|
const projectName = options.rootProject ? 'e2e' : `${options.pluginName}-e2e`;
|
|
15
|
-
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
16
|
-
const addPlugin = options.addPlugin ??
|
|
17
|
-
(process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
18
|
-
nxJson.useInferencePlugins !== false);
|
|
19
15
|
let projectRoot;
|
|
20
16
|
const projectNameAndRootOptions = await (0, internal_1.determineProjectNameAndRootOptions)(host, {
|
|
21
17
|
name: projectName,
|
|
@@ -33,7 +29,6 @@ async function normalizeOptions(host, options) {
|
|
|
33
29
|
linter,
|
|
34
30
|
pluginPropertyName,
|
|
35
31
|
projectRoot,
|
|
36
|
-
addPlugin,
|
|
37
32
|
useProjectJson: options.useProjectJson ?? !isTsSolutionSetup,
|
|
38
33
|
isTsSolutionSetup,
|
|
39
34
|
};
|
|
@@ -50,11 +45,15 @@ function addFiles(host, options) {
|
|
|
50
45
|
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.pluginName);
|
|
51
46
|
const { name: pluginPackageName } = (0, devkit_1.readJson)(host, (0, path_1.join)(projectConfiguration.root, 'package.json'));
|
|
52
47
|
const simplePluginName = options.pluginName.split('/').pop();
|
|
48
|
+
// One manager drives workspace creation, the install and the checks, so the
|
|
49
|
+
// generated e2e test cannot straddle two.
|
|
50
|
+
const packageManager = options.packageManager ?? (0, devkit_1.detectPackageManager)();
|
|
53
51
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.projectRoot, {
|
|
54
52
|
...options,
|
|
55
53
|
tmpl: '',
|
|
56
54
|
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
|
|
57
|
-
packageManagerCommands: (0, devkit_1.getPackageManagerCommand)(),
|
|
55
|
+
packageManagerCommands: (0, devkit_1.getPackageManagerCommand)(packageManager),
|
|
56
|
+
packageManager,
|
|
58
57
|
pluginPackageName,
|
|
59
58
|
simplePluginName,
|
|
60
59
|
});
|
|
@@ -86,7 +85,6 @@ async function addJest(host, options) {
|
|
|
86
85
|
supportTsx: false,
|
|
87
86
|
skipSerializers: true,
|
|
88
87
|
skipFormat: true,
|
|
89
|
-
addPlugin: options.addPlugin,
|
|
90
88
|
compiler: options.isTsSolutionSetup ? 'swc' : undefined,
|
|
91
89
|
});
|
|
92
90
|
const { startLocalRegistryPath, stopLocalRegistryPath } = (0, internal_2.addLocalRegistryScripts)(host);
|
|
@@ -98,18 +96,17 @@ async function addJest(host, options) {
|
|
|
98
96
|
(0, jest_1.addPropertyToJestConfig)(host, jestConfigPath, 'globalTeardown', (0, path_1.join)((0, devkit_1.offsetFromRoot)(options.projectRoot), stopLocalRegistryPath));
|
|
99
97
|
const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
100
98
|
project.targets ??= {};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
99
|
+
// The e2e target is inferred, so this partial target merges onto it.
|
|
100
|
+
const e2eTarget = project.targets.e2e;
|
|
101
|
+
project.targets.e2e = {
|
|
102
|
+
...e2eTarget,
|
|
103
|
+
dependsOn: [`^build`],
|
|
104
|
+
options: {
|
|
105
|
+
...e2eTarget?.options,
|
|
106
|
+
runInBand: true,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, project);
|
|
113
110
|
return jestTask;
|
|
114
111
|
}
|
|
115
112
|
async function addVitest(host, options) {
|
|
@@ -141,7 +138,6 @@ async function addVitest(host, options) {
|
|
|
141
138
|
project: options.projectName,
|
|
142
139
|
testTarget: 'e2e',
|
|
143
140
|
skipFormat: true,
|
|
144
|
-
addPlugin: options.addPlugin,
|
|
145
141
|
testEnvironment: 'node',
|
|
146
142
|
coverageProvider: 'none',
|
|
147
143
|
});
|
|
@@ -199,22 +195,21 @@ export { default as teardown } from './stop-local-registry';
|
|
|
199
195
|
}
|
|
200
196
|
const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
201
197
|
project.targets ??= {};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
198
|
+
const e2eTarget = project.targets.e2e;
|
|
199
|
+
// The suites share a single tmp/test-project directory, so they have to run
|
|
200
|
+
// one at a time. Vitest 4 removed `poolOptions`, and nested options do not
|
|
201
|
+
// survive the argv round-trip anyway, so use the scalar options. The e2e
|
|
202
|
+
// target is inferred, so this partial target merges onto it.
|
|
203
|
+
project.targets.e2e = {
|
|
204
|
+
...e2eTarget,
|
|
205
|
+
dependsOn: [`^build`],
|
|
206
|
+
options: {
|
|
207
|
+
...e2eTarget?.options,
|
|
208
|
+
maxWorkers: 1,
|
|
209
|
+
isolate: false,
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, project);
|
|
218
213
|
return vitestTask;
|
|
219
214
|
}
|
|
220
215
|
async function addLintingToApplication(tree, options) {
|
|
@@ -226,7 +221,6 @@ async function addLintingToApplication(tree, options) {
|
|
|
226
221
|
],
|
|
227
222
|
unitTestRunner: options.testRunner ?? 'jest',
|
|
228
223
|
enableTypedLinting: false,
|
|
229
|
-
addPlugin: options.addPlugin,
|
|
230
224
|
});
|
|
231
225
|
}
|
|
232
226
|
function updatePluginPackageJson(tree, options) {
|
|
@@ -239,7 +233,6 @@ function updatePluginPackageJson(tree, options) {
|
|
|
239
233
|
}
|
|
240
234
|
async function e2eProjectGenerator(host, schema) {
|
|
241
235
|
return await e2eProjectGeneratorInternal(host, {
|
|
242
|
-
addPlugin: false,
|
|
243
236
|
useProjectJson: true,
|
|
244
237
|
...schema,
|
|
245
238
|
});
|
|
@@ -58,7 +58,7 @@ function createTestProject() {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
execSync(
|
|
61
|
-
`<%= packageManagerCommands.dlx %> create-nx-workspace@latest ${projectName} --preset apps --nxCloud=skip --no-interactive
|
|
61
|
+
`<%= packageManagerCommands.dlx %> create-nx-workspace@latest ${projectName} --preset apps --nxCloud=skip --no-interactive --packageManager=<%= packageManager %>`,
|
|
62
62
|
{
|
|
63
63
|
cwd: dirname(projectDirectory),
|
|
64
64
|
stdio: 'inherit',
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { PackageManager } from '@nx/devkit';
|
|
1
2
|
import type { LinterType } from '@nx/js';
|
|
2
3
|
|
|
3
4
|
export interface Schema {
|
|
4
5
|
pluginName: string;
|
|
5
6
|
npmPackageName: string;
|
|
7
|
+
packageManager?: PackageManager;
|
|
6
8
|
projectDirectory?: string;
|
|
7
9
|
pluginOutputPath?: string;
|
|
8
10
|
jestConfig?: string;
|
|
@@ -11,5 +13,4 @@ export interface Schema {
|
|
|
11
13
|
skipFormat?: boolean;
|
|
12
14
|
rootProject?: boolean;
|
|
13
15
|
useProjectJson?: boolean;
|
|
14
|
-
addPlugin?: boolean;
|
|
15
16
|
}
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
"description": "the package name of the plugin as it would be published to NPM.",
|
|
18
18
|
"x-priority": "important"
|
|
19
19
|
},
|
|
20
|
+
"packageManager": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"enum": ["npm", "pnpm", "yarn", "bun"],
|
|
23
|
+
"description": "Package manager the generated e2e test uses to create the test workspace, install the plugin and run its checks. Defaults to the package manager the workspace already uses."
|
|
24
|
+
},
|
|
20
25
|
"projectDirectory": {
|
|
21
26
|
"type": "string",
|
|
22
27
|
"description": "the directory where the plugin is placed."
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Schema as EsLintExecutorOptions } from '@nx/eslint/internal';
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
3
2
|
import { PluginLintChecksGeneratorSchema } from './schema';
|
|
4
3
|
import { PackageJson } from '@nx/devkit/internal';
|
|
5
4
|
export default function pluginLintCheckGenerator(host: Tree, options: PluginLintChecksGeneratorSchema): Promise<void>;
|
|
6
5
|
export declare function addMigrationJsonChecks(host: Tree, options: PluginLintChecksGeneratorSchema, packageJson: PackageJson): void;
|
|
7
|
-
export declare function getEsLintOptions(project: ProjectConfiguration): [target: string, configuration: TargetConfiguration<EsLintExecutorOptions>];
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = pluginLintCheckGenerator;
|
|
4
4
|
exports.addMigrationJsonChecks = addMigrationJsonChecks;
|
|
5
|
-
exports.getEsLintOptions = getEsLintOptions;
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const internal_1 = require("@nx/eslint/internal");
|
|
8
7
|
const internal_2 = require("@nx/devkit/internal");
|
|
@@ -13,7 +12,6 @@ async function pluginLintCheckGenerator(host, options) {
|
|
|
13
12
|
if (projectIsEsLintEnabled(host, project)) {
|
|
14
13
|
updateRootEslintConfig(host);
|
|
15
14
|
updateProjectEslintConfig(host, project, packageJson);
|
|
16
|
-
updateProjectTarget(host, options, packageJson);
|
|
17
15
|
// Project is setup for vscode
|
|
18
16
|
if (host.exists('.vscode')) {
|
|
19
17
|
setupVsCodeLintingForJsonFiles(host);
|
|
@@ -31,21 +29,10 @@ function addMigrationJsonChecks(host, options, packageJson) {
|
|
|
31
29
|
if (!projectIsEsLintEnabled(host, projectConfiguration)) {
|
|
32
30
|
return;
|
|
33
31
|
}
|
|
34
|
-
const [eslintTarget, eslintTargetConfiguration] = getEsLintOptions(projectConfiguration) ?? [];
|
|
35
32
|
const relativeMigrationsJsonPath = (0, internal_2.readNxMigrateConfig)(packageJson).migrations;
|
|
36
33
|
if (!relativeMigrationsJsonPath) {
|
|
37
34
|
return;
|
|
38
35
|
}
|
|
39
|
-
const migrationsJsonPath = (0, devkit_1.joinPathFragments)(projectConfiguration.root, relativeMigrationsJsonPath);
|
|
40
|
-
if (!eslintTarget) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
// Add path to lintFilePatterns if different than default "{projectRoot}"
|
|
44
|
-
if (eslintTargetConfiguration.options?.lintFilePatterns &&
|
|
45
|
-
!eslintTargetConfiguration.options.lintFilePatterns.includes(migrationsJsonPath)) {
|
|
46
|
-
eslintTargetConfiguration.options.lintFilePatterns.push(migrationsJsonPath);
|
|
47
|
-
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfiguration);
|
|
48
|
-
}
|
|
49
36
|
// Update project level eslintrc
|
|
50
37
|
(0, internal_1.updateOverrideInLintConfig)(host, projectConfiguration.root, (o) => Object.keys(o.rules ?? {})?.includes('@nx/nx-plugin-checks') ||
|
|
51
38
|
Object.keys(o.rules ?? {})?.includes('@nrwl/nx/nx-plugin-checks'), (o) => {
|
|
@@ -67,57 +54,6 @@ function formatFilesEntries(tree, files) {
|
|
|
67
54
|
});
|
|
68
55
|
return filesAfter;
|
|
69
56
|
}
|
|
70
|
-
function updateProjectTarget(host, options, packageJson) {
|
|
71
|
-
const project = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
72
|
-
if (!project.targets) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
for (const [target, configuration] of Object.entries(project.targets)) {
|
|
76
|
-
if (configuration.executor === '@nx/eslint:lint' &&
|
|
77
|
-
// only add patterns if there are already hardcoded ones
|
|
78
|
-
configuration.options?.lintFilePatterns) {
|
|
79
|
-
const opts = configuration.options ?? {};
|
|
80
|
-
opts.lintFilePatterns ??= [];
|
|
81
|
-
if (packageJson.generators) {
|
|
82
|
-
opts.lintFilePatterns.push((0, devkit_1.joinPathFragments)(project.root, packageJson.generators));
|
|
83
|
-
}
|
|
84
|
-
if (packageJson.schematics &&
|
|
85
|
-
packageJson.schematics !== packageJson.generators) {
|
|
86
|
-
opts.lintFilePatterns.push((0, devkit_1.joinPathFragments)(project.root, packageJson.schematics));
|
|
87
|
-
}
|
|
88
|
-
if (packageJson.executors) {
|
|
89
|
-
opts.lintFilePatterns.push((0, devkit_1.joinPathFragments)(project.root, packageJson.executors));
|
|
90
|
-
}
|
|
91
|
-
if (packageJson.builders &&
|
|
92
|
-
packageJson.builders !== packageJson.executors) {
|
|
93
|
-
opts.lintFilePatterns.push((0, devkit_1.joinPathFragments)(project.root, packageJson.builders));
|
|
94
|
-
}
|
|
95
|
-
opts.lintFilePatterns.push(`${project.root}/package.json`);
|
|
96
|
-
opts.lintFilePatterns = [...new Set(opts.lintFilePatterns)];
|
|
97
|
-
project.targets[target].options = opts;
|
|
98
|
-
// Plugin checks read schema/implementation files which may live in the
|
|
99
|
-
// project's build outputs (and migration prompt files copied as assets).
|
|
100
|
-
// Ensure lint runs after build and includes the relevant build outputs
|
|
101
|
-
// as inputs so the sandbox allows the reads and the cache invalidates
|
|
102
|
-
// when those outputs change.
|
|
103
|
-
const targetConfig = project.targets[target];
|
|
104
|
-
const dependsOn = new Set(targetConfig.dependsOn ?? []);
|
|
105
|
-
dependsOn.add('build');
|
|
106
|
-
targetConfig.dependsOn = Array.from(dependsOn);
|
|
107
|
-
const inputs = targetConfig.inputs ?? ['...'];
|
|
108
|
-
const hasDependentOutputs = inputs.some((input) => typeof input === 'object' &&
|
|
109
|
-
input !== null &&
|
|
110
|
-
'dependentTasksOutputFiles' in input);
|
|
111
|
-
if (!hasDependentOutputs) {
|
|
112
|
-
inputs.push({
|
|
113
|
-
dependentTasksOutputFiles: '**/*.{json,d.ts,js,md}',
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
targetConfig.inputs = inputs;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, project);
|
|
120
|
-
}
|
|
121
57
|
function updateProjectEslintConfig(host, options, packageJson) {
|
|
122
58
|
if ((0, internal_1.isEslintConfigSupported)(host, options.root)) {
|
|
123
59
|
const lookup = (o) => Object.keys(o.rules ?? {}).includes('@nx/nx-plugin-checks') ||
|
|
@@ -206,8 +142,3 @@ function setupVsCodeLintingForJsonFiles(host) {
|
|
|
206
142
|
function projectIsEsLintEnabled(tree, project) {
|
|
207
143
|
return !!(0, internal_1.findEslintFile)(tree, project.root);
|
|
208
144
|
}
|
|
209
|
-
function getEsLintOptions(project) {
|
|
210
|
-
return Object.entries(project.targets || {}).find(([, x]) => x.executor === '@nx/eslint:lint' ||
|
|
211
|
-
x.executor === '@nx/linter:eslint' ||
|
|
212
|
-
x.executor === '@nrwl/linter:eslint');
|
|
213
|
-
}
|
|
@@ -5,6 +5,7 @@ exports.pluginGeneratorInternal = pluginGeneratorInternal;
|
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
|
7
7
|
const internal_1 = require("@nx/devkit/internal");
|
|
8
|
+
const jest_1 = require("@nx/jest");
|
|
8
9
|
const js_1 = require("@nx/js");
|
|
9
10
|
const internal_2 = require("@nx/js/internal");
|
|
10
11
|
const path = tslib_1.__importStar(require("path"));
|
|
@@ -42,7 +43,6 @@ function updatePluginConfig(host, options) {
|
|
|
42
43
|
async function pluginGenerator(tree, schema) {
|
|
43
44
|
return await pluginGeneratorInternal(tree, {
|
|
44
45
|
useProjectJson: true,
|
|
45
|
-
addPlugin: false,
|
|
46
46
|
...schema,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
@@ -60,7 +60,6 @@ async function pluginGeneratorInternal(host, schema) {
|
|
|
60
60
|
linter: options.linter,
|
|
61
61
|
unitTestRunner: options.unitTestRunner,
|
|
62
62
|
useProjectJson: options.useProjectJson,
|
|
63
|
-
addPlugin: options.addPlugin,
|
|
64
63
|
skipFormat: true,
|
|
65
64
|
useTscExecutor: true,
|
|
66
65
|
}));
|
|
@@ -106,6 +105,13 @@ async function pluginGeneratorInternal(host, schema) {
|
|
|
106
105
|
tasks.push((0, internal_2.addSwcRegisterDependencies)(host));
|
|
107
106
|
await addFiles(host, options);
|
|
108
107
|
updatePluginConfig(host, options);
|
|
108
|
+
if (options.unitTestRunner === 'jest') {
|
|
109
|
+
// addFiles removes src/lib and its spec, so a fresh plugin has no tests yet.
|
|
110
|
+
const jestConfig = (0, jest_1.findJestConfig)(host, options.projectRoot);
|
|
111
|
+
if (jestConfig) {
|
|
112
|
+
(0, jest_1.addPropertyToJestConfig)(host, jestConfig, 'passWithNoTests', true);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
109
115
|
if (options.e2eTestRunner !== 'none') {
|
|
110
116
|
tasks.push(await (0, e2e_1.e2eProjectGenerator)(host, {
|
|
111
117
|
pluginName: options.projectName,
|
|
@@ -116,7 +122,6 @@ async function pluginGeneratorInternal(host, schema) {
|
|
|
116
122
|
rootProject: options.rootProject,
|
|
117
123
|
linter: options.linter,
|
|
118
124
|
useProjectJson: options.useProjectJson,
|
|
119
|
-
addPlugin: options.addPlugin,
|
|
120
125
|
testRunner: options.e2eTestRunner,
|
|
121
126
|
}));
|
|
122
127
|
}
|
|
@@ -13,13 +13,8 @@ export interface Schema {
|
|
|
13
13
|
unitTestRunner?: 'jest' | 'vitest' | 'none';
|
|
14
14
|
linter?: LinterType;
|
|
15
15
|
enableTypedLinting?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated Use `enableTypedLinting` instead. This option will be removed in Nx v24.
|
|
18
|
-
*/
|
|
19
|
-
setParserOptionsProject?: boolean;
|
|
20
16
|
compiler?: 'swc' | 'tsc';
|
|
21
17
|
rootProject?: boolean;
|
|
22
18
|
publishable?: boolean;
|
|
23
19
|
useProjectJson?: boolean;
|
|
24
|
-
addPlugin?: boolean;
|
|
25
20
|
}
|
|
@@ -80,12 +80,6 @@
|
|
|
80
80
|
"description": "Whether to enable typed linting. For flat configs, this configures the recommended `parserOptions.projectService` and `tsconfigRootDir`. For legacy `.eslintrc` configs, this configures `parserOptions.project`. We do not enable this by default for lint performance reasons.",
|
|
81
81
|
"default": false
|
|
82
82
|
},
|
|
83
|
-
"setParserOptionsProject": {
|
|
84
|
-
"type": "boolean",
|
|
85
|
-
"description": "Deprecated alias for `enableTypedLinting`.",
|
|
86
|
-
"default": false,
|
|
87
|
-
"x-deprecated": "Use `enableTypedLinting` instead. This option will be removed in Nx v24."
|
|
88
|
-
},
|
|
89
83
|
"compiler": {
|
|
90
84
|
"type": "string",
|
|
91
85
|
"enum": ["tsc", "swc"],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Tree } from '@nx/devkit';
|
|
2
2
|
import type { LinterType } from '@nx/js';
|
|
3
3
|
import type { Schema } from '../schema';
|
|
4
4
|
export interface NormalizedSchema extends Schema {
|
|
@@ -14,7 +14,6 @@ export interface NormalizedSchema extends Schema {
|
|
|
14
14
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
15
15
|
linter: LinterType;
|
|
16
16
|
useProjectJson: boolean;
|
|
17
|
-
addPlugin: boolean;
|
|
18
17
|
isTsSolutionSetup: boolean;
|
|
19
18
|
}
|
|
20
19
|
export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeOptions = normalizeOptions;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
4
|
const internal_1 = require("@nx/devkit/internal");
|
|
6
5
|
const internal_2 = require("@nx/js/internal");
|
|
7
6
|
async function normalizeOptions(host, options) {
|
|
@@ -10,13 +9,7 @@ async function normalizeOptions(host, options) {
|
|
|
10
9
|
// this helper is called before the jsLibraryGenerator is called, so, if the
|
|
11
10
|
// TS solution setup is not configured, we additionally check if the TS
|
|
12
11
|
// solution setup will be configured by the jsLibraryGenerator
|
|
13
|
-
const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)(host) ||
|
|
14
|
-
(0, internal_2.shouldConfigureTsSolutionSetup)(host, options.addPlugin);
|
|
15
|
-
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
16
|
-
const addPlugin = options.addPlugin ??
|
|
17
|
-
(isTsSolutionSetup &&
|
|
18
|
-
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
19
|
-
nxJson.useInferencePlugins !== false);
|
|
12
|
+
const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)(host) || (0, internal_2.shouldConfigureTsSolutionSetup)(host);
|
|
20
13
|
await (0, internal_1.ensureRootProjectName)(options, 'library');
|
|
21
14
|
const { projectName, projectRoot, importPath } = await (0, internal_1.determineProjectNameAndRootOptions)(host, {
|
|
22
15
|
name: options.name,
|
|
@@ -45,7 +38,6 @@ async function normalizeOptions(host, options) {
|
|
|
45
38
|
unitTestRunner,
|
|
46
39
|
// We default to generate a project.json file if the new setup is not being used
|
|
47
40
|
useProjectJson: options.useProjectJson ?? !isTsSolutionSetup,
|
|
48
|
-
addPlugin,
|
|
49
41
|
isTsSolutionSetup,
|
|
50
42
|
};
|
|
51
43
|
}
|
|
@@ -8,7 +8,6 @@ const plugin_1 = require("../plugin/plugin");
|
|
|
8
8
|
const internal_1 = require("@nx/js/internal");
|
|
9
9
|
async function presetGenerator(tree, rawOptions) {
|
|
10
10
|
return await presetGeneratorInternal(tree, {
|
|
11
|
-
addPlugin: false,
|
|
12
11
|
useProjectJson: true,
|
|
13
12
|
...rawOptions,
|
|
14
13
|
});
|
|
@@ -30,7 +29,6 @@ async function presetGeneratorInternal(tree, rawOptions) {
|
|
|
30
29
|
: options.pluginName,
|
|
31
30
|
rootProject: options.createPackageName ? false : true,
|
|
32
31
|
useProjectJson: options.useProjectJson,
|
|
33
|
-
addPlugin: options.addPlugin,
|
|
34
32
|
});
|
|
35
33
|
tasks.push(pluginTask);
|
|
36
34
|
moveNxPluginToDevDeps(tree);
|
|
@@ -46,7 +44,6 @@ async function presetGeneratorInternal(tree, rawOptions) {
|
|
|
46
44
|
linter: options.linter,
|
|
47
45
|
compiler: 'tsc',
|
|
48
46
|
useProjectJson: options.useProjectJson,
|
|
49
|
-
addPlugin: options.addPlugin,
|
|
50
47
|
});
|
|
51
48
|
tasks.push(cliTask);
|
|
52
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/plugin",
|
|
3
|
-
"version": "24.0.0-
|
|
3
|
+
"version": "24.0.0-rc.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "This plugin is used to create Nx plugins! It contains generators for generating common plugin features like generators, executors, migrations and more.",
|
|
6
6
|
"repository": {
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"tslib": "^2.3.0",
|
|
39
|
-
"@nx/devkit": "24.0.0-
|
|
40
|
-
"@nx/jest": "24.0.0-
|
|
41
|
-
"@nx/js": "24.0.0-
|
|
42
|
-
"@nx/eslint": "24.0.0-
|
|
39
|
+
"@nx/devkit": "24.0.0-rc.0",
|
|
40
|
+
"@nx/jest": "24.0.0-rc.0",
|
|
41
|
+
"@nx/js": "24.0.0-rc.0",
|
|
42
|
+
"@nx/eslint": "24.0.0-rc.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"nx": "24.0.0-
|
|
45
|
+
"nx": "24.0.0-rc.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@nx/vitest": "24.0.0-
|
|
48
|
+
"@nx/vitest": "24.0.0-rc.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"@nx/vitest": {
|