@modern-js/app-tools 2.35.0 → 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 (54) hide show
  1. package/dist/cjs/analyze/constants.js +1 -0
  2. package/dist/cjs/analyze/generateCode.js +3 -4
  3. package/dist/cjs/analyze/getFileSystemEntry.js +1 -2
  4. package/dist/cjs/analyze/getServerRoutes.js +4 -5
  5. package/dist/cjs/analyze/nestedRoutes.js +11 -2
  6. package/dist/cjs/analyze/templates.js +4 -4
  7. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +1 -2
  8. package/dist/cjs/builder/index.js +1 -1
  9. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +4 -20
  10. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -14
  11. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  12. package/dist/cjs/commands/build.js +2 -3
  13. package/dist/cjs/commands/inspect.js +1 -2
  14. package/dist/cjs/commands/serve.js +3 -3
  15. package/dist/cjs/index.js +127 -130
  16. package/dist/cjs/utils/config.js +1 -1
  17. package/dist/cjs/utils/printInstructions.js +1 -1
  18. package/dist/esm/analyze/constants.js +1 -0
  19. package/dist/esm/analyze/generateCode.js +4 -4
  20. package/dist/esm/analyze/getFileSystemEntry.js +1 -2
  21. package/dist/esm/analyze/getServerRoutes.js +4 -5
  22. package/dist/esm/analyze/nestedRoutes.js +11 -2
  23. package/dist/esm/analyze/templates.js +4 -4
  24. package/dist/esm/builder/generator/createBuilderProviderConfig.js +1 -2
  25. package/dist/esm/builder/index.js +1 -1
  26. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +12 -43
  27. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +12 -14
  28. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  29. package/dist/esm/commands/build.js +3 -3
  30. package/dist/esm/commands/inspect.js +2 -2
  31. package/dist/esm/commands/serve.js +4 -4
  32. package/dist/esm/index.js +2 -3
  33. package/dist/esm/utils/config.js +2 -2
  34. package/dist/esm/utils/printInstructions.js +1 -1
  35. package/dist/esm-node/analyze/constants.js +1 -0
  36. package/dist/esm-node/analyze/generateCode.js +3 -4
  37. package/dist/esm-node/analyze/getFileSystemEntry.js +1 -2
  38. package/dist/esm-node/analyze/getServerRoutes.js +4 -5
  39. package/dist/esm-node/analyze/nestedRoutes.js +11 -2
  40. package/dist/esm-node/analyze/templates.js +4 -4
  41. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +1 -2
  42. package/dist/esm-node/builder/index.js +1 -1
  43. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +4 -19
  44. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +12 -14
  45. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +2 -2
  46. package/dist/esm-node/commands/build.js +2 -3
  47. package/dist/esm-node/commands/inspect.js +1 -2
  48. package/dist/esm-node/commands/serve.js +4 -4
  49. package/dist/esm-node/index.js +127 -130
  50. package/dist/esm-node/utils/config.js +2 -2
  51. package/dist/esm-node/utils/printInstructions.js +1 -1
  52. package/dist/types/analyze/constants.d.ts +1 -0
  53. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -0
  54. package/package.json +24 -25
