@nx/rspack 19.8.0 → 20.0.0-beta.3

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.
Files changed (121) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +70 -34
  3. package/executors.json +2 -2
  4. package/module-federation.js +0 -1
  5. package/package.json +14 -9
  6. package/plugin.js +0 -1
  7. package/src/executors/dev-server/dev-server.impl.js +39 -38
  8. package/src/executors/dev-server/lib/get-dev-server-config.js +1 -3
  9. package/src/executors/dev-server/lib/serve-path.js +0 -1
  10. package/src/executors/dev-server/schema.json +3 -9
  11. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +109 -98
  12. package/src/executors/module-federation-dev-server/schema.json +1 -3
  13. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +153 -148
  14. package/src/executors/module-federation-ssr-dev-server/schema.json +1 -4
  15. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +117 -125
  16. package/src/executors/rspack/rspack.impl.js +60 -67
  17. package/src/executors/rspack/schema.json +6 -26
  18. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +0 -1
  19. package/src/executors/ssr-dev-server/schema.json +1 -4
  20. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +26 -40
  21. package/src/generators/application/application.js +79 -76
  22. package/src/generators/application/lib/create-ts-config.js +5 -3
  23. package/src/generators/application/lib/normalize-options.js +12 -7
  24. package/src/generators/application/schema.json +1 -0
  25. package/src/generators/configuration/configuration.js +63 -65
  26. package/src/generators/configuration/schema.json +2 -1
  27. package/src/generators/init/init.js +58 -59
  28. package/src/generators/init/schema.json +2 -1
  29. package/src/generators/preset/preset.js +26 -29
  30. package/src/generators/preset/schema.json +1 -0
  31. package/src/index.js +0 -1
  32. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -7
  33. package/src/plugins/generate-package-json-plugin.js +1 -3
  34. package/src/plugins/plugin.js +81 -90
  35. package/src/utils/config.js +7 -11
  36. package/src/utils/create-compiler.js +21 -25
  37. package/src/utils/generator-utils.js +55 -66
  38. package/src/utils/get-copy-patterns.js +1 -3
  39. package/src/utils/jest-utils.js +0 -1
  40. package/src/utils/mode-utils.js +0 -1
  41. package/src/utils/model.js +0 -1
  42. package/src/utils/module-federation/build-static.remotes.js +57 -61
  43. package/src/utils/module-federation/dependencies.js +1 -3
  44. package/src/utils/module-federation/get-remotes-for-host.js +4 -8
  45. package/src/utils/module-federation/index.js +0 -1
  46. package/src/utils/module-federation/models/index.js +0 -1
  47. package/src/utils/module-federation/package-json.js +0 -1
  48. package/src/utils/module-federation/parse-static-remotes-config.js +2 -3
  49. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +1 -2
  50. package/src/utils/module-federation/public-api.js +0 -1
  51. package/src/utils/module-federation/remotes.js +0 -1
  52. package/src/utils/module-federation/secondary-entry-points.js +4 -5
  53. package/src/utils/module-federation/share.js +22 -19
  54. package/src/utils/module-federation/start-remote-proxies.js +0 -1
  55. package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -1
  56. package/src/utils/module-federation/typescript.js +6 -6
  57. package/src/utils/module-federation/with-module-federation/package-json.js +0 -1
  58. package/src/utils/module-federation/with-module-federation/utils.js +41 -43
  59. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +48 -35
  60. package/src/utils/module-federation/with-module-federation/with-module-federation.js +56 -38
  61. package/src/utils/normalize-assets.js +5 -3
  62. package/src/utils/read-rspack-options.js +23 -27
  63. package/src/utils/resolve-user-defined-rspack-config.js +0 -1
  64. package/src/utils/versions.js +0 -1
  65. package/src/utils/with-nx.js +30 -13
  66. package/src/utils/with-react.js +11 -5
  67. package/src/utils/with-web.js +20 -11
  68. package/module-federation.js.map +0 -1
  69. package/plugin.js.map +0 -1
  70. package/src/executors/dev-server/dev-server.impl.js.map +0 -1
  71. package/src/executors/dev-server/lib/get-dev-server-config.js.map +0 -1
  72. package/src/executors/dev-server/lib/serve-path.js.map +0 -1
  73. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js.map +0 -1
  74. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js.map +0 -1
  75. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js.map +0 -1
  76. package/src/executors/rspack/rspack.impl.js.map +0 -1
  77. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js.map +0 -1
  78. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js.map +0 -1
  79. package/src/generators/application/application.js.map +0 -1
  80. package/src/generators/application/lib/create-ts-config.js.map +0 -1
  81. package/src/generators/application/lib/normalize-options.js.map +0 -1
  82. package/src/generators/configuration/configuration.js.map +0 -1
  83. package/src/generators/init/init.js.map +0 -1
  84. package/src/generators/preset/preset.js.map +0 -1
  85. package/src/index.js.map +0 -1
  86. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +0 -1
  87. package/src/plugins/generate-package-json-plugin.js.map +0 -1
  88. package/src/plugins/plugin.js.map +0 -1
  89. package/src/utils/config.js.map +0 -1
  90. package/src/utils/create-compiler.js.map +0 -1
  91. package/src/utils/generator-utils.js.map +0 -1
  92. package/src/utils/get-copy-patterns.js.map +0 -1
  93. package/src/utils/jest-utils.js.map +0 -1
  94. package/src/utils/mode-utils.js.map +0 -1
  95. package/src/utils/model.js.map +0 -1
  96. package/src/utils/module-federation/build-static.remotes.js.map +0 -1
  97. package/src/utils/module-federation/dependencies.js.map +0 -1
  98. package/src/utils/module-federation/get-remotes-for-host.js.map +0 -1
  99. package/src/utils/module-federation/index.js.map +0 -1
  100. package/src/utils/module-federation/models/index.js.map +0 -1
  101. package/src/utils/module-federation/package-json.js.map +0 -1
  102. package/src/utils/module-federation/parse-static-remotes-config.js.map +0 -1
  103. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js.map +0 -1
  104. package/src/utils/module-federation/public-api.js.map +0 -1
  105. package/src/utils/module-federation/remotes.js.map +0 -1
  106. package/src/utils/module-federation/secondary-entry-points.js.map +0 -1
  107. package/src/utils/module-federation/share.js.map +0 -1
  108. package/src/utils/module-federation/start-remote-proxies.js.map +0 -1
  109. package/src/utils/module-federation/start-ssr-remote-proxies.js.map +0 -1
  110. package/src/utils/module-federation/typescript.js.map +0 -1
  111. package/src/utils/module-federation/with-module-federation/package-json.js.map +0 -1
  112. package/src/utils/module-federation/with-module-federation/utils.js.map +0 -1
  113. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js.map +0 -1
  114. package/src/utils/module-federation/with-module-federation/with-module-federation.js.map +0 -1
  115. package/src/utils/normalize-assets.js.map +0 -1
  116. package/src/utils/read-rspack-options.js.map +0 -1
  117. package/src/utils/resolve-user-defined-rspack-config.js.map +0 -1
  118. package/src/utils/versions.js.map +0 -1
  119. package/src/utils/with-nx.js.map +0 -1
  120. package/src/utils/with-react.js.map +0 -1
  121. package/src/utils/with-web.js.map +0 -1
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/README.md CHANGED
@@ -1,3 +1,72 @@
1
+ <p style="text-align: center;">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
+ <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
+ </picture>
6
+ </p>
7
+
8
+ <div style="text-align: center;">
9
+
10
+ [![CircleCI](https://circleci.com/gh/nrwl/nx.svg?style=svg)](https://circleci.com/gh/nrwl/nx)
11
+ [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)]()
12
+ [![NPM Version](https://badge.fury.io/js/%40nrwl%2Fworkspace.svg)](https://www.npmjs.com/@nx/workspace)
13
+ [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]()
14
+ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
15
+ [![Join the chat at https://gitter.im/nrwl-nx/community](https://badges.gitter.im/nrwl-nx/community.svg)](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
16
+ [![Join us on the Official Nx Discord Server](https://img.shields.io/discord/1143497901675401286?label=discord)](https://go.nx.dev/community)
17
+
18
+ </div>
19
+
20
+
21
+ <hr>
22
+
23
+ # Nx: Smart Monorepos · Fast CI
24
+
25
+ Nx is a build system, optimized for monorepos, with plugins for popular frameworks and tools and advanced CI capabilities including caching and distribution.
26
+
27
+ This package is a [Rspack plugin for Nx](https://nx.dev/nx-api/rspack).
28
+
29
+ ## Getting Started
30
+
31
+ ### Creating an Nx Workspace
32
+
33
+ **Using `npx`**
34
+
35
+ ```bash
36
+ npx create-nx-workspace
37
+ ```
38
+
39
+ **Using `npm init`**
40
+
41
+ ```bash
42
+ npm init nx-workspace
43
+ ```
44
+
45
+ **Using `yarn create`**
46
+
47
+ ```bash
48
+ yarn create nx-workspace
49
+ ```
50
+
51
+ ### Adding Nx to an Existing Repository
52
+
53
+ Run:
54
+
55
+ ```bash
56
+ npx nx@latest init
57
+ ```
58
+
59
+ ## Documentation & Resources
60
+
61
+ - [Nx.Dev: Documentation, Guides, Tutorials](https://nx.dev)
62
+ - [Intro to Nx](https://nx.dev/getting-started/intro)
63
+ - [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
64
+ - [Blog Posts About Nx](https://nx.dev/blog)
65
+
66
+ <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
67
+ width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
68
+
69
+
1
70
  <p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
2
71
 
3
72
  <hr>
@@ -43,39 +112,6 @@ First, install the plugin:
43
112
  npm install --save-dev @nx/rspack
44
113
  ```
45
114
 
46
- Then, run the `rspack-project` generator:
47
-
48
- ```bash
49
- npx nx g @nx/rspack:rspack-project --skipValidation
50
- ```
51
-
52
- **Note:** The `--skipValidation` option allows you to overwrite existing build targets.
53
-
54
- ## Workspace libraries
55
-
56
- The `@nx/rspack` executor support importing workspace libs into the app.
57
-
58
- ```bash
59
- npx nx g @nx/react:lib mylib
60
- ```
61
-
62
- Import the new library in your app.
63
-
64
- ```typescript jsx
65
- // src/app/app.tsx
66
- import { Mylib } from '@rspack-demo/mylib';
67
-
68
- // ...
69
-
70
- export default function App() {
71
- return <MyLib />;
72
- }
73
- ```
74
-
75
- Now, run the dev server again to see the new library in action.
76
-
77
- ```bash
78
- npm start
79
- ```
115
+ Then, r
80
116
 
81
117
  **Note:** You must restart the server if you make any changes to your library.
package/executors.json CHANGED
@@ -4,12 +4,12 @@
4
4
  "rspack": {
5
5
  "implementation": "./src/executors/rspack/rspack.impl",
6
6
  "schema": "./src/executors/rspack/schema.json",
7
- "description": "rspack executor"
7
+ "description": "Run Rspack via an executor for a project."
8
8
  },
9
9
  "dev-server": {
10
10
  "implementation": "./src/executors/dev-server/dev-server.impl",
11
11
  "schema": "./src/executors/dev-server/schema.json",
12
- "description": "dev-server executor"
12
+ "description": "Run @rspack/dev-server to serve a project."
13
13
  },
14
14
  "ssr-dev-server": {
15
15
  "implementation": "./src/executors/ssr-dev-server/ssr-dev-server.impl",
@@ -2,4 +2,3 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./src/utils/module-federation/public-api"), exports);
5
- //# sourceMappingURL=module-federation.js.map
package/package.json CHANGED
@@ -1,16 +1,21 @@
1
1
  {
2
2
  "name": "@nx/rspack",
3
- "version": "19.8.0",
3
+ "description": "The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.",
4
+ "version": "20.0.0-beta.3",
4
5
  "type": "commonjs",
5
6
  "repository": {
6
7
  "type": "git",
7
- "url": "https://github.com/nrwl/nx-labs.git",
8
+ "url": "https://github.com/nrwl/nx.git",
8
9
  "directory": "packages/rspack"
9
10
  },
11
+ "bugs": {
12
+ "url": "https://github.com/nrwl/nx/issues"
13
+ },
10
14
  "keywords": [
11
15
  "Monorepo",
12
- "Next",
13
- "Vercel"
16
+ "Rspack",
17
+ "Bundling",
18
+ "Module Federation"
14
19
  ],
15
20
  "author": "Jack Hsu",
16
21
  "license": "MIT",
@@ -19,20 +24,20 @@
19
24
  "generators": "./generators.json",
20
25
  "executors": "./executors.json",
21
26
  "dependencies": {
22
- "@nx/js": "^19.5.7",
23
- "@nx/devkit": "^19.5.7",
27
+ "@nx/js": "20.0.0-beta.3",
28
+ "@nx/devkit": "20.0.0-beta.3",
29
+ "@nx/eslint": "20.0.0-beta.3",
24
30
  "@phenomnomnominal/tsquery": "~5.0.1",
25
31
  "less-loader": "11.1.0",
26
32
  "license-webpack-plugin": "^4.0.2",
27
33
  "sass-loader": "^12.2.0",
28
34
  "stylus-loader": "^7.1.0",
29
35
  "postcss-loader": "^8.1.1",
30
- "@nx/eslint": "^19.5.7",
31
- "@rspack/core": "^1.0.2",
36
+ "@rspack/core": "^1.0.4",
32
37
  "@rspack/plugin-react-refresh": "^1.0.0",
33
38
  "@rspack/plugin-minify": "^0.7.5",
34
39
  "chalk": "~4.1.0",
35
- "@nrwl/rspack": "19.8.0"
40
+ "@nrwl/rspack": "20.0.0-beta.3"
36
41
  },
37
42
  "peerDependencies": {
38
43
  "@module-federation/enhanced": "~0.6.0",
package/plugin.js CHANGED
@@ -4,4 +4,3 @@ exports.createNodesV2 = exports.createDependencies = void 0;
4
4
  var plugin_1 = require("./src/plugins/plugin");
5
5
  Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return plugin_1.createDependencies; } });
6
6
  Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
7
- //# sourceMappingURL=plugin.js.map
@@ -1,49 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = runExecutor;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
7
6
  const dev_server_1 = require("@rspack/dev-server");
8
7
  const create_compiler_1 = require("../../utils/create-compiler");
9
8
  const mode_utils_1 = require("../../utils/mode-utils");
10
9
  const get_dev_server_config_1 = require("./lib/get-dev-server-config");
11
- function runExecutor(options, context) {
12
- return tslib_1.__asyncGenerator(this, arguments, function* runExecutor_1() {
13
- var _a, _b, _c;
14
- var _d;
15
- (_a = (_d = process.env).NODE_ENV) !== null && _a !== void 0 ? _a : (_d.NODE_ENV = (_b = options.mode) !== null && _b !== void 0 ? _b : 'development');
16
- if ((0, mode_utils_1.isMode)(process.env.NODE_ENV)) {
17
- options.mode = process.env.NODE_ENV;
18
- }
19
- const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, context.projectGraph);
20
- const buildOptions = (0, devkit_1.readTargetOptions)(buildTarget, context);
21
- let devServerConfig = (0, get_dev_server_config_1.getDevServerOptions)(context.root, options, buildOptions);
22
- const compiler = yield tslib_1.__await((0, create_compiler_1.createCompiler)(Object.assign(Object.assign({}, buildOptions), { devServer: devServerConfig, mode: options.mode }), context));
23
- // Use the first one if it's MultiCompiler
24
- // https://webpack.js.org/configuration/dev-server/#root:~:text=Be%20aware%20that%20when%20exporting%20multiple%20configurations%20only%20the%20devServer%20options%20for%20the%20first%20configuration%20will%20be%20taken%20into%20account%20and%20used%20for%20all%20the%20configurations%20in%20the%20array.
25
- const firstCompiler = (0, create_compiler_1.isMultiCompiler)(compiler)
26
- ? compiler.compilers[0]
27
- : compiler;
28
- devServerConfig = Object.assign(Object.assign(Object.assign({}, devServerConfig), firstCompiler.options.devServer), { port: devServerConfig.port });
29
- const baseUrl = `http://localhost:${(_c = options.port) !== null && _c !== void 0 ? _c : 4200}`;
30
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.createAsyncIterable)(({ next }) => {
31
- const server = new dev_server_1.RspackDevServer(Object.assign(Object.assign({}, devServerConfig), { onListening: () => {
32
- next({
33
- success: true,
34
- baseUrl,
35
- });
36
- } }), compiler);
37
- server.compiler.hooks.done.tap('NX Rspack Dev Server', (stats) => {
38
- if (stats.hasErrors()) {
39
- devkit_1.logger.error(`NX Compilation failed. See above for more details.`);
40
- }
41
- else {
42
- devkit_1.logger.info(`NX Server ready at ${baseUrl}`);
43
- }
44
- });
45
- server.start();
46
- })))));
10
+ async function* runExecutor(options, context) {
11
+ process.env.NODE_ENV ??= options.mode ?? 'development';
12
+ if ((0, mode_utils_1.isMode)(process.env.NODE_ENV)) {
13
+ options.mode = process.env.NODE_ENV;
14
+ }
15
+ const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, context.projectGraph);
16
+ const buildOptions = (0, devkit_1.readTargetOptions)(buildTarget, context);
17
+ let devServerConfig = (0, get_dev_server_config_1.getDevServerOptions)(context.root, options, buildOptions);
18
+ const compiler = await (0, create_compiler_1.createCompiler)({ ...buildOptions, devServer: devServerConfig, mode: options.mode }, context);
19
+ // Use the first one if it's MultiCompiler
20
+ // https://webpack.js.org/configuration/dev-server/#root:~:text=Be%20aware%20that%20when%20exporting%20multiple%20configurations%20only%20the%20devServer%20options%20for%20the%20first%20configuration%20will%20be%20taken%20into%20account%20and%20used%20for%20all%20the%20configurations%20in%20the%20array.
21
+ const firstCompiler = (0, create_compiler_1.isMultiCompiler)(compiler)
22
+ ? compiler.compilers[0]
23
+ : compiler;
24
+ devServerConfig = {
25
+ ...devServerConfig,
26
+ ...firstCompiler.options.devServer,
27
+ port: devServerConfig.port,
28
+ };
29
+ const baseUrl = `http://localhost:${options.port ?? 4200}`;
30
+ return yield* (0, async_iterable_1.createAsyncIterable)(({ next }) => {
31
+ const server = new dev_server_1.RspackDevServer({
32
+ ...devServerConfig,
33
+ onListening: () => {
34
+ next({
35
+ success: true,
36
+ baseUrl,
37
+ });
38
+ },
39
+ }, compiler);
40
+ server.compiler.hooks.done.tap('NX Rspack Dev Server', (stats) => {
41
+ if (stats.hasErrors()) {
42
+ devkit_1.logger.error(`NX Compilation failed. See above for more details.`);
43
+ }
44
+ else {
45
+ devkit_1.logger.info(`NX Server ready at ${baseUrl}`);
46
+ }
47
+ });
48
+ server.start();
47
49
  });
48
50
  }
49
- //# sourceMappingURL=dev-server.impl.js.map
@@ -31,9 +31,8 @@ function getDevServerOptions(root, serveOptions, buildOptions) {
31
31
  htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
32
32
  },
33
33
  onListening(server) {
34
- var _a;
35
34
  const isHttps = server.options.https ||
36
- ((_a = server.options.server) === null || _a === void 0 ? void 0 : _a.type) === 'https';
35
+ server.options.server?.type === 'https';
37
36
  devkit_1.logger.info(`NX Web Development Server is listening at ${isHttps ? 'https' : 'http'}://${server.options.host}:${server.options.port}${(0, serve_path_1.buildServePath)(buildOptions)}`);
38
37
  },
39
38
  open: false,
@@ -68,4 +67,3 @@ function getSslConfig(root, options) {
68
67
  cert: (0, fs_1.readFileSync)(path.resolve(root, options.sslCert), 'utf-8'),
69
68
  };
70
69
  }
71
- //# sourceMappingURL=get-dev-server-config.js.map
@@ -42,4 +42,3 @@ function _findDefaultServePath(baseHref, deployUrl) {
42
42
  // Join together baseHref and deployUrl
43
43
  return `${normalizedBaseHref}${deployUrl || ''}`;
44
44
  }
45
- //# sourceMappingURL=serve-path.js.map
@@ -2,7 +2,7 @@
2
2
  "$schema": "http://json-schema.org/schema",
3
3
  "version": 2,
4
4
  "title": "Rspack dev-server executor",
5
- "description": "",
5
+ "description": "Run @rspack/dev-server to serve a project.",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "buildTarget": {
@@ -16,11 +16,7 @@
16
16
  "mode": {
17
17
  "type": "string",
18
18
  "description": "Mode to run the server in.",
19
- "enum": [
20
- "development",
21
- "production",
22
- "none"
23
- ]
19
+ "enum": ["development", "production", "none"]
24
20
  },
25
21
  "host": {
26
22
  "type": "string",
@@ -45,7 +41,5 @@
45
41
  "description": "Public URL where the application will be served."
46
42
  }
47
43
  },
48
- "required": [
49
- "buildTarget"
50
- ]
44
+ "required": ["buildTarget"]
51
45
  }
@@ -16,7 +16,9 @@ const dev_server_impl_1 = tslib_1.__importDefault(require("../dev-server/dev-ser
16
16
  function getBuildOptions(buildTarget, context) {
17
17
  const target = (0, devkit_1.parseTargetString)(buildTarget, context);
18
18
  const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
19
- return Object.assign({}, buildOptions);
19
+ return {
20
+ ...buildOptions,
21
+ };
20
22
  }
21
23
  function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
22
24
  if (!staticRemotesConfig.remotes ||
@@ -61,106 +63,115 @@ function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
61
63
  }, context);
62
64
  return staticRemotesIter;
63
65
  }
64
- function startRemotes(remotes_1, context_1, options_1) {
65
- return tslib_1.__awaiter(this, arguments, void 0, function* (remotes, context, options, target = 'serve') {
66
- var _a, _b;
67
- const remoteIters = [];
68
- for (const app of remotes) {
69
- const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets[target];
70
- const isUsingModuleFederationDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-dev-server');
71
- const configurationOverride = (_b = (_a = options.devRemotes) === null || _a === void 0 ? void 0 : _a.find((r) => typeof r !== 'string' && r.remoteName === app)) === null || _b === void 0 ? void 0 : _b.configuration;
72
- const defaultOverrides = Object.assign(Object.assign(Object.assign(Object.assign({}, (options.host ? { host: options.host } : {})), (options.ssl ? { ssl: options.ssl } : {})), (options.sslCert ? { sslCert: options.sslCert } : {})), (options.sslKey ? { sslKey: options.sslKey } : {}));
73
- const overrides = target === 'serve'
74
- ? Object.assign(Object.assign({ watch: true }, (isUsingModuleFederationDevServerExecutor
66
+ async function startRemotes(remotes, context, options, target = 'serve') {
67
+ const remoteIters = [];
68
+ for (const app of remotes) {
69
+ const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets[target];
70
+ const isUsingModuleFederationDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-dev-server');
71
+ const configurationOverride = options.devRemotes?.find((r) => typeof r !== 'string' && r.remoteName === app)?.configuration;
72
+ const defaultOverrides = {
73
+ ...(options.host ? { host: options.host } : {}),
74
+ ...(options.ssl ? { ssl: options.ssl } : {}),
75
+ ...(options.sslCert ? { sslCert: options.sslCert } : {}),
76
+ ...(options.sslKey ? { sslKey: options.sslKey } : {}),
77
+ };
78
+ const overrides = target === 'serve'
79
+ ? {
80
+ watch: true,
81
+ ...(isUsingModuleFederationDevServerExecutor
75
82
  ? { isInitialHost: false }
76
- : {})), defaultOverrides) : Object.assign({}, defaultOverrides);
77
- remoteIters.push(yield (0, devkit_1.runExecutor)({
78
- project: app,
79
- target,
80
- configuration: configurationOverride !== null && configurationOverride !== void 0 ? configurationOverride : context.configurationName,
81
- }, overrides, context));
82
- }
83
- return remoteIters;
84
- });
85
- }
86
- function moduleFederationDevServer(options, context) {
87
- return tslib_1.__asyncGenerator(this, arguments, function* moduleFederationDevServer_1() {
88
- var _a, _b, _c;
89
- // Force Node to resolve to look for the nx binary that is inside node_modules
90
- const nxBin = require.resolve('nx/bin/nx');
91
- const currIter = options.static
92
- ? (0, file_server_impl_1.default)(Object.assign(Object.assign({}, options), { parallel: false, withDeps: false, spa: false, cors: true, cacheSeconds: -1 }), context)
93
- : (0, dev_server_impl_1.default)(options, context);
94
- const p = context.projectsConfigurations.projects[context.projectName];
95
- const buildOptions = getBuildOptions(options.buildTarget, context);
96
- let pathToManifestFile = (0, path_1.join)(context.root, p.sourceRoot, 'assets/module-federation.manifest.json');
97
- if (options.pathToManifestFile) {
98
- const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
99
- if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
100
- throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
83
+ : {}),
84
+ ...defaultOverrides,
101
85
  }
102
- else if ((0, path_1.extname)(options.pathToManifestFile) !== '.json') {
103
- throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
104
- }
105
- pathToManifestFile = userPathToManifestFile;
86
+ : { ...defaultOverrides };
87
+ remoteIters.push(await (0, devkit_1.runExecutor)({
88
+ project: app,
89
+ target,
90
+ configuration: configurationOverride ?? context.configurationName,
91
+ }, overrides, context));
92
+ }
93
+ return remoteIters;
94
+ }
95
+ async function* moduleFederationDevServer(options, context) {
96
+ // Force Node to resolve to look for the nx binary that is inside node_modules
97
+ const nxBin = require.resolve('nx/bin/nx');
98
+ const currIter = options.static
99
+ ? (0, file_server_impl_1.default)({
100
+ ...options,
101
+ parallel: false,
102
+ withDeps: false,
103
+ spa: false,
104
+ cors: true,
105
+ cacheSeconds: -1,
106
+ }, context)
107
+ : (0, dev_server_impl_1.default)(options, context);
108
+ const p = context.projectsConfigurations.projects[context.projectName];
109
+ const buildOptions = getBuildOptions(options.buildTarget, context);
110
+ let pathToManifestFile = (0, path_1.join)(context.root, p.sourceRoot, 'assets/module-federation.manifest.json');
111
+ if (options.pathToManifestFile) {
112
+ const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
113
+ if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
114
+ throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
106
115
  }
116
+ else if ((0, path_1.extname)(options.pathToManifestFile) !== '.json') {
117
+ throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
118
+ }
119
+ pathToManifestFile = userPathToManifestFile;
120
+ }
121
+ if (!options.isInitialHost) {
122
+ return yield* currIter;
123
+ }
124
+ const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, p.root, 'react');
125
+ const remoteNames = options.devRemotes?.map((r) => typeof r === 'string' ? r : r.remoteName);
126
+ const remotes = (0, module_federation_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
127
+ projectName: context.projectName,
128
+ projectGraph: context.projectGraph,
129
+ root: context.root,
130
+ }, pathToManifestFile);
131
+ options.staticRemotesPort ??= remotes.staticRemotePort;
132
+ // Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
133
+ process.env.NX_MF_DEV_REMOTES = JSON.stringify([
134
+ ...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []),
135
+ p.name,
136
+ ]);
137
+ const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
138
+ const mappedLocationsOfStaticRemotes = await (0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options);
139
+ const devRemoteIters = await startRemotes(remotes.devRemotes, context, options, 'serve');
140
+ const staticRemotesIter = startStaticRemotesFileServer(staticRemotesConfig, context, options);
141
+ (0, start_remote_proxies_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
142
+ ? {
143
+ pathToCert: (0, path_1.join)(devkit_1.workspaceRoot, options.sslCert),
144
+ pathToKey: (0, path_1.join)(devkit_1.workspaceRoot, options.sslKey),
145
+ }
146
+ : undefined);
147
+ return yield* (0, async_iterable_1.combineAsyncIterables)(currIter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
107
148
  if (!options.isInitialHost) {
108
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(currIter))));
149
+ done();
150
+ return;
109
151
  }
110
- const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, p.root, 'react');
111
- const remoteNames = (_a = options.devRemotes) === null || _a === void 0 ? void 0 : _a.map((r) => typeof r === 'string' ? r : r.remoteName);
112
- const remotes = (0, module_federation_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
113
- projectName: context.projectName,
114
- projectGraph: context.projectGraph,
115
- root: context.root,
116
- }, pathToManifestFile);
117
- (_b = options.staticRemotesPort) !== null && _b !== void 0 ? _b : (options.staticRemotesPort = remotes.staticRemotePort);
118
- // Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
119
- process.env.NX_MF_DEV_REMOTES = JSON.stringify([
120
- ...((_c = remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName)) !== null && _c !== void 0 ? _c : []),
121
- p.name,
122
- ]);
123
- const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
124
- const mappedLocationsOfStaticRemotes = yield tslib_1.__await((0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options));
125
- const devRemoteIters = yield tslib_1.__await(startRemotes(remotes.devRemotes, context, options, 'serve'));
126
- const staticRemotesIter = startStaticRemotesFileServer(staticRemotesConfig, context, options);
127
- (0, start_remote_proxies_1.startRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
128
- ? {
129
- pathToCert: (0, path_1.join)(devkit_1.workspaceRoot, options.sslCert),
130
- pathToKey: (0, path_1.join)(devkit_1.workspaceRoot, options.sslKey),
131
- }
132
- : undefined);
133
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.combineAsyncIterables)(currIter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, async_iterable_1.createAsyncIterable)((_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ next, done }) {
134
- var _b;
135
- if (!options.isInitialHost) {
136
- done();
137
- return;
138
- }
139
- if (remotes.remotePorts.length === 0) {
140
- done();
141
- return;
142
- }
143
- try {
144
- const host = (_b = options.host) !== null && _b !== void 0 ? _b : 'localhost';
145
- const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
146
- const portsToWaitFor = staticRemotesIter
147
- ? [options.staticRemotesPort, ...remotes.remotePorts]
148
- : [...remotes.remotePorts];
149
- yield Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
150
- retries: 480,
151
- retryDelay: 2500,
152
- host: host,
153
- })));
154
- devkit_1.logger.info(`NX All remotes started, server ready at ${baseUrl}`);
155
- next({ success: true, baseUrl: baseUrl });
156
- }
157
- catch (err) {
158
- throw new Error(`Failed to start remotes. Check above for any errors.`);
159
- }
160
- finally {
161
- done();
162
- }
163
- })))))));
164
- });
152
+ if (remotes.remotePorts.length === 0) {
153
+ done();
154
+ return;
155
+ }
156
+ try {
157
+ const host = options.host ?? 'localhost';
158
+ const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
159
+ const portsToWaitFor = staticRemotesIter
160
+ ? [options.staticRemotesPort, ...remotes.remotePorts]
161
+ : [...remotes.remotePorts];
162
+ await Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
163
+ retries: 480,
164
+ retryDelay: 2500,
165
+ host: host,
166
+ })));
167
+ devkit_1.logger.info(`NX All remotes started, server ready at ${baseUrl}`);
168
+ next({ success: true, baseUrl: baseUrl });
169
+ }
170
+ catch (err) {
171
+ throw new Error(`Failed to start remotes. Check above for any errors.`);
172
+ }
173
+ finally {
174
+ done();
175
+ }
176
+ }));
165
177
  }
166
- //# sourceMappingURL=module-federation-dev-server.impl.js.map
@@ -23,9 +23,7 @@
23
23
  "type": "string"
24
24
  }
25
25
  },
26
- "required": [
27
- "remoteName"
28
- ],
26
+ "required": ["remoteName"],
29
27
  "additionalProperties": false
30
28
  }
31
29
  ]