@nx/web 17.2.0-beta.0 → 17.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/web",
3
- "version": "17.2.0-beta.0",
3
+ "version": "17.2.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, 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": {
@@ -34,9 +34,9 @@
34
34
  "detect-port": "^1.5.1",
35
35
  "http-server": "^14.1.0",
36
36
  "tslib": "^2.3.0",
37
- "@nx/devkit": "17.2.0-beta.0",
38
- "@nx/js": "17.2.0-beta.0",
39
- "@nrwl/web": "17.2.0-beta.0"
37
+ "@nx/devkit": "17.2.0-beta.10",
38
+ "@nx/js": "17.2.0-beta.10",
39
+ "@nrwl/web": "17.2.0-beta.10"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
@@ -78,14 +78,14 @@ function createFileWatcher(project, changeHandler) {
78
78
  watchProjects: project ? [project] : 'all',
79
79
  includeGlobalWorkspaceFiles: true,
80
80
  includeDependentProjects: true,
81
- }, async (error, { changedFiles }) => {
81
+ }, async (error, val) => {
82
82
  if (error === 'closed') {
83
83
  throw new Error('Watch error: Daemon closed the connection');
84
84
  }
85
85
  else if (error) {
86
86
  throw new Error(`Watch error: ${error?.message ?? 'Unknown'}`);
87
87
  }
88
- else if (changedFiles.length > 0) {
88
+ else if (val?.changedFiles.length > 0) {
89
89
  changeHandler();
90
90
  }
91
91
  });
@@ -1,7 +1,7 @@
1
1
  export interface Schema {
2
- host: string;
3
- port: number;
4
- ssl: boolean;
2
+ host?: string;
3
+ port?: number;
4
+ ssl?: boolean;
5
5
  sslKey?: string;
6
6
  sslCert?: string;
7
7
  proxyUrl?: string;
@@ -9,16 +9,42 @@ const path_1 = require("path");
9
9
  const versions_2 = require("../../utils/versions");
10
10
  const init_1 = require("../init/init");
11
11
  const get_npm_scope_1 = require("@nx/js/src/utils/package-json/get-npm-scope");
12
+ const has_webpack_plugin_1 = require("../../utils/has-webpack-plugin");
12
13
  function createApplicationFiles(tree, options) {
13
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, options.bundler === 'vite' ? './files/app-vite' : './files/app-webpack'), options.appProjectRoot, {
14
- ...options,
15
- ...(0, devkit_1.names)(options.name),
16
- tmpl: '',
17
- offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
18
- rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
19
- });
20
- if (options.unitTestRunner === 'none') {
21
- tree.delete((0, path_1.join)(options.appProjectRoot, './src/app/app.element.spec.ts'));
14
+ if (options.bundler === 'vite') {
15
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/app-vite'), options.appProjectRoot, {
16
+ ...options,
17
+ ...(0, devkit_1.names)(options.name),
18
+ tmpl: '',
19
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
20
+ rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
21
+ });
22
+ }
23
+ else {
24
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/app-webpack'), options.appProjectRoot, {
25
+ ...options,
26
+ ...(0, devkit_1.names)(options.name),
27
+ tmpl: '',
28
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
29
+ rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(tree, options.appProjectRoot),
30
+ webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)
31
+ ? {
32
+ target: 'web',
33
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot != '.'
34
+ ? options.appProjectRoot
35
+ : options.projectName),
36
+ tsConfig: './tsconfig.app.json',
37
+ main: './src/main.ts',
38
+ assets: ['./src/favicon.ico', './src/assets'],
39
+ index: './src/index.html',
40
+ baseHref: '/',
41
+ styles: [`./src/styles.${options.style}`],
42
+ }
43
+ : null,
44
+ });
45
+ if (options.unitTestRunner === 'none') {
46
+ tree.delete((0, path_1.join)(options.appProjectRoot, './src/app/app.element.spec.ts'));
47
+ }
22
48
  }
23
49
  }
