@nx/web 21.0.0-beta.0 → 21.0.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.
package/migrations.json CHANGED
@@ -1,14 +1,4 @@
1
1
  {
2
2
  "generators": {},
3
- "packageJsonUpdates": {
4
- "17.3.0": {
5
- "version": "17.3.0-beta.3",
6
- "packages": {
7
- "@types/node": {
8
- "version": "18.16.9",
9
- "alwaysAddToPackageJson": false
10
- }
11
- }
12
- }
13
- }
3
+ "packageJsonUpdates": {}
14
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/web",
3
- "version": "21.0.0-beta.0",
3
+ "version": "21.0.0-beta.10",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Web Components contains generators for managing Web Component applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Playwright, Cypress, and Storybook.\n\n- Scaffolding for creating buildable libraries that can be published to npm.\n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -35,8 +35,8 @@
35
35
  "http-server": "^14.1.0",
36
36
  "picocolors": "^1.1.0",
37
37
  "tslib": "^2.3.0",
38
- "@nx/devkit": "21.0.0-beta.0",
39
- "@nx/js": "21.0.0-beta.0"
38
+ "@nx/devkit": "21.0.0-beta.10",
39
+ "@nx/js": "21.0.0-beta.10"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "version": 2,
3
+ "continuous": true,
3
4
  "outputCapture": "direct-nodejs",
4
5
  "title": "File Server",
5
6
  "description": "Serve a web application from a folder. This executor is a wrapper around the [http-server](https://www.npmjs.com/package/http-server) package.",
@@ -14,15 +14,12 @@ const has_webpack_plugin_1 = require("../../utils/has-webpack-plugin");
14
14
  const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
15
15
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
16
16
  const static_serve_configuration_1 = require("../static-serve/static-serve-configuration");
17
- const find_plugin_for_config_file_1 = require("@nx/devkit/src/utils/find-plugin-for-config-file");
18
17
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
19
- const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
20
18
  function createApplicationFiles(tree, options) {
21
19
  const rootTsConfigPath = (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot);
22
20
  if (options.bundler === 'vite') {
23
21
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/app-vite'), options.appProjectRoot, {
24
22
  ...options,
25
- ...(0, devkit_1.names)(options.name),
26
23
  tmpl: '',
27
24
  offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
28
25
  rootTsConfigPath,
@@ -32,7 +29,6 @@ function createApplicationFiles(tree, options) {
32
29
  const rootOffset = (0, devkit_1.offsetFromRoot)(options.appProjectRoot);
33
30
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/app-webpack'), options.appProjectRoot, {
34
31
  ...options,
35
- ...(0, devkit_1.names)(options.name),
36
32
  tmpl: '',
37
33
  offsetFromRoot: rootOffset,
38
34
  rootTsConfigPath,
@@ -153,17 +149,19 @@ async function setupBundler(tree, options) {
153
149
  }
154
150
  }
155
151
  async function addProject(tree, options) {
156
- if (options.isUsingTsSolutionConfig) {
157
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
158
- name: (0, get_import_path_1.getImportPath)(tree, options.name),
159
- version: '0.0.1',
160
- private: true,
161
- nx: options.parsedTags?.length
162
- ? {
163
- tags: options.parsedTags,
164
- }
165
- : undefined,
166
- });
152
+ const packageJson = {
153
+ name: options.importPath,
154
+ version: '0.0.1',
155
+ private: true,
156
+ };
157
+ if (!options.useProjectJson) {
158
+ if (options.projectName !== options.importPath) {
159
+ packageJson.nx = { name: options.projectName };
160
+ }
161
+ if (options.parsedTags?.length) {
162
+ packageJson.nx ??= {};
163
+ packageJson.nx.tags = options.parsedTags;
164
+ }
167
165
  }
168
166
  else {
169
167
  (0, devkit_1.addProjectConfiguration)(tree, options.projectName, {
@@ -174,6 +172,9 @@ async function addProject(tree, options) {
174
172
  targets: {},
175
173
  });
176
174
  }
175
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
176
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
177
+ }
177
178
  }
178
179
  function setDefaults(tree, options) {
179
180
  const nxJson = (0, devkit_1.readNxJson)(tree);
@@ -196,7 +197,7 @@ async function applicationGenerator(host, schema) {
196
197
  async function applicationGeneratorInternal(host, schema) {
197
198
  const options = await normalizeOptions(host, schema);
198
199
  if (options.isUsingTsSolutionConfig) {
199
- (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.appProjectRoot);
200
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.appProjectRoot);
200
201
  }
201
202
  const tasks = [];
202
203
  const jsInitTask = await (0, js_1.initGenerator)(host, {
@@ -215,6 +216,21 @@ async function applicationGeneratorInternal(host, schema) {
215
216
  await setupBundler(host, options);
216
217
  }
217
218
  createApplicationFiles(host, options);
219
+ if (options.linter === 'eslint') {
220
+ const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/eslint', versions_2.nxVersion);
221
+ const lintTask = await lintProjectGenerator(host, {
222
+ linter: options.linter,
223
+ project: options.projectName,
224
+ tsConfigPaths: [
225
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
226
+ ],
227
+ unitTestRunner: options.unitTestRunner,
228
+ skipFormat: true,
229
+ setParserOptionsProject: options.setParserOptionsProject,
230
+ addPlugin: options.addPlugin,
231
+ });
232
+ tasks.push(lintTask);
233
+ }
218
234
  if (options.bundler === 'vite') {
219
235
  const { viteConfigurationGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_2.nxVersion);
220
236
  // We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
@@ -262,21 +278,6 @@ async function applicationGeneratorInternal(host, schema) {
262
278
  options.inSourceTests) {
263
279
  host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/app/app.element.spec.ts`));
264
280
  }
265
- if (options.linter === 'eslint') {
266
- const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/eslint', versions_2.nxVersion);
267
- const lintTask = await lintProjectGenerator(host, {
268
- linter: options.linter,
269
- project: options.projectName,
270
- tsConfigPaths: [
271
- (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
272
- ],
273
- unitTestRunner: options.unitTestRunner,
274
- skipFormat: true,
275
- setParserOptionsProject: options.setParserOptionsProject,
276
- addPlugin: options.addPlugin,
277
- });
278
- tasks.push(lintTask);
279
- }
280
281
  const nxJson = (0, devkit_1.readNxJson)(host);
281
282
  let hasPlugin;
282
283
  let buildPlugin;
@@ -310,17 +311,15 @@ async function applicationGeneratorInternal(host, schema) {
310
311
  }
311
312
  if (options.e2eTestRunner === 'cypress') {
312
313
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_2.nxVersion);
313
- if (options.isUsingTsSolutionConfig) {
314
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
315
- name: options.e2eProjectName,
316
- version: '0.0.1',
317
- private: true,
318
- nx: {
319
- projectType: 'application',
320
- sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
321
- implicitDependencies: [options.projectName],
322
- },
323
- });
314
+ const packageJson = {
315
+ name: options.e2eProjectName,
316
+ version: '0.0.1',
317
+ private: true,
318
+ };
319
+ if (!options.useProjectJson) {
320
+ packageJson.nx = {
321
+ implicitDependencies: [options.projectName],
322
+ };
324
323
  }
325
324
  else {
326
325
  (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
@@ -332,6 +331,9 @@ async function applicationGeneratorInternal(host, schema) {
332
331
  implicitDependencies: [options.projectName],
333
332
  });
334
333
  }
334
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
335
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
336
+ }
335
337
  const cypressTask = await configurationGenerator(host, {
336
338
  ...options,
337
339
  project: options.e2eProjectName,
@@ -339,45 +341,26 @@ async function applicationGeneratorInternal(host, schema) {
339
341
  baseUrl: e2eWebServerInfo.e2eWebServerAddress,
340
342
  directory: 'src',
341
343
  skipFormat: true,
342
- webServerCommands: hasPlugin
343
- ? {
344
- default: e2eWebServerInfo.e2eWebServerCommand,
345
- production: e2eWebServerInfo.e2eCiWebServerCommand,
346
- }
347
- : undefined,
348
- ciWebServerCommand: hasPlugin
349
- ? e2eWebServerInfo.e2eCiWebServerCommand
350
- : undefined,
344
+ webServerCommands: {
345
+ default: e2eWebServerInfo.e2eWebServerCommand,
346
+ production: e2eWebServerInfo.e2eCiWebServerCommand,
347
+ },
348
+ ciWebServerCommand: e2eWebServerInfo.e2eCiWebServerCommand,
351
349
  ciBaseUrl: e2eWebServerInfo.e2eCiBaseUrl,
352
350
  });
353
- if (options.addPlugin ||
354
- (0, devkit_1.readNxJson)(host).plugins?.find((p) => typeof p === 'string'
355
- ? p === '@nx/cypress/plugin'
356
- : p.plugin === '@nx/cypress/plugin')) {
357
- let buildTarget = '^build';
358
- if (hasPlugin) {
359
- const matchingPlugin = await (0, find_plugin_for_config_file_1.findPluginForConfigFile)(host, buildPlugin, (0, devkit_1.joinPathFragments)(options.appProjectRoot, buildConfigFile));
360
- if (matchingPlugin && typeof matchingPlugin !== 'string') {
361
- buildTarget = `^${matchingPlugin.options?.buildTargetName ?? 'build'}`;
362
- }
363
- }
364
- await (0, target_defaults_utils_1.addE2eCiTargetDefaults)(host, '@nx/cypress/plugin', buildTarget, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, `cypress.config.ts`));
365
- }
366
351
  tasks.push(cypressTask);
367
352
  }
368
353
  else if (options.e2eTestRunner === 'playwright') {
369
354
  const { configurationGenerator: playwrightConfigGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_2.nxVersion);
370
- if (options.isUsingTsSolutionConfig) {
371
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
372
- name: options.e2eProjectName,
373
- version: '0.0.1',
374
- private: true,
375
- nx: {
376
- projectType: 'application',
377
- sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
378
- implicitDependencies: [options.projectName],
379
- },
380
- });
355
+ const packageJson = {
356
+ name: options.e2eProjectName,
357
+ version: '0.0.1',
358
+ private: true,
359
+ };
360
+ if (!options.useProjectJson) {
361
+ packageJson.nx = {
362
+ implicitDependencies: [options.projectName],
363
+ };
381
364
  }
382
365
  else {
383
366
  (0, devkit_1.addProjectConfiguration)(host, options.e2eProjectName, {
@@ -389,6 +372,9 @@ async function applicationGeneratorInternal(host, schema) {
389
372
  implicitDependencies: [options.projectName],
390
373
  });
391
374
  }
375
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
376
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
377
+ }
392
378
  const playwrightTask = await playwrightConfigGenerator(host, {
393
379
  project: options.e2eProjectName,
394
380
  skipFormat: true,
@@ -401,19 +387,6 @@ async function applicationGeneratorInternal(host, schema) {
401
387
  webServerAddress: e2eWebServerInfo.e2eCiBaseUrl,
402
388
  addPlugin: options.addPlugin,
403
389
  });
404
- if (options.addPlugin ||
405
- (0, devkit_1.readNxJson)(host).plugins?.find((p) => typeof p === 'string'
406
- ? p === '@nx/playwright/plugin'
407
- : p.plugin === '@nx/playwright/plugin')) {
408
- let buildTarget = '^build';
409
- if (hasPlugin) {
410
- const matchingPlugin = await (0, find_plugin_for_config_file_1.findPluginForConfigFile)(host, buildPlugin, (0, devkit_1.joinPathFragments)(options.appProjectRoot, buildConfigFile));
411
- if (matchingPlugin && typeof matchingPlugin !== 'string') {
412
- buildTarget = `^${matchingPlugin.options?.buildTargetName ?? 'build'}`;
413
- }
414
- }
415
- await (0, target_defaults_utils_1.addE2eCiTargetDefaults)(host, '@nx/playwright/plugin', buildTarget, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, `playwright.config.ts`));
416
- }
417
390
  tasks.push(playwrightTask);
418
391
  }
419
392
  if (options.unitTestRunner === 'jest') {
@@ -462,8 +435,8 @@ async function applicationGeneratorInternal(host, schema) {
462
435
  return (0, devkit_1.runTasksInSerial)(...tasks);
463
436
  }
464
437
  async function normalizeOptions(host, options) {
465
- await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
466
- const { projectName: appProjectName, projectRoot: appProjectRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
438
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
439
+ const { projectName, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
467
440
  name: options.name,
468
441
  projectType: 'application',
469
442
  directory: options.directory,
@@ -472,9 +445,10 @@ async function normalizeOptions(host, options) {
472
445
  const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
473
446
  nxJson.useInferencePlugins !== false;
474
447
  options.addPlugin ??= addPluginDefault;
448
+ const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
449
+ const appProjectName = !isUsingTsSolutionConfig || options.name ? projectName : importPath;
475
450
  const e2eProjectName = `${appProjectName}-e2e`;
476
451
  const e2eProjectRoot = `${appProjectRoot}-e2e`;
477
- const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
478
452
  const npmScope = (0, get_npm_scope_1.getNpmScope)(host);
479
453
  const parsedTags = options.tags
480
454
  ? options.tags.split(',').map((s) => s.trim())
@@ -486,18 +460,18 @@ async function normalizeOptions(host, options) {
486
460
  return {
487
461
  ...options,
488
462
  prefix: options.prefix ?? npmScope ?? 'app',
489
- name: (0, devkit_1.names)(options.name).fileName,
490
463
  compiler: options.compiler ?? 'babel',
491
464
  bundler: options.bundler ?? 'webpack',
492
- projectName: isUsingTsSolutionConfig
493
- ? (0, get_import_path_1.getImportPath)(host, appProjectName)
494
- : appProjectName,
465
+ projectName: appProjectName,
466
+ importPath,
495
467
  strict: options.strict ?? true,
496
468
  appProjectRoot,
497
469
  e2eProjectRoot,
498
470
  e2eProjectName,
499
471
  parsedTags,
472
+ names: (0, devkit_1.names)(projectName),
500
473
  isUsingTsSolutionConfig,
474
+ useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig,
501
475
  };
502
476
  }
503
477
  exports.default = applicationGenerator;
@@ -2,7 +2,7 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
- <title><%= className %></title>
5
+ <title><%= names.className %></title>
6
6
  <base href="/" />
7
7
 
8
8
  <meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -2,7 +2,7 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
- <title><%= className %></title>
5
+ <title><%= names.className %></title>
6
6
  <base href="/" />
7
7
 
8
8
  <meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -16,4 +16,5 @@ export interface Schema {
16
16
  setParserOptionsProject?: boolean;
17
17
  strict?: boolean;
18
18
  addPlugin?: boolean;
19
+ useProjectJson?: boolean;
19
20
  }
@@ -104,6 +104,10 @@
104
104
  "type": "boolean",
105
105
  "description": "Creates an application with strict mode and strict type checking.",
106
106
  "default": true
107
+ },
108
+ "useProjectJson": {
109
+ "type": "boolean",
110
+ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
107
111
  }
108
112
  },
109
113
  "required": ["directory"],