@nx/node 21.4.0-beta.0 → 21.4.0-beta.10

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.
Files changed (27) hide show
  1. package/package.json +7 -6
  2. package/src/generators/application/application.d.ts.map +1 -1
  3. package/src/generators/application/application.js +5 -3
  4. package/src/generators/application/files/common/webpack.config.js__tmpl__ +11 -0
  5. package/src/generators/application/lib/add-dependencies.d.ts +4 -1
  6. package/src/generators/application/lib/add-dependencies.d.ts.map +1 -1
  7. package/src/generators/application/lib/add-dependencies.js +11 -8
  8. package/src/generators/application/lib/create-files.d.ts.map +1 -1
  9. package/src/generators/application/lib/create-files.js +6 -0
  10. package/src/generators/application/lib/create-project.d.ts +1 -1
  11. package/src/generators/application/lib/create-project.d.ts.map +1 -1
  12. package/src/generators/application/lib/create-project.js +6 -1
  13. package/src/generators/application/lib/create-targets.d.ts +5 -0
  14. package/src/generators/application/lib/create-targets.d.ts.map +1 -1
  15. package/src/generators/application/lib/create-targets.js +34 -0
  16. package/src/generators/application/schema.d.ts +1 -0
  17. package/src/generators/application/schema.json +6 -1
  18. package/src/generators/library/library.d.ts.map +1 -1
  19. package/src/generators/library/library.js +5 -1
  20. package/src/generators/setup-docker/files/Dockerfile__tmpl__ +16 -13
  21. package/src/generators/setup-docker/schema.d.ts +1 -0
  22. package/src/generators/setup-docker/schema.json +6 -1
  23. package/src/generators/setup-docker/setup-docker.d.ts.map +1 -1
  24. package/src/generators/setup-docker/setup-docker.js +52 -11
  25. package/src/utils/vscode-debug-config.d.ts +8 -0
  26. package/src/utils/vscode-debug-config.d.ts.map +1 -0
  27. package/src/utils/vscode-debug-config.js +82 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/node",
3
- "version": "21.4.0-beta.0",
3
+ "version": "21.4.0-beta.10",
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-beta.0",
36
- "@nx/jest": "21.4.0-beta.0",
37
- "@nx/js": "21.4.0-beta.0",
38
- "@nx/eslint": "21.4.0-beta.0",
35
+ "@nx/devkit": "21.4.0-beta.10",
36
+ "@nx/jest": "21.4.0-beta.10",
37
+ "@nx/js": "21.4.0-beta.10",
38
+ "@nx/eslint": "21.4.0-beta.10",
39
+ "@nx/docker": "21.4.0-beta.10",
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-beta.0"
44
+ "nx": "21.4.0-beta.10"
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;AAcpB,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,8BAwL5E;AAED,eAAe,oBAAoB,CAAC"}
@@ -50,11 +50,12 @@ async function applicationGenerator(tree, schema) {
50
50
  }
51
51
  async function applicationGeneratorInternal(tree, schema) {
52
52
  const tasks = [];
53
+ const addTsPlugin = (0, ts_solution_setup_1.shouldConfigureTsSolutionSetup)(tree, schema.addPlugin, schema.useTsSolution);
53
54
  const jsInitTask = await (0, js_1.initGenerator)(tree, {
54
55
  ...schema,
55
56
  tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
56
57
  skipFormat: true,
57
- addTsPlugin: schema.useTsSolution,
58
+ addTsPlugin,
58
59
  });
59
60
  tasks.push(jsInitTask);
60
61
  const options = await (0, lib_1.normalizeOptions)(tree, schema);
@@ -86,7 +87,7 @@ async function applicationGeneratorInternal(tree, schema) {
86
87
  skipFormat: true,
87
88
  });
88
89
  tasks.push(initTask);
89
- const installTask = (0, lib_1.addProjectDependencies)(tree, options);
90
+ const { installTask, frameworkDependencies } = (0, lib_1.addProjectDependencies)(tree, options);
90
91
  tasks.push(installTask);
