@nx/js 21.2.0 → 21.2.1
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/executors.json +5 -0
- package/package.json +3 -3
- package/src/executors/copy-workspace-modules/copy-workspace-modules.d.ts +5 -0
- package/src/executors/copy-workspace-modules/copy-workspace-modules.js +91 -0
- package/src/executors/copy-workspace-modules/schema.d.ts +4 -0
- package/src/executors/copy-workspace-modules/schema.json +20 -0
- package/src/executors/release-publish/release-publish.impl.js +2 -7
- package/src/utils/package-json/get-workspace-packages-from-graph.d.ts +2 -0
- package/src/utils/package-json/get-workspace-packages-from-graph.js +13 -0
package/executors.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"executors": {
|
|
4
|
+
"copy-workspace-modules": {
|
|
5
|
+
"implementation": "./src/executors/copy-workspace-modules/copy-workspace-modules",
|
|
6
|
+
"schema": "./src/executors/copy-workspace-modules/schema.json",
|
|
7
|
+
"description": "Copies Workspace Modules into the output directory after a build to prepare it for use with Docker or alternatives."
|
|
8
|
+
},
|
|
4
9
|
"tsc": {
|
|
5
10
|
"implementation": "./src/executors/tsc/tsc.impl",
|
|
6
11
|
"batchImplementation": "./src/executors/tsc/tsc.batch-impl",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "21.2.
|
|
3
|
+
"version": "21.2.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
|
|
6
6
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.23.2",
|
|
40
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
41
41
|
"@babel/runtime": "^7.22.6",
|
|
42
|
-
"@nx/devkit": "21.2.
|
|
43
|
-
"@nx/workspace": "21.2.
|
|
42
|
+
"@nx/devkit": "21.2.1",
|
|
43
|
+
"@nx/workspace": "21.2.1",
|
|
44
44
|
"@zkochan/js-yaml": "0.0.7",
|
|
45
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
46
46
|
"babel-plugin-macros": "^3.1.0",
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = copyWorkspaceModules;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const get_workspace_packages_from_graph_1 = require("../../utils/package-json/get-workspace-packages-from-graph");
|
|
10
|
+
async function copyWorkspaceModules(schema, context) {
|
|
11
|
+
devkit_1.logger.log('Copying Workspace Modules to Build Directory...');
|
|
12
|
+
const outputDirectory = getOutputDir(schema, context);
|
|
13
|
+
const packageJson = getPackageJson(schema, context);
|
|
14
|
+
createWorkspaceModules(outputDirectory);
|
|
15
|
+
handleWorkspaceModules(outputDirectory, packageJson, context.projectGraph);
|
|
16
|
+
devkit_1.logger.log('Success!');
|
|
17
|
+
return { success: true };
|
|
18
|
+
}
|
|
19
|
+
function handleWorkspaceModules(outputDirectory, packageJson, projectGraph) {
|
|
20
|
+
if (!packageJson.dependencies) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const workspaceModules = (0, get_workspace_packages_from_graph_1.getWorkspacePackagesFromGraph)(projectGraph);
|
|
24
|
+
for (const [pkgName] of Object.entries(packageJson.dependencies)) {
|
|
25
|
+
if (workspaceModules.has(pkgName)) {
|
|
26
|
+
devkit_1.logger.verbose(`Copying ${pkgName}.`);
|
|
27
|
+
const workspaceModuleProject = workspaceModules.get(pkgName);
|
|
28
|
+
const workspaceModuleRoot = workspaceModuleProject.data.root;
|
|
29
|
+
const newWorkspaceModulePath = (0, path_1.join)(outputDirectory, 'workspace_modules', pkgName);
|
|
30
|
+
(0, node_fs_1.mkdirSync)(newWorkspaceModulePath, { recursive: true });
|
|
31
|
+
(0, node_fs_1.cpSync)(workspaceModuleRoot, newWorkspaceModulePath, {
|
|
32
|
+
filter: (src) => !src.includes('node_modules'),
|
|
33
|
+
recursive: true,
|
|
34
|
+
});
|
|
35
|
+
devkit_1.logger.verbose(`Copied ${pkgName} successfully.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function createWorkspaceModules(outputDirectory) {
|
|
40
|
+
(0, node_fs_1.mkdirSync)((0, path_1.join)(outputDirectory, 'workspace_modules'), { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
function getPackageJson(schema, context) {
|
|
43
|
+
const target = (0, devkit_1.parseTargetString)(schema.buildTarget, context);
|
|
44
|
+
const project = context.projectGraph.nodes[target.project].data;
|
|
45
|
+
const packageJsonPath = (0, path_1.join)(devkit_1.workspaceRoot, project.root, 'package.json');
|
|
46
|
+
if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
47
|
+
throw new Error(`${packageJsonPath} does not exist.`);
|
|
48
|
+
}
|
|
49
|
+
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
50
|
+
return packageJson;
|
|
51
|
+
}
|
|
52
|
+
function getOutputDir(schema, context) {
|
|
53
|
+
let outputDir = schema.outputPath;
|
|
54
|
+
if (outputDir) {
|
|
55
|
+
outputDir = normalizeOutputPath(outputDir);
|
|
56
|
+
if ((0, node_fs_1.existsSync)(outputDir)) {
|
|
57
|
+
return outputDir;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const target = (0, devkit_1.parseTargetString)(schema.buildTarget, context);
|
|
61
|
+
const project = context.projectGraph.nodes[target.project].data;
|
|
62
|
+
const buildTarget = project.targets[target.target];
|
|
63
|
+
let maybeOutputPath = buildTarget.outputs?.[0] ??
|
|
64
|
+
buildTarget.options.outputPath ??
|
|
65
|
+
buildTarget.options.outputDir;
|
|
66
|
+
if (!maybeOutputPath) {
|
|
67
|
+
throw new Error(`Could not infer an output directory from the '${schema.buildTarget}' target. Please provide 'outputPath'.`);
|
|
68
|
+
}
|
|
69
|
+
maybeOutputPath = (0, utils_1.interpolate)(maybeOutputPath, {
|
|
70
|
+
workspaceRoot: devkit_1.workspaceRoot,
|
|
71
|
+
projectRoot: project.root,
|
|
72
|
+
projectName: project.name,
|
|
73
|
+
options: {
|
|
74
|
+
...(buildTarget.options ?? {}),
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
outputDir = normalizeOutputPath(maybeOutputPath);
|
|
78
|
+
if (!(0, node_fs_1.existsSync)(outputDir)) {
|
|
79
|
+
throw new Error(`The output directory '${outputDir}' inferred from the '${schema.buildTarget}' target does not exist.\nPlease ensure a build has run first, and that the path is correct. Otherwise, please provide 'outputPath'.`);
|
|
80
|
+
}
|
|
81
|
+
return outputDir;
|
|
82
|
+
}
|
|
83
|
+
function normalizeOutputPath(outputPath) {
|
|
84
|
+
if (!outputPath.startsWith(devkit_1.workspaceRoot)) {
|
|
85
|
+
outputPath = (0, path_1.join)(devkit_1.workspaceRoot, outputPath);
|
|
86
|
+
}
|
|
87
|
+
if (!(0, fs_1.lstatSync)(outputPath).isDirectory()) {
|
|
88
|
+
outputPath = (0, path_1.dirname)(outputPath);
|
|
89
|
+
}
|
|
90
|
+
return outputPath;
|
|
91
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"outputCapture": "direct-nodejs",
|
|
4
|
+
"title": "Copy Workspace Modules",
|
|
5
|
+
"description": "Copies Workspace Modules into the output directory after a build to prepare it for use with Docker or alternatives.",
|
|
6
|
+
"cli": "nx",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"buildTarget": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The build target that produces the output directory to transform.",
|
|
12
|
+
"default": "build"
|
|
13
|
+
},
|
|
14
|
+
"outputPath": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "The output path to transform. Usually inferred from the outputs of the buildTarget."
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"required": ["buildTarget"]
|
|
20
|
+
}
|
|
@@ -201,14 +201,9 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
|
|
|
201
201
|
* to running from the package root directly), then special attention should be paid to the fact that npm/pnpm publish will nest its
|
|
202
202
|
* JSON output under the name of the package in that case (and it would need to be handled below).
|
|
203
203
|
*/
|
|
204
|
+
const pmCommand = (0, devkit_1.getPackageManagerCommand)(pm);
|
|
204
205
|
const publishCommandSegments = [
|
|
205
|
-
|
|
206
|
-
? // Unlike npm, bun publish does not support a custom registryConfigKey option
|
|
207
|
-
`bun publish --cwd="${packageRoot}" --json --registry="${registry}" --tag=${tag}`
|
|
208
|
-
: pm === 'pnpm'
|
|
209
|
-
? // Unlike npm, pnpm publish does not support a custom registryConfigKey option, and will error on uncommitted changes by default if --no-git-checks is not set
|
|
210
|
-
`pnpm publish "${packageRoot}" --json --registry="${registry}" --tag=${tag} --no-git-checks`
|
|
211
|
-
: `npm publish "${packageRoot}" --json --"${registryConfigKey}=${registry}" --tag=${tag}`,
|
|
206
|
+
pmCommand.publish(packageRoot, registry, registryConfigKey, tag),
|
|
212
207
|
];
|
|
213
208
|
if (options.otp) {
|
|
214
209
|
publishCommandSegments.push(`--otp=${options.otp}`);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWorkspacePackagesFromGraph = getWorkspacePackagesFromGraph;
|
|
4
|
+
function getWorkspacePackagesFromGraph(graph) {
|
|
5
|
+
const workspacePackages = new Map();
|
|
6
|
+
for (const [projectName, project] of Object.entries(graph.nodes)) {
|
|
7
|
+
const pkgName = project.data?.metadata?.js?.packageName;
|
|
8
|
+
if (pkgName) {
|
|
9
|
+
workspacePackages.set(pkgName, project);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return workspacePackages;
|
|
13
|
+
}
|