@modern-js/app-tools 2.4.0 → 3.0.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/js/modern/analyze/getServerRoutes.js +5 -2
  3. package/dist/js/modern/analyze/index.js +6 -2
  4. package/dist/js/modern/builder/builder-webpack/webpackPlugins/RouterPlugin.js +3 -0
  5. package/dist/js/modern/builder/generator/getBuilderTargets.js +10 -1
  6. package/dist/js/modern/builder/shared/builderPlugins/adapterModern.js +23 -7
  7. package/dist/js/node/analyze/getServerRoutes.js +3 -1
  8. package/dist/js/node/analyze/index.js +6 -2
  9. package/dist/js/node/builder/builder-webpack/webpackPlugins/RouterPlugin.js +3 -0
  10. package/dist/js/node/builder/generator/getBuilderTargets.js +4 -0
  11. package/dist/js/node/builder/shared/builderPlugins/adapterModern.js +23 -7
  12. package/dist/js/treeshaking/analyze/generateCode.js +14 -14
  13. package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
  14. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
  15. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  16. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
  17. package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
  18. package/dist/js/treeshaking/analyze/index.js +8 -8
  19. package/dist/js/treeshaking/analyze/nestedRoutes.js +5 -5
  20. package/dist/js/treeshaking/analyze/templates.js +6 -6
  21. package/dist/js/treeshaking/analyze/utils.js +3 -3
  22. package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +4 -4
  23. package/dist/js/treeshaking/builder/builder-webpack/index.js +2 -2
  24. package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/RouterPlugin.js +5 -2
  25. package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +2 -2
  26. package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +5 -1
  27. package/dist/js/treeshaking/builder/generator/index.js +2 -2
  28. package/dist/js/treeshaking/builder/shared/builderPlugins/adapterModern.js +62 -13
  29. package/dist/js/treeshaking/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +2 -2
  30. package/dist/js/treeshaking/commands/dev.js +2 -2
  31. package/dist/js/treeshaking/commands/serve.js +2 -2
  32. package/dist/js/treeshaking/config/initialize/inits.js +2 -2
  33. package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +1 -1
  34. package/dist/js/treeshaking/config/legacy/createOutputConfig.js +1 -1
  35. package/dist/js/treeshaking/config/legacy/createSourceConfig.js +1 -1
  36. package/dist/js/treeshaking/config/legacy/createToolsConfig.js +1 -1
  37. package/dist/js/treeshaking/initialize/index.js +2 -2
  38. package/dist/js/treeshaking/utils/config.js +2 -2
  39. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
  40. package/dist/types/types/hooks.d.ts +5 -4
  41. package/dist/types/types/index.d.ts +3 -1
  42. package/package.json +20 -20
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 3.0.0-beta.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 840142c: fix: the `@modern-js/app-tools` hooks should set `webpack` as default type.
8
+ fix: `@modern-js/app-tools` hooks 应该将 'webpack' 设置为默认类型
9
+ - 11c053b: feat: ssr support deploy worker
10
+
11
+ feat: ssr 支持边缘部署
12
+
13
+ - Updated dependencies [c4c10e7]
14
+ - Updated dependencies [84c21f9]
15
+ - Updated dependencies [11c053b]
16
+ - Updated dependencies [28e7dc6]
17
+ - @modern-js/builder@2.4.1-beta.0
18
+ - @modern-js/builder-rspack-provider@2.5.0-beta.0
19
+ - @modern-js/builder-shared@2.5.0-beta.0
20
+ - @modern-js/builder-webpack-provider@2.5.0-beta.0
21
+ - @modern-js/builder-plugin-node-polyfill@2.4.1-beta.0
22
+ - @modern-js/prod-server@2.4.1-beta.0
23
+ - @modern-js/utils@2.4.1-beta.0
24
+ - @modern-js/builder-plugin-esbuild@2.4.1-beta.0
25
+ - @modern-js/core@2.4.1-beta.0
26
+ - @modern-js/plugin-data-loader@2.4.1-beta.0
27
+ - @modern-js/server@2.4.1-beta.0
28
+ - @modern-js/plugin-i18n@2.4.1-beta.0
29
+ - @modern-js/plugin-lint@2.4.1-beta.0
30
+ - @modern-js/new-action@2.4.1-beta.0
31
+ - @modern-js/node-bundle-require@2.4.1-beta.0
32
+ - @modern-js/upgrade@2.4.1-beta.0
33
+
3
34
  ## 2.4.0
