@modern-js/app-tools 2.13.4 → 2.15.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/dist/cjs/analyze/constants.js +3 -1
  3. package/dist/cjs/analyze/getServerRoutes.js +5 -2
  4. package/dist/cjs/analyze/nestedRoutes.js +12 -0
  5. package/dist/cjs/analyze/templates.js +18 -1
  6. package/dist/cjs/builder/builder-rspack/adapterCopy.js +136 -0
  7. package/dist/cjs/builder/builder-rspack/index.js +6 -1
  8. package/dist/cjs/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js} +9 -10
  9. package/dist/cjs/builder/builder-webpack/createCopyPattern.js +67 -0
  10. package/dist/cjs/builder/builder-webpack/index.js +4 -4
  11. package/dist/cjs/builder/shared/{createCopyPattern.js → createCopyInfo.js} +11 -44
  12. package/dist/cjs/builder/shared/index.js +1 -1
  13. package/dist/cjs/config/default.js +3 -1
  14. package/dist/cjs/config/initialize/inits.js +0 -7
  15. package/dist/cjs/index.js +6 -3
  16. package/dist/cjs/locale/en.js +5 -5
  17. package/dist/cjs/locale/zh.js +4 -4
  18. package/dist/cjs/schema/legacy.js +1 -1
  19. package/dist/esm/analyze/constants.js +3 -1
  20. package/dist/esm/analyze/getServerRoutes.js +4 -2
  21. package/dist/esm/analyze/nestedRoutes.js +13 -1
  22. package/dist/esm/analyze/templates.js +35 -3
  23. package/dist/esm/builder/builder-rspack/adapterCopy.js +372 -0
  24. package/dist/esm/builder/builder-rspack/index.js +8 -1
  25. package/dist/esm/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js} +5 -5
  26. package/dist/esm/builder/builder-webpack/createCopyPattern.js +39 -0
  27. package/dist/esm/builder/builder-webpack/index.js +4 -4
  28. package/dist/esm/builder/shared/createCopyInfo.js +12 -0
  29. package/dist/esm/builder/shared/index.js +1 -1
  30. package/dist/esm/config/default.js +3 -1
  31. package/dist/esm/config/initialize/inits.js +0 -7
  32. package/dist/esm/index.js +7 -2
  33. package/dist/esm/locale/en.js +5 -5
  34. package/dist/esm/locale/zh.js +4 -4
  35. package/dist/esm/schema/legacy.js +4 -1
  36. package/dist/esm-node/analyze/constants.js +3 -1
  37. package/dist/esm-node/analyze/getServerRoutes.js +5 -2
  38. package/dist/esm-node/analyze/nestedRoutes.js +12 -0
  39. package/dist/esm-node/analyze/templates.js +18 -1
  40. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +103 -0
  41. package/dist/esm-node/builder/builder-rspack/index.js +6 -1
  42. package/dist/esm-node/builder/builder-webpack/{builderPlugins/compatModern.js → adapterModern.js} +5 -6
  43. package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +43 -0
  44. package/dist/esm-node/builder/builder-webpack/index.js +4 -4
  45. package/dist/esm-node/builder/shared/createCopyInfo.js +17 -0
  46. package/dist/esm-node/builder/shared/index.js +1 -1
  47. package/dist/esm-node/config/default.js +3 -1
  48. package/dist/esm-node/config/initialize/inits.js +0 -7
  49. package/dist/esm-node/index.js +6 -3
  50. package/dist/esm-node/locale/en.js +5 -5
  51. package/dist/esm-node/locale/zh.js +4 -4
  52. package/dist/esm-node/schema/legacy.js +1 -1
  53. package/dist/types/analyze/constants.d.ts +2 -0
  54. package/dist/types/builder/builder-rspack/adapterCopy.d.ts +4 -0
  55. package/dist/types/builder/builder-webpack/{builderPlugins/compatModern.d.ts → adapterModern.d.ts} +2 -2
  56. package/dist/types/builder/{shared → builder-webpack}/createCopyPattern.d.ts +3 -3
  57. package/dist/types/builder/shared/createCopyInfo.d.ts +6 -0
  58. package/dist/types/builder/shared/index.d.ts +2 -2
  59. package/dist/types/types/config/deploy.d.ts +3 -0
  60. package/lib/types.d.ts +1 -0
  61. package/package.json +24 -24
  62. package/dist/esm/builder/shared/createCopyPattern.js +0 -44
  63. package/dist/esm-node/builder/shared/createCopyPattern.js +0 -50
