@modern-js/app-tools 2.0.0-beta.4 → 2.0.0-beta.6

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 (146) hide show
  1. package/CHANGELOG.md +314 -0
  2. package/bin/modern.js +2 -0
  3. package/dist/js/modern/analyze/constants.js +10 -0
  4. package/dist/js/modern/analyze/generateCode.js +7 -9
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +9 -6
  6. package/dist/js/modern/analyze/getFileSystemEntry.js +11 -3
  7. package/dist/js/modern/analyze/index.js +7 -5
  8. package/dist/js/modern/analyze/nestedRoutes.js +29 -22
  9. package/dist/js/modern/analyze/templates.js +8 -1
  10. package/dist/js/modern/analyze/utils.js +19 -3
  11. package/dist/js/modern/builder/builderPlugins/compatModern.js +8 -2
  12. package/dist/js/modern/builder/index.js +1 -7
  13. package/dist/js/modern/commands/dev.js +6 -9
  14. package/dist/js/modern/commands/index.js +1 -1
  15. package/dist/js/modern/commands/{start.js → serve.js} +3 -1
  16. package/dist/js/modern/config/default.js +38 -61
  17. package/dist/js/modern/config/initial/createOutputConfig.js +1 -3
  18. package/dist/js/modern/config/initial/createSourceConfig.js +5 -1
  19. package/dist/js/modern/config/initial/transformNormalizedConfig.js +5 -1
  20. package/dist/js/modern/hooks.js +1 -0
  21. package/dist/js/modern/index.js +5 -5
  22. package/dist/js/modern/initialize/index.js +5 -4
  23. package/dist/js/modern/locale/en.js +1 -1
  24. package/dist/js/modern/locale/zh.js +1 -1
  25. package/dist/js/modern/schema/index.js +3 -1
  26. package/dist/js/modern/utils/commands.js +6 -1
  27. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  28. package/dist/js/node/analyze/Builder.js +14 -8
  29. package/dist/js/node/analyze/constants.js +35 -3
  30. package/dist/js/node/analyze/generateCode.js +27 -24
  31. package/dist/js/node/analyze/getBundleEntry.js +7 -3
  32. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +33 -28
  33. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +24 -22
  34. package/dist/js/node/analyze/getClientRoutes/index.js +8 -3
  35. package/dist/js/node/analyze/getClientRoutes/utils.js +10 -3
  36. package/dist/js/node/analyze/getFileSystemEntry.js +18 -6
  37. package/dist/js/node/analyze/getHtmlTemplate.js +18 -14
  38. package/dist/js/node/analyze/getServerRoutes.js +36 -34
  39. package/dist/js/node/analyze/index.js +45 -59
  40. package/dist/js/node/analyze/isDefaultExportFunction.js +7 -3
  41. package/dist/js/node/analyze/makeLegalIdentifier.js +7 -3
  42. package/dist/js/node/analyze/nestedRoutes.js +58 -49
  43. package/dist/js/node/analyze/templates.js +45 -32
  44. package/dist/js/node/analyze/utils.js +39 -17
  45. package/dist/js/node/builder/builderPlugins/compatModern.js +32 -24
  46. package/dist/js/node/builder/index.js +36 -48
  47. package/dist/js/node/builder/loaders/routerLoader.js +5 -3
  48. package/dist/js/node/builder/loaders/serverModuleLoader.js +5 -3
  49. package/dist/js/node/builder/share.js +7 -3
  50. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +7 -3
  51. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +7 -3
  52. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +9 -7
  53. package/dist/js/node/commands/build.js +30 -28
  54. package/dist/js/node/commands/deploy.js +9 -5
  55. package/dist/js/node/commands/dev.js +39 -40
  56. package/dist/js/node/commands/index.js +5 -5
  57. package/dist/js/node/commands/inspect.js +10 -6
  58. package/dist/js/node/commands/{start.js → serve.js} +16 -10
  59. package/dist/js/node/config/default.js +44 -64
  60. package/dist/js/node/config/index.js +10 -3
  61. package/dist/js/node/config/initial/createHtmlConfig.js +7 -3
  62. package/dist/js/node/config/initial/createOutputConfig.js +8 -6
  63. package/dist/js/node/config/initial/createSourceConfig.js +12 -4
  64. package/dist/js/node/config/initial/createToolsConfig.js +7 -3
  65. package/dist/js/node/config/initial/index.js +9 -3
  66. package/dist/js/node/config/initial/inits.js +26 -22
  67. package/dist/js/node/config/initial/transformNormalizedConfig.js +12 -4
  68. package/dist/js/node/defineConfig.js +25 -22
  69. package/dist/js/node/exports/server.js +7 -3
  70. package/dist/js/node/hooks.js +8 -3
  71. package/dist/js/node/index.js +56 -69
  72. package/dist/js/node/initialize/index.js +33 -32
  73. package/dist/js/node/locale/en.js +8 -4
  74. package/dist/js/node/locale/index.js +8 -3
  75. package/dist/js/node/locale/zh.js +8 -4
  76. package/dist/js/node/schema/Schema.js +7 -3
  77. package/dist/js/node/schema/index.js +11 -4
  78. package/dist/js/node/schema/legacy.js +5 -3
  79. package/dist/js/node/types/config/deploy.js +15 -0
  80. package/dist/js/node/types/config/dev.js +15 -0
  81. package/dist/js/node/types/config/experiments.js +15 -0
  82. package/dist/js/node/types/config/html.js +15 -0
  83. package/dist/js/node/types/config/index.js +3 -3
  84. package/dist/js/node/types/config/output.js +15 -0
  85. package/dist/js/node/types/config/performance.js +15 -0
  86. package/dist/js/node/types/config/security.js +15 -0
  87. package/dist/js/node/types/config/source.js +15 -0
  88. package/dist/js/node/types/config/tools.js +15 -0
  89. package/dist/js/node/types/hooks.js +15 -0
  90. package/dist/js/node/types/index.js +5 -5
  91. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  92. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  93. package/dist/js/node/types/legacyConfig/index.js +15 -0
  94. package/dist/js/node/types/legacyConfig/output.js +15 -0
  95. package/dist/js/node/types/legacyConfig/source.js +15 -0
  96. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  97. package/dist/js/node/utils/commands.js +14 -4
  98. package/dist/js/node/utils/config.js +35 -30
  99. package/dist/js/node/utils/createFileWatcher.js +15 -10
  100. package/dist/js/node/utils/createServer.js +35 -29
  101. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  102. package/dist/js/node/utils/getSpecifiedEntries.js +10 -6
  103. package/dist/js/node/utils/language.js +7 -3
  104. package/dist/js/node/utils/printInstructions.js +10 -6
  105. package/dist/js/node/utils/restart.js +11 -7
  106. package/dist/js/node/utils/routes.js +11 -7
  107. package/dist/js/node/utils/types.js +15 -0
  108. package/dist/js/treeshaking/analyze/constants.js +10 -1
  109. package/dist/js/treeshaking/analyze/generateCode.js +7 -11
  110. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +9 -6
  111. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +11 -3
  112. package/dist/js/treeshaking/analyze/index.js +7 -4
  113. package/dist/js/treeshaking/analyze/nestedRoutes.js +30 -23
  114. package/dist/js/treeshaking/analyze/templates.js +6 -1
  115. package/dist/js/treeshaking/analyze/utils.js +12 -3
  116. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +6 -2
  117. package/dist/js/treeshaking/builder/index.js +1 -7
  118. package/dist/js/treeshaking/commands/dev.js +19 -24
  119. package/dist/js/treeshaking/commands/index.js +1 -1
  120. package/dist/js/treeshaking/commands/{start.js → serve.js} +10 -3
  121. package/dist/js/treeshaking/config/default.js +53 -56
  122. package/dist/js/treeshaking/config/initial/createOutputConfig.js +1 -3
  123. package/dist/js/treeshaking/config/initial/createSourceConfig.js +5 -1
  124. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +5 -1
  125. package/dist/js/treeshaking/hooks.js +1 -0
  126. package/dist/js/treeshaking/index.js +5 -5
  127. package/dist/js/treeshaking/initialize/index.js +6 -5
  128. package/dist/js/treeshaking/locale/en.js +1 -1
  129. package/dist/js/treeshaking/locale/zh.js +1 -1
  130. package/dist/js/treeshaking/schema/index.js +7 -1
  131. package/dist/js/treeshaking/utils/commands.js +5 -1
  132. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  133. package/dist/types/analyze/constants.d.ts +10 -1
  134. package/dist/types/analyze/utils.d.ts +2 -1
  135. package/dist/types/commands/index.d.ts +1 -1
  136. package/dist/types/commands/{start.d.ts → serve.d.ts} +0 -0
  137. package/dist/types/index.d.ts +1 -0
  138. package/dist/types/locale/en.d.ts +1 -1
  139. package/dist/types/locale/index.d.ts +2 -2
  140. package/dist/types/locale/zh.d.ts +1 -1
  141. package/dist/types/types/config/index.d.ts +3 -0
  142. package/dist/types/types/config/source.d.ts +1 -0
  143. package/dist/types/types/hooks.d.ts +3 -0
  144. package/dist/types/utils/commands.d.ts +2 -1
  145. package/dist/types/utils/getServerInternalPlugins.d.ts +2 -0
  146. package/package.json +25 -22
