@nx/node 21.4.0-canary.20250730-8ef7d0e → 21.4.0-canary.20250801-e0a3829

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/node",
3
- "version": "21.4.0-canary.20250730-8ef7d0e",
3
+ "version": "21.4.0-canary.20250801-e0a3829",
4
4
  "private": false,
5
5
  "description": "The Node Plugin for Nx contains generators to manage Node applications within an Nx workspace.",
6
6
  "repository": {
@@ -32,15 +32,16 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "tslib": "^2.3.0",
35
- "@nx/devkit": "21.4.0-canary.20250730-8ef7d0e",
36
- "@nx/jest": "21.4.0-canary.20250730-8ef7d0e",
37
- "@nx/js": "21.4.0-canary.20250730-8ef7d0e",
38
- "@nx/eslint": "21.4.0-canary.20250730-8ef7d0e",
35
+ "@nx/devkit": "21.4.0-canary.20250801-e0a3829",
36
+ "@nx/jest": "21.4.0-canary.20250801-e0a3829",
37
+ "@nx/js": "21.4.0-canary.20250801-e0a3829",
38
+ "@nx/eslint": "21.4.0-canary.20250801-e0a3829",
39
+ "@nx/docker": "21.4.0-canary.20250801-e0a3829",
39
40
  "tcp-port-used": "^1.0.2",
40
41
  "kill-port": "^1.6.1"
41
42
  },
42
43
  "devDependencies": {
43
- "nx": "21.4.0-canary.20250730-8ef7d0e"
44
+ "nx": "21.4.0-canary.20250801-e0a3829"
44
45
  },
45
46
  "publishConfig": {
46
47
  "access": "public"
@@ -1 +1 @@
1
- {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/application/application.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAIjB,IAAI,EAIL,MAAM,YAAY,CAAC;AAapB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAwClC,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BAMpE;AAED,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BA+K5E;AAED,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/application/application.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAIjB,IAAI,EAIL,MAAM,YAAY,CAAC;AAapB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAwClC,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BAMpE;AAED,wBAAsB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BAgL5E;AAED,eAAe,oBAAoB,CAAC"}
@@ -167,6 +167,7 @@ async function applicationGeneratorInternal(tree, schema) {
167
167
  ...options,
168
168
  project: options.name,
169
169
  skipFormat: true,
170
+ skipDockerPlugin: options.skipDockerPlugin ?? false,
170
171
  });
171
172
  tasks.push(dockerTask);
172
173
  }