24
50
  async function setupBundler(tree, options) {
@@ -31,6 +57,7 @@ async function setupBundler(tree, options) {
31
57
  if (options.bundler === 'webpack') {
32
58
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_2.nxVersion);
33
59
  await configurationGenerator(tree, {
60
+ target: 'web',
34
61
  project: options.projectName,
35
62
  main,
36
63
  tsConfig,
@@ -40,35 +67,37 @@ async function setupBundler(tree, options) {
40
67
  skipFormat: true,
41
68
  });
42
69
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
43
- const prodConfig = project.targets.build.configurations.production;
44
- const buildOptions = project.targets.build.options;
45
- buildOptions.assets = assets;
46
- buildOptions.index = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html');
47
- buildOptions.baseHref = '/';
48
- buildOptions.styles = [
49
- (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
50
- ];
51
- // We can delete that, because this projest is an application
52
- // and applications have a .babelrc file in their root dir.
53
- // So Nx will find it and use it
54
- delete buildOptions.babelUpwardRootMode;
55
- buildOptions.scripts = [];
56
- prodConfig.fileReplacements = [
57
- {
58
- replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.ts`),
59
- with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.prod.ts`),
60
- },
61
- ];
62
- prodConfig.optimization = true;
63
- prodConfig.outputHashing = 'all';
64
- prodConfig.sourceMap = false;
65
- prodConfig.namedChunks = false;
66
- prodConfig.extractLicenses = true;
67
- prodConfig.vendorChunk = false;
68
- (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
70
+ if (project.targets.build) {
71
+ const prodConfig = project.targets.build.configurations.production;
72
+ const buildOptions = project.targets.build.options;
73
+ buildOptions.assets = assets;
74
+ buildOptions.index = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html');
75
+ buildOptions.baseHref = '/';
76
+ buildOptions.styles = [
77
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
78
+ ];
79
+ // We can delete that, because this projest is an application
80
+ // and applications have a .babelrc file in their root dir.
81
+ // So Nx will find it and use it
82
+ delete buildOptions.babelUpwardRootMode;
83
+ buildOptions.scripts = [];
84
+ prodConfig.fileReplacements = [
85
+ {
86
+ replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.ts`),
87
+ with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/environments/environment.prod.ts`),
88
+ },
89
+ ];
90
+ prodConfig.optimization = true;
91
+ prodConfig.outputHashing = 'all';
92
+ prodConfig.sourceMap = false;
93
+ prodConfig.namedChunks = false;
94
+ prodConfig.extractLicenses = true;
95
+ prodConfig.vendorChunk = false;
96
+ (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
97
+ }
98
+ // TODO(jack): Flush this out... no bundler should be possible for web but the experience isn't holistic due to missing features (e.g. writing index.html).
69
99
  }
70
100
  else if (options.bundler === 'none') {
71
- // TODO(jack): Flush this out... no bundler should be possible for web but the experience isn't holistic due to missing features (e.g. writing index.html).
72
101
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
73
102
  project.targets.build = {
74
103
  executor: `@nx/js:${options.compiler}`,
@@ -77,7 +106,6 @@ async function setupBundler(tree, options) {
77
106
  main,
78
107
  outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot),
79
108
  tsConfig,
80
- assets,
81
109
  },
82
110
  };
83
111
  (0, devkit_1.updateProjectConfiguration)(tree, options.projectName, project);
@@ -95,9 +123,6 @@ async function addProject(tree, options) {
95
123
  tags: options.parsedTags,
96
124
  targets,
97
125
  }, options.standaloneConfig);
98
- if (options.bundler !== 'vite') {
99
- await setupBundler(tree, options);
100
- }
101
126
  }
102
127
  function setDefaults(tree, options) {
103
128
  const nxJson = (0, devkit_1.readNxJson)(tree);
@@ -126,8 +151,11 @@ async function applicationGeneratorInternal(host, schema) {
126
151
  skipFormat: true,
127
152
  });
128
153
  tasks.push(webTask);
129
- createApplicationFiles(host, options);
130
154
  await addProject(host, options);
155
+ if (options.bundler !== 'vite') {
156
+ await setupBundler(host, options);
157
+ }
158
+ createApplicationFiles(host, options);
131
159
  if (options.bundler === 'vite') {
132
160
  const { viteConfigurationGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_2.nxVersion);
133
161
  // We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
@@ -181,7 +209,6 @@ async function applicationGeneratorInternal(host, schema) {
181
209
  (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
182
210
  ],
183
211
  unitTestRunner: options.unitTestRunner,
184
- eslintFilePatterns: [`${options.appProjectRoot}/**/*.ts`],
185
212
  skipFormat: true,
186
213
  setParserOptionsProject: options.setParserOptionsProject,
187
214
  });
@@ -201,6 +228,7 @@ async function applicationGeneratorInternal(host, schema) {
201
228
  ...options,
202
229
  project: options.e2eProjectName,
203
230
  devServerTarget: `${options.projectName}:serve`,
231
+ baseUrl: 'http://localhost:4200',
204
232
  directory: 'src',
205
233
  skipFormat: true,
206
234
  });
