@modern-js/app-tools 2.19.1 → 2.21.0

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 (116) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/bin/modern.js +0 -1
  3. package/dist/cjs/analyze/generateCode.js +22 -48
  4. package/dist/cjs/analyze/getBundleEntry.js +3 -7
  5. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +2 -6
  6. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +2 -6
  7. package/dist/cjs/analyze/getClientRoutes/utils.js +2 -6
  8. package/dist/cjs/analyze/getFileSystemEntry.js +3 -7
  9. package/dist/cjs/analyze/getHtmlTemplate.js +4 -47
  10. package/dist/cjs/analyze/getServerRoutes.js +5 -7
  11. package/dist/cjs/analyze/index.js +11 -48
  12. package/dist/cjs/analyze/isDefaultExportFunction.js +5 -48
  13. package/dist/cjs/analyze/nestedRoutes.js +2 -41
  14. package/dist/cjs/analyze/templates.js +2 -6
  15. package/dist/cjs/analyze/utils.js +3 -7
  16. package/dist/cjs/builder/builder-rspack/adapterCopy.js +4 -21
  17. package/dist/cjs/builder/builder-webpack/index.js +2 -41
  18. package/dist/cjs/builder/generator/index.js +3 -42
  19. package/dist/cjs/builder/index.js +4 -43
  20. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +6 -56
  21. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +6 -45
  22. package/dist/cjs/builder/shared/builderPlugins/index.js +4 -16
  23. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +3 -15
  24. package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +5 -17
  25. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +2 -6
  26. package/dist/cjs/builder/shared/bundlerPlugins/index.js +4 -16
  27. package/dist/cjs/builder/shared/createCopyInfo.js +2 -6
  28. package/dist/cjs/builder/shared/index.js +4 -16
  29. package/dist/cjs/commands/index.js +4 -16
  30. package/dist/cjs/commands/serve.js +2 -6
  31. package/dist/cjs/config/index.js +4 -16
  32. package/dist/cjs/config/initialize/inits.js +2 -41
  33. package/dist/cjs/index.js +41 -80
  34. package/dist/cjs/schema/Schema.js +2 -14
  35. package/dist/cjs/schema/index.js +2 -6
  36. package/dist/cjs/types/config/index.js +2 -14
  37. package/dist/cjs/types/index.js +4 -16
  38. package/dist/cjs/utils/config.js +2 -41
  39. package/dist/cjs/utils/generateWatchFiles.js +2 -6
  40. package/dist/cjs/utils/routes.js +2 -6
  41. package/dist/esm/analyze/generateCode.js +13 -170
  42. package/dist/esm/analyze/getBundleEntry.js +1 -1
  43. package/dist/esm/analyze/getClientRoutes/getRoutes.js +2 -52
  44. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +2 -52
  45. package/dist/esm/analyze/getHtmlTemplate.js +6 -151
  46. package/dist/esm/analyze/getServerRoutes.js +6 -118
  47. package/dist/esm/analyze/index.js +19 -251
  48. package/dist/esm/analyze/nestedRoutes.js +5 -184
  49. package/dist/esm/analyze/templates.js +6 -242
  50. package/dist/esm/analyze/utils.js +6 -205
  51. package/dist/esm/builder/builder-rspack/adapterCopy.js +10 -235
  52. package/dist/esm/builder/builder-webpack/adapterModern.js +1 -34
  53. package/dist/esm/builder/builder-webpack/index.js +7 -219
  54. package/dist/esm/builder/generator/createBuilderProviderConfig.js +2 -52
  55. package/dist/esm/builder/generator/index.js +4 -133
  56. package/dist/esm/builder/index.js +3 -132
  57. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +9 -191
  58. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +10 -139
  59. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +4 -69
  60. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +3 -35
  61. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +7 -226
  62. package/dist/esm/commands/build.js +5 -184
  63. package/dist/esm/commands/deploy.js +3 -132
  64. package/dist/esm/commands/dev.js +6 -185
  65. package/dist/esm/commands/inspect.js +3 -132
  66. package/dist/esm/commands/serve.js +6 -185
  67. package/dist/esm/config/default.js +3 -52
  68. package/dist/esm/config/initialize/inits.js +3 -86
  69. package/dist/esm/defineConfig.js +2 -52
  70. package/dist/esm/index.js +49 -207
  71. package/dist/esm/initialize/index.js +6 -185
  72. package/dist/esm/schema/Schema.js +8 -213
  73. package/dist/esm/schema/index.js +1 -13
  74. package/dist/esm/schema/legacy.js +1 -13
  75. package/dist/esm/utils/config.js +7 -186
  76. package/dist/esm/utils/createServer.js +6 -185
  77. package/dist/esm/utils/generateWatchFiles.js +5 -167
  78. package/dist/esm/utils/getSelectedEntries.js +3 -132
  79. package/dist/esm/utils/getServerInternalPlugins.js +5 -184
  80. package/dist/esm/utils/printInstructions.js +3 -132
  81. package/dist/esm/utils/restart.js +3 -132
  82. package/dist/esm/utils/routes.js +3 -132
  83. package/dist/esm-node/analyze/generateCode.js +19 -2
  84. package/dist/esm-node/analyze/getBundleEntry.js +1 -1
  85. package/dist/esm-node/analyze/getServerRoutes.js +2 -0
  86. package/dist/esm-node/analyze/index.js +4 -2
  87. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +1 -14
  88. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -6
  89. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +5 -5
  90. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +1 -13
  91. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +1 -13
  92. package/dist/esm-node/index.js +22 -6
  93. package/dist/esm-node/schema/Schema.js +1 -13
  94. package/dist/types/analyze/index.d.ts +0 -2
  95. package/dist/types/builder/builder-rspack/index.d.ts +1 -1
  96. package/dist/types/builder/builder-webpack/adapterModern.d.ts +0 -1
  97. package/dist/types/builder/generator/index.d.ts +1 -2
  98. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +0 -1
  99. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +2 -3
  100. package/dist/types/defineConfig.d.ts +0 -1
  101. package/dist/types/index.d.ts +0 -2
  102. package/dist/types/initialize/index.d.ts +0 -2
  103. package/dist/types/types/config/index.d.ts +2 -2
  104. package/dist/types/types/config/output.d.ts +1 -0
  105. package/dist/types/types/config/security.d.ts +2 -0
  106. package/dist/types/types/config/source.d.ts +0 -1
  107. package/dist/types/types/config/tools.d.ts +0 -2
  108. package/dist/types/types/hooks.d.ts +3 -1
  109. package/dist/types/types/legacyConfig/dev.d.ts +0 -1
  110. package/dist/types/types/legacyConfig/output.d.ts +2 -3
  111. package/dist/types/types/legacyConfig/source.d.ts +0 -1
  112. package/dist/types/types/legacyConfig/tools.d.ts +0 -1
  113. package/dist/types/utils/config.d.ts +0 -1
  114. package/dist/types/utils/getSelectedEntries.d.ts +0 -1
  115. package/lib/types.d.ts +8 -8
  116. package/package.json +29 -29
