@nx/node 20.5.0-rc.4 → 20.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/node",
3
- "version": "20.5.0-rc.4",
3
+ "version": "20.6.0-beta.0",
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,10 +32,10 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "tslib": "^2.3.0",
35
- "@nx/devkit": "20.5.0-rc.4",
36
- "@nx/jest": "20.5.0-rc.4",
37
- "@nx/js": "20.5.0-rc.4",
38
- "@nx/eslint": "20.5.0-rc.4"
35
+ "@nx/devkit": "20.6.0-beta.0",
36
+ "@nx/jest": "20.6.0-beta.0",
37
+ "@nx/js": "20.6.0-beta.0",
38
+ "@nx/eslint": "20.6.0-beta.0"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
@@ -137,21 +137,24 @@ function addProject(tree, options) {
137
137
  }
138
138
  }
139
139
  project.targets.serve = getServeConfig(options);
140
- if (options.isUsingTsSolutionConfig) {
141
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
142
- name: options.importPath,
143
- version: '0.0.1',
144
- private: true,
145
- nx: {
146
- name: options.name !== options.importPath ? options.name : undefined,
147
- targets: project.targets,
148
- tags: project.tags?.length ? project.tags : undefined,
149
- },
150
- });
140
+ const packageJson = {
141
+ name: options.importPath,
142
+ version: '0.0.1',
143
+ private: true,
144
+ };
145
+ if (!options.useProjectJson) {
146
+ packageJson.nx = {
147
+ name: options.name !== options.importPath ? options.name : undefined,
148
+ targets: project.targets,
149
+ tags: project.tags?.length ? project.tags : undefined,
150
+ };
151
151
  }
152
152
  else {
153
153
  (0, devkit_1.addProjectConfiguration)(tree, options.name, project, options.standaloneConfig);
154
154
  }
155
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
156
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
157
+ }
155
158
  }
