@nx/web 16.8.0-beta.3 → 16.8.0-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/web",
3
- "version": "16.8.0-beta.3",
3
+ "version": "16.8.0-beta.5",
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": {
@@ -30,19 +30,17 @@
30
30
  "migrations": "./migrations.json"
31
31
  },
32
32
  "dependencies": {
33
- "@nrwl/web": "16.8.0-beta.3",
34
- "@nx/devkit": "16.8.0-beta.3",
35
- "@nx/js": "16.8.0-beta.3",
33
+ "@nrwl/web": "16.8.0-beta.5",
34
+ "@nx/devkit": "16.8.0-beta.5",
35
+ "@nx/js": "16.8.0-beta.5",
36
36
  "chalk": "^4.1.0",
37
- "chokidar": "^3.5.1",
38
37
  "detect-port": "^1.5.1",
39
38
  "http-server": "^14.1.0",
40
- "ignore": "^5.0.4",
41
39
  "tslib": "^2.3.0"
42
40
  },
43
41
  "publishConfig": {
44
42
  "access": "public"
45
43
  },
46
44
  "type": "commonjs",
47
- "gitHead": "dcd48165a485bc8db57a1fb02b96a0772de3b7e9"
45
+ "gitHead": "ad2d1e8a55b2d1b358bb5e7483343d9757ff2c53"
48
46
  }
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const child_process_1 = require("child_process");
5
4
  const chalk = require("chalk");
6
5
  const devkit_1 = require("@nx/devkit");
7
- const ignore_1 = require("ignore");
8
6
  const fs_1 = require("fs");
9
- const chokidar_1 = require("chokidar");
10
7
  const os_1 = require("os");
11
8
  const path_1 = require("path");
12
9
  const package_json_1 = require("nx/src/utils/package-json");
13
10
  const detectPort = require("detect-port");
11
+ const client_1 = require("nx/src/daemon/client/client");
14
12
  // platform specific command name
15
13
  const pmCmd = (0, os_1.platform)() === 'win32' ? `npx.cmd` : 'npx';
16
14
  function getHttpServerArgs(options) {
@@ -75,111 +73,104 @@ function getBuildTargetOutputPath(options, context) {
75
73
  }
76
74
  return outputPath;
77
75
  }