@@ -1,134 +1,5 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(void 0);
27
- });
28
- };
29
- }
30
- var __generator = function(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1)
35
- throw t[1];
36
- return t[1];
37
- },
38
- trys: [],
39
- ops: []
40
- };
41
- return g = {
42
- next: verb(0),
43
- "throw": verb(1),
44
- "return": verb(2)
45
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
46
- return this;
47
- }), g;
48
- function verb(n) {
49
- return function(v) {
50
- return step([
51
- n,
52
- v
53
- ]);
54
- };
55
- }
56
- function step(op) {
57
- if (f)
58
- throw new TypeError("Generator is already executing.");
59
- while (_)
60
- try {
61
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
62
- return t;
63
- if (y = 0, t)
64
- op = [
65
- op[0] & 2,
66
- t.value
67
- ];
68
- switch (op[0]) {
69
- case 0:
70
- case 1:
71
- t = op;
72
- break;
73
- case 4:
74
- _.label++;
75
- return {
76
- value: op[1],
77
- done: false
78
- };
79
- case 5:
80
- _.label++;
81
- y = op[1];
82
- op = [
83
- 0
84
- ];
85
- continue;
86
- case 7:
87
- op = _.ops.pop();
88
- _.trys.pop();
89
- continue;
90
- default:
91
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
92
- _ = 0;
93
- continue;
94
- }
95
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
96
- _.label = op[1];
97
- break;
98
- }
99
- if (op[0] === 6 && _.label < t[1]) {
100
- _.label = t[1];
101
- t = op;
102
- break;
103
- }
104
- if (t && _.label < t[2]) {
105
- _.label = t[2];
106
- _.ops.push(op);
107
- break;
108
- }
109
- if (t[2])
110
- _.ops.pop();
111
- _.trys.pop();
112
- continue;
113
- }
114
- op = body.call(thisArg, _);
115
- } catch (e) {
116
- op = [
117
- 6,
118
- e
119
- ];
120
- y = 0;
121
- } finally {
122
- f = t = 0;
123
- }
124
- if (op[0] & 5)
125
- throw op[1];
126
- return {
127
- value: op[0] ? op[1] : void 0,
128
- done: true
129
- };
130
- }
131
- };
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
132
3
  import { cli } from "@modern-js/core";
