@modern-js/app-tools 2.0.3-alpha.0 → 2.2.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 (64) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/dist/js/modern/analyze/constants.js +1 -1
  3. package/dist/js/modern/analyze/generateCode.js +4 -12
  4. package/dist/js/modern/analyze/index.js +28 -7
  5. package/dist/js/modern/analyze/nestedRoutes.js +5 -1
  6. package/dist/js/modern/analyze/templates.js +15 -17
  7. package/dist/js/modern/analyze/utils.js +2 -19
  8. package/dist/js/modern/builder/index.js +5 -6
  9. package/dist/js/modern/commands/dev.js +1 -23
  10. package/dist/js/modern/config/default.js +3 -1
  11. package/dist/js/modern/hooks.js +0 -2
  12. package/dist/js/modern/index.js +8 -0
  13. package/dist/js/modern/initialize/index.js +7 -7
  14. package/dist/js/modern/locale/en.js +3 -1
  15. package/dist/js/modern/locale/zh.js +3 -1
  16. package/dist/js/modern/utils/generateWatchFiles.js +55 -0
  17. package/dist/js/modern/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +9 -8
  18. package/dist/js/node/analyze/constants.js +1 -1
  19. package/dist/js/node/analyze/generateCode.js +3 -7
  20. package/dist/js/node/analyze/index.js +19 -5
  21. package/dist/js/node/analyze/nestedRoutes.js +5 -1
  22. package/dist/js/node/analyze/templates.js +15 -17
  23. package/dist/js/node/analyze/utils.js +1 -18
  24. package/dist/js/node/builder/index.js +5 -6
  25. package/dist/js/node/commands/dev.js +1 -23
  26. package/dist/js/node/config/default.js +3 -1
  27. package/dist/js/node/hooks.js +0 -2
  28. package/dist/js/node/index.js +8 -0
  29. package/dist/js/node/initialize/index.js +7 -7
  30. package/dist/js/node/locale/en.js +3 -1
  31. package/dist/js/node/locale/zh.js +3 -1
  32. package/dist/js/node/utils/{createFileWatcher.js → generateWatchFiles.js} +12 -66
  33. package/dist/js/node/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +12 -11
  34. package/dist/js/treeshaking/analyze/constants.js +1 -1
  35. package/dist/js/treeshaking/analyze/generateCode.js +5 -8
  36. package/dist/js/treeshaking/analyze/index.js +29 -14
  37. package/dist/js/treeshaking/analyze/nestedRoutes.js +12 -3
  38. package/dist/js/treeshaking/analyze/templates.js +10 -9
  39. package/dist/js/treeshaking/analyze/utils.js +2 -11
  40. package/dist/js/treeshaking/builder/index.js +6 -7
  41. package/dist/js/treeshaking/commands/dev.js +13 -31
  42. package/dist/js/treeshaking/config/default.js +3 -1
  43. package/dist/js/treeshaking/hooks.js +0 -2
  44. package/dist/js/treeshaking/index.js +14 -0
  45. package/dist/js/treeshaking/initialize/index.js +19 -42
  46. package/dist/js/treeshaking/locale/en.js +3 -1
  47. package/dist/js/treeshaking/locale/zh.js +3 -1
  48. package/dist/js/treeshaking/utils/{createFileWatcher.js → generateWatchFiles.js} +16 -85
  49. package/dist/js/treeshaking/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +8 -7
  50. package/dist/types/analyze/constants.d.ts +1 -1
  51. package/dist/types/analyze/templates.d.ts +2 -8
  52. package/dist/types/analyze/utils.d.ts +0 -1
  53. package/dist/types/locale/en.d.ts +2 -0
  54. package/dist/types/locale/index.d.ts +4 -0
  55. package/dist/types/locale/zh.d.ts +2 -0
  56. package/dist/types/types/config/dev.d.ts +1 -1
  57. package/dist/types/types/hooks.d.ts +0 -5
  58. package/dist/types/utils/generateWatchFiles.d.ts +3 -0
  59. package/dist/types/utils/getSelectedEntries.d.ts +6 -0
  60. package/lib/types.d.ts +6 -2
  61. package/package.json +24 -24
  62. package/dist/js/modern/utils/createFileWatcher.js +0 -115
  63. package/dist/types/utils/createFileWatcher.d.ts +0 -4
  64. package/dist/types/utils/getSpecifiedEntries.d.ts +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,112 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 12ef50f: feat: `modern-js/core` can watch files change