@@ -1,8 +1,38 @@
1
+ <% if (webpackPluginOptions) { %>
2
+ const { NxWebpackPlugin } = require('@nx/webpack');
3
+ const { join } = require('path');
4
+
5
+ module.exports = {
6
+ output: {
7
+ path: join(__dirname, '<%= offsetFromRoot %><%= webpackPluginOptions.outputPath %>'),
8
+ },
9
+ devServer: {
10
+ port: 4200
11
+ },
12
+ plugins: [
13
+ new NxWebpackPlugin({
14
+ tsConfig: '<%= webpackPluginOptions.tsConfig %>',
15
+ main: '<%= webpackPluginOptions.main %>',
16
+ index: '<%= webpackPluginOptions.index %>',
17
+ baseHref: '<%= webpackPluginOptions.baseHref %>',
18
+ assets: <%- JSON.stringify(webpackPluginOptions.assets) %>,
19
+ styles: <%- JSON.stringify(webpackPluginOptions.styles) %>,
20
+ outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
21
+ optimization: process.env['NODE_ENV'] === 'production',
22
+ })
23
+ ],
24
+ };
25
+ <% } else { %>
1
26
  const { composePlugins, withNx, withWeb } = require('@nx/webpack');
2
27
 
3
28
  // Nx plugins for webpack.
4
- module.exports = composePlugins(withNx(), withWeb(), (config) => {
5
- // Update the webpack config as needed here.
6
- // e.g. `config.plugins.push(new MyPlugin())`
7
- return config;
8
- });
29
+ module.exports = composePlugins(
30
+ withNx(),
31
+ withWeb(),
32
+ (config) => {
33
+ // Update the webpack config as needed here.
34
+ // e.g. `config.plugins.push(new MyPlugin())`
35
+ return config;
36
+ }
37
+ );
38
+ <% } %>
@@ -13,7 +13,7 @@ async function addDroppedDependencies(tree) {
13
13
  for (const [_, projectConfiguration] of projects) {
14
14
  for (const [_, targetConfiguration] of Object.entries(projectConfiguration.targets ?? {})) {
15
15
  for (const droppedDependency of droppedDependencies) {
16
- if (targetConfiguration.executor?.startsWith(droppedDependency + ':')) {
16
+ if (targetConfiguration?.['executor']?.startsWith(droppedDependency + ':')) {
17
17
  devDependencies[droppedDependency] = devkit_1.NX_VERSION;
18
18
  }
19
19
  }
@@ -22,7 +22,7 @@ async function addDroppedDependencies(tree) {
22
22
  const nxJson = (0, devkit_1.readNxJson)(tree);
23
23
  for (const [_, targetConfiguration] of Object.entries(nxJson?.targetDefaults ?? {})) {
24
24
  for (const droppedDependency of droppedDependencies) {
25
- if (targetConfiguration.executor?.startsWith(droppedDependency + ':')) {
25
+ if (targetConfiguration?.['executor']?.startsWith(droppedDependency + ':')) {
26
26
  devDependencies[droppedDependency] = devkit_1.NX_VERSION;
27
27
  }
28
28
  }
@@ -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,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.waitForPortOpen = void 0;
4
+ const devkit_1 = require("@nx/devkit");
4
5
  const net = require("net");
5
6
  function waitForPortOpen(port, options = {}) {
6
- const allowedErrorCodes = ['ECONNREFUSED', 'ECONNRESET'];
7
+ const host = options.host ?? '127.0.0.1';
8
+ const allowedErrorCodes = ['ECONNREFUSED', 'ECONNRESET', 'ETIMEDOUT'];
7
9
  return new Promise((resolve, reject) => {
8
10
  const checkPort = (retries = options.retries ?? 120) => {
9
11
  const client = new net.Socket();
@@ -20,6 +22,9 @@ function waitForPortOpen(port, options = {}) {
20
22
  });
21
23
  client.once('error', (err) => {
22
24
  if (retries === 0 || !allowedErrorCodes.includes(err['code'])) {
25
+ if (process.env['NX_VERBOSE_LOGGING'] === 'true') {
26
+ devkit_1.logger.info(`Error connecting on ${host}:${port}: ${err['code'] || err}`);
27
+ }
23
28
  cleanupClient();
24
29
  reject(err);
25
30
  }
@@ -29,7 +34,10 @@ function waitForPortOpen(port, options = {}) {
29
34
  });
30
35
  // Node will use IPv6 if it is available, but this can cause issues if the server is only listening on IPv4.
31
36
  // Hard-coding to look on 127.0.0.1 to avoid using the IPv6 loopback address "::1".
32
- client.connect({ port, host: options.host ?? '127.0.0.1' });
37
+ if (process.env['NX_VERBOSE_LOGGING'] === 'true') {
38
+ devkit_1.logger.info(`Connecting on ${host}:${port}`);
39
+ }
40
+ client.connect({ port, host });
33
41
  };
34
42
  checkPort();
35
43
  });
@@ -1,3 +0,0 @@
1
- export const environment = {
2
- production: true
3
- };
@@ -1,6 +0,0 @@
1
- // This file can be replaced during build by using the `fileReplacements` array.
2
- // When building for production, this file is replaced with `environment.prod.ts`.
3
-
4
- export const environment = {
5
- production: false
6
- };