78
- function getIgnoredGlobs(root) {
79
- const ig = (0, ignore_1.default)();
80
- try {
81
- ig.add((0, fs_1.readFileSync)(`${root}/.gitignore`, 'utf-8'));
82
- }
83
- catch (_a) { }
84
- try {
85
- ig.add((0, fs_1.readFileSync)(`${root}/.nxignore`, 'utf-8'));
86
- }
87
- catch (_b) { }
88
- return ig;
89
- }
90
- function createFileWatcher(root, projectRoot, changeHandler) {
91
- const ignoredGlobs = getIgnoredGlobs(root);
92
- const watcher = (0, chokidar_1.watch)([(0, devkit_1.joinPathFragments)(projectRoot, '**')], {
93
- cwd: root,
94
- ignoreInitial: true,
95
- });
96
- watcher.on('all', (_event, path) => {
97
- if (ignoredGlobs.ignores(path))
98
- return;
99
- changeHandler();
76
+ function createFileWatcher(project, changeHandler) {
77
+ return client_1.daemonClient.registerFileWatcher({
78
+ watchProjects: project ? [project] : 'all',
79
+ includeGlobalWorkspaceFiles: true,
80
+ includeDependentProjects: true,
81
+ }, async (error, { changedFiles }) => {
82
+ if (error === 'closed') {
83
+ throw new Error('Watch error: Daemon closed the connection');
84
+ }
85
+ else if (error) {
86
+ throw new Error(`Watch error: ${error?.message ?? 'Unknown'}`);
87
+ }
88
+ else if (changedFiles.length > 0) {
89
+ changeHandler();
90
+ }
100
91
  });
101
- return () => watcher.close();
102
92
  }
103
- function fileServerExecutor(options, context) {
104
- return tslib_1.__asyncGenerator(this, arguments, function* fileServerExecutor_1() {
105
- let running = false;
106
- const run = () => {
107
- if (!running) {
108
- running = true;
109
- try {
110
- const args = getBuildTargetCommand(options);
111
- (0, child_process_1.execFileSync)(pmCmd, args, {
112
- stdio: [0, 1, 2],
113
- });
114
- }
115
- catch (_a) {
116
- throw new Error(`Build target failed: ${chalk.bold(options.buildTarget)}`);
117
- }
118
- finally {
119
- running = false;
120
- }
93
+ async function* fileServerExecutor(options, context) {
94
+ let running = false;
95
+ const run = () => {
96
+ if (!running) {
97
+ running = true;
98
+ try {
99
+ const args = getBuildTargetCommand(options);
100
+ (0, child_process_1.execFileSync)(pmCmd, args, {
101
+ stdio: [0, 1, 2],
102
+ });
103
+ }
104
+ catch {
105
+ throw new Error(`Build target failed: ${chalk.bold(options.buildTarget)}`);
121
106
  }
122
- };
123
- let disposeWatch;
124
- if (options.watch) {
125
- const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
126
- disposeWatch = createFileWatcher(context.root, projectRoot, run);
107
+ finally {
108
+ running = false;
109
+ }
110
+ }
111
+ };
112
+ let disposeWatch;
113
+ if (options.watch) {
114
+ const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
115
+ disposeWatch = await createFileWatcher(context.projectName, run);
116
+ }
117
+ // perform initial run
118
+ run();
119
+ const outputPath = getBuildTargetOutputPath(options, context);
120
+ if (options.spa) {
121
+ const src = (0, path_1.join)(outputPath, 'index.html');
122
+ const dst = (0, path_1.join)(outputPath, '404.html');
123
+ // See: https://github.com/http-party/http-server#magic-files
124
+ (0, fs_1.copyFileSync)(src, dst);
125
+ }
126
+ const args = getHttpServerArgs(options);
127
+ const { path: pathToHttpServerPkgJson, packageJson } = (0, package_json_1.readModulePackageJson)('http-server', module.paths);
128
+ const pathToHttpServerBin = packageJson.bin['http-server'];
129
+ const pathToHttpServer = (0, path_1.resolve)(pathToHttpServerPkgJson.replace('package.json', ''), pathToHttpServerBin);
130
+ // detect port as close to when used to prevent port being used by another process
131
+ // when running in parallel
132
+ const port = await detectPort(options.port || 8080);
133
+ args.push(`-p=${port}`);
134
+ const serve = (0, child_process_1.fork)(pathToHttpServer, [outputPath, ...args], {
135
+ stdio: 'pipe',
136
+ cwd: context.root,
137
+ env: {
138
+ FORCE_COLOR: 'true',
139
+ ...process.env,
140
+ },
141
+ });
142
+ const processExitListener = () => {
143
+ serve.kill();
144
+ if (disposeWatch) {
145
+ disposeWatch();
127
146
  }
128
- // perform initial run
129
- run();
130
- const outputPath = getBuildTargetOutputPath(options, context);
131
147
  if (options.spa) {
132
- const src = (0, path_1.join)(outputPath, 'index.html');
133
- const dst = (0, path_1.join)(outputPath, '404.html');
134
- // See: https://github.com/http-party/http-server#magic-files
135
- (0, fs_1.copyFileSync)(src, dst);
148
+ (0, fs_1.unlinkSync)((0, path_1.join)(outputPath, '404.html'));
136
149
  }
137
- const args = getHttpServerArgs(options);
138
- const { path: pathToHttpServerPkgJson, packageJson } = (0, package_json_1.readModulePackageJson)('http-server', module.paths);
139
- const pathToHttpServerBin = packageJson.bin['http-server'];
140
- const pathToHttpServer = (0, path_1.resolve)(pathToHttpServerPkgJson.replace('package.json', ''), pathToHttpServerBin);
141
- // detect port as close to when used to prevent port being used by another process
142
- // when running in parallel
143
- const port = yield tslib_1.__await(detectPort(options.port || 8080));
144
- args.push(`-p=${port}`);
145
- const serve = (0, child_process_1.fork)(pathToHttpServer, [outputPath, ...args], {
146
- stdio: 'pipe',
147
- cwd: context.root,
148
- env: Object.assign({ FORCE_COLOR: 'true' }, process.env),
149
- });
150
- const processExitListener = () => {
151
- serve.kill();
152
- if (disposeWatch) {
153
- disposeWatch();
154
- }
155
- if (options.spa) {
156
- (0, fs_1.unlinkSync)((0, path_1.join)(outputPath, '404.html'));
150
+ };
151
+ process.on('exit', processExitListener);
152
+ process.on('SIGTERM', processExitListener);
153
+ serve.stdout.on('data', (chunk) => {
154
+ if (chunk.toString().indexOf('GET') === -1) {
155
+ process.stdout.write(chunk);
156
+ }
157
+ });
158
+ serve.stderr.on('data', (chunk) => {
159
+ process.stderr.write(chunk);
160
+ });
161
+ yield {
162
+ success: true,
163
+ baseUrl: `${options.ssl ? 'https' : 'http'}://${options.host}:${port}`,
164
+ };
165
+ return new Promise((res) => {
166
+ serve.on('exit', (code) => {
167
+ if (code == 0) {
168
+ res({ success: true });
157
169
  }
158
- };
159
- process.on('exit', processExitListener);
160
- process.on('SIGTERM', processExitListener);
161
- serve.stdout.on('data', (chunk) => {
162
- if (chunk.toString().indexOf('GET') === -1) {
163
- process.stdout.write(chunk);
170
+ else {
171
+ res({ success: false });
164
172
  }
165
173
  });
166
- serve.stderr.on('data', (chunk) => {
167
- process.stderr.write(chunk);
168
- });
169
- yield yield tslib_1.__await({
170
- success: true,
171
- baseUrl: `${options.ssl ? 'https' : 'http'}://${options.host}:${port}`,
172
- });
173
- return yield tslib_1.__await(new Promise((res) => {
174
- serve.on('exit', (code) => {
175
- if (code == 0) {
176
- res({ success: true });
177
- }
178
- else {
179
- res({ success: false });
180
- }
181
- });
182
- }));
183
174
  });
184
175
  }
185
176
  exports.default = fileServerExecutor;