@nx/node 17.0.3 → 17.0.5

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 (29) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -4
  3. package/migrations.json +20 -1
  4. package/package.json +6 -6
  5. package/src/generators/application/application.d.ts +2 -2
  6. package/src/generators/application/application.js +65 -10
  7. package/src/generators/application/files/common/webpack.config.js__tmpl__ +32 -5
  8. package/src/generators/application/files/fastify/src/app/app.ts__tmpl__ +1 -1
  9. package/src/generators/application/files/fastify/src/app/plugins/sensible.ts__tmpl__ +1 -1
  10. package/src/generators/application/files/fastify/src/app/routes/root.ts__tmpl__ +2 -2
  11. package/src/generators/application/schema.d.ts +1 -0
  12. package/src/generators/application/schema.json +1 -1
  13. package/src/generators/e2e-project/e2e-project.js +11 -1
  14. package/src/generators/e2e-project/files/server/common/src/__fileName__/__fileName__.spec.ts__tmpl__ +1 -1
  15. package/src/generators/e2e-project/files/server/nest/src/__fileName__/__fileName__.spec.ts__tmpl__ +1 -1
  16. package/src/generators/e2e-project/schema.d.ts +1 -0
  17. package/src/generators/e2e-project/schema.json +1 -1
  18. package/src/generators/init/init.d.ts +1 -1
  19. package/src/generators/init/init.js +10 -25
  20. package/src/generators/init/schema.d.ts +2 -3
  21. package/src/generators/init/schema.json +10 -10
  22. package/src/generators/library/library.js +13 -1
  23. package/src/generators/library/schema.d.ts +1 -0
  24. package/src/generators/library/schema.json +1 -1
  25. package/src/generators/setup-docker/schema.json +1 -1
  26. package/src/utils/has-webpack-plugin.d.ts +2 -0
  27. package/src/utils/has-webpack-plugin.js +11 -0
  28. package/src/utils/versions.d.ts +2 -2
  29. package/src/utils/versions.js +2 -2
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2023 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2024 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/README.md CHANGED
@@ -1,4 +1,9 @@
1
- <p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
1
+ <p style="text-align: center;">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
+ <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
+ </picture>
6
+ </p>
2
7
 
3
8
  <div style="text-align: center;">
4
9
 
@@ -15,9 +20,9 @@
15
20
 
16
21
  <hr>
17
22
 
18
- # Nx: Smart, Fast and Extensible Build System
23
+ # Nx: Smart Monorepos · Fast CI
19
24
 
20
- Nx is a next generation build system with first class monorepo support and powerful integrations.
25
+ Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
21
26
 
22
27
  ## Getting Started
23
28
 
@@ -57,5 +62,5 @@ npx nx@latest init
57
62
  - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
58
63
 
59
64
  <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
60
- width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
65
+ width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
61
66
 
package/migrations.json CHANGED
@@ -25,5 +25,24 @@
25
25
  "implementation": "./src/migrations/update-16-4-0/replace-node-executor"
26
26
  }
27
27
  },
28
- "packageJsonUpdates": {}
28
+ "packageJsonUpdates": {
29
+ "17.3.0": {
30
+ "version": "17.3.0-beta.3",
31
+ "packages": {
32
+ "@types/node": {
33
+ "version": "18.16.9",
34
+ "alwaysAddToPackageJson": false
35
+ }
36
+ }
37
+ },
38
+ "17.3.1": {
39
+ "version": "17.3.1-beta.0",
40
+ "packages": {
41
+ "axios": {
42
+ "version": "^1.6.0",
43
+ "alwaysAddToPackageJson": false
44
+ }
45
+ }
46
+ }
47
+ }
29
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/node",
3
- "version": "17.0.3",
3
+ "version": "17.0.5",
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": {
@@ -31,11 +31,11 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "tslib": "^2.3.0",
34
- "@nx/devkit": "17.0.3",
35
- "@nx/jest": "17.0.3",
36
- "@nx/js": "17.0.3",
37
- "@nx/eslint": "17.0.3",
38
- "@nrwl/node": "17.0.3"
34
+ "@nx/devkit": "17.0.5",
35
+ "@nx/jest": "17.0.5",
36
+ "@nx/js": "17.0.5",
37
+ "@nx/eslint": "17.0.5",
38
+ "@nrwl/node": "17.0.5"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
@@ -5,6 +5,6 @@ export interface NormalizedSchema extends Schema {
5
5
  parsedTags: string[];
6
6
  }
