@modern-js/app-tools 2.10.0 → 2.11.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,71 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 2.11.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 415bee6: fix: load chunk while can not load all css asset, when streaming ssr.
8
+ fix: 使用 streaming ssr 时,不能加载当前 chunk 的所有 css 资源
9
+ - c0ba89b: feat: 控制台输出 rspack 版本
10
+ feat: Print the version of rspack in the console.
11
+ - 0bd018b: feat: support use node api run dev & build & deploy command
12
+ feat: 支持通过 node api 运行 dev & build & deploy 命令
13
+ - 5d624fd: feat: assets and data prefetching is supported
14
+ feat: 支持资源和数据预加载
15
+ - 7017909: fix: distpath.root not take effect when serve
16
+
17
+ fix: 修复 distpath.root 在 run serve 时不生效的问题
18
+
19
+ - 381a3b9: feat(utils): move universal utils to the universal folder
20
+
21
+ feat(utils): 将运行时使用的 utils 移动到 universal 目录
22
+
23
+ - a47543a: fix: should hide publicPath in injected manifest
24
+ fix: 应该隐藏 publicPath 在注入的 manifest 中
25
+ - Updated dependencies [adcedad]
26
+ - Updated dependencies [cfb058f]
27
+ - Updated dependencies [a9c6083]
28
+ - Updated dependencies [55b07fd]
29
+ - Updated dependencies [c0ba89b]
30
+ - Updated dependencies [0bd018b]
31
+ - Updated dependencies [8b90c79]
32
+ - Updated dependencies [a8c08c3]
33
+ - Updated dependencies [3aa318d]
34
+ - Updated dependencies [5d624fd]
35
+ - Updated dependencies [e2466a1]
36
+ - Updated dependencies [58faba2]
37
+ - Updated dependencies [53b0a63]
38
+ - Updated dependencies [02bb383]
39
+ - Updated dependencies [3171c9d]
40
+ - Updated dependencies [381a3b9]
41
+ - Updated dependencies [7a60f10]
42
+ - Updated dependencies [73cfc9b]
43
+ - Updated dependencies [cd1040f]
44
+ - Updated dependencies [e262a99]
45
+ - Updated dependencies [7178795]
46
+ - Updated dependencies [1140a69]
47
+ - Updated dependencies [b71cef1]
48
+ - Updated dependencies [274b2e5]
49
+ - Updated dependencies [b9e1c54]
50
+ - @modern-js/builder-shared@2.11.0
51
+ - @modern-js/builder-webpack-provider@2.11.0
52
+ - @modern-js/builder@2.11.0
53
+ - @modern-js/utils@2.11.0
54
+ - @modern-js/builder-rspack-provider@2.11.0
55
+ - @modern-js/core@2.11.0
56
+ - @modern-js/builder-plugin-node-polyfill@2.11.0
57
+ - @modern-js/plugin-data-loader@2.11.0
58
+ - @modern-js/plugin-lint@2.11.0
59
+ - @modern-js/prod-server@2.11.0
60
+ - @modern-js/server@2.11.0
61
+ - @modern-js/builder-plugin-esbuild@2.11.0
62
+ - @modern-js/plugin-i18n@2.11.0
63
+ - @modern-js/new-action@2.11.0
64
+ - @modern-js/node-bundle-require@2.11.0
65
+ - @modern-js/upgrade@2.11.0
66
+ - @modern-js/plugin@2.11.0
67
+ - @modern-js/types@2.11.0
68
+
3
69
  ## 2.10.0
4
70
 
5
71
  ### Patch Changes
