@nx/node 0.0.0-pr-32149-2d2cbf3 → 0.0.0-pr-32117-f006df9

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": "0.0.0-pr-32149-2d2cbf3",
3
+ "version": "0.0.0-pr-32117-f006df9",
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": "0.0.0-pr-32149-2d2cbf3",
36
- "@nx/jest": "0.0.0-pr-32149-2d2cbf3",
37
- "@nx/js": "0.0.0-pr-32149-2d2cbf3",
38
- "@nx/eslint": "0.0.0-pr-32149-2d2cbf3",
35
+ "@nx/devkit": "0.0.0-pr-32117-f006df9",
36
+ "@nx/jest": "0.0.0-pr-32117-f006df9",
37
+ "@nx/js": "0.0.0-pr-32117-f006df9",
38
+ "@nx/eslint": "0.0.0-pr-32117-f006df9",
39
+ "@nx/docker": "0.0.0-pr-32117-f006df9",
39
40
  "tcp-port-used": "^1.0.2",
40
41
  "kill-port": "^1.6.1"
41
42
  },
42
43
  "devDependencies": {
43
- "nx": "0.0.0-pr-32149-2d2cbf3"
44
+ "nx": "0.0.0-pr-32117-f006df9"
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":"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,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,CAwBA"}
@@ -109,6 +109,7 @@ function getNestWebpackBuildConfig() {
109
109
  function getPruneTargets(buildTarget) {
110
110
  return {
111
111
  'prune-lockfile': {
112
+ dependsOn: ['build'],
112
113
  cache: true,
113
114
  executor: '@nx/js:prune-lockfile',
114
115
  options: {
@@ -116,6 +117,7 @@ function getPruneTargets(buildTarget) {
116
117
  },
117
118
  },
118
119
  'copy-workspace-modules': {
120
+ dependsOn: ['build'],
119
121
  cache: true,
120
122
  executor: '@nx/js:copy-workspace-modules',
121
123
  options: {
@@ -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);