@modern-js/app-tools 3.9.1 → 3.9.3

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 (45) hide show
  1. package/dist/cjs/commands/build.js +1 -2
  2. package/dist/cjs/commands/deploy.js +1 -3
  3. package/dist/cjs/commands/index.js +4 -0
  4. package/dist/cjs/compat/hooks.js +1 -1
  5. package/dist/cjs/index.js +27 -57
  6. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +1 -1
  7. package/dist/cjs/plugins/analyze/getServerRoutes.js +1 -1
  8. package/dist/cjs/plugins/analyze/index.js +2 -2
  9. package/dist/cjs/plugins/analyze/utils.js +4 -5
  10. package/dist/cjs/plugins/initialize/index.js +3 -4
  11. package/dist/esm/commands/build.mjs +1 -2
  12. package/dist/esm/commands/deploy.mjs +1 -3
  13. package/dist/esm/commands/index.mjs +4 -0
  14. package/dist/esm/compat/hooks.mjs +1 -1
  15. package/dist/esm/index.mjs +2 -12
  16. package/dist/esm/plugins/analyze/getFileSystemEntry.mjs +1 -1
  17. package/dist/esm/plugins/analyze/getServerRoutes.mjs +1 -1
  18. package/dist/esm/plugins/analyze/index.mjs +2 -2
  19. package/dist/esm/plugins/analyze/utils.mjs +4 -5
  20. package/dist/esm/plugins/initialize/index.mjs +3 -4
  21. package/dist/esm-node/commands/build.mjs +1 -2
  22. package/dist/esm-node/commands/deploy.mjs +1 -3
  23. package/dist/esm-node/commands/index.mjs +4 -0
  24. package/dist/esm-node/compat/hooks.mjs +1 -1
  25. package/dist/esm-node/index.mjs +2 -12
  26. package/dist/esm-node/plugins/analyze/getFileSystemEntry.mjs +1 -1
  27. package/dist/esm-node/plugins/analyze/getServerRoutes.mjs +1 -1
  28. package/dist/esm-node/plugins/analyze/index.mjs +2 -2
  29. package/dist/esm-node/plugins/analyze/utils.mjs +4 -5
  30. package/dist/esm-node/plugins/initialize/index.mjs +3 -4
  31. package/dist/types/index.d.ts +1 -3
  32. package/dist/types/plugins/analyze/utils.d.ts +1 -1
  33. package/docs/configure/app/output/disable-svgr.md +4 -0
  34. package/docs/configure/app/output/svg-default-export.md +4 -0
  35. package/docs/configure/app/tools/less.md +94 -19
  36. package/docs/configure/app/tools/sass.md +87 -18
  37. package/docs/configure/app/tools/svgr.md +89 -0
  38. package/docs/guides/basic-features/static-assets/svg-assets.md +29 -17
  39. package/docs/llms.txt +3 -2
  40. package/docs/plugin/introduction.md +10 -10
  41. package/package.json +16 -16
  42. package/dist/cjs/plugins/serverRuntime.js +0 -53
  43. package/dist/esm/plugins/serverRuntime.mjs +0 -15
  44. package/dist/esm-node/plugins/serverRuntime.mjs +0 -16
  45. package/dist/types/plugins/serverRuntime.d.ts +0 -3
