@nx/js 21.3.0-beta.6 → 21.3.0-canary.20250613-18155f4
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 +0 -10
- package/package.json +3 -3
- package/src/executors/release-publish/release-publish.impl.js +7 -2
- package/src/generators/library/library.js +4 -8
- package/src/generators/library/schema.json +1 -2
- package/src/generators/release-version/release-version.js +1 -2
- package/src/generators/setup-build/generator.js +2 -2
- package/src/plugins/typescript/util.js +12 -89
- package/src/utils/assets/copy-assets-handler.js +2 -5
- package/src/utils/inline.js +1 -2
- package/src/utils/typescript/ts-solution-setup.d.ts +2 -2
- package/src/utils/typescript/ts-solution-setup.js +5 -12
- package/src/executors/copy-workspace-modules/copy-workspace-modules.d.ts +0 -5
- package/src/executors/copy-workspace-modules/copy-workspace-modules.js +0 -92
- package/src/executors/copy-workspace-modules/schema.d.ts +0 -4
- package/src/executors/copy-workspace-modules/schema.json +0 -20
- package/src/executors/prune-lockfile/prune-lockfile.d.ts +0 -5
- package/src/executors/prune-lockfile/prune-lockfile.js +0 -95
- package/src/executors/prune-lockfile/schema.d.ts +0 -4
- package/src/executors/prune-lockfile/schema.json +0 -20
package/executors.json
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
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
|
-
},
|
|
9
4
|
"tsc": {
|
|
10
5
|
"implementation": "./src/executors/tsc/tsc.impl",
|
|
11
6
|
"batchImplementation": "./src/executors/tsc/tsc.batch-impl",
|
|
@@ -22,11 +17,6 @@
|
|
|
22
17
|
"schema": "./src/executors/node/schema.json",
|
|
23
18
|
"description": "Execute a Node application."
|
|
24
19
|
},
|
|
25
|
-
"prune-lockfile": {
|
|
26
|
-
"implementation": "./src/executors/prune-lockfile/prune-lockfile",
|
|
27
|
-
"schema": "./src/executors/prune-lockfile/schema.json",
|
|
28
|
-
"description": "Creates a pruned lockfile based on the project dependencies and places it into the output directory."
|
|
29
|
-
},
|
|
30
20
|
"release-publish": {
|
|
31
21
|
"implementation": "./src/executors/release-publish/release-publish.impl",
|
|
32
22
|
"schema": "./src/executors/release-publish/schema.json",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "21.3.0-
|
|
3
|
+
"version": "21.3.0-canary.20250613-18155f4",
|
|
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.3.0-
|
|
43
|
-
"@nx/workspace": "21.3.0-
|
|
42
|
+
"@nx/devkit": "21.3.0-canary.20250613-18155f4",
|
|
43
|
+
"@nx/workspace": "21.3.0-canary.20250613-18155f4",
|
|
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",
|
|
@@ -201,9 +201,14 @@ 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);
|
|
205
204
|
const publishCommandSegments = [
|
|
206
|
-
|
|
205
|
+
pm === 'bun'
|
|
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}`,
|
|
207
212
|
];
|
|
208
213
|
if (options.otp) {
|
|
209
214
|
publishCommandSegments.push(`--otp=${options.otp}`);
|
|
@@ -43,10 +43,6 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
43
43
|
formatter: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree) ? 'none' : 'prettier',
|
|
44
44
|
}));
|
|
45
45
|
const options = await normalizeOptions(tree, schema);
|
|
46
|
-
if (schema.simpleName !== undefined && schema.simpleName !== false) {
|
|
47
|
-
// TODO(v22): Remove simpleName as user should be using name.
|
|
48
|
-
devkit_1.logger.warn(`The "--simpleName" option is deprecated and will be removed in Nx 22. Please use the "--name" option to provide the exact name you want for the library.`);
|
|
49
|
-
}
|
|
50
46
|
createFiles(tree, options);
|
|
51
47
|
await configureProject(tree, options);
|
|
52
48
|
if (!options.skipPackageJson) {
|
|
@@ -388,14 +384,14 @@ function createFiles(tree, options) {
|
|
|
388
384
|
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
|
389
385
|
});
|
|
390
386
|
}
|
|
391
|
-
if (options.
|
|
392
|
-
addBabelRc(tree, options);
|
|
393
|
-
}
|
|
394
|
-
else if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
387
|
+
if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
395
388
|
(0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' && !options.isUsingTsSolutionConfig
|
|
396
389
|
? 'commonjs'
|
|
397
390
|
: 'es6');
|
|
398
391
|
}
|
|
392
|
+
else if (options.includeBabelRc) {
|
|
393
|
+
addBabelRc(tree, options);
|
|
394
|
+
}
|
|
399
395
|
if (options.unitTestRunner === 'none') {
|
|
400
396
|
tree.delete((0, path_1.join)(options.projectRoot, 'src/lib', `${options.fileName}.spec.ts`));
|
|
401
397
|
tree.delete((0, path_1.join)(options.projectRoot, 'src/app', `${options.fileName}.spec.ts`));
|
|
@@ -130,8 +130,7 @@
|
|
|
130
130
|
"simpleName": {
|
|
131
131
|
"description": "Don't include the directory in the generated file name.",
|
|
132
132
|
"type": "boolean",
|
|
133
|
-
"default": false
|
|
134
|
-
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
|
|
133
|
+
"default": false
|
|
135
134
|
},
|
|
136
135
|
"useProjectJson": {
|
|
137
136
|
"type": "boolean",
|
|
@@ -188,10 +188,9 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
188
188
|
// We always need to independently resolve the current version from git tag per project if the projects are independent
|
|
189
189
|
options.releaseGroup.projectsRelationship === 'independent') {
|
|
190
190
|
const releaseTagPattern = options.releaseGroup.releaseTagPattern;
|
|
191
|
-
const releaseTagPatternRequireSemver = options.releaseGroup.releaseTagPatternRequireSemver;
|
|
192
191
|
latestMatchingGitTag = await (0, git_1.getLatestGitTagForPattern)(releaseTagPattern, {
|
|
193
192
|
projectName: project.name,
|
|
194
|
-
}, options.releaseGroup.releaseTagPatternCheckAllBranchesWhen
|
|
193
|
+
}, options.releaseGroup.releaseTagPatternCheckAllBranchesWhen);
|
|
195
194
|
if (!latestMatchingGitTag) {
|
|
196
195
|
if (options.fallbackCurrentVersionResolver === 'disk') {
|
|
197
196
|
if (!currentVersionFromDisk &&
|
|
@@ -5,12 +5,12 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
6
6
|
const posix_1 = require("node:path/posix");
|
|
7
7
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
8
|
+
const plugin_1 = require("../../utils/typescript/plugin");
|
|
8
9
|
const get_import_path_1 = require("../../utils/get-import-path");
|
|
9
10
|
const update_package_json_1 = require("../../utils/package-json/update-package-json");
|
|
10
11
|
const add_swc_config_1 = require("../../utils/swc/add-swc-config");
|
|
11
12
|
const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
|
|
12
13
|
const ensure_typescript_1 = require("../../utils/typescript/ensure-typescript");
|
|
13
|
-
const plugin_1 = require("../../utils/typescript/plugin");
|
|
14
14
|
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
15
15
|
const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
|
|
16
16
|
const versions_1 = require("../../utils/versions");
|
|
@@ -29,7 +29,7 @@ async function setupBuildGenerator(tree, options) {
|
|
|
29
29
|
mainFile = options.main;
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
const root =
|
|
32
|
+
const root = project.sourceRoot ?? project.root;
|
|
33
33
|
for (const f of [
|
|
34
34
|
(0, devkit_1.joinPathFragments)(root, 'main.ts'),
|
|
35
35
|
(0, devkit_1.joinPathFragments)(root, 'main.js'),
|
|
@@ -6,7 +6,6 @@ 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");
|
|
10
9
|
/**
|
|
11
10
|
* Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
|
|
12
11
|
*/
|
|
@@ -47,98 +46,22 @@ function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
|
|
|
47
46
|
return true;
|
|
48
47
|
}
|
|
49
48
|
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
}
|
|
49
|
+
const outDir = tsConfig.options.outFile
|
|
50
|
+
? (0, node_path_1.dirname)(tsConfig.options.outFile)
|
|
51
|
+
: tsConfig.options.outDir;
|
|
52
|
+
const resolvedOutDir = outDir
|
|
53
|
+
? (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, outDir)
|
|
54
|
+
: undefined;
|
|
111
55
|
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);
|
|
115
56
|
if (resolvedOutDir) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (!relativePath.startsWith('..')) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
57
|
+
const pathToCheck = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
|
|
58
|
+
return !pathToCheck.startsWith(resolvedOutDir);
|
|
121
59
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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;
|
|
60
|
+
const ext = (0, node_path_1.extname)(path);
|
|
61
|
+
// Check that the file extension is a TS file extension. As the source files are in the same directory as the output files.
|
|
62
|
+
return ['.ts', '.tsx', '.cts', '.mts'].includes(ext);
|
|
141
63
|
};
|
|
64
|
+
// Checks if the value is a path within the `src` directory.
|
|
142
65
|
const containsInvalidPath = (value) => {
|
|
143
66
|
if (typeof value === 'string') {
|
|
144
67
|
return isPathSourceFile(value);
|
|
@@ -52,19 +52,16 @@ 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);
|
|
58
55
|
if (typeof f === 'string') {
|
|
59
56
|
pattern = f;
|
|
60
57
|
input = path.relative(opts.rootDir, opts.projectDir);
|
|
61
|
-
output = path.relative(opts.rootDir,
|
|
58
|
+
output = path.relative(opts.rootDir, opts.outputDir);
|
|
62
59
|
}
|
|
63
60
|
else {
|
|
64
61
|
isGlob = true;
|
|
65
62
|
pattern = pathPosix.join(f.input, f.glob);
|
|
66
63
|
input = f.input;
|
|
67
|
-
output = pathPosix.join(path.relative(opts.rootDir,
|
|
64
|
+
output = pathPosix.join(path.relative(opts.rootDir, opts.outputDir), f.output);
|
|
68
65
|
if (f.ignore)
|
|
69
66
|
ignore = f.ignore.map((ig) => pathPosix.join(f.input, ig));
|
|
70
67
|
}
|
package/src/utils/inline.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.getRootTsConfigPath = getRootTsConfigPath;
|
|
|
7
7
|
const devkit_1 = require("@nx/devkit");
|
|
8
8
|
const node_fs_1 = require("node:fs");
|
|
9
9
|
const path_1 = require("path");
|
|
10
|
-
const ts_solution_setup_1 = require("./typescript/ts-solution-setup");
|
|
11
10
|
function isInlineGraphEmpty(inlineGraph) {
|
|
12
11
|
return Object.keys(inlineGraph.nodes).length === 0;
|
|
13
12
|
}
|
|
@@ -73,7 +72,7 @@ function projectNodeToInlineProjectNode(projectNode, pathAlias = '', buildOutput
|
|
|
73
72
|
return {
|
|
74
73
|
name: projectNode.name,
|
|
75
74
|
root: projectNode.data.root,
|
|
76
|
-
sourceRoot:
|
|
75
|
+
sourceRoot: projectNode.data.sourceRoot,
|
|
77
76
|
pathAlias,
|
|
78
77
|
buildOutputPath,
|
|
79
78
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
2
|
export declare function isUsingTypeScriptPlugin(tree: Tree): boolean;
|
|
3
3
|
export declare function isUsingTsSolutionSetup(tree?: Tree): boolean;
|
|
4
4
|
export declare function assertNotUsingTsSolutionSetup(tree: Tree, pluginName: string, generatorName: string): void;
|
|
@@ -6,4 +6,4 @@ export declare function findRuntimeTsConfigName(projectRoot: string, tree?: Tree
|
|
|
6
6
|
export declare function updateTsconfigFiles(tree: Tree, projectRoot: string, runtimeTsconfigFileName: string, compilerOptions: Record<string, string | boolean | string[]>, exclude?: string[], rootDir?: string): void;
|
|
7
7
|
export declare function addProjectToTsSolutionWorkspace(tree: Tree, projectDir: string): Promise<void>;
|
|
8
8
|
export declare function getProjectType(tree: Tree, projectRoot: string, projectType?: 'library' | 'application'): 'library' | 'application';
|
|
9
|
-
export declare function getProjectSourceRoot(
|
|
9
|
+
export declare function getProjectSourceRoot(tree: Tree, projectSourceRoot: string | undefined, projectRoot: string): string | undefined;
|
|
@@ -9,7 +9,6 @@ exports.addProjectToTsSolutionWorkspace = addProjectToTsSolutionWorkspace;
|
|
|
9
9
|
exports.getProjectType = getProjectType;
|
|
10
10
|
exports.getProjectSourceRoot = getProjectSourceRoot;
|
|
11
11
|
const devkit_1 = require("@nx/devkit");
|
|
12
|
-
const node_fs_1 = require("node:fs");
|
|
13
12
|
const posix_1 = require("node:path/posix");
|
|
14
13
|
const tree_1 = require("nx/src/generators/tree");
|
|
15
14
|
const package_manager_workspaces_1 = require("../package-manager-workspaces");
|
|
@@ -207,15 +206,9 @@ function getProjectType(tree, projectRoot, projectType) {
|
|
|
207
206
|
return 'application';
|
|
208
207
|
return 'library';
|
|
209
208
|
}
|
|
210
|
-
function getProjectSourceRoot(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
(
|
|
214
|
-
|
|
215
|
-
: project.root));
|
|
216
|
-
}
|
|
217
|
-
return (project.sourceRoot ??
|
|
218
|
-
((0, node_fs_1.existsSync)((0, posix_1.join)(devkit_1.workspaceRoot, project.root, 'src'))
|
|
219
|
-
? (0, devkit_1.joinPathFragments)(project.root, 'src')
|
|
220
|
-
: project.root));
|
|
209
|
+
function getProjectSourceRoot(tree, projectSourceRoot, projectRoot) {
|
|
210
|
+
return (projectSourceRoot ??
|
|
211
|
+
(tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'src'))
|
|
212
|
+
? (0, devkit_1.joinPathFragments)(projectRoot, 'src')
|
|
213
|
+
: projectRoot));
|
|
221
214
|
}
|
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
10
|
-
const get_workspace_packages_from_graph_1 = require("nx/src/plugins/js/utils/get-workspace-packages-from-graph");
|
|
11
|
-
async function copyWorkspaceModules(schema, context) {
|
|
12
|
-
devkit_1.logger.log('Copying Workspace Modules to Build Directory...');
|
|
13
|
-
const outputDirectory = getOutputDir(schema, context);
|
|
14
|
-
const packageJson = getPackageJson(schema, context);
|
|
15
|
-
createWorkspaceModules(outputDirectory);
|
|
16
|
-
handleWorkspaceModules(outputDirectory, packageJson, context.projectGraph);
|
|
17
|
-
devkit_1.logger.log('Success!');
|
|
18
|
-
return { success: true };
|
|
19
|
-
}
|
|
20
|
-
function handleWorkspaceModules(outputDirectory, packageJson, projectGraph) {
|
|
21
|
-
if (!packageJson.dependencies) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const workspaceModules = (0, get_workspace_packages_from_graph_1.getWorkspacePackagesFromGraph)(projectGraph);
|
|
25
|
-
for (const [pkgName] of Object.entries(packageJson.dependencies)) {
|
|
26
|
-
if (workspaceModules.has(pkgName)) {
|
|
27
|
-
devkit_1.logger.verbose(`Copying ${pkgName}.`);
|
|
28
|
-
const workspaceModuleProject = workspaceModules.get(pkgName);
|
|
29
|
-
const workspaceModuleRoot = workspaceModuleProject.data.root;
|
|
30
|
-
const newWorkspaceModulePath = (0, path_1.join)(outputDirectory, 'workspace_modules', pkgName);
|
|
31
|
-
(0, node_fs_1.mkdirSync)(newWorkspaceModulePath, { recursive: true });
|
|
32
|
-
(0, node_fs_1.cpSync)(workspaceModuleRoot, newWorkspaceModulePath, {
|
|
33
|
-
filter: (src) => !src.includes('node_modules'),
|
|
34
|
-
recursive: true,
|
|
35
|
-
});
|
|
36
|
-
devkit_1.logger.verbose(`Copied ${pkgName} successfully.`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function createWorkspaceModules(outputDirectory) {
|
|
41
|
-
(0, node_fs_1.mkdirSync)((0, path_1.join)(outputDirectory, 'workspace_modules'), { recursive: true });
|
|
42
|
-
}
|
|
43
|
-
function getPackageJson(schema, context) {
|
|
44
|
-
const target = (0, devkit_1.parseTargetString)(schema.buildTarget, context);
|
|
45
|
-
const project = context.projectGraph.nodes[target.project].data;
|
|
46
|
-
const packageJsonPath = (0, path_1.join)(devkit_1.workspaceRoot, project.root, 'package.json');
|
|
47
|
-
if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
48
|
-
throw new Error(`${packageJsonPath} does not exist.`);
|
|
49
|
-
}
|
|
50
|
-
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
51
|
-
return packageJson;
|
|
52
|
-
}
|
|
53
|
-
function getOutputDir(schema, context) {
|
|
54
|
-
let outputDir = schema.outputPath;
|
|
55
|
-
if (outputDir) {
|
|
56
|
-
outputDir = normalizeOutputPath(outputDir);
|
|
57
|
-
if ((0, node_fs_1.existsSync)(outputDir)) {
|
|
58
|
-
return outputDir;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const target = (0, devkit_1.parseTargetString)(schema.buildTarget, context);
|
|
62
|
-
const project = context.projectGraph.nodes[target.project].data;
|
|
63
|
-
const buildTarget = project.targets[target.target];
|
|
64
|
-
let maybeOutputPath = buildTarget.outputs?.[0] ??
|
|
65
|
-
buildTarget.options.outputPath ??
|
|
66
|
-
buildTarget.options.outputDir;
|
|
67
|
-
if (!maybeOutputPath) {
|
|
68
|
-
throw new Error(`Could not infer an output directory from the '${schema.buildTarget}' target. Please provide 'outputPath'.`);
|
|
69
|
-
}
|
|
70
|
-
maybeOutputPath = (0, utils_1.interpolate)(maybeOutputPath, {
|
|
71
|
-
workspaceRoot: devkit_1.workspaceRoot,
|
|
72
|
-
projectRoot: project.root,
|
|
73
|
-
projectName: project.name,
|
|
74
|
-
options: {
|
|
75
|
-
...(buildTarget.options ?? {}),
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
outputDir = normalizeOutputPath(maybeOutputPath);
|
|
79
|
-
if (!(0, node_fs_1.existsSync)(outputDir)) {
|
|
80
|
-
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'.`);
|
|
81
|
-
}
|
|
82
|
-
return outputDir;
|
|
83
|
-
}
|
|
84
|
-
function normalizeOutputPath(outputPath) {
|
|
85
|
-
if (!outputPath.startsWith(devkit_1.workspaceRoot)) {
|
|
86
|
-
outputPath = (0, path_1.join)(devkit_1.workspaceRoot, outputPath);
|
|
87
|
-
}
|
|
88
|
-
if (!(0, fs_1.lstatSync)(outputPath).isDirectory()) {
|
|
89
|
-
outputPath = (0, path_1.dirname)(outputPath);
|
|
90
|
-
}
|
|
91
|
-
return outputPath;
|
|
92
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = pruneLockfileExecutor;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
9
|
-
const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
|
|
10
|
-
async function pruneLockfileExecutor(schema, context) {
|
|
11
|
-
devkit_1.logger.log('Pruning lockfile...');
|
|
12
|
-
const outputDirectory = getOutputDir(schema, context);
|
|
13
|
-
const packageJson = getPackageJson(schema, context);
|
|
14
|
-
const packageManager = (0, devkit_1.detectPackageManager)(devkit_1.workspaceRoot);
|
|
15
|
-
if (packageManager === 'bun') {
|
|
16
|
-
devkit_1.logger.warn('Bun lockfile generation is not supported. Only package.json will be generated. Run "bun install" in the output directory if needed.');
|
|
17
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(outputDirectory, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
const { lockfileName, lockFile } = createPrunedLockfile(packageJson, context.projectGraph);
|
|
21
|
-
const lockfileOutputPath = (0, path_1.join)(outputDirectory, lockfileName);
|
|
22
|
-
(0, fs_1.writeFileSync)(lockfileOutputPath, lockFile);
|
|
23
|
-
(0, fs_1.writeFileSync)((0, path_1.join)(outputDirectory, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
24
|
-
devkit_1.logger.log(`Lockfile pruned: ${lockfileOutputPath}`);
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
success: true,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function createPrunedLockfile(packageJson, graph) {
|
|
31
|
-
const packageManager = (0, devkit_1.detectPackageManager)(devkit_1.workspaceRoot);
|
|
32
|
-
const lockfileName = (0, lock_file_1.getLockFileName)(packageManager);
|
|
33
|
-
const lockFile = (0, lock_file_1.createLockFile)(packageJson, graph, packageManager);
|
|
34
|
-
for (const [pkgName, pkgVersion] of Object.entries(packageJson.dependencies ?? {})) {
|
|
35
|
-
if (pkgVersion.startsWith('workspace:') ||
|
|
36
|
-
pkgVersion.startsWith('file:') ||
|
|
37
|
-
pkgVersion.startsWith('link:')) {
|
|
38
|
-
packageJson.dependencies[pkgName] = `file:./workspace_modules/${pkgName}`;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
lockfileName,
|
|
43
|
-
lockFile,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function getPackageJson(schema, context) {
|
|
47
|
-
const target = (0, devkit_1.parseTargetString)(schema.buildTarget, context);
|
|
48
|
-
const project = context.projectGraph.nodes[target.project].data;
|
|
49
|
-
const packageJsonPath = (0, path_1.join)(devkit_1.workspaceRoot, project.root, 'package.json');
|
|
50
|
-
if (!(0, fs_1.existsSync)(packageJsonPath)) {
|
|
51
|
-
throw new Error(`${packageJsonPath} does not exist.`);
|
|
52
|
-
}
|
|
53
|
-
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
54
|
-
return packageJson;
|
|
55
|
-
}
|
|
56
|
-
function getOutputDir(schema, context) {
|
|
57
|
-
let outputDir = schema.outputPath;
|
|
58
|
-
if (outputDir) {
|
|
59
|
-
outputDir = normalizeOutputPath(outputDir);
|
|
60
|
-
if ((0, fs_1.existsSync)(outputDir)) {
|
|
61
|
-
return outputDir;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const target = (0, devkit_1.parseTargetString)(schema.buildTarget, context);
|
|
65
|
-
const project = context.projectGraph.nodes[target.project].data;
|
|
66
|
-
const buildTarget = project.targets[target.target];
|
|
67
|
-
let maybeOutputPath = buildTarget.outputs?.[0] ??
|
|
68
|
-
buildTarget.options.outputPath ??
|
|
69
|
-
buildTarget.options.outputDir;
|
|
70
|
-
if (!maybeOutputPath) {
|
|
71
|
-
throw new Error(`Could not infer an output directory from the '${schema.buildTarget}' target. Please provide 'outputPath'.`);
|
|
72
|
-
}
|
|
73
|
-
maybeOutputPath = (0, utils_1.interpolate)(maybeOutputPath, {
|
|
74
|
-
workspaceRoot: devkit_1.workspaceRoot,
|
|
75
|
-
projectRoot: project.root,
|
|
76
|
-
projectName: project.name,
|
|
77
|
-
options: {
|
|
78
|
-
...(buildTarget.options ?? {}),
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
outputDir = normalizeOutputPath(maybeOutputPath);
|
|
82
|
-
if (!(0, fs_1.existsSync)(outputDir)) {
|
|
83
|
-
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'.`);
|
|
84
|
-
}
|
|
85
|
-
return outputDir;
|
|
86
|
-
}
|
|
87
|
-
function normalizeOutputPath(outputPath) {
|
|
88
|
-
if (!outputPath.startsWith(devkit_1.workspaceRoot)) {
|
|
89
|
-
outputPath = (0, path_1.join)(devkit_1.workspaceRoot, outputPath);
|
|
90
|
-
}
|
|
91
|
-
if (!(0, fs_1.lstatSync)(outputPath).isDirectory()) {
|
|
92
|
-
outputPath = (0, path_1.dirname)(outputPath);
|
|
93
|
-
}
|
|
94
|
-
return outputPath;
|
|
95
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 2,
|
|
3
|
-
"outputCapture": "direct-nodejs",
|
|
4
|
-
"title": "Prune Lockfile",
|
|
5
|
-
"description": "Creates a pruned lockfile based on the project dependencies and places it into the output directory.",
|
|
6
|
-
"cli": "nx",
|
|
7
|
-
"type": "object",
|
|
8
|
-
"properties": {
|
|
9
|
-
"buildTarget": {
|
|
10
|
-
"type": "string",
|
|
11
|
-
"description": "The build target that produces the output directory to place the pruned lockfile.",
|
|
12
|
-
"default": "build"
|
|
13
|
-
},
|
|
14
|
-
"outputPath": {
|
|
15
|
-
"type": "string",
|
|
16
|
-
"description": "The output path to place the pruned lockfile. Usually inferred from the outputs of the buildTarget."
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"required": ["buildTarget"]
|
|
20
|
-
}
|