91
92
  if (options.bundler === 'webpack') {
92
93
  const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
@@ -104,7 +105,7 @@ async function applicationGeneratorInternal(tree, schema) {
104
105
  }
105
106
  }
106
107
  (0, lib_1.addAppFiles)(tree, options);
107
- (0, lib_1.addProject)(tree, options);
108
+ (0, lib_1.addProject)(tree, options, frameworkDependencies);
108
109
  // If we are using the new TS solution
109
110
  // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
110
111
  if (options.isUsingTsSolutionConfig) {
@@ -167,6 +168,7 @@ async function applicationGeneratorInternal(tree, schema) {
167
168
  ...options,
168
169
  project: options.name,
169
170
  skipFormat: true,
171
+ skipDockerPlugin: options.skipDockerPlugin ?? false,
170
172
  });
171
173
  tasks.push(dockerTask);
172
174
  }
@@ -5,6 +5,9 @@ const { join } = require('path');
5
5
  module.exports = {
6
6
  output: {
7
7
  path: join(__dirname, '<%= webpackPluginOptions.outputPath %>'),
8
+ ...(process.env.NODE_ENV !== 'production' && {
9
+ devtoolModuleFilenameTemplate: '[absolute-resource-path]',
10
+ }),
8
11
  },
9
12
  plugins: [
10
13
  new NxAppWebpackPlugin({
@@ -16,6 +19,7 @@ module.exports = {
16
19
  optimization: false,
17
20
  outputHashing: 'none',
18
21
  generatePackageJson: true,
22
+ sourceMaps: true,
19
23
  })
20
24
  ],
21
25
  };
@@ -28,6 +32,13 @@ module.exports = composePlugins(
28
32
  target: 'node',
29
33
  }),
30
34
  (config) => {
35
+ config.output = {
36
+ ...config.output,
37
+ ...(process.env.NODE_ENV !== 'production' && {
38
+ devtoolModuleFilenameTemplate: '[absolute-resource-path]',
39
+ }),
40
+ };
41
+ config.devtool = 'source-map';
31
42
  // Update the webpack config as needed here.
32
43
  // e.g. `config.plugins.push(new MyPlugin())`
33
44
  return config;
@@ -1,4 +1,7 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { NormalizedSchema } from './normalized-schema';
3
- export declare function addProjectDependencies(tree: Tree, options: NormalizedSchema): GeneratorCallback;
3
+ export declare function addProjectDependencies(tree: Tree, options: NormalizedSchema): {
4
+ installTask: GeneratorCallback;
5
+ frameworkDependencies: Record<string, string>;
6
+ };
4
7
  //# sourceMappingURL=add-dependencies.d.ts.map
@@ -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;IACD,WAAW,EAAE,iBAAiB,CAAC;IAC/B,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/C,CAkDA"}
@@ -37,12 +37,15 @@ function addProjectDependencies(tree, options) {
37
37
  },
38
38
  fastify: {},
39
39
  };
