@modern-js/app-tools 2.54.6 → 2.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +84 -0
  2. package/dist/cjs/builder/generator/index.js +6 -5
  3. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +7 -14
  4. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +8 -8
  5. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +6 -8
  6. package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +5 -3
  7. package/dist/cjs/commands/index.js +2 -2
  8. package/dist/cjs/commands/inspect.js +1 -2
  9. package/dist/cjs/commands/serve.js +1 -0
  10. package/dist/cjs/config/default.js +2 -2
  11. package/dist/cjs/config/legacy/createSourceConfig.js +2 -1
  12. package/dist/cjs/config/legacy/index.js +1 -0
  13. package/dist/cjs/hooks.js +2 -5
  14. package/dist/cjs/plugins/analyze/constants.js +3 -18
  15. package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -1
  16. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +36 -11
  17. package/dist/cjs/plugins/analyze/index.js +7 -64
  18. package/dist/cjs/plugins/analyze/templates.js +2 -55
  19. package/dist/cjs/plugins/analyze/utils.js +0 -86
  20. package/dist/esm/builder/generator/{createBuilderOptions.js → getBuilderEnvironments.js} +43 -7
  21. package/dist/esm/builder/generator/index.js +9 -9
  22. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +7 -14
  23. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +8 -8
  24. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +6 -8
  25. package/dist/esm/builder/shared/builderPlugins/adapterWorker.js +6 -4
  26. package/dist/esm/commands/index.js +1 -1
  27. package/dist/esm/commands/inspect.js +1 -2
  28. package/dist/esm/commands/serve.js +1 -0
  29. package/dist/esm/config/default.js +2 -5
  30. package/dist/esm/config/legacy/createSourceConfig.js +2 -1
  31. package/dist/esm/config/legacy/index.js +1 -0
  32. package/dist/esm/hooks.js +2 -5
  33. package/dist/esm/plugins/analyze/constants.js +2 -12
  34. package/dist/esm/plugins/analyze/getBundleEntry.js +2 -1
  35. package/dist/esm/plugins/analyze/getFileSystemEntry.js +57 -14
  36. package/dist/esm/plugins/analyze/index.js +25 -128
  37. package/dist/esm/plugins/analyze/templates.js +1 -17
  38. package/dist/esm/plugins/analyze/utils.js +1 -87
  39. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
  40. package/dist/esm-node/builder/generator/index.js +6 -5
  41. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +7 -14
  42. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +7 -7
  43. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +5 -7
  44. package/dist/esm-node/builder/shared/builderPlugins/adapterWorker.js +5 -3
  45. package/dist/esm-node/commands/index.js +1 -1
  46. package/dist/esm-node/commands/inspect.js +1 -2
  47. package/dist/esm-node/commands/serve.js +1 -0
  48. package/dist/esm-node/config/default.js +2 -2
  49. package/dist/esm-node/config/legacy/createSourceConfig.js +2 -1
  50. package/dist/esm-node/config/legacy/index.js +1 -0
  51. package/dist/esm-node/hooks.js +2 -5
  52. package/dist/esm-node/plugins/analyze/constants.js +2 -12
  53. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -1
  54. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +37 -12
  55. package/dist/esm-node/plugins/analyze/index.js +10 -67
  56. package/dist/esm-node/plugins/analyze/templates.js +1 -52
  57. package/dist/esm-node/plugins/analyze/utils.js +1 -86
  58. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  59. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +5 -0
  60. package/dist/types/builder/generator/index.d.ts +1 -2
  61. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +1 -1
  62. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
  63. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
  64. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +1 -1
  65. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
  66. package/dist/types/commands/inspect.d.ts +1 -1
  67. package/dist/types/plugins/analyze/constants.d.ts +1 -6
  68. package/dist/types/plugins/analyze/templates.d.ts +0 -14
  69. package/dist/types/plugins/analyze/utils.d.ts +0 -11
  70. package/dist/types/types/config/index.d.ts +2 -0
  71. package/dist/types/types/config/source.d.ts +11 -0
  72. package/dist/types/types/hooks.d.ts +7 -27
  73. package/dist/types/types/index.d.ts +1 -1
  74. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  75. package/dist/types/types/legacyConfig/source.d.ts +4 -0
  76. package/dist/types/utils/register.d.ts +1 -1
  77. package/package.json +22 -23
  78. package/dist/cjs/builder/generator/createBuilderOptions.js +0 -50
  79. package/dist/cjs/builder/generator/getBuilderTargets.js +0 -42
  80. package/dist/cjs/plugins/analyze/generateCode.js +0 -185
  81. package/dist/esm/builder/generator/getBuilderTargets.js +0 -18
  82. package/dist/esm/plugins/analyze/generateCode.js +0 -296
  83. package/dist/esm-node/builder/generator/createBuilderOptions.js +0 -26
  84. package/dist/esm-node/builder/generator/getBuilderTargets.js +0 -18
  85. package/dist/esm-node/plugins/analyze/generateCode.js +0 -149
  86. package/dist/types/builder/generator/createBuilderOptions.d.ts +0 -4
  87. package/dist/types/builder/generator/getBuilderTargets.d.ts +0 -3
  88. package/dist/types/plugins/analyze/generateCode.d.ts +0 -16
