@modern-js/app-tools 2.1.0 → 2.2.1-alpha.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 (52) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/js/modern/analyze/constants.js +2 -1
  3. package/dist/js/modern/analyze/index.js +14 -4
  4. package/dist/js/modern/analyze/nestedRoutes.js +17 -1
  5. package/dist/js/modern/builder/index.js +4 -4
  6. package/dist/js/modern/commands/dev.js +1 -23
  7. package/dist/js/modern/hooks.js +0 -2
  8. package/dist/js/modern/index.js +14 -2
  9. package/dist/js/modern/initialize/index.js +6 -2
  10. package/dist/js/modern/locale/en.js +3 -1
  11. package/dist/js/modern/locale/zh.js +3 -1
  12. package/dist/js/modern/utils/generateWatchFiles.js +55 -0
  13. package/dist/js/modern/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +9 -8
  14. package/dist/js/node/analyze/constants.js +2 -1
  15. package/dist/js/node/analyze/index.js +11 -4
  16. package/dist/js/node/analyze/nestedRoutes.js +17 -1
  17. package/dist/js/node/builder/index.js +4 -4
  18. package/dist/js/node/commands/dev.js +1 -23
  19. package/dist/js/node/hooks.js +0 -2
  20. package/dist/js/node/index.js +9 -2
  21. package/dist/js/node/initialize/index.js +1 -2
  22. package/dist/js/node/locale/en.js +3 -1
  23. package/dist/js/node/locale/zh.js +3 -1
  24. package/dist/js/node/utils/{createFileWatcher.js → generateWatchFiles.js} +12 -66
  25. package/dist/js/node/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +12 -11
  26. package/dist/js/treeshaking/analyze/constants.js +2 -1
  27. package/dist/js/treeshaking/analyze/index.js +24 -11
  28. package/dist/js/treeshaking/analyze/nestedRoutes.js +20 -3
  29. package/dist/js/treeshaking/builder/index.js +5 -5
  30. package/dist/js/treeshaking/commands/dev.js +13 -31
  31. package/dist/js/treeshaking/hooks.js +0 -2
  32. package/dist/js/treeshaking/index.js +15 -2
  33. package/dist/js/treeshaking/initialize/index.js +1 -2
  34. package/dist/js/treeshaking/locale/en.js +3 -1
  35. package/dist/js/treeshaking/locale/zh.js +3 -1
  36. package/dist/js/treeshaking/utils/{createFileWatcher.js → generateWatchFiles.js} +16 -85
  37. package/dist/js/treeshaking/utils/{getSpecifiedEntries.js → getSelectedEntries.js} +8 -7
  38. package/dist/types/analyze/constants.d.ts +1 -0
  39. package/dist/types/locale/en.d.ts +2 -0
  40. package/dist/types/locale/index.d.ts +4 -0
  41. package/dist/types/locale/zh.d.ts +2 -0
  42. package/dist/types/types/hooks.d.ts +0 -5
  43. package/dist/types/utils/generateWatchFiles.d.ts +3 -0
  44. package/dist/types/utils/getSelectedEntries.d.ts +6 -0
  45. package/package.json +24 -24
  46. package/dist/js/modern/utils/commands.js +0 -13
  47. package/dist/js/modern/utils/createFileWatcher.js +0 -115
  48. package/dist/js/node/utils/commands.js +0 -37
  49. package/dist/js/treeshaking/utils/commands.js +0 -10
  50. package/dist/types/utils/commands.d.ts +0 -2
  51. package/dist/types/utils/createFileWatcher.d.ts +0 -4
  52. package/dist/types/utils/getSpecifiedEntries.d.ts +0 -2
@@ -41,20 +41,18 @@ var __async = (__this, __arguments, generator) => {
41
41
  step((generator = generator.apply(__this, __arguments)).next());
42
42
  });
43
43
  };