@@ -1 +1 @@
1
- {"version":3,"file":"add-dependencies.d.ts","sourceRoot":"","sources":["../../../../../../../packages/node/src/generators/application/lib/add-dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,IAAI,EACL,MAAM,YAAY,CAAC;AAepB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,gBAAgB,GACxB,iBAAiB,CA8CnB"}
1
+ {"version":3,"file":"add-dependencies.d.ts","sourceRoot":"","sources":["../../../../../../../packages/node/src/generators/application/lib/add-dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAEjB,IAAI,EAEL,MAAM,YAAY,CAAC;AAepB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,gBAAgB,GACxB,iBAAiB,CA0DnB"}
@@ -37,6 +37,13 @@ function addProjectDependencies(tree, options) {
37
37
  },
38
38
  fastify: {},
39
39
  };
40
+ const projectPackageJson = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json');
41
+ if (tree.exists(projectPackageJson)) {
42
+ (0, devkit_1.updateJson)(tree, projectPackageJson, (json) => {
43
+ json.dependencies ??= { ...frameworkDependencies };
44
+ return json;
45
+ });
46
+ }
40
47
  return (0, devkit_1.addDependenciesToPackageJson)(tree, {
41
48
  ...frameworkDependencies[options.framework],
42
49
  tslib: versions_2.tslibVersion,
@@ -30,7 +30,7 @@ function addProject(tree, options) {
30
30
  }
31
31
  project.targets = {
32
32
  ...project.targets,
33
- ...(0, create_targets_1.getPruneTargets)('build'),
33
+ ...(0, create_targets_1.getPruneTargets)('build', options.outputPath),
34
34
  };
35
35
  project.targets.serve = (0, create_targets_1.getServeConfig)(options);
36
36
  const packageJson = {
@@ -4,7 +4,7 @@ export declare function getWebpackBuildConfig(tree: Tree, project: ProjectConfig
4
4
  export declare function getEsBuildConfig(tree: Tree, project: ProjectConfiguration, options: NormalizedSchema): TargetConfiguration;
5
5
  export declare function getServeConfig(options: NormalizedSchema): TargetConfiguration;
6
6
  export declare function getNestWebpackBuildConfig(): TargetConfiguration;
7
- export declare function getPruneTargets(buildTarget: string): {
7
+ export declare function getPruneTargets(buildTarget: string, outputPath: string): {
8
8
  prune: TargetConfiguration;
9
9
  'prune-lockfile': TargetConfiguration;
10
10
  'copy-workspace-modules': TargetConfiguration;
@@ -1 +1 @@
1
- {"version":3,"file":"create-targets.d.ts","sourceRoot":"","sources":["../../../../../../../packages/node/src/generators/application/lib/create-targets.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EACpB,IAAI,EACJ,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,gBAAgB,GACxB,mBAAmB,CA+BrB;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,gBAAgB,GACxB,mBAAmB,CAqCrB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,mBAAmB,CAuB7E;AAED,wBAAgB,yBAAyB,IAAI,mBAAmB,CAa/D;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG;IACpD,KAAK,EAAE,mBAAmB,CAAC;IAC3B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,wBAAwB,EAAE,mBAAmB,CAAC;CAC/C,CAsBA"}
1
+ {"version":3,"file":"create-targets.d.ts","sourceRoot":"","sources":["../../../../../../../packages/node/src/generators/application/lib/create-targets.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EACpB,IAAI,EACJ,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,gBAAgB,GACxB,mBAAmB,CA+BrB;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,gBAAgB,GACxB,mBAAmB,CAqCrB;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,mBAAmB,CAuB7E;AAED,wBAAgB,yBAAyB,IAAI,mBAAmB,CAa/D;AAED,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB;IACD,KAAK,EAAE,mBAAmB,CAAC;IAC3B,gBAAgB,EAAE,mBAAmB,CAAC;IACtC,wBAAwB,EAAE,mBAAmB,CAAC;CAC/C,CAgCA"}
@@ -7,6 +7,7 @@ exports.getNestWebpackBuildConfig = getNestWebpackBuildConfig;
7
7
  exports.getPruneTargets = getPruneTargets;
8
8
  const devkit_1 = require("@nx/devkit");
9
9
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
10
+ const js_1 = require("@nx/js");
10
11
  function getWebpackBuildConfig(tree, project, options) {
11
12
  const sourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(project, tree);
12
13
  return {
@@ -106,24 +107,33 @@ function getNestWebpackBuildConfig() {
106
107
  },
107
108
  };
108
109
  }
109
- function getPruneTargets(buildTarget) {
110
+ function getPruneTargets(buildTarget, outputPath) {
111
+ const lockFileName = (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)() ?? 'npm') ?? 'package-lock.json';
110
112
  return {
111
113
  'prune-lockfile': {
114
+ dependsOn: ['build'],
112
115
  cache: true,
113
116
  executor: '@nx/js:prune-lockfile',
117
+ outputs: [
118
+ `{workspaceRoot}/${(0, devkit_1.joinPathFragments)(outputPath, 'package.json')}`,
119
+ `{workspaceRoot}/${(0, devkit_1.joinPathFragments)(outputPath, lockFileName)}`,
120
+ ],
114
121
  options: {
115
122
  buildTarget,
116
123
  },
117
124
  },
118
125
  'copy-workspace-modules': {
126
+ dependsOn: ['build'],
119
127
  cache: true,
128
+ outputs: [
129
+ `{workspaceRoot}/${(0, devkit_1.joinPathFragments)(outputPath, 'workspace_modules')}`,
130
+ ],
120
131
  executor: '@nx/js:copy-workspace-modules',
121
132
  options: {
122
133
  buildTarget,
123
134
  },
124
135
  },
125
136
  prune: {
126
- cache: true,
127
137
  dependsOn: ['prune-lockfile', 'copy-workspace-modules'],
128
138
  executor: 'nx:noop',
129
139
  },
@@ -22,6 +22,7 @@ export interface Schema {
22
22
  port?: number;
23
23
  rootProject?: boolean;
24
24
  docker?: boolean;
25
+ skipDockerPlugin?: boolean;
25
26
  isNest?: boolean;
26
27
  addPlugin?: boolean;
27
28
  useTsSolution?: boolean;
@@ -124,6 +124,11 @@
124
124
  "type": "boolean",
125
125
  "description": "Add a docker build target"
126
126
  },
127
+ "skipDockerPlugin": {
128
+ "type": "boolean",
129
+ "description": "Skip the @nx/docker plugin and use the legacy docker build target instead.",
130
+ "default": false
131
+ },
127
132
  "useProjectJson": {
128
133
  "type": "boolean",
129
134
  "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
@@ -1,9 +1,11 @@
1
1
  # This file is generated by Nx.
2
- #
3
- # Build the docker image with `npx nx docker-build <%= project %>`.
4
- # Tip: Modify "docker-build" options in project.json to change docker build args.
5
- #
2
+ # Build the docker image with `npx nx docker:build <%= project %>`.
3
+ # Tip: Modify "docker:build" options in project.json to change docker build args.
4
+ #<% if (skipDockerPlugin) { %>
6
5
  # Run the container with `docker run -p 3000:3000 -t <%= sanitizedProjectName %>`.
6
+ #<% } else { %>
7
+ # Run the container with `nx docker:run <%= project %> -p 3000:3000`.
8
+ #<% } %>
7
9
  FROM docker.io/node:lts-alpine
8
10
 
9
11
  ENV HOST=0.0.0.0
@@ -15,7 +17,7 @@ RUN addgroup --system <%= sanitizedProjectName %> && \
15
17
  adduser --system -G <%= sanitizedProjectName %> <%= sanitizedProjectName %>
16
18
 
17
19
  COPY <%= buildLocation %> <%= sanitizedProjectName %>/
18
- COPY <%= projectPath %>/package.json <%= sanitizedProjectName %>/
20
+ <% if (skipDockerPlugin) { %>COPY <%= projectPath %>/package.json <%= sanitizedProjectName %>/<% } else { %>COPY package.json <%= sanitizedProjectName %>/<% } %>
19
21
  RUN chown -R <%= sanitizedProjectName %>:<%= sanitizedProjectName %> .
20
22
 
21
23
  # You can remove this install step if you build with `--bundle` option.
@@ -4,4 +4,5 @@ export interface SetUpDockerOptions {
4
4
  buildTarget?: string;
5
5
  skipFormat?: boolean;
6
6
  outputPath: string;
7
+ skipDockerPlugin?: boolean;
7
8
  }
@@ -18,7 +18,7 @@
18
18
  "targetName": {
19
19
  "description": "The name of the target to create",
20
20
  "type": "string",
21
- "default": "docker-build"
21
+ "default": "docker:build"
22
22
  },
23
23
  "buildTargetName": {
24
24
  "description": "The name of the build target",
@@ -28,6 +28,11 @@
28
28
  "outputPath": {
29
29
  "description": "The output path for the node application",
30
30
  "type": "string"
31
+ },
32
+ "skipDockerPlugin": {
33
+ "type": "boolean",
34
+ "description": "Skip the @nx/docker plugin and use the legacy docker build target instead.",
35
+ "default": false
31
36
  }
32
37
  }
33
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setup-docker.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/setup-docker/setup-docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAKjB,IAAI,EAEL,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAmD9C,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,kBAAkB,QAe1E;AAED,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,kBAAkB,8BAajC;AAED,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"setup-docker.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/setup-docker/setup-docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAIjB,IAAI,EAEL,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AA4E9C,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,kBAAkB,QAqB1E;AAED,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,kBAAkB,8BAcjC;AAED,eAAe,oBAAoB,CAAC"}
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateProjectConfig = updateProjectConfig;
4
4
  exports.setupDockerGenerator = setupDockerGenerator;
5
5
  const devkit_1 = require("@nx/devkit");
6
+ const generators_1 = require("@nx/docker/generators");
6
7
  const path_1 = require("path");
7
8
  function normalizeOptions(tree, setupOptions) {
8
9
  return {
9
10
  ...setupOptions,
10
11
  project: setupOptions.project ?? (0, devkit_1.readNxJson)(tree).defaultProject,
11
- targetName: setupOptions.targetName ?? 'docker-build',
12
+ targetName: setupOptions.targetName ?? 'docker:build',
12
13
  buildTarget: setupOptions.buildTarget ?? 'build',
14
+ skipDockerPlugin: setupOptions.skipDockerPlugin ?? false,
13
15
  };
14
16
  }
15
17
  function sanitizeProjectName(projectName) {
@@ -20,7 +22,11 @@ function sanitizeProjectName(projectName) {
20
22
  .replace(/-+/g, '-')
21
23
  .replace(/^-|-$/g, '');
22
24
  }
23
- function addDocker(tree, options) {
25
+ async function addDocker(tree, options) {
26
+ let installTask = () => { };
27
+ if (!options.skipDockerPlugin) {
28
+ installTask = await (0, generators_1.initGenerator)(tree, { skipFormat: true });
29
+ }
24
30
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
25
31
  const outputPath = projectConfig.targets[options.buildTarget]?.options['outputPath'];
26
32
  if (!projectConfig) {
@@ -30,29 +36,58 @@ function addDocker(tree, options) {
30
36
  throw new Error(`The output path for the project ${options.project} is not defined. Please provide it as an option to the generator.`);
31
37
  }
32
38
  const sanitizedProjectName = sanitizeProjectName(options.project);
39
+ const finalOutputPath = options.outputPath ?? outputPath;
40
+ // Calculate build location based on skipDockerPlugin flag
41
+ let buildLocation;
42
+ if (options.skipDockerPlugin) {
43
+ // Legacy mode: use workspace-relative paths
44
+ buildLocation = finalOutputPath;
45
+ }
46
+ else {
47
+ // New mode: use project-relative paths
48
+ // Remove the project root prefix from the output path
49
+ const projectRootWithSlash = projectConfig.root + '/';
50
+ buildLocation = finalOutputPath.startsWith(projectRootWithSlash)
51
+ ? finalOutputPath.substring(projectRootWithSlash.length)
52
+ : finalOutputPath.startsWith(projectConfig.root)
53
+ ? finalOutputPath.substring(projectConfig.root.length)
54
+ : 'dist';
55
+ }
33
56
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), projectConfig.root, {
34
57
  tmpl: '',
35
- buildLocation: options.outputPath ?? outputPath,
58
+ buildLocation,
36
59
  project: options.project,
37
60
  projectPath: projectConfig.root,
38
61
  sanitizedProjectName,
62
+ skipDockerPlugin: options.skipDockerPlugin,
39
63
  });
64
+ return installTask;
40
65
  }
41
66
  function updateProjectConfig(tree, options) {
42
67
  let projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
43
- // Use sanitized project name for Docker image tag
44
- const sanitizedProjectName = sanitizeProjectName(options.project);
45
- projectConfig.targets[`${options.targetName}`] = {
46
- dependsOn: [`${options.buildTarget}`],
47
- command: `docker build -f ${(0, devkit_1.joinPathFragments)(projectConfig.root, 'Dockerfile')} . -t ${sanitizedProjectName}`,
48
- };
68
+ if (options.skipDockerPlugin) {
69
+ // Use sanitized project name for Docker image tag
70
+ const sanitizedProjectName = sanitizeProjectName(options.project);
71
+ projectConfig.targets[`${options.targetName}`] = {
72
+ dependsOn: [`${options.buildTarget}`, 'prune'],
73
+ command: `docker build . -t ${sanitizedProjectName}`,
74
+ options: {
75
+ cwd: projectConfig.root,
76
+ },
77
+ };
78
+ }
79
+ else {
80
+ projectConfig.targets[`${options.targetName}`] = {
81
+ dependsOn: [`${options.buildTarget}`, 'prune'],
82
+ };
83
+ }
49
84
  (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
50
85
  }
51
86
  async function setupDockerGenerator(tree, setupOptions) {
52
87
  const tasks = [];
53
88
  const options = normalizeOptions(tree, setupOptions);
54
- // Should check if the node project exists
55
- addDocker(tree, options);
89
+ const installTask = await addDocker(tree, options);
90
+ tasks.push(installTask);
56
91
  updateProjectConfig(tree, options);
57
92
  if (!options.skipFormat) {
58
93
  await (0, devkit_1.formatFiles)(tree);