@modern-js/app-tools 2.0.2 → 2.1.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 (53) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/js/modern/analyze/constants.js +1 -1
  3. package/dist/js/modern/analyze/generateCode.js +8 -93
  4. package/dist/js/modern/analyze/index.js +36 -10
  5. package/dist/js/modern/analyze/nestedRoutes.js +2 -15
  6. package/dist/js/modern/analyze/templates.js +36 -68
  7. package/dist/js/modern/analyze/utils.js +5 -14
  8. package/dist/js/modern/builder/index.js +1 -2
  9. package/dist/js/modern/config/default.js +3 -1
  10. package/dist/js/modern/config/initial/inits.js +1 -9
  11. package/dist/js/modern/index.js +6 -7
  12. package/dist/js/modern/initialize/index.js +7 -7
  13. package/dist/js/modern/locale/en.js +2 -1
  14. package/dist/js/modern/locale/zh.js +2 -1
  15. package/dist/js/node/analyze/constants.js +1 -1
  16. package/dist/js/node/analyze/generateCode.js +5 -84
  17. package/dist/js/node/analyze/index.js +28 -8
  18. package/dist/js/node/analyze/nestedRoutes.js +1 -14
  19. package/dist/js/node/analyze/templates.js +36 -68
  20. package/dist/js/node/analyze/utils.js +5 -13
  21. package/dist/js/node/builder/index.js +1 -2
  22. package/dist/js/node/config/default.js +3 -1
  23. package/dist/js/node/config/initial/inits.js +1 -9
  24. package/dist/js/node/index.js +2 -3
  25. package/dist/js/node/initialize/index.js +7 -7
  26. package/dist/js/node/locale/en.js +2 -1
  27. package/dist/js/node/locale/zh.js +2 -1
  28. package/dist/js/treeshaking/analyze/constants.js +1 -1
  29. package/dist/js/treeshaking/analyze/generateCode.js +26 -156
  30. package/dist/js/treeshaking/analyze/index.js +23 -15
  31. package/dist/js/treeshaking/analyze/nestedRoutes.js +26 -77
  32. package/dist/js/treeshaking/analyze/templates.js +93 -76
  33. package/dist/js/treeshaking/analyze/utils.js +5 -11
  34. package/dist/js/treeshaking/builder/index.js +1 -2
  35. package/dist/js/treeshaking/config/default.js +3 -1
  36. package/dist/js/treeshaking/config/initial/inits.js +1 -12
  37. package/dist/js/treeshaking/index.js +8 -9
  38. package/dist/js/treeshaking/initialize/index.js +19 -42
  39. package/dist/js/treeshaking/locale/en.js +2 -1
  40. package/dist/js/treeshaking/locale/zh.js +2 -1
  41. package/dist/types/analyze/constants.d.ts +1 -1
  42. package/dist/types/analyze/templates.d.ts +2 -8
  43. package/dist/types/analyze/utils.d.ts +2 -2
  44. package/dist/types/locale/en.d.ts +1 -0
  45. package/dist/types/locale/index.d.ts +2 -0
  46. package/dist/types/locale/zh.d.ts +1 -0
  47. package/dist/types/types/config/dev.d.ts +1 -1
  48. package/lib/types.d.ts +6 -2
  49. package/package.json +22 -22
  50. package/dist/js/modern/analyze/Builder.js +0 -39
  51. package/dist/js/node/analyze/Builder.js +0 -64
  52. package/dist/js/treeshaking/analyze/Builder.js +0 -199
  53. package/dist/types/analyze/Builder.d.ts +0 -8