4
35
 
5
36
  ### Minor Changes
@@ -38,7 +38,8 @@ import {
38
38
  getEntryOptions,
39
39
  SERVER_BUNDLE_DIRECTORY,
40
40
  MAIN_ENTRY_NAME,
41
- removeTailSlash
41
+ removeTailSlash,
42
+ SERVER_WORKER_BUNDLE_DIRECTORY
42
43
  } from "@modern-js/utils";
43
44
  import { walkDirectory } from "./utils";
44
45
  const applyBaseUrl = (baseUrl, routes) => {
@@ -101,7 +102,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
101
102
  const {
102
103
  html: { disableHtmlFolder },
103
104
  output: { distPath: { html: htmlPath } = {} },
104
- server: { baseUrl, routes, ssr, ssrByEntries }
105
+ server: { baseUrl, routes, ssr, ssrByEntries, worker }
105
106
  } = config;
106
107
  const { packageName } = appContext;
107
108
  let htmlRoutes = entrypoints.reduce(
@@ -113,6 +114,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
113
114
  packageName
114
115
  );
115
116
  const isSSR = Boolean(entryOptions);
117
+ const isWorker = Boolean(worker);
116
118
  const { resHeaders } = (routes == null ? void 0 : routes[entryName]) || {};
117
119
  let route = {
118
120
  urlPath: `/${entryName === MAIN_ENTRY_NAME ? "" : entryName}`,
@@ -125,6 +127,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
125
127
  isSPA: true,
126
128
  isSSR,
127
129
  responseHeaders: resHeaders,
130
+ worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
128
131
  bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
129
132
  };
130
133
  if (routes == null ? void 0 : routes.hasOwnProperty(entryName)) {
@@ -169,7 +169,9 @@ var analyze_default = ({
169
169
  return __async(this, arguments, function* ({ bundlerConfigs }) {
170
170
  const hookRunners2 = api.useHookRunners();
171
171
  yield generateRoutes(appContext);
172
- yield hookRunners2.beforeBuild({ bundlerConfigs });
172
+ yield hookRunners2.beforeBuild({
173
+ bundlerConfigs
174
+ });
173
175
  });
174
176
  },
175
177
  onAfterBuild(_0) {
@@ -204,7 +206,9 @@ var analyze_default = ({
204
206
  onAfterCreateCompiler(_0) {
205
207
  return __async(this, arguments, function* ({ compiler }) {
206
208
  const hookRunners2 = api.useHookRunners();
207
- yield hookRunners2.afterCreateCompiler({ compiler });
209
+ yield hookRunners2.afterCreateCompiler({
210
+ compiler
211
+ });
208
212
  });
209
213
  }
210
214
  });
@@ -32,6 +32,9 @@ class RouterPlugin {
32
32
  if (target === "node" || Array.isArray(target) && target.includes("node")) {
33
33
  return;
34
34
  }
35
+ if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
36
+ return;
37
+ }
35
38
  const { webpack } = compiler;
36
39
  const { Compilation, sources } = webpack;
37
40
  const { RawSource } = sources;
@@ -1,10 +1,19 @@
1
- import { isProd, isSSR, isUseSSRBundle } from "@modern-js/utils";
1
+ import {
2
+ isProd,
3
+ isServiceWorker,
4
+ isSSR,
5
+ isUseSSRBundle
6
+ } from "@modern-js/utils";
2
7
  function getBuilderTargets(normalizedConfig) {
3
8
  const targets = ["web"];
4
9
  const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
5
10
  if (useNodeTarget) {
6
11
  targets.push("node");
7
12
  }
13
+ const useWorkerTarget = isProd() ? isServiceWorker(normalizedConfig) : false;
14
+ if (useWorkerTarget) {
15
+ targets.push("service-worker");
16
+ }
8
17
  return targets;
9
18
  }
10
19
  export {
@@ -58,13 +58,17 @@ const builderPluginAdapterModern = (options) => ({
58
58
  const builderConfig = api.getNormalizedConfig();
59
59
  if (target === "node") {
60
60
  chain.name("server");
61
+ } else if (target === "service-worker") {
62
+ chain.name("service-worker");
63
+ } else if (target === "web-worker") {
64
+ chain.name("worker");
61
65
  } else if (target === "modern-web") {
62
66
  chain.name("modern");
63
67
  } else {
64
68
  chain.name("client");
65
69
  }
66
- if (target === "node") {
67
- applyNodeCompat(chain, normalizedConfig, isProd);
70
+ if (target === "node" || target === "service-worker") {
71
+ applyNodeCompat(target, chain, normalizedConfig, isProd);
68
72
  }
69
73
  if (isHtmlEnabled(builderConfig, target)) {
70
74
  applyBottomHtmlPlugin({
@@ -80,7 +84,7 @@ const builderPluginAdapterModern = (options) => ({
80
84
  CHAIN_ID
81
85
  });
82
86
  }
83
- if (target !== "node") {
87
+ if (target !== "node" && target !== "web-worker" && target !== "service-worker") {
84
88
  const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
85
89
  chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
86
90
  chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
@@ -89,7 +93,7 @@ const builderPluginAdapterModern = (options) => ({
89
93
  applyCallbacks(api, options);
90
94
  function isHtmlEnabled(config, target) {
91
95
  var _a;
92
- return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "web-worker";
96
+ return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
93
97
  }
94
98
  }
95
99
  });
@@ -146,8 +150,8 @@ function applyAsyncChunkHtmlPlugin({
146
150
  chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlWebpackPlugin]);
147
151
  }
148
152
  }
149
- function applyNodeCompat(chain, modernConfig, isProd) {
150
- for (const ext of [
153
+ function applyNodeCompat(target, chain, modernConfig, isProd) {
154
+ const nodeExts = [
151
155
  ".node.js",
152
156
  ".node.jsx",
153
157
  ".node.ts",
@@ -156,9 +160,21 @@ function applyNodeCompat(chain, modernConfig, isProd) {
156
160
  ".server.ts",
157
161
  ".server.ts",
158
162
  ".server.tsx"
159
- ]) {
163
+ ];
164
+ const webWorkerExts = [
165
+ ".worker.js",
166
+ ".worker.jsx",
167
+ ".worker.ts",
168
+ ".worker.tsx"
169
+ ];
170
+ for (const ext of nodeExts) {
160
171
  chain.resolve.extensions.prepend(ext);
161
172
  }
173
+ if (target === "service-worker") {
174
+ for (const ext of webWorkerExts) {
175
+ chain.resolve.extensions.prepend(ext);
176
+ }
177
+ }
162
178
  filterEntriesBySSRConfig(
163
179
  isProd,
164
180
  chain,
@@ -119,7 +119,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
119
119
  const {
120
120
  html: { disableHtmlFolder },
121
121
  output: { distPath: { html: htmlPath } = {} },
122
- server: { baseUrl, routes, ssr, ssrByEntries }
122
+ server: { baseUrl, routes, ssr, ssrByEntries, worker }
123
123
  } = config;
124
124
  const { packageName } = appContext;
125
125
  let htmlRoutes = entrypoints.reduce(
@@ -131,6 +131,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
131
131
  packageName
132
132
  );
133
133
  const isSSR = Boolean(entryOptions);
134
+ const isWorker = Boolean(worker);
134
135
  const { resHeaders } = (routes == null ? void 0 : routes[entryName]) || {};
135
136
  let route = {
136
137
  urlPath: `/${entryName === import_utils.MAIN_ENTRY_NAME ? "" : entryName}`,
@@ -143,6 +144,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
143
144
  isSPA: true,
144
145
  isSSR,
145
146
  responseHeaders: resHeaders,
147
+ worker: isWorker ? `${import_utils.SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
146
148
  bundle: isSSR ? `${import_utils.SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
147
149
  };
148
150
  if (routes == null ? void 0 : routes.hasOwnProperty(entryName)) {
@@ -177,7 +177,9 @@ var analyze_default = ({
177
177
  return __async(this, arguments, function* ({ bundlerConfigs }) {
178
178
  const hookRunners2 = api.useHookRunners();
179
179
  yield (0, import_routes.generateRoutes)(appContext);
180
- yield hookRunners2.beforeBuild({ bundlerConfigs });
180
+ yield hookRunners2.beforeBuild({
181
+ bundlerConfigs
182
+ });
181
183
  });
182
184
  },
183
185
  onAfterBuild(_0) {
@@ -212,7 +214,9 @@ var analyze_default = ({
212
214
  onAfterCreateCompiler(_0) {
213
215
  return __async(this, arguments, function* ({ compiler }) {
214
216
  const hookRunners2 = api.useHookRunners();
215
- yield hookRunners2.afterCreateCompiler({ compiler });
217
+ yield hookRunners2.afterCreateCompiler({
218
+ compiler
219
+ });
216
220
  });
217
221
  }
218
222
  });
@@ -55,6 +55,9 @@ class RouterPlugin {
55
55
  if (target === "node" || Array.isArray(target) && target.includes("node")) {
56
56
  return;
57
57
  }
58
+ if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
59
+ return;
60
+ }
58
61
  const { webpack } = compiler;
59
62
  const { Compilation, sources } = webpack;
60
63
  const { RawSource } = sources;
@@ -27,6 +27,10 @@ function getBuilderTargets(normalizedConfig) {
27
27
  if (useNodeTarget) {
28
28
  targets.push("node");
29
29
  }
30
+ const useWorkerTarget = (0, import_utils.isProd)() ? (0, import_utils.isServiceWorker)(normalizedConfig) : false;
31
+ if (useWorkerTarget) {
32
+ targets.push("service-worker");
33
+ }
30
34
  return targets;
31
35
  }
32
36
  // Annotate the CommonJS export names for ESM import in node:
@@ -83,13 +83,17 @@ const builderPluginAdapterModern = (options) => ({
83
83
  const builderConfig = api.getNormalizedConfig();
84
84
  if (target === "node") {
85
85
  chain.name("server");
86
+ } else if (target === "service-worker") {
87
+ chain.name("service-worker");
88
+ } else if (target === "web-worker") {
89
+ chain.name("worker");
86
90
  } else if (target === "modern-web") {
87
91
  chain.name("modern");
88
92
  } else {
89
93
  chain.name("client");
90
94
  }
91
- if (target === "node") {
92
- applyNodeCompat(chain, normalizedConfig, isProd);
95
+ if (target === "node" || target === "service-worker") {
96
+ applyNodeCompat(target, chain, normalizedConfig, isProd);
93
97
  }
94
98
  if (isHtmlEnabled(builderConfig, target)) {
95
99
  applyBottomHtmlPlugin({
@@ -105,7 +109,7 @@ const builderPluginAdapterModern = (options) => ({
105
109
  CHAIN_ID
106
110
  });
107
111
  }
108
- if (target !== "node") {
112
+ if (target !== "node" && target !== "web-worker" && target !== "service-worker") {
109
113
  const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
110
114
  chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
111
115
  chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
@@ -114,7 +118,7 @@ const builderPluginAdapterModern = (options) => ({
114
118
  applyCallbacks(api, options);
115
119
  function isHtmlEnabled(config, target) {
116
120
  var _a;
117
- return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "web-worker";
121
+ return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
118
122
  }
119
123
  }
120
124
  });
@@ -171,8 +175,8 @@ function applyAsyncChunkHtmlPlugin({
171
175
  chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(import_HtmlAsyncChunkPlugin.HtmlAsyncChunkPlugin, [import_html_webpack_plugin.default]);
172
176
  }
173
177
  }
174
- function applyNodeCompat(chain, modernConfig, isProd) {
175
- for (const ext of [
178
+ function applyNodeCompat(target, chain, modernConfig, isProd) {
179
+ const nodeExts = [
176
180
  ".node.js",
177
181
  ".node.jsx",
178
182
  ".node.ts",
@@ -181,9 +185,21 @@ function applyNodeCompat(chain, modernConfig, isProd) {
181
185
  ".server.ts",
182
186
  ".server.ts",
183
187
  ".server.tsx"
184
- ]) {
188
+ ];
189
+ const webWorkerExts = [
190
+ ".worker.js",
191
+ ".worker.jsx",
192
+ ".worker.ts",
193
+ ".worker.tsx"
194
+ ];
195
+ for (const ext of nodeExts) {
185
196
  chain.resolve.extensions.prepend(ext);
186
197
  }
198
+ if (target === "service-worker") {
199
+ for (const ext of webWorkerExts) {
200
+ chain.resolve.extensions.prepend(ext);
201
+ }
202
+ }
187
203
  filterEntriesBySSRConfig(
188
204
  isProd,
189
205
  chain,
@@ -161,7 +161,7 @@ var createImportSpecifier = function(specifiers) {
161
161
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
162
162
  try {
163
163
  for(var _iterator = specifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
164
- var _value = _step.value, local = _value.local, imported = _value.imported;
164
+ var _step_value = _step.value, local = _step_value.local, imported = _step_value.imported;
165
165
  if (local && imported) {
166
166
  named.push("".concat(imported, " as ").concat(local));
167
167
  } else if (local) {
@@ -198,7 +198,7 @@ var createImportStatements = function(statements) {
198
198
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
199
199
  try {
200
200
  var _loop = function() {
201
- var _value = _step.value, value = _value.value, specifiers = _value.specifiers, initialize = _value.initialize;
201
+ var _step_value = _step.value, value = _step_value.value, specifiers = _step_value.specifiers, initialize = _step_value.initialize;
202
202
  if (!seen.has(value)) {
203
203
  deDuplicated.push({
204
204
  value: value,
@@ -207,14 +207,14 @@ var createImportStatements = function(statements) {
207
207
  });
208
208
  seen.set(value, specifiers);
209
209
  } else {
210
- var _instance;
211
- var ref;
212
- (_instance = seen.get(value)).push.apply(_instance, _toConsumableArray(specifiers));
210
+ var _seen_get;
211
+ var _deDuplicated_modifyIndex;
212
+ (_seen_get = seen.get(value)).push.apply(_seen_get, _toConsumableArray(specifiers));
213
213
  var modifyIndex = deDuplicated.findIndex(function(v) {
214
214
  return v.value === value;
215
215
  });
216
- var ref1;
217
- var originInitialize = (ref1 = (ref = deDuplicated[modifyIndex]) === null || ref === void 0 ? void 0 : ref.initialize) !== null && ref1 !== void 0 ? ref1 : "";
216
+ var _deDuplicated_modifyIndex_initialize;
217
+ var originInitialize = (_deDuplicated_modifyIndex_initialize = (_deDuplicated_modifyIndex = deDuplicated[modifyIndex]) === null || _deDuplicated_modifyIndex === void 0 ? void 0 : _deDuplicated_modifyIndex.initialize) !== null && _deDuplicated_modifyIndex_initialize !== void 0 ? _deDuplicated_modifyIndex_initialize : "";
218
218
  deDuplicated[modifyIndex].initialize = originInitialize.concat("\n".concat(initialize || ""));
219
219
  }
220
220
  };
@@ -240,13 +240,13 @@ var createImportStatements = function(statements) {
240
240
  };
241
241
  var generateCode = function() {
242
242
  var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
243
- var ref, ref1, ref2, internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
243
+ var _config_runtime, _config_runtime1, _config_runtime_router, internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
244
244
  function generateEntryCode(entrypoint) {
245
245
  return _generateEntryCode.apply(this, arguments);
246
246
  }
247
247
  function _generateEntryCode() {
248
248
  _generateEntryCode = _asyncToGenerator(function(entrypoint) {
249
- var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, ref, code2, _, _tmp, routesServerFile, code3, ref1, importStatements, plugins, ref2, renderFunction, exportStatement, code, entryFile, ref3, asyncEntryCode, bootstrapFile;
249
+ var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
250
250
  return __generator(this, function(_state) {
251
251
  switch(_state.label){
252
252
  case 0:
@@ -346,7 +346,7 @@ var generateCode = function() {
346
346
  ])
347
347
  ];
348
348
  case 6:
349
- ref = _state.sent(), code2 = ref.code;
349
+ _ref = _state.sent(), code2 = _ref.code;
350
350
  if (!(entrypoint.nestedRoutesEntry && mode)) return [
351
351
  3,
352
352
  9
@@ -386,7 +386,7 @@ var generateCode = function() {
386
386
  })
387
387
  ];
388
388
  case 11:
389
- ref1 = _state.sent(), importStatements = ref1.imports;
389
+ _ref1 = _state.sent(), importStatements = _ref1.imports;
390
390
  return [
391
391
  4,
392
392
  hookRunners.modifyEntryRuntimePlugins({
@@ -408,7 +408,7 @@ var generateCode = function() {
408
408
  })
409
409
  ];
410
410
  case 13:
411
- ref2 = _state.sent(), renderFunction = ref2.code;
411
+ _ref2 = _state.sent(), renderFunction = _ref2.code;
412
412
  return [
413
413
  4,
414
414
  hookRunners.modifyEntryExport({
@@ -438,7 +438,7 @@ var generateCode = function() {
438
438
  })
439
439
  ];
440
440
  case 15:
441
- ref3 = _state.sent(), asyncEntryCode = ref3.code;
441
+ _ref3 = _state.sent(), asyncEntryCode = _ref3.code;
442
442
  fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
443
443
  bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
444
444
  fs.outputFileSync(bootstrapFile, code, "utf8");
@@ -463,7 +463,7 @@ var generateCode = function() {
463
463
  case 0:
464
464
  internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
465
465
  hookRunners = api.useHookRunners();
466
- isV5 = typeof ((ref = config.runtime) === null || ref === void 0 ? void 0 : ref.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (ref1 = config.runtime) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.router) === null || ref2 === void 0 ? void 0 : ref2.mode) === "react-router-5";
466
+ isV5 = typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
467
467
  mountId = config.html.mountId;
468
468
  getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
469
469
  return [
@@ -24,7 +24,7 @@ var ifAlreadyExists = function(entrypoints, checked) {
24
24
  };
25
25
  var getBundleEntry = function(appContext, config) {
26
26
  var appDirectory = appContext.appDirectory, packageName = appContext.packageName;
27
- var _source = config.source, disableDefaultEntries = _source.disableDefaultEntries, entries = _source.entries, entriesDir = _source.entriesDir;
27
+ var _config_source = config.source, disableDefaultEntries = _config_source.disableDefaultEntries, entries = _config_source.entries, entriesDir = _config_source.entriesDir;
28
28
  var defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config);
29
29
  if (entries) {
30
30
  Object.keys(entries).forEach(function(name) {
@@ -52,7 +52,7 @@ var getBundleEntry = function(appContext, config) {
52
52
  if (!disableDefaultEntries) {
53
53
  var entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir || "");
54
54
  var found = defaults.find(function(param) {
55
- var entryName = param.entryName, entry = param.entry, _nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _nestedRoutesEntry === void 0 ? "" : _nestedRoutesEntry;
55
+ var entryName = param.entryName, entry = param.entry, _param_nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _param_nestedRoutesEntry === void 0 ? "" : _param_nestedRoutesEntry;
56
56
  return entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs;
57
57
  });
58
58
  found && (found.entryName = MAIN_ENTRY_NAME);
@@ -67,7 +67,7 @@ var layoutNameAbbr = function(filePath) {
67
67
  };
68
68
  var parents = [];
69
69
  var recursiveReadDir = function(param) {
70
- var dir = param.dir, routes = param.routes, _basePath = param.basePath, basePath = _basePath === void 0 ? "/" : _basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
70
+ var dir = param.dir, routes = param.routes, _param_basePath = param.basePath, basePath = _param_basePath === void 0 ? "/" : _param_basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
71
71
  var hasDynamicRoute = false;
72
72
  var resetParent = false;
73
73
  var parent = parents[parents.length - 1];
@@ -67,7 +67,7 @@ var layoutNameAbbr = function(filePath) {
67
67
  };
68
68
  var parents = [];
69
69
  var recursiveReadDirLegacy = function(param) {
70
- var dir = param.dir, routes = param.routes, _basePath = param.basePath, basePath = _basePath === void 0 ? "/" : _basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
70
+ var dir = param.dir, routes = param.routes, _param_basePath = param.basePath, basePath = _param_basePath === void 0 ? "/" : _param_basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
71
71
  var hasDynamicRoute = false;
72
72
  var resetParent = false;
73
73
  var parent = parents[parents.length - 1];
@@ -80,7 +80,7 @@ var scanDir = function(dirs) {
80
80
  };
81
81
  var getFileSystemEntry = function(appContext, config) {
82
82
  var appDirectory = appContext.appDirectory;
83
- var _source = config.source, entriesDir = _source.entriesDir, disableEntryDirs = _source.disableEntryDirs;
83
+ var _config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs;
84
84
  var disabledDirs = [];
85
85
  if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
86
86
  disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map(function(dir) {
@@ -104,7 +104,7 @@ function _unsupportedIterableToArray(o, minLen) {
104
104
  }
105
105
  import path from "path";
106
106
  import fs from "fs";
107
- import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash } from "@modern-js/utils";
107
+ import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
108
108
  import { walkDirectory } from "./utils";
109
109
  var applyBaseUrl = function(baseUrl, routes) {
110
110
  if (baseUrl) {
@@ -130,8 +130,8 @@ var applyRouteOptions = function(original, routeOptions) {
130
130
  var routes;
131
131
  if (route) {
132
132
  if (Array.isArray(route)) {
133
- var _tmp;
134
- _tmp = route.map(function(url) {
133
+ var _route_map;
134
+ _route_map = route.map(function(url) {
135
135
  if (isPlainObject(url)) {
136
136
  var urlPath = url.path, other = _objectWithoutProperties(url, [
137
137
  "path"
@@ -144,7 +144,7 @@ var applyRouteOptions = function(original, routeOptions) {
144
144
  urlPath: url
145
145
  });
146
146
  }
147
- }), routes = _tmp, _tmp;
147
+ }), routes = _route_map, _route_map;
148
148
  } else if (isPlainObject(route)) {
149
149
  var urlPath = route.path, other = _objectWithoutProperties(route, [
150
150
  "path"
@@ -169,12 +169,13 @@ var applyRouteOptions = function(original, routeOptions) {
169
169
  return routes;
170
170
  };
171
171
  var collectHtmlRoutes = function(entrypoints, appContext, config) {
172
- var disableHtmlFolder = config.html.disableHtmlFolder, _output = config.output, tmp = _output.distPath, ref = tmp === void 0 ? {} : tmp, htmlPath = ref.html, _server = config.server, baseUrl = _server.baseUrl, routes = _server.routes, ssr = _server.ssr, ssrByEntries = _server.ssrByEntries;
172
+ var disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, worker = _config_server.worker;
173
173
  var packageName = appContext.packageName;
174
174
  var htmlRoutes = entrypoints.reduce(function(previous, param) {
175
175
  var entryName = param.entryName;
176
176
  var entryOptions = getEntryOptions(entryName, ssr, ssrByEntries, packageName);
177
177
  var isSSR = Boolean(entryOptions);
178
+ var isWorker = Boolean(worker);
178
179
  var resHeaders = ((routes === null || routes === void 0 ? void 0 : routes[entryName]) || {}).resHeaders;
179
180
  var route = {
180
181
  urlPath: "/".concat(entryName === MAIN_ENTRY_NAME ? "" : entryName),
@@ -183,6 +184,7 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
183
184
  isSPA: true,
184
185
  isSSR: isSSR,
185
186
  responseHeaders: resHeaders,
187
+ worker: isWorker ? "".concat(SERVER_WORKER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0,
186
188
  bundle: isSSR ? "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0
187
189
  };
188
190
  if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
@@ -200,7 +202,7 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
200
202
  };
201
203
  var collectStaticRoutes = function(appContext, config) {
202
204
  var appDirectory = appContext.appDirectory;
203
- var configDir = config.source.configDir, _server = config.server, _publicRoutes = _server.publicRoutes, publicRoutes = _publicRoutes === void 0 ? {} : _publicRoutes;
205
+ var configDir = config.source.configDir, _config_server = config.server, _config_server_publicRoutes = _config_server.publicRoutes, publicRoutes = _config_server_publicRoutes === void 0 ? {} : _config_server_publicRoutes;
204
206
  var publicFolder = path.resolve(appDirectory, configDir || "", "public");
205
207
  return fs.existsSync(publicFolder) ? walkDirectory(publicFolder).map(function(filePath) {
206
208
  var urlPath = "".concat(urlJoin(toPosix(filePath).slice(toPosix(publicFolder).length)));
@@ -243,7 +243,7 @@ var analyze_default = function(param) {
243
243
  return {
244
244
  prepare: function prepare() {
245
245
  return _asyncToGenerator(function() {
246
- var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes, htmlTemplates, checkedEntries, entry, command, buildCommands, normalizedConfig, createBuilderForModern, builder;
246
+ var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, _ref, routes2, _ref1, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, initialRoutes, routes, htmlTemplates, checkedEntries, entry, command, buildCommands, normalizedConfig, createBuilderForModern, builder;
247
247
  return __generator(this, function(_state) {
248
248
  switch(_state.label){
249
249
  case 0:
@@ -255,7 +255,7 @@ var analyze_default = function(param) {
255
255
  } catch (e) {}
256
256
  return [
257
257
  4,
258
- isApiOnly(appContext.appDirectory, (ref = resolvedConfig.source) === null || ref === void 0 ? void 0 : ref.entriesDir)
258
+ isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir)
259
259
  ];
260
260
  case 1:
261
261
  apiOnly = _state.sent();
@@ -276,7 +276,7 @@ var analyze_default = function(param) {
276
276
  })
277
277
  ];
278
278
  case 3:
279
- ref1 = _state.sent(), routes2 = ref1.routes;
279
+ _ref = _state.sent(), routes2 = _ref.routes;
280
280
  debug("server routes: %o", routes2);
281
281
  appContext = _objectSpreadProps(_objectSpread({}, appContext), {
282
282
  apiOnly: apiOnly,
@@ -297,10 +297,10 @@ var analyze_default = function(param) {
297
297
  ])
298
298
  ];
299
299
  case 5:
300
- ref2 = _slicedToArray.apply(void 0, [
300
+ _ref1 = _slicedToArray.apply(void 0, [
301
301
  _state.sent(),
302
302
  4
303
- ]), getBundleEntry = ref2[0].getBundleEntry, getServerRoutes = ref2[1].getServerRoutes, generateCode = ref2[2].generateCode, getHtmlTemplate = ref2[3].getHtmlTemplate;
303
+ ]), getBundleEntry = _ref1[0].getBundleEntry, getServerRoutes = _ref1[1].getServerRoutes, generateCode = _ref1[2].generateCode, getHtmlTemplate = _ref1[3].getHtmlTemplate;
304
304
  entrypoints = getBundleEntry(appContext, resolvedConfig);
305
305
  debug("entrypoints: %o", entrypoints);
306
306
  initialRoutes = getServerRoutes(entrypoints, {
@@ -573,7 +573,7 @@ var analyze_default = function(param) {
573
573
  modifyEntryImports: function modifyEntryImports(param) {
574
574
  var entrypoint = param.entrypoint, imports = param.imports;
575
575
  return _asyncToGenerator(function() {
576
- var appContext, srcDirectory, internalSrcAlias, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout, ref, moduleExports, hasAppConfig, generateLayoutPath, hasAppInit;
576
+ var appContext, srcDirectory, internalSrcAlias, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout, _ref, moduleExports, hasAppConfig, generateLayoutPath, hasAppInit;
577
577
  return __generator(this, function(_state) {
578
578
  switch(_state.label){
579
579
  case 0:
@@ -612,10 +612,10 @@ var analyze_default = function(param) {
612
612
  })
613
613
  ];
614
614
  case 2:
615
- ref = _slicedToArray.apply(void 0, [
615
+ _ref = _slicedToArray.apply(void 0, [
616
616
  _state.sent(),
617
617
  2
618
- ]), moduleExports = ref[1];
618
+ ]), moduleExports = _ref[1];
619
619
  hasAppConfig = moduleExports.some(function(e) {
620
620
  return e.n === APP_CONFIG_NAME;
621
621
  });