@nx/js 21.2.2 → 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 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.2.2",
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.2.2",
43
- "@nx/workspace": "21.2.2",
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
- const get_workspace_packages_from_graph_1 = require("../../utils/package-json/get-workspace-packages-from-graph");
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,5 @@
1
+ import { type ExecutorContext } from '@nx/devkit';
2
+ import { type PruneLockfileOptions } from './schema';
3
+ export default function pruneLockfileExecutor(schema: PruneLockfileOptions, context: ExecutorContext): Promise<{
4
+ success: boolean;
5
+ }>;
@@ -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,4 @@
1
+ export interface PruneLockfileOptions {
2
+ buildTarget: string;
3
+ outputPath?: string;
4
+ }
@@ -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",
@@ -1,2 +0,0 @@
1
- import { type ProjectGraph, ProjectGraphProjectNode } from '@nx/devkit';
2
- export declare function getWorkspacePackagesFromGraph(graph: ProjectGraph): Map<string, ProjectGraphProjectNode>;
@@ -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
- }