@@ -18,60 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var templates_exports = {};
20
20
  __export(templates_exports, {
21
- html: () => html,
22
- index: () => index,
23
- renderFunction: () => renderFunction
21
+ html: () => html
24
22
  });
25
23
  module.exports = __toCommonJS(templates_exports);
26
- var import_constants = require("./constants");
27
- const index = ({ mountId, imports, renderFunction: renderFunction2, exportStatement }) => `
28
- const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
29
- const IS_REACT18 = process.env.IS_REACT18 === 'true';
30
- const MOUNT_ID = '${mountId}';
31
-
32
- ${imports}
33
-
34
- let AppWrapper = null;
35
-
36
- let root = null;
37
-
38
- function render() {
39
- ${renderFunction2}
40
- }
41
-
42
- AppWrapper = render();
43
-
44
- ${exportStatement};
45
- `;
46
- const renderFunction = ({ plugins, customBootstrap, fileSystemRoutes, customRuntimeConfig }) => {
47
- const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
48
- const runtimePlugins = `...(runtimeConfig?.plugins || []),`;
49
- return `
50
- const finalAppConfig = {
51
- ...App.config,
52
- ...typeof ${import_constants.APP_CONFIG_NAME} === 'function' ? ${import_constants.APP_CONFIG_NAME}() : {},
53
- }
54
-
55
- AppWrapper = createApp({
56
- plugins: [
57
- ${plugins.map(({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`).join("\n")}
58
- ${customRuntimeConfig ? runtimePlugins : ""}
59
- ]
60
- })(${fileSystemRoutes ? "" : `App`})
61
-
62
-
63
- if(!AppWrapper.init && typeof appInit !== 'undefined') {
64
- AppWrapper.init = appInit;
65
- }
66
-
67
-
68
- if (IS_BROWSER) {
69
- ${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
70
- }
71
-
72
- return AppWrapper
73
- `;
74
- };
75
24
  const html = (partials) => `
76
25
  <!DOCTYPE html>
77
26
  <html>
@@ -95,7 +44,5 @@ const html = (partials) => `
95
44
  `;
96
45
  // Annotate the CommonJS export names for ESM import in node:
97
46
  0 && (module.exports = {
98
- html,
99
- index,
100
- renderFunction
47
+ html
101
48
  });
@@ -29,7 +29,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var utils_exports = {};
30
30
  __export(utils_exports, {
31
31
  checkIsBuildCommands: () => checkIsBuildCommands,
32
- getDefaultImports: () => getDefaultImports,
33
32
  getServerCombinedModueFile: () => getServerCombinedModueFile,
34
33
  isSubDirOrEqual: () => isSubDirOrEqual,
35
34
  parseModule: () => parseModule,
@@ -42,7 +41,6 @@ var import_path = __toESM(require("path"));
42
41
  var import_utils = require("@modern-js/utils");
43
42
  var import_esbuild = require("esbuild");
44
43
  var import_es_module_lexer = require("es-module-lexer");
45
- var import_constants = require("./constants");
46
44
  const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previous, filename) => {
47
45
  const filePath = import_path.default.join(dir, filename);
48
46
  if (import_fs.default.statSync(filePath).isDirectory()) {
@@ -57,89 +55,6 @@ const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previo
57
55
  ];
58
56
  }
59
57
  }, []);