@@ -23,7 +23,11 @@ import path from "path";
23
23
  import { isReact18, normalizeToPosixPath, fs as fse } from "@modern-js/utils";
24
24
  import { transform } from "esbuild";
25
25
  import { parse } from "es-module-lexer";
26
- import { FILE_SYSTEM_ROUTES_FILE_NAME, LOADER_EXPORT_NAME } from "./constants";
26
+ import {
27
+ FILE_SYSTEM_ROUTES_FILE_NAME,
28
+ LOADER_EXPORT_NAME,
29
+ NESTED_ROUTE
30
+ } from "./constants";
27
31
  const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) => {
28
32
  const filePath = path.join(dir, filename);
29
33
  if (fs.statSync(filePath).isDirectory()) {
@@ -91,7 +95,7 @@ const getDefaultImports = ({
91
95
  }
92
96
  return imports;
93
97
  };
94
- const isRouteComponentFile = (filePath) => {
98
+ const isPageComponentFile = (filePath) => {
95
99
  if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
96
100
  return false;
97
101
  }
@@ -100,6 +104,17 @@ const isRouteComponentFile = (filePath) => {
100
104
  }
101
105
  return false;
102
106
  };
107
+ const isNestedRouteComponent = (nestedRouteEntries, absoluteFilePath) => {
108
+ const reg = new RegExp(
109
+ `(${NESTED_ROUTE.LAYOUT_FILE}|${NESTED_ROUTE.PAGE_FILE}})\\.tsx?$`
110
+ );
111
+ return nestedRouteEntries.some((nestedRoutesEntry) => {
112
+ if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
113
+ return true;
114
+ }
115
+ return false;
116
+ });
117
+ };
103
118
  const replaceWithAlias = (base, filePath, alias) => normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
104
119
  const parseModule = (_0) => __async(void 0, [_0], function* ({
105
120
  source,
@@ -126,7 +141,8 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
126
141
  export {
127
142
  getDefaultImports,
128
143
  hasLoader,
129
- isRouteComponentFile,
144
+ isNestedRouteComponent,
145
+ isPageComponentFile,
130
146
  parseModule,
131
147
  replaceWithAlias,
132
148
  walkDirectory
@@ -42,7 +42,7 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
42
42
  return config;
43
43
  });
44
44
  api.modifyWebpackChain((chain, { target, CHAIN_ID, isProd }) => {
45
- var _a, _b;
45
+ var _a;
46
46
  const builderNormalizedConfig = api.getNormalizedConfig();
47
47
  if (target === "node") {
48
48
  chain.name("server");
@@ -89,7 +89,8 @@ const PluginCompatModern = (appContext, modernConfig, options) => ({
89
89
  const existNestedRoutes = entrypoints.some(
90
90
  (entrypoint) => entrypoint.nestedRoutesEntry
91
91
  );
92
- const routerManifest = Boolean((_b = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router) == null ? void 0 : _b.manifest);
92
+ const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
93
+ const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
93
94
  if (existNestedRoutes || routerManifest) {
94
95
  chain.plugin("route-plugin").use(RouterPlugin);
95
96
  }
@@ -143,6 +144,11 @@ function applyNodeCompat(chain, modernConfig, isProd) {
143
144
  if (isProd2 && ((outputConfig == null ? void 0 : outputConfig.ssg) === true || typeof ((_a = outputConfig == null ? void 0 : outputConfig.ssg) == null ? void 0 : _a[0]) === "function")) {
144
145
  return;
145
146
  }
147
+ if (typeof entries === "undefined") {
148
+ throw new Error(
149
+ "No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required"
150
+ );
151
+ }
146
152
  const entryNames = Object.keys(entries);
147
153
  if (isProd2 && entryNames.length === 1 && (outputConfig == null ? void 0 : outputConfig.ssg)) {
148
154
  return;
@@ -88,17 +88,11 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
88
88
  htmlConfig.templateByEntries = __spreadValues(__spreadValues({}, htmlConfig.templateByEntries), appContext.htmlTemplates);
89
89
  }
90
90
  return __spreadProps(__spreadValues({}, normalizedConfig), {
91
- source: __spreadProps(__spreadValues({}, normalizedConfig.source), {
92
- resolveExtensionPrefix: ".web"
93
- }),
94
91
  output,
95
92
  dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
96
93
  port: (_a = normalizedConfig.server) == null ? void 0 : _a.port
97
94
  }),
98
- html: htmlConfig,
99
- performance: __spreadProps(__spreadValues({}, normalizedConfig.performance), {
100
- removeMomentLocale: true
101
- })
95
+ html: htmlConfig
102
96
  });
103
97
  function createOutputConfig(config, appContext2) {
104
98
  const defaultCopyPattern = createCopyPattern(appContext2, config, "upload");
@@ -48,6 +48,7 @@ import {
48
48
  import { generateRoutes } from "../utils/routes";
49
49
  import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
50
50
  import { buildServerConfig } from "../utils/config";
51
+ import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
51
52
  const dev = (api, options) => __async(void 0, null, function* () {
52
53
  var _a;
53
54
  if (options.analyze) {
@@ -64,8 +65,7 @@ const dev = (api, options) => __async(void 0, null, function* () {
64
65
  port,
65
66
  apiOnly,
66
67
  entrypoints,
67
- serverConfigFile,
68
- serverInternalPlugins
68
+ serverConfigFile
69
69
  } = appContext;
70
70
  const checkedEntries = yield getSpecifiedEntries(
71
71
  options.entry || false,
@@ -86,29 +86,27 @@ const dev = (api, options) => __async(void 0, null, function* () {
86
86
  }
87
87
  });
88
88
  yield hookRunners.beforeDev();
89
- let compiler;
90
89
  if (!appContext.builder && !apiOnly) {
91
90
  throw new Error(
92
91
  "Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
93
92
  );
94
93
  }
95
- if (!apiOnly) {
96
- compiler = yield appContext.builder.createCompiler();
97
- }
98
94
  yield generateRoutes(appContext);
95
+ const serverInternalPlugins = yield getServerInternalPlugins(api);
99
96
  const serverOptions = {
100
97
  dev: __spreadValues({
101
98
  port,
102
99
  https: normalizedConfig.dev.https
103
100
  }, (_a = normalizedConfig.tools) == null ? void 0 : _a.devServer),
104
- compiler: compiler || null,
105
101
  pwd: appDirectory,
106
102
  config: normalizedConfig,
107
103
  serverConfigFile,
108
104
  internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
109
105
  };
110
106
  if (apiOnly) {
111
- const app = yield createServer(serverOptions);
107
+ const app = yield createServer(__spreadProps(__spreadValues({}, serverOptions), {
108
+ compiler: null
109
+ }));
112
110
  app.listen(port, (err) => __async(void 0, null, function* () {
113
111
  if (err) {
114
112
  throw err;
@@ -117,7 +115,6 @@ const dev = (api, options) => __async(void 0, null, function* () {
117
115
  }));
118
116
  } else {
119
117
  const { server } = yield appContext.builder.startDevServer({
120
- compiler,
121
118
  printURLs: false,
122
119
  serverOptions
123
120
  });
@@ -1,3 +1,3 @@
1
1
  export * from "./dev";
2
2
  export * from "./build";
3
- export * from "./start";
3
+ export * from "./serve";
@@ -22,6 +22,7 @@ import { logger, chalk, isApiOnly } from "@modern-js/utils";
22
22
  import server from "@modern-js/prod-server";
23
23
  import { printInstructions } from "../utils/printInstructions";
24
24
  import { injectDataLoaderPlugin } from "../utils/createServer";
25
+ import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
25
26
  const start = (api) => __async(void 0, null, function* () {
26
27
  var _a;
27
28
  const appContext = api.useAppContext();
@@ -33,11 +34,12 @@ const start = (api) => __async(void 0, null, function* () {
33
34
  appContext.appDirectory,
34
35
  (_a = userConfig == null ? void 0 : userConfig.source) == null ? void 0 : _a.entriesDir
35
36
  );
37
+ const serverInternalPlugins = yield getServerInternalPlugins(api);
36
38
  const app = yield server({
37
39
  pwd: appDirectory,
38
40
  config: userConfig,
39
41
  serverConfigFile,
40
- internalPlugins: injectDataLoaderPlugin(appContext.serverInternalPlugins),
42
+ internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
41
43
  apiOnly
42
44
  });
43
45
  app.listen(port, (err) => __async(void 0, null, function* () {
@@ -1,46 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
1
21
  function createDefaultConfig(appContext) {
2
- const defaultAlias = appContext ? {
3
- [appContext.internalDirAlias]: appContext.internalDirectory,
4
- [appContext.internalSrcAlias]: appContext.srcDirectory,
5
- "@": appContext.srcDirectory,
6
- "@shared": appContext.sharedDirectory
7
- } : {};
8
- const source = {
22
+ const defaultBuilderConfig = createDefaultBuilderConfig();
23
+ const dev = __spreadValues({}, defaultBuilderConfig.dev);
24
+ const tools = __spreadValues({}, defaultBuilderConfig.tools);
25
+ const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
26
+ disableNodePolyfill: true
27
+ });
28
+ const source = __spreadProps(__spreadValues({}, defaultBuilderConfig.source), {
9
29
  entries: void 0,
10
30
  enableAsyncEntry: false,
11
31
  disableDefaultEntries: false,
12
32
  entriesDir: "./src",
13
33
  configDir: "./config",
14
- globalVars: void 0,
15
- moduleScopes: void 0,
16
- include: [],
17
- alias: defaultAlias
18
- };
19
- const output = {
20
- assetPrefix: "/",
21
- distPath: {
22
- html: "html",
23
- js: "static/js",
24
- css: "static/css",
25
- media: "static/media",
26
- root: "dist"
27
- },
28
- copy: void 0,
29
- disableCssModuleExtension: false,
30
- enableCssModuleTSDeclaration: false,
31
- disableMinimize: false,
32
- enableInlineStyles: false,
33
- enableInlineScripts: false,
34
- disableSourceMap: false,
35
- disableInlineRuntimeChunk: false,
36
- disableFilenameHash: false,
37
- enableLatestDecorators: false,
38
- polyfill: "entry",
39
- cssModuleLocalIdentName: void 0
40
- };
41
- const html = {
34
+ alias: {
35
+ [appContext.internalDirAlias]: appContext.internalDirectory,
36
+ [appContext.internalSrcAlias]: appContext.srcDirectory,
37
+ "@": appContext.srcDirectory,
38
+ "@shared": appContext.sharedDirectory
39
+ }
40
+ });
41
+ const html = __spreadProps(__spreadValues({}, defaultBuilderConfig.html), {
42
42
  title: "",
43
- titleByEntries: void 0,
44
43
  meta: {
45
44
  charset: { charset: "utf-8" },
46
45
  viewport: "width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no",
@@ -50,17 +49,8 @@ function createDefaultConfig(appContext) {
50
49
  imagemode: "force",
51
50
  "wap-font-scale": "no",
52
51
  "format-detection": "telephone=no"
53
- },
54
- metaByEntries: void 0,
55
- inject: "head",
56
- injectByEntries: void 0,
57
- mountId: "root",
58
- favicon: "",
59
- faviconByEntries: void 0,
60
- disableHtmlFolder: false,
61
- templateParameters: {},
62
- templateParametersByEntries: void 0
63
- };
52
+ }
53
+ });
64
54
  const server = {
65
55
  routes: void 0,
66
56
  publicRoutes: void 0,
@@ -69,20 +59,6 @@ function createDefaultConfig(appContext) {
69
59
  baseUrl: "/",
70
60
  port: 8080
71
61
  };
72
- const dev = {
73
- assetPrefix: false,
74
- https: false
75
- };
76
- const tools = {
77
- webpack: void 0,
78
- babel: void 0,
79
- postcss: void 0,
80
- autoprefixer: void 0,
81
- devServer: void 0,
82
- tsLoader: void 0,
83
- terser: void 0,
84
- minifyCss: void 0
85
- };
86
62
  return {
87
63
  source,
88
64
  output,
@@ -91,6 +67,7 @@ function createDefaultConfig(appContext) {
91
67
  html,
92
68
  tools,
93
69
  plugins: [],
70
+ builderPlugins: [],
94
71
  runtime: {},
95
72
  runtimeByEntries: {}
96
73
  };
@@ -44,6 +44,7 @@ function createOutputConfig(config) {
44
44
  font: dataUriLimit,
45
45
  media: dataUriLimit
46
46
  },
47
+ cssModuleLocalIdentName,
47
48
  disableCssExtract,
48
49
  disableCssModuleExtension,
49
50
  disableInlineRuntimeChunk,
@@ -56,9 +57,6 @@ function createOutputConfig(config) {
56
57
  polyfill,
57
58
  disableFilenameHash: disableAssetsCache,
58
59
  enableLatestDecorators,
59
- filename: {
60
- css: cssModuleLocalIdentName
61
- },
62
60
  ssg,
63
61
  enableAssetFallback: true,
64
62
  enableAssetManifest: true,
@@ -27,7 +27,11 @@ function createSourceConfig(config) {
27
27
  enableAsyncEntry,
28
28
  disableDefaultEntries,
29
29
  entriesDir,
30
- configDir
30
+ configDir,
31
+ resolveExtensionPrefix: {
32
+ web: ".web",
33
+ node: ".node"
34
+ }
31
35
  };
32
36
  }
33
37
  export {
@@ -31,11 +31,15 @@ function transformNormalizedConfig(config) {
31
31
  server,
32
32
  cliOptions,
33
33
  testing,
34
+ builderPlugins: [],
34
35
  plugins,
35
36
  security: {},
36
37
  _raw: {},
37
38
  experiments: {},
38
- performance: {}
39
+ autoLoadPlugins: true,
40
+ performance: {
41
+ removeMomentLocale: true
42
+ }
39
43
  };
40
44
  }
41
45
  export {
@@ -14,6 +14,7 @@ const hooks = {
14
14
  htmlPartials: createAsyncWaterfall(),
15
15
  beforeGenerateRoutes: createAsyncWaterfall(),
16
16
  addDefineTypes: createAsyncWaterfall(),
17
+ collectServerPlugins: createAsyncWaterfall(),
17
18
  beforeDev: createAsyncWorkflow(),
18
19
  afterDev: createAsyncWorkflow(),
19
20
  beforeCreateCompiler: createAsyncWorkflow(),
@@ -57,7 +57,7 @@ const upgradeModel = Import.lazy(
57
57
  const devCommand = (program, api) => __async(void 0, null, function* () {
58
58
  const runner = api.useHookRunners();
59
59
  const devToolMetas = yield runner.registerDev();
60
- const devProgram = program.command("dev").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).action((options) => __async(void 0, null, function* () {
60
+ const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).action((options) => __async(void 0, null, function* () {
61
61
  const { dev } = yield import("./commands/dev");
62
62
  yield dev(api, options);
63
63
  }));
@@ -108,7 +108,7 @@ var src_default = () => ({
108
108
  "@modern-js/plugin-document",
109
109
  "@modern-js/plugin-state",
110
110
  "@modern-js/plugin-router",
111
- "@modern-js/plugin-router-legacy",
111
+ "@modern-js/plugin-router-v5",
112
112
  "@modern-js/plugin-polyfill"
113
113
  ],
114
114
  registerHook: hooks,
@@ -121,11 +121,11 @@ var src_default = () => ({
121
121
  return __async(this, arguments, function* ({ program }) {
122
122
  yield devCommand(program, api);
123
123
  yield buildCommand(program, api);
124
- program.command("start").usage("[options]").description(i18n.t(localeKeys.command.start.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option(
124
+ program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option(
125
125
  "-c --config <config>",
126
126
  i18n.t(localeKeys.command.shared.config)
127
127
  ).action(() => __async(this, null, function* () {
128
- const { start } = yield import("./commands/start");
128
+ const { start } = yield import("./commands/serve");
129
129
  yield start(api);
130
130
  }));
131
131
  program.command("deploy").usage("[options]").option(
@@ -166,7 +166,7 @@ var src_default = () => ({
166
166
  prepare() {
167
167
  return __async(this, null, function* () {
168
168
  const command = getCommand();
169
- if (command === "dev" || command === "build") {
169
+ if (command === "dev" || command === "start" || command === "build") {
170
170
  const appContext = api.useAppContext();
171
171
  yield emptyDir(appContext.distDirectory);
172
172
  }
@@ -39,7 +39,7 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
  import { ensureAbsolutePath, getPort, isDev } from "@modern-js/utils";
41
41
  import { legacySchema, schema } from "../schema";
42
- import { getCommand } from "../utils/commands";
42
+ import { isDevCommand } from "../utils/commands";
43
43
  import { transformNormalizedConfig } from "../config/initial/transformNormalizedConfig";
44
44
  import {
45
45
  checkIsLegacyConfig,
@@ -92,11 +92,13 @@ var initialize_default = () => ({
92
92
  tools: normalizedConfig.tools || {},
93
93
  testing: normalizedConfig.testing || {},
94
94
  plugins: normalizedConfig.plugins || [],
95
+ builderPlugins: normalizedConfig.builderPlugins || [],
95
96
  runtime: normalizedConfig.runtime || {},
96
97
  runtimeByEntries: normalizedConfig.runtimeByEntries || {},
97
98
  deploy: normalizedConfig.deploy || {},
98
99
  performance: normalizedConfig.performance || {},
99
- experiments: normalizedConfig.experiments || {}
100
+ experiments: normalizedConfig.experiments || {},
101
+ autoLoadPlugins: normalizedConfig.autoLoadPlugins || false
100
102
  }
101
103
  };
102
104
  });
@@ -107,8 +109,7 @@ var initialize_default = () => ({
107
109
  function getDevServerPort(appContext, resolved) {
108
110
  return __async(this, null, function* () {
109
111
  var _a;
110
- const command = getCommand();
111
- if (isDev() && command === "dev") {
112
+ if (isDev() && isDevCommand()) {
112
113
  return ((_a = appContext.port) != null ? _a : 0) > 0 ? appContext.port : yield getPort(resolved.server.port || 8080);
113
114
  }
114
115
  return resolved.server.port;
@@ -12,7 +12,7 @@ const EN_LOCALE = {
12
12
  build: {
13
13
  describe: "build application"
14
14
  },
15
- start: { describe: "start server" },
15
+ serve: { describe: "start server" },
16
16
  deploy: { describe: "deploy application" },
17
17
  new: {
18
18
  describe: "generator runner for MWA project",
@@ -12,7 +12,7 @@ const ZH_LOCALE = {
12
12
  build: {
13
13
  describe: "构建应用命令"
14
14
  },
15
- start: { describe: "应用启动命令" },
15
+ serve: { describe: "应用启动命令" },
16
16
  deploy: { describe: "部署应用命令" },
17
17
  new: {
18
18
  describe: "MWA 项目中执行生成器",
@@ -22,6 +22,7 @@ const source = {
22
22
  enableAsyncEntry: { type: "boolean" },
23
23
  disableDefaultEntries: { type: "boolean" },
24
24
  entriesDir: { type: "string" },
25
+ disableEntryDirs: { type: "array" },
25
26
  configDir: { type: "string" },
26
27
  designSystem: { type: "object" }
27
28
  };
@@ -81,8 +82,9 @@ const tools = {
81
82
  const deploy = {
82
83
  microFrontend: { type: ["boolean", "object"] }
83
84
  };
85
+ const builderPlugins = { type: "array" };
84
86
  const schema = new Schema();
85
- schema.setSchema("bff", bff).setSchema("dev", dev).setSchema("server", server).setSchema("source", source).setSchema("output", output).setSchema("tools", tools).setSchema("deploy", deploy);
87
+ schema.setSchema("bff", bff).setSchema("dev", dev).setSchema("server", server).setSchema("source", source).setSchema("output", output).setSchema("tools", tools).setSchema("deploy", deploy).set("builderPlugin", builderPlugins);
86
88
  import { default as default2 } from "./legacy";
87
89
  export {
88
90
  default2 as legacySchema,
@@ -3,6 +3,11 @@ const getCommand = () => {
3
3
  const command = args[0];
4
4
  return command;
5
5
  };
6
+ const isDevCommand = () => {
7
+ const command = getCommand();
8
+ return command === "dev" || command === "start";
9
+ };
6
10
  export {
7
- getCommand
11
+ getCommand,
12
+ isDevCommand
8
13
  };
@@ -0,0 +1,58 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ function getServerInternalPlugins(api) {
41
+ return __async(this, null, function* () {
42
+ const hookRunners = api.useHookRunners();
43
+ const { plugins: serverPlugins } = yield hookRunners.collectServerPlugins({
44
+ plugins: []
45
+ });
46
+ const serverInternalPlugins = serverPlugins.reduce(
47
+ (result, plugin) => Object.assign(result, plugin),
48
+ {}
49
+ );
50
+ api.setAppContext(__spreadProps(__spreadValues({}, api.useAppContext()), {
51
+ serverInternalPlugins
52
+ }));
53
+ return serverInternalPlugins;
54
+ });
55
+ }
56
+ export {
57
+ getServerInternalPlugins
58
+ };
@@ -15,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var stdin_exports = {};
19
- __export(stdin_exports, {
20
- Builder: () => Builder,
21
- loaderBuilder: () => loaderBuilder,
22
- serverLoaderBuilder: () => serverLoaderBuilder
23
- });
24
- module.exports = __toCommonJS(stdin_exports);
25
- var import_esbuild = require("esbuild");
26
18
  var __async = (__this, __arguments, generator) => {
27
19
  return new Promise((resolve, reject) => {
28
20
  var fulfilled = (value) => {
@@ -43,6 +35,14 @@ var __async = (__this, __arguments, generator) => {
43
35
  step((generator = generator.apply(__this, __arguments)).next());
44
36
  });
45
37
  };
38
+ var Builder_exports = {};
39
+ __export(Builder_exports, {
40
+ Builder: () => Builder,
41
+ loaderBuilder: () => loaderBuilder,
42
+ serverLoaderBuilder: () => serverLoaderBuilder
43
+ });
44
+ module.exports = __toCommonJS(Builder_exports);
45
+ var import_esbuild = require("esbuild");
46
46
  class Builder {
47
47
  build(options) {
48
48
  return __async(this, null, function* () {
@@ -56,3 +56,9 @@ class Builder {
56
56
  }
57
57
  const loaderBuilder = new Builder();
58
58
  const serverLoaderBuilder = new Builder();
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ Builder,
62
+ loaderBuilder,
63
+ serverLoaderBuilder
64
+ });
@@ -15,8 +15,8 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var stdin_exports = {};
19
- __export(stdin_exports, {
18
+ var constants_exports = {};
19
+ __export(constants_exports, {
20
20
  APP_FILE_NAME: () => APP_FILE_NAME,
21
21
  ENTRY_BOOTSTRAP_FILE_NAME: () => ENTRY_BOOTSTRAP_FILE_NAME,
22
22
  ENTRY_POINT_FILE_NAME: () => ENTRY_POINT_FILE_NAME,
@@ -32,11 +32,12 @@ __export(stdin_exports, {
32
32
  INDEX_FILE_NAME: () => INDEX_FILE_NAME,
33
33
  JS_EXTENSIONS: () => JS_EXTENSIONS,
34
34
  LOADER_EXPORT_NAME: () => LOADER_EXPORT_NAME,
35
+ NESTED_ROUTE: () => NESTED_ROUTE,
35
36
  NESTED_ROUTES_DIR: () => NESTED_ROUTES_DIR,
36
37
  PAGES_DIR_NAME: () => PAGES_DIR_NAME,
37
38
  TEMP_LOADERS_DIR: () => TEMP_LOADERS_DIR
38
39
  });
39
- module.exports = __toCommonJS(stdin_exports);
40
+ module.exports = __toCommonJS(constants_exports);
40
41
  const JS_EXTENSIONS = [".js", ".ts", ".jsx", ".tsx"];
41
42
  const INDEX_FILE_NAME = "index";
42
43
  const APP_FILE_NAME = "App";
@@ -55,3 +56,34 @@ const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/
55
56
  const HTML_PARTIALS_FOLDER = "html";
56
57
  const HTML_PARTIALS_EXTENSIONS = [".htm", ".html", ".ejs"];
57
58
  const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
59
+ const NESTED_ROUTE = {
60
+ LAYOUT_FILE: "layout",
61
+ LAYOUT_LOADER_FILE: "layout.loader",
62
+ PAGE_FILE: "page",
63
+ PAGE_LOADER_FILE: "page.loader",
64
+ LOADING_FILE: "loading",
65
+ ERROR_FILE: "error",
66
+ LOADER_FILE: "loader"
67
+ };
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ APP_FILE_NAME,
71
+ ENTRY_BOOTSTRAP_FILE_NAME,
72
+ ENTRY_POINT_FILE_NAME,
73
+ FILE_SYSTEM_ROUTES_COMPONENTS_DIR,
74
+ FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP,
75
+ FILE_SYSTEM_ROUTES_FILE_NAME,
76
+ FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT,
77
+ FILE_SYSTEM_ROUTES_IGNORED_REGEX,
78
+ FILE_SYSTEM_ROUTES_INDEX,
79
+ FILE_SYSTEM_ROUTES_LAYOUT,
80
+ HTML_PARTIALS_EXTENSIONS,
81
+ HTML_PARTIALS_FOLDER,
82
+ INDEX_FILE_NAME,
83
+ JS_EXTENSIONS,
84
+ LOADER_EXPORT_NAME,
85
+ NESTED_ROUTE,
86
+ NESTED_ROUTES_DIR,
87
+ PAGES_DIR_NAME,
88
+ TEMP_LOADERS_DIR
89
+ });