@@ -29,7 +29,7 @@ export var builderPluginAdapterSSR = function(options) {
29
29
  target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer;
30
30
  builderConfig = api.getNormalizedConfig();
31
31
  normalizedConfig2 = options.normalizedConfig;
32
- applyRouterPlugin(chain, options, HtmlBundlerPlugin);
32
+ applyRouterPlugin(chain, CHAIN_ID.PLUGIN.ROUTER_MANIFEST, options, HtmlBundlerPlugin);
33
33
  if (!isSSR(normalizedConfig2))
34
34
  return [
35
35
  3,
@@ -76,7 +76,6 @@ export var builderPluginAdapterSSR = function(options) {
76
76
  };
77
77
  };
78
78
  var isStreamingSSR = function(userConfig) {
79
- var _server;
80
79
  var isStreaming = function(ssr) {
81
80
  return ssr && typeof ssr === "object" && ssr.mode === "stream";
82
81
  };
@@ -84,7 +83,7 @@ var isStreamingSSR = function(userConfig) {
84
83
  if (isStreaming(server.ssr)) {
85
84
  return true;
86
85
  }
87
- if (((_server = server) === null || _server === void 0 ? void 0 : _server.ssrByEntries) && typeof server.ssrByEntries === "object") {
86
+ if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
88
87
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
89
88
  try {
90
89
  for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
@@ -118,19 +117,19 @@ function applyAsyncChunkHtmlPlugin(param) {
118
117
  ]);
119
118
  }
120
119
  }
121
- function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
122
- var _normalizedConfig_runtime, _normalizedConfig, _routerConfig, _normalizedConfig_deploy_worker;
120
+ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
121
+ var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
123
122
  var appContext = options.appContext, normalizedConfig = options.normalizedConfig;
124
123
  var entrypoints = appContext.entrypoints;
125
124
  var existNestedRoutes = entrypoints.some(function(entrypoint) {
126
125
  return entrypoint.nestedRoutesEntry;
127
126
  });
128
- var routerConfig = (_normalizedConfig = normalizedConfig) === null || _normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = _normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
129
- var routerManifest = Boolean((_routerConfig = routerConfig) === null || _routerConfig === void 0 ? void 0 : _routerConfig.manifest);
127
+ var routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
128
+ var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
130
129
  var workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
131
130
  if (existNestedRoutes || routerManifest || workerSSR) {
132
131
  var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
133
- chain.plugin("route-plugin").use(RouterPlugin, [
132
+ chain.plugin(pluginName).use(RouterPlugin, [
134
133
  {
135
134
  HtmlBundlerPlugin: HtmlBundlerPlugin,
136
135
  enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
@@ -144,21 +143,21 @@ function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
144
143
  }
145
144
  function applyFilterEntriesBySSRConfig(param) {
146
145
  var isProd = param.isProd, chain = param.chain, appNormalizedConfig = param.appNormalizedConfig;
147
- var _outputConfig, _this, _outputConfig1, _outputConfig2, _outputConfig3;
146
+ var _this;
148
147
  var serverConfig = appNormalizedConfig.server, outputConfig = appNormalizedConfig.output;
149
148
  var entries = chain.entryPoints.entries();
150
- 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")) {
149
+ 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")) {
151
150
  return;
152
151
  }
153
152
  if (typeof entries === "undefined") {
154
153
  throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
155
154
  }
156
155
  var entryNames = Object.keys(entries);
157
- if (isProd && entryNames.length === 1 && ((_outputConfig2 = outputConfig) === null || _outputConfig2 === void 0 ? void 0 : _outputConfig2.ssg)) {
156
+ if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
158
157
  return;
159
158
  }
160
159
  var ssgEntries = [];
161
- if (isProd && ((_outputConfig3 = outputConfig) === null || _outputConfig3 === void 0 ? void 0 : _outputConfig3.ssg)) {
160
+ if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
162
161
  var ssg = outputConfig.ssg;
163
162
  entryNames.forEach(function(name) {
164
163
  if (ssg[name]) {
@@ -168,8 +167,7 @@ function applyFilterEntriesBySSRConfig(param) {
168
167
  }
169
168
  var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
170
169
  entryNames.forEach(function(name) {
171
- var _ssrByEntries, _ssrByEntries1;
172
- 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]))) {
170
+ 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]))) {
173
171
  chain.entryPoints.delete(name);
174
172
  }
175
173
  });
@@ -18,6 +18,7 @@ export var RouterPlugin = /* @__PURE__ */ function() {
18
18
  function RouterPlugin2(param) {
19
19
  var _param_staticJsDir = param.staticJsDir, staticJsDir = _param_staticJsDir === void 0 ? "static/js" : _param_staticJsDir, HtmlBundlerPlugin = param.HtmlBundlerPlugin, enableInlineRouteManifests = param.enableInlineRouteManifests, _param_disableFilenameHash = param.disableFilenameHash, disableFilenameHash = _param_disableFilenameHash === void 0 ? false : _param_disableFilenameHash, _param_scriptLoading = param.scriptLoading, scriptLoading = _param_scriptLoading === void 0 ? "defer" : _param_scriptLoading, nonce = param.nonce;
20
20
  _class_call_check(this, RouterPlugin2);
21
+ _define_property(this, "name", "RouterPlugin");
21
22
  _define_property(this, "HtmlBundlerPlugin", void 0);
22
23
  _define_property(this, "enableInlineRouteManifests", void 0);
23
24
  _define_property(this, "staticJsDir", void 0);
@@ -117,10 +118,9 @@ export var RouterPlugin = /* @__PURE__ */ function() {
117
118
  var relatedAssets = {};
118
119
  if (entryChunkFiles.length > 1) {
119
120
  Object.keys(routeAssets).forEach(function(routeId) {
120
- var _chunkNames;
121
121
  var segments = routeId.split("_");
122
122
  var chunkName = segments[0];
123
- if ((_chunkNames = chunkNames) === null || _chunkNames === void 0 ? void 0 : _chunkNames.includes(chunkName)) {
123
+ if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
124
124
  relatedAssets[routeId] = routeAssets[routeId];
125
125
  }
126
126
  });
@@ -8,11 +8,11 @@ import { generateRoutes } from "../utils/routes";
8
8
  import { buildServerConfig } from "../utils/config";
9
9
  export var build = function() {
10
10
  var _ref = _async_to_generator(function(api, options) {
11
- var _options, resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
11
+ var resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
12
12
  return _ts_generator(this, function(_state) {
13
13
  switch (_state.label) {
14
14
  case 0:
15
- if ((_options = options) === null || _options === void 0 ? void 0 : _options.analyze) {
15
+ if (options === null || options === void 0 ? void 0 : options.analyze) {
16
16
  process.env.BUNDLE_ANALYZE = "true";
17
17
  }
18
18
  resolvedConfig = api.useResolvedConfigContext();
@@ -78,7 +78,7 @@ export var build = function() {
78
78
  ];
79
79
  case 6:
80
80
  _state.sent();
81
- logger.info("Create a production build...\n");
81
+ logger.info("Starting production build...");
82
82
  if (!appContext.builder) {
83
83
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
84
84
  }
@@ -3,7 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { join } from "path";
4
4
  export var inspect = function() {
5
5
  var _ref = _async_to_generator(function(api, options) {
6
- var _appContext, appContext;
6
+ var appContext;
7
7
  return _ts_generator(this, function(_state) {
8
8
  appContext = api.useAppContext();
9
9
  if (!appContext.builder) {
@@ -14,7 +14,7 @@ export var inspect = function() {
14
14
  appContext.builder.inspectConfig({
15
15
  env: options.env,
16
16
  verbose: options.verbose,
17
- outputPath: join((_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.builder.context.distPath, options.output),
17
+ outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
18
18
  writeToDisk: true
19
19
  })
20
20
  ];
@@ -2,14 +2,14 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
3
  import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
- import { logger, chalk, isApiOnly, getTargetDir } from "@modern-js/utils";
5
+ import { logger, isApiOnly, getTargetDir } from "@modern-js/utils";
6
6
  import server from "@modern-js/prod-server";
7
7
  import { printInstructions } from "../utils/printInstructions";
8
8
  import { injectDataLoaderPlugin } from "../utils/createServer";
9
9
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
10
10
  export var start = function() {
11
11
  var _ref = _async_to_generator(function(api) {
12
- var _userConfig_source, _userConfig, _userConfig_output_distPath, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, metaName, apiOnly, serverInternalPlugins, app;
12
+ var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, metaName, apiOnly, serverInternalPlugins, app;
13
13
  return _ts_generator(this, function(_state) {
14
14
  switch (_state.label) {
15
15
  case 0:
@@ -17,10 +17,10 @@ export var start = function() {
17
17
  userConfig = api.useResolvedConfigContext();
18
18
  hookRunners = api.useHookRunners();
19
19
  appDirectory = appContext.appDirectory, port = appContext.port, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName;
20
- logger.log(chalk.cyan("Starting the modern server..."));
20
+ logger.info("Starting production server...");
21
21
  return [
22
22
  4,
23
- 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
+ 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)
24
24
  ];
25
25
  case 1:
26
26
  apiOnly = _state.sent();
package/dist/esm/index.js CHANGED
@@ -273,7 +273,6 @@ export var appTools = function() {
273
273
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
274
274
  bundler: "webpack"
275
275
  };
276
- var _options, _options1;
277
276
  return {
278
277
  name: "@modern-js/app-tools",
279
278
  post: [
@@ -289,10 +288,10 @@ export var appTools = function() {
289
288
  registerHook: hooks,
290
289
  usePlugins: [
291
290
  initializePlugin({
292
- bundler: ((_options = options) === null || _options === void 0 ? void 0 : _options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
291
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
293
292
  }),
294
293
  analyzePlugin({
295
- bundler: ((_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.bundler) === "experimental-rspack" ? "rspack" : "webpack"
294
+ bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
296
295
  }),
297
296
  lintPlugin()
298
297
  ],
@@ -4,7 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import * as path from "path";
6
6
  import { bundle } from "@modern-js/node-bundle-require";
7
- import { CONFIG_FILE_EXTENSIONS, fs, getServerConfig, OUTPUT_CONFIG_FILE } from "@modern-js/utils";
7
+ import { fs, getServerConfig, ensureAbsolutePath, OUTPUT_CONFIG_FILE, CONFIG_FILE_EXTENSIONS } from "@modern-js/utils";
8
8
  export var defineServerConfig = function(config) {
9
9
  return config;
10
10
  };
@@ -109,7 +109,7 @@ export var emitResolvedConfig = function() {
109
109
  return _ts_generator(this, function(_state) {
110
110
  switch (_state.label) {
111
111
  case 0:
112
- outputPath = path.join(appDirectory, ((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", OUTPUT_CONFIG_FILE);
112
+ outputPath = ensureAbsolutePath(appDirectory, path.join(((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", OUTPUT_CONFIG_FILE));
113
113
  return [
114
114
  4,
115
115
  fs.writeJSON(outputPath, resolvedConfig, {
@@ -16,7 +16,7 @@ export var printInstructions = function() {
16
16
  ];
17
17
  case 1:
18
18
  instructions = _state.sent().instructions;
19
- logger.info(instructions);
19
+ logger.log(instructions);
20
20
  return [
21
21
  2
22
22
  ];
@@ -37,6 +37,7 @@ export const NESTED_ROUTE = {
37
37
  PAGE_DATA_FILE: "page.data",
38
38
  PAGE_CLIENT_LOADER: "page.data.client",
39
39
  SPLATE_FILE: "$",
40
+ SPLATE_CONFIG_FILE: "$.config",
40
41
  SPLATE_LOADER_FILE: "$.loader",
41
42
  SPLATE_DATA_FILE: "$.data",
42
43
  SPLATE_CLIENT_DATA: "$.data.client",
@@ -50,13 +50,12 @@ ${initialize || ""}`);
50
50
  ${initialize || ""}`).join("\n");
51
51
  };
52
52
  export const generateCode = async (appContext, config, entrypoints, api) => {
53
- var _config, _config1;
54
53
  const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
55
54
  const hookRunners = api.useHookRunners();
56
55
  const isV5 = isRouterV5(config);
57
56
  const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
58
57
  const importsStatemets = /* @__PURE__ */ new Map();
59
- 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;
58
+ 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;
60
59
  await Promise.all(entrypoints.map(generateEntryCode));
61
60
  return {
62
61
  importsStatemets
@@ -65,7 +64,7 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
65
64
  const { entryName, isMainEntry, isAutoMount, fileSystemRoutes } = entrypoint;
66
65
  if (isAutoMount) {
67
66
  if (fileSystemRoutes) {
68
- var _config_output, _config2;
67
+ var _config_output;
69
68
  let initialRoutes = [];
70
69
  let nestedRoutes = null;
71
70
  if (entrypoint.entry) {
@@ -119,7 +118,7 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
119
118
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
120
119
  entryName: entrypoint.entryName,
121
120
  internalDirectory,
122
- splitRouteChunks: (_config2 = config2) === null || _config2 === void 0 ? void 0 : (_config_output = _config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
121
+ splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
123
122
  })
124
123
  });
125
124
  if (entrypoint.nestedRoutesEntry && isUseSSRBundle(config2)) {
@@ -69,8 +69,7 @@ export const getFileSystemEntry = (appContext, config) => {
69
69
  const { source: { entriesDir, disableEntryDirs } } = config;
70
70
  let disabledDirs = [];
71
71
  if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
72
- var _disableEntryDirs;
73
- disabledDirs = (_disableEntryDirs = disableEntryDirs) === null || _disableEntryDirs === void 0 ? void 0 : _disableEntryDirs.map((dir) => ensureAbsolutePath(appDirectory, dir));
72
+ disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map((dir) => ensureAbsolutePath(appDirectory, dir));
74
73
  }
75
74
  const src = ensureAbsolutePath(appDirectory, entriesDir || "");
76
75
  if (fs.existsSync(src)) {
@@ -68,18 +68,17 @@ const applyRouteOptions = (original, routeOptions) => {
68
68
  return routes;
69
69
  };
70
70
  const collectHtmlRoutes = (entrypoints, appContext, config) => {
71
- var _deploy_worker, _deploy;
71
+ var _deploy_worker;
72
72
  const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
73
73
  const { packageName } = appContext;
74
- const workerSSR = (_deploy = deploy) === null || _deploy === void 0 ? void 0 : (_deploy_worker = _deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
74
+ const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
75
75
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
76
- var _routes, _routes1;
77
76
  const isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
78
77
  const entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
79
78
  const isSSR = Boolean(entryOptions);
80
79
  const isWorker = Boolean(workerSSR);
81
80
  const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
82
- const { resHeaders } = ((_routes = routes) === null || _routes === void 0 ? void 0 : _routes[entryName]) || {};
81
+ const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
83
82
  let route = {
84
83
  urlPath: `/${isMainEntry ? "" : entryName}`,
85
84
  entryName,
@@ -91,7 +90,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
91
90
  worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
92
91
  bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
93
92
  };
94
- if ((_routes1 = routes) === null || _routes1 === void 0 ? void 0 : _routes1.hasOwnProperty(entryName)) {
93
+ if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
95
94
  const routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
96
95
  route: routes[entryName]
97
96
  };
@@ -70,7 +70,7 @@ export const optimizeRoute = (routeTree) => {
70
70
  }
71
71
  };
72
72
  export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldVersion) => {
73
- var _routePath, _finalRoute_children;
73
+ var _finalRoute_children;
74
74
  if (!await fs.pathExists(dirname)) {
75
75
  return null;
76
76
  }
@@ -90,7 +90,7 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
90
90
  }
91
91
  routePath = replaceDynamicPath(routePath);
92
92
  const route = {
93
- path: (_routePath = routePath) === null || _routePath === void 0 ? void 0 : _routePath.replace(/\$$/, "?"),
93
+ path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
94
94
  children: [],
95
95
  isRoot
96
96
  };
@@ -101,6 +101,7 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
101
101
  let splatData = "";
102
102
  let splatRoute = null;
103
103
  let pageConfigFile = "";
104
+ let splatConfigFile = "";
104
105
  const items = await fs.readdir(dirname);
105
106
  for (const item of items) {
106
107
  const itemPath = path.join(dirname, item);
@@ -167,6 +168,11 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
167
168
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_CLIENT_DATA) {
168
169
  splatClientData = itemPath;
169
170
  }
171
+ if (itemWithoutExt === NESTED_ROUTE.SPLATE_CONFIG_FILE) {
172
+ if (!route.config) {
173
+ splatConfigFile = itemPath;
174
+ }
175
+ }
170
176
  if (itemWithoutExt === NESTED_ROUTE.SPLATE_DATA_FILE) {
171
177
  splatData = itemPath;
172
178
  }
@@ -185,6 +191,9 @@ export const walk = async (dirname, rootDir, alias, entryName, isMainEntry, oldV
185
191
  if (splatData) {
186
192
  splatRoute.data = splatData;
187
193
  }
194
+ if (splatConfigFile) {
195
+ splatRoute.config = splatConfigFile;
196
+ }
188
197
  (_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(splatRoute);
189
198
  }
190
199
  if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
@@ -76,8 +76,8 @@ export const routesForServer = ({ routes }) => {
76
76
  const traverseRouteTree = (route) => {
77
77
  let children;
78
78
  if ("children" in route && route.children) {
79
- var _route_children, _route;
80
- children = (_route = route) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
79
+ var _route_children;
80
+ children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
81
81
  }
82
82
  let loader;
83
83
  if (route.type === "nested") {
@@ -145,8 +145,8 @@ export const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, ent
145
145
  const traverseRouteTree = (route) => {
146
146
  let children;
147
147
  if ("children" in route && route.children) {
148
- var _route_children, _route;
149
- children = (_route = route) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
148
+ var _route_children;
149
+ children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
150
150
  }
151
151
  let loading;
152
152
  let error;
@@ -1,9 +1,8 @@
1
1
  import { createUploadPattern } from "../builder-webpack/createCopyPattern";
2
2
  function modifyOutputConfig(config, appContext) {
3
- var _copy;
4
3
  const defaultCopyPattern = createUploadPattern(appContext, config);
5
4
  const { copy } = config.output;
6
- const copyOptions = Array.isArray(copy) ? copy : (_copy = copy) === null || _copy === void 0 ? void 0 : _copy.patterns;
5
+ const copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
7
6
  const builderCopy = [
8
7
  ...copyOptions || [],
9
8
  defaultCopyPattern
@@ -5,7 +5,7 @@ export async function createBuilderGenerator(bundler) {
5
5
  const { createRspackBuilderForModern } = await import("./builder-rspack");
6
6
  const { getRspackVersion } = await import("@modern-js/builder-rspack-provider");
7
7
  const version = await getRspackVersion();
8
- logger.info(`Using Rspack v${version} 🦀`);
8
+ logger.info(`Using Rspack v${version}`);
9
9
  return createRspackBuilderForModern;
10
10
  } catch (_) {
11
11
  throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
@@ -16,35 +16,20 @@ export const builderPluginAdapterHtml = (options) => ({
16
16
  HtmlBundlerPlugin
17
17
  });
18
18
  await injectAssetPrefix({
19
- api,
20
19
  chain
21
20
  });
22
21
  }
23
22
  });
24
23
  }
25
24
  });
26
- async function injectAssetPrefix({ api, chain }) {
25
+ async function injectAssetPrefix({ chain }) {
27
26
  const entries = chain.entryPoints.entries() || {};
28
27
  const entryNames = Object.keys(entries);
29
28
  const assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
30
29
  const code = `window.__assetPrefix__ = '${assetPrefix}';`;
31
- const isRspack = api.context.bundlerType === "rspack";
32
- if (isRspack) {
33
- const fileName = "rspack-asset-prefix";
34
- const { default: RspackVirtualModulePlugin } = await import("rspack-plugin-virtual-module");
35
- entryNames.forEach((entryName) => {
36
- entries[entryName].prepend(fileName);
37
- chain.plugin("rspack-asset-prefix").use(RspackVirtualModulePlugin, [
38
- {
39
- [fileName]: code
40
- }
41
- ]);
42
- });
43
- } else {
44
- entryNames.forEach((entryName) => {
45
- entries[entryName].prepend(createVirtualModule(code));
46
- });
47
- }
30
+ entryNames.forEach((entryName) => {
31
+ entries[entryName].prepend(createVirtualModule(code));
32
+ });
48
33
  }
49
34
  function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugin }) {
50
35
  const { normalizedConfig: modernConfig, appContext } = options;
@@ -20,7 +20,7 @@ export const builderPluginAdapterSSR = (options) => ({
20
20
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
21
21
  const builderConfig = api.getNormalizedConfig();
22
22
  const { normalizedConfig: normalizedConfig2 } = options;
23
- applyRouterPlugin(chain, options, HtmlBundlerPlugin);
23
+ applyRouterPlugin(chain, CHAIN_ID.PLUGIN.ROUTER_MANIFEST, options, HtmlBundlerPlugin);
24
24
  if (isSSR(normalizedConfig2)) {
25
25
  await applySSRLoaderEntry(chain, options, isServer);
26
26
  applySSRDataLoader(chain, options);
@@ -47,13 +47,12 @@ export const builderPluginAdapterSSR = (options) => ({
47
47
  }
48
48
  });
49
49
  const isStreamingSSR = (userConfig) => {
50
- var _server;
51
50
  const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
52
51
  const { server } = userConfig;
53
52
  if (isStreaming(server.ssr)) {
54
53
  return true;
55
54
  }
56
- if (((_server = server) === null || _server === void 0 ? void 0 : _server.ssrByEntries) && typeof server.ssrByEntries === "object") {
55
+ if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
57
56
  for (const name of Object.keys(server.ssrByEntries)) {
58
57
  if (isStreaming(server.ssrByEntries[name])) {
59
58
  return true;
@@ -69,17 +68,17 @@ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerP
69
68
  ]);
70
69
  }
71
70
  }
72
- function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
73
- var _normalizedConfig_runtime, _normalizedConfig, _routerConfig, _normalizedConfig_deploy_worker;
71
+ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
72
+ var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
74
73
  const { appContext, normalizedConfig } = options;
75
74
  const { entrypoints } = appContext;
76
75
  const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
77
- const routerConfig = (_normalizedConfig = normalizedConfig) === null || _normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = _normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
78
- const routerManifest = Boolean((_routerConfig = routerConfig) === null || _routerConfig === void 0 ? void 0 : _routerConfig.manifest);
76
+ const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
77
+ const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
79
78
  const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
80
79
  if (existNestedRoutes || routerManifest || workerSSR) {
81
80
  var _normalizedConfig_output_distPath, _normalizedConfig_output, _normalizedConfig_output1, _normalizedConfig_html, _normalizedConfig_security;
82
- chain.plugin("route-plugin").use(RouterPlugin, [
81
+ chain.plugin(pluginName).use(RouterPlugin, [
83
82
  {
84
83
  HtmlBundlerPlugin,
85
84
  enableInlineRouteManifests: normalizedConfig.output.enableInlineRouteManifests,
@@ -92,21 +91,21 @@ function applyRouterPlugin(chain, options, HtmlBundlerPlugin) {
92
91
  }
93
92
  }
94
93
  function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
95
- var _outputConfig, _this, _outputConfig1, _outputConfig2, _outputConfig3;
94
+ var _this;
96
95
  const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
97
96
  const entries = chain.entryPoints.entries();
98
- 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")) {
97
+ 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")) {
99
98
  return;
100
99
  }
101
100
  if (typeof entries === "undefined") {
102
101
  throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
103
102
  }
104
103
  const entryNames = Object.keys(entries);
105
- if (isProd && entryNames.length === 1 && ((_outputConfig2 = outputConfig) === null || _outputConfig2 === void 0 ? void 0 : _outputConfig2.ssg)) {
104
+ if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
106
105
  return;
107
106
  }
108
107
  const ssgEntries = [];
109
- if (isProd && ((_outputConfig3 = outputConfig) === null || _outputConfig3 === void 0 ? void 0 : _outputConfig3.ssg)) {
108
+ if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
110
109
  const { ssg } = outputConfig;
111
110
  entryNames.forEach((name) => {
112
111
  if (ssg[name]) {
@@ -116,8 +115,7 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
116
115
  }
117
116
  const { ssr, ssrByEntries } = serverConfig || {};
118
117
  entryNames.forEach((name) => {
119
- var _ssrByEntries, _ssrByEntries1;
120
- 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]))) {
118
+ 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]))) {
121
119
  chain.entryPoints.delete(name);
122
120
  }
123
121
  });
@@ -119,10 +119,9 @@ export class RouterPlugin {
119
119
  let relatedAssets = {};
120
120
  if (entryChunkFiles.length > 1) {
121
121
  Object.keys(routeAssets).forEach((routeId) => {
122
- var _chunkNames;
123
122
  const segments = routeId.split("_");
124
123
  const chunkName = segments[0];
125
- if ((_chunkNames = chunkNames) === null || _chunkNames === void 0 ? void 0 : _chunkNames.includes(chunkName)) {
124
+ if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
126
125
  relatedAssets[routeId] = routeAssets[routeId];
127
126
  }
128
127
  });
@@ -194,6 +193,7 @@ export class RouterPlugin {
194
193
  });
195
194
  }
196
195
  constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
196
+ _define_property(this, "name", "RouterPlugin");
197
197
  _define_property(this, "HtmlBundlerPlugin", void 0);
198
198
  _define_property(this, "enableInlineRouteManifests", void 0);
199
199
  _define_property(this, "staticJsDir", void 0);
@@ -3,8 +3,7 @@ import { logger } from "@modern-js/utils";
3
3
  import { generateRoutes } from "../utils/routes";
4
4
  import { buildServerConfig } from "../utils/config";
5
5
  export const build = async (api, options) => {
6
- var _options;
7
- if ((_options = options) === null || _options === void 0 ? void 0 : _options.analyze) {
6
+ if (options === null || options === void 0 ? void 0 : options.analyze) {
8
7
  process.env.BUNDLE_ANALYZE = "true";
9
8
  }
10
9
  let resolvedConfig = api.useResolvedConfigContext();
@@ -40,7 +39,7 @@ export const build = async (api, options) => {
40
39
  distDirectory,
41
40
  configFile: serverConfigFile
42
41
  });
43
- logger.info("Create a production build...\n");
42
+ logger.info("Starting production build...");
44
43
  if (!appContext.builder) {
45
44
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
46
45
  }
@@ -1,6 +1,5 @@
1
1
  import { join } from "path";
2
2
  export const inspect = async (api, options) => {
3
- var _appContext;
4
3
  const appContext = api.useAppContext();
5
4
  if (!appContext.builder) {
6
5
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
@@ -8,7 +7,7 @@ export const inspect = async (api, options) => {
8
7
  return appContext.builder.inspectConfig({
9
8
  env: options.env,
10
9
  verbose: options.verbose,
11
- outputPath: join((_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.builder.context.distPath, options.output),
10
+ outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
12
11
  writeToDisk: true
13
12
  });
14
13
  };
@@ -1,16 +1,16 @@
1
- import { logger, chalk, isApiOnly, getTargetDir } from "@modern-js/utils";
1
+ import { logger, isApiOnly, getTargetDir } from "@modern-js/utils";
2
2
  import server from "@modern-js/prod-server";
3
3
  import { printInstructions } from "../utils/printInstructions";
4
4
  import { injectDataLoaderPlugin } from "../utils/createServer";
5
5
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
6
6
  export const start = async (api) => {
7
- var _userConfig_source, _userConfig, _userConfig_output_distPath;
7
+ var _userConfig_source, _userConfig_output_distPath;
8
8
  const appContext = api.useAppContext();
9
9
  const userConfig = api.useResolvedConfigContext();
10
10
  const hookRunners = api.useHookRunners();
11
11
  const { appDirectory, port, serverConfigFile, metaName } = appContext;
12
- logger.log(chalk.cyan(`Starting the modern server...`));
13
- const apiOnly = await 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);
12
+ logger.info(`Starting production server...`);
13
+ const apiOnly = await 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);
14
14
  const serverInternalPlugins = await getServerInternalPlugins(api);
15
15
  const app = await server({
16
16
  pwd: appDirectory,