8
+ feat: `modern-js/core` 可以监听文件变化
9
+
10
+ ### Patch Changes
11
+
12
+ - 64ade69: fix(app-tools): dev --entry not work
13
+
14
+ fix(app-tools): 修复 dev --entry 参数不生效的问题
15
+
16
+ - 16bdc0a: chore: adjust builder plugin name
17
+
18
+ chore: 调整 builder 插件命名格式
19
+
20
+ - 19bb384: fix: when a child route does not exist, an empty layout should not be created
21
+ fix: 子路由不存在时,不应该创建空的 layout
22
+ - Updated dependencies [f2f8a83]
23
+ - Updated dependencies [cb12ee7]
24
+ - Updated dependencies [49eff0c]
25
+ - Updated dependencies [2d3e3df]
26
+ - Updated dependencies [360a259]
27
+ - Updated dependencies [9fc6de9]
28
+ - Updated dependencies [d82b621]
29
+ - Updated dependencies [16bdc0a]
30
+ - Updated dependencies [12ef50f]
31
+ - Updated dependencies [19bb384]
32
+ - @modern-js/builder-shared@2.2.0
33
+ - @modern-js/builder-webpack-provider@2.2.0
34
+ - @modern-js/core@2.2.0
35
+ - @modern-js/plugin-data-loader@2.2.0
36
+ - @modern-js/utils@2.2.0
37
+ - @modern-js/prod-server@2.2.0
38
+ - @modern-js/server@2.2.0
39
+ - @modern-js/builder@2.2.0
40
+ - @modern-js/builder-plugin-esbuild@2.2.0
41
+ - @modern-js/builder-plugin-node-polyfill@2.2.0
42
+ - @modern-js/types@2.2.0
43
+ - @modern-js/plugin-lint@2.2.0
44
+ - @modern-js/plugin-i18n@2.2.0
45
+ - @modern-js/new-action@2.2.0
46
+ - @modern-js/node-bundle-require@2.2.0
47
+ - @modern-js/upgrade@2.2.0
48
+ - @modern-js/plugin@2.2.0
49
+
50
+ ## 2.1.0
51
+
52
+ ### Patch Changes
53
+
54
+ - 2ad9642: feat: new command support --lang params
55
+
56
+ feat: new 命令支持 --lang 参数
57
+
58
+ - bf38bda: feat(app-tools): allow to use dev.port config
59
+
60
+ feat(app-tools): 支持使用 dev.port 配置
61
+
62
+ - 29fbc66: fix(app-tools): SVG default export type
63
+
64
+ fix(app-tools): 修复 SVG 默认导出的类型错误
65
+
66
+ - 3a7da8c: fix(app-tools): server.port not work in development
67
+
68
+ fix(app-tools): 修复开发环境下 server.port 不生效的问题
69
+
70
+ - 3d0fb38: fix: remove the prebundle for data loader
71
+ fix: 移除 data loader 的预打包
72
+ - 6562578: chore: optimize the capitalization of plugin names
73
+
74
+ chore: 规范引用插件时的命名格式,统一使用 camelCase 代替 PascalCase
75
+
76
+ - 0d2af52: docs: add docs for config and init
77
+ docs: 添加 config 和 init 在嵌套路由下的文档
78
+ - 84ee9e9: fix: can't exit process after build
79
+ fix: 在 build 后不退出程序
80
+ - 5b54418: fix(builder): no longer remove comments of HTML
81
+
82
+ fix(builder): 不再默认移除 HTML 中的注释
83
+
84
+ - Updated dependencies [837620c]
85
+ - Updated dependencies [3d0fb38]
86
+ - Updated dependencies [3ad26c2]
87
+ - Updated dependencies [5b54418]
88
+ - Updated dependencies [bafa52e]
89
+ - Updated dependencies [ccbac43]
90
+ - Updated dependencies [8a9482c]
91
+ - Updated dependencies [679296d]
92
+ - @modern-js/utils@2.1.0
93
+ - @modern-js/plugin-data-loader@2.1.0
94
+ - @modern-js/server@2.1.0
95
+ - @modern-js/builder-shared@2.1.0
96
+ - @modern-js/builder-webpack-provider@2.1.0
97
+ - @modern-js/core@2.1.0
98
+ - @modern-js/builder@2.1.0
99
+ - @modern-js/builder-plugin-esbuild@2.1.0
100
+ - @modern-js/builder-plugin-node-polyfill@2.1.0
101
+ - @modern-js/plugin-i18n@2.1.0
102
+ - @modern-js/plugin-lint@2.1.0
103
+ - @modern-js/new-action@2.1.0
104
+ - @modern-js/prod-server@2.1.0
105
+ - @modern-js/node-bundle-require@2.1.0
106
+ - @modern-js/upgrade@2.1.0
107
+ - @modern-js/plugin@2.1.0
108
+ - @modern-js/types@2.1.0
109
+
3
110
  ## 2.0.2
