@modern-js/app-tools 2.53.1-alpha.4 → 2.54.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. package/bin/modern.js +0 -2
  2. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
  4. package/dist/cjs/commands/build.js +2 -0
  5. package/dist/cjs/commands/deploy.js +2 -2
  6. package/dist/cjs/commands/dev.js +19 -5
  7. package/dist/cjs/commands/index.js +113 -7
  8. package/dist/cjs/commands/serve.js +19 -5
  9. package/dist/cjs/hooks.js +5 -0
  10. package/dist/cjs/index.js +14 -83
  11. package/dist/cjs/plugins/analyze/constants.js +56 -0
  12. package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
  13. package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  14. package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
  15. package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  16. package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
  17. package/dist/cjs/plugins/analyze/templates.js +101 -0
  18. package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
  19. package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -2
  20. package/dist/cjs/plugins/deploy/platforms/node.js +2 -2
  21. package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -2
  22. package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
  23. package/dist/cjs/plugins/serverBuild.js +10 -4
  24. package/dist/cjs/utils/createServer.js +1 -1
  25. package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
  26. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
  27. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  28. package/dist/esm/commands/build.js +16 -9
  29. package/dist/esm/commands/deploy.js +2 -2
  30. package/dist/esm/commands/dev.js +13 -9
  31. package/dist/esm/commands/index.js +411 -3
  32. package/dist/esm/commands/serve.js +12 -8
  33. package/dist/esm/hooks.js +5 -0
  34. package/dist/esm/index.js +12 -394
  35. package/dist/esm/plugins/analyze/constants.js +24 -0
  36. package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
  37. package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
  38. package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
  39. package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  40. package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
  41. package/dist/esm/plugins/analyze/templates.js +22 -0
  42. package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
  43. package/dist/esm/plugins/deploy/platforms/netlify.js +5 -3
  44. package/dist/esm/plugins/deploy/platforms/node.js +5 -3
  45. package/dist/esm/plugins/deploy/platforms/vercel.js +5 -3
  46. package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
  47. package/dist/esm/plugins/serverBuild.js +13 -6
  48. package/dist/esm/utils/createServer.js +2 -2
  49. package/dist/esm/utils/loadPlugins.js +64 -0
  50. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
  51. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  52. package/dist/esm-node/commands/build.js +2 -0
  53. package/dist/esm-node/commands/deploy.js +2 -2
  54. package/dist/esm-node/commands/dev.js +11 -7
  55. package/dist/esm-node/commands/index.js +92 -3
  56. package/dist/esm-node/commands/serve.js +10 -6
  57. package/dist/esm-node/hooks.js +5 -0
  58. package/dist/esm-node/index.js +12 -79
  59. package/dist/esm-node/plugins/analyze/constants.js +24 -0
  60. package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
  61. package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  62. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
  63. package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  64. package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
  65. package/dist/esm-node/plugins/analyze/templates.js +75 -0
  66. package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
  67. package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -3
  68. package/dist/esm-node/plugins/deploy/platforms/node.js +3 -3
  69. package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -3
  70. package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
  71. package/dist/esm-node/plugins/serverBuild.js +11 -5
  72. package/dist/esm-node/utils/createServer.js +2 -2
  73. package/dist/esm-node/utils/loadPlugins.js +21 -0
  74. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  75. package/dist/types/commands/index.d.ts +10 -3
  76. package/dist/types/config/initialize/inits.d.ts +1 -1
  77. package/dist/types/exports/server.d.ts +4 -0
  78. package/dist/types/index.d.ts +2 -5
  79. package/dist/types/plugins/analyze/constants.d.ts +9 -0
  80. package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
  81. package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
  82. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
  83. package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
  84. package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
  85. package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
  86. package/dist/types/plugins/analyze/templates.d.ts +19 -0
  87. package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
  88. package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
  89. package/dist/types/types/hooks.d.ts +11 -1
  90. package/dist/types/utils/loadPlugins.d.ts +5 -0
  91. package/package.json +22 -22
  92. package/dist/cjs/analyze/constants.js +0 -122
  93. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
  94. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
  95. package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
  96. package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
  97. package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
  98. package/dist/cjs/analyze/nestedRoutes.js +0 -295
  99. package/dist/cjs/analyze/templates.js +0 -444
  100. package/dist/esm/analyze/constants.js +0 -76
  101. package/dist/esm/analyze/getBundleEntry.js +0 -75
  102. package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
  103. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
  104. package/dist/esm/analyze/getClientRoutes/index.js +0 -6
  105. package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
  106. package/dist/esm/analyze/getFileSystemEntry.js +0 -113
  107. package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
  108. package/dist/esm/analyze/nestedRoutes.js +0 -398
  109. package/dist/esm/analyze/templates.js +0 -435
  110. package/dist/esm/utils/getServerInternalPlugins.js +0 -40
  111. package/dist/esm-node/analyze/constants.js +0 -76
  112. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
  113. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
  114. package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
  115. package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
  116. package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
  117. package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
  118. package/dist/esm-node/analyze/nestedRoutes.js +0 -259
  119. package/dist/esm-node/analyze/templates.js +0 -405
  120. package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
  121. package/dist/types/analyze/constants.d.ts +0 -42
  122. package/dist/types/analyze/getBundleEntry.d.ts +0 -3
  123. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
  124. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
  125. package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
  126. package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
  127. package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
  128. package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
  129. package/dist/types/analyze/nestedRoutes.d.ts +0 -7
  130. package/dist/types/analyze/templates.d.ts +0 -30
  131. package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
  132. /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  133. /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  134. /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  135. /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  136. /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  137. /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  138. /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