7
7
  export declare function addLintingToApplication(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
8
- export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<any>;
9
- export declare function applicationGeneratorInternal(tree: Tree, schema: Schema): Promise<any>;
8
+ export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
9
+ export declare function applicationGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
10
10
  export default applicationGenerator;
@@ -7,12 +7,14 @@ const jest_1 = require("@nx/jest");
7
7
  const js_1 = require("@nx/js");
8
8
  const versions_1 = require("@nx/js/src/utils/versions");
9
9
  const eslint_1 = require("@nx/eslint");
10
- const lint_project_1 = require("@nx/eslint/src/generators/lint-project/lint-project");
11
10
  const path_1 = require("path");
12
11
  const versions_2 = require("../../utils/versions");
13
12
  const e2e_project_1 = require("../e2e-project/e2e-project");
14
13
  const init_1 = require("../init/init");
15
14
  const setup_docker_1 = require("../setup-docker/setup-docker");
15
+ const has_webpack_plugin_1 = require("../../utils/has-webpack-plugin");
16
+ const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
17
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
16
18
  function getWebpackBuildConfig(project, options) {
17
19
  return {
18
20
  executor: `@nx/webpack:webpack`,
@@ -25,7 +27,6 @@ function getWebpackBuildConfig(project, options) {
25
27
  main: (0, devkit_1.joinPathFragments)(project.sourceRoot, 'main' + (options.js ? '.js' : '.ts')),
26
28
  tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
27
29
  assets: [(0, devkit_1.joinPathFragments)(project.sourceRoot, 'assets')],
28
- isolatedConfig: true,
29
30
  webpackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'),
30
31
  },
31
32
  configurations: {
@@ -95,14 +96,21 @@ function addProject(tree, options) {
95
96
  targets: {},
96
97
  tags: options.parsedTags,
97
98
  };
98
- project.targets.build =
99
- options.bundler === 'esbuild'
100
- ? getEsBuildConfig(project, options)
101
- : getWebpackBuildConfig(project, options);
99
+ if (options.bundler === 'esbuild') {
100
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, '@nx/esbuild:esbuild');
101
+ project.targets.build = getEsBuildConfig(project, options);
102
+ }
103
+ else if (options.bundler === 'webpack') {
104
+ if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) {
105
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, `@nx/webpack:webpack`);
106
+ project.targets.build = getWebpackBuildConfig(project, options);
107
+ }
108
+ }
102
109
  project.targets.serve = getServeConfig(options);
103
110
  (0, devkit_1.addProjectConfiguration)(tree, options.name, project, options.standaloneConfig);
104
111
  }
105
112
  function addAppFiles(tree, options) {
113
+ const sourceRoot = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src');
106
114
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/common'), options.appProjectRoot, {
107
115
  ...options,
108
116
  tmpl: '',
@@ -110,6 +118,14 @@ function addAppFiles(tree, options) {
110
118
  root: options.appProjectRoot,
111
119
  offset: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
112
120
  rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
121
+ webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)
122
+ ? {
123
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.rootProject ? options.name : options.appProjectRoot),
124
+ main: './src/main' + (options.js ? '.js' : '.ts'),
125
+ tsConfig: './tsconfig.app.json',
126
+ assets: ['./src/assets'],
127
+ }
128
+ : null,
113
129
  });
114
130
  if (options.bundler !== 'webpack') {
115
131
  tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'));
@@ -169,13 +185,11 @@ async function addLintingToApplication(tree, options) {
169
185
  tsConfigPaths: [
170
186
  (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
171
187
  ],
172
- eslintFilePatterns: [
173
- (0, lint_project_1.mapLintPattern)(options.appProjectRoot, options.js ? 'js' : 'ts', options.rootProject),
174
- ],
175
188
  unitTestRunner: options.unitTestRunner,
176
189
  skipFormat: true,
177
190
  setParserOptionsProject: options.setParserOptionsProject,
178
191
  rootProject: options.rootProject,
192
+ addPlugin: options.addPlugin,
179
193
  });
180
194
  return lintTask;
181
195
  }