4
111
 
5
112
  ### Patch Changes
@@ -25,7 +25,7 @@ const NESTED_ROUTE = {
25
25
  ERROR_FILE: "error",
26
26
  LOADER_FILE: "loader"
27
27
  };
28
- const APP_CONFIG_NAME = "appConfig";
28
+ const APP_CONFIG_NAME = "config";
29
29
  const APP_INIT_EXPORTED = "init";
30
30
  const APP_INIT_IMPORTED = "appInit";
31
31
  export {
@@ -19,11 +19,7 @@ var __async = (__this, __arguments, generator) => {
19
19
  });
20
20
  };
21
21
  import path from "path";
22
- import {
23
- fs,
24
- getEntryOptions,
25
- logger
26
- } from "@modern-js/utils";
22
+ import { fs, getEntryOptions, logger } from "@modern-js/utils";
27
23
  import {
28
24
  useResolvedConfigContext
29
25
  } from "@modern-js/core";
@@ -87,7 +83,6 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
87
83
  var _a, _b, _c;
88
84
  const {
89
85
  internalDirectory,
90
- distDirectory,
91
86
  srcDirectory,
92
87
  internalDirAlias,
93
88
  internalSrcAlias,
@@ -168,19 +163,16 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
168
163
  ssrMode: mode,
169
164
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
170
165
  entryName: entrypoint.entryName,
171
- internalDirectory,
172
- internalDirAlias
166
+ internalDirectory
173
167
  })
174
168
  });
175
- if (entrypoint.nestedRoutesEntry) {
169
+ if (entrypoint.nestedRoutesEntry && mode) {
176
170
  const routesServerFile = getServerLoadersFile(
177
171
  internalDirectory,
178
172
  entryName
179
173
  );
180
174
  const code3 = templates.routesForServer({
181
- routes,
182
- internalDirectory,
183
- entryName
175
+ routes
184
176
  });
185
177
  yield fs.ensureFile(routesServerFile);
186
178
  yield fs.writeFile(routesServerFile, code3);
@@ -38,13 +38,21 @@ var __async = (__this, __arguments, generator) => {
38
38
  });
39
39
  };
40
40
  import * as path from "path";
41
- import { createDebugger, findExists, fs, isApiOnly, isUseSSRBundle } from "@modern-js/utils";
41
+ import {
42
+ createDebugger,
43
+ findExists,
44
+ fs,
45
+ getEntryOptions,
46
+ isApiOnly,
47
+ minimist
48
+ } from "@modern-js/utils";
42
49
  import { cloneDeep } from "@modern-js/utils/lodash";
43
50
  import { createBuilderForModern } from "../builder";
44
51
  import { printInstructions } from "../utils/printInstructions";
45
52
  import { generateRoutes } from "../utils/routes";
46
53
  import { emitResolvedConfig } from "../utils/config";
47
- import { getCommand } from "../utils/commands";
54
+ import { getCommand, isDevCommand } from "../utils/commands";
55
+ import { getSelectedEntries } from "../utils/getSelectedEntries";
48
56
  import { initialNormalizedConfig } from "../config";