40
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {
41
- ...frameworkDependencies[options.framework],
42
- tslib: versions_2.tslibVersion,
43
- }, {
44
- ...frameworkDevDependencies[options.framework],
45
- ...bundlers[options.bundler],
46
- '@types/node': versions_2.typesNodeVersion,
47
- });
40
+ return {
41
+ installTask: (0, devkit_1.addDependenciesToPackageJson)(tree, {
42
+ ...frameworkDependencies[options.framework],
43
+ tslib: versions_2.tslibVersion,
44
+ }, {
45
+ ...frameworkDevDependencies[options.framework],
46
+ ...bundlers[options.bundler],
47
+ '@types/node': versions_2.typesNodeVersion,
48
+ }),
49
+ frameworkDependencies: frameworkDependencies[options.framework],
50
+ };
48
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"create-files.d.ts","sourceRoot":"","sources":["../../../../../../../packages/node/src/generators/application/lib/create-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,IAAI,EACL,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,QA0DhE"}
1
+ {"version":3,"file":"create-files.d.ts","sourceRoot":"","sources":["../../../../../../../packages/node/src/generators/application/lib/create-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,IAAI,EACL,MAAM,YAAY,CAAC;AAKpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,QAgEhE"}
@@ -5,6 +5,7 @@ const devkit_1 = require("@nx/devkit");
5
5
  const js_1 = require("@nx/js");
6
6
  const path_1 = require("path");
7
7
  const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
8
+ const vscode_debug_config_1 = require("../../../utils/vscode-debug-config");
8
9
  function addAppFiles(tree, options) {
9
10
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, '../files/common'), options.appProjectRoot, {
10
11
  ...options,
@@ -40,4 +41,9 @@ function addAppFiles(tree, options) {
40
41
  if (options.js) {
41
42
  (0, devkit_1.toJS)(tree);
42
43
  }
44
+ // Generate a debug config for VS Code so that users can easily debug their application
45
+ (0, vscode_debug_config_1.addVSCodeDebugConfiguration)(tree, {
46
+ projectName: options.name,
47
+ projectRoot: options.appProjectRoot,
48
+ });
43
49
  }
@@ -1,4 +1,4 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { NormalizedSchema } from './normalized-schema';
3
- export declare function addProject(tree: Tree, options: NormalizedSchema): void;
3
+ export declare function addProject(tree: Tree, options: NormalizedSchema, frameworkDependencies: Record<string, string>): void;
4
4
  //# sourceMappingURL=create-project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-project.d.ts","sourceRoot":"","sources":["../../../../../../../packages/node/src/generators/application/lib/create-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,EAEL,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAQvD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,QAoD/D"}
1
+ {"version":3,"file":"create-project.d.ts","sourceRoot":"","sources":["../../../../../../../packages/node/src/generators/application/lib/create-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,EAEL,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AASvD,wBAAgB,UAAU,CACxB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,gBAAgB,EACzB,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QA0D9C"}
@@ -5,7 +5,7 @@ const devkit_1 = require("@nx/devkit");
5
5
  const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
6
6
  const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
7
7
  const create_targets_1 = require("./create-targets");
8
- function addProject(tree, options) {
8
+ function addProject(tree, options, frameworkDependencies) {
9
9
  const project = {
10
10
  root: options.appProjectRoot,
11
11
  sourceRoot: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src'),
@@ -28,11 +28,16 @@ function addProject(tree, options) {
28
28
  project.targets.build = (0, create_targets_1.getNestWebpackBuildConfig)();
29
29
  }
30
30
  }
31
+ project.targets = {
32
+ ...project.targets,
33
+ ...(0, create_targets_1.getPruneTargets)('build', options.outputPath),
34
+ };
31
35
  project.targets.serve = (0, create_targets_1.getServeConfig)(options);
32
36
  const packageJson = {
33
37
  name: options.importPath,
34
38
  version: '0.0.1',
35
39
  private: true,
40
+ dependencies: { ...frameworkDependencies },
36
41
  };
37
42
  if (!options.useProjectJson) {
38
43
  packageJson.nx = {
@@ -4,4 +4,9 @@ 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, outputPath: string): {
8
+ prune: TargetConfiguration;
9
+ 'prune-lockfile': TargetConfiguration;
10
+ 'copy-workspace-modules': TargetConfiguration;
11
+ };
7
12
  //# sourceMappingURL=create-targets.d.ts.map
@@ -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"}
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"}
@@ -4,8 +4,10 @@ exports.getWebpackBuildConfig = getWebpackBuildConfig;
4
4
  exports.getEsBuildConfig = getEsBuildConfig;
5
5
  exports.getServeConfig = getServeConfig;
6
6
  exports.getNestWebpackBuildConfig = getNestWebpackBuildConfig;
7
+ exports.getPruneTargets = getPruneTargets;
7
8
  const devkit_1 = require("@nx/devkit");
8
9
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
10
+ const js_1 = require("@nx/js");
9
11
  function getWebpackBuildConfig(tree, project, options) {
10
12
  const sourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(project, tree);
11
13
  return {
@@ -105,3 +107,35 @@ function getNestWebpackBuildConfig() {
105
107
  },
106
108
  };
107
109
  }
110
+ function getPruneTargets(buildTarget, outputPath) {
111
+ const lockFileName = (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)() ?? 'npm') ?? 'package-lock.json';
112
+ return {
113
+ 'prune-lockfile': {
114
+ dependsOn: ['build'],
115
+ cache: true,
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
+ ],
121
+ options: {
122
+ buildTarget,
123
+ },
124
+ },
125
+ 'copy-workspace-modules': {
126
+ dependsOn: ['build'],
127
+ cache: true,
128
+ outputs: [
129
+ `{workspaceRoot}/${(0, devkit_1.joinPathFragments)(outputPath, 'workspace_modules')}`,
130
+ ],
131
+ executor: '@nx/js:copy-workspace-modules',
132
+ options: {
133
+ buildTarget,
134
+ },
135
+ },
136
+ prune: {
137
+ dependsOn: ['prune-lockfile', 'copy-workspace-modules'],
138
+ executor: 'nx:noop',
139
+ },
140
+ };
141
+ }
@@ -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;
@@ -18,7 +18,7 @@
18
18
  "name": {
19
19
  "description": "The name of the application.",
20
20
  "type": "string",
21
- "pattern": "^[a-zA-Z][^:]*$",
21
+ "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$",
22
22
  "x-priority": "important"
23
23
  },
24
24
  "skipFormat": {
@@ -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 +1 @@
1
- {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/library/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EAUjB,IAAI,EAIL,MAAM,YAAY,CAAC;AAWpB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAQlC,MAAM,WAAW,gBAAiB,SAAQ,MAAM;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,uBAAuB,EAAE,OAAO,CAAC;CAClC;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BAMhE;AAED,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BA0ExE;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../../../../../packages/node/src/generators/library/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EAUjB,IAAI,EAIL,MAAM,YAAY,CAAC;AAWpB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AASlC,MAAM,WAAW,gBAAiB,SAAQ,MAAM;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,uBAAuB,EAAE,OAAO,CAAC;CAClC;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BAMhE;AAED,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BA0ExE;AAED,eAAe,gBAAgB,CAAC"}
@@ -92,7 +92,11 @@ async function normalizeOptions(tree, options) {
92
92
  const parsedTags = options.tags
93
93
  ? options.tags.split(',').map((s) => s.trim())
94
94
  : [];
95
- const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
95
+ // this helper is called before the jsLibraryGenerator is called, so, if the
96
+ // TS solution setup is not configured, we additionally check if the TS
97
+ // solution setup will be configured by the jsLibraryGenerator
98
+ const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree) ||
99
+ (0, ts_solution_setup_1.shouldConfigureTsSolutionSetup)(tree, options.addPlugin);
96
100
  return {
97
101
  ...options,
98
102
  fileName,
@@ -1,25 +1,28 @@
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
10
12
  ENV PORT=3000
13
+ <% if(packageManager === "pnpm" || packageManager === 'yarn') { %>
14
+ RUN corepack enable
15
+ <% } %>
11
16
 
12
17
  WORKDIR /app
13
18
 
14
- RUN addgroup --system <%= sanitizedProjectName %> && \
15
- adduser --system -G <%= sanitizedProjectName %> <%= sanitizedProjectName %>
16
-
17
- COPY <%= buildLocation %> <%= sanitizedProjectName %>/
18
- COPY <%= projectPath %>/package.json <%= sanitizedProjectName %>/
19
- RUN chown -R <%= sanitizedProjectName %>:<%= sanitizedProjectName %> .
19
+ COPY <%= buildLocation %> .
20
20
 
21
21
  # You can remove this install step if you build with `--bundle` option.
22
22
  # The bundled output will include external dependencies.
23
- RUN npm --prefix <%= sanitizedProjectName %> --omit=dev -f install
24
-
25
- CMD [ "node", "<%= sanitizedProjectName %>" ]
23
+ <% if(packageManager === 'npm') { %>
24
+ RUN npm --omit=dev -f install
25
+ <% } else { %>
26
+ RUN <%= packageManager %> install
27
+ <% } %>
28
+ CMD [ "node", "main.js" ]
@@ -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,EAML,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAsF9C,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,16 @@ 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");
8
+ const fs_1 = require("fs");
7
9
  function normalizeOptions(tree, setupOptions) {
8
10
  return {
9
11
  ...setupOptions,
10
12
  project: setupOptions.project ?? (0, devkit_1.readNxJson)(tree).defaultProject,
11
- targetName: setupOptions.targetName ?? 'docker-build',
13
+ targetName: setupOptions.targetName ?? 'docker:build',
12
14
  buildTarget: setupOptions.buildTarget ?? 'build',
15
+ skipDockerPlugin: setupOptions.skipDockerPlugin ?? false,
13
16
  };
14
17
  }
15
18
  function sanitizeProjectName(projectName) {
@@ -20,7 +23,11 @@ function sanitizeProjectName(projectName) {
20
23
  .replace(/-+/g, '-')
21
24
  .replace(/^-|-$/g, '');
22
25
  }
23
- function addDocker(tree, options) {
26
+ async function addDocker(tree, options) {
27
+ let installTask = () => { };
28
+ if (!options.skipDockerPlugin) {
29
+ installTask = await (0, generators_1.initGenerator)(tree, { skipFormat: true });
30
+ }
24
31
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
25
32
  const outputPath = projectConfig.targets[options.buildTarget]?.options['outputPath'];
26
33
  if (!projectConfig) {
@@ -30,29 +37,63 @@ function addDocker(tree, options) {
30
37
  throw new Error(`The output path for the project ${options.project} is not defined. Please provide it as an option to the generator.`);
31
38
  }
32
39
  const sanitizedProjectName = sanitizeProjectName(options.project);
40
+ const finalOutputPath = options.outputPath ?? outputPath;
41
+ // Calculate build location based on skipDockerPlugin flag
42
+ let buildLocation;
43
+ if (options.skipDockerPlugin) {
44
+ // Legacy mode: use workspace-relative paths
45
+ // docker target is set to run at project root, so ensure offset to workspace root
46
+ buildLocation = (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(projectConfig.root), finalOutputPath);
47
+ }
48
+ else {
49
+ // New mode: use project-relative paths
50
+ // Remove the project root prefix from the output path
51
+ const projectRootWithSlash = projectConfig.root + '/';
52
+ buildLocation = finalOutputPath.startsWith(projectRootWithSlash)
53
+ ? finalOutputPath.substring(projectRootWithSlash.length)
54
+ : finalOutputPath.startsWith(projectConfig.root)
55
+ ? finalOutputPath.substring(projectConfig.root.length)
56
+ : 'dist';
57
+ }
58
+ const packageManager = (0, fs_1.existsSync)(projectConfig.root)
59
+ ? (0, devkit_1.detectPackageManager)(projectConfig.root)
60
+ : (0, devkit_1.detectPackageManager)(devkit_1.workspaceRoot);
33
61
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), projectConfig.root, {
34
62
  tmpl: '',
35
- buildLocation: options.outputPath ?? outputPath,
63
+ buildLocation,
36
64
  project: options.project,
37
65
  projectPath: projectConfig.root,
38
66
  sanitizedProjectName,
67
+ skipDockerPlugin: options.skipDockerPlugin,
68
+ packageManager,
39
69
  });
70
+ return installTask;
40
71
  }
41
72
  function updateProjectConfig(tree, options) {
42
73
  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
- };
74
+ if (options.skipDockerPlugin) {
75
+ // Use sanitized project name for Docker image tag
76
+ const sanitizedProjectName = sanitizeProjectName(options.project);
77
+ projectConfig.targets[`${options.targetName}`] = {
78
+ dependsOn: [`${options.buildTarget}`, 'prune'],
79
+ command: `docker build . -t ${sanitizedProjectName}`,
80
+ options: {
81
+ cwd: projectConfig.root,
82
+ },
83
+ };
84
+ }
85
+ else {
86
+ projectConfig.targets[`${options.targetName}`] = {
87
+ dependsOn: [`${options.buildTarget}`, 'prune'],
88
+ };
89
+ }
49
90
  (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
50
91
  }
51
92
  async function setupDockerGenerator(tree, setupOptions) {
52
93
  const tasks = [];
53
94
  const options = normalizeOptions(tree, setupOptions);
54
- // Should check if the node project exists
55
- addDocker(tree, options);
95
+ const installTask = await addDocker(tree, options);
96
+ tasks.push(installTask);
56
97
  updateProjectConfig(tree, options);
57
98
  if (!options.skipFormat) {
58
99
  await (0, devkit_1.formatFiles)(tree);
@@ -0,0 +1,8 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export interface VSCodeDebugConfigOptions {
3
+ projectName: string;
4
+ projectRoot: string;
5
+ packageManager?: string;
6
+ }
7
+ export declare function addVSCodeDebugConfiguration(tree: Tree, options: VSCodeDebugConfigOptions): void;
8
+ //# sourceMappingURL=vscode-debug-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vscode-debug-config.d.ts","sourceRoot":"","sources":["../../../../../packages/node/src/utils/vscode-debug-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAKL,MAAM,YAAY,CAAC;AA+BpB,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,wBAAwB,GAChC,IAAI,CAwDN"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addVSCodeDebugConfiguration = addVSCodeDebugConfiguration;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function findFreeDebugPort(tree) {
6
+ let highestPort = 0;
7
+ // Check existing launch.json configurations for used debug ports
8
+ if (tree.exists('.vscode/launch.json')) {
9
+ try {
10
+ const launchConfig = JSON.parse(tree.read('.vscode/launch.json', 'utf-8'));
11
+ if (launchConfig.configurations) {
12
+ for (const config of launchConfig.configurations) {
13
+ if (config.env && config.env.NODE_OPTIONS) {
14
+ const match = config.env.NODE_OPTIONS.match(/--inspect=(\d+)/);
15
+ if (match) {
16
+ const currentPort = parseInt(match[1]);
17
+ highestPort = Math.max(highestPort, currentPort);
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
23
+ catch {
24
+ // Ignore parsing errors
25
+ }
26
+ }
27
+ // Return the next available port after the highest used port, or 9229 if none are used
28
+ return highestPort > 0 ? highestPort + 1 : 9229;
29
+ }
30
+ function addVSCodeDebugConfiguration(tree, options) {
31
+ const pmCommand = (0, devkit_1.getPackageManagerCommand)().exec;
32
+ // Determine the output path based on project configuration
33
+ let outputPath;
34
+ try {
35
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
36
+ outputPath = projectConfig.targets?.build?.options?.outputPath;
37
+ }
38
+ catch {
39
+ outputPath = undefined;
40
+ }
41
+ // If no outputPath is configured, assume it's in the project directory
42
+ if (!outputPath) {
43
+ outputPath = `${options.projectRoot}/dist`;
44
+ }
45
+ // Find a free debug port to avoid conflicts
46
+ const debugPort = findFreeDebugPort(tree);
47
+ const debugConfig = {
48
+ type: 'node',
49
+ request: 'launch',
50
+ name: `Debug ${options.projectName} with Nx`,
51
+ runtimeExecutable: pmCommand,
52
+ runtimeArgs: ['nx', 'serve', options.projectName],
53
+ env: {
54
+ NODE_OPTIONS: `--inspect=${debugPort}`,
55
+ },
56
+ console: 'integratedTerminal',
57
+ internalConsoleOptions: 'neverOpen',
58
+ skipFiles: ['<node_internals>/**'],
59
+ sourceMaps: true,
60
+ outFiles: [
61
+ `\${workspaceFolder}/${outputPath}/**/*.(m|c|)js`,
62
+ '!**/node_modules/**',
63
+ ],
64
+ };
65
+ if (!tree.exists('.vscode/launch.json')) {
66
+ // Create launch.json with the configuration
67
+ (0, devkit_1.writeJson)(tree, '.vscode/launch.json', {
68
+ version: '0.2.0',
69
+ configurations: [debugConfig],
70
+ });
71
+ }
72
+ else {
73
+ // Add configuration to existing launch.json
74
+ (0, devkit_1.updateJson)(tree, '.vscode/launch.json', (json) => {
75
+ if (!json.configurations) {
76
+ json.configurations = [];
77
+ }
78
+ json.configurations.push(debugConfig);
79
+ return json;
80
+ });
81
+ }
82
+ }