package/dist/cjs/index.js CHANGED
@@ -151,7 +151,7 @@ var src_default = (options = {
151
151
  const { MWANewAction } = await Promise.resolve().then(() => __toESM(require("@modern-js/new-action")));
152
152
  await MWANewAction({ ...options2, locale: options2.lang || locale });
153
153
  });
154
- program.command("inspect").description("inspect internal webpack config").option(
154
+ program.command("inspect").description("inspect the internal configs").option(
155
155
  `--env <env>`,
156
156
  import_locale.i18n.t(import_locale.localeKeys.command.inspect.env),
157
157
  "development"
@@ -171,8 +171,11 @@ var src_default = (options = {
171
171
  async prepare() {
172
172
  const command = (0, import_utils.getCommand)();
173
173
  if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
174
- const appContext = api.useAppContext();
175
- await (0, import_utils.emptyDir)(appContext.distDirectory);
174
+ const resolvedConfig = api.useResolvedConfigContext();
175
+ if (resolvedConfig.output.cleanDistPath) {
176
+ const appContext = api.useAppContext();
177
+ await (0, import_utils.emptyDir)(appContext.distDirectory);
178
+ }
176
179
  }
177
180
  },
178
181
  async watchFiles() {
@@ -27,7 +27,7 @@ const EN_LOCALE = {
27
27
  config: "specify config file"
28
28
  },
29
29
  dev: {
30
- describe: "start dev server",
30
+ describe: "starting the dev server",
31
31
  entry: "compiler by entry",
32
32
  apiOnly: "start api server only",
33
33
  webOnly: "start web server only",
@@ -35,12 +35,12 @@ const EN_LOCALE = {
35
35
  requireEntry: "You must choose at least one entry"
36
36
  },
37
37
  build: {
38
- describe: "build application"
38
+ describe: "build the app for production"
39
39
  },
40
- serve: { describe: "start server" },
41
- deploy: { describe: "deploy application" },
40
+ serve: { describe: "preview the production build locally" },
41
+ deploy: { describe: "deploy the application" },
42
42
  new: {
43
- describe: "generator runner for MWA project",
43
+ describe: "enable optional features or add a new entry",
44
44
  debug: "using debug mode to log something",
45
45
  config: "set default generator config(json string)",
46
46
  distTag: `use specified tag version for it's generator`,
@@ -27,7 +27,7 @@ const ZH_LOCALE = {
27
27
  config: "指定配置文件路径,可以为相对路径或绝对路径"
28
28
  },
29
29
  dev: {
30
- describe: "本地开发命令",
30
+ describe: "启动开发服务器",
31
31
  entry: "指定入口,编译特定的页面",
32
32
  apiOnly: "仅启动 API 接口服务",
33
33
  webOnly: "仅启动 Web 服务",
@@ -35,10 +35,10 @@ const ZH_LOCALE = {
35
35
  requireEntry: "请至少选择一个入口"
36
36
  },
37
37
  build: {
38
- describe: "构建应用命令"
38
+ describe: "构建生产环境产物"
39
39
  },
40
- serve: { describe: "应用启动命令" },
41
- deploy: { describe: "部署应用命令" },
40
+ serve: { describe: "启动生产环境服务" },
41
+ deploy: { describe: "部署应用" },
42
42
  new: {
43
43
  describe: "Web App 项目中执行生成器",
44
44
  debug: "开启 Debug 模式,打印调试日志信息",
@@ -45,7 +45,7 @@ const source = {
45
45
  enableAsyncEntry: { type: "boolean" },
46
46
  disableDefaultEntries: { type: "boolean" },
47
47
  envVars: { type: "array" },
48
- globalVars: { type: "object" },
48
+ globalVars: { typeof: ["object", "function"] },
49
49
  moduleScopes: { instanceof: ["Array", "Function"] },
50
50
  entriesDir: { type: "string" },
51
51
  configDir: { type: "string" },
@@ -34,7 +34,9 @@ var NESTED_ROUTE = {
34
34
  ERROR_FILE: "error",
35
35
  LOADER_FILE: "loader",
36
36
  SPLATE_FILE: "$",
37
- SPLATE_LOADER_FILE: "$.loader"
37
+ SPLATE_LOADER_FILE: "$.loader",
38
+ LAYOUT_CONFIG_FILE: "layout.config",
39
+ PAGE_CONFIG_FILE: "page.config"
38
40
  };
39
41
  var APP_CONFIG_NAME = "config";
40
42
  var APP_INIT_EXPORTED = "init";
@@ -169,13 +169,15 @@ var applyRouteOptions = function(original, routeOptions) {
169
169
  return routes;
170
170
  };
171
171
  var collectHtmlRoutes = function(entrypoints, appContext, config) {
172
- var disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, worker = _config_server.worker;
172
+ var _deploy_worker;
173
+ var disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, deploy = config.deploy;
173
174
  var packageName = appContext.packageName;
175
+ var workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
174
176
  var htmlRoutes = entrypoints.reduce(function(previous, param) {
175
177
  var entryName = param.entryName;
176
178
  var entryOptions = getEntryOptions(entryName, ssr, ssrByEntries, packageName);
177
179
  var isSSR = Boolean(entryOptions);
178
- var isWorker = Boolean(worker);
180
+ var isWorker = Boolean(workerSSR);
179
181
  var resHeaders = ((routes === null || routes === void 0 ? void 0 : routes[entryName]) || {}).resHeaders;
180
182
  var route = {
181
183
  urlPath: "/".concat(entryName === MAIN_ENTRY_NAME ? "" : entryName),
@@ -197,7 +197,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
197
197
  };
198
198
  var walk = function() {
199
199
  var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
200
- var _route_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, _route_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, path2;
200
+ var _route_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, pageConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, _route_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, path2;
201
201
  return __generator(this, function(_state) {
202
202
  switch(_state.label){
203
203
  case 0:
@@ -244,6 +244,7 @@ var walk = function() {
244
244
  pageRoute = null;
245
245
  splatLoaderFile = "";
246
246
  splatRoute = null;
247
+ pageConfigFile = "";
247
248
  return [
248
249
  4,
249
250
  fs.readdir(dirname)
@@ -303,12 +304,20 @@ var walk = function() {
303
304
  route.loader = itemPath;
304
305
  }
305
306
  }
307
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_CONFIG_FILE) {
308
+ if (!route.config) {
309
+ route.config = itemPath;
310
+ }
311
+ }
306
312
  if (itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE) {
307
313
  route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
308
314
  }
309
315
  if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
310
316
  pageLoaderFile = itemPath;
311
317
  }
318
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_CONFIG_FILE) {
319
+ pageConfigFile = itemPath;
320
+ }
312
321
  if (itemWithoutExt === NESTED_ROUTE.PAGE_FILE) {
313
322
  ;
314
323
  pageRoute = createIndexRoute({
@@ -317,6 +326,9 @@ var walk = function() {
317
326
  if (pageLoaderFile) {
318
327
  pageRoute.loader = pageLoaderFile;
319
328
  }
329
+ if (pageConfigFile) {
330
+ pageRoute.config = pageConfigFile;
331
+ }
320
332
  (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(pageRoute);
321
333
  }
322
334
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
@@ -301,7 +301,7 @@ var createMatchReg = function(keyword) {
301
301
  };
302
302
  var fileSystemRoutes = function() {
303
303
  var _ref = _asyncToGenerator(function(param) {
304
- var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, _param_splitRouteChunks, splitRouteChunks, components, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, routeStr, keywords, regs, newRouteStr, component, finalRoute, keywords1, routeStr1, regs1, newRouteStr1, importLoadingCode, importComponentsCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo;
304
+ var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, _param_splitRouteChunks, splitRouteChunks, components, loadings, errors, loaders, loadersMap, configs, configsMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, routeStr, keywords, regs, newRouteStr, component, finalRoute, keywords1, routeStr1, regs1, newRouteStr1, importLoadingCode, importComponentsCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo, importConfigsCode, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _step_value1, key1, configPath;
305
305
  return __generator(this, function(_state) {
306
306
  switch(_state.label){
307
307
  case 0:
@@ -311,6 +311,8 @@ var fileSystemRoutes = function() {
311
311
  errors = [];
312
312
  loaders = [];
313
313
  loadersMap = {};
314
+ configs = [];
315
+ configsMap = {};
314
316
  loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
315
317
  importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
316
318
  rootLayoutCode = "";
@@ -332,6 +334,7 @@ var fileSystemRoutes = function() {
332
334
  var loading;
333
335
  var error;
334
336
  var loader;
337
+ var config;
335
338
  var component = "";
336
339
  var lazyImport = null;
337
340
  if (route.type === "nested") {
@@ -353,6 +356,12 @@ var fileSystemRoutes = function() {
353
356
  inline: false
354
357
  };
355
358
  }
359
+ if (typeof route.config === "string") {
360
+ configs.push(route.config);
361
+ var configId = configs.length - 1;
362
+ config = "config_".concat(configId);
363
+ configsMap[config] = route.config;
364
+ }
356
365
  if (route._component) {
357
366
  if (splitRouteChunks) {
358
367
  if (route.isRoot) {
@@ -383,6 +392,7 @@ var fileSystemRoutes = function() {
383
392
  lazyImport: lazyImport,
384
393
  loading: loading,
385
394
  loader: loader,
395
+ config: config,
386
396
  error: error,
387
397
  children: children
388
398
  });
@@ -404,7 +414,8 @@ var fileSystemRoutes = function() {
404
414
  "lazyImport",
405
415
  "loader",
406
416
  "loading",
407
- "error"
417
+ "error",
418
+ "config"
408
419
  ];
409
420
  regs = keywords.map(createMatchReg);
410
421
  newRouteStr = regs.reduce(function(acc, reg) {
@@ -477,6 +488,27 @@ var fileSystemRoutes = function() {
477
488
  }
478
489
  }
479
490
  }
491
+ importConfigsCode = "";
492
+ _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
493
+ try {
494
+ for(_iterator2 = Object.entries(configsMap)[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
495
+ _step_value1 = _slicedToArray(_step2.value, 2), key1 = _step_value1[0], configPath = _step_value1[1];
496
+ importConfigsCode += "import * as ".concat(key1, ' from "').concat(slash(configPath), '";\n');
497
+ }
498
+ } catch (err) {
499
+ _didIteratorError2 = true;
500
+ _iteratorError2 = err;
501
+ } finally{
502
+ try {
503
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
504
+ _iterator2.return();
505
+ }
506
+ } finally{
507
+ if (_didIteratorError2) {
508
+ throw _iteratorError2;
509
+ }
510
+ }
511
+ }
480
512
  return [
481
513
  4,
482
514
  fs.ensureFile(loadersMapFile)
@@ -491,7 +523,7 @@ var fileSystemRoutes = function() {
491
523
  _state.sent();
492
524
  return [
493
525
  2,
494
- "\n ".concat(importLazyCode, "\n ").concat(importComponentsCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
526
+ "\n ".concat(importLazyCode, "\n ").concat(importComponentsCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(importConfigsCode, "\n ").concat(routeComponentsCode, "\n ")
495
527
  ];
496
528
  }
497
529
  });
@@ -0,0 +1,372 @@
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithoutHoles(arr) {
7
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _asyncToGenerator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _defineProperty(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
51
+ function _iterableToArray(iter) {
52
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
+ }
54
+ function _nonIterableSpread() {
55
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _objectSpread(target) {
58
+ for(var i = 1; i < arguments.length; i++){
59
+ var source = arguments[i] != null ? arguments[i] : {};
60
+ var ownKeys = Object.keys(source);
61
+ if (typeof Object.getOwnPropertySymbols === "function") {
62
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
63
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
64
+ }));
65
+ }
66
+ ownKeys.forEach(function(key) {
67
+ _defineProperty(target, key, source[key]);
68
+ });
69
+ }
70
+ return target;
71
+ }
72
+ function ownKeys(object, enumerableOnly) {
73
+ var keys = Object.keys(object);
74
+ if (Object.getOwnPropertySymbols) {
75
+ var symbols = Object.getOwnPropertySymbols(object);
76
+ if (enumerableOnly) {
77
+ symbols = symbols.filter(function(sym) {
78
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
79
+ });
80
+ }
81
+ keys.push.apply(keys, symbols);
82
+ }
83
+ return keys;
84
+ }
85
+ function _objectSpreadProps(target, source) {
86
+ source = source != null ? source : {};
87
+ if (Object.getOwnPropertyDescriptors) {
88
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
89
+ } else {
90
+ ownKeys(Object(source)).forEach(function(key) {
91
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
92
+ });
93
+ }
94
+ return target;
95
+ }
96
+ function _toConsumableArray(arr) {
97
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
98
+ }
99
+ function _unsupportedIterableToArray(o, minLen) {
100
+ if (!o) return;
101
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
102
+ var n = Object.prototype.toString.call(o).slice(8, -1);
103
+ if (n === "Object" && o.constructor) n = o.constructor.name;
104
+ if (n === "Map" || n === "Set") return Array.from(n);
105
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
106
+ }
107
+ var __generator = this && this.__generator || function(thisArg, body) {
108
+ var f, y, t, g, _ = {
109
+ label: 0,
110
+ sent: function() {
111
+ if (t[0] & 1) throw t[1];
112
+ return t[1];
113
+ },
114
+ trys: [],
115
+ ops: []
116
+ };
117
+ return(g = {
118
+ next: verb(0),
119
+ "throw": verb(1),
120
+ "return": verb(2)
121
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
122
+ return this;
123
+ }), g);
124
+ function verb(n) {
125
+ return function(v) {
126
+ return step([
127
+ n,
128
+ v
129
+ ]);
130
+ };
131
+ }
132
+ function step(op) {
133
+ if (f) throw new TypeError("Generator is already executing.");
134
+ while(_)try {
135
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
136
+ if (y = 0, t) op = [
137
+ op[0] & 2,
138
+ t.value
139
+ ];
140
+ switch(op[0]){
141
+ case 0:
142
+ case 1:
143
+ t = op;
144
+ break;
145
+ case 4:
146
+ _.label++;
147
+ return {
148
+ value: op[1],
149
+ done: false
150
+ };
151
+ case 5:
152
+ _.label++;
153
+ y = op[1];
154
+ op = [
155
+ 0
156
+ ];
157
+ continue;
158
+ case 7:
159
+ op = _.ops.pop();
160
+ _.trys.pop();
161
+ continue;
162
+ default:
163
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
164
+ _ = 0;
165
+ continue;
166
+ }
167
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
168
+ _.label = op[1];
169
+ break;
170
+ }
171
+ if (op[0] === 6 && _.label < t[1]) {
172
+ _.label = t[1];
173
+ t = op;
174
+ break;
175
+ }
176
+ if (t && _.label < t[2]) {
177
+ _.label = t[2];
178
+ _.ops.push(op);
179
+ break;
180
+ }
181
+ if (t[2]) _.ops.pop();
182
+ _.trys.pop();
183
+ continue;
184
+ }
185
+ op = body.call(thisArg, _);
186
+ } catch (e) {
187
+ op = [
188
+ 6,
189
+ e
190
+ ];
191
+ y = 0;
192
+ } finally{
193
+ f = t = 0;
194
+ }
195
+ if (op[0] & 5) throw op[1];
196
+ return {
197
+ value: op[0] ? op[1] : void 0,
198
+ done: true
199
+ };
200
+ }
201
+ };
202
+ import path from "path";
203
+ import fs from "@modern-js/utils/fs-extra";
204
+ import { logger, removeTailSlash } from "@modern-js/utils";
205
+ import { createCopyInfo } from "../shared";
206
+ var builderPluginAdpaterCopy = function(options) {
207
+ return {
208
+ name: "builder-plugin-adapter-rspack-copy",
209
+ setup: function setup(api) {
210
+ var publicPath;
211
+ api.modifyRspackConfig(function(config) {
212
+ var _config_builtins, _config_builtins_copy, _config_output;
213
+ config.builtins = _objectSpreadProps(_objectSpread({}, config.builtins || {}), {
214
+ copy: {
215
+ patterns: _toConsumableArray(transformCopy((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns)).concat(_toConsumableArray(createConfigBuiltinCopy(options)))
216
+ }
217
+ });
218
+ publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
219
+ });
220
+ api.onDevCompileDone(/*#__PURE__*/ _asyncToGenerator(function() {
221
+ return __generator(this, function(_state) {
222
+ switch(_state.label){
223
+ case 0:
224
+ return [
225
+ 4,
226
+ transformHtmlFiles()
227
+ ];
228
+ case 1:
229
+ _state.sent();
230
+ return [
231
+ 2
232
+ ];
233
+ }
234
+ });
235
+ }));
236
+ api.onAfterBuild(/*#__PURE__*/ _asyncToGenerator(function() {
237
+ return __generator(this, function(_state) {
238
+ switch(_state.label){
239
+ case 0:
240
+ return [
241
+ 4,
242
+ transformHtmlFiles()
243
+ ];
244
+ case 1:
245
+ _state.sent();
246
+ return [
247
+ 2
248
+ ];
249
+ }
250
+ });
251
+ }));
252
+ function transformHtmlFiles() {
253
+ return _transformHtmlFiles.apply(this, arguments);
254
+ }
255
+ function _transformHtmlFiles() {
256
+ _transformHtmlFiles = _asyncToGenerator(function() {
257
+ var _normalizedConfig_output_distPath, normalizedConfig, publicDir, HTML_REGEXP, filepaths;
258
+ return __generator(this, function(_state) {
259
+ switch(_state.label){
260
+ case 0:
261
+ normalizedConfig = options.normalizedConfig;
262
+ publicDir = path.resolve(((_normalizedConfig_output_distPath = normalizedConfig.output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.root) || "./dist", "./public");
263
+ if (!fs.existsSync(publicDir) || !fs.statSync(publicDir).isDirectory()) {
264
+ return [
265
+ 2
266
+ ];
267
+ }
268
+ HTML_REGEXP = /\.html?$/;
269
+ return [
270
+ 4,
271
+ fs.readdir(publicDir)
272
+ ];
273
+ case 1:
274
+ filepaths = _state.sent().map(function(file) {
275
+ return path.resolve(publicDir, file);
276
+ });
277
+ return [
278
+ 4,
279
+ Promise.all(filepaths.filter(function(file) {
280
+ return HTML_REGEXP.test(file);
281
+ }).map(function() {
282
+ var _ref = _asyncToGenerator(function(file) {
283
+ var content;
284
+ return __generator(this, function(_state) {
285
+ switch(_state.label){
286
+ case 0:
287
+ return [
288
+ 4,
289
+ fs.readFile(file, "utf-8")
290
+ ];
291
+ case 1:
292
+ content = _state.sent();
293
+ if (!publicPath) return [
294
+ 3,
295
+ 3
296
+ ];
297
+ return [
298
+ 4,
299
+ fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash(publicPath)))
300
+ ];
301
+ case 2:
302
+ _state.sent();
303
+ return [
304
+ 3,
305
+ 5
306
+ ];
307
+ case 3:
308
+ logger.warn("Expect get a string from `publicPath`, but receive `undefined`.");
309
+ return [
310
+ 4,
311
+ fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash("/")))
312
+ ];
313
+ case 4:
314
+ _state.sent();
315
+ _state.label = 5;
316
+ case 5:
317
+ return [
318
+ 2
319
+ ];
320
+ }
321
+ });
322
+ });
323
+ return function(file) {
324
+ return _ref.apply(this, arguments);
325
+ };
326
+ }()))
327
+ ];
328
+ case 2:
329
+ _state.sent();
330
+ return [
331
+ 2
332
+ ];
333
+ }
334
+ });
335
+ });
336
+ return _transformHtmlFiles.apply(this, arguments);
337
+ }
338
+ }
339
+ };
340
+ };
341
+ function transformCopy(patterns) {
342
+ if (patterns) {
343
+ patterns.map(function(value) {
344
+ if (typeof value === "string") {
345
+ return {
346
+ from: value
347
+ };
348
+ }
349
+ return value;
350
+ });
351
+ }
352
+ return [];
353
+ }
354
+ function createConfigBuiltinCopy(options) {
355
+ var normalizedConfig = options.normalizedConfig, appContext = options.appContext;
356
+ var _createCopyInfo = createCopyInfo(appContext, normalizedConfig), uploadDir = _createCopyInfo.uploadDir, publicDir = _createCopyInfo.publicDir;
357
+ return [
358
+ {
359
+ from: "**/*",
360
+ to: "public",
361
+ context: publicDir,
362
+ noErrorOnMissing: true
363
+ },
364
+ {
365
+ from: "**/*",
366
+ to: "upload",
367
+ context: uploadDir,
368
+ noErrorOnMissing: true
369
+ }
370
+ ];
371
+ }
372
+ export { builderPluginAdpaterCopy };
@@ -1,6 +1,13 @@
1
1
  import { builderRspackProvider } from "@modern-js/builder-rspack-provider";
2
2
  import { generateBuilder } from "../generator";
3
+ import { builderPluginAdpaterCopy } from "./adapterCopy";
3
4
  function createRspackBuilderForModern(options) {
4
- return generateBuilder(options, builderRspackProvider);
5
+ return generateBuilder(options, builderRspackProvider, {
6
+ modifyBuilderInstance: function modifyBuilderInstance(builder) {
7
+ builder.addPlugins([
8
+ builderPluginAdpaterCopy(options)
9
+ ]);
10
+ }
11
+ });
5
12
  }
6
13
  export { createRspackBuilderForModern };