@nx/web 18.2.0-beta.0 → 18.2.0-beta.2

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/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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/web",
3
- "version": "18.2.0-beta.0",
3
+ "version": "18.2.0-beta.2",
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": "18.2.0-beta.0",
38
- "@nx/js": "18.2.0-beta.0",
39
- "@nrwl/web": "18.2.0-beta.0"
37
+ "@nx/devkit": "18.2.0-beta.2",
38
+ "@nx/js": "18.2.0-beta.2",
39
+ "@nrwl/web": "18.2.0-beta.2"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
@@ -150,12 +150,16 @@ async function* fileServerExecutor(options, context) {
150
150
  // perform initial run
151
151
  run();
152
152
  }
153
+ const port = await detectPort(options.port || 8080);
153
154
  const outputPath = getBuildTargetOutputPath(options, context);
154
155
  if (options.spa) {
155
156
  const src = (0, path_1.join)(outputPath, 'index.html');
156
157
  const dst = (0, path_1.join)(outputPath, '404.html');
157
158
  // See: https://github.com/http-party/http-server#magic-files
158
159
  (0, fs_1.copyFileSync)(src, dst);
160
+ // We also need to ensure the proxyUrl is set, otherwise the browser will continue to throw a 404 error
161
+ // This can cause unexpected behaviors and failures especially in automated test suites
162
+ options.proxyUrl ??= `http${options.ssl ? 's' : ''}://localhost:${port}?`;
159
163
  }
160
164
  const args = getHttpServerArgs(options);
161
165
  const { path: pathToHttpServerPkgJson, packageJson } = (0, package_json_1.readModulePackageJson)('http-server', module.paths);
@@ -163,7 +167,6 @@ async function* fileServerExecutor(options, context) {
163
167
  const pathToHttpServer = (0, path_1.resolve)(pathToHttpServerPkgJson.replace('package.json', ''), pathToHttpServerBin);
164
168
  // detect port as close to when used to prevent port being used by another process
165
169
  // when running in parallel
166
- const port = await detectPort(options.port || 8080);
167
170
  args.push(`-p=${port}`);
168
171
  const serve = (0, child_process_1.fork)(pathToHttpServer, [outputPath, ...args], {
169
172
  stdio: 'pipe',
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "proxyUrl": {
46
46
  "type": "string",
47
- "description": "URL to proxy unhandled requests to."
47
+ "description": "URL to proxy unhandled requests to. _Note: If the 'spa' flag is set to true, manually setting this value will override the catch-all redirect functionality from http-server which may lead to unexpected behavior._"
48
48
  },
49
49
  "proxyOptions": {
50
50
  "type": "object",
@@ -18,6 +18,11 @@
18
18
  "type": "string",
19
19
  "description": "Name of the serve target to add. Defaults to 'serve-static'.",
20
20
  "default": "serve-static"
21
+ },
22
+ "spa": {
23
+ "type": "boolean",
24
+ "description": "Whether to set the 'spa' flag on the generated target.",
25
+ "default": true
21
26
  }
22
27
  },
23
28
  "required": ["buildTarget"]
@@ -1,8 +1,9 @@
1
- import { Tree } from '@nx/devkit';
1
+ import { type Tree } from '@nx/devkit';
2
2
  interface WebStaticServeSchema {
3
3
  buildTarget: string;
4
4
  outputPath?: string;
5
5
  targetName?: string;
6
+ spa?: boolean;
6
7
  }
7
- export declare function webStaticServeGenerator(tree: Tree, options: WebStaticServeSchema): void;
8
+ export declare function webStaticServeGenerator(tree: Tree, options: WebStaticServeSchema): Promise<void>;
8
9
  export default webStaticServeGenerator;
@@ -2,17 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.webStaticServeGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- function webStaticServeGenerator(tree, options) {
6
- const opts = normalizeOptions(tree, options);
5
+ async function webStaticServeGenerator(tree, options) {
6
+ const opts = await normalizeOptions(tree, options);
7
7
  addStaticConfig(tree, opts);
8
8
  }
9
9
  exports.webStaticServeGenerator = webStaticServeGenerator;
10
- function normalizeOptions(tree, options) {
11
- const target = (0, devkit_1.parseTargetString)(options.buildTarget);
10
+ async function normalizeOptions(tree, options) {
11
+ let projectGraph;
12
+ try {
13
+ projectGraph = (0, devkit_1.readCachedProjectGraph)();
14
+ }
15
+ catch (e) {
16
+ projectGraph = await (0, devkit_1.createProjectGraphAsync)();
17
+ }
18
+ const target = (0, devkit_1.parseTargetString)(options.buildTarget, projectGraph);
12
19
  const opts = {
13
20
  ...options,
14
21
  targetName: options.targetName || 'serve-static',
15
22
  projectName: target.project,
23
+ spa: options.spa ?? true,
16
24
  };
17
25
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, target.project);
18
26
  const buildTargetConfig = projectConfig?.targets?.[target.target];
@@ -27,7 +35,7 @@ Optionally, you can provide a different name with the --target-name option other
27
35
  }
28
36
  // NOTE: @nx/web:file-server only looks for the outputPath option
29
37
  if (!buildTargetConfig.options?.outputPath && !opts.outputPath) {
30
- // attempt to find the suiteable path from the outputs
38
+ // attempt to find the suitable path from the outputs
31
39
  let maybeOutputValue;
32
40
  for (const o of buildTargetConfig?.outputs || []) {
33
41
  const isInterpolatedOutput = o.trim().startsWith('{options.');
@@ -65,6 +73,7 @@ function addStaticConfig(tree, opts) {
65
73
  options: {
66
74
  buildTarget: opts.buildTarget,
67
75
  staticFilePath: opts.outputPath,
76
+ spa: opts.spa,
68
77
  },
69
78
  };
70
79
  projectConfig.targets[opts.targetName] = staticServeOptions;