@@ -1,3 +1,11 @@
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 _arrayWithHoles(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
1
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
10
  try {
3
11
  var info = gen[key](arg);
@@ -40,6 +48,33 @@ function _defineProperty(obj, key, value) {
40
48
  }
41
49
  return obj;
42
50
  }
51
+ function _iterableToArrayLimit(arr, i) {
52
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
53
+ if (_i == null) return;
54
+ var _arr = [];
55
+ var _n = true;
56
+ var _d = false;
57
+ var _s, _e;
58
+ try {
59
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
60
+ _arr.push(_s.value);
61
+ if (i && _arr.length === i) break;
62
+ }
63
+ } catch (err) {
64
+ _d = true;
65
+ _e = err;
66
+ } finally{
67
+ try {
68
+ if (!_n && _i["return"] != null) _i["return"]();
69
+ } finally{
70
+ if (_d) throw _e;
71
+ }
72
+ }
73
+ return _arr;
74
+ }
75
+ function _nonIterableRest() {
76
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
+ }
43
78
  function _objectSpread(target) {
44
79
  for(var i = 1; i < arguments.length; i++){
45
80
  var source = arguments[i] != null ? arguments[i] : {};
@@ -79,6 +114,17 @@ function _objectSpreadProps(target, source) {
79
114
  }
80
115
  return target;
81
116
  }
117
+ function _slicedToArray(arr, i) {
118
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
119
+ }
120
+ function _unsupportedIterableToArray(o, minLen) {
121
+ if (!o) return;
122
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
123
+ var n = Object.prototype.toString.call(o).slice(8, -1);
124
+ if (n === "Object" && o.constructor) n = o.constructor.name;
125
+ if (n === "Map" || n === "Set") return Array.from(n);
126
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
127
+ }
82
128
  var __generator = this && this.__generator || function(thisArg, body) {
83
129
  var f, y, t, g, _ = {
84
130
  label: 0,
@@ -183,7 +229,7 @@ var index = function(param) {
183
229
  };
184
230
  var renderFunction = function(param) {
185
231
  var plugins = param.plugins, customBootstrap = param.customBootstrap, fileSystemRoutes2 = param.fileSystemRoutes;
186
- return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === 'object' ? ").concat(APP_CONFIG_NAME, " : {},\n }\n\n AppWrapper = createApp({\n plugins: [\n ").concat(plugins.map(function(param) {
232
+ return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === 'function' ? ").concat(APP_CONFIG_NAME, "() : {},\n }\n\n AppWrapper = createApp({\n plugins: [\n ").concat(plugins.map(function(param) {
187
233
  var name = param.name, options = param.options, args = param.args;
188
234
  return "".concat(name, "({...").concat(options, ", ...finalAppConfig?.").concat(args || name, "}),");
189
235
  }).join("\n"), "\n ]\n })(").concat(fileSystemRoutes2 ? "" : "App", ")\n\n\n if(!AppWrapper.init && typeof appInit !== 'undefined') {\n AppWrapper.init = appInit;\n }\n\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper);" : "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);", "\n }\n\n return AppWrapper\n");
@@ -192,9 +238,8 @@ var html = function(partials) {
192
238
  return "\n<!DOCTYPE html>\n<html>\n<head>\n <%= meta %>\n <title><%= title %></title>\n\n ".concat(partials.top.join("\n"), "\n\n <script>\n window.__assetPrefix__ = '<%= assetPrefix %>';\n </script>\n ").concat(partials.head.join("\n"), "\n\n <!--<?- chunksMap.css ?>-->\n</head>\n\n<body>\n <noscript>\n We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.\n </noscript>\n <div id=\"<%= mountId %>\"><!--<?- html ?>--></div>\n ").concat(partials.body.join("\n"), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
193
239
  };
194
240
  var routesForServer = function(param) {
195
- var routes = param.routes, internalDirectory = param.internalDirectory, entryName = param.entryName;
241
+ var routes = param.routes;
196
242
  var loaders = [];
197
- var loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "index.js");
198
243
  var traverseRouteTree = function(route) {
199
244
  var children;
200
245
  if ("children" in route && route.children) {
@@ -243,34 +288,38 @@ var routesForServer = function(param) {
243
288
  routesCode += "\n];";
244
289
  var importLoadersCode = "";
245
290
  if (loaders.length > 0) {
246
- importLoadersCode = "\n import { ".concat(loaders.map(function(loader, index2) {
247
- return "loader_".concat(index2);
248
- }), ' } from "').concat(slash(loaderIndexFile), '"');
291
+ importLoadersCode = loaders.map(function(loader, index2) {
292
+ return "import loader_".concat(index2, ' from "').concat(slash(loader), '"');
293
+ }).join("\n");
249
294
  }
250
295
  return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
251
296
  };
252
297
  var fileSystemRoutes = function() {
253
298
  var _ref = _asyncToGenerator(function(param) {
254
- var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, internalDirAlias, loadings, errors, loaders, loadersMap, loadersIndexFile, loadersMapFile, importLazyCode, rootLayoutCode, dataLoaderPath, componentLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, loaderEntryCode, loaderEntryFile;
299
+ var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, componentLoaderPath, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _value, key, loaderInfo;
255
300
  return __generator(this, function(_state) {
256
301
  switch(_state.label){
257
302
  case 0:
258
- routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory, internalDirAlias = param.internalDirAlias;
303
+ routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory;
259
304
  loadings = [];
260
305
  errors = [];
261
306
  loaders = [];
262
307
  loadersMap = {};
263
- loadersIndexFile = path.join(internalDirAlias, entryName, TEMP_LOADERS_DIR, "index.js");
264
308
  loadersMapFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "map.json");
265
309
  importLazyCode = '\n import { lazy } from "react";\n import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"\n ';
266
310
  rootLayoutCode = "";
267
- dataLoaderPath = "";
268
311
  componentLoaderPath = "";
269
- if (ssrMode) {
270
- dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
312
+ getDataLoaderPath = function(loaderId) {
313
+ if (!ssrMode) {
314
+ return "";
315
+ }
316
+ var dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
271
317
  if (nestedRoutesEntry) {
272
- dataLoaderPath = "".concat(dataLoaderPath, "?routesDir=").concat(nestedRoutesEntry, "&mapFile=").concat(loadersMapFile, "!");
318
+ dataLoaderPath = "".concat(slash(dataLoaderPath), "?mapFile=").concat(slash(loadersMapFile), "&loaderId=").concat(loaderId, "!");
273
319
  }
320
+ return dataLoaderPath;
321
+ };
322
+ if (ssrMode) {
274
323
  componentLoaderPath = "".concat(path.join(__dirname, "../builder/loaders/routerLoader"), "!");
275
324
  }
276
325
  traverseRouteTree = function(route) {
@@ -297,7 +346,11 @@ var fileSystemRoutes = function() {
297
346
  loaders.push(route.loader);
298
347
  var loaderId = loaders.length - 1;
299
348
  loader = "loader_".concat(loaderId);
300
- loadersMap[loader] = route.id;
349
+ loadersMap[loader] = {
350
+ routeId: route.id,
351
+ filePath: route.loader,
352
+ inline: false
353
+ };
301
354
  }
302
355
  if (route._component) {
303
356
  if (route.isRoot) {
@@ -365,78 +418,42 @@ var fileSystemRoutes = function() {
365
418
  return "import error_".concat(index2, " from '").concat(error, "';\n");
366
419
  }).join("");
367
420
  importLoadersCode = "";
368
- if (!(loaders.length > 0)) return [
369
- 3,
370
- 5
371
- ];
372
- importLoadersCode = "\n import { ".concat(loaders.map(function(loader, index2) {
373
- return "loader_".concat(index2);
374
- }), ' } from "').concat(slash(dataLoaderPath)).concat(slash(loadersIndexFile), '"\n ');
375
- loaderEntryCode = loaders.map(function(loader, index2) {
376
- return "export * from './loader_".concat(index2, ".js';");
377
- }).join("\n");
378
- loaderEntryFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "entry.js");
421
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
422
+ try {
423
+ for(_iterator1 = Object.entries(loadersMap)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
424
+ _value = _slicedToArray(_step1.value, 2), key = _value[0], loaderInfo = _value[1];
425
+ if (loaderInfo.inline) {
426
+ importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(getDataLoaderPath(key)).concat(slash(loaderInfo.filePath), '";\n');
427
+ } else {
428
+ importLoadersCode += "import ".concat(key, ' from "').concat(getDataLoaderPath(key)).concat(slash(loaderInfo.filePath), '";\n');
429
+ }
430
+ }
431
+ } catch (err) {
432
+ _didIteratorError1 = true;
433
+ _iteratorError1 = err;
434
+ } finally{
435
+ try {
436
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
437
+ _iterator1.return();
438
+ }
439
+ } finally{
440
+ if (_didIteratorError1) {
441
+ throw _iteratorError1;
442
+ }
443
+ }
444
+ }
379
445
  return [
380
446
  4,
381
- fs.ensureFile(loaderEntryFile)
447
+ fs.ensureFile(loadersMapFile)
382
448
  ];
383
449
  case 1:
384
- _state.sent();
385
- return [
386
- 4,
387
- fs.writeFile(loaderEntryFile, loaderEntryCode)
388
- ];
389
- case 2:
390
450
  _state.sent();
391
451
  return [
392
452
  4,
393
453
  fs.writeJSON(loadersMapFile, loadersMap)
394
454
  ];
395
- case 3:
396
- _state.sent();
397
- return [
398
- 4,
399
- Promise.all(loaders.map(function() {
400
- var _ref = _asyncToGenerator(function(loader, index2) {
401
- var name, filename, code;
402
- return __generator(this, function(_state) {
403
- switch(_state.label){
404
- case 0:
405
- name = "loader_".concat(index2);
406
- filename = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "".concat(name, ".js"));
407
- code = "";
408
- if (loader.includes(".loader.")) {
409
- code = "\n export { default as ".concat(name, " } from '").concat(slash(loader), "'\n ");
410
- } else {
411
- code = "\n export { loader as ".concat(name, " } from '").concat(slash(loader), "'\n ");
412
- }
413
- return [
414
- 4,
415
- fs.ensureFile(filename)
416
- ];
417
- case 1:
418
- _state.sent();
419
- return [
420
- 4,
421
- fs.writeFile(filename, code)
422
- ];
423
- case 2:
424
- _state.sent();
425
- return [
426
- 2
427
- ];
428
- }
429
- });
430
- });
431
- return function(loader, index2) {
432
- return _ref.apply(this, arguments);
433
- };
434
- }()))
435
- ];
436
- case 4:
455
+ case 2:
437
456
  _state.sent();
438
- _state.label = 5;
439
- case 5:
440
457
  return [
441
458
  2,
442
459
  "\n ".concat(importLazyCode, "\n ").concat(rootLayoutCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoadersCode, "\n ").concat(routeComponentsCode, "\n ")
@@ -185,7 +185,7 @@ import path from "path";
185
185
  import { isReact18, normalizeToPosixPath, fs as fse } from "@modern-js/utils";
186
186
  import { transform } from "esbuild";
187
187
  import { parse } from "es-module-lexer";
188
- import { FILE_SYSTEM_ROUTES_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTE } from "./constants";
188
+ import { FILE_SYSTEM_ROUTES_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME } from "./constants";
189
189
  var walkDirectory = function(dir) {
190
190
  return fs.readdirSync(dir).reduce(function(previous, filename) {
191
191
  var filePath = path.join(dir, filename);
@@ -286,15 +286,6 @@ var isPageComponentFile = function(filePath) {
286
286
  }
287
287
  return false;
288
288
  };
289
- var isNestedRouteComponent = function(nestedRouteEntries, absoluteFilePath) {
290
- var reg = new RegExp("(".concat(NESTED_ROUTE.LAYOUT_FILE, "|").concat(NESTED_ROUTE.PAGE_FILE, ")\\.tsx?$"));
291
- return nestedRouteEntries.some(function(nestedRoutesEntry) {
292
- if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
293
- return true;
294
- }
295
- return false;
296
- });
297
- };
298
289
  var replaceWithAlias = function(base, filePath, alias) {
299
290
  return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
300
291
  };
@@ -377,4 +368,7 @@ var hasLoader = function() {
377
368
  return _ref.apply(this, arguments);
378
369
  };
379
370
  }();
380
- export { getDefaultImports, hasLoader, isNestedRouteComponent, isPageComponentFile, parseModule, replaceWithAlias, walkDirectory };
371
+ var getServerLoadersFile = function(internalDirectory, entryName) {
372
+ return path.join(internalDirectory, entryName, "route-server-loaders.js");
373
+ };
374
+ export { getDefaultImports, getServerLoadersFile, hasLoader, isPageComponentFile, parseModule, replaceWithAlias, walkDirectory };
@@ -264,7 +264,6 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
264
264
  cleanDistPath: false
265
265
  });
266
266
  };
267
- var ref;
268
267
  var output = createOutputConfig(normalizedConfig, appContext);
269
268
  var htmlConfig = _objectSpread({}, normalizedConfig.html);
270
269
  if (!htmlConfig.template) {
@@ -273,7 +272,7 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
273
272
  return _objectSpreadProps(_objectSpread({}, normalizedConfig), {
274
273
  output: output,
275
274
  dev: _objectSpreadProps(_objectSpread({}, normalizedConfig.dev), {
276
- port: (ref = normalizedConfig.server) === null || ref === void 0 ? void 0 : ref.port
275
+ port: appContext.port
277
276
  }),
278
277
  html: htmlConfig
279
278
  });
@@ -53,7 +53,9 @@ function _objectSpreadProps(target, source) {
53
53
  import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
54
54
  function createDefaultConfig(appContext) {
55
55
  var defaultBuilderConfig = createDefaultBuilderConfig();
56
- var dev = _objectSpread({}, defaultBuilderConfig.dev);
56
+ var dev = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.dev), {
57
+ port: void 0
58
+ });
57
59
  var tools = _objectSpread({}, defaultBuilderConfig.tools);
58
60
  var output = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.output), {
59
61
  disableNodePolyfill: true
@@ -197,7 +197,7 @@ function initToolsConfig(config) {
197
197
  ]
198
198
  }
199
199
  };
200
- var _tools = config.tools, tsChecker = _tools.tsChecker, tsLoader = _tools.tsLoader, htmlPlugin = _tools.htmlPlugin;
200
+ var _tools = config.tools, tsChecker = _tools.tsChecker, tsLoader = _tools.tsLoader;
201
201
  config.tools.tsChecker = applyOptionsChain(defaultTsChecker, tsChecker);
202
202
  tsLoader && (config.tools.tsLoader = function(tsLoaderConfig, utils) {
203
203
  applyOptionsChain(_objectSpreadProps(_objectSpread({}, tsLoaderConfig), {
@@ -205,16 +205,5 @@ function initToolsConfig(config) {
205
205
  allowTsInNodeModules: true
206
206
  }), tsLoader || {}, utils);
207
207
  });
208
- config.tools.htmlPlugin = [
209
- function(config2) {
210
- return _objectSpreadProps(_objectSpread({}, config2), {
211
- minify: typeof config2.minify === "object" ? _objectSpreadProps(_objectSpread({}, config2.minify), {
212
- removeComments: false
213
- }) : config2.minify
214
- });
215
- }
216
- ].concat(_toConsumableArray(Array.isArray(htmlPlugin) ? htmlPlugin : htmlPlugin ? [
217
- htmlPlugin
218
- ] : []));
219
208
  }
220
209
  export { initHtmlConfig, initSourceConfig, initToolsConfig };
@@ -175,11 +175,11 @@ var __generator = this && this.__generator || function(thisArg, body) {
175
175
  }
176
176
  };
177
177
  import path from "path";
178
- import LintPlugin from "@modern-js/plugin-lint";
178
+ import lintPlugin from "@modern-js/plugin-lint";
179
179
  import { cleanRequireCache, emptyDir, Import } from "@modern-js/utils";
180
180
  import { castArray } from "@modern-js/utils/lodash";
181
- import AnalyzePlugin from "./analyze";
182
- import InitializePlugin from "./initialize";
181
+ import analyzePlugin from "./analyze";
182
+ import initializePlugin from "./initialize";
183
183
  import { hooks } from "./hooks";
184
184
  import { i18n, localeKeys } from "./locale";
185
185
  import { getLocaleLanguage } from "./utils/language";
@@ -345,7 +345,6 @@ var buildCommand = function() {
345
345
  ];
346
346
  case 2:
347
347
  _state.sent();
348
- process.exit(0);
349
348
  return [
350
349
  2
351
350
  ];
@@ -454,9 +453,9 @@ var src_default = function() {
454
453
  ],
455
454
  registerHook: hooks,
456
455
  usePlugins: [
457
- InitializePlugin(),
458
- AnalyzePlugin(),
459
- LintPlugin()
456
+ initializePlugin(),
457
+ analyzePlugin(),
458
+ lintPlugin()
460
459
  ],
461
460
  setup: function(api) {
462
461
  var locale = getLocaleLanguage();
@@ -546,7 +545,7 @@ var src_default = function() {
546
545
  return _ref.apply(this, arguments);
547
546
  };
548
547
  }());
549
- program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action(function() {
548
+ program.command("new").usage("[options]").description(i18n.t(localeKeys.command.new.describe)).option("--lang <lang>", i18n.t(localeKeys.command.new.lang)).option("-d, --debug", i18n.t(localeKeys.command.new.debug), false).option("-c, --config <config>", i18n.t(localeKeys.command.new.config)).option("--dist-tag <tag>", i18n.t(localeKeys.command.new.distTag)).option("--registry", i18n.t(localeKeys.command.new.registry)).action(function() {
550
549
  var _ref = _asyncToGenerator(function(options) {
551
550
  var MWANewAction;
552
551
  return __generator(this, function(_state) {
@@ -561,7 +560,7 @@ var src_default = function() {
561
560
  return [
562
561
  4,
563
562
  MWANewAction(_objectSpreadProps(_objectSpread({}, options), {
564
- locale: locale
563
+ locale: options.lang || locale
565
564
  }))
566
565
  ];
567
566
  case 2:
@@ -199,7 +199,7 @@ var initialize_default = function() {
199
199
  resolvedConfig: function resolvedConfig(param) {
200
200
  var resolved = param.resolved;
201
201
  return _asyncToGenerator(function() {
202
- var ref, ref1, appContext, userConfig, port, normalizedConfig;
202
+ var ref, appContext, userConfig, port, normalizedConfig;
203
203
  return __generator(this, function(_state) {
204
204
  switch(_state.label){
205
205
  case 0:
@@ -207,7 +207,7 @@ var initialize_default = function() {
207
207
  userConfig = api.useConfigContext();
208
208
  return [
209
209
  4,
210
- getDevServerPort(appContext, resolved)
210
+ getServerPort(resolved)
211
211
  ];
212
212
  case 1:
213
213
  port = _state.sent();
@@ -224,7 +224,7 @@ var initialize_default = function() {
224
224
  _raw: userConfig,
225
225
  source: normalizedConfig.source || {},
226
226
  server: _objectSpreadProps(_objectSpread({}, normalizedConfig.server || {}), {
227
- port: port || ((ref1 = normalizedConfig.server) === null || ref1 === void 0 ? void 0 : ref1.port)
227
+ port: port
228
228
  }),
229
229
  bff: normalizedConfig.bff || {},
230
230
  dev: normalizedConfig.dev || {},
@@ -252,49 +252,26 @@ var initialize_default = function() {
252
252
  }
253
253
  };
254
254
  };
255
- function getDevServerPort(appContext, resolved) {
256
- return _getDevServerPort.apply(this, arguments);
255
+ function getServerPort(config) {
256
+ return _getServerPort.apply(this, arguments);
257
257
  }
258
- function _getDevServerPort() {
259
- _getDevServerPort = _asyncToGenerator(function(appContext, resolved) {
260
- var _port, _tmp;
258
+ function _getServerPort() {
259
+ _getServerPort = _asyncToGenerator(function(config) {
260
+ var prodPort;
261
261
  return __generator(this, function(_state) {
262
- switch(_state.label){
263
- case 0:
264
- if (!(isDev() && isDevCommand())) return [
265
- 3,
266
- 4
267
- ];
268
- if (!(((_port = appContext.port) !== null && _port !== void 0 ? _port : 0) > 0)) return [
269
- 3,
270
- 1
271
- ];
272
- _tmp = appContext.port;
273
- return [
274
- 3,
275
- 3
276
- ];
277
- case 1:
278
- return [
279
- 4,
280
- getPort(resolved.server.port || 8080)
281
- ];
282
- case 2:
283
- _tmp = _state.sent();
284
- _state.label = 3;
285
- case 3:
286
- return [
287
- 2,
288
- _tmp
289
- ];
290
- case 4:
291
- return [
292
- 2,
293
- resolved.server.port
294
- ];
262
+ prodPort = config.server.port || 8080;
263
+ if (isDev() && isDevCommand()) {
264
+ return [
265
+ 2,
266
+ getPort(config.dev.port || prodPort)
267
+ ];
295
268
  }
269
+ return [
270
+ 2,
271
+ prodPort
272
+ ];
296
273
  });
297
274
  });
298
- return _getDevServerPort.apply(this, arguments);
275
+ return _getServerPort.apply(this, arguments);
299
276
  }
300
277
  export { initialize_default as default };
@@ -23,7 +23,8 @@ var EN_LOCALE = {
23
23
  debug: "using debug mode to log something",
24
24
  config: "set default generator config(json string)",
25
25
  distTag: "use specified tag version for it's generator",
26
- registry: "set npm registry url to run npm command"
26
+ registry: "set npm registry url to run npm command",
27
+ lang: "set new command language(en or zh)"
27
28
  },
28
29
  inspect: {
29
30
  env: "specify env mode",
@@ -23,7 +23,8 @@ var ZH_LOCALE = {
23
23
  debug: "开启 Debug 模式,打印调试日志信息",
24
24
  config: "生成器运行默认配置(JSON 字符串)",
25
25
  distTag: "生成器使用特殊的 npm Tag 版本",
26
- registry: "生成器运行过程中定制 npm Registry"
26
+ registry: "生成器运行过程中定制 npm Registry",
27
+ lang: "设置 new 命令执行语言(zh 或者 en)"
27
28
  },
28
29
  inspect: {
29
30
  env: "查看指定环境下的配置",
@@ -25,6 +25,6 @@ export declare const NESTED_ROUTE: {
25
25
  ERROR_FILE: string;
26
26
  LOADER_FILE: string;
27
27
  };
28
- export declare const APP_CONFIG_NAME = "appConfig";
28
+ export declare const APP_CONFIG_NAME = "config";
29
29
  export declare const APP_INIT_EXPORTED = "init";
30
30
  export declare const APP_INIT_IMPORTED = "appInit";
@@ -26,26 +26,20 @@ export declare const html: (partials: {
26
26
  body: string[];
27
27
  }) => string;
28
28
  export declare const routesForServer: ({
29
- routes,
30
- internalDirectory,
31
- entryName
29
+ routes
32
30
  }: {
33
31
  routes: (NestedRoute | PageRoute)[];
34
- internalDirectory: string;
35
- entryName: string;
36
32
  }) => string;
37
33
  export declare const fileSystemRoutes: ({
38
34
  routes,
39
35
  ssrMode,
40
36
  nestedRoutesEntry,
41
37
  entryName,
42
- internalDirectory,
43
- internalDirAlias
38
+ internalDirectory
44
39
  }: {
45
40
  routes: RouteLegacy[] | (NestedRoute | PageRoute)[];
46
41
  ssrMode: 'string' | 'stream' | false;
47
42
  nestedRoutesEntry?: string | undefined;
48
43
  entryName: string;
49
44
  internalDirectory: string;
50
- internalDirAlias: string;
51
45
  }) => Promise<string>;
@@ -15,7 +15,6 @@ export declare const getDefaultImports: ({
15
15
  internalDirectory: string;
16
16
  }) => ImportStatement[];
17
17
  export declare const isPageComponentFile: (filePath: string) => boolean;
18
- export declare const isNestedRouteComponent: (nestedRouteEntries: string[], absoluteFilePath: string) => boolean;
19
18
  export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
20
19
  export declare const parseModule: ({
21
20
  source,
@@ -24,4 +23,5 @@ export declare const parseModule: ({
24
23
  source: string;
25
24
  filename: string;
26
25
  }) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean]>;
27
- export declare const hasLoader: (filename: string) => Promise<boolean>;
26
+ export declare const hasLoader: (filename: string) => Promise<boolean>;
27
+ export declare const getServerLoadersFile: (internalDirectory: string, entryName: string) => string;
@@ -24,6 +24,7 @@ export declare const EN_LOCALE: {
24
24
  config: string;
25
25
  distTag: string;
26
26
  registry: string;
27
+ lang: string;
27
28
  };
28
29
  inspect: {
29
30
  env: string;
@@ -26,6 +26,7 @@ declare const localeKeys: {
26
26
  config: string;
27
27
  distTag: string;
28
28
  registry: string;
29
+ lang: string;
29
30
  };
30
31
  inspect: {
31
32
  env: string;
@@ -59,6 +60,7 @@ declare const localeKeys: {
59
60
  config: string;
60
61
  distTag: string;
61
62
  registry: string;
63
+ lang: string;
62
64
  };
63
65
  inspect: {
64
66
  env: string;
@@ -24,6 +24,7 @@ export declare const ZH_LOCALE: {
24
24
  config: string;
25
25
  distTag: string;
26
26
  registry: string;
27
+ lang: string;
27
28
  };
28
29
  inspect: {
29
30
  env: string;
@@ -1,7 +1,7 @@
1
1
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
2
  type BuilderDevConfig = Required<BuilderConfig>['dev'];
3
3
  export type DevProxyOptions = string | Record<string, string>;
4
- export interface DevUserConfig extends Omit<BuilderDevConfig, 'port'> {
4
+ export interface DevUserConfig extends BuilderDevConfig {
5
5
  /**
6
6
  * The configuration of `dev.proxy` is provided by `proxy` plugin.
7
7
  * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
package/lib/types.d.ts CHANGED
@@ -98,8 +98,12 @@ declare module '*.svg?inline' {
98
98
  React.SVGProps<SVGSVGElement>
99
99
  >;
100
100
 
101
- const src: string;
102
- export default src;
101
+ /**
102
+ * The default export type depends on the svgDefaultExport config,
103
+ * it can be a string or a ReactComponent
104
+ * */
105
+ const content: any;
106
+ export default content;
103
107
  }
104
108
 
105
109
  declare module '*.bmp?url' {