44
- var createFileWatcher_exports = {};
45
- __export(createFileWatcher_exports, {
44
+ var generateWatchFiles_exports = {};
45
+ __export(generateWatchFiles_exports, {
46
46
  addServerConfigToDeps: () => addServerConfigToDeps,
47
- createFileWatcher: () => createFileWatcher
47
+ generateWatchFiles: () => generateWatchFiles
48
48
  });
49
- module.exports = __toCommonJS(createFileWatcher_exports);
50
- var import_crypto = __toESM(require("crypto"));
51
- var import_fs = __toESM(require("fs"));
49
+ module.exports = __toCommonJS(generateWatchFiles_exports);
52
50
  var import_path = __toESM(require("path"));
53
51
  var import_utils = require("@modern-js/utils");
54
52
  const getPackageConfig = (appDirectory, packageJsonConfig) => {
55
53
  const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
56
54
  const json = JSON.parse(
57
- import_fs.default.readFileSync(import_path.default.resolve(appDirectory, "./package.json"), "utf8")
55
+ import_utils.fs.readFileSync(import_path.default.resolve(appDirectory, "./package.json"), "utf8")
58
56
  );
59
57
  return json[packageJsonConfig != null ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
60
58
  };
@@ -64,14 +62,10 @@ const addServerConfigToDeps = (dependencies, appDirectory, serverConfigFile) =>
64
62
  dependencies.push(serverConfig);
65
63
  }
66
64
  });
67
- const debug = (0, import_utils.createDebugger)("watch-files");
68
- const md5 = (data) => import_crypto.default.createHash("md5").update(data).digest("hex");
69
- const hashMap = /* @__PURE__ */ new Map();
70
- const createFileWatcher = (appContext, configDir, hooksRunner) => __async(void 0, null, function* () {
71
- if ((0, import_utils.isDev)() || (0, import_utils.isTest)()) {
65
+ function generateWatchFiles(appContext, configDir) {
66
+ return __async(this, null, function* () {
72
67
  const { appDirectory, configFile } = appContext;
73
- const extraFiles = yield hooksRunner.watchFiles();
74
- const configPath = import_path.default.join(appDirectory, configDir);
68
+ const configPath = import_path.default.join(appDirectory, configDir || "");
75
69
  const dependencies = getPackageConfig(
76
70
  appContext.appDirectory,
77
71
  appContext.packageName
@@ -81,59 +75,11 @@ const createFileWatcher = (appContext, configDir, hooksRunner) => __async(void 0
81
75
  appContext.appDirectory,
82
76
  appContext.serverConfigFile
83
77
  );
84
- const watched = [
85
- `${configPath}/html`,
86
- ...extraFiles,
87
- ...dependencies,
88
- configFile
89
- ].filter(Boolean);
90
- debug(`watched: %o`, watched);
91
- const watcher = import_utils.chokidar.watch(watched, {
92
- cwd: appDirectory,
93
- ignoreInitial: true,
94
- ignorePermissionErrors: true,
95
- ignored: [
96
- /node_modules/,
97
- "**/__test__/**",
98
- "**/*.test.(js|jsx|ts|tsx)",
99
- "**/*.spec.(js|jsx|ts|tsx)",
100
- "**/*.stories.(js|jsx|ts|tsx)"
101
- ]
102
- });
103
- watcher.on("change", (changed) => {
104
- const lastHash = hashMap.get(changed);
105
- const currentHash = md5(
106
- import_fs.default.readFileSync(import_path.default.join(appDirectory, changed), "utf8")
107
- );
108
- if (currentHash !== lastHash) {
109
- debug(`file change: %s`, changed);
110
- hashMap.set(changed, currentHash);
111
- hooksRunner.fileChange({ filename: changed, eventType: "change" });
112
- }
113
- });
114
- watcher.on("add", (name) => {
115
- debug(`add file: %s`, name);
116
- const currentHash = md5(
117
- import_fs.default.readFileSync(import_path.default.join(appDirectory, name), "utf8")
118
- );
119
- hashMap.set(name, currentHash);
120
- hooksRunner.fileChange({ filename: name, eventType: "add" });
121
- });
122
- watcher.on("unlink", (name) => {
123
- debug(`remove file: %s`, name);
124
- if (hashMap.has(name)) {
125
- hashMap.delete(name);
126
- }
127
- hooksRunner.fileChange({ filename: name, eventType: "unlink" });
128
- });
129
- watcher.on("error", (err) => {
130
- throw err;
131
- });
132
- return watcher;
133
- }
134
- });
78
+ return [`${configPath}/html`, configFile || "./config", ...dependencies];
79
+ });
80
+ }
135
81
  // Annotate the CommonJS export names for ESM import in node:
136
82
  0 && (module.exports = {
137
83
  addServerConfigToDeps,
138
- createFileWatcher
84
+ generateWatchFiles
139
85
  });
@@ -35,13 +35,14 @@ var __async = (__this, __arguments, generator) => {
35
35
  step((generator = generator.apply(__this, __arguments)).next());
36
36
  });
37
37
  };