133
4
  import { chalk, clearConsole, getFullArgv, logger, program } from "@modern-js/utils";
134
5
  export function restart(hooksRunner, filename) {
@@ -137,7 +8,7 @@ export function restart(hooksRunner, filename) {
137
8
  function _restart() {
138
9
  _restart = _async_to_generator(function(hooksRunner, filename) {
139
10
  var hasGetError, err;
140
- return __generator(this, function(_state) {
11
+ return _ts_generator(this, function(_state) {
141
12
  switch (_state.label) {
142
13
  case 0:
143
14
  clearConsole();
@@ -1,140 +1,11 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(void 0);
27
- });
28
- };
29
- }
30
- var __generator = function(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1)
35
- throw t[1];
36
- return t[1];
37
- },
38
- trys: [],
39
- ops: []
40
- };
41
- return g = {
42
- next: verb(0),
43
- "throw": verb(1),
44
- "return": verb(2)
45
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
46
- return this;
47
- }), g;
48
- function verb(n) {
49
- return function(v) {
50
- return step([
51
- n,
52
- v
53
- ]);
54
- };
55
- }
56
- function step(op) {
57
- if (f)
58
- throw new TypeError("Generator is already executing.");
59
- while (_)
60
- try {
61
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
62
- return t;
63
- if (y = 0, t)
64
- op = [
65
- op[0] & 2,
66
- t.value
67
- ];
68
- switch (op[0]) {
69
- case 0:
70
- case 1:
71
- t = op;
72
- break;
73
- case 4:
74
- _.label++;
75
- return {
76
- value: op[1],
77
- done: false
78
- };
79
- case 5:
80
- _.label++;
81
- y = op[1];
82
- op = [
83
- 0
84
- ];
85
- continue;
86
- case 7:
87
- op = _.ops.pop();
88
- _.trys.pop();
89
- continue;
90
- default:
91
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
92
- _ = 0;
93
- continue;
94
- }
95
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
96
- _.label = op[1];
97
- break;
98
- }
99
- if (op[0] === 6 && _.label < t[1]) {
100
- _.label = t[1];
101
- t = op;
102
- break;
103
- }
104
- if (t && _.label < t[2]) {
105
- _.label = t[2];
106
- _.ops.push(op);
107
- break;
108
- }
109
- if (t[2])
110
- _.ops.pop();
111
- _.trys.pop();
112
- continue;
113
- }
114
- op = body.call(thisArg, _);
115
- } catch (e) {
116
- op = [
117
- 6,
118
- e
119
- ];
120
- y = 0;
121
- } finally {
122
- f = t = 0;
123
- }
124
- if (op[0] & 5)
125
- throw op[1];
126
- return {
127
- value: op[0] ? op[1] : void 0,
128
- done: true
129
- };
130
- }
131
- };
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
132
3
  import path from "path";
133
4
  import { fs, ROUTE_SPEC_FILE } from "@modern-js/utils";
