@nx/js 21.2.3 → 21.3.0-beta.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/executors.json +5 -0
- package/package.json +3 -3
- package/src/executors/copy-workspace-modules/copy-workspace-modules.js +2 -1
- package/src/executors/prune-lockfile/prune-lockfile.d.ts +5 -0
- package/src/executors/prune-lockfile/prune-lockfile.js +95 -0
- package/src/executors/prune-lockfile/schema.d.ts +4 -0
- package/src/executors/prune-lockfile/schema.json +20 -0
- package/src/generators/library/library.js +4 -0
- package/src/generators/library/schema.json +2 -1
- package/src/generators/setup-build/generator.js +2 -2
- 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/utils/package-json/get-workspace-packages-from-graph.d.ts +0 -2
- package/src/utils/package-json/get-workspace-packages-from-graph.js +0 -13
package/executors.json
CHANGED
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
"schema": "./src/executors/node/schema.json",
|
|
23
23
|
"description": "Execute a Node application."
|
|
24
24
|
},
|
|
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
|
+
},
|
|
25
30
|
"release-publish": {
|
|
26
31
|
"implementation": "./src/executors/release-publish/release-publish.impl",
|
|
27
32
|
"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
|
+
"version": "21.3.0-beta.0",
|
|
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.
|
|
43
|
-
"@nx/workspace": "21.
|
|
42
|
+
"@nx/devkit": "21.3.0-beta.0",
|
|
43
|
+
"@nx/workspace": "21.3.0-beta.0",
|
|
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",
|
|
@@ -6,7 +6,8 @@ const utils_1 = require("nx/src/tasks-runner/utils");
|
|
|
6
6
|
const node_fs_1 = require("node:fs");
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
|
-
|
|
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");
|
|
10
11
|
async function copyWorkspaceModules(schema, context) {
|
|
11
12
|
devkit_1.logger.log('Copying Workspace Modules to Build Directory...');
|
|
12
13
|
const outputDirectory = getOutputDir(schema, context);
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -43,6 +43,10 @@ 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
|
+
}
|
|
46
50
|
createFiles(tree, options);
|
|
47
51
|
await configureProject(tree, options);
|
|
48
52
|
if (!options.skipPackageJson) {
|
|
@@ -130,7 +130,8 @@
|
|
|
130
130
|
"simpleName": {
|
|
131
131
|
"description": "Don't include the directory in the generated file name.",
|
|
132
132
|
"type": "boolean",
|
|
133
|
-
"default": false
|
|
133
|
+
"default": false,
|
|
134
|
+
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
|
|
134
135
|
},
|
|
135
136
|
"useProjectJson": {
|
|
136
137
|
"type": "boolean",
|
|
@@ -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'),
|
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,13 +0,0 @@
|
|
|
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
|
-
}
|