@@ -98,10 +98,9 @@ const build = async (api, options)=>{
98
98
  utils_namespaceObject.logger.info('Starting production build...');
99
99
  if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
100
100
  await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
101
- const buildResult = await appContext.builder.build({
101
+ await appContext.builder.build({
102
102
  watch: options?.watch
103
103
  });
104
- if (!options?.watch) await buildResult?.close();
105
104
  };
106
105
  exports.build = __webpack_exports__.build;
107
106
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -31,12 +31,10 @@ __webpack_require__.d(__webpack_exports__, {
31
31
  deploy: ()=>deploy
32
32
  });
33
33
  const loadPlugins_js_namespaceObject = require("../utils/loadPlugins.js");
34
- const external_build_js_namespaceObject = require("./build.js");
35
34
  const deploy = async (api, options = {})=>{
36
35
  const hooks = api.getHooks();
37
36
  const { metaName } = api.getAppContext();
38
- if (options.skipBuild) await (0, loadPlugins_js_namespaceObject.getServerPlugins)(api, metaName);
39
- else await (0, external_build_js_namespaceObject.build)(api);
37
+ await (0, loadPlugins_js_namespaceObject.getServerPlugins)(api, metaName);
40
38
  await hooks.onBeforeDeploy.call(options);
41
39
  await hooks.deploy.call();
42
40
  await hooks.onAfterDeploy.call(options);
@@ -56,6 +56,10 @@ const serverCommand = (program, api)=>{
56
56
  };
57
57
  const deployCommand = (program, api)=>{
58
58
  program.command('deploy').usage('[options]').option('-c --config <config>', index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.shared.config)).option('-s --skip-build', index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.shared.skipBuild)).description(index_js_namespaceObject.i18n.t(index_js_namespaceObject.localeKeys.command.deploy.describe)).action(async (options)=>{
59
+ if (!options.skipBuild) {
60
+ const { build } = await import("./build.js");
61
+ await build(api);
62
+ }
59
63
  const { deploy } = await import("./deploy.js");
60
64
  await deploy(api, options);
61
65
  process.exit(0);
@@ -92,7 +92,7 @@ function handleSetupResult(setupResult, api) {
92
92
  if (newAPI && api[newAPI]) api[newAPI](async (...params)=>{
93
93
  const { isMultiple, params: transformParams } = (0, external_utils_js_namespaceObject.transformHookParams)(key, params);
94
94
  if (isMultiple) return (0, external_utils_js_namespaceObject.transformHookResult)(key, await fn(...transformParams));
95
- return (0, external_utils_js_namespaceObject.transformHookResult)(key, await fn(transformParams));
95
+ else return (0, external_utils_js_namespaceObject.transformHookResult)(key, await fn(transformParams));
96
96
  });
97
97
  }
98
98
  });
package/dist/cjs/index.js CHANGED
@@ -1,11 +1,5 @@
1
1
  "use strict";
2
2
  var __webpack_modules__ = {
3
- "./commands/build" (module) {
4
- module.exports = require("./commands/build.js");
5
- },
6
- "./commands/deploy" (module) {
7
- module.exports = require("./commands/deploy.js");
8
- },
9
3
  "./commands/dev" (module) {
10
4
  module.exports = require("./commands/dev.js");
11
5
  },
@@ -39,9 +33,6 @@ var __webpack_modules__ = {
39
33
  "./plugins/serverBuild" (module) {
40
34
  module.exports = require("./plugins/serverBuild.js");
41
35
  },
42
- "./plugins/serverRuntime" (module) {
43
- module.exports = require("./plugins/serverRuntime.js");
44
- },
45
36
  "./rsbuild" (module) {
46
37
  module.exports = require("./rsbuild.js");
47
38
  },
@@ -144,14 +135,12 @@ var __webpack_exports__ = {};
144
135
  var _plugins_initialize__rspack_import_11_default = /*#__PURE__*/ __webpack_require__.n(_plugins_initialize__rspack_import_11);
145
136
  var _plugins_serverBuild__rspack_import_12 = __webpack_require__("./plugins/serverBuild");
146
137
  var _plugins_serverBuild__rspack_import_12_default = /*#__PURE__*/ __webpack_require__.n(_plugins_serverBuild__rspack_import_12);
147
- var _plugins_serverRuntime__rspack_import_13 = __webpack_require__("./plugins/serverRuntime");
148
- var _plugins_serverRuntime__rspack_import_13_default = /*#__PURE__*/ __webpack_require__.n(_plugins_serverRuntime__rspack_import_13);
149
- var _utils_generateWatchFiles__rspack_import_14 = __webpack_require__("./utils/generateWatchFiles");
150
- var _utils_initAppContext__rspack_import_15 = __webpack_require__("./utils/initAppContext");
151
- var _utils_restart__rspack_import_16 = __webpack_require__("./utils/restart");
152
- var _defineConfig__rspack_import_17 = __webpack_require__("./defineConfig");
138
+ var _utils_generateWatchFiles__rspack_import_13 = __webpack_require__("./utils/generateWatchFiles");
139
+ var _utils_initAppContext__rspack_import_14 = __webpack_require__("./utils/initAppContext");
140
+ var _utils_restart__rspack_import_15 = __webpack_require__("./utils/restart");
141
+ var _defineConfig__rspack_import_16 = __webpack_require__("./defineConfig");
153
142
  var __rspack_reexport = {};
154
- for(const __rspack_import_key in _defineConfig__rspack_import_17)if ([
143
+ for(const __rspack_import_key in _defineConfig__rspack_import_16)if ([
155
144
  "dev",
156
145
  "resolveModernRsbuildConfig",
157
146
  "mergeConfig",
@@ -160,21 +149,17 @@ var __webpack_exports__ = {};
160
149
  "serve",
161
150
  "generateWatchFiles",
162
151
  "initAppContext",
163
- "deploy",
164
152
  "defineConfig",
165
- "build",
166
153
  "closeServer"
167
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_defineConfig__rspack_import_17[__rspack_import_key];
154
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_defineConfig__rspack_import_16[__rspack_import_key];
168
155
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
169
- var _commands_build__rspack_import_18 = __webpack_require__("./commands/build");
170
- var _commands_deploy__rspack_import_19 = __webpack_require__("./commands/deploy");
171
- var _commands_dev__rspack_import_20 = __webpack_require__("./commands/dev");
172
- var _commands_serve__rspack_import_21 = __webpack_require__("./commands/serve");
173
- var _utils_createServer__rspack_import_22 = __webpack_require__("./utils/createServer");
174
- var _rsbuild__rspack_import_23 = __webpack_require__("./rsbuild");
175
- var _types__rspack_import_24 = __webpack_require__("./types?6efa");
156
+ var _commands_dev__rspack_import_17 = __webpack_require__("./commands/dev");
157
+ var _commands_serve__rspack_import_18 = __webpack_require__("./commands/serve");
158
+ var _utils_createServer__rspack_import_19 = __webpack_require__("./utils/createServer");
159
+ var _rsbuild__rspack_import_20 = __webpack_require__("./rsbuild");
160
+ var _types__rspack_import_21 = __webpack_require__("./types?6efa");
176
161
  var __rspack_reexport = {};
177
- for(const __rspack_import_key in _types__rspack_import_24)if ([
162
+ for(const __rspack_import_key in _types__rspack_import_21)if ([
178
163
  "dev",
179
164
  "resolveModernRsbuildConfig",
180
165
  "mergeConfig",
@@ -183,17 +168,14 @@ var __webpack_exports__ = {};
183
168
  "serve",
184
169
  "generateWatchFiles",
185
170
  "initAppContext",
186
- "deploy",
187
171
  "defineConfig",
188
- "build",
189
172
  "closeServer"
190
- ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_24[__rspack_import_key];
173
+ ].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_types__rspack_import_21[__rspack_import_key];
191
174
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
192
- var _modern_js_plugin_cli__rspack_import_25 = __webpack_require__("@modern-js/plugin/cli");
175
+ var _modern_js_plugin_cli__rspack_import_22 = __webpack_require__("@modern-js/plugin/cli");
193
176
  const appTools = ()=>({
194
177
  name: '@modern-js/app-tools',
195
178
  usePlugins: [
196
- _plugins_serverRuntime__rspack_import_13_default()(),
197
179
  (0, _compat__rspack_import_6.compatPlugin)(),
198
180
  _plugins_initialize__rspack_import_11_default()(),
199
181
  _plugins_analyze__rspack_import_9_default()(),
@@ -226,7 +208,7 @@ var __webpack_exports__ = {};
226
208
  _locale__rspack_import_8.i18n.changeLanguage({
227
209
  locale
228
210
  });
229
- api.updateAppContext((0, _utils_initAppContext__rspack_import_15.initAppContext)({
211
+ api.updateAppContext((0, _utils_initAppContext__rspack_import_14.initAppContext)({
230
212
  metaName: context.metaName,
231
213
  appDirectory: context.appDirectory,
232
214
  runtimeConfigFile: _constants__rspack_import_7.DEFAULT_RUNTIME_CONFIG_FILE,
@@ -250,18 +232,12 @@ var __webpack_exports__ = {};
250
232
  ].some((tag)=>(0, _modern_js_utils__rspack_import_4.getArgv)().includes(tag));
251
233
  if (isSkipBuild) return;
252
234
  }
253
- const { command: contextCommand } = api.getAppContext();
254
- const shouldClean = [
235
+ if ([
255
236
  'dev',
256
237
  'start',
257
238
  'build',
258
239
  'deploy'
259
- ].includes(command) || [
260
- 'dev',
261
- 'start',
262
- 'build'
263
- ].includes(contextCommand);
264
- if (shouldClean) {
240
+ ].includes(command)) {
265
241
  const resolvedConfig = api.getNormalizedConfig();
266
242
  if (resolvedConfig.output.cleanDistPath) {
267
243
  const appContext = api.getAppContext();
@@ -272,7 +248,7 @@ var __webpack_exports__ = {};
272
248
  api.addWatchFiles(async ()=>{
273
249
  const appContext = api.getAppContext();
274
250
  const config = api.getNormalizedConfig();
275
- const files = await (0, _utils_generateWatchFiles__rspack_import_14.generateWatchFiles)(appContext, config.source.configDir);
251
+ const files = await (0, _utils_generateWatchFiles__rspack_import_13.generateWatchFiles)(appContext, config.source.configDir);
276
252
  const watchFiles = (0, _modern_js_builder__rspack_import_1.castArray)(config.dev.watchFiles);
277
253
  watchFiles.forEach(({ type, paths })=>{
278
254
  if ('reload-server' === type) files.push(...Array.isArray(paths) ? paths : [
@@ -289,7 +265,7 @@ var __webpack_exports__ = {};
289
265
  if (!isPrivate && ('change' === eventType || 'unlink' === eventType) && !isApiProject) {
290
266
  const { closeServer } = await import("./utils/createServer.js");
291
267
  await closeServer();
292
- await (0, _utils_restart__rspack_import_16.restart)(api.getHooks(), filename);
268
+ await (0, _utils_restart__rspack_import_15.restart)(api.getHooks(), filename);
293
269
  }
294
270
  });
295
271
  api.onBeforeRestart(()=>{
@@ -301,27 +277,23 @@ var __webpack_exports__ = {};
301
277
  });
302
278
  const __rspack_default_export = appTools;
303
279
  __webpack_require__.d(__webpack_exports__, {
304
- build: ()=>_commands_build__rspack_import_18.build,
305
- closeServer: ()=>_utils_createServer__rspack_import_22.closeServer,
306
- defineConfig: ()=>_defineConfig__rspack_import_17.defineConfig,
307
- deploy: ()=>_commands_deploy__rspack_import_19.deploy,
308
- dev: ()=>_commands_dev__rspack_import_20.dev,
309
- generateWatchFiles: ()=>_utils_generateWatchFiles__rspack_import_14.generateWatchFiles,
310
- initAppContext: ()=>_utils_initAppContext__rspack_import_15.initAppContext,
311
- mergeConfig: ()=>_modern_js_plugin_cli__rspack_import_25.mergeConfig,
312
- resolveModernRsbuildConfig: ()=>_rsbuild__rspack_import_23.resolveModernRsbuildConfig,
313
- serve: ()=>_commands_serve__rspack_import_21.serve
280
+ closeServer: ()=>_utils_createServer__rspack_import_19.closeServer,
281
+ defineConfig: ()=>_defineConfig__rspack_import_16.defineConfig,
282
+ dev: ()=>_commands_dev__rspack_import_17.dev,
283
+ generateWatchFiles: ()=>_utils_generateWatchFiles__rspack_import_13.generateWatchFiles,
284
+ initAppContext: ()=>_utils_initAppContext__rspack_import_14.initAppContext,
285
+ mergeConfig: ()=>_modern_js_plugin_cli__rspack_import_22.mergeConfig,
286
+ resolveModernRsbuildConfig: ()=>_rsbuild__rspack_import_20.resolveModernRsbuildConfig,
287
+ serve: ()=>_commands_serve__rspack_import_18.serve
314
288
  }, {
315
289
  appTools: appTools,
316
290
  default: __rspack_default_export
317
291
  });
318
292
  })();
319
293
  exports.appTools = __webpack_exports__.appTools;
320
- exports.build = __webpack_exports__.build;
321
294
  exports.closeServer = __webpack_exports__.closeServer;
322
295
  exports["default"] = __webpack_exports__["default"];
323
296
  exports.defineConfig = __webpack_exports__.defineConfig;
324
- exports.deploy = __webpack_exports__.deploy;
325
297
  exports.dev = __webpack_exports__.dev;
326
298
  exports.generateWatchFiles = __webpack_exports__.generateWatchFiles;
327
299
  exports.initAppContext = __webpack_exports__.initAppContext;
@@ -330,11 +302,9 @@ exports.resolveModernRsbuildConfig = __webpack_exports__.resolveModernRsbuildCon
330
302
  exports.serve = __webpack_exports__.serve;
331
303
  for(var __rspack_i in __webpack_exports__)if (-1 === [
332
304
  "appTools",
333
- "build",
334
305
  "closeServer",
335
306
  "default",
336
307
  "defineConfig",
337
- "deploy",
338
308
  "dev",
339
309
  "generateWatchFiles",
340
310
  "initAppContext",
@@ -106,7 +106,7 @@ const getFileSystemEntry = async (hooks, appContext, config)=>{
106
106
  }));
107
107
  return scanDir(hooks, dirs);
108
108
  } else throw Error("source.entriesDir accept a directory.");
109
- throw Error(`src dir ${entriesDir} not found.`);
109
+ else throw Error(`src dir ${entriesDir} not found.`);
110
110
  };
111
111
  exports.getFileSystemEntry = __webpack_exports__.getFileSystemEntry;
112
112
  exports.hasEntry = __webpack_exports__.hasEntry;
@@ -69,7 +69,7 @@ const applyRouteOptions = (original, routeOptions)=>{
69
69
  ...original,
70
70
  urlPath: url
71
71
  };
72
- {
72
+ else {
73
73
  const { path: urlPath, ...other } = url;
74
74
  return {
75
75
  ...original,
@@ -55,7 +55,7 @@ const analyze = ()=>({
55
55
  const resolvedConfig = api.getNormalizedConfig();
56
56
  const hooks = api.getHooks();
57
57
  try {
58
- if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)(appContext.command)) utils_namespaceObject.fs.emptydirSync(appContext.internalDirectory);
58
+ if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)()) utils_namespaceObject.fs.emptydirSync(appContext.internalDirectory);
59
59
  } catch {}
60
60
  const apiOnly = await (0, utils_namespaceObject.isApiOnly)(appContext.appDirectory, resolvedConfig.source?.entriesDir, appContext.apiDirectory);
61
61
  const [{ getProdServerRoutes }] = await Promise.all([
@@ -149,7 +149,7 @@ const analyze = ()=>({
149
149
  htmlTemplates
150
150
  };
151
151
  api.updateAppContext(appContext);
152
- if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)(appContext.command)) {
152
+ if ((0, external_utils_js_namespaceObject.checkIsBuildCommands)()) {
153
153
  await hooks.generateEntryCode.call({
154
154
  entrypoints
155
155
  });
@@ -58,14 +58,14 @@ const walkDirectory = (dir)=>external_fs_default().readdirSync(dir).reduce((prev
58
58
  ...previous,
59
59
  ...walkDirectory(filePath)
60
60
  ];
61
- return [
61
+ else return [
62
62
  ...previous,
63
63
  filePath
64
64
  ];
65
65
  }, []);
66
66
  const replaceWithAlias = (base, filePath, alias)=>{
67
67
  if (filePath.includes(base)) return (0, utils_namespaceObject.normalizeToPosixPath)(external_path_default().join(alias, external_path_default().relative(base, filePath)));
68
- return filePath;
68
+ else return filePath;
69
69
  };
70
70
  const parseModule = async ({ source, filename })=>{
71
71
  let content = source;
@@ -101,7 +101,7 @@ const parseModule = async ({ source, filename })=>{
101
101
  return await (0, external_es_module_lexer_namespaceObject.parse)(content);
102
102
  };
103
103
  const getServerCombinedModuleFile = (internalDirectory, entryName)=>external_path_default().join(internalDirectory, entryName, 'server-loader-combined.js');
104
- const checkIsBuildCommands = (contextCommand)=>{
104
+ const checkIsBuildCommands = ()=>{
105
105
  const buildCommands = [
106
106
  'dev',
107
107
  'start',
@@ -111,8 +111,7 @@ const checkIsBuildCommands = (contextCommand)=>{
111
111
  'dev-worker'
112
112
  ];
113
113
  const command = (0, utils_namespaceObject.getCommand)();
114
- if (buildCommands.includes(command)) return true;
115
- return 'dev' === contextCommand || 'start' === contextCommand || 'build' === contextCommand || 'deploy' === contextCommand;
114
+ return buildCommands.includes(command);
116
115
  };
117
116
  const checkIsServeCommand = ()=>{
118
117
  const command = (0, utils_namespaceObject.getCommand)();
@@ -57,7 +57,7 @@ const initialize = ()=>({
57
57
  api.modifyResolvedConfig(async (resolved)=>{
58
58
  let appContext = api.getAppContext();
59
59
  const userConfig = api.getConfig();
60
- const port = await getServerPort(resolved, appContext.command);
60
+ const port = await getServerPort(resolved);
61
61
  appContext = {
62
62
  ...appContext,
63
63
  port,
@@ -92,10 +92,9 @@ function stabilizeConfig(resolve, config, keys) {
92
92
  resolve[key] = config[key] || {};
93
93
  });
94
94
  }
95
- async function getServerPort(config, contextCommand) {
95
+ async function getServerPort(config) {
96
96
  const prodPort = Number(process.env.PORT) || config.server.port || 8080;
97
- const isProgrammaticDev = 'dev' === contextCommand || 'start' === contextCommand;
98
- if ((0, utils_namespaceObject.isDev)() && ((0, utils_namespaceObject.isDevCommand)() || isProgrammaticDev)) return (0, utils_namespaceObject.getPort)(Number(process.env.PORT) || prodPort);
97
+ if ((0, utils_namespaceObject.isDev)() && (0, utils_namespaceObject.isDevCommand)()) return (0, utils_namespaceObject.getPort)(Number(process.env.PORT) || prodPort);
99
98
  return prodPort;
100
99
  }
101
100
  exports["default"] = __webpack_exports__["default"];
@@ -56,9 +56,8 @@ const build = async (api, options)=>{
56
56
  logger.info('Starting production build...');
57
57
  if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
58
58
  await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
59
- const buildResult = await appContext.builder.build({
59
+ await appContext.builder.build({
60
60
  watch: options?.watch
61
61
  });
62
- if (!options?.watch) await buildResult?.close();
63
62
  };
64
63
  export { build };
@@ -1,10 +1,8 @@
1
1
  import { getServerPlugins } from "../utils/loadPlugins.mjs";
2
- import { build } from "./build.mjs";
3
2
  const deploy = async (api, options = {})=>{
4
3
  const hooks = api.getHooks();
5
4
  const { metaName } = api.getAppContext();
6
- if (options.skipBuild) await getServerPlugins(api, metaName);
7
- else await build(api);
5
+ await getServerPlugins(api, metaName);
8
6
  await hooks.onBeforeDeploy.call(options);
9
7
  await hooks.deploy.call();
10
8
  await hooks.onAfterDeploy.call(options);
@@ -19,6 +19,10 @@ const serverCommand = (program, api)=>{
19
19
  };
20
20
  const deployCommand = (program, api)=>{
21
21
  program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
22
+ if (!options.skipBuild) {
23
+ const { build } = await import("./build.mjs");
24
+ await build(api);
25
+ }
22
26
  const { deploy } = await import("./deploy.mjs");
23
27
  await deploy(api, options);
24
28
  process.exit(0);
@@ -59,7 +59,7 @@ function handleSetupResult(setupResult, api) {
59
59
  if (newAPI && api[newAPI]) api[newAPI](async (...params)=>{
60
60
  const { isMultiple, params: transformParams } = transformHookParams(key, params);
61
61
  if (isMultiple) return transformHookResult(key, await fn(...transformParams));
62
- return transformHookResult(key, await fn(transformParams));
62
+ else return transformHookResult(key, await fn(transformParams));
63
63
  });
64
64
  }
65
65
  });
@@ -11,7 +11,6 @@ import analyze from "./plugins/analyze/index.mjs";
11
11
  import deploy from "./plugins/deploy/index.mjs";
12
12
  import initialize from "./plugins/initialize/index.mjs";
13
13
  import serverBuild from "./plugins/serverBuild.mjs";
14
- import serverRuntime from "./plugins/serverRuntime.mjs";
15
14
  import { generateWatchFiles } from "./utils/generateWatchFiles.mjs";
16
15
  import { initAppContext } from "./utils/initAppContext.mjs";
17
16
  import { restart } from "./utils/restart.mjs";
@@ -20,7 +19,6 @@ export * from "./types/index.mjs";
20
19
  const appTools = ()=>({
21
20
  name: '@modern-js/app-tools',
22
21
  usePlugins: [
23
- serverRuntime(),
24
22
  compatPlugin(),
25
23
  initialize(),
26
24
  analyze(),
@@ -77,18 +75,12 @@ const appTools = ()=>({
77
75
  ].some((tag)=>getArgv().includes(tag));
78
76
  if (isSkipBuild) return;
79
77
  }
80
- const { command: contextCommand } = api.getAppContext();
81
- const shouldClean = [
78
+ if ([
82
79
  'dev',
83
80
  'start',
84
81
  'build',
85
82
  'deploy'
86
- ].includes(command) || [
87
- 'dev',
88
- 'start',
89
- 'build'
90
- ].includes(contextCommand);
91
- if (shouldClean) {
83
+ ].includes(command)) {
92
84
  const resolvedConfig = api.getNormalizedConfig();
93
85
  if (resolvedConfig.output.cleanDistPath) {
94
86
  const appContext = api.getAppContext();
@@ -128,8 +120,6 @@ const appTools = ()=>({
128
120
  });
129
121
  const src = appTools;
130
122
  export { defineConfig } from "./defineConfig.mjs";
131
- export { build } from "./commands/build.mjs";
132
- export { deploy } from "./commands/deploy.mjs";
133
123
  export { dev } from "./commands/dev.mjs";
134
124
  export { serve } from "./commands/serve.mjs";
135
125
  export { closeServer } from "./utils/createServer.mjs";
@@ -61,6 +61,6 @@ const getFileSystemEntry = async (hooks, appContext, config)=>{
61
61
  }));
62
62
  return scanDir(hooks, dirs);
63
63
  } else throw Error("source.entriesDir accept a directory.");
64
- throw Error(`src dir ${entriesDir} not found.`);
64
+ else throw Error(`src dir ${entriesDir} not found.`);
65
65
  };
66
66
  export { getFileSystemEntry, hasEntry, hasServerEntry };
@@ -26,7 +26,7 @@ const applyRouteOptions = (original, routeOptions)=>{
26
26
  ...original,
27
27
  urlPath: url
28
28
  };
29
- {
29
+ else {
30
30
  const { path: urlPath, ...other } = url;
31
31
  return {
32
32
  ...original,
@@ -23,7 +23,7 @@ const analyze = ()=>({
23
23
  const resolvedConfig = api.getNormalizedConfig();
24
24
  const hooks = api.getHooks();
25
25
  try {
26
- if (checkIsBuildCommands(appContext.command)) fs.emptydirSync(appContext.internalDirectory);
26
+ if (checkIsBuildCommands()) fs.emptydirSync(appContext.internalDirectory);
27
27
  } catch {}
28
28
  const apiOnly = await isApiOnly(appContext.appDirectory, resolvedConfig.source?.entriesDir, appContext.apiDirectory);
29
29
  const [{ getProdServerRoutes }] = await Promise.all([
@@ -117,7 +117,7 @@ const analyze = ()=>({
117
117
  htmlTemplates
118
118
  };
119
119
  api.updateAppContext(appContext);
120
- if (checkIsBuildCommands(appContext.command)) {
120
+ if (checkIsBuildCommands()) {
121
121
  await hooks.generateEntryCode.call({
122
122
  entrypoints
123
123
  });
@@ -9,14 +9,14 @@ const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
9
9
  ...previous,
10
10
  ...walkDirectory(filePath)
11
11
  ];
12
- return [
12
+ else return [
13
13
  ...previous,
14
14
  filePath
15
15
  ];
16
16
  }, []);
17
17
  const replaceWithAlias = (base, filePath, alias)=>{
18
18
  if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
19
- return filePath;
19
+ else return filePath;
20
20
  };
21
21
  const parseModule = async ({ source, filename })=>{
22
22
  let content = source;
@@ -52,7 +52,7 @@ const parseModule = async ({ source, filename })=>{
52
52
  return await parse(content);
53
53
  };
54
54
  const getServerCombinedModuleFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
55
- const checkIsBuildCommands = (contextCommand)=>{
55
+ const checkIsBuildCommands = ()=>{
56
56
  const buildCommands = [
57
57
  'dev',
58
58
  'start',
@@ -62,8 +62,7 @@ const checkIsBuildCommands = (contextCommand)=>{
62
62
  'dev-worker'
63
63
  ];
64
64
  const command = getCommand();
65
- if (buildCommands.includes(command)) return true;
66
- return 'dev' === contextCommand || 'start' === contextCommand || 'build' === contextCommand || 'deploy' === contextCommand;
65
+ return buildCommands.includes(command);
67
66
  };
68
67
  const checkIsServeCommand = ()=>{
69
68
  const command = getCommand();
@@ -25,7 +25,7 @@ const initialize = ()=>({
25
25
  api.modifyResolvedConfig(async (resolved)=>{
26
26
  let appContext = api.getAppContext();
27
27
  const userConfig = api.getConfig();
28
- const port = await getServerPort(resolved, appContext.command);
28
+ const port = await getServerPort(resolved);
29
29
  appContext = {
30
30
  ...appContext,
31
31
  port,
@@ -60,10 +60,9 @@ function stabilizeConfig(resolve, config, keys) {
60
60
  resolve[key] = config[key] || {};
61
61
  });
62
62
  }
63
- async function getServerPort(config, contextCommand) {
63
+ async function getServerPort(config) {
64
64
  const prodPort = Number(process.env.PORT) || config.server.port || 8080;
65
- const isProgrammaticDev = 'dev' === contextCommand || 'start' === contextCommand;
66
- if (isDev() && (isDevCommand() || isProgrammaticDev)) return getPort(Number(process.env.PORT) || prodPort);
65
+ if (isDev() && isDevCommand()) return getPort(Number(process.env.PORT) || prodPort);
67
66
  return prodPort;
68
67
  }
69
68
  export default initialize;
@@ -57,9 +57,8 @@ const build = async (api, options)=>{
57
57
  logger.info('Starting production build...');
58
58
  if (!appContext.builder) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
59
59
  await appContext.builder.onAfterBuild(async ()=>copyEnvFiles(appContext.appDirectory, appContext.distDirectory));
60
- const buildResult = await appContext.builder.build({
60
+ await appContext.builder.build({
61
61
  watch: options?.watch
62
62
  });
63
- if (!options?.watch) await buildResult?.close();
64
63
  };
65
64
  export { build };
@@ -1,11 +1,9 @@
1
1
  import "node:module";
2
2
  import { getServerPlugins } from "../utils/loadPlugins.mjs";
3
- import { build } from "./build.mjs";
4
3
  const deploy = async (api, options = {})=>{
5
4
  const hooks = api.getHooks();
6
5
  const { metaName } = api.getAppContext();
7
- if (options.skipBuild) await getServerPlugins(api, metaName);
8
- else await build(api);
6
+ await getServerPlugins(api, metaName);
9
7
  await hooks.onBeforeDeploy.call(options);
10
8
  await hooks.deploy.call();
11
9
  await hooks.onAfterDeploy.call(options);
@@ -20,6 +20,10 @@ const serverCommand = (program, api)=>{
20
20
  };
21
21
  const deployCommand = (program, api)=>{
22
22
  program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
23
+ if (!options.skipBuild) {
24
+ const { build } = await import("./build.mjs");
25
+ await build(api);
26
+ }
23
27
  const { deploy } = await import("./deploy.mjs");
24
28
  await deploy(api, options);
25
29
  process.exit(0);
@@ -60,7 +60,7 @@ function handleSetupResult(setupResult, api) {
60
60
  if (newAPI && api[newAPI]) api[newAPI](async (...params)=>{
61
61
  const { isMultiple, params: transformParams } = transformHookParams(key, params);
62
62
  if (isMultiple) return transformHookResult(key, await fn(...transformParams));
63
- return transformHookResult(key, await fn(transformParams));
63
+ else return transformHookResult(key, await fn(transformParams));
64
64
  });
65
65
  }
66
66
  });
@@ -13,7 +13,6 @@ import analyze from "./plugins/analyze/index.mjs";
13
13
  import deploy from "./plugins/deploy/index.mjs";
14
14
  import initialize from "./plugins/initialize/index.mjs";
15
15
  import serverBuild from "./plugins/serverBuild.mjs";
16
- import serverRuntime from "./plugins/serverRuntime.mjs";
17
16
  import { generateWatchFiles } from "./utils/generateWatchFiles.mjs";
18
17
  import { initAppContext } from "./utils/initAppContext.mjs";
19
18
  import { restart } from "./utils/restart.mjs";
@@ -22,7 +21,6 @@ export * from "./types/index.mjs";
22
21
  const appTools = ()=>({
23
22
  name: '@modern-js/app-tools',
24
23
  usePlugins: [
25
- serverRuntime(),
26
24
  compatPlugin(),
27
25
  initialize(),
28
26
  analyze(),
@@ -79,18 +77,12 @@ const appTools = ()=>({
79
77
  ].some((tag)=>getArgv().includes(tag));
80
78
  if (isSkipBuild) return;
81
79
  }
82
- const { command: contextCommand } = api.getAppContext();
83
- const shouldClean = [
80
+ if ([
84
81
  'dev',
85
82
  'start',
86
83
  'build',
87
84
  'deploy'
88
- ].includes(command) || [
89
- 'dev',
90
- 'start',
91
- 'build'
92
- ].includes(contextCommand);
93
- if (shouldClean) {
85
+ ].includes(command)) {
94
86
  const resolvedConfig = api.getNormalizedConfig();
95
87
  if (resolvedConfig.output.cleanDistPath) {
96
88
  const appContext = api.getAppContext();
@@ -130,8 +122,6 @@ const appTools = ()=>({
130
122
  });
131
123
  const src = appTools;
132
124
  export { defineConfig } from "./defineConfig.mjs";
133
- export { build } from "./commands/build.mjs";
134
- export { deploy } from "./commands/deploy.mjs";
135
125
  export { dev } from "./commands/dev.mjs";
136
126
  export { serve } from "./commands/serve.mjs";
137
127
  export { closeServer } from "./utils/createServer.mjs";
@@ -62,6 +62,6 @@ const getFileSystemEntry = async (hooks, appContext, config)=>{
62
62
  }));
63
63
  return scanDir(hooks, dirs);
64
64
  } else throw Error("source.entriesDir accept a directory.");
65
- throw Error(`src dir ${entriesDir} not found.`);
65
+ else throw Error(`src dir ${entriesDir} not found.`);
66
66
  };
67
67
  export { getFileSystemEntry, hasEntry, hasServerEntry };
@@ -27,7 +27,7 @@ const applyRouteOptions = (original, routeOptions)=>{
27
27
  ...original,
28
28
  urlPath: url
29
29
  };
30
- {
30
+ else {
31
31
  const { path: urlPath, ...other } = url;
32
32
  return {
33
33
  ...original,