49
57
  import {
50
58
  getServerLoadersFile,
@@ -104,7 +112,6 @@ var analyze_default = () => ({
104
112
  import("./getHtmlTemplate")
105
113
  ]);
106
114
  const entrypoints = getBundleEntry(appContext, resolvedConfig);
107
- const defaultChecked = entrypoints.map((point) => point.entryName);
108
115
  debug(`entrypoints: %o`, entrypoints);
109
116
  const initialRoutes = getServerRoutes(entrypoints, {
110
117
  appContext,
@@ -130,9 +137,17 @@ var analyze_default = () => ({
130
137
  debug(`html templates: %o`, htmlTemplates);
131
138
  yield hookRunners.addDefineTypes();
132
139
  debug(`add Define Types`);
140
+ let checkedEntries = entrypoints.map((point) => point.entryName);
141
+ if (isDevCommand()) {
142
+ const { entry } = minimist(process.argv.slice(2));
143
+ checkedEntries = yield getSelectedEntries(
144
+ typeof entry === "string" ? entry.split(",") : entry,
145
+ entrypoints
146
+ );
147
+ }
133
148
  appContext = __spreadProps(__spreadValues({}, appContext), {
134
149
  entrypoints,
135
- checkedEntries: defaultChecked,
150
+ checkedEntries,
136
151
  apiOnly,
137
152
  serverRoutes: routes,
138
153
  htmlTemplates
@@ -209,13 +224,19 @@ var analyze_default = () => ({
209
224
  config() {
210
225
  return {
211
226
  tools: {
212
- webpackChain: (chain, { name, CHAIN_ID }) => {
227
+ webpackChain: (chain, { name }) => {
213
228
  const appContext = api.useAppContext();
214
229
  const resolvedConfig = api.useResolvedConfigContext();
215
- const { entrypoints, internalDirectory } = appContext;
230
+ const { entrypoints, internalDirectory, packageName } = appContext;
216
231
  entrypoints.forEach((entrypoint) => {
217
232
  const { entryName } = entrypoint;
218
- if (entrypoint.nestedRoutesEntry && isUseSSRBundle(resolvedConfig)) {
233
+ const ssr = getEntryOptions(
234
+ entryName,
235
+ resolvedConfig.server.ssr,
236
+ resolvedConfig.server.ssrByEntries,
237
+ packageName
238
+ );
239
+ if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
219
240
  const serverLoadersFile = getServerLoadersFile(
220
241
  internalDirectory,
221
242
  entryName
@@ -64,7 +64,7 @@ const createRoute = (routeInfo, rootDir, filename, entryName) => {
64
64
  });
65
65
  };
66
66
  const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, function* () {
67
- var _a, _b;
67
+ var _a, _b, _c;
68
68
  if (!(yield fs.pathExists(dirname))) {
69
69
  return null;
70
70
  }
@@ -146,6 +146,10 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
146
146
  if (isPathlessLayout) {
147
147
  delete finalRoute.path;
148
148
  }
149
+ route.children = (_c = route.children) == null ? void 0 : _c.filter((childRoute) => childRoute);
150
+ if (route.children && route.children.length === 0 && !route.index) {
151
+ return null;
152
+ }
149
153
  return finalRoute;
150
154
  });
151
155
  export {
@@ -72,7 +72,7 @@ const renderFunction = ({
72
72
  return `
73
73
  const finalAppConfig = {
74
74
  ...App.config,
75
- ...typeof ${APP_CONFIG_NAME} === 'object' ? ${APP_CONFIG_NAME} : {},
75
+ ...typeof ${APP_CONFIG_NAME} === 'function' ? ${APP_CONFIG_NAME}() : {},
76
76
  }
77
77
 
78
78
  AppWrapper = createApp({
@@ -127,17 +127,9 @@ const html = (partials) => `
127
127
  </html>
128
128
  `;
129
129
  const routesForServer = ({
130
- routes,
131
- internalDirectory,
132
- entryName
130
+ routes
133
131
  }) => {
134
132
  const loaders = [];
135
- const loaderIndexFile = path.join(
136
- internalDirectory,
137
- entryName,
138
- TEMP_LOADERS_DIR,
139
- "index.js"
140
- );
141
133
  const traverseRouteTree = (route) => {
142
134
  var _a;
143
135
  let children;
@@ -176,7 +168,7 @@ const routesForServer = ({
176
168
  let importLoadersCode = "";
177
169
  if (loaders.length > 0) {
178
170
  importLoadersCode = loaders.map((loader, index2) => {
179
- return `import loader_${index2} from "${loader}"`;
171
+ return `import loader_${index2} from "${slash(loader)}"`;
180
172
  }).join("\n");
181
173
  }
182
174
  return `
@@ -189,8 +181,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
189
181
  ssrMode,
190
182
  nestedRoutesEntry,
191
183
  entryName,
192
- internalDirectory,
193
- internalDirAlias
184
+ internalDirectory
194
185
  }) {
195
186
  const loadings = [];
196
187
  const errors = [];
@@ -209,11 +200,14 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
209
200
  let rootLayoutCode = ``;
210
201
  let componentLoaderPath = "";
211
202
  const getDataLoaderPath = (loaderId) => {
212
- if (!ssrMode)
203
+ if (!ssrMode) {
213
204
  return "";
205
+ }
214
206
  let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
215
207
  if (nestedRoutesEntry) {
216
- dataLoaderPath = `${slash(dataLoaderPath)}?mapFile=${slash(loadersMapFile)}&loaderId=${loaderId}!`;
208
+ dataLoaderPath = `${slash(dataLoaderPath)}?mapFile=${slash(
209
+ loadersMapFile
210
+ )}&loaderId=${loaderId}!`;
217
211
  }
218
212
  return dataLoaderPath;
219
213
  };
@@ -309,10 +303,14 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
309
303
  let importLoadersCode = "";
310
304
  for (const [key, loaderInfo] of Object.entries(loadersMap)) {
311
305
  if (loaderInfo.inline) {
312
- importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(key)}${loaderInfo.filePath}";
306
+ importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
307
+ key
308
+ )}${slash(loaderInfo.filePath)}";
313
309
  `;
314
310
  } else {
315
- importLoadersCode += `import ${key} from "${getDataLoaderPath(key)}${loaderInfo.filePath}";
311
+ importLoadersCode += `import ${key} from "${getDataLoaderPath(
312
+ key
313
+ )}${slash(loaderInfo.filePath)}";
316
314
  `;
317
315
  }
318
316
  }
@@ -26,8 +26,7 @@ import { parse } from "es-module-lexer";
26
26
  import {
27
27
  FILE_SYSTEM_ROUTES_FILE_NAME,
28
28
  JS_EXTENSIONS,
29
- LOADER_EXPORT_NAME,
30
- NESTED_ROUTE
29
+ LOADER_EXPORT_NAME
31
30
  } from "./constants";
32
31
  const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) => {
33
32
  const filePath = path.join(dir, filename);
@@ -105,17 +104,6 @@ const isPageComponentFile = (filePath) => {
105
104
  }
106
105
  return false;
107
106
  };
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
- };
119
107
  const replaceWithAlias = (base, filePath, alias) => normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
120
108
  const parseModule = (_0) => __async(void 0, [_0], function* ({
121
109
  source,
@@ -140,17 +128,12 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
140
128
  return moduleExports.some((e) => e.n === LOADER_EXPORT_NAME);
141
129
  });
142
130
  const getServerLoadersFile = (internalDirectory, entryName) => {
143
- return path.join(
144
- internalDirectory,
145
- entryName,
146
- "route-server-loaders.js"
147
- );
131
+ return path.join(internalDirectory, entryName, "route-server-loaders.js");
148
132
  };
149
133
  export {
150
134
  getDefaultImports,
151
135
  getServerLoadersFile,
152
136
  hasLoader,
153
- isNestedRouteComponent,
154
137
  isPageComponentFile,
155
138
  parseModule,
156
139
  replaceWithAlias,
@@ -87,7 +87,6 @@ function createBuilderForModern(_0) {
87
87
  });
88
88
  }
89
89
  function createBuilderProviderConfig(normalizedConfig, appContext) {
90
- var _a;
91
90
  const output = createOutputConfig(normalizedConfig, appContext);
92
91
  const htmlConfig = __spreadValues({}, normalizedConfig.html);
93
92
  if (!htmlConfig.template) {
@@ -96,7 +95,7 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
96
95
  return __spreadProps(__spreadValues({}, normalizedConfig), {
97
96
  output,
98
97
  dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
99
- port: (_a = normalizedConfig.server) == null ? void 0 : _a.port
98
+ port: appContext.port
100
99
  }),
101
100
  html: htmlConfig
102
101
  });
@@ -135,14 +134,14 @@ function createBuilderOptions(target, appContext) {
135
134
  function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
136
135
  return __async(this, null, function* () {
137
136
  if (!normalizedConfig.output.disableNodePolyfill) {
138
- const { PluginNodePolyfill } = yield import("@modern-js/builder-plugin-node-polyfill");
139
- builder.addPlugins([PluginNodePolyfill()]);
137
+ const { builderPluginNodePolyfill } = yield import("@modern-js/builder-plugin-node-polyfill");
138
+ builder.addPlugins([builderPluginNodePolyfill()]);
140
139
  }
141
140
  if (normalizedConfig.tools.esbuild) {
142
141
  const { esbuild: esbuildOptions } = normalizedConfig.tools;
143
- const { PluginEsbuild } = yield import("@modern-js/builder-plugin-esbuild");
142
+ const { builderPluginEsbuild } = yield import("@modern-js/builder-plugin-esbuild");
144
143
  builder.addPlugins([
145
- PluginEsbuild({
144
+ builderPluginEsbuild({
146
145
  loader: false,
147
146
  minimize: applyOptionsChain({}, esbuildOptions)
148
147
  })
@@ -38,7 +38,6 @@ var __async = (__this, __arguments, generator) => {
38
38
  });
39
39
  };
40
40
  import { ResolvedConfigContext } from "@modern-js/core";
41
- import { createFileWatcher } from "../utils/createFileWatcher";
42
41
  import { printInstructions } from "../utils/printInstructions";
43
42
  import {
44
43
  setServer,
@@ -46,7 +45,6 @@ import {
46
45
  injectDataLoaderPlugin
47
46
  } from "../utils/createServer";
48
47
  import { generateRoutes } from "../utils/routes";
49
- import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
50
48
  import { buildServerConfig } from "../utils/config";
51
49
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
52
50
  const dev = (api, options) => __async(void 0, null, function* () {
@@ -59,22 +57,7 @@ const dev = (api, options) => __async(void 0, null, function* () {
59
57
  const hookRunners = api.useHookRunners();
60
58
  normalizedConfig = __spreadProps(__spreadValues({}, normalizedConfig), { cliOptions: options });
61
59
  ResolvedConfigContext.set(normalizedConfig);
62
- const {
63
- appDirectory,
64
- distDirectory,
65
- port,
66
- apiOnly,
67
- entrypoints,
68
- serverConfigFile
69
- } = appContext;
70
- const checkedEntries = yield getSpecifiedEntries(
71
- options.entry || false,
72
- entrypoints
73
- );
74
- api.setAppContext(__spreadProps(__spreadValues({}, appContext), {
75
- checkedEntries
76
- }));
77
- appContext.checkedEntries = checkedEntries;
60
+ const { appDirectory, distDirectory, port, apiOnly, serverConfigFile } = appContext;
78
61
  yield buildServerConfig({
79
62
  appDirectory,
80
63
  distDirectory,
@@ -120,11 +103,6 @@ const dev = (api, options) => __async(void 0, null, function* () {
120
103
  });
121
104
  setServer(server);
122
105
  }
123
- yield createFileWatcher(
124
- appContext,
125
- normalizedConfig.source.configDir,
126
- hookRunners
127
- );
128
106
  });
129
107
  export {
130
108
  dev
@@ -20,7 +20,9 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
21
21
  function createDefaultConfig(appContext) {
22
22
  const defaultBuilderConfig = createDefaultBuilderConfig();
23
- const dev = __spreadValues({}, defaultBuilderConfig.dev);
23
+ const dev = __spreadProps(__spreadValues({}, defaultBuilderConfig.dev), {
24
+ port: void 0
25
+ });
24
26
  const tools = __spreadValues({}, defaultBuilderConfig.tools);
25
27
  const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
26
28
  disableNodePolyfill: true
@@ -24,8 +24,6 @@ const hooks = {
24
24
  afterBuild: createAsyncWorkflow(),
25
25
  beforeDeploy: createAsyncWorkflow(),
26
26
  afterDeploy: createAsyncWorkflow(),
27
- watchFiles: createParallelWorkflow(),
28
- fileChange: createAsyncWorkflow(),
29
27
  beforeRestart: createAsyncWorkflow(),
30
28
  registerDev: createParallelWorkflow(),
31
29
  beforeDevTask: createParallelWorkflow(),
@@ -48,6 +48,7 @@ import { i18n, localeKeys } from "./locale";
48
48
  import { getLocaleLanguage } from "./utils/language";
49
49
  import { getCommand } from "./utils/commands";
50
50
  import { restart } from "./utils/restart";
51
+ import { generateWatchFiles } from "./utils/generateWatchFiles";
51
52
  export * from "./defineConfig";
52
53
  export * from "./types";
53
54
  const upgradeModel = Import.lazy(
@@ -171,6 +172,13 @@ var src_default = () => ({
171
172
  }
172
173
  });
173
174
  },
175
+ watchFiles() {
176
+ return __async(this, null, function* () {
177
+ const appContext = api.useAppContext();
178
+ const config = api.useResolvedConfigContext();
179
+ return generateWatchFiles(appContext, config.source.configDir);
180
+ });
181
+ },
174
182
  fileChange(e) {
175
183
  return __async(this, null, function* () {
176
184
  const { filename, eventType } = e;
@@ -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 {
@@ -7,7 +7,9 @@ const EN_LOCALE = {
7
7
  dev: {
8
8
  describe: "start dev server",
9
9
  entry: "compiler by entry",
10
- apiOnly: "start api server only"
10
+ apiOnly: "start api server only",
11
+ selectEntry: "Please select the entry that needs to be built",
12
+ requireEntry: "You must choose at least one entry"
11
13
  },
12
14
  build: {
13
15
  describe: "build application"
@@ -7,7 +7,9 @@ const ZH_LOCALE = {
7
7
  dev: {
8
8
  describe: "本地开发命令",
9
9
  entry: "指定入口,编译特定的页面",
10
- apiOnly: "仅启动 API 接口服务"
10
+ apiOnly: "仅启动 API 接口服务",
11
+ selectEntry: "请选择需要构建的入口",
12
+ requireEntry: "请至少选择一个入口"
11
13
  },
12
14
  build: {
13
15
  describe: "构建应用命令"
@@ -0,0 +1,55 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import path from "path";
22
+ import { fs, getServerConfig } from "@modern-js/utils";
23
+ const getPackageConfig = (appDirectory, packageJsonConfig) => {
24
+ const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
25
+ const json = JSON.parse(
26
+ fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8")
27
+ );
28
+ return json[packageJsonConfig != null ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
29
+ };
30
+ const addServerConfigToDeps = (dependencies, appDirectory, serverConfigFile) => __async(void 0, null, function* () {
31
+ const serverConfig = yield getServerConfig(appDirectory, serverConfigFile);
32
+ if (serverConfig) {
33
+ dependencies.push(serverConfig);
34
+ }
35
+ });
36
+ function generateWatchFiles(appContext, configDir) {
37
+ return __async(this, null, function* () {
38
+ const { appDirectory, configFile } = appContext;
39
+ const configPath = path.join(appDirectory, configDir || "");
40
+ const dependencies = getPackageConfig(
41
+ appContext.appDirectory,
42
+ appContext.packageName
43
+ ) ? [path.resolve(appDirectory, "./package.json")] : [];
44
+ yield addServerConfigToDeps(
45
+ dependencies,
46
+ appContext.appDirectory,
47
+ appContext.serverConfigFile
48
+ );
49
+ return [`${configPath}/html`, configFile || "./config", ...dependencies];
50
+ });
51
+ }
52
+ export {
53
+ addServerConfigToDeps,
54
+ generateWatchFiles
55
+ };