@modern-js/app-tools 2.34.1-alpha.1 → 2.35.1

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 (50) hide show
  1. package/dist/cjs/analyze/generateCode.js +3 -4
  2. package/dist/cjs/analyze/getFileSystemEntry.js +1 -2
  3. package/dist/cjs/analyze/getServerRoutes.js +4 -5
  4. package/dist/cjs/analyze/nestedRoutes.js +2 -2
  5. package/dist/cjs/analyze/templates.js +4 -4
  6. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +1 -2
  7. package/dist/cjs/builder/index.js +1 -1
  8. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +4 -20
  9. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -14
  10. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  11. package/dist/cjs/commands/build.js +2 -3
  12. package/dist/cjs/commands/inspect.js +1 -2
  13. package/dist/cjs/commands/serve.js +3 -3
  14. package/dist/cjs/index.js +127 -130
  15. package/dist/cjs/utils/config.js +1 -1
  16. package/dist/cjs/utils/printInstructions.js +1 -1
  17. package/dist/esm/analyze/generateCode.js +4 -4
  18. package/dist/esm/analyze/getFileSystemEntry.js +1 -2
  19. package/dist/esm/analyze/getServerRoutes.js +4 -5
  20. package/dist/esm/analyze/nestedRoutes.js +2 -2
  21. package/dist/esm/analyze/templates.js +4 -4
  22. package/dist/esm/builder/generator/createBuilderProviderConfig.js +1 -2
  23. package/dist/esm/builder/index.js +1 -1
  24. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +12 -43
  25. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +12 -14
  26. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  27. package/dist/esm/commands/build.js +3 -3
  28. package/dist/esm/commands/inspect.js +2 -2
  29. package/dist/esm/commands/serve.js +4 -4
  30. package/dist/esm/index.js +2 -3
  31. package/dist/esm/utils/config.js +2 -2
  32. package/dist/esm/utils/printInstructions.js +1 -1
  33. package/dist/esm-node/analyze/generateCode.js +3 -4
  34. package/dist/esm-node/analyze/getFileSystemEntry.js +1 -2
  35. package/dist/esm-node/analyze/getServerRoutes.js +4 -5
  36. package/dist/esm-node/analyze/nestedRoutes.js +2 -2
  37. package/dist/esm-node/analyze/templates.js +4 -4
  38. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +1 -2
  39. package/dist/esm-node/builder/index.js +1 -1
  40. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +4 -19
  41. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +12 -14
  42. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  43. package/dist/esm-node/commands/build.js +2 -3
  44. package/dist/esm-node/commands/inspect.js +1 -2
  45. package/dist/esm-node/commands/serve.js +4 -4
  46. package/dist/esm-node/index.js +127 -130
  47. package/dist/esm-node/utils/config.js +2 -2
  48. package/dist/esm-node/utils/printInstructions.js +1 -1
  49. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -0
  50. package/package.json +24 -25
@@ -74,13 +74,12 @@ ${initialize || ""}`);
74
74
  ${initialize || ""}`).join("\n");
75
75
  };
76
76
  const generateCode = async (appContext, config, entrypoints, api) => {
77
- var _config, _config1;
78
77
  const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
79
78
  const hookRunners = api.useHookRunners();
80
79
  const isV5 = (0, _utils.isRouterV5)(config);
81
80
  const getRoutes = isV5 ? _getClientRoutes.getClientRoutesLegacy : _getClientRoutes.getClientRoutes;
82
81
  const importsStatemets = /* @__PURE__ */ new Map();
83
- const oldVersion = typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.runtime.router) === "object" ? Boolean(((_config1 = config) === null || _config1 === void 0 ? void 0 : _config1.runtime.router).oldVersion) : false;
82
+ const oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
84
83
  await Promise.all(entrypoints.map(generateEntryCode));