134
5
  var generateRoutes = function() {
135
6
  var _ref = _async_to_generator(function(appContext) {
136
7
  var serverRoutes, distDirectory, output;
137
- return __generator(this, function(_state) {
8
+ return _ts_generator(this, function(_state) {
138
9
  switch (_state.label) {
139
10
  case 0:
140
11
  serverRoutes = appContext.serverRoutes, distDirectory = appContext.distDirectory;
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
2
+ import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
3
3
  import * as templates from "./templates";
4
4
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
5
5
  import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
@@ -160,9 +160,26 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
160
160
  const entryFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
161
161
  entrypoint.entry = entryFile;
162
162
  if (config.source.enableAsyncEntry) {
163
+ let rawAsyncEntryCode = `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`;
164
+ const ssr = getEntryOptions(entryName, config.server.ssr, config.server.ssrByEntries, packageName);
165
+ if (ssr) {
166
+ rawAsyncEntryCode = `
167
+ export const ${SERVER_RENDER_FUNCTION_NAME} = async (...args) => {
168
+ let entry = await ${rawAsyncEntryCode};
169
+ if (entry.default instanceof Promise){
170
+ entry = await entry.default;
171
+ return entry.default.${SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
172
+ }
173
+ return entry.${SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
174
+ };
175
+ if(typeof window!=='undefined'){
176
+ ${rawAsyncEntryCode}
177
+ }
178
+ `;
179
+ }
163
180
  const { code: asyncEntryCode } = await hookRunners.modifyAsyncEntry({
164
181
  entrypoint,
165
- code: `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`
182
+ code: rawAsyncEntryCode
166
183
  });
167
184
  fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
168
185
  const bootstrapFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
@@ -42,7 +42,7 @@ export const getBundleEntry = (appContext, config) => {
42
42
  customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
43
43
  fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
44
44
  };
45
- if (entrypoint.fileSystemRoutes && isRouterV5(config)) {
45
+ if (entrypoint.fileSystemRoutes && !isRouterV5(config)) {
46
46
  entrypoint.nestedRoutesEntry = entrypoint.entry;
47
47
  }
48
48
  if (!ifAlreadyExists(defaults, entrypoint)) {
@@ -76,12 +76,14 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
76
76
  const entryOptions = getEntryOptions(entryName, ssr, ssrByEntries, packageName);
77
77
  const isSSR = Boolean(entryOptions);
78
78
  const isWorker = Boolean(workerSSR);
79
+ const isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
79
80
  const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
80
81
  let route = {
81
82
  urlPath: `/${entryName === MAIN_ENTRY_NAME ? "" : entryName}`,
82
83
  entryName,
83
84
  entryPath: removeLeadingSlash(path.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
84
85
  isSPA: true,
86
+ isStream,
85
87
  isSSR,
86
88
  responseHeaders: resHeaders,
87
89
  worker: isWorker ? `${SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
@@ -65,7 +65,7 @@ export default ({ bundler }) => {
65
65
  };
66
66
  api.setAppContext(appContext);
67
67
  nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
68
- pagesDir = entrypoints.map((point) => point.entry).filter(Boolean).concat(nestedRouteEntries);
68
+ pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
69
69
  originEntrypoints = cloneDeep(entrypoints);
70
70
  await generateCode(appContext, resolvedConfig, entrypoints, api);
71
71
  const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
@@ -120,7 +120,9 @@ export default ({ bundler }) => {
120
120
  async onDevCompileDone({ isFirstCompile }) {
121
121
  const hookRunners2 = api.useHookRunners();
122
122
  if (process.stdout.isTTY || isFirstCompile) {
123
- hookRunners2.afterDev();
123
+ hookRunners2.afterDev({
124
+ isFirstCompile
125
+ });
124
126
  if (isFirstCompile) {
125
127
  printInstructions(hookRunners2, appContext, normalizedConfig);
126
128
  }
@@ -13,7 +13,7 @@ export const builderPluginAdpaterCopy = (options) => {
13
13
  ...config.builtins || {},
14
14
  copy: {
15
15
  patterns: [
16
- ...transformCopy((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns),
16
+ ...((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns) || [],
17
17
  ...createConfigBuiltinCopy(options)
18
18
  ]
19
19
  }
@@ -48,19 +48,6 @@ export const builderPluginAdpaterCopy = (options) => {
48
48
  }
49
49
  };
50
50
  };
51
- function transformCopy(patterns) {
52
- if (patterns) {
53
- patterns.map((value) => {
54
- if (typeof value === "string") {
55
- return {
56
- from: value
57
- };
58
- }
59
- return value;
60
- });
61
- }
62
- return [];
63
- }
64
51
  function createConfigBuiltinCopy(options) {
65
52
  const { normalizedConfig, appContext } = options;
66
53
  const { uploadDir, publicDir } = createCopyInfo(appContext, normalizedConfig);
@@ -1,17 +1,13 @@
1
- import { createVirtualModule } from "@modern-js/builder-shared";
1
+ import { isHtmlDisabled, createVirtualModule } from "@modern-js/builder-shared";
2
2
  import { getEntryOptions, removeTailSlash } from "@modern-js/utils";
3
3
  import { template as lodashTemplate } from "@modern-js/utils/lodash";
4
4
  import { BottomTemplatePlugin } from "../bundlerPlugins";
5
- export function isHtmlEnabled(config, target) {
6
- var _config_tools;
7
- return ((_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
8
- }
9
5
  export const builderPluginAdapterHtml = (options) => ({
10
6
  name: "builder-plugin-adapter-modern-html",
11
7
  setup(api) {
12
8
  api.modifyBundlerChain(async (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin }) => {
13
9
  const builderConfig = api.getNormalizedConfig();
14
- if (isHtmlEnabled(builderConfig, target)) {
10
+ if (!isHtmlDisabled(builderConfig, target)) {
15
11
  applyBottomHtmlPlugin({
16
12
  api,
17
13
  options,
@@ -1,9 +1,8 @@
1
1
  import * as path from "path";
2
- import { mergeBuilderConfig } from "@modern-js/builder-shared";
2
+ import { isHtmlDisabled, mergeBuilderConfig } from "@modern-js/builder-shared";
3
3
  import { isSSR, fs } from "@modern-js/utils";
4
4
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
5
5
  import { getServerCombinedModueFile } from "../../../analyze/utils";
6
- import { isHtmlEnabled } from "./adapterHtml";
7
6
  export const builderPluginAdapterSSR = (options) => ({
8
7
  name: "builder-plugin-adapter-modern-ssr",
9
8
  setup(api) {
@@ -36,7 +35,7 @@ export const builderPluginAdapterSSR = (options) => ({
36
35
  appNormalizedConfig: normalizedConfig2
37
36
  });
38
37
  }
39
- if (isHtmlEnabled(builderConfig, target)) {
38
+ if (!isHtmlDisabled(builderConfig, target)) {
40
39
  applyAsyncChunkHtmlPlugin({
41
40
  chain,
42
41
  modernConfig: options.normalizedConfig,
@@ -70,13 +69,14 @@ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerP
70
69
  }
71
70
  }
72
71
  function applyRouterPlugin(chain, options) {
73
- var _normalizedConfig_runtime;
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
76
  const routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
78
77
  const routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
79
- if (existNestedRoutes || routerManifest) {
78
+ const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
79
+ if (existNestedRoutes || routerManifest || workerSSR) {
80
80
  chain.plugin("route-plugin").use(RouterPlugin);
81
81
  }
82
82
  }
@@ -1,16 +1,4 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
1
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
14
2
  export class HtmlAsyncChunkPlugin {
15
3
  apply(compiler) {
16
4
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -1,16 +1,4 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
1
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
14
2
  export class BottomTemplatePlugin {
15
3
  apply(compiler) {
16
4
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -83,11 +83,27 @@ export default (options = {
83
83
  lintPlugin()
84
84
  ],
85
85
  setup: (api) => {
86
+ const appContext = api.useAppContext();
87
+ api.setAppContext({
88
+ ...appContext,
89
+ toolsType: "app-tools"
90
+ });
86
91
  const locale = getLocaleLanguage();
87
92
  i18n.changeLanguage({
88
93
  locale
89
94
  });
90
95
  return {
96
+ async beforeConfig() {
97
+ var _userConfig_output;
98
+ const userConfig = api.useConfigContext();
99
+ const appContext2 = api.useAppContext();
100
+ if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
101
+ api.setAppContext({
102
+ ...appContext2,
103
+ internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
104
+ });
105
+ }
106
+ },
91
107
  async commands({ program }) {
92
108
  await devCommand(program, api);
93
109
  await buildCommand(program, api);
@@ -120,21 +136,21 @@ export default (options = {
120
136
  if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
121
137
  const resolvedConfig = api.useResolvedConfigContext();
122
138
  if (resolvedConfig.output.cleanDistPath) {
123
- const appContext = api.useAppContext();
124
- await emptyDir(appContext.distDirectory);
139
+ const appContext2 = api.useAppContext();
140
+ await emptyDir(appContext2.distDirectory);
125
141
  }
126
142
  }
127
143
  },
128
144
  async watchFiles() {
129
- const appContext = api.useAppContext();
145
+ const appContext2 = api.useAppContext();
130
146
  const config = api.useResolvedConfigContext();
131
- return generateWatchFiles(appContext, config.source.configDir);
147
+ return generateWatchFiles(appContext2, config.source.configDir);
132
148
  },
133
149
  // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
134
150
  async fileChange(e) {
135
151
  const { filename, eventType } = e;
136
- const appContext = api.useAppContext();
137
- const { appDirectory, srcDirectory } = appContext;
152
+ const appContext2 = api.useAppContext();
153
+ const { appDirectory, srcDirectory } = appContext2;
138
154
  const absolutePath = path.resolve(appDirectory, filename);
139
155
  if (!absolutePath.includes(srcDirectory) && (eventType === "change" || eventType === "unlink")) {
140
156
  const { closeServer } = await import("./utils/createServer");
@@ -1,16 +1,4 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
1
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
14
2
  import { merge } from "@modern-js/utils/lodash";
15
3
  export class Schema extends Map {
16
4
  setSchema(key, object) {
@@ -1,10 +1,8 @@
1
1
  import type { CliPlugin } from '@modern-js/core';
2
2
  import { AppTools } from '../types';
3
-
4
3
  declare const _default: ({
5
4
  bundler
6
5
  }: {
7
6
  bundler: 'webpack' | 'rspack';
8
7
  }) => CliPlugin<AppTools<'shared'>>;
9
-
10
8
  export default _default;
@@ -1,2 +1,2 @@
1
1
  import { BuilderOptions } from '../shared';
2
- export declare function createRspackBuilderForModern(options: BuilderOptions<'rspack'>): Promise<import("@modern-js/builder-shared").BuilderInstance<import("@modern-js/builder-shared").BuilderProvider<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>>;
2
+ export declare function createRspackBuilderForModern(options: BuilderOptions<'rspack'>): Promise<import("@modern-js/builder-shared").BuilderInstance<import("@modern-js/builder-shared").BuilderProvider>>;
@@ -4,5 +4,4 @@ import { BuilderOptions } from '../shared';
4
4
  /**
5
5
  * Provides default configuration consistent with modern.js v1
6
6
  */
7
-
8
7
  export declare const builderPluginAdapterModern: (options: BuilderOptions<'webpack'>) => BuilderPlugin<BuilderPluginAPI>;
@@ -10,8 +10,7 @@ export type GenerateProvider = (c: {
10
10
  * @param utils - ModifyBuilderConfig, ModifyBuilderInstance
11
11
  * @returns BuilderInstance
12
12
  */
13
-
14
13
  export declare function generateBuilder<B extends Bundler>(options: BuilderOptions<B>, generateProvider: GenerateProvider, utils?: {
15
14
  modifyBuilderConfig?: ModifyBuilderConfig<B>;
16
15
  modifyBuilderInstance?: ModifyBuilderInstance;
17
- }): Promise<BuilderInstance<BuilderProvider<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>>;
16
+ }): Promise<BuilderInstance<BuilderProvider>>;
@@ -3,5 +3,4 @@ import type { BuilderOptions, BuilderPluginAPI } from '../types';
3
3
  import type { Bundler } from '../../../types';
4
4
  export declare const builderPluginAdapterBasic: <B extends Bundler>(options: BuilderOptions<B>) => BuilderPlugin<BuilderPluginAPI>;
5
5
  /** register builder hooks callback */
6
-
7
6
  export declare function applyCallbacks<B extends Bundler>(api: BuilderPluginAPI, options: BuilderOptions<B>): void;
@@ -1,5 +1,4 @@
1
- import { BuilderPlugin, BuilderTarget } from '@modern-js/builder-shared';
1
+ import { BuilderPlugin } from '@modern-js/builder-shared';
2
2
  import { Bundler } from '../../../types';
3
- import type { BuilderNormalizedConfig, BuilderOptions, BuilderPluginAPI } from '../types';
4
- export declare function isHtmlEnabled(config: BuilderNormalizedConfig, target: BuilderTarget): boolean;
3
+ import type { BuilderOptions, BuilderPluginAPI } from '../types';
5
4
  export declare const builderPluginAdapterHtml: <B extends Bundler>(options: BuilderOptions<B>) => BuilderPlugin<BuilderPluginAPI>;
@@ -6,5 +6,4 @@ export declare const defineConfig: <B extends "webpack" | "rspack" = "webpack">(
6
6
  *
7
7
  * `defineLegacyConfig` will be deprecated in the future.
8
8
  */
9
-
10
9
  export declare const defineLegacyConfig: (config: AppLegacyUserConfig) => AppLegacyUserConfig;
@@ -11,7 +11,5 @@ export type AppToolsOptions = {
11
11
  /** Specify the use what kind of bundler to compiler, default: `webpack` */
12
12
  bundler?: 'experimental-rspack' | 'webpack';
13
13
  };
14
-
15
14
  declare const _default: (options?: AppToolsOptions) => CliPlugin<AppTools<'shared'>>;
16
-
17
15
  export default _default;
@@ -1,9 +1,7 @@
1
1
  import type { CliPlugin, AppTools } from '../types';
2
-
3
2
  declare const _default: ({
4
3
  bundler
5
4
  }: {
6
5
  bundler: 'rspack' | 'webpack';
7
6
  }) => CliPlugin<AppTools<'shared'>>;
8
-
9
7
  export default _default;