package/bin/modern.js CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  const {
3
3
  INTERNAL_APP_TOOLS_PLUGINS,
4
- INTERNAL_SERVER_PLUGINS,
5
4
  INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
6
5
  } = require('@modern-js/utils');
7
6
 
@@ -14,7 +13,6 @@ if (!process.env.MODERN_JS_VERSION) {
14
13
  require('@modern-js/core/runBin').run({
15
14
  internalPlugins: {
16
15
  cli: INTERNAL_APP_TOOLS_PLUGINS,
17
- server: INTERNAL_SERVER_PLUGINS,
18
16
  autoLoad: INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
19
17
  },
20
18
  initialLog: `Modern.js Framework v${version}`,
@@ -25,6 +25,7 @@ var import_shared = require("@rsbuild/shared");
25
25
  var import_utils = require("@modern-js/utils");
26
26
  var import_lodash = require("@modern-js/utils/lodash");
27
27
  var import_bundlerPlugins = require("../bundlerPlugins");
28
+ const createVirtualModule = (content) => `data:text/javascript,${content}`;
28
29
  const builderPluginAdapterHtml = (options) => ({
29
30
  name: "builder-plugin-adapter-modern-html",
30
31
  setup(api) {
@@ -51,7 +52,7 @@ async function injectAssetPrefix({ chain }) {
51
52
  const assetPrefix = (0, import_utils.removeTailSlash)(chain.output.get("publicPath") || "");
52
53
  const code = `window.__assetPrefix__ = '${assetPrefix}';`;
53
54
  entryNames.forEach((entryName) => {
54
- entries[entryName].prepend((0, import_shared.createVirtualModule)(code));
55
+ entries[entryName].prepend(createVirtualModule(code));
55
56
  });
56
57
  }
57
58
  function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugin }) {
@@ -36,7 +36,7 @@ var import_shared = require("@rsbuild/shared");
36
36
  var import_core = require("@rsbuild/core");
37
37
  var import_utils = require("@modern-js/utils");
38
38
  var import_bundlerPlugins = require("../bundlerPlugins");
39
- var import_utils2 = require("../../../analyze/utils");
39
+ var import_utils2 = require("../../../plugins/analyze/utils");
40
40
  const builderPluginAdapterSSR = (options) => ({
41
41
  name: "builder-plugin-adapter-modern-ssr",
42
42
  setup(api) {
@@ -157,7 +157,7 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
157
157
  }
158
158
  const { ssr, ssrByEntries } = serverConfig || {};
159
159
  entryNames.forEach((name) => {
160
- if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
160
+ if (!ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
161
161
  chain.entryPoints.delete(name);
162
162
  }
163
163
  });
@@ -23,6 +23,7 @@ __export(build_exports, {
23
23
  module.exports = __toCommonJS(build_exports);
24
24
  var import_core = require("@modern-js/core");
25
25
  var import_utils = require("@modern-js/utils");
26
+ var import_loadPlugins = require("../utils/loadPlugins");
26
27
  var import_routes = require("../utils/routes");
27
28
  var import_config = require("../utils/config");
28
29
  var import_register = require("../utils/register");
@@ -34,6 +35,7 @@ const build = async (api, options) => {
34
35
  let resolvedConfig = api.useResolvedConfigContext();
35
36
  const appContext = api.useAppContext();
36
37
  const hookRunners = api.useHookRunners();
38
+ await (0, import_loadPlugins.loadServerPlugins)(api, appContext.appDirectory);
37
39
  await (0, import_register.registerCompiler)(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias);
38
40
  const { apiOnly } = appContext;
39
41
  if (apiOnly) {
@@ -21,10 +21,10 @@ __export(deploy_exports, {
21
21
  deploy: () => deploy
22
22
  });
23
23
  module.exports = __toCommonJS(deploy_exports);
24
- var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
24
+ var import_loadPlugins = require("../utils/loadPlugins");
25
25
  const deploy = async (api, options) => {
26
26
  const hookRunners = api.useHookRunners();
27
- await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
27
+ await (0, import_loadPlugins.getServerPlugins)(api);
28
28
  await hookRunners.beforeDeploy(options);
29
29
  await hookRunners.deploy(options);
30
30
  await hookRunners.afterDeploy(options);
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,22 +17,31 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var dev_exports = {};
20
30
  __export(dev_exports, {
21
31
  dev: () => dev
22
32
  });
23
33
  module.exports = __toCommonJS(dev_exports);
34
+ var import_node_path = __toESM(require("node:path"));
24
35
  var import_core = require("@modern-js/core");
25
36
  var import_utils = require("@modern-js/utils");
26
37
  var import_server = require("@modern-js/server");
27
38
  var import_prod_server = require("@modern-js/prod-server");
39
+ var import_loadPlugins = require("../utils/loadPlugins");
28
40
  var import_register = require("../utils/register");
29
41
  var import_printInstructions = require("../utils/printInstructions");
30
42
  var import_createServer = require("../utils/createServer");
31
43
  var import_routes = require("../utils/routes");
32
44
  var import_config = require("../utils/config");
33
- var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
34
45
  const dev = async (api, options, devServerOptions = {}) => {
35
46
  var _normalizedConfig_source, _normalizedConfig_tools;
36
47
  if (options.analyze) {
@@ -52,12 +63,14 @@ const dev = async (api, options, devServerOptions = {}) => {
52
63
  configFile: serverConfigFile,
53
64
  watch: true
54
65
  });
66
+ const meta = (0, import_utils.getMeta)(metaName);
67
+ const serverConfigPath = import_node_path.default.resolve(appDirectory, import_utils.SERVER_DIR, `${meta}.server`);
55
68
  await hookRunners.beforeDev();
56
69
  if (!appContext.builder && !apiOnly) {
57
70
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
58
71
  }
59
72
  await (0, import_routes.generateRoutes)(appContext);
60
- const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
73
+ const pluginInstances = await (0, import_loadPlugins.loadServerPlugins)(api, appDirectory);
61
74
  const serverOptions = {
62
75
  metaName,
63
76
  dev: {
@@ -72,16 +85,17 @@ const dev = async (api, options, devServerOptions = {}) => {
72
85
  lambdaDirectory: appContext.lambdaDirectory,
73
86
  sharedDirectory: appContext.sharedDirectory
74
87
  },
88
+ serverConfigPath,
75
89
  routes: serverRoutes,
76
90
  pwd: appDirectory,
77
91
  config: normalizedConfig,
78
92
  serverConfigFile,
79
- internalPlugins: serverInternalPlugins,
93
+ plugins: pluginInstances,
80
94
  ...devServerOptions
81
95
  };
82
96
  if (apiOnly) {
83
97
  var _normalizedConfig_dev;
84
- const app = await (0, import_server.createDevServer)(serverOptions, import_prod_server.initProdMiddlewares);
98
+ const app = await (0, import_server.createDevServer)(serverOptions, import_prod_server.applyPlugins);
85
99
  const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || import_utils.DEFAULT_DEV_HOST;
86
100
  app.listen({
87
101
  port,
@@ -92,7 +106,7 @@ const dev = async (api, options, devServerOptions = {}) => {
92
106
  } else {
93
107
  const { server } = await appContext.builder.startDevServer({
94
108
  serverOptions,
95
- initProdMiddlewares: import_prod_server.initProdMiddlewares
109
+ applyPlugins: import_prod_server.applyPlugins
96
110
  });
97
111
  (0, import_createServer.setServer)(server);
98
112
  }
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
6
12
  var __copyProps = (to, from, except, desc) => {
7
13
  if (from && typeof from === "object" || typeof from === "function") {
8
14
  for (let key of __getOwnPropNames(from))
@@ -11,16 +17,116 @@ var __copyProps = (to, from, except, desc) => {
11
17
  }
12
18
  return to;
13
19
  };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
15
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
29
  var commands_exports = {};
30
+ __export(commands_exports, {
31
+ buildCommand: () => buildCommand,
32
+ deployCommand: () => deployCommand,
33
+ devCommand: () => devCommand,
34
+ inspectCommand: () => inspectCommand,
35
+ newCommand: () => newCommand,
36
+ serverCommand: () => serverCommand,
37
+ upgradeCommand: () => upgradeCommand
38
+ });
17
39
  module.exports = __toCommonJS(commands_exports);
18
- __reExport(commands_exports, require("./dev"), module.exports);
19
- __reExport(commands_exports, require("./build"), module.exports);
20
- __reExport(commands_exports, require("./serve"), module.exports);
40
+ var import_utils = require("@modern-js/utils");
41
+ var import_shared = require("@rsbuild/shared");
42
+ var import_locale = require("../locale");
43
+ const devCommand = async (program, api) => {
44
+ const runner = api.useHookRunners();
45
+ const devToolMetas = await runner.registerDev();
46
+ const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("--web-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.webOnly)).action(async (options) => {
47
+ const { dev } = await Promise.resolve().then(() => __toESM(require("./dev")));
48
+ await dev(api, options);
49
+ });
50
+ for (const meta of devToolMetas) {
51
+ if (!meta.subCommands) {
52
+ continue;
53
+ }
54
+ for (const subCmd of meta.subCommands) {
55
+ devProgram.command(subCmd).action(async (options = {}) => {
56
+ const { appDirectory } = api.useAppContext();
57
+ const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
58
+ await runner.beforeDevTask(meta);
59
+ await meta.action(options, {
60
+ isTsProject: isTypescript(appDirectory)
61
+ });
62
+ });
63
+ }
64
+ }
65
+ };
66
+ const buildCommand = async (program, api) => {
67
+ const runner = api.useHookRunners();
68
+ const platformBuilders = await runner.registerBuildPlatform();
69
+ const buildProgram = program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).action(async (options) => {
70
+ const { build } = await Promise.resolve().then(() => __toESM(require("./build")));
71
+ await build(api, options);
72
+ });
73
+ for (const platformBuilder of platformBuilders) {
74
+ const platforms = (0, import_shared.castArray)(platformBuilder.platform);
75
+ for (const platform of platforms) {
76
+ buildProgram.command(platform).action(async () => {
77
+ const { appDirectory } = api.useAppContext();
78
+ const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
79
+ await runner.beforeBuildPlatform(platformBuilders);
80
+ await platformBuilder.build(platform, {
81
+ isTsProject: isTypescript(appDirectory)
82
+ });
83
+ });
84
+ }
85
+ }
86
+ };
87
+ const serverCommand = (program, api) => {
88
+ program.command("serve").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.serve.describe)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async () => {
89
+ const { start } = await Promise.resolve().then(() => __toESM(require("./serve")));
90
+ await start(api);
91
+ });
92
+ };
93
+ const deployCommand = (program, api) => {
94
+ program.command("deploy").usage("[options]").option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-s --skip-build", import_locale.i18n.t(import_locale.localeKeys.command.shared.skipBuild)).description(import_locale.i18n.t(import_locale.localeKeys.command.deploy.describe)).action(async (options) => {
95
+ if (!options.skipBuild) {
96
+ const { build } = await Promise.resolve().then(() => __toESM(require("./build")));
97
+ await build(api);
98
+ }
99
+ const { deploy } = await Promise.resolve().then(() => __toESM(require("./deploy")));
100
+ await deploy(api, options);
101
+ process.exit(0);
102
+ });
103
+ };
104
+ const newCommand = (program, locale) => {
105
+ program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("--config-file <configFile>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--lang <lang>", import_locale.i18n.t(import_locale.localeKeys.command.new.lang)).option("-c, --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.new.config)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option("--dist-tag <tag>", import_locale.i18n.t(import_locale.localeKeys.command.new.distTag)).option("--registry", import_locale.i18n.t(import_locale.localeKeys.command.new.registry)).option("--no-need-install", import_locale.i18n.t(import_locale.localeKeys.command.shared.noNeedInstall)).action(async (options) => {
106
+ await (0, import_utils.newAction)({
107
+ ...options,
108
+ locale: options.lang || locale
109
+ }, "mwa");
110
+ });
111
+ };
112
+ const inspectCommand = (program, api) => {
113
+ program.command("inspect").description("inspect the internal configs").option(`--env <env>`, import_locale.i18n.t(import_locale.localeKeys.command.inspect.env), "development").option("--output <output>", import_locale.i18n.t(import_locale.localeKeys.command.inspect.output), "/").option("--verbose", import_locale.i18n.t(import_locale.localeKeys.command.inspect.verbose)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async (options) => {
114
+ const { inspect } = await Promise.resolve().then(() => __toESM(require("./inspect")));
115
+ inspect(api, options);
116
+ });
117
+ };
118
+ const upgradeCommand = (program) => {
119
+ program.command("upgrade").allowUnknownOption().option("-h --help", "Show help").action(async () => {
120
+ await (0, import_utils.upgradeAction)();
121
+ });
122
+ };
21
123
  // Annotate the CommonJS export names for ESM import in node:
22
124
  0 && (module.exports = {
23
- ...require("./dev"),
24
- ...require("./build"),
25
- ...require("./serve")
125
+ buildCommand,
126
+ deployCommand,
127
+ devCommand,
128
+ inspectCommand,
129
+ newCommand,
130
+ serverCommand,
131
+ upgradeCommand
26
132
  });
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,29 +17,40 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var serve_exports = {};
20
30
  __export(serve_exports, {
21
31
  start: () => start
22
32
  });
23
33
  module.exports = __toCommonJS(serve_exports);
34
+ var import_path = __toESM(require("path"));
24
35
  var import_utils = require("@modern-js/utils");
25
36
  var import_prod_server = require("@modern-js/prod-server");
26
37
  var import_printInstructions = require("../utils/printInstructions");
27
- var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
38
+ var import_loadPlugins = require("../utils/loadPlugins");
28
39
  const start = async (api) => {
29
40
  var _userConfig_source, _userConfig_output_distPath;
30
41
  const appContext = api.useAppContext();
31
42
  const userConfig = api.useResolvedConfigContext();
32
43
  const hookRunners = api.useHookRunners();
33
- const { distDirectory, appDirectory, port, serverConfigFile, metaName, serverRoutes } = appContext;
44
+ const { distDirectory, appDirectory, port, metaName, serverRoutes, serverConfigFile } = appContext;
34
45
  import_utils.logger.info(`Starting production server...`);
35
46
  const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
36
47
  let runMode;
37
48
  if (apiOnly) {
38
49
  runMode = "apiOnly";
39
50
  }
40
- const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
51
+ const meta = (0, import_utils.getMeta)(metaName);
52
+ const serverConfigPath = import_path.default.resolve(distDirectory, import_utils.SERVER_DIR, `${meta}.server`);
53
+ const pluginInstances = await (0, import_loadPlugins.loadServerPlugins)(api, appDirectory);
41
54
  const app = await (0, import_prod_server.createProdServer)({
42
55
  metaName,
43
56
  pwd: distDirectory,
@@ -50,14 +63,15 @@ const start = async (api) => {
50
63
  }
51
64
  },
52
65
  routes: serverRoutes,
66
+ plugins: pluginInstances,
67
+ serverConfigFile,
68
+ serverConfigPath,
53
69
  appContext: {
54
70
  appDirectory,
55
71
  sharedDirectory: (0, import_utils.getTargetDir)(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
56
72
  apiDirectory: (0, import_utils.getTargetDir)(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
57
73
  lambdaDirectory: (0, import_utils.getTargetDir)(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
58
74
  },
59
- serverConfigFile,
60
- internalPlugins: serverInternalPlugins,
61
75
  runMode
62
76
  });
63
77
  app.listen(port, async () => {
package/dist/cjs/hooks.js CHANGED
@@ -30,10 +30,15 @@ const hooks = {
30
30
  modifyAsyncEntry: (0, import_plugin.createAsyncWaterfall)(),
31
31
  modifyFileSystemRoutes: (0, import_plugin.createAsyncWaterfall)(),
32
32
  modifyServerRoutes: (0, import_plugin.createAsyncWaterfall)(),
33
+ /** add entry point info to entrypoints array */
34
+ modifyEntrypoints: (0, import_plugin.createAsyncWaterfall)(),
35
+ /** add entry type */
36
+ checkEntryPoint: (0, import_plugin.createAsyncWaterfall)(),
33
37
  htmlPartials: (0, import_plugin.createAsyncWaterfall)(),
34
38
  beforeGenerateRoutes: (0, import_plugin.createAsyncWaterfall)(),
35
39
  addDefineTypes: (0, import_plugin.createAsyncWaterfall)(),
36
40
  collectServerPlugins: (0, import_plugin.createAsyncWaterfall)(),
41
+ _internalServerPlugins: (0, import_plugin.createAsyncWaterfall)(),
37
42
  beforeDev: (0, import_plugin.createAsyncWorkflow)(),
38
43
  afterDev: (0, import_plugin.createAsyncWorkflow)(),
39
44
  beforeCreateCompiler: (0, import_plugin.createAsyncWorkflow)(),
package/dist/cjs/index.js CHANGED
@@ -30,74 +30,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var src_exports = {};
31
31
  __export(src_exports, {
32
32
  appTools: () => appTools,
33
- buildCommand: () => buildCommand,
34
33
  default: () => src_default,
35
- dev: () => import_commands.dev,
36
- devCommand: () => devCommand,
34
+ dev: () => import_dev.dev,
37
35
  mergeConfig: () => import_core.mergeConfig
38
36
  });
39
37
  module.exports = __toCommonJS(src_exports);
40
38
  var import_path = __toESM(require("path"));
41
39
  var import_plugin_lint = require("@modern-js/plugin-lint");
42
40
  var import_utils = require("@modern-js/utils");
43
- var import_lodash = require("@modern-js/utils/lodash");
44
41
  var import_language_detector = require("@modern-js/plugin-i18n/language-detector");
45
- var import_analyze = __toESM(require("./analyze"));
46
- var import_initialize = __toESM(require("./initialize"));
47
- var import_hooks = require("./hooks");
48
- var import_locale = require("./locale");
42
+ var import_initialize = __toESM(require("./plugins/initialize"));
43
+ var import_analyze = __toESM(require("./plugins/analyze"));
49
44
  var import_serverBuild = __toESM(require("./plugins/serverBuild"));
50
45
  var import_deploy = __toESM(require("./plugins/deploy"));
46
+ var import_hooks = require("./hooks");
47
+ var import_locale = require("./locale");
51
48
  var import_restart = require("./utils/restart");
52
49
  var import_generateWatchFiles = require("./utils/generateWatchFiles");
53
- var import_core = require("@modern-js/core");
54
50
  var import_commands = require("./commands");
51
+ var import_dev = require("./commands/dev");
52
+ var import_core = require("@modern-js/core");
55
53
  __reExport(src_exports, require("./defineConfig"), module.exports);
56
54
  __reExport(src_exports, require("./types"), module.exports);
57
- const devCommand = async (program, api) => {
58
- const runner = api.useHookRunners();
59
- const devToolMetas = await runner.registerDev();
60
- const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("--web-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.webOnly)).action(async (options) => {
61
- const { dev: dev2 } = await Promise.resolve().then(() => __toESM(require("./commands/dev")));
62
- await dev2(api, options);
63
- });
64
- for (const meta of devToolMetas) {
65
- if (!meta.subCommands) {
66
- continue;
67
- }
68
- for (const subCmd of meta.subCommands) {
69
- devProgram.command(subCmd).action(async (options = {}) => {
70
- const { appDirectory } = api.useAppContext();
71
- const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
72
- await runner.beforeDevTask(meta);
73
- await meta.action(options, {
74
- isTsProject: isTypescript(appDirectory)
75
- });
76
- });
77
- }
78
- }
79
- };
80
- const buildCommand = async (program, api) => {
81
- const runner = api.useHookRunners();
82
- const platformBuilders = await runner.registerBuildPlatform();
83
- const buildProgram = program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).action(async (options) => {
84
- const { build } = await Promise.resolve().then(() => __toESM(require("./commands/build")));
85
- await build(api, options);
86
- });
87
- for (const platformBuilder of platformBuilders) {
88
- const platforms = (0, import_lodash.castArray)(platformBuilder.platform);
89
- for (const platform of platforms) {
90
- buildProgram.command(platform).action(async () => {
91
- const { appDirectory } = api.useAppContext();
92
- const { isTypescript } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
93
- await runner.beforeBuildPlatform(platformBuilders);
94
- await platformBuilder.build(platform, {
95
- isTsProject: isTypescript(appDirectory)
96
- });
97
- });
98
- }
99
- }
100
- };
101
55
  const appTools = (options = {
102
56
  bundler: "webpack"
103
57
  }) => ({
@@ -148,34 +102,13 @@ const appTools = (options = {
148
102
  }
149
103
  },
150
104
  async commands({ program }) {
151
- await devCommand(program, api);
152
- await buildCommand(program, api);
153
- program.command("serve").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.serve.describe)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async () => {
154
- const { start } = await Promise.resolve().then(() => __toESM(require("./commands/serve")));
155
- await start(api);
156
- });
157
- program.command("deploy").usage("[options]").option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-s --skip-build", import_locale.i18n.t(import_locale.localeKeys.command.shared.skipBuild)).description(import_locale.i18n.t(import_locale.localeKeys.command.deploy.describe)).action(async (options2) => {
158
- if (!options2.skipBuild) {
159
- const { build } = await Promise.resolve().then(() => __toESM(require("./commands/build")));
160
- await build(api);
161
- }
162
- const { deploy } = await Promise.resolve().then(() => __toESM(require("./commands/deploy")));
163
- await deploy(api, options2);
164
- process.exit(0);
165
- });
166
- program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("--config-file <configFile>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--lang <lang>", import_locale.i18n.t(import_locale.localeKeys.command.new.lang)).option("-c, --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.new.config)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option("--dist-tag <tag>", import_locale.i18n.t(import_locale.localeKeys.command.new.distTag)).option("--registry", import_locale.i18n.t(import_locale.localeKeys.command.new.registry)).option("--no-need-install", import_locale.i18n.t(import_locale.localeKeys.command.shared.noNeedInstall)).action(async (options2) => {
167
- await (0, import_utils.newAction)({
168
- ...options2,
169
- locale: options2.lang || locale
170
- }, "mwa");
171
- });
172
- program.command("inspect").description("inspect the internal configs").option(`--env <env>`, import_locale.i18n.t(import_locale.localeKeys.command.inspect.env), "development").option("--output <output>", import_locale.i18n.t(import_locale.localeKeys.command.inspect.output), "/").option("--verbose", import_locale.i18n.t(import_locale.localeKeys.command.inspect.verbose)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).action(async (options2) => {
173
- const { inspect } = await Promise.resolve().then(() => __toESM(require("./commands/inspect")));
174
- inspect(api, options2);
175
- });
176
- program.command("upgrade").allowUnknownOption().option("-h --help", "Show help").action(async () => {
177
- await (0, import_utils.upgradeAction)();
178
- });
105
+ await (0, import_commands.devCommand)(program, api);
106
+ await (0, import_commands.buildCommand)(program, api);
107
+ (0, import_commands.serverCommand)(program, api);
108
+ (0, import_commands.deployCommand)(program, api);
109
+ (0, import_commands.newCommand)(program, locale);
110
+ (0, import_commands.inspectCommand)(program, api);
111
+ (0, import_commands.upgradeCommand)(program);
179
112
  },
180
113
  async prepare() {
181
114
  const command = (0, import_utils.getCommand)();
@@ -239,9 +172,7 @@ var src_default = appTools;
239
172
  // Annotate the CommonJS export names for ESM import in node:
240
173
  0 && (module.exports = {
241
174
  appTools,
242
- buildCommand,
243
175
  dev,
244
- devCommand,
245
176
  mergeConfig,
246
177
  ...require("./defineConfig"),
247
178
  ...require("./types")
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var constants_exports = {};
20
+ __export(constants_exports, {
21
+ APP_CONFIG_NAME: () => APP_CONFIG_NAME,
22
+ APP_INIT_EXPORTED: () => APP_INIT_EXPORTED,
23
+ APP_INIT_IMPORTED: () => APP_INIT_IMPORTED,
24
+ ENTRY_BOOTSTRAP_FILE_NAME: () => ENTRY_BOOTSTRAP_FILE_NAME,
25
+ ENTRY_POINT_FILE_NAME: () => ENTRY_POINT_FILE_NAME,
26
+ FILE_SYSTEM_ROUTES_FILE_NAME: () => FILE_SYSTEM_ROUTES_FILE_NAME,
27
+ HTML_PARTIALS_EXTENSIONS: () => HTML_PARTIALS_EXTENSIONS,
28
+ HTML_PARTIALS_FOLDER: () => HTML_PARTIALS_FOLDER,
29
+ INDEX_FILE_NAME: () => INDEX_FILE_NAME
30
+ });
31
+ module.exports = __toCommonJS(constants_exports);
32
+ const INDEX_FILE_NAME = "index";
33
+ const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
34
+ const ENTRY_POINT_FILE_NAME = "index.jsx";
35
+ const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
36
+ const HTML_PARTIALS_FOLDER = "html";
37
+ const HTML_PARTIALS_EXTENSIONS = [
38
+ ".htm",
39
+ ".html",
40
+ ".ejs"
41
+ ];
42
+ const APP_CONFIG_NAME = "config";
43
+ const APP_INIT_EXPORTED = "init";
44
+ const APP_INIT_IMPORTED = "appInit";
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ APP_CONFIG_NAME,
48
+ APP_INIT_EXPORTED,
49
+ APP_INIT_IMPORTED,
50
+ ENTRY_BOOTSTRAP_FILE_NAME,
51
+ ENTRY_POINT_FILE_NAME,
52
+ FILE_SYSTEM_ROUTES_FILE_NAME,
53
+ HTML_PARTIALS_EXTENSIONS,
54
+ HTML_PARTIALS_FOLDER,
55
+ INDEX_FILE_NAME
56
+ });