@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
@@ -64,10 +64,10 @@ var initialize_default = () => ({
64
64
  validateSchema,
65
65
  resolvedConfig(_0) {
66
66
  return __async(this, arguments, function* ({ resolved }) {
67
- var _a2, _b;
67
+ var _a2;
68
68
  let appContext = api.useAppContext();
69
69
  const userConfig = api.useConfigContext();
70
- const port = yield getDevServerPort(appContext, resolved);
70
+ const port = yield getServerPort(resolved);
71
71
  appContext = __spreadProps(__spreadValues({}, appContext), {
72
72
  port,
73
73
  distDirectory: ensureAbsolutePath(
@@ -82,7 +82,7 @@ var initialize_default = () => ({
82
82
  _raw: userConfig,
83
83
  source: normalizedConfig.source || {},
84
84
  server: __spreadProps(__spreadValues({}, normalizedConfig.server || {}), {
85
- port: port || ((_b = normalizedConfig.server) == null ? void 0 : _b.port)
85
+ port
86
86
  }),
87
87
  bff: normalizedConfig.bff || {},
88
88
  dev: normalizedConfig.dev || {},
@@ -106,13 +106,13 @@ var initialize_default = () => ({
106
106
  };
107
107
  }
108
108
  });
109
- function getDevServerPort(appContext, resolved) {
109
+ function getServerPort(config) {
110
110
  return __async(this, null, function* () {
111
- var _a;
111
+ const prodPort = config.server.port || 8080;
112
112
  if (isDev() && isDevCommand()) {
113
- return ((_a = appContext.port) != null ? _a : 0) > 0 ? appContext.port : yield getPort(resolved.server.port || 8080);
113
+ return getPort(config.dev.port || prodPort);
114
114
  }
115
- return resolved.server.port;
115
+ return prodPort;
116
116
  });
117
117
  }
118
118
  export {
@@ -19,7 +19,8 @@ const EN_LOCALE = {
19
19
  debug: "using debug mode to log something",
20
20
  config: "set default generator config(json string)",
21
21
  distTag: `use specified tag version for it's generator`,
22
- registry: "set npm registry url to run npm command"
22
+ registry: "set npm registry url to run npm command",
23
+ lang: "set new command language(en or zh)"
23
24
  },
24
25
  inspect: {
25
26
  env: "specify env mode",
@@ -19,7 +19,8 @@ const ZH_LOCALE = {
19
19
  debug: "开启 Debug 模式,打印调试日志信息",
20
20
  config: "生成器运行默认配置(JSON 字符串)",
21
21
  distTag: "生成器使用特殊的 npm Tag 版本",
22
- registry: "生成器运行过程中定制 npm Registry"
22
+ registry: "生成器运行过程中定制 npm Registry",
23
+ lang: "设置 new 命令执行语言(zh 或者 en)"
23
24
  },
24
25
  inspect: {
25
26
  env: "查看指定环境下的配置",
@@ -68,7 +68,7 @@ const NESTED_ROUTE = {
68
68
  ERROR_FILE: "error",
69
69
  LOADER_FILE: "loader"
70
70
  };
71
- const APP_CONFIG_NAME = "appConfig";
71
+ const APP_CONFIG_NAME = "config";
72
72
  const APP_INIT_EXPORTED = "init";
73
73
  const APP_INIT_IMPORTED = "appInit";
74
74
  // Annotate the CommonJS export names for ESM import in node:
@@ -50,18 +50,11 @@ module.exports = __toCommonJS(generateCode_exports);
50
50
  var import_path = __toESM(require("path"));
51
51
  var import_utils = require("@modern-js/utils");
52
52
  var import_core = require("@modern-js/core");
53
- var import_commands = require("../utils/commands");
54
53
  var templates = __toESM(require("./templates"));
55
54
  var import_getClientRoutes = require("./getClientRoutes");
56
55
  var import_constants = require("./constants");
57
56
  var import_utils2 = require("./utils");
58
57
  var import_nestedRoutes = require("./nestedRoutes");
59
- var import_Builder = require("./Builder");
60
- const loader = {
61
- ".js": "jsx",
62
- ".ts": "tsx"
63
- };
64
- const EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
65
58
  const createImportSpecifier = (specifiers) => {
66
59
  let defaults = "";
67
60
  const named = [];
@@ -109,54 +102,10 @@ ${initialize || ""}`
109
102
  ${initialize || ""}`
110
103
  ).join("\n");
111
104
  };
112
- const buildLoader = (entry, outfile) => __async(void 0, null, function* () {
113
- yield import_Builder.loaderBuilder.build({
114
- format: "esm",
115
- platform: "browser",
116
- target: "esnext",
117
- loader,
118
- watch: (0, import_commands.isDevCommand)() && {},
119
- bundle: true,
120
- logLevel: "error",
121
- entryPoints: [entry],
122
- outfile,
123
- plugins: [
124
- {
125
- name: "make-all-packages-external",
126
- setup(build) {
127
- build.onResolve({ filter: EXTERNAL_REGEXP }, (args) => {
128
- let external = true;
129
- if (args.kind === "entry-point") {
130
- external = false;
131
- }
132
- return {
133
- path: args.path,
134
- external
135
- };
136
- });
137
- }
138
- }
139
- ]
140
- });
141
- });
142
- const buildServerLoader = (entry, outfile) => __async(void 0, null, function* () {
143
- yield import_Builder.serverLoaderBuilder.build({
144
- format: "cjs",
145
- platform: "node",
146
- target: "esnext",
147
- loader,
148
- watch: (0, import_commands.isDevCommand)() && {},
149
- bundle: true,
150
- logLevel: "error",
151
- entryPoints: [entry],
152
- outfile
153
- });
154
- });
155
105
  const generateCode = (appContext, config, entrypoints, api) => __async(void 0, null, function* () {
156
106
  var _a, _b, _c;
157
107
  const {
158
108
  internalDirectory,
159
- distDirectory,
160
109
  srcDirectory,
161
110
  internalDirAlias,
162
111
  internalSrcAlias,
@@ -237,47 +186,19 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
237
186
  ssrMode: mode,
238
187
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
239
188
  entryName: entrypoint.entryName,
240
- internalDirectory,
241
- internalDirAlias
189
+ internalDirectory
242
190
  })
243
191
  });
244
- if (entrypoint.nestedRoutesEntry) {
245
- const routesServerFile = import_path.default.join(
192
+ if (entrypoint.nestedRoutesEntry && mode) {
193
+ const routesServerFile = (0, import_utils2.getServerLoadersFile)(
246
194
  internalDirectory,
247
- entryName,
248
- "route-server-loaders.js"
249
- );
250
- const outputRoutesServerFile = import_path.default.join(
251
- distDirectory,
252
- import_utils.LOADER_ROUTES_DIR,
253
- entryName,
254
- "index.js"
195
+ entryName
255
196
  );
256
197
  const code3 = templates.routesForServer({
257
- routes,
258
- internalDirectory,
259
- entryName
198
+ routes
260
199
  });
261
200
  yield import_utils.fs.ensureFile(routesServerFile);
262
201
  yield import_utils.fs.writeFile(routesServerFile, code3);
263
- const loaderEntryFile = import_path.default.join(
264
- internalDirectory,
265
- entryName,
266
- import_constants.TEMP_LOADERS_DIR,
267
- "entry.js"
268
- );
269
- const loaderIndexFile = import_path.default.join(
270
- internalDirectory,
271
- entryName,
272
- import_constants.TEMP_LOADERS_DIR,
273
- "index.js"
274
- );
275
- if (yield import_utils.fs.pathExists(loaderEntryFile)) {
276
- yield buildLoader(loaderEntryFile, loaderIndexFile);
277
- }
278
- if (yield import_utils.fs.pathExists(routesServerFile)) {
279
- yield buildServerLoader(routesServerFile, outputRoutesServerFile);
280
- }
281
202
  }
282
203
  import_utils.fs.outputFileSync(
283
204
  import_path.default.resolve(
@@ -73,7 +73,6 @@ var import_config = require("../utils/config");
73
73
  var import_commands = require("../utils/commands");
74
74
  var import_config2 = require("../config");
75
75
  var import_utils2 = require("./utils");
76
- var import_Builder = require("./Builder");
77
76
  var import_constants = require("./constants");
78
77
  const debug = (0, import_utils.createDebugger)("plugin-analyze");
79
78
  var analyze_default = () => ({
@@ -224,6 +223,33 @@ var analyze_default = () => ({
224
223
  watchFiles() {
225
224
  return pagesDir;
226
225
  },
226
+ config() {
227
+ return {
228
+ tools: {
229
+ webpackChain: (chain, { name }) => {
230
+ const appContext = api.useAppContext();
231
+ const resolvedConfig = api.useResolvedConfigContext();
232
+ const { entrypoints, internalDirectory, packageName } = appContext;
233
+ entrypoints.forEach((entrypoint) => {
234
+ const { entryName } = entrypoint;
235
+ const ssr = (0, import_utils.getEntryOptions)(
236
+ entryName,
237
+ resolvedConfig.server.ssr,
238
+ resolvedConfig.server.ssrByEntries,
239
+ packageName
240
+ );
241
+ if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
242
+ const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
243
+ internalDirectory,
244
+ entryName
245
+ );
246
+ chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
247
+ }
248
+ });
249
+ }
250
+ }
251
+ };
252
+ },
227
253
  resolvedConfig({ resolved }) {
228
254
  const appContext = api.useAppContext();
229
255
  const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext);
@@ -283,12 +309,6 @@ var analyze_default = () => ({
283
309
  };
284
310
  });
285
311
  },
286
- beforeRestart() {
287
- return __async(this, null, function* () {
288
- import_Builder.serverLoaderBuilder.stop();
289
- import_Builder.loaderBuilder.stop();
290
- });
291
- },
292
312
  fileChange(e) {
293
313
  return __async(this, null, function* () {
294
314
  const appContext = api.useAppContext();
@@ -297,7 +317,7 @@ var analyze_default = () => ({
297
317
  const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
298
318
  const absoluteFilePath = path.resolve(appDirectory, filename);
299
319
  const isRouteComponent = isPageFile(absoluteFilePath) && (0, import_utils2.isPageComponentFile)(absoluteFilePath);
300
- if (isRouteComponent && (eventType === "add" || eventType === "unlink") || (0, import_utils2.isNestedRouteComponent)(nestedRouteEntries, absoluteFilePath) && eventType === "change") {
320
+ if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
301
321
  const resolvedConfig = api.useResolvedConfigContext();
302
322
  const { generateCode } = yield Promise.resolve().then(() => __toESM(require("./generateCode")));
303
323
  const entrypoints = (0, import_lodash.cloneDeep)(originEntrypoints);
@@ -68,12 +68,6 @@ var import_utils = require("@modern-js/utils");
68
68
  var import_constants = require("./constants");
69
69
  var import_utils2 = require("./utils");
70
70
  const conventionNames = Object.values(import_constants.NESTED_ROUTE);
71
- const getLoaderPath = (filename) => __async(void 0, null, function* () {
72
- if (yield (0, import_utils2.hasLoader)(filename)) {
73
- return filename;
74
- }
75
- return void 0;
76
- });
77
71
  const replaceDynamicPath = (routePath) => {
78
72
  return routePath.replace(/\[(.*?)\]/g, ":$1");
79
73
  };
@@ -144,10 +138,6 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
144
138
  }
145
139
  if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_FILE) {
146
140
  route._component = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
147
- const loaderPath = yield getLoaderPath(itemPath);
148
- if (loaderPath) {
149
- route.loader = loaderPath;
150
- }
151
141
  }
152
142
  if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_LOADER_FILE) {
153
143
  pageLoaderFile = itemPath;
@@ -161,10 +151,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
161
151
  itemPath,
162
152
  entryName
163
153
  );
164
- const loaderPath = yield getLoaderPath(itemPath);
165
- if (loaderPath) {
166
- pageRoute.loader = loaderPath;
167
- } else if (pageLoaderFile) {
154
+ if (pageLoaderFile) {
168
155
  pageRoute.loader = pageLoaderFile;
169
156
  }
170
157
  (_b = route.children) == null ? void 0 : _b.push(pageRoute);
@@ -102,7 +102,7 @@ const renderFunction = ({
102
102
  return `
103
103
  const finalAppConfig = {
104
104
  ...App.config,
105
- ...typeof ${import_constants.APP_CONFIG_NAME} === 'object' ? ${import_constants.APP_CONFIG_NAME} : {},
105
+ ...typeof ${import_constants.APP_CONFIG_NAME} === 'function' ? ${import_constants.APP_CONFIG_NAME}() : {},
106
106
  }
107
107
 
108
108
  AppWrapper = createApp({
@@ -157,17 +157,9 @@ const html = (partials) => `
157
157
  </html>
158
158
  `;
159
159
  const routesForServer = ({
160
- routes,
161
- internalDirectory,
162
- entryName
160
+ routes
163
161
  }) => {
164
162
  const loaders = [];
165
- const loaderIndexFile = import_path.default.join(
166
- internalDirectory,
167
- entryName,
168
- import_constants.TEMP_LOADERS_DIR,
169
- "index.js"
170
- );
171
163
  const traverseRouteTree = (route) => {
172
164
  var _a;
173
165
  let children;
@@ -205,10 +197,9 @@ const routesForServer = ({
205
197
  ];`;
206
198
  let importLoadersCode = "";
207
199
  if (loaders.length > 0) {
208
- importLoadersCode = `
209
- import { ${loaders.map(
210
- (loader, index2) => `loader_${index2}`
211
- )} } from "${(0, import_utils.slash)(loaderIndexFile)}"`;
200
+ importLoadersCode = loaders.map((loader, index2) => {
201
+ return `import loader_${index2} from "${(0, import_utils.slash)(loader)}"`;
202
+ }).join("\n");
212
203
  }
213
204
  return `
214
205
  ${importLoadersCode}
@@ -220,19 +211,12 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
220
211
  ssrMode,
221
212
  nestedRoutesEntry,
222
213
  entryName,
223
- internalDirectory,
224
- internalDirAlias
214
+ internalDirectory
225
215
  }) {
226
216
  const loadings = [];
227
217
  const errors = [];
228
218
  const loaders = [];
229
219
  const loadersMap = {};
230
- const loadersIndexFile = import_path.default.join(
231
- internalDirAlias,
232
- entryName,
233
- import_constants.TEMP_LOADERS_DIR,
234
- "index.js"
235
- );
236
220
  const loadersMapFile = import_path.default.join(
237
221
  internalDirectory,
238
222
  entryName,
@@ -244,13 +228,20 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
244
228
  import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
245
229
  `;
246
230
  let rootLayoutCode = ``;
247
- let dataLoaderPath = "";
248
231
  let componentLoaderPath = "";
249
- if (ssrMode) {
250
- dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
232
+ const getDataLoaderPath = (loaderId) => {
233
+ if (!ssrMode) {
234
+ return "";
235
+ }
236
+ let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
251
237
  if (nestedRoutesEntry) {
252
- dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}&mapFile=${loadersMapFile}!`;
238
+ dataLoaderPath = `${(0, import_utils.slash)(dataLoaderPath)}?mapFile=${(0, import_utils.slash)(
239
+ loadersMapFile
240
+ )}&loaderId=${loaderId}!`;
253
241
  }
242
+ return dataLoaderPath;
243
+ };
244
+ if (ssrMode) {
254
245
  componentLoaderPath = `${import_path.default.join(
255
246
  __dirname,
256
247
  "../builder/loaders/routerLoader"
@@ -280,7 +271,11 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
280
271
  loaders.push(route.loader);
281
272
  const loaderId = loaders.length - 1;
282
273
  loader = `loader_${loaderId}`;
283
- loadersMap[loader] = route.id;
274
+ loadersMap[loader] = {
275
+ routeId: route.id,
276
+ filePath: route.loader,
277
+ inline: false
278
+ };
284
279
  }
285
280
  if (route._component) {
286
281
  if (route.isRoot) {
@@ -336,48 +331,21 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
336
331
  `;
337
332
  }).join("");
338
333
  let importLoadersCode = "";
339
- if (loaders.length > 0) {
340
- importLoadersCode = `
341
- import { ${loaders.map(
342
- (loader, index2) => `loader_${index2}`
343
- )} } from "${(0, import_utils.slash)(dataLoaderPath)}${(0, import_utils.slash)(loadersIndexFile)}"
344
- `;
345
- const loaderEntryCode = loaders.map((loader, index2) => {
346
- return `export * from './loader_${index2}.js';`;
347
- }).join("\n");
348
- const loaderEntryFile = import_path.default.join(
349
- internalDirectory,
350
- entryName,
351
- import_constants.TEMP_LOADERS_DIR,
352
- "entry.js"
353
- );
354
- yield import_utils.fs.ensureFile(loaderEntryFile);
355
- yield import_utils.fs.writeFile(loaderEntryFile, loaderEntryCode);
356
- yield import_utils.fs.writeJSON(loadersMapFile, loadersMap);
357
- yield Promise.all(
358
- loaders.map((loader, index2) => __async(void 0, null, function* () {
359
- const name = `loader_${index2}`;
360
- const filename = import_path.default.join(
361
- internalDirectory,
362
- entryName,
363
- import_constants.TEMP_LOADERS_DIR,
364
- `${name}.js`
365
- );
366
- let code = "";
367
- if (loader.includes(".loader.")) {
368
- code = `
369
- export { default as ${name} } from '${(0, import_utils.slash)(loader)}'
370
- `;
371
- } else {
372
- code = `
373
- export { loader as ${name} } from '${(0, import_utils.slash)(loader)}'
374
- `;
375
- }
376
- yield import_utils.fs.ensureFile(filename);
377
- yield import_utils.fs.writeFile(filename, code);
378
- }))
379
- );
334
+ for (const [key, loaderInfo] of Object.entries(loadersMap)) {
335
+ if (loaderInfo.inline) {
336
+ importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
337
+ key
338
+ )}${(0, import_utils.slash)(loaderInfo.filePath)}";
339
+ `;
340
+ } else {
341
+ importLoadersCode += `import ${key} from "${getDataLoaderPath(
342
+ key
343
+ )}${(0, import_utils.slash)(loaderInfo.filePath)}";
344
+ `;
345
+ }
380
346
  }
347
+ yield import_utils.fs.ensureFile(loadersMapFile);
348
+ yield import_utils.fs.writeJSON(loadersMapFile, loadersMap);
381
349
  return `
382
350
  ${importLazyCode}
383
351
  ${rootLayoutCode}
@@ -44,8 +44,8 @@ var __async = (__this, __arguments, generator) => {
44
44
  var utils_exports = {};
45
45
  __export(utils_exports, {
46
46
  getDefaultImports: () => getDefaultImports,
47
+ getServerLoadersFile: () => getServerLoadersFile,
47
48
  hasLoader: () => hasLoader,
48
- isNestedRouteComponent: () => isNestedRouteComponent,
49
49
  isPageComponentFile: () => isPageComponentFile,
50
50
  parseModule: () => parseModule,
51
51
  replaceWithAlias: () => replaceWithAlias,
@@ -134,17 +134,6 @@ const isPageComponentFile = (filePath) => {
134
134
  }
135
135
  return false;
136
136
  };
137
- const isNestedRouteComponent = (nestedRouteEntries, absoluteFilePath) => {
138
- const reg = new RegExp(
139
- `(${import_constants.NESTED_ROUTE.LAYOUT_FILE}|${import_constants.NESTED_ROUTE.PAGE_FILE})\\.tsx?$`
140
- );
141
- return nestedRouteEntries.some((nestedRoutesEntry) => {
142
- if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
143
- return true;
144
- }
145
- return false;
146
- });
147
- };
148
137
  const replaceWithAlias = (base, filePath, alias) => (0, import_utils.normalizeToPosixPath)(import_path.default.join(alias, import_path.default.relative(base, filePath)));
149
138
  const parseModule = (_0) => __async(void 0, [_0], function* ({
150
139
  source,
@@ -168,11 +157,14 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
168
157
  });
169
158
  return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
170
159
  });
160
+ const getServerLoadersFile = (internalDirectory, entryName) => {
161
+ return import_path.default.join(internalDirectory, entryName, "route-server-loaders.js");
162
+ };
171
163
  // Annotate the CommonJS export names for ESM import in node:
172
164
  0 && (module.exports = {
173
165
  getDefaultImports,
166
+ getServerLoadersFile,
174
167
  hasLoader,
175
- isNestedRouteComponent,
176
168
  isPageComponentFile,
177
169
  parseModule,
178
170
  replaceWithAlias,
@@ -104,7 +104,6 @@ function createBuilderForModern(_0) {
104
104
  });
105
105
  }
106
106
  function createBuilderProviderConfig(normalizedConfig, appContext) {
107
- var _a;
108
107
  const output = createOutputConfig(normalizedConfig, appContext);
109
108
  const htmlConfig = __spreadValues({}, normalizedConfig.html);
110
109
  if (!htmlConfig.template) {
@@ -113,7 +112,7 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
113
112
  return __spreadProps(__spreadValues({}, normalizedConfig), {
114
113
  output,
115
114
  dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
116
- port: (_a = normalizedConfig.server) == null ? void 0 : _a.port
115
+ port: appContext.port
117
116
  }),
118
117
  html: htmlConfig
119
118
  });
@@ -41,7 +41,9 @@ module.exports = __toCommonJS(default_exports);
41
41
  var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
42
42
  function createDefaultConfig(appContext) {
43
43
  const defaultBuilderConfig = (0, import_builder_webpack_provider.createDefaultConfig)();
44
- const dev = __spreadValues({}, defaultBuilderConfig.dev);
44
+ const dev = __spreadProps(__spreadValues({}, defaultBuilderConfig.dev), {
45
+ port: void 0
46
+ });
45
47
  const tools = __spreadValues({}, defaultBuilderConfig.tools);
46
48
  const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
47
49
  disableNodePolyfill: true
@@ -154,7 +154,7 @@ function initToolsConfig(config) {
154
154
  ]
155
155
  }
156
156
  };
157
- const { tsChecker, tsLoader, htmlPlugin } = config.tools;
157
+ const { tsChecker, tsLoader } = config.tools;
158
158
  config.tools.tsChecker = (0, import_utils.applyOptionsChain)(defaultTsChecker, tsChecker);
159
159
  tsLoader && (config.tools.tsLoader = (tsLoaderConfig, utils) => {
160
160
  (0, import_utils.applyOptionsChain)(
@@ -166,14 +166,6 @@ function initToolsConfig(config) {
166
166
  utils
167
167
  );
168
168
  });
169
- config.tools.htmlPlugin = [
170
- (config2) => __spreadProps(__spreadValues({}, config2), {
171
- minify: typeof config2.minify === "object" ? __spreadProps(__spreadValues({}, config2.minify), {
172
- removeComments: false
173
- }) : config2.minify
174
- }),
175
- ...Array.isArray(htmlPlugin) ? htmlPlugin : htmlPlugin ? [htmlPlugin] : []
176
- ];
177
169
  }
178
170
  // Annotate the CommonJS export names for ESM import in node:
179
171
  0 && (module.exports = {
@@ -112,7 +112,6 @@ const buildCommand = (program, api) => __async(void 0, null, function* () {
112
112
  const buildProgram = program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).action((options) => __async(void 0, null, function* () {
113
113
  const { build } = yield Promise.resolve().then(() => __toESM(require("./commands/build")));
114
114
  yield build(api, options);
115
- process.exit(0);
116
115
  }));
117
116
  for (const platformBuilder of platformBuilders) {
118
117
  const platforms = (0, import_lodash.castArray)(platformBuilder.platform);
@@ -167,12 +166,12 @@ var src_default = () => ({
167
166
  yield deploy(api, options);
168
167
  process.exit(0);
169
168
  }));
170
- program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option(
169
+ program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("--lang <lang>", import_locale.i18n.t(import_locale.localeKeys.command.new.lang)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option(
171
170
  "-c, --config <config>",
172
171
  import_locale.i18n.t(import_locale.localeKeys.command.new.config)
173
172
  ).option("--dist-tag <tag>", import_locale.i18n.t(import_locale.localeKeys.command.new.distTag)).option("--registry", import_locale.i18n.t(import_locale.localeKeys.command.new.registry)).action((options) => __async(this, null, function* () {
174
173
  const { MWANewAction } = yield Promise.resolve().then(() => __toESM(require("@modern-js/new-action")));
175
- yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale }));
174
+ yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale: options.lang || locale }));
176
175
  }));
177
176
  program.command("inspect").description("inspect internal webpack config").option(
178
177
  `--env <env>`,
@@ -80,10 +80,10 @@ var initialize_default = () => ({
80
80
  validateSchema,
81
81
  resolvedConfig(_0) {
82
82
  return __async(this, arguments, function* ({ resolved }) {
83
- var _a2, _b;
83
+ var _a2;
84
84
  let appContext = api.useAppContext();
85
85
  const userConfig = api.useConfigContext();
86
- const port = yield getDevServerPort(appContext, resolved);
86
+ const port = yield getServerPort(resolved);
87
87
  appContext = __spreadProps(__spreadValues({}, appContext), {
88
88
  port,
89
89
  distDirectory: (0, import_utils.ensureAbsolutePath)(
@@ -98,7 +98,7 @@ var initialize_default = () => ({
98
98
  _raw: userConfig,
99
99
  source: normalizedConfig.source || {},
100
100
  server: __spreadProps(__spreadValues({}, normalizedConfig.server || {}), {
101
- port: port || ((_b = normalizedConfig.server) == null ? void 0 : _b.port)
101
+ port
102
102
  }),
103
103
  bff: normalizedConfig.bff || {},
104
104
  dev: normalizedConfig.dev || {},
@@ -122,13 +122,13 @@ var initialize_default = () => ({
122
122
  };
123
123
  }
124
124
  });
125
- function getDevServerPort(appContext, resolved) {
125
+ function getServerPort(config) {
126
126
  return __async(this, null, function* () {
127
- var _a;
127
+ const prodPort = config.server.port || 8080;
128
128
  if ((0, import_utils.isDev)() && (0, import_commands.isDevCommand)()) {
129
- return ((_a = appContext.port) != null ? _a : 0) > 0 ? appContext.port : yield (0, import_utils.getPort)(resolved.server.port || 8080);
129
+ return (0, import_utils.getPort)(config.dev.port || prodPort);
130
130
  }
131
- return resolved.server.port;
131
+ return prodPort;
132
132
  });
133
133
  }
134
134
  // Annotate the CommonJS export names for ESM import in node:
@@ -41,7 +41,8 @@ const EN_LOCALE = {
41
41
  debug: "using debug mode to log something",
42
42
  config: "set default generator config(json string)",
43
43
  distTag: `use specified tag version for it's generator`,
44
- registry: "set npm registry url to run npm command"
44
+ registry: "set npm registry url to run npm command",
45
+ lang: "set new command language(en or zh)"
45
46
  },
46
47
  inspect: {
47
48
  env: "specify env mode",
@@ -41,7 +41,8 @@ const ZH_LOCALE = {
41
41
  debug: "开启 Debug 模式,打印调试日志信息",
42
42
  config: "生成器运行默认配置(JSON 字符串)",
43
43
  distTag: "生成器使用特殊的 npm Tag 版本",
44
- registry: "生成器运行过程中定制 npm Registry"
44
+ registry: "生成器运行过程中定制 npm Registry",
45
+ lang: "设置 new 命令执行语言(zh 或者 en)"
45
46
  },
46
47
  inspect: {
47
48
  env: "查看指定环境下的配置",
@@ -34,7 +34,7 @@ var NESTED_ROUTE = {
34
34
  ERROR_FILE: "error",
35
35
  LOADER_FILE: "loader"
36
36
  };
37
- var APP_CONFIG_NAME = "appConfig";
37
+ var APP_CONFIG_NAME = "config";
38
38
  var APP_INIT_EXPORTED = "init";
39
39
  var APP_INIT_IMPORTED = "appInit";
40
40
  export { APP_CONFIG_NAME, APP_FILE_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_FILE_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT, HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER, INDEX_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTE, NESTED_ROUTES_DIR, PAGES_DIR_NAME, TEMP_LOADERS_DIR };