@nx/plugin 24.0.0-beta.0 → 24.0.0-beta.2
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/files/create-framework-package/bin/index.ts__tmpl__ +65 -2
- package/dist/src/generators/e2e-project/e2e.js +5 -1
- package/dist/src/generators/e2e-project/files/src/__simplePluginName__.spec.ts__tmpl__ +1 -1
- package/dist/src/generators/e2e-project/schema.d.ts +2 -0
- package/dist/src/generators/e2e-project/schema.json +5 -0
- package/package.json +7 -7
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
|
|
|
@@ -50,11 +50,15 @@ function addFiles(host, options) {
|
|
|
50
50
|
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(host, options.pluginName);
|
|
51
51
|
const { name: pluginPackageName } = (0, devkit_1.readJson)(host, (0, path_1.join)(projectConfiguration.root, 'package.json'));
|
|
52
52
|
const simplePluginName = options.pluginName.split('/').pop();
|
|
53
|
+
// One manager drives workspace creation, the install and the checks, so the
|
|
54
|
+
// generated e2e test cannot straddle two.
|
|
55
|
+
const packageManager = options.packageManager ?? (0, devkit_1.detectPackageManager)();
|
|
53
56
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.projectRoot, {
|
|
54
57
|
...options,
|
|
55
58
|
tmpl: '',
|
|
56
59
|
rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
|
|
57
|
-
packageManagerCommands: (0, devkit_1.getPackageManagerCommand)(),
|
|
60
|
+
packageManagerCommands: (0, devkit_1.getPackageManagerCommand)(packageManager),
|
|
61
|
+
packageManager,
|
|
58
62
|
pluginPackageName,
|
|
59
63
|
simplePluginName,
|
|
60
64
|
});
|
|
@@ -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;
|
|
@@ -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."
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/plugin",
|
|
3
|
-
"version": "24.0.0-beta.
|
|
3
|
+
"version": "24.0.0-beta.2",
|
|
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-beta.
|
|
40
|
-
"@nx/jest": "24.0.0-beta.
|
|
41
|
-
"@nx/js": "24.0.0-beta.
|
|
42
|
-
"@nx/eslint": "24.0.0-beta.
|
|
39
|
+
"@nx/devkit": "24.0.0-beta.2",
|
|
40
|
+
"@nx/jest": "24.0.0-beta.2",
|
|
41
|
+
"@nx/js": "24.0.0-beta.2",
|
|
42
|
+
"@nx/eslint": "24.0.0-beta.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"nx": "24.0.0-beta.
|
|
45
|
+
"nx": "24.0.0-beta.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@nx/vitest": "24.0.0-beta.
|
|
48
|
+
"@nx/vitest": "24.0.0-beta.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"@nx/vitest": {
|