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

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 (151) hide show
  1. package/CHANGELOG.md +366 -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/getBundleEntry.js +2 -1
  6. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +9 -6
  7. package/dist/js/modern/analyze/getFileSystemEntry.js +11 -3
  8. package/dist/js/modern/analyze/index.js +7 -5
  9. package/dist/js/modern/analyze/nestedRoutes.js +29 -22
  10. package/dist/js/modern/analyze/templates.js +8 -1
  11. package/dist/js/modern/analyze/utils.js +21 -4
  12. package/dist/js/modern/builder/builderPlugins/compatModern.js +8 -2
  13. package/dist/js/modern/builder/index.js +9 -9
  14. package/dist/js/modern/commands/dev.js +6 -9
  15. package/dist/js/modern/commands/index.js +1 -1
  16. package/dist/js/modern/commands/{start.js → serve.js} +3 -1
  17. package/dist/js/modern/config/default.js +38 -61
  18. package/dist/js/modern/config/initial/createOutputConfig.js +1 -3
  19. package/dist/js/modern/config/initial/createSourceConfig.js +5 -1
  20. package/dist/js/modern/config/initial/transformNormalizedConfig.js +5 -1
  21. package/dist/js/modern/hooks.js +1 -0
  22. package/dist/js/modern/index.js +5 -5
  23. package/dist/js/modern/initialize/index.js +5 -4
  24. package/dist/js/modern/locale/en.js +1 -1
  25. package/dist/js/modern/locale/zh.js +1 -1
  26. package/dist/js/modern/schema/index.js +5 -7
  27. package/dist/js/modern/schema/legacy.js +1 -2
  28. package/dist/js/modern/utils/commands.js +6 -1
  29. package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
  30. package/dist/js/node/analyze/Builder.js +14 -8
  31. package/dist/js/node/analyze/constants.js +35 -3
  32. package/dist/js/node/analyze/generateCode.js +27 -24
  33. package/dist/js/node/analyze/getBundleEntry.js +9 -4
  34. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +33 -28
  35. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +24 -22
  36. package/dist/js/node/analyze/getClientRoutes/index.js +8 -3
  37. package/dist/js/node/analyze/getClientRoutes/utils.js +10 -3
  38. package/dist/js/node/analyze/getFileSystemEntry.js +18 -6
  39. package/dist/js/node/analyze/getHtmlTemplate.js +18 -14
  40. package/dist/js/node/analyze/getServerRoutes.js +36 -34
  41. package/dist/js/node/analyze/index.js +45 -59
  42. package/dist/js/node/analyze/isDefaultExportFunction.js +7 -3
  43. package/dist/js/node/analyze/makeLegalIdentifier.js +7 -3
  44. package/dist/js/node/analyze/nestedRoutes.js +58 -49
  45. package/dist/js/node/analyze/templates.js +45 -32
  46. package/dist/js/node/analyze/utils.js +41 -18
  47. package/dist/js/node/builder/builderPlugins/compatModern.js +32 -24
  48. package/dist/js/node/builder/index.js +38 -49
  49. package/dist/js/node/builder/loaders/routerLoader.js +5 -3
  50. package/dist/js/node/builder/loaders/serverModuleLoader.js +5 -3
  51. package/dist/js/node/builder/share.js +7 -3
  52. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +7 -3
  53. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +7 -3
  54. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +9 -7
  55. package/dist/js/node/commands/build.js +30 -28
  56. package/dist/js/node/commands/deploy.js +9 -5
  57. package/dist/js/node/commands/dev.js +39 -40
  58. package/dist/js/node/commands/index.js +5 -5
  59. package/dist/js/node/commands/inspect.js +10 -6
  60. package/dist/js/node/commands/{start.js → serve.js} +16 -10
  61. package/dist/js/node/config/default.js +44 -64
  62. package/dist/js/node/config/index.js +10 -3
  63. package/dist/js/node/config/initial/createHtmlConfig.js +7 -3
  64. package/dist/js/node/config/initial/createOutputConfig.js +8 -6
  65. package/dist/js/node/config/initial/createSourceConfig.js +12 -4
  66. package/dist/js/node/config/initial/createToolsConfig.js +7 -3
  67. package/dist/js/node/config/initial/index.js +9 -3
  68. package/dist/js/node/config/initial/inits.js +26 -22
  69. package/dist/js/node/config/initial/transformNormalizedConfig.js +12 -4
  70. package/dist/js/node/defineConfig.js +25 -22
  71. package/dist/js/node/exports/server.js +7 -3
  72. package/dist/js/node/hooks.js +8 -3
  73. package/dist/js/node/index.js +56 -69
  74. package/dist/js/node/initialize/index.js +33 -32
  75. package/dist/js/node/locale/en.js +8 -4
  76. package/dist/js/node/locale/index.js +8 -3
  77. package/dist/js/node/locale/zh.js +8 -4
  78. package/dist/js/node/schema/Schema.js +7 -3
  79. package/dist/js/node/schema/index.js +13 -10
  80. package/dist/js/node/schema/legacy.js +6 -5
  81. package/dist/js/node/types/config/deploy.js +15 -0
  82. package/dist/js/node/types/config/dev.js +15 -0
  83. package/dist/js/node/types/config/experiments.js +15 -0
  84. package/dist/js/node/types/config/html.js +15 -0
  85. package/dist/js/node/types/config/index.js +3 -3
  86. package/dist/js/node/types/config/output.js +15 -0
  87. package/dist/js/node/types/config/performance.js +15 -0
  88. package/dist/js/node/types/config/security.js +15 -0
  89. package/dist/js/node/types/config/source.js +15 -0
  90. package/dist/js/node/types/config/tools.js +15 -0
  91. package/dist/js/node/types/hooks.js +15 -0
  92. package/dist/js/node/types/index.js +5 -5
  93. package/dist/js/node/types/legacyConfig/deploy.js +15 -0
  94. package/dist/js/node/types/legacyConfig/dev.js +15 -0
  95. package/dist/js/node/types/legacyConfig/index.js +15 -0
  96. package/dist/js/node/types/legacyConfig/output.js +15 -0
  97. package/dist/js/node/types/legacyConfig/source.js +15 -0
  98. package/dist/js/node/types/legacyConfig/tools.js +15 -0
  99. package/dist/js/node/utils/commands.js +14 -4
  100. package/dist/js/node/utils/config.js +35 -30
  101. package/dist/js/node/utils/createFileWatcher.js +15 -10
  102. package/dist/js/node/utils/createServer.js +35 -29
  103. package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
  104. package/dist/js/node/utils/getSpecifiedEntries.js +10 -6
  105. package/dist/js/node/utils/language.js +7 -3
  106. package/dist/js/node/utils/printInstructions.js +10 -6
  107. package/dist/js/node/utils/restart.js +11 -7
  108. package/dist/js/node/utils/routes.js +11 -7
  109. package/dist/js/node/utils/types.js +15 -0
  110. package/dist/js/treeshaking/analyze/constants.js +10 -1
  111. package/dist/js/treeshaking/analyze/generateCode.js +7 -11
  112. package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -1
  113. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +9 -6
  114. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +11 -3
  115. package/dist/js/treeshaking/analyze/index.js +7 -4
  116. package/dist/js/treeshaking/analyze/nestedRoutes.js +30 -23
  117. package/dist/js/treeshaking/analyze/templates.js +6 -1
  118. package/dist/js/treeshaking/analyze/utils.js +14 -4
  119. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +6 -2
  120. package/dist/js/treeshaking/builder/index.js +4 -9
  121. package/dist/js/treeshaking/commands/dev.js +19 -24
  122. package/dist/js/treeshaking/commands/index.js +1 -1
  123. package/dist/js/treeshaking/commands/{start.js → serve.js} +10 -3
  124. package/dist/js/treeshaking/config/default.js +53 -56
  125. package/dist/js/treeshaking/config/initial/createOutputConfig.js +1 -3
  126. package/dist/js/treeshaking/config/initial/createSourceConfig.js +5 -1
  127. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +5 -1
  128. package/dist/js/treeshaking/hooks.js +1 -0
  129. package/dist/js/treeshaking/index.js +5 -5
  130. package/dist/js/treeshaking/initialize/index.js +6 -5
  131. package/dist/js/treeshaking/locale/en.js +1 -1
  132. package/dist/js/treeshaking/locale/zh.js +1 -1
  133. package/dist/js/treeshaking/schema/index.js +10 -11
  134. package/dist/js/treeshaking/schema/legacy.js +0 -3
  135. package/dist/js/treeshaking/utils/commands.js +5 -1
  136. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
  137. package/dist/types/analyze/constants.d.ts +10 -1
  138. package/dist/types/analyze/utils.d.ts +2 -1
  139. package/dist/types/commands/index.d.ts +1 -1
  140. package/dist/types/commands/{start.d.ts → serve.d.ts} +0 -0
  141. package/dist/types/index.d.ts +1 -0
  142. package/dist/types/locale/en.d.ts +1 -1
  143. package/dist/types/locale/index.d.ts +2 -2
  144. package/dist/types/locale/zh.d.ts +1 -1
  145. package/dist/types/types/config/index.d.ts +3 -0
  146. package/dist/types/types/config/source.d.ts +2 -1
  147. package/dist/types/types/hooks.d.ts +3 -0
  148. package/dist/types/types/legacyConfig/source.d.ts +0 -1
  149. package/dist/types/utils/commands.d.ts +2 -1
  150. package/dist/types/utils/getServerInternalPlugins.d.ts +2 -0
  151. package/package.json +25 -22