@@ -215,9 +229,11 @@ function addProjectDependencies(tree, options) {
215
229
  };
216
230
  return (0, devkit_1.addDependenciesToPackageJson)(tree, {
217
231
  ...frameworkDependencies[options.framework],
232
+ tslib: versions_2.tslibVersion,
218
233
  }, {
219
234
  ...frameworkDevDependencies[options.framework],
220
235
  ...bundlers[options.bundler],
236
+ '@types/node': versions_2.typesNodeVersion,
221
237
  });
222
238
  }
223
239
  function updateTsConfigOptions(tree, options) {
@@ -247,6 +263,7 @@ function updateTsConfigOptions(tree, options) {
247
263
  }
248
264
  async function applicationGenerator(tree, schema) {
249
265
  return await applicationGeneratorInternal(tree, {
266
+ addPlugin: false,
250
267
  projectNameAndRootFormat: 'derived',
251
268
  ...schema,
252
269
  });
@@ -256,9 +273,25 @@ async function applicationGeneratorInternal(tree, schema) {
256
273
  const options = await normalizeOptions(tree, schema);
257
274
  const tasks = [];
258
275
  if (options.framework === 'nest') {
276
+ // nx-ignore-next-line
259
277
  const { applicationGenerator } = (0, devkit_1.ensurePackage)('@nx/nest', versions_2.nxVersion);
260
- return await applicationGenerator(tree, { ...options, skipFormat: true });
278
+ const nestTasks = await applicationGenerator(tree, {
279
+ ...options,
280
+ skipFormat: true,
281
+ });
282
+ return (0, devkit_1.runTasksInSerial)(...[
283
+ nestTasks,
284
+ () => {
285
+ (0, log_show_project_command_1.logShowProjectCommand)(options.name);
286
+ },
287
+ ]);
261
288
  }
289
+ const jsInitTask = await (0, js_1.initGenerator)(tree, {
290
+ ...schema,
291
+ tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
292
+ skipFormat: true,
293
+ });
294
+ tasks.push(jsInitTask);
262
295
  const initTask = await (0, init_1.initGenerator)(tree, {
263
296
  ...schema,
264
297
  skipFormat: true,
@@ -266,6 +299,21 @@ async function applicationGeneratorInternal(tree, schema) {
266
299
  tasks.push(initTask);
267
300
  const installTask = addProjectDependencies(tree, options);
268
301
  tasks.push(installTask);
302
+ if (options.bundler === 'webpack') {
303
+ const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_2.nxVersion);
304
+ const webpackInitTask = await webpackInitGenerator(tree, {
305
+ skipPackageJson: options.skipPackageJson,
306
+ skipFormat: true,
307
+ addPlugin: options.addPlugin,
308
+ });
309
+ tasks.push(webpackInitTask);
310
+ if (!options.skipPackageJson) {
311
+ const { ensureDependencies } = await Promise.resolve().then(() => require('@nx/webpack/src/utils/ensure-dependencies'));
312
+ tasks.push(ensureDependencies(tree, {
313
+ uiFramework: options.isNest ? 'none' : 'react',
314
+ }));
315
+ }
316
+ }
269
317
  addAppFiles(tree, options);
270
318
  addProject(tree, options);
271
319
  updateTsConfigOptions(tree, options);
@@ -321,6 +369,9 @@ async function applicationGeneratorInternal(tree, schema) {
321
369
  if (!options.skipFormat) {
322
370
  await (0, devkit_1.formatFiles)(tree);
323
371
  }
372
+ tasks.push(() => {
373
+ (0, log_show_project_command_1.logShowProjectCommand)(options.name);
374
+ });
324
375
  return (0, devkit_1.runTasksInSerial)(...tasks);
325
376
  }
326
377
  exports.applicationGeneratorInternal = applicationGeneratorInternal;
@@ -340,7 +391,11 @@ async function normalizeOptions(host, options) {
340
391
  const parsedTags = options.tags
341
392
  ? options.tags.split(',').map((s) => s.trim())
342
393
  : [];
394
+ const nxJson = (0, devkit_1.readNxJson)(host);
395
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
396
+ nxJson.useInferencePlugins !== false;
343
397
  return {
398
+ addPlugin,
344
399
  ...options,
345
400
  name: appProjectName,
346
401
  frontendProject: options.frontendProject
@@ -1,8 +1,35 @@
1
+ <% if (webpackPluginOptions) { %>
2
+ const { NxWebpackPlugin } = require('@nx/webpack');
3
+ const { join } = require('path');
4
+
5
+ module.exports = {
6
+ output: {
7
+ path: join(__dirname, '<%= offset %><%= webpackPluginOptions.outputPath %>'),
8
+ },
9
+ plugins: [
10
+ new NxWebpackPlugin({
11
+ target: 'node',
12
+ compiler: 'tsc',
13
+ main: '<%= webpackPluginOptions.main %>',
14
+ tsConfig: '<%= webpackPluginOptions.tsConfig %>',
15
+ assets: <%- JSON.stringify(webpackPluginOptions.assets) %>,
16
+ optimization: false,
17
+ outputHashing: 'none',
18
+ })
19
+ ],
20
+ };
21
+ <% } else { %>
1
22
  const { composePlugins, withNx} = require('@nx/webpack');
2
23
 
3
24
  // Nx plugins for webpack.
4
- module.exports = composePlugins(withNx(), (config) => {
5
- // Update the webpack config as needed here.
6
- // e.g. `config.plugins.push(new MyPlugin())`
7
- return config;
8
- });
25
+ module.exports = composePlugins(
26
+ withNx({
27
+ target: 'node',
28
+ }),
29
+ (config) => {
30
+ // Update the webpack config as needed here.
31
+ // e.g. `config.plugins.push(new MyPlugin())`
32
+ return config;
33
+ }
34
+ );
35
+ <% } %>
@@ -1,5 +1,5 @@
1
1
  import * as path from 'path';
2
- import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
2
+ import { FastifyInstance } from 'fastify';
3
3
  import AutoLoad from '@fastify/autoload';
4
4
 
5
5
  /* eslint-disable-next-line */
@@ -1,4 +1,4 @@
1
- import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
1
+ import { FastifyInstance } from 'fastify';
2
2
  import fp from 'fastify-plugin';
3
3
  import sensible from '@fastify/sensible';
4
4
 
@@ -1,7 +1,7 @@
1
- import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
1
+ import { FastifyInstance } from 'fastify';
2
2
 
3
3
  export default async function(fastify: FastifyInstance) {
4
- fastify.get('/', async function(request: FastifyRequest, reply: FastifyReply) {
4
+ fastify.get('/', async function() {
5
5
  return { message: 'Hello API' };
6
6
  });
7
7
  }
@@ -25,6 +25,7 @@ export interface Schema {
25
25
  rootProject?: boolean;
26
26
  docker?: boolean;
27
27
  isNest?: boolean;
28
+ addPlugin?: boolean;
28
29
  }
29
30
 
30
31
  export type NodeJsFrameWorks = 'express' | 'koa' | 'fastify' | 'nest' | 'none';
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "SchematicsNxNodeApp",
5
5
  "title": "Nx Application Options Schema",
@@ -8,8 +8,10 @@ const global_eslint_config_1 = require("@nx/eslint/src/generators/init/global-es
8
8
  const path = require("path");
9
9
  const versions_1 = require("../../utils/versions");
10
10
  const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
11
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
11
12
  async function e2eProjectGenerator(host, options) {
12
13
  return await e2eProjectGeneratorInternal(host, {
14
+ addPlugin: false,
13
15
  projectNameAndRootFormat: 'derived',
14
16
  ...options,
15
17
  });
@@ -19,6 +21,7 @@ async function e2eProjectGeneratorInternal(host, _options) {
19
21
  const tasks = [];
20
22
  const options = await normalizeOptions(host, _options);
21
23
  const appProject = (0, devkit_1.readProjectConfiguration)(host, options.project);
24
+ // TODO(@ndcunningham): This is broken.. the outputs are wrong.. and this isn't using the jest generator
22
25
  (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
23
26
  root: options.e2eProjectRoot,
24
27
  implicitDependencies: [options.project],
@@ -71,10 +74,10 @@ async function e2eProjectGeneratorInternal(host, _options) {
71
74
  tsConfigPaths: [
72
75
  (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'tsconfig.json'),
73
76
  ],
74
- eslintFilePatterns: [`${options.e2eProjectRoot}/**/*.{js,ts}`],
75
77
  setParserOptionsProject: false,
76
78
  skipPackageJson: false,
77
79
  rootProject: options.rootProject,
80
+ addPlugin: options.addPlugin,
78
81
  });
79
82
  tasks.push(linterTask);
80
83
  if (options.rootProject && (0, eslint_file_1.isEslintConfigSupported)(host)) {
@@ -88,6 +91,9 @@ async function e2eProjectGeneratorInternal(host, _options) {
88
91
  if (!options.skipFormat) {
89
92
  await (0, devkit_1.formatFiles)(host);
90
93
  }
94
+ tasks.push(() => {
95
+ (0, log_show_project_command_1.logShowProjectCommand)(options.e2eProjectName);
96
+ });
91
97
  return (0, devkit_1.runTasksInSerial)(...tasks);
92
98
  }
93
99
  exports.e2eProjectGeneratorInternal = e2eProjectGeneratorInternal;
@@ -102,7 +108,11 @@ async function normalizeOptions(tree, options) {
102
108
  // this is an internal generator, don't save defaults
103
109
  callingGenerator: null,
104
110
  });
111
+ const nxJson = (0, devkit_1.readNxJson)(tree);
112
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
113
+ nxJson.useInferencePlugins !== false;
105
114
  return {
115
+ addPlugin,
106
116
  ...options,
107
117
  e2eProjectRoot,
108
118
  e2eProjectName,
@@ -4,7 +4,7 @@ describe('GET /', () => {
4
4
  it('should return a message', async () => {
5
5
  const res = await axios.get(`/`);
6
6
 
7
- expect(res.status).toBe(200);;
7
+ expect(res.status).toBe(200);
8
8
  expect(res.data).toEqual({ message: 'Hello API' });
9
9
  });
10
10
  })
@@ -4,7 +4,7 @@ describe('GET /api', () => {
4
4
  it('should return a message', async () => {
5
5
  const res = await axios.get(`/api`);
6
6
 
7
- expect(res.status).toBe(200);;
7
+ expect(res.status).toBe(200);
8
8
  expect(res.data).toEqual({ message: 'Hello API' });
9
9
  });
10
10
  })
@@ -11,4 +11,5 @@ export interface Schema {
11
11
  rootProject?: boolean;
12
12
  isNest?: boolean;
13
13
  skipFormat?: boolean;
14
+ addPlugin?: boolean;
14
15
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "SchematicsNxNodeE2eProject",
5
5
  "title": "Node E2E Project Generator",
@@ -1,4 +1,4 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
- export declare function initGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
3
+ export declare function initGenerator(tree: Tree, options: Schema): Promise<GeneratorCallback>;
4
4
  export default initGenerator;
@@ -2,37 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const jest_1 = require("@nx/jest");
6
- const js_1 = require("@nx/js");
7
5
  const versions_1 = require("../../utils/versions");
8
- function updateDependencies(tree) {
9
- (0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@nx/node'], []);
10
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {
11
- tslib: versions_1.tslibVersion,
12
- }, { '@nx/node': versions_1.nxVersion, '@types/node': versions_1.typesNodeVersion });
13
- }
14
- function normalizeOptions(schema) {
15
- return {
16
- ...schema,
17
- unitTestRunner: schema.unitTestRunner ?? 'jest',
18
- };
19
- }
20
- async function initGenerator(tree, schema) {
21
- const options = normalizeOptions(schema);
6
+ function updateDependencies(tree, options) {
22
7
  const tasks = [];
23
- tasks.push(await (0, js_1.initGenerator)(tree, {
24
- ...schema,
25
- tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
26
- skipFormat: true,
27
- }));
28
- if (options.unitTestRunner === 'jest') {
29
- tasks.push(await (0, jest_1.jestInitGenerator)(tree, { ...schema, testEnvironment: 'node' }));
8
+ tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@nx/node'], []));
9
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/node': versions_1.nxVersion }, undefined, options.keepExistingVersions));
10
+ return (0, devkit_1.runTasksInSerial)(...tasks);
11
+ }
12
+ async function initGenerator(tree, options) {
13
+ let installTask = () => { };
14
+ if (!options.skipPackageJson) {
15
+ installTask = updateDependencies(tree, options);
30
16
  }
31
- tasks.push(updateDependencies(tree));
32
17
  if (!options.skipFormat) {
33
18
  await (0, devkit_1.formatFiles)(tree);
34
19
  }
35
- return (0, devkit_1.runTasksInSerial)(...tasks);
20
+ return installTask;
36
21
  }
37
22
  exports.initGenerator = initGenerator;
38
23
  exports.default = initGenerator;
@@ -1,6 +1,5 @@
1
1
  export interface Schema {
2
- unitTestRunner?: 'jest' | 'none';
3
2
  skipFormat?: boolean;
4
- js?: boolean;
5
- rootProject?: boolean;
3
+ skipPackageJson?: boolean;
4
+ keepExistingVersions?: boolean;
6
5
  }
@@ -1,26 +1,26 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxNodeInit",
5
5
  "title": "Init Node Plugin",
6
6
  "description": "Init Node Plugin.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "unitTestRunner": {
10
- "description": "Adds the specified unit test runner.",
11
- "type": "string",
12
- "enum": ["jest", "none"],
13
- "default": "jest"
14
- },
15
9
  "skipFormat": {
16
10
  "description": "Skip formatting files.",
17
11
  "type": "boolean",
18
12
  "default": false
19
13
  },
20
- "js": {
14
+ "skipPackageJson": {
15
+ "description": "Do not add dependencies to `package.json`.",
21
16
  "type": "boolean",
22
- "default": false,
23
- "description": "Use JavaScript instead of TypeScript"
17
+ "default": false
18
+ },
19
+ "keepExistingVersions": {
20
+ "type": "boolean",
21
+ "x-priority": "internal",
22
+ "description": "Keep existing dependencies versions",
23
+ "default": false
24
24
  }
25
25
  },
26
26
  "required": []
@@ -7,9 +7,12 @@ const js_1 = require("@nx/js");
7
7
  const add_swc_config_1 = require("@nx/js/src/utils/swc/add-swc-config");
8
8
  const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
9
9
  const path_1 = require("path");
10
+ const versions_1 = require("../../utils/versions");
10
11
  const init_1 = require("../init/init");
12
+ const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
11
13
  async function libraryGenerator(tree, schema) {
12
14
  return await libraryGeneratorInternal(tree, {
15
+ addPlugin: false,
13
16
  projectNameAndRootFormat: 'derived',
14
17
  ...schema,
15
18
  });
@@ -27,7 +30,7 @@ async function libraryGeneratorInternal(tree, schema) {
27
30
  throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
28
31
  }
29
32
  const libraryInstall = await (0, js_1.libraryGenerator)(tree, {
30
- ...schema,
33
+ ...options,
31
34
  bundler: schema.buildable ? 'tsc' : 'none',
32
35
  includeBabelRc: schema.babelJest,
33
36
  importPath: options.importPath,
@@ -41,6 +44,7 @@ async function libraryGeneratorInternal(tree, schema) {
41
44
  (0, devkit_1.updateTsConfigsToJs)(tree, options);
42
45
  }
43
46
  updateProject(tree, options);
47
+ tasks.push(ensureDependencies(tree));
44
48
  if (!schema.skipFormat) {
45
49
  await (0, devkit_1.formatFiles)(tree);
46
50
  }
@@ -58,6 +62,10 @@ async function normalizeOptions(tree, options) {
58
62
  callingGenerator: '@nx/node:library',
59
63
  });
60
64
  options.projectNameAndRootFormat = projectNameAndRootFormat;
65
+ const nxJson = (0, devkit_1.readNxJson)(tree);
66
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
67
+ nxJson.useInferencePlugins !== false;
68
+ options.addPlugin ??= addPluginDefault;
61
69
  const fileName = getCaseAwareFileName({
62
70
  fileName: options.simpleModuleName
63
71
  ? projectNames.projectSimpleName
@@ -107,6 +115,7 @@ function updateProject(tree, options) {
107
115
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
108
116
  const rootProject = options.projectRoot === '.' || options.projectRoot === '';
109
117
  project.targets = project.targets || {};
118
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, `@nx/js:${options.compiler}`);
110
119
  project.targets.build = {
111
120
  executor: `@nx/js:${options.compiler}`,
112
121
  outputs: ['{options.outputPath}'],
@@ -127,3 +136,6 @@ function updateProject(tree, options) {
127
136
  }
128
137
  (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
129
138
  }
139
+ function ensureDependencies(tree) {
140
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, { tslib: versions_1.tslibVersion }, { '@types/node': versions_1.typesNodeVersion });
141
+ }
@@ -23,4 +23,5 @@ export interface Schema {
23
23
  standaloneConfig?: boolean;
24
24
  setParserOptionsProject?: boolean;
25
25
  compiler: 'tsc' | 'swc';
26
+ addPlugin?: boolean;
26
27
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxNodeLibrary",
5
5
  "title": "Create a Node Library for Nx",
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "SchematicsNxSetupDocker",
5
5
  "title": "Nx Node Docker Options Schema",
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function hasWebpackPlugin(tree: Tree): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasWebpackPlugin = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function hasWebpackPlugin(tree) {
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
7
+ return !!nxJson.plugins?.some((p) => typeof p === 'string'
8
+ ? p === '@nx/webpack/plugin'
9
+ : p.plugin === '@nx/webpack/plugin');
10
+ }
11
+ exports.hasWebpackPlugin = hasWebpackPlugin;
@@ -1,6 +1,6 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const tslibVersion = "^2.3.0";
3
- export declare const typesNodeVersion = "~18.7.1";
3
+ export declare const typesNodeVersion = "~18.16.9";
4
4
  export declare const expressVersion = "~4.18.1";
5
5
  export declare const expressTypingsVersion = "~4.17.13";
6
6
  export declare const koaVersion = "~2.14.1";
@@ -9,4 +9,4 @@ export declare const fastifyVersion = "~4.13.0";
9
9
  export declare const fastifyAutoloadVersion = "~5.7.1";
10
10
  export declare const fastifySensibleVersion = "~5.2.0";
11
11
  export declare const fastifyPluginVersion = "~4.5.0";
12
- export declare const axiosVersion = "^1.0.0";
12
+ export declare const axiosVersion = "^1.6.0";
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.axiosVersion = exports.fastifyPluginVersion = exports.fastifySensibleVersion = exports.fastifyAutoloadVersion = exports.fastifyVersion = exports.koaTypingsVersion = exports.koaVersion = exports.expressTypingsVersion = exports.expressVersion = exports.typesNodeVersion = exports.tslibVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
5
  exports.tslibVersion = '^2.3.0';
6
- exports.typesNodeVersion = '~18.7.1';
6
+ exports.typesNodeVersion = '~18.16.9';
7
7
  exports.expressVersion = '~4.18.1';
8
8
  exports.expressTypingsVersion = '~4.17.13';
9
9
  exports.koaVersion = '~2.14.1';
@@ -12,4 +12,4 @@ exports.fastifyVersion = '~4.13.0';
12
12
  exports.fastifyAutoloadVersion = '~5.7.1';
13
13
  exports.fastifySensibleVersion = '~5.2.0';
14
14
  exports.fastifyPluginVersion = '~4.5.0';
15
- exports.axiosVersion = '^1.0.0';
15
+ exports.axiosVersion = '^1.6.0';