85
84
  return {
86
85
  importsStatemets
@@ -89,7 +88,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
89
88
  const { entryName, isMainEntry, isAutoMount, fileSystemRoutes } = entrypoint;
90
89
  if (isAutoMount) {
91
90
  if (fileSystemRoutes) {
92
- var _config_output, _config2;
91
+ var _config_output;
93
92
  let initialRoutes = [];
94
93
  let nestedRoutes = null;
95
94
  if (entrypoint.entry) {
@@ -143,7 +142,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
143
142
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
144
143
  entryName: entrypoint.entryName,
145
144
  internalDirectory,
146
- splitRouteChunks: (_config2 = config2) === null || _config2 === void 0 ? void 0 : (_config_output = _config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
145
+ splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
147
146
  })
148
147
  });
149
148
  if (entrypoint.nestedRoutesEntry && (0, _utils.isUseSSRBundle)(config2)) {
@@ -80,8 +80,7 @@ const getFileSystemEntry = (appContext, config) => {
80
80
  const { source: { entriesDir, disableEntryDirs } } = config;
81
81
  let disabledDirs = [];
82
82
  if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
83
- var _disableEntryDirs;
84
- disabledDirs = (_disableEntryDirs = disableEntryDirs) === null || _disableEntryDirs === void 0 ? void 0 : _disableEntryDirs.map((dir) => (0, _utils.ensureAbsolutePath)(appDirectory, dir));
83
+ disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map((dir) => (0, _utils.ensureAbsolutePath)(appDirectory, dir));
85
84
  }
86
85
  const src = (0, _utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
87
86
  if (_fs.default.existsSync(src)) {
@@ -79,18 +79,17 @@ const applyRouteOptions = (original, routeOptions) => {
79
79
  return routes;
80
80
  };
81
81
  const collectHtmlRoutes = (entrypoints, appContext, config) => {
82
- var _deploy_worker, _deploy;
82
+ var _deploy_worker;
83
83
  const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
84
84
  const { packageName } = appContext;
85
- const workerSSR = (_deploy = deploy) === null || _deploy === void 0 ? void 0 : (_deploy_worker = _deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
85
+ const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
86
86
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
87
- var _routes, _routes1;
88
87
  const isMainEntry = entryName === (mainEntryName || _utils.MAIN_ENTRY_NAME);
89
88
  const entryOptions = (0, _utils.getEntryOptions)(entryName, isMainEntry, ssr, ssrByEntries, packageName);
90
89
  const isSSR = Boolean(entryOptions);
91
90
  const isWorker = Boolean(workerSSR);
92
91
  const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
93
- const { resHeaders } = ((_routes = routes) === null || _routes === void 0 ? void 0 : _routes[entryName]) || {};
92
+ const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
94
93
  let route = {
95
94
  urlPath: `/${isMainEntry ? "" : entryName}`,
96
95
  entryName,
@@ -102,7 +101,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
102
101
  worker: isWorker ? `${_utils.SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
103
102
  bundle: isSSR ? `${_utils.SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
104
103
  };
105
- if ((_routes1 = routes) === null || _routes1 === void 0 ? void 0 : _routes1.hasOwnProperty(entryName)) {
104
+ if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
106
105
  const routeOptions = (0, _utils.isPlainObject)(routes[entryName]) ? routes[entryName] : {
107
106
  route: routes[entryName]
108
107
  };
@@ -93,7 +93,7 @@ const optimizeRoute = (routeTree) => {
93
93
  }
94
94
  };
95
95
  const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion) => {
96
- var _routePath, _finalRoute_children;
96
+ var _finalRoute_children;
97
97
  if (!await _utils.fs.pathExists(dirname)) {
98
98
  return null;
99
99
  }
@@ -113,7 +113,7 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion)
113
113
  }
114
114
  routePath = replaceDynamicPath(routePath);
115
115
  const route = {
116
- path: (_routePath = routePath) === null || _routePath === void 0 ? void 0 : _routePath.replace(/\$$/, "?"),
116
+ path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
117
117
  children: [],
118
118
  isRoot
119
119
  };
@@ -108,8 +108,8 @@ const routesForServer = ({ routes }) => {
108
108
  const traverseRouteTree = (route) => {
109
109
  let children;
110
110
  if ("children" in route && route.children) {
111
- var _route_children, _route;
112
- children = (_route = route) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
111
+ var _route_children;
112
+ children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
113
113
  }
114
114
  let loader;
115
115
  if (route.type === "nested") {
@@ -177,8 +177,8 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
177
177
  const traverseRouteTree = (route) => {
178
178
  let children;
179
179
  if ("children" in route && route.children) {
180
- var _route_children, _route;
181
- children = (_route = route) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
180
+ var _route_children;
181
+ children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
182
182
  }
183
183
  let loading;
184
184
  let error;
@@ -10,10 +10,9 @@ Object.defineProperty(exports, "createBuilderProviderConfig", {
10
10
  });
11
11
  const _createCopyPattern = require("../builder-webpack/createCopyPattern");
12
12
  function modifyOutputConfig(config, appContext) {
13
- var _copy;
14
13
  const defaultCopyPattern = (0, _createCopyPattern.createUploadPattern)(appContext, config);
15
14
  const { copy } = config.output;
16
- const copyOptions = Array.isArray(copy) ? copy : (_copy = copy) === null || _copy === void 0 ? void 0 : _copy.patterns;
15
+ const copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
17
16
  const builderCopy = [
18
17
  ...copyOptions || [],
19
18
  defaultCopyPattern
@@ -16,7 +16,7 @@ async function createBuilderGenerator(bundler) {
16
16
  const { createRspackBuilderForModern } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./builder-rspack")));
17
17
  const { getRspackVersion } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/builder-rspack-provider")));
18
18
  const version = await getRspackVersion();
19
- _utils.logger.info(`Using Rspack v${version} 🦀`);
19
+ _utils.logger.info(`Using Rspack v${version}`);
20
20
  return createRspackBuilderForModern;
21
21
  } catch (_) {
22
22
  throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "builderPluginAdapterHtml", {
8
8
  return builderPluginAdapterHtml;
9
9
  }
10
10
  });
11
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
11
  const _buildershared = require("@modern-js/builder-shared");
13
12
  const _utils = require("@modern-js/utils");
14
13
  const _lodash = require("@modern-js/utils/lodash");
@@ -27,35 +26,20 @@ const builderPluginAdapterHtml = (options) => ({
27
26
  HtmlBundlerPlugin
28
27
  });
29
28
  await injectAssetPrefix({
30
- api,
31
29
  chain
32
30
  });
33
31
  }
34
32
  });
35
33
  }
36
34
  });
37
- async function injectAssetPrefix({ api, chain }) {
35
+ async function injectAssetPrefix({ chain }) {
38
36
  const entries = chain.entryPoints.entries() || {};
39
37
  const entryNames = Object.keys(entries);
40
38
  const assetPrefix = (0, _utils.removeTailSlash)(chain.output.get("publicPath") || "");
41
39
  const code = `window.__assetPrefix__ = '${assetPrefix}';`;
42
- const isRspack = api.context.bundlerType === "rspack";
43
- if (isRspack) {
44
- const fileName = "rspack-asset-prefix";
45
- const { default: RspackVirtualModulePlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("rspack-plugin-virtual-module")));
46
- entryNames.forEach((entryName) => {
47
- entries[entryName].prepend(fileName);
48
- chain.plugin("rspack-asset-prefix").use(RspackVirtualModulePlugin, [
49
- {
50
- [fileName]: code
51
- }
52
- ]);
53
- });
54
- } else {
55
- entryNames.forEach((entryName) => {
56
- entries[entryName].prepend((0, _buildershared.createVirtualModule)(code));
57
- });
58
- }
40
+ entryNames.forEach((entryName) => {
41
+ entries[entryName].prepend((0, _buildershared.createVirtualModule)(code));
42
+ });
59
43
  }
60
44
  function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugin }) {
61
45
  const { normalizedConfig: modernConfig, appContext } = options;
@@ -31,7 +31,7 @@ const builderPluginAdapterSSR = (options) => ({
31
31
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
32
32
  const builderConfig = api.getNormalizedConfig();
33
33
  const { normalizedConfig: normalizedConfig2 } = options;
34
- applyRouterPlugin(chain, options, HtmlBundlerPlugin);
34
+ applyRouterPlugin(chain, CHAIN_ID.PLUGIN.ROUTER_MANIFEST, options, HtmlBundlerPlugin);
35
35
  if ((0, _utils.isSSR)(normalizedConfig2)) {
36
36
  await applySSRLoaderEntry(chain, options, isServer);
37
37
  applySSRDataLoader(chain, options);
@@ -58,13 +58,12 @@ const builderPluginAdapterSSR = (options) => ({
58
58
  }
59
59
  });
60
60
  const isStreamingSSR = (userConfig) => {
61
- var _server;
62
61
  const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
63
62
  const { server } = userConfig;
64
63
  if (isStreaming(server.ssr)) {
65
64
  return true;
66
65
  }
67
- if (((_server = server) === null || _server === void 0 ? void 0 : _server.ssrByEntries) && typeof server.ssrByEntries === "object") {
66
+ if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
68
67
  for (const name of Object.keys(server.ssrByEntries)) {
69
68
  if (isStreaming(server.ssrByEntries[name])) {
70
69
  return true;
@@ -80,17 +79,17 @@ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerP
80
79
  ]);
81
80
  }
82
81
  }
83
- function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
84
- var _normalizedConfig_runtime, _normalizedConfig, _routerConfig, _normalizedConfig_deploy_worker;
82
+ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
83
+ var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
85
84
  const { appContext, normalizedConfig } = options;
86
85
  const { entrypoints } = appContext;
87
86
  const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
88
- const routerConfig = (_normalizedConfig = normalizedConfig) === null || _normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = _normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
89
- const routerManifest = Boolean((_routerConfig = routerConfig) === null || _routerConfig === void 0 ? void 0 : _routerConfig.manifest);
87
+ const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
88
+ const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
90
89
  const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
91
90
  if (existNestedRoutes || routerManifest || workerSSR) {
92
91
  var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
93
- chain.plugin("route-plugin").use(_bundlerPlugins.RouterPlugin, [
92
+ chain.plugin(pluginName).use(_bundlerPlugins.RouterPlugin, [
94
93
  {
95
94
  HtmlBundlerPlugin,
96
95
  enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
@@ -103,21 +102,21 @@ function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
103
102
  }
104
103
  }
105
104
  function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
106
- var _outputConfig, _this, _outputConfig1, _outputConfig2, _outputConfig3;
105
+ var _this;
107
106
  const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
108
107
  const entries = chain.entryPoints.entries();
109
- if (isProd && (((_outputConfig = outputConfig) === null || _outputConfig === void 0 ? void 0 : _outputConfig.ssg) === true || typeof ((_this = (_outputConfig1 = outputConfig) === null || _outputConfig1 === void 0 ? void 0 : _outputConfig1.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
108
+ if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof ((_this = outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
110
109
  return;
111
110
  }
112
111
  if (typeof entries === "undefined") {
113
112
  throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
114
113
  }
115
114
  const entryNames = Object.keys(entries);
116
- if (isProd && entryNames.length === 1 && ((_outputConfig2 = outputConfig) === null || _outputConfig2 === void 0 ? void 0 : _outputConfig2.ssg)) {
115
+ if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
117
116
  return;
118
117
  }
119
118
  const ssgEntries = [];
120
- if (isProd && ((_outputConfig3 = outputConfig) === null || _outputConfig3 === void 0 ? void 0 : _outputConfig3.ssg)) {
119
+ if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
121
120
  const { ssg } = outputConfig;
122
121
  entryNames.forEach((name) => {
123
122
  if (ssg[name]) {
@@ -127,8 +126,7 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
127
126
  }
128
127
  const { ssr, ssrByEntries } = serverConfig || {};
129
128
  entryNames.forEach((name) => {
130
- var _ssrByEntries, _ssrByEntries1;
131
- if (!ssgEntries.includes(name) && (ssr && ((_ssrByEntries = ssrByEntries) === null || _ssrByEntries === void 0 ? void 0 : _ssrByEntries[name]) === false || !ssr && !((_ssrByEntries1 = ssrByEntries) === null || _ssrByEntries1 === void 0 ? void 0 : _ssrByEntries1[name]))) {
129
+ 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]))) {
132
130
  chain.entryPoints.delete(name);
133
131
  }
134
132
  });
@@ -129,10 +129,9 @@ class RouterPlugin {
129
129
  let relatedAssets = {};
130
130
  if (entryChunkFiles.length > 1) {
131
131
  Object.keys(routeAssets).forEach((routeId) => {
132
- var _chunkNames;
133
132
  const segments = routeId.split("_");
134
133
  const chunkName = segments[0];
135
- if ((_chunkNames = chunkNames) === null || _chunkNames === void 0 ? void 0 : _chunkNames.includes(chunkName)) {
134
+ if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
136
135
  relatedAssets[routeId] = routeAssets[routeId];
137
136
  }
138
137
  });
@@ -204,6 +203,7 @@ class RouterPlugin {
204
203
  });
205
204
  }
206
205
  constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
206
+ _define_property._(this, "name", "RouterPlugin");
207
207
  _define_property._(this, "HtmlBundlerPlugin", void 0);
208
208
  _define_property._(this, "enableInlineRouteManifests", void 0);
209
209
  _define_property._(this, "staticJsDir", void 0);
@@ -13,8 +13,7 @@ const _utils = require("@modern-js/utils");
13
13
  const _routes = require("../utils/routes");
14
14
  const _config = require("../utils/config");
15
15
  const build = async (api, options) => {
16
- var _options;
17
- if ((_options = options) === null || _options === void 0 ? void 0 : _options.analyze) {
16
+ if (options === null || options === void 0 ? void 0 : options.analyze) {
18
17
  process.env.BUNDLE_ANALYZE = "true";
19
18
  }
20
19
  let resolvedConfig = api.useResolvedConfigContext();
@@ -50,7 +49,7 @@ const build = async (api, options) => {
50
49
  distDirectory,
51
50
  configFile: serverConfigFile
52
51
  });
53
- _utils.logger.info("Create a production build...\n");
52
+ _utils.logger.info("Starting production build...");
54
53
  if (!appContext.builder) {
55
54
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
56
55
  }
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "inspect", {
10
10
  });
11
11
  const _path = require("path");
12
12
  const inspect = async (api, options) => {
13
- var _appContext;
14
13
  const appContext = api.useAppContext();
15
14
  if (!appContext.builder) {
16
15
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
@@ -18,7 +17,7 @@ const inspect = async (api, options) => {
18
17
  return appContext.builder.inspectConfig({
19
18
  env: options.env,
20
19
  verbose: options.verbose,
21
- outputPath: (0, _path.join)((_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.builder.context.distPath, options.output),
20
+ outputPath: (0, _path.join)(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
22
21
  writeToDisk: true
23
22
  });
24
23
  };
@@ -15,13 +15,13 @@ const _printInstructions = require("../utils/printInstructions");
15
15
  const _createServer = require("../utils/createServer");
16
16
  const _getServerInternalPlugins = require("../utils/getServerInternalPlugins");
17
17
  const start = async (api) => {
18
- var _userConfig_source, _userConfig, _userConfig_output_distPath;
18
+ var _userConfig_source, _userConfig_output_distPath;
19
19
  const appContext = api.useAppContext();
20
20
  const userConfig = api.useResolvedConfigContext();
21
21
  const hookRunners = api.useHookRunners();
22
22
  const { appDirectory, port, serverConfigFile, metaName } = appContext;
23
- _utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
24
- const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, (_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_source = _userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
23
+ _utils.logger.info(`Starting production server...`);
24
+ const apiOnly = await (0, _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);
25
25
  const serverInternalPlugins = await (0, _getServerInternalPlugins.getServerInternalPlugins)(api);
26
26
  const app = await (0, _prodserver.default)({
27
27
  pwd: appDirectory,
package/dist/cjs/index.js CHANGED
@@ -93,140 +93,137 @@ const buildCommand = async (program, api) => {
93
93
  };
94
94
  const appTools = (options = {
95
95
  bundler: "webpack"
96
- }) => {
97
- var _options, _options1;
98
- return {
99
- name: "@modern-js/app-tools",
100
- post: [
101
- "@modern-js/plugin-initialize",
102
- "@modern-js/plugin-analyze",
103
- "@modern-js/plugin-ssr",
104
- "@modern-js/plugin-document",
105
- "@modern-js/plugin-state",
106
- "@modern-js/plugin-router",
107
- "@modern-js/plugin-router-v5",
108
- "@modern-js/plugin-polyfill"
109
- ],
110
- registerHook: _hooks.hooks,
111
- usePlugins: [
112
- (0, _initialize.default)({
113
- bundler: ((_options = options) === null || _options === void 0 ? void 0 : _options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
114
- }),
115
- (0, _analyze.default)({
116
- bundler: ((_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.bundler) === "experimental-rspack" ? "rspack" : "webpack"
117
- }),
118
- (0, _pluginlint.lintPlugin)()
119
- ],
120
- setup: (api) => {
121
- const appContext = api.useAppContext();
122
- api.setAppContext({
123
- ...appContext,
124
- toolsType: "app-tools"
125
- });
126
- const nestedRoutes = {};
127
- const locale = (0, _languagedetector.getLocaleLanguage)();
128
- _locale.i18n.changeLanguage({
129
- locale
130
- });
131
- return {
132
- async beforeConfig() {
133
- var _userConfig_output;
134
- const userConfig = api.useConfigContext();
135
- const appContext2 = api.useAppContext();
136
- if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
137
- api.setAppContext({
138
- ...appContext2,
139
- internalDirectory: _path.default.resolve(appContext2.appDirectory, userConfig.output.tempDir)
140
- });
141
- }
142
- },
143
- async commands({ program }) {
144
- await devCommand(program, api);
145
- await buildCommand(program, api);
146
- program.command("serve").usage("[options]").description(_locale.i18n.t(_locale.localeKeys.command.serve.describe)).option("--api-only", _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async () => {
147
- const { start } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./commands/serve")));
148
- await start(api);
149
- });
150
- program.command("deploy").usage("[options]").option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).option("-s --skip-build", _locale.i18n.t(_locale.localeKeys.command.shared.skipBuild)).description(_locale.i18n.t(_locale.localeKeys.command.deploy.describe)).action(async (options2) => {
151
- if (!options2.skipBuild) {
152
- const { build } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./commands/build")));
153
- await build(api);
154
- }
155
- const { deploy } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./commands/deploy")));
156
- await deploy(api, options2);
157
- process.exit(0);
96
+ }) => ({
97
+ name: "@modern-js/app-tools",
98
+ post: [
99
+ "@modern-js/plugin-initialize",
100
+ "@modern-js/plugin-analyze",
101
+ "@modern-js/plugin-ssr",
102
+ "@modern-js/plugin-document",
103
+ "@modern-js/plugin-state",
104
+ "@modern-js/plugin-router",
105
+ "@modern-js/plugin-router-v5",
106
+ "@modern-js/plugin-polyfill"
107
+ ],
108
+ registerHook: _hooks.hooks,
109
+ usePlugins: [
110
+ (0, _initialize.default)({
111
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
112
+ }),
113
+ (0, _analyze.default)({
114
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
115
+ }),
116
+ (0, _pluginlint.lintPlugin)()
117
+ ],
118
+ setup: (api) => {
119
+ const appContext = api.useAppContext();
120
+ api.setAppContext({
121
+ ...appContext,
122
+ toolsType: "app-tools"
123
+ });
124
+ const nestedRoutes = {};
125
+ const locale = (0, _languagedetector.getLocaleLanguage)();
126
+ _locale.i18n.changeLanguage({
127
+ locale
128
+ });
129
+ return {
130
+ async beforeConfig() {
131
+ var _userConfig_output;
132
+ const userConfig = api.useConfigContext();
133
+ const appContext2 = api.useAppContext();
134
+ if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
135
+ api.setAppContext({
136
+ ...appContext2,
137
+ internalDirectory: _path.default.resolve(appContext2.appDirectory, userConfig.output.tempDir)
158
138
  });
159
- program.command("new").usage("[options]").description(_locale.i18n.t(_locale.localeKeys.command.new.describe)).option("--config-file <configFile>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).option("--lang <lang>", _locale.i18n.t(_locale.localeKeys.command.new.lang)).option("-c, --config <config>", _locale.i18n.t(_locale.localeKeys.command.new.config)).option("-d, --debug", _locale.i18n.t(_locale.localeKeys.command.new.debug), false).option("--dist-tag <tag>", _locale.i18n.t(_locale.localeKeys.command.new.distTag)).option("--registry", _locale.i18n.t(_locale.localeKeys.command.new.registry)).option("--no-need-install", _locale.i18n.t(_locale.localeKeys.command.shared.noNeedInstall)).action(async (options2) => {
160
- const { MWANewAction } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/new-action")));
161
- await MWANewAction({
162
- ...options2,
163
- locale: options2.lang || locale
164
- });
139
+ }
140
+ },
141
+ async commands({ program }) {
142
+ await devCommand(program, api);
143
+ await buildCommand(program, api);
144
+ program.command("serve").usage("[options]").description(_locale.i18n.t(_locale.localeKeys.command.serve.describe)).option("--api-only", _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async () => {
145
+ const { start } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./commands/serve")));
146
+ await start(api);
147
+ });
148
+ program.command("deploy").usage("[options]").option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).option("-s --skip-build", _locale.i18n.t(_locale.localeKeys.command.shared.skipBuild)).description(_locale.i18n.t(_locale.localeKeys.command.deploy.describe)).action(async (options2) => {
149
+ if (!options2.skipBuild) {
150
+ const { build } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./commands/build")));
151
+ await build(api);
152
+ }
153
+ const { deploy } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./commands/deploy")));
154
+ await deploy(api, options2);
155
+ process.exit(0);
156
+ });
157
+ program.command("new").usage("[options]").description(_locale.i18n.t(_locale.localeKeys.command.new.describe)).option("--config-file <configFile>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).option("--lang <lang>", _locale.i18n.t(_locale.localeKeys.command.new.lang)).option("-c, --config <config>", _locale.i18n.t(_locale.localeKeys.command.new.config)).option("-d, --debug", _locale.i18n.t(_locale.localeKeys.command.new.debug), false).option("--dist-tag <tag>", _locale.i18n.t(_locale.localeKeys.command.new.distTag)).option("--registry", _locale.i18n.t(_locale.localeKeys.command.new.registry)).option("--no-need-install", _locale.i18n.t(_locale.localeKeys.command.shared.noNeedInstall)).action(async (options2) => {
158
+ const { MWANewAction } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/new-action")));
159
+ await MWANewAction({
160
+ ...options2,
161
+ locale: options2.lang || locale
165
162
  });
166
- program.command("inspect").description("inspect the internal configs").option(`--env <env>`, _locale.i18n.t(_locale.localeKeys.command.inspect.env), "development").option("--output <output>", _locale.i18n.t(_locale.localeKeys.command.inspect.output), "/").option("--verbose", _locale.i18n.t(_locale.localeKeys.command.inspect.verbose)).option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async (options2) => {
167
- const { inspect } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./commands/inspect")));
168
- inspect(api, options2);
163
+ });
164
+ program.command("inspect").description("inspect the internal configs").option(`--env <env>`, _locale.i18n.t(_locale.localeKeys.command.inspect.env), "development").option("--output <output>", _locale.i18n.t(_locale.localeKeys.command.inspect.output), "/").option("--verbose", _locale.i18n.t(_locale.localeKeys.command.inspect.verbose)).option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async (options2) => {
165
+ const { inspect } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./commands/inspect")));
166
+ inspect(api, options2);
167
+ });
168
+ const { defineCommand } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/upgrade")));
169
+ defineCommand(program.command("upgrade").option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).option("--no-need-install", _locale.i18n.t(_locale.localeKeys.command.shared.noNeedInstall)));
170
+ },
171
+ async prepare() {
172
+ const command = (0, _utils.getCommand)();
173
+ if (command === "deploy") {
174
+ const isSkipBuild = [
175
+ "-s",
176
+ "--skip-build"
177
+ ].some((tag) => {
178
+ return (0, _utils.getArgv)().includes(tag);
169
179
  });
170
- const { defineCommand } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/upgrade")));
171
- defineCommand(program.command("upgrade").option("-c --config <config>", _locale.i18n.t(_locale.localeKeys.command.shared.config)).option("--no-need-install", _locale.i18n.t(_locale.localeKeys.command.shared.noNeedInstall)));
172
- },
173
- async prepare() {
174
- const command = (0, _utils.getCommand)();
175
- if (command === "deploy") {
176
- const isSkipBuild = [
177
- "-s",
178
- "--skip-build"
179
- ].some((tag) => {
180
- return (0, _utils.getArgv)().includes(tag);
181
- });
182
- if (isSkipBuild) {
183
- return;
184
- }
185
- }
186
- if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
187
- const resolvedConfig = api.useResolvedConfigContext();
188
- if (resolvedConfig.output.cleanDistPath) {
189
- const appContext2 = api.useAppContext();
190
- await (0, _utils.emptyDir)(appContext2.distDirectory);
191
- }
180
+ if (isSkipBuild) {
181
+ return;
192
182
  }
193
- },
194
- async watchFiles() {
195
- const appContext2 = api.useAppContext();
196
- const config = api.useResolvedConfigContext();
197
- return await (0, _generateWatchFiles.generateWatchFiles)(appContext2, config.source.configDir);
198
- },
199
- // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
200
- async fileChange(e) {
201
- const { filename, eventType, isPrivate } = e;
202
- if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
203
- const { closeServer } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./utils/createServer")));
204
- await closeServer();
205
- await (0, _restart.restart)(api.useHookRunners(), filename);
183
+ }
184
+ if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
185
+ const resolvedConfig = api.useResolvedConfigContext();
186
+ if (resolvedConfig.output.cleanDistPath) {
187
+ const appContext2 = api.useAppContext();
188
+ await (0, _utils.emptyDir)(appContext2.distDirectory);
206
189
  }
207
- },
208
- async beforeRestart() {
209
- (0, _utils.cleanRequireCache)([
210
- require.resolve("./analyze")
211
- ]);
212
- },
213
- async modifyFileSystemRoutes({ entrypoint, routes }) {
214
- nestedRoutes[entrypoint.entryName] = routes;
215
- return {
216
- entrypoint,
217
- routes
218
- };
219
- },
220
- async beforeGenerateRoutes({ entrypoint, code }) {
221
- const { distDirectory } = api.useAppContext();
222
- await _utils.fs.outputJSON(_path.default.resolve(distDirectory, _utils.NESTED_ROUTE_SPEC_FILE), nestedRoutes);
223
- return {
224
- entrypoint,
225
- code
226
- };
227
190
  }
228
- };
229
- }
230
- };
231
- };
191
+ },
192
+ async watchFiles() {
193
+ const appContext2 = api.useAppContext();
194
+ const config = api.useResolvedConfigContext();
195
+ return await (0, _generateWatchFiles.generateWatchFiles)(appContext2, config.source.configDir);
196
+ },
197
+ // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
198
+ async fileChange(e) {
199
+ const { filename, eventType, isPrivate } = e;
200
+ if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
201
+ const { closeServer } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./utils/createServer")));
202
+ await closeServer();
203
+ await (0, _restart.restart)(api.useHookRunners(), filename);
204
+ }
205
+ },
206
+ async beforeRestart() {
207
+ (0, _utils.cleanRequireCache)([
208
+ require.resolve("./analyze")
209
+ ]);
210
+ },
211
+ async modifyFileSystemRoutes({ entrypoint, routes }) {
212
+ nestedRoutes[entrypoint.entryName] = routes;
213
+ return {
214
+ entrypoint,
215
+ routes
216
+ };
217
+ },
218
+ async beforeGenerateRoutes({ entrypoint, code }) {
219
+ const { distDirectory } = api.useAppContext();
220
+ await _utils.fs.outputJSON(_path.default.resolve(distDirectory, _utils.NESTED_ROUTE_SPEC_FILE), nestedRoutes);
221
+ return {
222
+ entrypoint,
223
+ code
224
+ };
225
+ }
226
+ };
227
+ }
228
+ });
232
229
  const _default = appTools;
@@ -76,7 +76,7 @@ const safeReplacer = () => {
76
76
  };
77
77
  const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
78
78
  var _resolvedConfig_output_distPath;
79
- const outputPath = _path.join(appDirectory, ((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", _utils.OUTPUT_CONFIG_FILE);
79
+ const outputPath = (0, _utils.ensureAbsolutePath)(appDirectory, _path.join(((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", _utils.OUTPUT_CONFIG_FILE));
80
80
  await _utils.fs.writeJSON(outputPath, resolvedConfig, {
81
81
  spaces: 2,
82
82
  replacer: safeReplacer()