@@ -39,20 +39,9 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
  import * as path from "path";
41
41
  import { fs, getRouteId } from "@modern-js/utils";
42
- import { JS_EXTENSIONS } from "./constants";
42
+ import { JS_EXTENSIONS, NESTED_ROUTE } from "./constants";
43
43
  import { hasLoader, replaceWithAlias } from "./utils";
44
- const LAYOUT_FILE = "layout";
45
- const PAGE_FILE = "page";
46
- const LOADING_FILE = "loading";
47
- const ERROR_FILE = "error";
48
- const LOADER_FILE = "loader";
49
- const conventionNames = [
50
- LAYOUT_FILE,
51
- PAGE_FILE,
52
- LOADING_FILE,
53
- ERROR_FILE,
54
- LOADER_FILE
55
- ];
44
+ const conventionNames = Object.values(NESTED_ROUTE);
56
45
  const getLoaderPath = (filename) => __async(void 0, null, function* () {
57
46
  if (yield hasLoader(filename)) {
58
47
  return filename;
@@ -105,6 +94,8 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
105
94
  children: [],
106
95
  isRoot
107
96
  };
97
+ let pageLoaderFile = "";
98
+ let pageRoute = null;
108
99
  const items = yield fs.readdir(dirname);
109
100
  for (const item of items) {
110
101
  const itemPath = path.join(dirname, item);
@@ -120,12 +111,23 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
120
111
  if (extname && (!JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
121
112
  continue;
122
113
  }
123
- if (itemWithoutExt === LAYOUT_FILE) {
114
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_LOADER_FILE) {
115
+ if (!route.loader) {
116
+ route.loader = itemPath;
117
+ }
118
+ }
119
+ if (itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE) {
124
120
  route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
125
- route.loader = yield getLoaderPath(itemPath);
121
+ const loaderPath = yield getLoaderPath(itemPath);
122
+ if (loaderPath) {
123
+ route.loader = loaderPath;
124
+ }
126
125
  }
127
- if (itemWithoutExt === PAGE_FILE) {
128
- const childRoute = createIndexRoute(
126
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
127
+ pageLoaderFile = itemPath;
128
+ }
129
+ if (itemWithoutExt === NESTED_ROUTE.PAGE_FILE) {
130
+ pageRoute = createIndexRoute(
129
131
  {
130
132
  _component: replaceWithAlias(alias.basename, itemPath, alias.name)
131
133
  },
@@ -133,20 +135,25 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
133
135
  itemPath,
134
136
  entryName
135
137
  );
136
- childRoute.loader = yield getLoaderPath(itemPath);
137
- (_b = route.children) == null ? void 0 : _b.push(childRoute);
138
+ const loaderPath = yield getLoaderPath(itemPath);
139
+ if (loaderPath) {
140
+ pageRoute.loader = loaderPath;
141
+ } else if (pageLoaderFile) {
142
+ pageRoute.loader = pageLoaderFile;
143
+ }
144
+ (_b = route.children) == null ? void 0 : _b.push(pageRoute);
138
145
  }
139
- if (itemWithoutExt === LOADING_FILE) {
146
+ if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
140
147
  route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
141
148
  }
142
- if (itemWithoutExt === ERROR_FILE) {
149
+ if (itemWithoutExt === NESTED_ROUTE.ERROR_FILE) {
143
150
  route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
144
151
  }
145
152
  }
146
153
  const finalRoute = createRoute(
147
154
  route,
148
155
  rootDir,
149
- path.join(dirname, `${LAYOUT_FILE}.ts`),
156
+ path.join(dirname, `${NESTED_ROUTE.LAYOUT_FILE}.ts`),
150
157
  entryName
151
158
  );
152
159
  if (isPathlessLayout) {
@@ -315,9 +315,16 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
315
315
  TEMP_LOADERS_DIR,
316
316
  `${name}.js`
317
317
  );
318
- const code = `
318
+ let code = "";
319
+ if (loader.includes(".loader.")) {
320
+ code = `
321
+ export { default as ${name} } from '${slash(loader)}'
322
+ `;
323
+ } else {
324
+ code = `
319
325
  export { loader as ${name} } from '${slash(loader)}'
320
326
  `;
327
+ }
321
328
  yield fs.ensureFile(filename);
322
329
  yield fs.writeFile(filename, code);
323
330
  }))
@@ -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()) {
@@ -55,6 +59,7 @@ const getDefaultImports = ({
55
59
  },
56
60
  customBootstrap && {
57
61
  specifiers: [{ local: "customBootstrap" }],
62
+ initialize: "const App = false;",
58
63
  value: normalizeToPosixPath(
59
64
  customBootstrap.replace(srcDirectory, internalSrcAlias)
60
65
  )
@@ -81,7 +86,7 @@ const getDefaultImports = ({
81
86
  route.initialize = "const App = false;";
82
87
  }
83
88
  imports.push(route);
84
- } else {
89
+ } else if (!customBootstrap) {
85
90
  imports.push({
86
91
  specifiers: [{ local: "App" }],
87
92
  value: normalizeToPosixPath(
@@ -91,7 +96,7 @@ const getDefaultImports = ({
91
96
  }
92
97
  return imports;
93
98
  };
94
- const isRouteComponentFile = (filePath) => {
99
+ const isPageComponentFile = (filePath) => {
95
100
  if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
96
101
  return false;
97
102
  }
@@ -100,6 +105,17 @@ const isRouteComponentFile = (filePath) => {
100
105
  }
101
106
  return false;
102
107
  };
108
+ const isNestedRouteComponent = (nestedRouteEntries, absoluteFilePath) => {
109
+ const reg = new RegExp(
110
+ `(${NESTED_ROUTE.LAYOUT_FILE}|${NESTED_ROUTE.PAGE_FILE}})\\.tsx?$`
111
+ );
112
+ return nestedRouteEntries.some((nestedRoutesEntry) => {
113
+ if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
114
+ return true;
115
+ }
116
+ return false;
117
+ });
118
+ };
103
119
  const replaceWithAlias = (base, filePath, alias) => normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
104
120
  const parseModule = (_0) => __async(void 0, [_0], function* ({
105
121
  source,
@@ -126,7 +142,8 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
126
142
  export {
127
143
  getDefaultImports,
128
144
  hasLoader,
129
- isRouteComponentFile,
145
+ isNestedRouteComponent,
146
+ isPageComponentFile,
130
147
  parseModule,
131
148
  replaceWithAlias,
132
149
  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;
@@ -43,14 +43,20 @@ import {
43
43
  import {
44
44
  builderWebpackProvider
45
45
  } from "@modern-js/builder-webpack-provider";
46
- import { applyOptionsChain, isUseSSRBundle } from "@modern-js/utils";
46
+ import {
47
+ applyOptionsChain,
48
+ isProd,
49
+ isSSR,
50
+ isUseSSRBundle
51
+ } from "@modern-js/utils";
47
52
  import {
48
53
  PluginCompatModern
49
54
  } from "./builderPlugins/compatModern";
50
55
  import { createCopyPattern } from "./share";
51
56
  function getBuilderTargets(normalizedConfig) {
52
57
  const targets = ["web"];
53
- if (isUseSSRBundle(normalizedConfig)) {
58
+ const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
59
+ if (useNodeTarget) {
54
60
  targets.push("node");
55
61
  }
56
62
  return targets;
@@ -88,17 +94,11 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
88
94
  htmlConfig.templateByEntries = __spreadValues(__spreadValues({}, htmlConfig.templateByEntries), appContext.htmlTemplates);
89
95
  }
90
96
  return __spreadProps(__spreadValues({}, normalizedConfig), {
91
- source: __spreadProps(__spreadValues({}, normalizedConfig.source), {
92
- resolveExtensionPrefix: ".web"
93
- }),
94
97
  output,
95
98
  dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
96
99
  port: (_a = normalizedConfig.server) == null ? void 0 : _a.port
97
100
  }),
98
- html: htmlConfig,
99
- performance: __spreadProps(__spreadValues({}, normalizedConfig.performance), {
100
- removeMomentLocale: true
101
- })
101
+ html: htmlConfig
102
102
  });
103
103
  function createOutputConfig(config, appContext2) {
104
104
  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 项目中执行生成器",
@@ -11,7 +11,7 @@ const source = {
11
11
  properties: {
12
12
  entry: { type: ["string", "array"] },
13
13
  disableMount: { type: "boolean" },
14
- enableFileSystemRoutes: { type: "boolean" }
14
+ customBootstrap: { type: "string" }
15
15
  },
16
16
  additionalProperties: false
17
17
  },
@@ -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
  };
@@ -40,11 +41,7 @@ const output = {
40
41
  ssg: { typeof: ["boolean", "object", "function"] },
41
42
  disableNodePolyfill: { type: "boolean" }
42
43
  };
43
- const dev = {
44
- proxy: {
45
- type: ["boolean", "object"]
46
- }
47
- };
44
+ const dev = {};
48
45
  const server = {
49
46
  routes: { type: "object" },
50
47
  publicRoutes: { type: "object" },
@@ -81,8 +78,9 @@ const tools = {
81
78
  const deploy = {
82
79
  microFrontend: { type: ["boolean", "object"] }
83
80
  };
81
+ const builderPlugins = { type: "array" };
84
82
  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);
83
+ 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
84
  import { default as default2 } from "./legacy";
87
85
  export {
88
86
  default2 as legacySchema,