38
- var getSpecifiedEntries_exports = {};
39
- __export(getSpecifiedEntries_exports, {
40
- getSpecifiedEntries: () => getSpecifiedEntries
38
+ var getSelectedEntries_exports = {};
39
+ __export(getSelectedEntries_exports, {
40
+ getSelectedEntries: () => getSelectedEntries
41
41
  });
42
- module.exports = __toCommonJS(getSpecifiedEntries_exports);
42
+ module.exports = __toCommonJS(getSelectedEntries_exports);
43
43
  var import_utils = require("@modern-js/utils");
44
- const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, function* () {
44
+ var import_locale = require("../locale");
45
+ const getSelectedEntries = (entry, entrypoints) => __async(void 0, null, function* () {
45
46
  const entryNames = entrypoints.map((e) => e.entryName);
46
47
  if (!entry) {
47
48
  return entryNames;
@@ -52,10 +53,10 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
52
53
  type: "checkbox",
53
54
  name: "selected",
54
55
  choices: entryNames,
55
- message: "请选择需要构建的入口",
56
+ message: import_locale.i18n.t(import_locale.localeKeys.command.dev.selectEntry),
56
57
  validate(answer) {
57
58
  if (answer.length < 1) {
58
- return "You must choose at least one topping.";
59
+ return import_locale.i18n.t(import_locale.localeKeys.command.dev.requireEntry);
59
60
  }
60
61
  return true;
61
62
  }
@@ -66,9 +67,9 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
66
67
  entry.forEach((name) => {
67
68
  if (!entryNames.includes(name)) {
68
69
  throw new Error(
69
- `can not found entry ${name}, compiler entry should in ${entryNames.join(
70
- ", "
71
- )}`
70
+ `Can not found entry ${import_utils.chalk.yellow(
71
+ name
72
+ )}, the entry should be one of ${import_utils.chalk.yellow(entryNames.join(", "))}`
72
73
  );
73
74
  }
74
75
  });
@@ -76,5 +77,5 @@ const getSpecifiedEntries = (entry, entrypoints) => __async(void 0, null, functi
76
77
  });
77
78
  // Annotate the CommonJS export names for ESM import in node:
78
79
  0 && (module.exports = {
79
- getSpecifiedEntries
80
+ getSelectedEntries
80
81
  });
@@ -32,7 +32,8 @@ var NESTED_ROUTE = {
32
32
  PAGE_LOADER_FILE: "page.loader",
33
33
  LOADING_FILE: "loading",
34
34
  ERROR_FILE: "error",
35
- LOADER_FILE: "loader"
35
+ LOADER_FILE: "loader",
36
+ SPLATE_FILE: "$"
36
37
  };
37
38
  var APP_CONFIG_NAME = "config";
38
39
  var APP_INIT_EXPORTED = "init";
@@ -221,13 +221,13 @@ var __generator = this && this.__generator || function(thisArg, body) {
221
221
  }
222
222
  };
223
223
  import * as path from "path";
224
- import { createDebugger, findExists, fs, getEntryOptions, isApiOnly } from "@modern-js/utils";
224
+ import { createDebugger, findExists, fs, getEntryOptions, isApiOnly, minimist, getCommand, isDevCommand } from "@modern-js/utils";
225
225
  import { cloneDeep } from "@modern-js/utils/lodash";
226
226
  import { createBuilderForModern } from "../builder";
227
227
  import { printInstructions } from "../utils/printInstructions";
228
228
  import { generateRoutes } from "../utils/routes";
229
229
  import { emitResolvedConfig } from "../utils/config";
230
- import { getCommand } from "../utils/commands";
230
+ import { getSelectedEntries } from "../utils/getSelectedEntries";
231
231
  import { initialNormalizedConfig } from "../config";
232
232
  import { getServerLoadersFile, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
233
233
  import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
@@ -242,7 +242,7 @@ var analyze_default = function() {
242
242
  return {
243
243
  prepare: function prepare() {
244
244
  return _asyncToGenerator(function() {
245
- var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, defaultChecked, initialRoutes, routes, htmlTemplates, command, buildCommands, normalizedConfig, builder;
245
+ var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes, htmlTemplates, checkedEntries, entry, command, buildCommands, normalizedConfig, builder;
246
246
  return __generator(this, function(_state) {
247
247
  switch(_state.label){
248
248
  case 0:
@@ -301,9 +301,6 @@ var analyze_default = function() {
301
301
  4
302
302
  ]), getBundleEntry = ref2[0].getBundleEntry, getServerRoutes = ref2[1].getServerRoutes, generateCode = ref2[2].generateCode, getHtmlTemplate = ref2[3].getHtmlTemplate;
303
303
  entrypoints = getBundleEntry(appContext, resolvedConfig);
304
- defaultChecked = entrypoints.map(function(point) {
305
- return point.entryName;
306
- });
307
304
  debug("entrypoints: %o", entrypoints);
308
305
  initialRoutes = getServerRoutes(entrypoints, {
309
306
  appContext: appContext,
@@ -353,9 +350,25 @@ var analyze_default = function() {
353
350
  case 9:
354
351
  _state.sent();
355
352
  debug("add Define Types");
353
+ checkedEntries = entrypoints.map(function(point) {
354
+ return point.entryName;
355
+ });
356
+ if (!isDevCommand()) return [
357
+ 3,
358
+ 11
359
+ ];
360
+ entry = minimist(process.argv.slice(2)).entry;
361
+ return [
362
+ 4,
363
+ getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
364
+ ];
365
+ case 10:
366
+ checkedEntries = _state.sent();
367
+ _state.label = 11;
368
+ case 11:
356
369
  appContext = _objectSpreadProps(_objectSpread({}, appContext), {
357
370
  entrypoints: entrypoints,
358
- checkedEntries: defaultChecked,
371
+ checkedEntries: checkedEntries,
359
372
  apiOnly: apiOnly,
360
373
  serverRoutes: routes,
361
374
  htmlTemplates: htmlTemplates
@@ -371,7 +384,7 @@ var analyze_default = function() {
371
384
  ];
372
385
  if (!buildCommands.includes(command)) return [
373
386
  3,
374
- 11
387
+ 13
375
388
  ];
376
389
  normalizedConfig = api.useResolvedConfigContext();
377
390
  return [
@@ -505,15 +518,15 @@ var analyze_default = function() {
505
518
  }
506
519
  })
507
520
  ];
508
- case 10:
521
+ case 12:
509
522
  builder = _state.sent();
510
523
  builder.addPlugins(resolvedConfig.builderPlugins);
511
524
  appContext = _objectSpreadProps(_objectSpread({}, appContext), {
512
525
  builder: builder
513
526
  });
514
527
  api.setAppContext(appContext);
515
- _state.label = 11;
516
- case 11:
528
+ _state.label = 13;
529
+ case 13:
517
530
  return [
518
531
  2
519
532
  ];
@@ -197,7 +197,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
197
197
  };
198
198
  var walk = function() {
199
199
  var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
200
- var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref, ref1, err, finalRoute;
200
+ var ref, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref1, ref2, ref3, splatRoute, err, finalRoute;
201
201
  return __generator(this, function(_state) {
202
202
  switch(_state.label){
203
203
  case 0:
@@ -286,7 +286,7 @@ var walk = function() {
286
286
  childRoute = _state.sent();
287
287
  if (childRoute) {
288
288
  ;
289
- (ref = route.children) === null || ref === void 0 ? void 0 : ref.push(childRoute);
289
+ (ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(childRoute);
290
290
  }
291
291
  _state.label = 8;
292
292
  case 8:
@@ -315,7 +315,15 @@ var walk = function() {
315
315
  if (pageLoaderFile) {
316
316
  pageRoute.loader = pageLoaderFile;
317
317
  }
318
- (ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(pageRoute);
318
+ (ref2 = route.children) === null || ref2 === void 0 ? void 0 : ref2.push(pageRoute);
319
+ }
320
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_FILE) {
321
+ ;
322
+ splatRoute = createRoute({
323
+ _component: replaceWithAlias(alias.basename, itemPath, alias.name),
324
+ path: "*"
325
+ }, rootDir, itemPath, entryName);
326
+ (ref3 = route.children) === null || ref3 === void 0 ? void 0 : ref3.push(splatRoute);
319
327
  }
320
328
  if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
321
329
  route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
@@ -361,6 +369,15 @@ var walk = function() {
361
369
  if (isPathlessLayout) {
362
370
  delete finalRoute.path;
363
371
  }
372
+ route.children = (ref = route.children) === null || ref === void 0 ? void 0 : ref.filter(function(childRoute) {
373
+ return childRoute;
374
+ });
375
+ if (route.children && route.children.length === 0 && !route.index) {
376
+ return [
377
+ 2,
378
+ null
379
+ ];
380
+ }
364
381
  return [
365
382
  2,
366
383
  finalRoute
@@ -322,7 +322,7 @@ function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPlugin
322
322
  }
323
323
  function _applyBuilderPlugins() {
324
324
  _applyBuilderPlugins = _asyncToGenerator(function(builder, normalizedConfig, appContext, compatPluginConfig) {
325
- var PluginNodePolyfill, _tools, esbuildOptions, PluginEsbuild;
325
+ var builderPluginNodePolyfill, _tools, esbuildOptions, builderPluginEsbuild;
326
326
  return __generator(this, function(_state) {
327
327
  switch(_state.label){
328
328
  case 0:
@@ -335,9 +335,9 @@ function _applyBuilderPlugins() {
335
335
  import("@modern-js/builder-plugin-node-polyfill")
336
336
  ];
337
337
  case 1:
338
- PluginNodePolyfill = _state.sent().PluginNodePolyfill;
338
+ builderPluginNodePolyfill = _state.sent().builderPluginNodePolyfill;
339
339
  builder.addPlugins([
340
- PluginNodePolyfill()
340
+ builderPluginNodePolyfill()
341
341
  ]);
342
342
  _state.label = 2;
343
343
  case 2:
@@ -351,9 +351,9 @@ function _applyBuilderPlugins() {
351
351
  import("@modern-js/builder-plugin-esbuild")
352
352
  ];
353
353
  case 3:
354
- PluginEsbuild = _state.sent().PluginEsbuild;
354
+ builderPluginEsbuild = _state.sent().builderPluginEsbuild;
355
355
  builder.addPlugins([
356
- PluginEsbuild({
356
+ builderPluginEsbuild({
357
357
  loader: false,
358
358
  minimize: applyOptionsChain({}, esbuildOptions)
359
359
  })
@@ -175,16 +175,14 @@ var __generator = this && this.__generator || function(thisArg, body) {
175
175
  }
176
176
  };
177
177
  import { ResolvedConfigContext } from "@modern-js/core";
178
- import { createFileWatcher } from "../utils/createFileWatcher";
179
178
  import { printInstructions } from "../utils/printInstructions";
180
179
  import { setServer, createServer, injectDataLoaderPlugin } from "../utils/createServer";
181
180
  import { generateRoutes } from "../utils/routes";
182
- import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
183
181
  import { buildServerConfig } from "../utils/config";
184
182
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
185
183
  var dev = function() {
186
184
  var _ref = _asyncToGenerator(function(api, options) {
187
- var ref, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, entrypoints, serverConfigFile, checkedEntries, serverInternalPlugins, serverOptions, app, server;
185
+ var ref, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, serverInternalPlugins, serverOptions, app, server;
188
186
  return __generator(this, function(_state) {
189
187
  switch(_state.label){
190
188
  case 0:
@@ -198,17 +196,7 @@ var dev = function() {
198
196
  cliOptions: options
199
197
  });
200
198
  ResolvedConfigContext.set(normalizedConfig);
201
- appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, entrypoints = appContext.entrypoints, serverConfigFile = appContext.serverConfigFile;
202
- return [
203
- 4,
204
- getSpecifiedEntries(options.entry || false, entrypoints)
205
- ];
206
- case 1:
207
- checkedEntries = _state.sent();
208
- api.setAppContext(_objectSpreadProps(_objectSpread({}, appContext), {
209
- checkedEntries: checkedEntries
210
- }));
211
- appContext.checkedEntries = checkedEntries;
199
+ appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile;
212
200
  return [
213
201
  4,
214
202
  buildServerConfig({
@@ -222,13 +210,13 @@ var dev = function() {
222
210
  }
223
211
  })
224
212
  ];
225
- case 2:
213
+ case 1:
226
214
  _state.sent();
227
215
  return [
228
216
  4,
229
217
  hookRunners.beforeDev()
230
218
  ];
231
- case 3:
219
+ case 2:
232
220
  _state.sent();
233
221
  if (!appContext.builder && !apiOnly) {
234
222
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
@@ -237,13 +225,13 @@ var dev = function() {
237
225
  4,
238
226
  generateRoutes(appContext)
239
227
  ];
240
- case 4:
228
+ case 3:
241
229
  _state.sent();
242
230
  return [
243
231
  4,
244
232
  getServerInternalPlugins(api)
245
233
  ];
246
- case 5:
234
+ case 4:
247
235
  serverInternalPlugins = _state.sent();
248
236
  serverOptions = {
249
237
  dev: _objectSpread({
@@ -257,7 +245,7 @@ var dev = function() {
257
245
  };
258
246
  if (!apiOnly) return [
259
247
  3,
260
- 7
248
+ 6
261
249
  ];
262
250
  return [
263
251
  4,
@@ -265,7 +253,7 @@ var dev = function() {
265
253
  compiler: null
266
254
  }))
267
255
  ];
268
- case 6:
256
+ case 5:
269
257
  app = _state.sent();
270
258
  app.listen(port, function() {
271
259
  var _ref = _asyncToGenerator(function(err) {
@@ -285,9 +273,9 @@ var dev = function() {
285
273
  }());
286
274
  return [
287
275
  3,
288
- 9
276
+ 8
289
277
  ];
290
- case 7:
278
+ case 6:
291
279
  return [
292
280
  4,
293
281
  appContext.builder.startDevServer({
@@ -295,17 +283,11 @@ var dev = function() {
295
283
  serverOptions: serverOptions
296
284
  })
297
285
  ];
298
- case 8:
286
+ case 7:
299
287
  server = _state.sent().server;
300
288
  setServer(server);
301
- _state.label = 9;
302
- case 9:
303
- return [
304
- 4,
305
- createFileWatcher(appContext, normalizedConfig.source.configDir, hookRunners)
306
- ];
307
- case 10:
308
- _state.sent();
289
+ _state.label = 8;
290
+ case 8:
309
291
  return [
310
292
  2
311
293
  ];
@@ -20,8 +20,6 @@ var hooks = {
20
20
  afterBuild: createAsyncWorkflow(),
21
21
  beforeDeploy: createAsyncWorkflow(),
22
22
  afterDeploy: createAsyncWorkflow(),
23
- watchFiles: createParallelWorkflow(),
24
- fileChange: createAsyncWorkflow(),
25
23
  beforeRestart: createAsyncWorkflow(),
26
24
  registerDev: createParallelWorkflow(),
27
25
  beforeDevTask: createParallelWorkflow(),
@@ -176,15 +176,15 @@ var __generator = this && this.__generator || function(thisArg, body) {
176
176
  };
177
177
  import path from "path";
178
178
  import lintPlugin from "@modern-js/plugin-lint";
179
- import { cleanRequireCache, emptyDir, Import } from "@modern-js/utils";
179
+ import { cleanRequireCache, emptyDir, Import, getCommand } from "@modern-js/utils";
180
180
  import { castArray } from "@modern-js/utils/lodash";
181
181
  import analyzePlugin from "./analyze";
182
182
  import initializePlugin from "./initialize";
183
183
  import { hooks } from "./hooks";
184
184
  import { i18n, localeKeys } from "./locale";
185
185
  import { getLocaleLanguage } from "./utils/language";
186
- import { getCommand } from "./utils/commands";
187
186
  import { restart } from "./utils/restart";
187
+ import { generateWatchFiles } from "./utils/generateWatchFiles";
188
188
  export * from "./defineConfig";
189
189
  export * from "./types";
190
190
  var upgradeModel = Import.lazy("@modern-js/upgrade", require);
@@ -633,6 +633,19 @@ var src_default = function() {
633
633
  });
634
634
  })();
635
635
  },
636
+ watchFiles: function watchFiles() {
637
+ return _asyncToGenerator(function() {
638
+ var appContext, config;
639
+ return __generator(this, function(_state) {
640
+ appContext = api.useAppContext();
641
+ config = api.useResolvedConfigContext();
642
+ return [
643
+ 2,
644
+ generateWatchFiles(appContext, config.source.configDir)
645
+ ];
646
+ });
647
+ })();
648
+ },
636
649
  fileChange: function fileChange(e) {
637
650
  return _asyncToGenerator(function() {
638
651
  var filename, eventType, appContext, appDirectory, srcDirectory, absolutePath, closeServer;
@@ -174,9 +174,8 @@ var __generator = this && this.__generator || function(thisArg, body) {
174
174
  };
175
175
  }
176
176
  };
177
- import { ensureAbsolutePath, getPort, isDev } from "@modern-js/utils";
177
+ import { ensureAbsolutePath, getPort, isDev, isDevCommand } from "@modern-js/utils";
178
178
  import { legacySchema, schema } from "../schema";
179
- import { isDevCommand } from "../utils/commands";
180
179
  import { transformNormalizedConfig } from "../config/initial/transformNormalizedConfig";
181
180
  import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig } from "../config";
182
181
  var initialize_default = function() {
@@ -7,7 +7,9 @@ var 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 @@ var 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: "构建应用命令"