156
159
  function addAppFiles(tree, options) {
157
160
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/common'), options.appProjectRoot, {
@@ -311,6 +314,7 @@ function updateTsConfigOptions(tree, options) {
311
314
  async function applicationGenerator(tree, schema) {
312
315
  return await applicationGeneratorInternal(tree, {
313
316
  addPlugin: false,
317
+ useProjectJson: true,
314
318
  ...schema,
315
319
  });
316
320
  }
@@ -374,7 +378,7 @@ async function applicationGeneratorInternal(tree, schema) {
374
378
  // If we are using the new TS solution
375
379
  // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
376
380
  if (options.isUsingTsSolutionConfig) {
377
- (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
381
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
378
382
  }
379
383
  updateTsConfigOptions(tree, options);
380
384
  if (options.linter === eslint_1.Linter.EsLint) {
@@ -469,6 +473,7 @@ async function normalizeOptions(host, options) {
469
473
  const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
470
474
  const swcJest = options.swcJest ?? isUsingTsSolutionConfig;
471
475
  const appProjectName = !isUsingTsSolutionConfig || options.name ? projectName : importPath;
476
+ const useProjectJson = options.useProjectJson ?? !isUsingTsSolutionConfig;
472
477
  return {
473
478
  addPlugin,
474
479
  ...options,
@@ -488,6 +493,7 @@ async function normalizeOptions(host, options) {
488
493
  : (0, devkit_1.joinPathFragments)('dist', options.rootProject ? appProjectName : appProjectRoot),
489
494
  isUsingTsSolutionConfig,
490
495
  swcJest,
496
+ useProjectJson,
491
497
  };
492
498
  }
493
499
  exports.default = applicationGenerator;
@@ -25,6 +25,7 @@ export interface Schema {
25
25
  isNest?: boolean;
26
26
  addPlugin?: boolean;
27
27
  useTsSolution?: boolean;
28
+ useProjectJson?: boolean;
28
29
  }
29
30
 
30
31
  export type NodeJsFrameWorks = 'express' | 'koa' | 'fastify' | 'nest' | 'none';
@@ -123,6 +123,10 @@
123
123
  "docker": {
124
124
  "type": "boolean",
125
125
  "description": "Add a docker build target"
126
+ },
127
+ "useProjectJson": {
128
+ "type": "boolean",
129
+ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
126
130
  }
127
131
  },
128
132
  "required": ["directory"]
@@ -17,6 +17,7 @@ const add_swc_config_1 = require("@nx/js/src/utils/swc/add-swc-config");
17
17
  async function e2eProjectGenerator(host, options) {
18
18
  return await e2eProjectGeneratorInternal(host, {
19
19
  addPlugin: false,
20
+ useProjectJson: true,
20
21
  ...options,
21
22
  });
22
23
  }
@@ -24,31 +25,30 @@ async function e2eProjectGeneratorInternal(host, _options) {
24
25
  const tasks = [];
25
26
  const options = await normalizeOptions(host, _options);
26
27
  const appProject = (0, devkit_1.readProjectConfiguration)(host, options.project);
27
- const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
28
28
  // TODO(@ndcunningham): This is broken.. the outputs are wrong.. and this isn't using the jest generator
29
- if (isUsingTsSolutionConfig) {
30
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
31
- name: options.importPath,
32
- version: '0.0.1',
33
- private: true,
34
- nx: {
35
- name: options.e2eProjectName !== options.importPath
36
- ? options.e2eProjectName
37
- : undefined,
38
- implicitDependencies: [options.project],
39
- targets: {
40
- e2e: {
41
- executor: '@nx/jest:jest',
42
- outputs: ['{projectRoot}/test-output/jest/coverage'],
43
- options: {
44
- jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
45
- passWithNoTests: true,
46
- },
47
- dependsOn: [`${options.project}:build`],
29
+ const packageJson = {
30
+ name: options.importPath,
31
+ version: '0.0.1',
32
+ private: true,
33
+ };
34
+ if (!options.useProjectJson) {
35
+ packageJson.nx = {
36
+ name: options.e2eProjectName !== options.importPath
37
+ ? options.e2eProjectName
38
+ : undefined,
39
+ implicitDependencies: [options.project],
40
+ targets: {
41
+ e2e: {
42
+ executor: '@nx/jest:jest',
43
+ outputs: ['{projectRoot}/test-output/jest/coverage'],
44
+ options: {
45
+ jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
46
+ passWithNoTests: true,
48
47
  },
48
+ dependsOn: [`${options.project}:build`],
49
49
  },
50
50
  },
51
- });
51
+ };
52
52
  }
53
53
  else {
54
54
  (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
@@ -68,6 +68,9 @@ async function e2eProjectGeneratorInternal(host, _options) {
68
68
  },
69
69
  });
70
70
  }
71
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
72
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
73
+ }
71
74
  // TODO(@nicholas): Find a better way to get build target
72
75
  // We remove the 'test' target from the e2e project because it is not needed
73
76
  // The 'e2e' target is the one that should run the tests for the e2e project
@@ -94,11 +97,11 @@ async function e2eProjectGeneratorInternal(host, _options) {
94
97
  });
95
98
  }
96
99
  const jestPreset = (0, config_file_1.findRootJestPreset)(host) ?? 'jest.preset.js';
97
- const tsConfigFile = isUsingTsSolutionConfig
100
+ const tsConfigFile = options.isUsingTsSolutionConfig
98
101
  ? 'tsconfig.json'
99
102
  : 'tsconfig.spec.json';
100
103
  const rootOffset = (0, devkit_1.offsetFromRoot)(options.e2eProjectRoot);
101
- const coverageDirectory = isUsingTsSolutionConfig
104
+ const coverageDirectory = options.isUsingTsSolutionConfig
102
105
  ? 'test-output/jest/coverage'
103
106
  : (0, devkit_1.joinPathFragments)(rootOffset, 'coverage', options.e2eProjectName);
104
107
  const projectSimpleName = options.project.split('/').pop();
@@ -110,7 +113,6 @@ async function e2eProjectGeneratorInternal(host, _options) {
110
113
  offsetFromRoot: rootOffset,
111
114
  jestPreset,
112
115
  coverageDirectory,
113
- isUsingTsSolutionConfig,
114
116
  tmpl: '',
115
117
  });
116
118
  if (options.isNest) {
@@ -133,11 +135,10 @@ async function e2eProjectGeneratorInternal(host, _options) {
133
135
  offsetFromRoot: rootOffset,
134
136
  jestPreset,
135
137
  coverageDirectory,
136
- isUsingTsSolutionConfig,
137
138
  tmpl: '',
138
139
  });
139
140
  }
140
- if (isUsingTsSolutionConfig) {
141
+ if (options.isUsingTsSolutionConfig) {
141
142
  (0, add_swc_config_1.addSwcTestConfig)(host, options.e2eProjectRoot, 'es6');
142
143
  (0, devkit_1.generateFiles)(host, path.join(__dirname, 'files/ts-solution'), options.e2eProjectRoot, {
143
144
  ...options,
@@ -178,7 +179,7 @@ async function e2eProjectGeneratorInternal(host, _options) {
178
179
  ]);
179
180
  }
180
181
  }
181
- if (isUsingTsSolutionConfig) {
182
+ if (options.isUsingTsSolutionConfig) {
182
183
  (0, devkit_1.updateJson)(host, 'tsconfig.json', (json) => {
183
184
  json.references ??= [];
184
185
  const e2eRef = `./${options.e2eProjectRoot}`;
@@ -190,8 +191,8 @@ async function e2eProjectGeneratorInternal(host, _options) {
190
191
  }
191
192
  // If we are using the new TS solution
192
193
  // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
193
- if (isUsingTsSolutionConfig) {
194
- (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.e2eProjectRoot);
194
+ if (options.isUsingTsSolutionConfig) {
195
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.e2eProjectRoot);
195
196
  }
196
197
  if (!options.skipFormat) {
197
198
  await (0, devkit_1.formatFiles)(host);
@@ -215,6 +216,7 @@ async function normalizeOptions(tree, options) {
215
216
  const nxJson = (0, devkit_1.readNxJson)(tree);
216
217
  const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
217
218
  nxJson.useInferencePlugins !== false;
219
+ const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
218
220
  return {
219
221
  addPlugin,
220
222
  ...options,
@@ -223,6 +225,8 @@ async function normalizeOptions(tree, options) {
223
225
  importPath,
224
226
  port: options.port ?? 3000,
225
227
  rootProject: !!options.rootProject,
228
+ isUsingTsSolutionConfig,
229
+ useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig,
226
230
  };
227
231
  }
228
232
  exports.default = e2eProjectGenerator;
@@ -9,4 +9,5 @@ export interface Schema {
9
9
  isNest?: boolean;
10
10
  skipFormat?: boolean;
11
11
  addPlugin?: boolean;
12
+ useProjectJson?: boolean;
12
13
  }
@@ -59,6 +59,10 @@
59
59
  "default": false,
60
60
  "hidden": true,
61
61
  "x-priority": "internal"
62
+ },
63
+ "useProjectJson": {
64
+ "type": "boolean",
65
+ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
62
66
  }
63
67
  },
64
68
  "required": ["project"]
@@ -16,6 +16,7 @@ const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
16
16
  async function libraryGenerator(tree, schema) {
17
17
  return await libraryGeneratorInternal(tree, {
18
18
  addPlugin: false,
19
+ useProjectJson: true,
19
20
  ...schema,
20
21
  });
21
22
  }
@@ -24,21 +25,21 @@ async function libraryGeneratorInternal(tree, schema) {
24
25
  // If we are using the new TS solution
25
26
  // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
26
27
  if (options.isUsingTsSolutionConfig) {
27
- (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
28
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
28
29
  }
29
30
  const tasks = [];
30
31
  if (options.publishable === true && !schema.importPath) {
31
32
  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)`);
32
33
  }
33
34
  // Create `package.json` first because @nx/js:lib generator will update it.
34
- if (options.isUsingTsSolutionConfig ||
35
+ if (!options.useProjectJson ||
36
+ options.isUsingTsSolutionConfig ||
35
37
  options.publishable ||
36
38
  options.buildable) {
37
39
  (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), {
38
40
  name: options.importPath,
39
41
  version: '0.0.1',
40
42
  private: true,
41
- files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
42
43
  });
43
44
  }
44
45
  tasks.push(await (0, js_1.libraryGenerator)(tree, {
@@ -49,7 +50,7 @@ async function libraryGeneratorInternal(tree, schema) {
49
50
  testEnvironment: 'node',
50
51
  skipFormat: true,
51
52
  setParserOptionsProject: schema.setParserOptionsProject,
52
- useProjectJson: !options.isUsingTsSolutionConfig,
53
+ useProjectJson: options.useProjectJson,
53
54
  }));
54
55
  updatePackageJson(tree, options);
55
56
  tasks.push(await (0, init_1.initGenerator)(tree, {
@@ -100,6 +101,7 @@ async function normalizeOptions(tree, options) {
100
101
  parsedTags,
101
102
  importPath,
102
103
  isUsingTsSolutionConfig,
104
+ useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig,
103
105
  };
104
106
  }
105
107
  function createFiles(tree, options) {
@@ -21,4 +21,5 @@ export interface Schema {
21
21
  setParserOptionsProject?: boolean;
22
22
  compiler: 'tsc' | 'swc';
23
23
  addPlugin?: boolean;
24
+ useProjectJson?: boolean;
24
25
  }
@@ -123,6 +123,10 @@
123
123
  "type": "boolean",
124
124
  "description": "Whether or not to configure the ESLint `parserOptions.project`. We do not do this by default for lint performance reasons.",
125
125
  "default": false
126
+ },
127
+ "useProjectJson": {
128
+ "type": "boolean",
129
+ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
126
130
  }
127
131
  },
128
132
  "required": ["directory"]