@@ -118,7 +118,7 @@ var analyze_default = ({
118
118
  debug(`add Define Types`);
119
119
  let checkedEntries = entrypoints.map((point) => point.entryName);
120
120
  if ((0, import_utils.isDevCommand)()) {
121
- const { entry } = (0, import_utils.minimist)(process.argv.slice(2));
121
+ const { entry } = (0, import_utils.minimist)((0, import_utils.getArgv)());
122
122
  checkedEntries = await (0, import_getSelectedEntries.getSelectedEntries)(
123
123
  typeof entry === "string" ? entry.split(",") : entry,
124
124
  entrypoints
@@ -35,7 +35,9 @@ async function createBuilderGenerator(bundler) {
35
35
  if (bundler === "rspack") {
36
36
  try {
37
37
  const { createRspackBuilderForModern } = await Promise.resolve().then(() => __toESM(require("./builder-rspack")));
38
- import_utils.logger.info("Using Rspack ");
38
+ const { getRspackVersion } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-rspack-provider")));
39
+ const version = await getRspackVersion();
40
+ import_utils.logger.info(`Using Rspack v${version} 🦀`);
39
41
  return createRspackBuilderForModern;
40
42
  } catch (_) {
41
43
  throw new Error(
@@ -43,8 +43,8 @@ const builderPluginAdapterSSR = (options) => ({
43
43
  async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
44
44
  const builderConfig = api.getNormalizedConfig();
45
45
  const { normalizedConfig: normalizedConfig2 } = options;
46
+ applyRouterPlugin(chain, options);
46
47
  if ((0, import_utils.isSSR)(normalizedConfig2)) {
47
- applyRouterPlugin(chain, options);
48
48
  await applySSRLoaderEntry(chain, options, isServer);
49
49
  }
50
50
  if (["node", "service-worker"].includes(target)) {
@@ -32,6 +32,8 @@ __export(RouterPlugin_exports, {
32
32
  module.exports = __toCommonJS(RouterPlugin_exports);
33
33
  var import_path = __toESM(require("path"));
34
34
  var import_utils = require("@modern-js/utils");
35
+ var import_constants = require("@modern-js/utils/constants");
36
+ var import_constants2 = require("@modern-js/utils/universal/constants");
35
37
  const PLUGIN_NAME = "ModernjsRoutePlugin";
36
38
  class RouterPlugin {
37
39
  apply(compiler) {
@@ -66,11 +68,12 @@ class RouterPlugin {
66
68
  publicPath: true,
67
69
  assets: true,
68
70
  chunkGroups: true,
69
- chunks: true
71
+ chunks: true,
72
+ ids: true
70
73
  });
71
- const { publicPath, chunks = [] } = stats;
74
+ const { publicPath, chunks = [], assetsByChunkName } = stats;
72
75
  const routeAssets = {};
73
- const { namedChunkGroups, assetsByChunkName } = stats;
76
+ const { namedChunkGroups } = stats;
74
77
  if (!namedChunkGroups || !assetsByChunkName) {
75
78
  import_utils.logger.warn(
76
79
  "Route manifest does not exist, performance will be affected"
@@ -78,21 +81,31 @@ class RouterPlugin {
78
81
  return;
79
82
  }
80
83
  for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
81
- if (assetsByChunkName[name]) {
82
- routeAssets[name] = {
83
- chunkIds: chunkGroup.chunks,
84
- assets: assetsByChunkName[name].map(
85
- (item) => publicPath ? normalizePath(publicPath) + item : item
86
- )
87
- };
88
- }
84
+ const referenceCssAssets = chunkGroup.assets.filter((asset) => /\.css$/.test(asset.name)).map((asset) => {
85
+ const item = asset.name;
86
+ return publicPath ? normalizePath(publicPath) + item : item;
87
+ });
88
+ routeAssets[name] = {
89
+ chunkIds: chunkGroup.chunks,
90
+ assets: assetsByChunkName[name].map(
91
+ (item) => publicPath ? normalizePath(publicPath) + item : item
92
+ ),
93
+ referenceCssAssets
94
+ };
89
95
  }
90
96
  const manifest = {
91
97
  routeAssets
92
98
  };
93
99
  const injectedContent = `
94
100
  ;(function(){
95
- window.${import_utils.ROUTE_MANIFEST} = ${JSON.stringify(manifest)};
101
+ window.${import_constants2.ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v) => {
102
+ if (k === "assets" && Array.isArray(v)) {
103
+ return v.map((item) => {
104
+ return item.replace(publicPath, "");
105
+ });
106
+ }
107
+ return v;
108
+ })};
96
109
  })();
97
110
  `;
98
111
  const entrypointsArray = Array.from(
@@ -122,7 +135,7 @@ class RouterPlugin {
122
135
  void 0
123
136
  );
124
137
  }
125
- const filename = import_path.default.join(outputPath, import_utils.ROUTE_MINIFEST_FILE);
138
+ const filename = import_path.default.join(outputPath, import_constants.ROUTE_MANIFEST_FILE);
126
139
  await import_utils.fs.ensureFile(filename);
127
140
  await import_utils.fs.writeFile(filename, JSON.stringify(manifest, null, 2));
128
141
  }
@@ -36,7 +36,7 @@ var import_printInstructions = require("../utils/printInstructions");
36
36
  var import_createServer = require("../utils/createServer");
37
37
  var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
38
38
  const start = async (api) => {
39
- var _a;
39
+ var _a, _b;
40
40
  const appContext = api.useAppContext();
41
41
  const userConfig = api.useResolvedConfigContext();
42
42
  const hookRunners = api.useHookRunners();
@@ -49,7 +49,14 @@ const start = async (api) => {
49
49
  const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
50
50
  const app = await (0, import_prod_server.default)({
51
51
  pwd: appDirectory,
52
- config: userConfig,
52
+ config: {
53
+ ...userConfig,
54
+ dev: userConfig.dev,
55
+ output: {
56
+ path: (_b = userConfig.output.distPath) == null ? void 0 : _b.root,
57
+ ...userConfig.output || {}
58
+ }
59
+ },
53
60
  appContext: {
54
61
  sharedDirectory: (0, import_utils.getTargetDir)(
55
62
  appContext.sharedDirectory,
@@ -35,7 +35,7 @@ async function restart(hooksRunner, filename) {
35
35
  hasGetError = true;
36
36
  } finally {
37
37
  if (!hasGetError) {
38
- import_utils.program.parse(process.argv);
38
+ import_utils.program.parse((0, import_utils.getArgv)());
39
39
  }
40
40
  }
41
41
  }
@@ -221,7 +221,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
221
221
  }
222
222
  };
223
223
  import * as path from "path";
224
- import { createDebugger, findExists, fs, isApiOnly, minimist, getCommand, isDevCommand } from "@modern-js/utils";
224
+ import { createDebugger, findExists, fs, isApiOnly, minimist, getCommand, isDevCommand, getArgv } from "@modern-js/utils";
225
225
  import { cloneDeep } from "@modern-js/utils/lodash";
226
226
  import { printInstructions } from "../utils/printInstructions";
227
227
  import { generateRoutes } from "../utils/routes";
@@ -358,7 +358,7 @@ var analyze_default = function(param) {
358
358
  3,
359
359
  11
360
360
  ];
361
- entry = minimist(process.argv.slice(2)).entry;
361
+ entry = minimist(getArgv()).entry;
362
362
  return [
363
363
  4,
364
364
  getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
@@ -128,21 +128,21 @@ function createBuilderGenerator(bundler) {
128
128
  }
129
129
  function _createBuilderGenerator() {
130
130
  _createBuilderGenerator = _asyncToGenerator(function(bundler) {
131
- var createRspackBuilderForModern, _, createWebpackBuilderForModern;
131
+ var createRspackBuilderForModern, getRspackVersion, version, _, createWebpackBuilderForModern;
132
132
  return __generator(this, function(_state) {
133
133
  switch(_state.label){
134
134
  case 0:
135
135
  if (!(bundler === "rspack")) return [
136
136
  3,
137
- 4
137
+ 6
138
138
  ];
139
139
  _state.label = 1;
140
140
  case 1:
141
141
  _state.trys.push([
142
142
  1,
143
- 3,
143
+ 5,
144
144
  ,
145
- 4
145
+ 6
146
146
  ]);
147
147
  return [
148
148
  4,
@@ -150,20 +150,32 @@ function _createBuilderGenerator() {
150
150
  ];
151
151
  case 2:
152
152
  createRspackBuilderForModern = _state.sent().createRspackBuilderForModern;
153
- logger.info("Using Rspack ✨");
153
+ return [
154
+ 4,
155
+ import("@modern-js/builder-rspack-provider")
156
+ ];
157
+ case 3:
158
+ getRspackVersion = _state.sent().getRspackVersion;
159
+ return [
160
+ 4,
161
+ getRspackVersion()
162
+ ];
163
+ case 4:
164
+ version = _state.sent();
165
+ logger.info("Using Rspack v".concat(version, " \uD83E\uDD80"));
154
166
  return [
155
167
  2,
156
168
  createRspackBuilderForModern
157
169
  ];
158
- case 3:
170
+ case 5:
159
171
  _ = _state.sent();
160
172
  throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
161
- case 4:
173
+ case 6:
162
174
  return [
163
175
  4,
164
176
  import("./builder-webpack")
165
177
  ];
166
- case 5:
178
+ case 7:
167
179
  createWebpackBuilderForModern = _state.sent().createWebpackBuilderForModern;
168
180
  return [
169
181
  2,
@@ -151,11 +151,11 @@ var builderPluginAdapterSSR = function(options) {
151
151
  target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer;
152
152
  builderConfig = api.getNormalizedConfig();
153
153
  normalizedConfig2 = options.normalizedConfig;
154
+ applyRouterPlugin(chain, options);
154
155
  if (!isSSR(normalizedConfig2)) return [
155
156
  3,
156
157
  2
157
158
  ];
158
- applyRouterPlugin(chain, options);
159
159
  return [
160
160
  4,
161
161
  applySSRLoaderEntry(chain, options, isServer)
@@ -200,7 +200,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
200
200
  }
201
201
  };
202
202
  import path from "path";
203
- import { fs, ROUTE_MANIFEST, logger, ROUTE_MINIFEST_FILE } from "@modern-js/utils";
203
+ import { fs, logger } from "@modern-js/utils";
204
+ import { ROUTE_MANIFEST_FILE } from "@modern-js/utils/constants";
205
+ import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
204
206
  var PLUGIN_NAME = "ModernjsRoutePlugin";
205
207
  var RouterPlugin = /*#__PURE__*/ function() {
206
208
  "use strict";
@@ -235,7 +237,7 @@ var RouterPlugin = /*#__PURE__*/ function() {
235
237
  name: PLUGIN_NAME,
236
238
  stage: PROCESS_ASSETS_STAGE_REPORT
237
239
  }, /*#__PURE__*/ _asyncToGenerator(function() {
238
- var stats, publicPath, _stats_chunks, chunks, routeAssets, namedChunkGroups, assetsByChunkName, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, manifest, injectedContent, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, file, asset, newContent, filename;
240
+ var stats, publicPath, _stats_chunks, chunks, assetsByChunkName, routeAssets, namedChunkGroups, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, referenceCssAssets, manifest, injectedContent, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, file, asset, newContent, filename;
239
241
  return __generator(this, function(_state) {
240
242
  switch(_state.label){
241
243
  case 0:
@@ -244,11 +246,12 @@ var RouterPlugin = /*#__PURE__*/ function() {
244
246
  publicPath: true,
245
247
  assets: true,
246
248
  chunkGroups: true,
247
- chunks: true
249
+ chunks: true,
250
+ ids: true
248
251
  });
249
- publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks;
252
+ publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, assetsByChunkName = stats.assetsByChunkName;
250
253
  routeAssets = {};
251
- namedChunkGroups = stats.namedChunkGroups, assetsByChunkName = stats.assetsByChunkName;
254
+ namedChunkGroups = stats.namedChunkGroups;
252
255
  if (!namedChunkGroups || !assetsByChunkName) {
253
256
  logger.warn("Route manifest does not exist, performance will be affected");
254
257
  return [
@@ -259,14 +262,19 @@ var RouterPlugin = /*#__PURE__*/ function() {
259
262
  try {
260
263
  for(_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
261
264
  _step_value = _slicedToArray(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
262
- if (assetsByChunkName[name]) {
263
- routeAssets[name] = {
264
- chunkIds: chunkGroup.chunks,
265
- assets: assetsByChunkName[name].map(function(item) {
266
- return publicPath ? normalizePath(publicPath) + item : item;
267
- })
268
- };
269
- }
265
+ referenceCssAssets = chunkGroup.assets.filter(function(asset) {
266
+ return /\.css$/.test(asset.name);
267
+ }).map(function(asset) {
268
+ var item = asset.name;
269
+ return publicPath ? normalizePath(publicPath) + item : item;
270
+ });
271
+ routeAssets[name] = {
272
+ chunkIds: chunkGroup.chunks,
273
+ assets: assetsByChunkName[name].map(function(item) {
274
+ return publicPath ? normalizePath(publicPath) + item : item;
275
+ }),
276
+ referenceCssAssets: referenceCssAssets
277
+ };
270
278
  }
271
279
  } catch (err) {
272
280
  _didIteratorError = true;
@@ -285,7 +293,14 @@ var RouterPlugin = /*#__PURE__*/ function() {
285
293
  manifest = {
286
294
  routeAssets: routeAssets
287
295
  };
288
- injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest), ";\n })();\n ");
296
+ injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest, function(k, v) {
297
+ if (k === "assets" && Array.isArray(v)) {
298
+ return v.map(function(item) {
299
+ return item.replace(publicPath, "");
300
+ });
301
+ }
302
+ return v;
303
+ }), ";\n })();\n ");
289
304
  entrypointsArray = Array.from(compilation.entrypoints.entries());
290
305
  entryChunkIds = entrypointsArray.map(function(entrypoint) {
291
306
  return entrypoint[0];
@@ -328,7 +343,7 @@ var RouterPlugin = /*#__PURE__*/ function() {
328
343
  }
329
344
  }
330
345
  }
331
- filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
346
+ filename = path.join(outputPath, ROUTE_MANIFEST_FILE);
332
347
  return [
333
348
  4,
334
349
  fs.ensureFile(filename)
@@ -27,6 +27,58 @@ function _asyncToGenerator(fn) {
27
27
  });
28
28
  };
29
29
  }
30
+ function _defineProperty(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
+ }
43
+ function _objectSpread(target) {
44
+ for(var i = 1; i < arguments.length; i++){
45
+ var source = arguments[i] != null ? arguments[i] : {};
46
+ var ownKeys = Object.keys(source);
47
+ if (typeof Object.getOwnPropertySymbols === "function") {
48
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
+ }));
51
+ }
52
+ ownKeys.forEach(function(key) {
53
+ _defineProperty(target, key, source[key]);
54
+ });
55
+ }
56
+ return target;
57
+ }
58
+ function ownKeys(object, enumerableOnly) {
59
+ var keys = Object.keys(object);
60
+ if (Object.getOwnPropertySymbols) {
61
+ var symbols = Object.getOwnPropertySymbols(object);
62
+ if (enumerableOnly) {
63
+ symbols = symbols.filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
+ });
66
+ }
67
+ keys.push.apply(keys, symbols);
68
+ }
69
+ return keys;
70
+ }
71
+ function _objectSpreadProps(target, source) {
72
+ source = source != null ? source : {};
73
+ if (Object.getOwnPropertyDescriptors) {
74
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
75
+ } else {
76
+ ownKeys(Object(source)).forEach(function(key) {
77
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
78
+ });
79
+ }
80
+ return target;
81
+ }
30
82
  var __generator = this && this.__generator || function(thisArg, body) {
31
83
  var f, y, t, g, _ = {
32
84
  label: 0,
@@ -129,7 +181,7 @@ import { injectDataLoaderPlugin } from "../utils/createServer";
129
181
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
130
182
  var start = function() {
131
183
  var _ref = _asyncToGenerator(function(api) {
132
- var _userConfig_source, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, serverInternalPlugins, app;
184
+ var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, serverInternalPlugins, app;
133
185
  return __generator(this, function(_state) {
134
186
  switch(_state.label){
135
187
  case 0:
@@ -154,7 +206,12 @@ var start = function() {
154
206
  4,
155
207
  server({
156
208
  pwd: appDirectory,
157
- config: userConfig,
209
+ config: _objectSpreadProps(_objectSpread({}, userConfig), {
210
+ dev: userConfig.dev,
211
+ output: _objectSpread({
212
+ path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root
213
+ }, userConfig.output || {})
214
+ }),
158
215
  appContext: {
159
216
  sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
160
217
  apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
@@ -123,7 +123,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
123
123
  }
124
124
  };
125
125
  import { cli } from "@modern-js/core";
126
- import { chalk, clearConsole, logger, program } from "@modern-js/utils";
126
+ import { chalk, clearConsole, getArgv, logger, program } from "@modern-js/utils";
127
127
  function restart(hooksRunner, filename) {
128
128
  return _restart.apply(this, arguments);
129
129
  }
@@ -170,7 +170,7 @@ function _restart() {
170
170
  ];
171
171
  case 5:
172
172
  if (!hasGetError) {
173
- program.parse(process.argv);
173
+ program.parse(getArgv());
174
174
  }
175
175
  return [
176
176
  7
@@ -6,7 +6,8 @@ import {
6
6
  isApiOnly,
7
7
  minimist,
8
8
  getCommand,
9
- isDevCommand
9
+ isDevCommand,
10
+ getArgv
10
11
  } from "@modern-js/utils";
11
12
  import { cloneDeep } from "@modern-js/utils/lodash";
12
13
  import { printInstructions } from "../utils/printInstructions";
@@ -98,7 +99,7 @@ var analyze_default = ({
98
99
  debug(`add Define Types`);
99
100
  let checkedEntries = entrypoints.map((point) => point.entryName);
100
101
  if (isDevCommand()) {
101
- const { entry } = minimist(process.argv.slice(2));
102
+ const { entry } = minimist(getArgv());
102
103
  checkedEntries = await getSelectedEntries(
103
104
  typeof entry === "string" ? entry.split(",") : entry,
104
105
  entrypoints
@@ -3,7 +3,9 @@ async function createBuilderGenerator(bundler) {
3
3
  if (bundler === "rspack") {
4
4
  try {
5
5
  const { createRspackBuilderForModern } = await import("./builder-rspack");
6
- logger.info("Using Rspack ");
6
+ const { getRspackVersion } = await import("@modern-js/builder-rspack-provider");
7
+ const version = await getRspackVersion();
8
+ logger.info(`Using Rspack v${version} 🦀`);
7
9
  return createRspackBuilderForModern;
8
10
  } catch (_) {
9
11
  throw new Error(
@@ -23,8 +23,8 @@ const builderPluginAdapterSSR = (options) => ({
23
23
  async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
24
24
  const builderConfig = api.getNormalizedConfig();
25
25
  const { normalizedConfig: normalizedConfig2 } = options;
26
+ applyRouterPlugin(chain, options);
26
27
  if (isSSR(normalizedConfig2)) {
27
- applyRouterPlugin(chain, options);
28
28
  await applySSRLoaderEntry(chain, options, isServer);
29
29
  }
30
30
  if (["node", "service-worker"].includes(target)) {
@@ -1,10 +1,7 @@
1
1
  import path from "path";
2
- import {
3
- fs,
4
- ROUTE_MANIFEST,
5
- logger,
6
- ROUTE_MINIFEST_FILE
7
- } from "@modern-js/utils";
2
+ import { fs, logger } from "@modern-js/utils";
3
+ import { ROUTE_MANIFEST_FILE } from "@modern-js/utils/constants";
4
+ import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
8
5
  const PLUGIN_NAME = "ModernjsRoutePlugin";
9
6
  class RouterPlugin {
10
7
  apply(compiler) {
@@ -39,11 +36,12 @@ class RouterPlugin {
39
36
  publicPath: true,
40
37
  assets: true,
41
38
  chunkGroups: true,
42
- chunks: true
39
+ chunks: true,
40
+ ids: true
43
41
  });
44
- const { publicPath, chunks = [] } = stats;
42
+ const { publicPath, chunks = [], assetsByChunkName } = stats;
45
43
  const routeAssets = {};
46
- const { namedChunkGroups, assetsByChunkName } = stats;
44
+ const { namedChunkGroups } = stats;
47
45
  if (!namedChunkGroups || !assetsByChunkName) {
48
46
  logger.warn(
49
47
  "Route manifest does not exist, performance will be affected"
@@ -51,21 +49,31 @@ class RouterPlugin {
51
49
  return;
52
50
  }
53
51
  for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
54
- if (assetsByChunkName[name]) {
55
- routeAssets[name] = {
56
- chunkIds: chunkGroup.chunks,
57
- assets: assetsByChunkName[name].map(
58
- (item) => publicPath ? normalizePath(publicPath) + item : item
59
- )
60
- };
61
- }
52
+ const referenceCssAssets = chunkGroup.assets.filter((asset) => /\.css$/.test(asset.name)).map((asset) => {
53
+ const item = asset.name;
54
+ return publicPath ? normalizePath(publicPath) + item : item;
55
+ });
56
+ routeAssets[name] = {
57
+ chunkIds: chunkGroup.chunks,
58
+ assets: assetsByChunkName[name].map(
59
+ (item) => publicPath ? normalizePath(publicPath) + item : item
60
+ ),
61
+ referenceCssAssets
62
+ };
62
63
  }
63
64
  const manifest = {
64
65
  routeAssets
65
66
  };
66
67
  const injectedContent = `
67
68
  ;(function(){
68
- window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest)};
69
+ window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v) => {
70
+ if (k === "assets" && Array.isArray(v)) {
71
+ return v.map((item) => {
72
+ return item.replace(publicPath, "");
73
+ });
74
+ }
75
+ return v;
76
+ })};
69
77
  })();
70
78
  `;
71
79
  const entrypointsArray = Array.from(
@@ -95,7 +103,7 @@ class RouterPlugin {
95
103
  void 0
96
104
  );
97
105
  }
98
- const filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
106
+ const filename = path.join(outputPath, ROUTE_MANIFEST_FILE);
99
107
  await fs.ensureFile(filename);
100
108
  await fs.writeFile(filename, JSON.stringify(manifest, null, 2));
101
109
  }
@@ -4,7 +4,7 @@ import { printInstructions } from "../utils/printInstructions";
4
4
  import { injectDataLoaderPlugin } from "../utils/createServer";
5
5
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
6
6
  const start = async (api) => {
7
- var _a;
7
+ var _a, _b;
8
8
  const appContext = api.useAppContext();
9
9
  const userConfig = api.useResolvedConfigContext();
10
10
  const hookRunners = api.useHookRunners();
@@ -17,7 +17,14 @@ const start = async (api) => {
17
17
  const serverInternalPlugins = await getServerInternalPlugins(api);
18
18
  const app = await server({
19
19
  pwd: appDirectory,
20
- config: userConfig,
20
+ config: {
21
+ ...userConfig,
22
+ dev: userConfig.dev,
23
+ output: {
24
+ path: (_b = userConfig.output.distPath) == null ? void 0 : _b.root,
25
+ ...userConfig.output || {}
26
+ }
27
+ },
21
28
  appContext: {
22
29
  sharedDirectory: getTargetDir(
23
30
  appContext.sharedDirectory,
@@ -1,5 +1,11 @@
1
1
  import { cli } from "@modern-js/core";
2
- import { chalk, clearConsole, logger, program } from "@modern-js/utils";
2
+ import {
3
+ chalk,
4
+ clearConsole,
5
+ getArgv,
6
+ logger,
7
+ program
8
+ } from "@modern-js/utils";
3
9
  async function restart(hooksRunner, filename) {
4
10
  clearConsole();
5
11
  logger.info(`Restart because ${chalk.yellow(filename)} is changed...
@@ -13,7 +19,7 @@ async function restart(hooksRunner, filename) {
13
19
  hasGetError = true;
14
20
  } finally {
15
21
  if (!hasGetError) {
16
- program.parse(process.argv);
22
+ program.parse(getArgv());
17
23
  }
18
24
  }
19
25
  }
@@ -24,5 +24,5 @@ export interface SharedSourceConfig extends BuilderSharedSourceConfig {
24
24
 
25
25
  designSystem?: Record<string, any>;
26
26
  }
27
- export interface SourceUserConfig extends BuilderSourceConfig, SharedSourceConfig {}
28
- export interface RsSourceUserConfig extends RsBuilderSourceConfig, SharedSourceConfig {}
27
+ export type SourceUserConfig = BuilderSourceConfig & SharedSourceConfig;
28
+ export type RsSourceUserConfig = RsBuilderSourceConfig & SharedSourceConfig;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.10.0",
14
+ "version": "2.11.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -68,23 +68,23 @@
68
68
  "@babel/types": "^7.18.0",
69
69
  "es-module-lexer": "^1.1.0",
70
70
  "esbuild": "0.15.7",
71
- "@modern-js/builder": "2.10.0",
72
- "@modern-js/builder-plugin-esbuild": "2.10.0",
73
- "@modern-js/builder-plugin-node-polyfill": "2.10.0",
74
- "@modern-js/builder-shared": "2.10.0",
75
- "@modern-js/builder-webpack-provider": "2.10.0",
76
- "@modern-js/core": "2.10.0",
77
- "@modern-js/new-action": "2.10.0",
78
- "@modern-js/node-bundle-require": "2.10.0",
79
- "@modern-js/plugin": "2.10.0",
80
- "@modern-js/plugin-data-loader": "2.10.0",
81
- "@modern-js/plugin-i18n": "2.10.0",
82
- "@modern-js/plugin-lint": "2.10.0",
83
- "@modern-js/prod-server": "2.10.0",
84
- "@modern-js/server": "2.10.0",
85
- "@modern-js/types": "2.10.0",
86
- "@modern-js/upgrade": "2.10.0",
87
- "@modern-js/utils": "2.10.0"
71
+ "@modern-js/builder": "2.11.0",
72
+ "@modern-js/builder-plugin-esbuild": "2.11.0",
73
+ "@modern-js/builder-plugin-node-polyfill": "2.11.0",
74
+ "@modern-js/builder-shared": "2.11.0",
75
+ "@modern-js/builder-webpack-provider": "2.11.0",
76
+ "@modern-js/core": "2.11.0",
77
+ "@modern-js/new-action": "2.11.0",
78
+ "@modern-js/node-bundle-require": "2.11.0",
79
+ "@modern-js/plugin": "2.11.0",
80
+ "@modern-js/plugin-data-loader": "2.11.0",
81
+ "@modern-js/plugin-i18n": "2.11.0",
82
+ "@modern-js/plugin-lint": "2.11.0",
83
+ "@modern-js/prod-server": "2.11.0",
84
+ "@modern-js/server": "2.11.0",
85
+ "@modern-js/types": "2.11.0",
86
+ "@modern-js/upgrade": "2.11.0",
87
+ "@modern-js/utils": "2.11.0"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@types/babel__traverse": "^7.14.2",
@@ -93,14 +93,14 @@
93
93
  "jest": "^29",
94
94
  "typescript": "^4",
95
95
  "webpack": "^5.76.2",
96
- "@modern-js/builder-plugin-swc": "2.10.0",
97
- "@modern-js/builder-rspack-provider": "2.10.0",
98
- "@modern-js/server-core": "2.10.0",
99
- "@scripts/build": "2.10.0",
100
- "@scripts/jest-config": "2.10.0"
96
+ "@modern-js/builder-plugin-swc": "2.11.0",
97
+ "@modern-js/builder-rspack-provider": "2.11.0",
98
+ "@modern-js/server-core": "2.11.0",
99
+ "@scripts/build": "2.11.0",
100
+ "@scripts/jest-config": "2.11.0"
101
101
  },
102
102
  "peerDependencies": {
103
- "@modern-js/builder-rspack-provider": "^2.10.0"
103
+ "@modern-js/builder-rspack-provider": "^2.11.0"
104
104
  },
105
105
  "peerDependenciesMeta": {
106
106
  "@modern-js/builder-rspack-provider": {