@nx/js 21.2.0 → 21.2.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/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/generators/library/library.js +4 -4
- package/src/plugins/typescript/util.js +89 -12
- package/src/utils/assets/copy-assets-handler.js +5 -2
- 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.2",
|
|
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.2",
|
|
43
|
+
"@nx/workspace": "21.2.2",
|
|
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}`);
|
|
@@ -384,14 +384,14 @@ function createFiles(tree, options) {
|
|
|
384
384
|
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
|
385
385
|
});
|
|
386
386
|
}
|
|
387
|
-
if (options.
|
|
387
|
+
if (options.includeBabelRc) {
|
|
388
|
+
addBabelRc(tree, options);
|
|
389
|
+
}
|
|
390
|
+
else if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
388
391
|
(0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' && !options.isUsingTsSolutionConfig
|
|
389
392
|
? 'commonjs'
|
|
390
393
|
: 'es6');
|
|
391
394
|
}
|
|
392
|
-
else if (options.includeBabelRc) {
|
|
393
|
-
addBabelRc(tree, options);
|
|
394
|
-
}
|
|
395
395
|
if (options.unitTestRunner === 'none') {
|
|
396
396
|
tree.delete((0, path_1.join)(options.projectRoot, 'src/lib', `${options.fileName}.spec.ts`));
|
|
397
397
|
tree.delete((0, path_1.join)(options.projectRoot, 'src/app', `${options.fileName}.spec.ts`));
|
|
@@ -6,6 +6,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
+
const picomatch = require("picomatch");
|
|
9
10
|
/**
|
|
10
11
|
* Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
|
|
11
12
|
*/
|
|
@@ -46,22 +47,98 @@ function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
|
|
|
46
47
|
return true;
|
|
47
48
|
}
|
|
48
49
|
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
:
|
|
50
|
+
const projectAbsolutePath = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath);
|
|
51
|
+
// Handle outFile first (has precedence over outDir)
|
|
52
|
+
if (tsConfig.options.outFile) {
|
|
53
|
+
const outFile = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, tsConfig.options.outFile);
|
|
54
|
+
const relativeToProject = (0, node_path_1.relative)(projectAbsolutePath, outFile);
|
|
55
|
+
// If outFile is outside project root: buildable
|
|
56
|
+
if (relativeToProject.startsWith('..')) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
// If outFile is inside project root: check if entry points point to outFile
|
|
60
|
+
const isPathSourceFile = (path) => {
|
|
61
|
+
const normalizedPath = (0, node_path_1.isAbsolute)(path)
|
|
62
|
+
? (0, node_path_1.resolve)(workspaceRoot, path.startsWith('/') ? path.slice(1) : path)
|
|
63
|
+
: (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
|
|
64
|
+
// For outFile case, check if path points to the specific outFile
|
|
65
|
+
return normalizedPath === outFile;
|
|
66
|
+
};
|
|
67
|
+
// Check if any entry points match the outFile
|
|
68
|
+
const exports = packageJson?.exports;
|
|
69
|
+
if (exports) {
|
|
70
|
+
if (typeof exports === 'string') {
|
|
71
|
+
return !isPathSourceFile(exports);
|
|
72
|
+
}
|
|
73
|
+
if (typeof exports === 'object' && '.' in exports) {
|
|
74
|
+
const dotExport = exports['.'];
|
|
75
|
+
if (typeof dotExport === 'string') {
|
|
76
|
+
return !isPathSourceFile(dotExport);
|
|
77
|
+
}
|
|
78
|
+
else if (typeof dotExport === 'object') {
|
|
79
|
+
const hasMatch = Object.entries(dotExport).some(([key, value]) => {
|
|
80
|
+
if (key === 'types' || key === 'development')
|
|
81
|
+
return false;
|
|
82
|
+
return typeof value === 'string' && isPathSourceFile(value);
|
|
83
|
+
});
|
|
84
|
+
return !hasMatch;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const buildPaths = ['main', 'module'];
|
|
89
|
+
for (const field of buildPaths) {
|
|
90
|
+
if (packageJson[field] && isPathSourceFile(packageJson[field])) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
// Handle outDir
|
|
97
|
+
const outDir = tsConfig.options.outDir;
|
|
98
|
+
let resolvedOutDir;
|
|
99
|
+
if (outDir) {
|
|
100
|
+
const potentialOutDir = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, outDir);
|
|
101
|
+
const relativePath = (0, node_path_1.relative)(projectAbsolutePath, potentialOutDir);
|
|
102
|
+
// If outDir is outside project root: buildable
|
|
103
|
+
if (relativePath.startsWith('..')) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
// If outDir is inside project root, then we should check entry points
|
|
107
|
+
if (!relativePath.startsWith('..')) {
|
|
108
|
+
resolvedOutDir = potentialOutDir;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
55
111
|
const isPathSourceFile = (path) => {
|
|
112
|
+
const normalizedPath = (0, node_path_1.isAbsolute)(path)
|
|
113
|
+
? (0, node_path_1.resolve)(workspaceRoot, path.startsWith('/') ? path.slice(1) : path)
|
|
114
|
+
: (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
|
|
56
115
|
if (resolvedOutDir) {
|
|
57
|
-
|
|
58
|
-
|
|
116
|
+
// If the path is within the outDir, we assume it's not a source file.
|
|
117
|
+
const relativePath = (0, node_path_1.relative)(resolvedOutDir, normalizedPath);
|
|
118
|
+
if (!relativePath.startsWith('..')) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
59
121
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
122
|
+
// If no include patterns, TypeScript includes all TS files by default
|
|
123
|
+
const include = tsConfig.raw?.include;
|
|
124
|
+
if (!include || !Array.isArray(include)) {
|
|
125
|
+
const ext = (0, node_path_1.extname)(path);
|
|
126
|
+
const tsExtensions = ['.ts', '.tsx', '.cts', '.mts'];
|
|
127
|
+
if (tsExtensions.includes(ext)) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
// If include is not defined and it's not a TS file, assume it's not a source file
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
const projectAbsolutePath = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath);
|
|
134
|
+
const relativeToProject = (0, node_path_1.relative)(projectAbsolutePath, normalizedPath);
|
|
135
|
+
for (const pattern of include) {
|
|
136
|
+
if (picomatch(pattern)(relativeToProject)) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
63
141
|
};
|
|
64
|
-
// Checks if the value is a path within the `src` directory.
|
|
65
142
|
const containsInvalidPath = (value) => {
|
|
66
143
|
if (typeof value === 'string') {
|
|
67
144
|
return isPathSourceFile(value);
|
|
@@ -52,16 +52,19 @@ class CopyAssetsHandler {
|
|
|
52
52
|
let input;
|
|
53
53
|
let output;
|
|
54
54
|
let ignore = null;
|
|
55
|
+
const resolvedOutputDir = path.isAbsolute(opts.outputDir)
|
|
56
|
+
? opts.outputDir
|
|
57
|
+
: path.resolve(opts.rootDir, opts.outputDir);
|
|
55
58
|
if (typeof f === 'string') {
|
|
56
59
|
pattern = f;
|
|
57
60
|
input = path.relative(opts.rootDir, opts.projectDir);
|
|
58
|
-
output = path.relative(opts.rootDir,
|
|
61
|
+
output = path.relative(opts.rootDir, resolvedOutputDir);
|
|
59
62
|
}
|
|
60
63
|
else {
|
|
61
64
|
isGlob = true;
|
|
62
65
|
pattern = pathPosix.join(f.input, f.glob);
|
|
63
66
|
input = f.input;
|
|
64
|
-
output = pathPosix.join(path.relative(opts.rootDir,
|
|
67
|
+
output = pathPosix.join(path.relative(opts.rootDir, resolvedOutputDir), f.output);
|
|
65
68
|
if (f.ignore)
|
|
66
69
|
ignore = f.ignore.map((ig) => pathPosix.join(f.input, ig));
|
|
67
70
|
}
|
|
@@ -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
|
+
}
|