60
- const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, runtimeConfigFile, customRuntimeConfig }) => {
61
- const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
62
- const imports = [
63
- {
64
- specifiers: [
65
- {
66
- local: "React"
67
- }
68
- ],
69
- value: "react"
70
- },
71
- {
72
- specifiers: [
73
- {
74
- local: "ReactDOM"
75
- }
76
- ],
77
- value: (0, import_utils.isReact18)(import_path.default.join(appDirectory)) ? "react-dom/client" : "react-dom"
78
- },
79
- {
80
- specifiers: [
81
- {
82
- imported: "createApp"
83
- },
84
- {
85
- imported: "bootstrap"
86
- }
87
- ],
88
- value: "@modern-js/runtime"
89
- },
90
- customBootstrap && {
91
- specifiers: [
92
- {
93
- local: "customBootstrap"
94
- }
95
- ],
96
- value: (0, import_utils.normalizeToPosixPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))
97
- }
98
- ].filter(Boolean);
99
- if (fileSystemRoutes) {
100
- const route = {
101
- specifiers: [
102
- {
103
- imported: "routes"
104
- }
105
- ],
106
- value: (0, import_utils.normalizeToPosixPath)(`${internalDirAlias}/${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME.replace(".js", "")}`)
107
- };
108
- if (fileSystemRoutes.globalApp) {
109
- imports.push({
110
- specifiers: [
111
- {
112
- local: "App"
113
- }
114
- ],
115
- value: (0, import_utils.normalizeToPosixPath)(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
116
- });
117
- } else {
118
- route.initialize = "const App = false;";
119
- }
120
- imports.push(route);
121
- } else {
122
- imports.push({
123
- specifiers: [
124
- {
125
- local: "App"
126
- }
127
- ],
128
- value: (0, import_utils.normalizeToPosixPath)(entry.replace(srcDirectory, internalSrcAlias))
129
- });
130
- }
131
- if (customRuntimeConfig) {
132
- imports.push({
133
- specifiers: [
134
- {
135
- local: "runtimeConfig"
136
- }
137
- ],
138
- value: import_path.default.join(internalSrcAlias, runtimeConfigFile || "")
139
- });
140
- }
141
- return imports;
142
- };
143
58
  const replaceWithAlias = (base, filePath, alias) => {
144
59
  if (filePath.includes(base)) {
145
60
  return (0, import_utils.normalizeToPosixPath)(import_path.default.join(alias, import_path.default.relative(base, filePath)));
@@ -184,7 +99,6 @@ const isSubDirOrEqual = (parent, child) => {
184
99
  // Annotate the CommonJS export names for ESM import in node:
185
100
  0 && (module.exports = {
186
101
  checkIsBuildCommands,
187
- getDefaultImports,
188
102
  getServerCombinedModueFile,
189
103
  isSubDirOrEqual,
190
104
  parseModule,
@@ -1,4 +1,6 @@
1
- function createBuilderOptions(target, appContext) {
1
+ import { isProd, isServiceWorker, isSSR, isUseSSRBundle } from "@modern-js/utils";
2
+ import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
3
+ function getBuilderEnvironments(normalizedConfig, appContext) {
2
4
  var entries = {};
3
5
  var _appContext_entrypoints = appContext.entrypoints, entrypoints = _appContext_entrypoints === void 0 ? [] : _appContext_entrypoints, checkedEntries = appContext.checkedEntries;
4
6
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
@@ -31,13 +33,47 @@ function createBuilderOptions(target, appContext) {
31
33
  }
32
34
  }
33
35
  }
34
- return {
35
- cwd: appContext.appDirectory,
36
- target,
37
- frameworkConfigPath: appContext.configFile || void 0,
38
- entry: entries
36
+ var serverEntries = {};
37
+ for (var entry1 in entries) {
38
+ var v = entries[entry1];
39
+ serverEntries[entry1] = v.map(function(entry2) {
40
+ return entry2.replace("index.jsx", "index.server.jsx");
41
+ });
42
+ }
43
+ var environments = {
44
+ web: {
45
+ output: {
46
+ target: "web"
47
+ },
48
+ source: {
49
+ entry: entries
50
+ }
51
+ }
39
52
  };
53
+ var useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
54
+ if (useNodeTarget) {
55
+ environments.node = {
56
+ output: {
57
+ target: "node"
58
+ },
59
+ source: {
60
+ entry: serverEntries
61
+ }
62
+ };
63
+ }
64
+ var useWorkerTarget = isServiceWorker(normalizedConfig);
65
+ if (useWorkerTarget) {
66
+ environments[SERVICE_WORKER_ENVIRONMENT_NAME] = {
67
+ output: {
68
+ target: "web-worker"
69
+ },
70
+ source: {
71
+ entry: serverEntries
72
+ }
73
+ };
74
+ }
75
+ return environments;
40
76
  }
41
77
  export {
42
- createBuilderOptions
78
+ getBuilderEnvironments
43
79
  };
@@ -1,30 +1,30 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
3
  import { createUniBuilder } from "@modern-js/uni-builder";
4
+ import { mergeRsbuildConfig } from "@rsbuild/core";
6
5
  import { createBuilderProviderConfig } from "./createBuilderProviderConfig";
7
- import { getBuilderTargets } from "./getBuilderTargets";
8
- import { createBuilderOptions } from "./createBuilderOptions";
6
+ import { getBuilderEnvironments } from "./getBuilderEnvironments";
9
7
  function generateBuilder(options, bundlerType) {
10
8
  return _generateBuilder.apply(this, arguments);
11
9
  }
12
10
  function _generateBuilder() {
13
11
  _generateBuilder = _async_to_generator(function(options, bundlerType) {
14
- var normalizedConfig, appContext, builderConfig, target, builderOptions, builder;
12
+ var normalizedConfig, appContext, builderConfig, environments, builder;
15
13
  return _ts_generator(this, function(_state) {
16
14
  switch (_state.label) {
17
15
  case 0:
18
16
  normalizedConfig = options.normalizedConfig, appContext = options.appContext;
19
17
  builderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
20
- target = getBuilderTargets(normalizedConfig);
21
- builderOptions = createBuilderOptions(target, appContext);
18
+ environments = getBuilderEnvironments(normalizedConfig, appContext);
19
+ builderConfig.environments = builderConfig.environments ? mergeRsbuildConfig(environments, builderConfig.environments) : environments;
22
20
  return [
23
21
  4,
24
- createUniBuilder(_object_spread_props(_object_spread({}, builderOptions), {
22
+ createUniBuilder({
23
+ cwd: appContext.appDirectory,
24
+ frameworkConfigPath: appContext.configFile || void 0,
25
25
  bundlerType,
26
26
  config: builderConfig
27
- }))
27
+ })
28
28
  ];
29
29
  case 1:
30
30
  builder = _state.sent();
@@ -1,21 +1,14 @@
1
1
  import path from "path";
2
+ import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
2
3
  var builderPluginAdapterBasic = function() {
3
4
  return {
4
5
  name: "builder-plugin-adapter-modern-basic",
5
6
  setup: function setup(api) {
6
7
  api.modifyBundlerChain(function(chain, param) {
7
- var target = param.target, CHAIN_ID = param.CHAIN_ID;
8
- if (target === "node") {
9
- chain.name("server");
10
- } else if (target === "service-worker") {
11
- chain.name("service-worker");
12
- } else if (target === "web-worker") {
13
- chain.name("worker");
14
- } else {
15
- chain.name("client");
16
- }
17
- if (target === "node" || target === "service-worker") {
18
- applyNodeCompat(target, chain);
8
+ var target = param.target, CHAIN_ID = param.CHAIN_ID, environment = param.environment;
9
+ var isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
10
+ if (target === "node" || isServiceWorker) {
11
+ applyNodeCompat(isServiceWorker, chain);
19
12
  }
20
13
  if (target === "web") {
21
14
  var bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
@@ -27,7 +20,7 @@ var builderPluginAdapterBasic = function() {
27
20
  }
28
21
  };
29
22
  };
30
- function applyNodeCompat(target, chain) {
23
+ function applyNodeCompat(isServiceWorker, chain) {
31
24
  var nodeExts = [
32
25
  ".node.js",
33
26
  ".node.jsx",
@@ -64,7 +57,7 @@ function applyNodeCompat(target, chain) {
64
57
  }
65
58
  }
66
59
  }
67
- if (target === "service-worker") {
60
+ if (isServiceWorker) {
68
61
  var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
69
62
  try {
70
63
  for (var _iterator1 = webWorkerExts[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
@@ -2,7 +2,7 @@ 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 { isHtmlDisabled } from "@rsbuild/shared";
5
+ import { isHtmlDisabled } from "@modern-js/uni-builder";
6
6
  import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
7
7
  import { template as lodashTemplate } from "@modern-js/utils/lodash";
8
8
  import { BottomTemplatePlugin } from "../bundlerPlugins";
@@ -15,23 +15,23 @@ var builderPluginAdapterHtml = function(options) {
15
15
  setup: function setup(api) {
16
16
  api.modifyBundlerChain(function() {
17
17
  var _ref = _async_to_generator(function(chain, param) {
18
- var CHAIN_ID, target, HtmlBundlerPlugin, builderConfig;
18
+ var CHAIN_ID, target, HtmlBundlerPlugin, environment, builderConfig;
19
19
  return _ts_generator(this, function(_state) {
20
20
  switch (_state.label) {
21
21
  case 0:
22
- CHAIN_ID = param.CHAIN_ID, target = param.target, HtmlBundlerPlugin = param.HtmlPlugin;
23
- builderConfig = api.getNormalizedConfig();
22
+ CHAIN_ID = param.CHAIN_ID, target = param.target, HtmlBundlerPlugin = param.HtmlPlugin, environment = param.environment;
23
+ builderConfig = environment.config;
24
24
  if (!!isHtmlDisabled(builderConfig, target))
25
25
  return [
26
26
  3,
27
27
  2
28
28
  ];
29
29
  applyBottomHtmlPlugin({
30
- api,
31
30
  options,
32
31
  chain,
33
32
  CHAIN_ID,
34
- HtmlBundlerPlugin
33
+ HtmlBundlerPlugin,
34
+ htmlPaths: environment.htmlPaths
35
35
  });
36
36
  return [
37
37
  4,
@@ -79,7 +79,7 @@ function _injectAssetPrefix() {
79
79
  return _injectAssetPrefix.apply(this, arguments);
80
80
  }
81
81
  function applyBottomHtmlPlugin(param) {
82
- var api = param.api, chain = param.chain, options = param.options, CHAIN_ID = param.CHAIN_ID, HtmlBundlerPlugin = param.HtmlBundlerPlugin;
82
+ var chain = param.chain, options = param.options, CHAIN_ID = param.CHAIN_ID, HtmlBundlerPlugin = param.HtmlBundlerPlugin, htmlPaths = param.htmlPaths;
83
83
  var modernConfig = options.normalizedConfig, appContext = options.appContext;
84
84
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
85
85
  try {
@@ -101,7 +101,7 @@ function applyBottomHtmlPlugin(param) {
101
101
  ];
102
102
  });
103
103
  };
104
- for (var _iterator = Object.keys(api.context.entry)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
104
+ for (var _iterator = Object.keys(htmlPaths)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
105
105
  _loop();
106
106
  } catch (err) {
107
107
  _didIteratorError = true;
@@ -1,9 +1,9 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import * as path from "path";
4
- import { isHtmlDisabled } from "@rsbuild/shared";
5
4
  import { mergeRsbuildConfig } from "@rsbuild/core";
6
5
  import { fs, isUseSSRBundle } from "@modern-js/utils";
6
+ import { isHtmlDisabled, SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
7
7
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
8
8
  import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
9
9
  var builderPluginAdapterSSR = function(options) {
@@ -25,12 +25,12 @@ var builderPluginAdapterSSR = function(options) {
25
25
  });
26
26
  api.modifyBundlerChain(function() {
27
27
  var _ref = _async_to_generator(function(chain, param) {
28
- var target, isProd, HtmlBundlerPlugin, isServer, builderConfig, normalizedConfig2;
28
+ var target, isProd, HtmlBundlerPlugin, isServer, environment, builderConfig, normalizedConfig2, isServiceWorker;
29
29
  return _ts_generator(this, function(_state) {
30
30
  switch (_state.label) {
31
31
  case 0:
32
- target = param.target, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer;
33
- builderConfig = api.getNormalizedConfig();
32
+ target = param.target, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer, environment = param.environment;
33
+ builderConfig = environment.config;
34
34
  normalizedConfig2 = options.normalizedConfig;
35
35
  applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
36
36
  if (!isUseSSRBundle(normalizedConfig2))
@@ -47,10 +47,8 @@ var builderPluginAdapterSSR = function(options) {
47
47
  applySSRDataLoader(chain, options);
48
48
  _state.label = 2;
49
49
  case 2:
50
- if ([
51
- "node",
52
- "service-worker"
53
- ].includes(target)) {
50
+ isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
51
+ if (target === "node" || isServiceWorker) {
54
52
  applyFilterEntriesBySSRConfig({
55
53
  isProd,
56
54
  chain,
@@ -1,6 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { posix } from "path";
4
+ import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
4
5
  var getDistPath = function(outputConfig, type) {
5
6
  var distPath = outputConfig.distPath;
6
7
  var ret = distPath[type];
@@ -15,12 +16,13 @@ var builderPluginAdapterWorker = function() {
15
16
  setup: function setup(api) {
16
17
  api.modifyBundlerChain(function() {
17
18
  var _ref = _async_to_generator(function(chain, param) {
18
- var isServiceWorker, config, workerPath, filename;
19
+ var environment, config, name, isServiceWorker, workerPath, filename;
19
20
  return _ts_generator(this, function(_state) {
20
- isServiceWorker = param.isServiceWorker;
21
- config = api.getNormalizedConfig();
21
+ environment = param.environment;
22
+ config = environment.config, name = environment.name;
23
+ isServiceWorker = name === SERVICE_WORKER_ENVIRONMENT_NAME;
22
24
  if (isServiceWorker) {
23
- workerPath = getDistPath(config.output, "worker");
25
+ workerPath = getDistPath(config.output, "root");
24
26
  filename = posix.join(workerPath, "[name].js");
25
27
  chain.output.filename(filename).chunkFilename(filename).libraryTarget("commonjs2");
26
28
  }
@@ -3,7 +3,7 @@ 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
5
  import { newAction, upgradeAction } from "@modern-js/utils";
6
- import { castArray } from "@rsbuild/shared";
6
+ import { castArray } from "@modern-js/uni-builder";
7
7
  import { i18n, localeKeys } from "../locale";
8
8
  var devCommand = function() {
9
9
  var _ref = _async_to_generator(function(program, api) {
@@ -1,6 +1,5 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import { join } from "path";
4
3
  var inspect = function() {
5
4
  var _ref = _async_to_generator(function(api, options) {
6
5
  var appContext;
@@ -14,7 +13,7 @@ var inspect = function() {
14
13
  appContext.builder.inspectConfig({
15
14
  env: options.env,
16
15
  verbose: options.verbose,
17
- outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
16
+ outputPath: options.output,
18
17
  writeToDisk: true
19
18
  })
20
19
  ];
@@ -42,6 +42,7 @@ var start = function() {
42
42
  pwd: distDirectory,
43
43
  config: _object_spread_props(_object_spread({}, userConfig), {
44
44
  dev: userConfig.dev,
45
+ // server-core can't get RegExp & Function output.enableInlineScripts by JSON.stringy;
45
46
  output: _object_spread({
46
47
  path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root
47
48
  }, userConfig.output || {})
@@ -16,11 +16,6 @@ function createDefaultConfig(appContext) {
16
16
  server: "bundles",
17
17
  worker: "worker"
18
18
  },
19
- // no need to emit assets for SSR bundles
20
- emitAssets: function(param) {
21
- var target = param.target;
22
- return target !== "node";
23
- },
24
19
  cleanDistPath: true,
25
20
  disableNodePolyfill: true,
26
21
  enableInlineRouteManifests: true,
@@ -31,6 +26,7 @@ function createDefaultConfig(appContext) {
31
26
  entries: void 0,
32
27
  mainEntryName: MAIN_ENTRY_NAME,
33
28
  enableAsyncEntry: false,
29
+ enableCustomEntry: false,
34
30
  disableDefaultEntries: false,
35
31
  entriesDir: "./src",
36
32
  configDir: "./config",
@@ -94,6 +90,7 @@ function createLegacyDefaultConfig(appContext) {
94
90
  entries: void 0,
95
91
  mainEntryName: MAIN_ENTRY_NAME,
96
92
  enableAsyncEntry: false,
93
+ enableCustomEntry: false,
97
94
  disableDefaultEntries: false,
98
95
  entriesDir: "./src",
99
96
  configDir: "./config",
@@ -1,5 +1,5 @@
1
1
  function createSourceConfig(config) {
2
- var _config_source = config.source, alias = _config_source.alias, envVars = _config_source.envVars, globalVars = _config_source.globalVars, include = _config_source.include, moduleScopes = _config_source.moduleScopes, preEntry = _config_source.preEntry, entries = _config_source.entries, mainEntryName = _config_source.mainEntryName, enableAsyncEntry = _config_source.enableAsyncEntry, disableDefaultEntries = _config_source.disableDefaultEntries, entriesDir = _config_source.entriesDir, configDir = _config_source.configDir;
2
+ var _config_source = config.source, alias = _config_source.alias, envVars = _config_source.envVars, globalVars = _config_source.globalVars, include = _config_source.include, moduleScopes = _config_source.moduleScopes, preEntry = _config_source.preEntry, entries = _config_source.entries, mainEntryName = _config_source.mainEntryName, enableAsyncEntry = _config_source.enableAsyncEntry, enableCustomEntry = _config_source.enableCustomEntry, disableDefaultEntries = _config_source.disableDefaultEntries, entriesDir = _config_source.entriesDir, configDir = _config_source.configDir;
3
3
  var builderGlobalVars = globalVars || {};
4
4
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
5
5
  try {
@@ -31,6 +31,7 @@ function createSourceConfig(config) {
31
31
  entries,
32
32
  mainEntryName,
33
33
  enableAsyncEntry,
34
+ enableCustomEntry,
34
35
  disableDefaultEntries,
35
36
  entriesDir,
36
37
  configDir,
@@ -27,6 +27,7 @@ function transformNormalizedConfig(config) {
27
27
  security: {},
28
28
  _raw: {},
29
29
  experiments: {},
30
+ environments: {},
30
31
  autoLoadPlugins,
31
32
  performance: {
32
33
  removeMomentLocale: true
package/dist/esm/hooks.js CHANGED
@@ -1,16 +1,13 @@
1
1
  import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
2
2
  var hooks = {
3
- modifyEntryExport: createAsyncWaterfall(),
4
- modifyEntryImports: createAsyncWaterfall(),
5
- modifyEntryRuntimePlugins: createAsyncWaterfall(),
6
- modifyEntryRenderFunction: createAsyncWaterfall(),
7
- modifyAsyncEntry: createAsyncWaterfall(),
3
+ _internalRuntimePlugins: createAsyncWaterfall(),
8
4
  modifyFileSystemRoutes: createAsyncWaterfall(),
9
5
  modifyServerRoutes: createAsyncWaterfall(),
10
6
  /** add entry point info to entrypoints array */
11
7
  modifyEntrypoints: createAsyncWaterfall(),
12
8
  /** add entry type */
13
9
  checkEntryPoint: createAsyncWaterfall(),
10
+ generateEntryCode: createAsyncWorkflow(),
14
11
  htmlPartials: createAsyncWaterfall(),
15
12
  beforeGenerateRoutes: createAsyncWaterfall(),
16
13
  addDefineTypes: createAsyncWaterfall(),
@@ -1,23 +1,13 @@
1
1
  var INDEX_FILE_NAME = "index";
2
- var FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
3
- var ENTRY_POINT_FILE_NAME = "index.jsx";
4
- var ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
2
+ var ENTRY_FILE_NAME = "entry";
5
3
  var HTML_PARTIALS_FOLDER = "html";
6
4
  var HTML_PARTIALS_EXTENSIONS = [
7
5
  ".htm",
8
6
  ".html",
9
7
  ".ejs"
10
8
  ];
11
- var APP_CONFIG_NAME = "config";
12
- var APP_INIT_EXPORTED = "init";
13
- var APP_INIT_IMPORTED = "appInit";
14
9
  export {
15
- APP_CONFIG_NAME,
16
- APP_INIT_EXPORTED,
17
- APP_INIT_IMPORTED,
18
- ENTRY_BOOTSTRAP_FILE_NAME,
19
- ENTRY_POINT_FILE_NAME,
20
- FILE_SYSTEM_ROUTES_FILE_NAME,
10
+ ENTRY_FILE_NAME,
21
11
  HTML_PARTIALS_EXTENSIONS,
22
12
  HTML_PARTIALS_FOLDER,
23
13
  INDEX_FILE_NAME
@@ -67,7 +67,8 @@ var getBundleEntry = function() {
67
67
  absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, entryName)) ? ensureAbsolutePath(appDirectory, entryName) : path.dirname(ensureAbsolutePath(appDirectory, entryName)),
68
68
  isAutoMount,
69
69
  customBootstrap: typeof value === "string" ? false : value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
70
- fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, entryName)).isDirectory() ? {} : void 0
70
+ fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, entryName)).isDirectory() ? {} : void 0,
71
+ isCustomSourceEntry: true
71
72
  };
72
73
  if (!ifAlreadyExists(defaults, entrypoint)) {
73
74
  defaults.push(entrypoint);