@unpackjs/core 1.7.5 → 1.7.6

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 (122) hide show
  1. package/compiled/css-loader/index.js +180 -178
  2. package/compiled/less-loader/index.js +11 -11
  3. package/compiled/line-diff/index.js +4 -4
  4. package/compiled/portfinder/index.js +37 -37
  5. package/compiled/postcss-loader/index.js +261 -256
  6. package/compiled/sass-loader/index.js +18 -18
  7. package/compiled/semver/index.js +188 -170
  8. package/compiled/semver/package.json +1 -1
  9. package/compiled/style-loader/index.js +13 -13
  10. package/compiled/webpack-bundle-analyzer/index.js +198 -198
  11. package/compiled/webpack-merge/index.js +29 -29
  12. package/dist/bundler-config/chunkSplit.cjs +169 -156
  13. package/dist/bundler-config/chunkSplit.d.ts +1 -1
  14. package/dist/bundler-config/chunkSplit.js +125 -134
  15. package/dist/bundler-config/css.cjs +181 -158
  16. package/dist/bundler-config/css.d.ts +1 -1
  17. package/dist/bundler-config/css.js +139 -151
  18. package/dist/bundler-config/experimentCss.cjs +203 -159
  19. package/dist/bundler-config/experimentCss.d.ts +1 -1
  20. package/dist/bundler-config/experimentCss.js +162 -152
  21. package/dist/bundler-config/helper.cjs +82 -78
  22. package/dist/bundler-config/helper.js +36 -55
  23. package/dist/bundler-config/index.cjs +260 -209
  24. package/dist/bundler-config/index.d.ts +1 -1
  25. package/dist/bundler-config/index.d.ts.map +1 -1
  26. package/dist/bundler-config/index.js +209 -182
  27. package/dist/bundler-config/jsMinify.cjs +114 -95
  28. package/dist/bundler-config/jsMinify.js +70 -73
  29. package/dist/colors.cjs +83 -56
  30. package/dist/colors.js +38 -37
  31. package/dist/config.cjs +107 -93
  32. package/dist/config.d.ts +1 -1
  33. package/dist/config.d.ts.map +1 -1
  34. package/dist/config.js +64 -70
  35. package/dist/constants.cjs +62 -62
  36. package/dist/constants.js +20 -38
  37. package/dist/createUnpack.cjs +111 -104
  38. package/dist/createUnpack.js +67 -82
  39. package/dist/global.cjs +36 -0
  40. package/dist/global.d.ts +2 -0
  41. package/dist/global.d.ts.map +1 -0
  42. package/dist/global.js +4 -0
  43. package/dist/index.cjs +174 -51
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +33 -15
  47. package/dist/lightningcss/cache.cjs +40 -32
  48. package/dist/lightningcss/cache.js +10 -20
  49. package/dist/lightningcss/loader.cjs +56 -53
  50. package/dist/lightningcss/loader.d.ts +1 -1
  51. package/dist/lightningcss/loader.js +25 -34
  52. package/dist/lightningcss/minimizer.cjs +90 -109
  53. package/dist/lightningcss/minimizer.d.ts +1 -1
  54. package/dist/lightningcss/minimizer.js +59 -87
  55. package/dist/logger.cjs +104 -98
  56. package/dist/logger.d.ts +1 -1
  57. package/dist/logger.js +59 -76
  58. package/dist/openBrowser.cjs +104 -81
  59. package/dist/openBrowser.js +56 -52
  60. package/dist/plugin-progress/rspack.cjs +104 -79
  61. package/dist/plugin-progress/rspack.d.ts +1 -1
  62. package/dist/plugin-progress/rspack.js +59 -57
  63. package/dist/plugin-progress/webpack.cjs +111 -89
  64. package/dist/plugin-progress/webpack.d.ts +1 -1
  65. package/dist/plugin-progress/webpack.js +65 -67
  66. package/dist/plugin.cjs +38 -29
  67. package/dist/plugin.js +8 -17
  68. package/dist/prebundleDeps.cjs +327 -337
  69. package/dist/prebundleDeps.d.ts.map +1 -1
  70. package/dist/prebundleDeps.js +278 -324
  71. package/dist/progressBar.cjs +82 -65
  72. package/dist/progressBar.js +38 -43
  73. package/dist/reporter.cjs +135 -120
  74. package/dist/reporter.js +88 -98
  75. package/dist/run/build.cjs +68 -67
  76. package/dist/run/build.d.ts +1 -1
  77. package/dist/run/build.js +24 -45
  78. package/dist/run/dev.cjs +96 -83
  79. package/dist/run/dev.d.ts +1 -1
  80. package/dist/run/dev.d.ts.map +1 -1
  81. package/dist/run/dev.js +50 -61
  82. package/dist/run/index.cjs +74 -21
  83. package/dist/run/index.js +2 -9
  84. package/dist/typed-css-modules/loader.cjs +179 -188
  85. package/dist/typed-css-modules/loader.d.ts +1 -1
  86. package/dist/typed-css-modules/loader.js +118 -151
  87. package/dist/typed-css-modules/plugin.cjs +113 -88
  88. package/dist/typed-css-modules/plugin.d.ts +1 -1
  89. package/dist/typed-css-modules/plugin.js +68 -66
  90. package/dist/typed-css-modules/utils.cjs +43 -42
  91. package/dist/typed-css-modules/utils.d.ts +1 -1
  92. package/dist/typed-css-modules/utils.js +13 -30
  93. package/dist/types/chunkSplit.cjs +19 -15
  94. package/dist/types/chunkSplit.d.ts +2 -10
  95. package/dist/types/chunkSplit.d.ts.map +1 -1
  96. package/dist/types/chunkSplit.js +2 -9
  97. package/dist/types/config.cjs +19 -15
  98. package/dist/types/config.d.ts +1 -1
  99. package/dist/types/config.js +2 -9
  100. package/dist/types/index.cjs +101 -27
  101. package/dist/types/index.js +2 -9
  102. package/dist/types/lightningcss.cjs +19 -15
  103. package/dist/types/lightningcss.js +2 -9
  104. package/dist/types/logger.cjs +43 -34
  105. package/dist/types/logger.js +13 -22
  106. package/dist/types/plugin.cjs +19 -15
  107. package/dist/types/plugin.js +2 -9
  108. package/dist/utils.cjs +280 -304
  109. package/dist/utils.js +195 -241
  110. package/dist/watchFiles.cjs +73 -0
  111. package/dist/watchFiles.d.ts +3 -0
  112. package/dist/watchFiles.d.ts.map +1 -0
  113. package/dist/watchFiles.js +27 -0
  114. package/package.json +14 -17
  115. package/compiled/commander/index.d.ts +0 -1047
  116. package/compiled/commander/index.js +0 -2428
  117. package/compiled/commander/license +0 -22
  118. package/compiled/commander/package.json +0 -1
  119. package/dist/bundleRequire.cjs +0 -200
  120. package/dist/bundleRequire.d.ts +0 -5
  121. package/dist/bundleRequire.d.ts.map +0 -1
  122. package/dist/bundleRequire.js +0 -173
@@ -1,350 +1,340 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var prebundleDeps_exports = {};
29
- __export(prebundleDeps_exports, {
30
- prebundleDeps: () => prebundleDeps
31
- });
32
- module.exports = __toCommonJS(prebundleDeps_exports);
33
- var import_node_fs = __toESM(require("node:fs"));
34
- var import_node_path = __toESM(require("node:path"));
35
- var import_core = require("@rspack/core");
36
- var import_cors = __toESM(require("cors"));
37
- var import_express = __toESM(require("express"));
38
- var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
39
- var import_tinyglobby = require("tinyglobby");
40
- var import_colors = __toESM(require("./colors.cjs"));
41
- var import_constants = require("./constants.cjs");
42
- var import_logger = require("./logger.cjs");
43
- var import_utils = require("./utils.cjs");
44
- const app = (0, import_express.default)();
45
- app.use((0, import_cors.default)());
46
- const CACHE_DIR = "umd";
47
- const externalAlias = {
48
- react: "React",
49
- "react-dom": "ReactDOM",
50
- "react-router": "ReactRouter",
51
- "react-router-dom": "ReactRouterDOM"
52
- };
53
- const count = {
54
- total: 0,
55
- bundled: 0
56
- };
57
- const failedDeps = [];
58
- const noEntryDeps = [];
59
- const updateProgress = () => {
60
- (0, import_utils.logUpdate)(
61
- `${import_colors.default.magenta(import_colors.default.bold("»"))} Optimizing dependencies (${count.bundled}/${count.total})`
62
- );
63
- if (count.total === count.bundled + failedDeps.length) {
64
- console.log();
65
- }
66
- };
67
- const getExternalLibraryName = (pkgName) => {
68
- return externalAlias[pkgName] || pkgName;
69
- };
70
- const getExternalValue = (pkgName) => {
71
- return `window ${getExternalLibraryName(pkgName)}`;
72
- };
73
- const bundleDep = ({
74
- root,
75
- name,
76
- entry,
77
- version
78
- }) => {
79
- return new Promise((resolve) => {
80
- const pkgDir = import_node_path.default.resolve(root, import_constants.TEMP_DIR, CACHE_DIR, name);
81
- const outDir = import_node_path.default.resolve(pkgDir, version);
82
- const getResult = () => {
83
- const assets = (0, import_tinyglobby.globSync)("**/index.{js,css}", {
84
- cwd: outDir,
85
- absolute: true
86
- });
87
- return {
88
- name,
89
- assets
90
- };
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = function(module) {
5
+ var getter = module && module.__esModule ? function() {
6
+ return module['default'];
7
+ } : function() {
8
+ return module;
9
+ };
10
+ __webpack_require__.d(getter, {
11
+ a: getter
12
+ });
13
+ return getter;
91
14
  };
92
- if (import_node_fs.default.existsSync(outDir)) {
93
- resolve(getResult());
94
- return;
95
- }
96
- (0, import_utils.removeDir)(pkgDir);
97
- count.total++;
98
- updateProgress();
99
- const getSwcOptions = ({ tsx }) => {
100
- return {
101
- jsc: {
102
- parser: {
103
- tsx,
104
- syntax: "typescript",
105
- dynamicImport: true,
106
- decorators: true
107
- },
108
- transform: {
109
- react: {
110
- runtime: "automatic"
111
- }
112
- }
113
- }
114
- };
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.d = function(exports1, definition) {
18
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
19
+ enumerable: true,
20
+ get: definition[key]
21
+ });
115
22
  };
116
- const compiler = (0, import_core.rspack)({
117
- entry: {
118
- index: entry
119
- },
120
- context: root,
121
- mode: "development",
122
- output: {
123
- clean: true,
124
- path: outDir,
125
- pathinfo: false,
126
- library: {
127
- name: getExternalLibraryName(name),
128
- type: "umd",
129
- umdNamedDefine: true
130
- },
131
- globalObject: "this"
132
- },
133
- devtool: false,
134
- module: {
135
- rules: [
136
- {
137
- test: /\.(j|t)s$/,
138
- use: [
139
- {
140
- loader: "builtin:swc-loader",
141
- options: getSwcOptions({ tsx: false })
142
- }
143
- ]
144
- },
145
- {
146
- test: /\.(j|t)sx$/,
147
- use: [
148
- {
149
- loader: "builtin:swc-loader",
150
- options: getSwcOptions({ tsx: true })
151
- }
152
- ]
153
- },
154
- {
155
- test: /\.less$/,
156
- type: "css/auto",
157
- use: [
158
- {
159
- loader: (0, import_utils.getCompiledPkgPath)("less-loader"),
160
- options: {
161
- lessOptions: {
162
- javascriptEnabled: true
163
- },
164
- implementation: (0, import_utils.getUserDepPath)(root, "less")
165
- }
166
- }
167
- ]
168
- },
169
- {
170
- test: /\.s[ac]ss$/i,
171
- type: "css/auto",
172
- use: [
173
- {
174
- loader: (0, import_utils.getCompiledPkgPath)("sass-loader"),
175
- options: {
176
- api: "modern-compiler",
177
- implementation: (0, import_utils.getUserDepPath)(root, ["sass-embedded", "sass"])
178
- }
179
- }
180
- ]
181
- }
182
- ]
183
- },
184
- optimization: {
185
- splitChunks: false
186
- },
187
- experiments: {
188
- css: true
189
- },
190
- externals: {
191
- react: getExternalValue("react"),
192
- "react-dom": getExternalValue("react-dom")
193
- }
194
- });
195
- compiler.run((_, stats) => {
196
- let isFailed = false;
197
- if (stats?.hasErrors()) {
198
- isFailed = true;
199
- failedDeps.push(name);
200
- (0, import_utils.removeDir)(outDir);
201
- } else {
202
- count.bundled++;
203
- }
204
- updateProgress();
205
- compiler.close(() => {
206
- resolve(!isFailed ? getResult() : void 0);
207
- });
208
- });
209
- });
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = function(obj, prop) {
26
+ return Object.prototype.hasOwnProperty.call(obj, prop);
27
+ };
28
+ })();
29
+ (()=>{
30
+ __webpack_require__.r = function(exports1) {
31
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
32
+ value: 'Module'
33
+ });
34
+ Object.defineProperty(exports1, '__esModule', {
35
+ value: true
36
+ });
37
+ };
38
+ })();
39
+ var __webpack_exports__ = {};
40
+ __webpack_require__.r(__webpack_exports__);
41
+ __webpack_require__.d(__webpack_exports__, {
42
+ prebundleDeps: ()=>prebundleDeps
43
+ });
44
+ const external_node_fs_namespaceObject = require("node:fs");
45
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
46
+ const external_node_path_namespaceObject = require("node:path");
47
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
48
+ const core_namespaceObject = require("@rspack/core");
49
+ const external_cors_namespaceObject = require("cors");
50
+ var external_cors_default = /*#__PURE__*/ __webpack_require__.n(external_cors_namespaceObject);
51
+ const external_express_namespaceObject = require("express");
52
+ var external_express_default = /*#__PURE__*/ __webpack_require__.n(external_express_namespaceObject);
53
+ const external_html_webpack_plugin_namespaceObject = require("html-webpack-plugin");
54
+ var external_html_webpack_plugin_default = /*#__PURE__*/ __webpack_require__.n(external_html_webpack_plugin_namespaceObject);
55
+ const external_tinyglobby_namespaceObject = require("tinyglobby");
56
+ const external_colors_cjs_namespaceObject = require("./colors.cjs");
57
+ var external_colors_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_colors_cjs_namespaceObject);
58
+ const external_constants_cjs_namespaceObject = require("./constants.cjs");
59
+ const external_global_cjs_namespaceObject = require("./global.cjs");
60
+ const external_logger_cjs_namespaceObject = require("./logger.cjs");
61
+ const external_utils_cjs_namespaceObject = require("./utils.cjs");
62
+ const CACHE_DIR = 'umd';
63
+ const getExternalLibraryName = (pkgName)=>{
64
+ const externalAlias = {
65
+ react: 'React',
66
+ 'react-dom': 'ReactDOM',
67
+ 'react-router': 'ReactRouter',
68
+ 'react-router-dom': 'ReactRouterDOM'
69
+ };
70
+ return externalAlias[pkgName] || pkgName;
210
71
  };
211
- const getExistExternals = (externals) => {
212
- const existExternals = /* @__PURE__ */ new Set();
213
- if (Array.isArray(externals)) {
214
- externals.forEach((item) => {
215
- if ((0, import_utils.isPlainObject)(item)) {
216
- Object.keys(item).forEach((key) => existExternals.add(key));
217
- }
72
+ const getExternalValue = (pkgName)=>`window ${getExternalLibraryName(pkgName)}`;
73
+ const getExistExternals = (externals)=>{
74
+ const existExternals = new Set();
75
+ if (Array.isArray(externals)) externals.forEach((item)=>{
76
+ if ((0, external_utils_cjs_namespaceObject.isPlainObject)(item)) Object.keys(item).forEach((key)=>existExternals.add(key));
218
77
  });
219
- } else if ((0, import_utils.isPlainObject)(externals)) {
220
- Object.keys(externals).forEach((key) => existExternals.add(key));
221
- }
222
- return Array.from(existExternals);
78
+ else if ((0, external_utils_cjs_namespaceObject.isPlainObject)(externals)) Object.keys(externals).forEach((key)=>existExternals.add(key));
79
+ return Array.from(existExternals);
223
80
  };
224
- const getPkgEntry = (packageJson) => {
225
- if (packageJson.module)
226
- return packageJson.module;
227
- if (packageJson.exports) {
228
- if ((0, import_utils.isString)(packageJson.exports))
229
- return packageJson.exports;
230
- const defaultExport = packageJson.exports["."];
231
- if (defaultExport) {
232
- if ((0, import_utils.isString)(defaultExport))
233
- return defaultExport;
234
- if ((0, import_utils.isString)(defaultExport.import))
235
- return defaultExport.import;
236
- if ((0, import_utils.isString)(defaultExport.browser))
237
- return defaultExport.browser;
238
- if ((0, import_utils.isString)(defaultExport.default))
239
- return defaultExport.default;
81
+ const getPkgEntry = (packageJson)=>{
82
+ if (packageJson.module) return packageJson.module;
83
+ if (packageJson.exports) {
84
+ if ((0, external_utils_cjs_namespaceObject.isString)(packageJson.exports)) return packageJson.exports;
85
+ const defaultExport = packageJson.exports['.'];
86
+ if (defaultExport) {
87
+ if ((0, external_utils_cjs_namespaceObject.isString)(defaultExport)) return defaultExport;
88
+ if ((0, external_utils_cjs_namespaceObject.isString)(defaultExport.import)) return defaultExport.import;
89
+ if ((0, external_utils_cjs_namespaceObject.isString)(defaultExport.browser)) return defaultExport.browser;
90
+ if ((0, external_utils_cjs_namespaceObject.isString)(defaultExport.default)) return defaultExport.default;
91
+ }
92
+ if ((0, external_utils_cjs_namespaceObject.isString)(packageJson.exports.default)) return packageJson.exports.default;
240
93
  }
241
- if ((0, import_utils.isString)(packageJson.exports.default))
242
- return packageJson.exports.default;
243
- }
244
- if (packageJson.main)
245
- return packageJson.main;
94
+ if (packageJson.main) return packageJson.main;
246
95
  };
247
- const prebundleDeps = async ({
248
- unpackConfig
249
- }) => {
250
- const userOptions = (0, import_utils.isPlainObject)(unpackConfig.dev?.prebundle) ? unpackConfig.dev.prebundle : {};
251
- const { root } = unpackConfig;
252
- const packageJson = JSON.parse(import_node_fs.default.readFileSync(import_node_path.default.resolve(root, "package.json"), "utf-8"));
253
- const existExternals = getExistExternals(unpackConfig.externals);
254
- const excludeDeps = [...existExternals || [], ...userOptions.exclude || []];
255
- const shouldIncludeDeps = Object.keys(packageJson.dependencies).filter(
256
- (pkgName) => !excludeDeps.includes(pkgName)
257
- );
258
- const needBundleDeps = shouldIncludeDeps.map((pkgName) => {
259
- const packageJson2 = JSON.parse(
260
- import_node_fs.default.readFileSync(import_node_path.default.resolve(root, "node_modules", pkgName, "package.json"), "utf-8")
261
- );
262
- const entry = getPkgEntry(packageJson2);
263
- if (!entry) {
264
- noEntryDeps.push(pkgName);
265
- return;
266
- }
267
- return {
268
- name: pkgName,
269
- entry: import_node_path.default.resolve(root, "node_modules", pkgName, entry),
270
- version: packageJson2.version
96
+ const prebundleDeps = async ({ unpackConfig })=>{
97
+ var _unpackConfig_dev;
98
+ const count = {
99
+ total: 0,
100
+ bundled: 0
101
+ };
102
+ const failedDeps = [];
103
+ const updateProgress = ()=>{
104
+ (0, external_utils_cjs_namespaceObject.logUpdate)(`${external_colors_cjs_default().magenta(external_colors_cjs_default().bold('»'))} Optimizing dependencies (${count.bundled}/${count.total})`);
105
+ if (count.total === count.bundled + failedDeps.length) console.log();
271
106
  };
272
- }).filter(Boolean);
273
- if (noEntryDeps[0]) {
274
- import_logger.logger.warn(`Could not find entry for "${import_colors.default.bold(noEntryDeps.join(", "))}"`);
275
- }
276
- const bundledDeps = await Promise.all(
277
- needBundleDeps.map((depInfo) => bundleDep({ root, ...depInfo }))
278
- );
279
- if (failedDeps[0]) {
280
- import_logger.logger.warn(`Something went wrong while optimizing "${import_colors.default.bold(failedDeps.join(", "))}"`);
281
- }
282
- const cachePath = import_node_path.default.resolve(root, import_constants.TEMP_DIR, CACHE_DIR);
283
- app.use(`/${CACHE_DIR}`, import_express.default.static(cachePath));
284
- const port = await (0, import_utils.getPort)(3200);
285
- app.listen(port, () => {
286
- });
287
- const externals = {};
288
- const jsAssets = [];
289
- const cssAssets = [];
290
- const preJsAssets = [];
291
- const ipv4Interfaces = (0, import_utils.getIpv4Interfaces)();
292
- bundledDeps.filter(Boolean).forEach((dep) => {
293
- externals[dep.name] = getExternalValue(dep.name);
294
- dep.assets.forEach((absPath) => {
295
- const relativePath = import_node_path.default.relative(cachePath, absPath);
296
- const preDeps = ["react", "react-dom", "react-router", "react-router-dom"];
297
- const serverPath = `//${ipv4Interfaces[1].address}:${port}/${CACHE_DIR}/${relativePath}`;
298
- switch (import_node_path.default.extname(relativePath)) {
299
- case ".js":
300
- if (preDeps.includes(dep.name)) {
301
- preJsAssets.push({
302
- path: serverPath,
303
- order: preDeps.indexOf(dep.name)
107
+ const { root } = unpackConfig;
108
+ const bundleDep = ({ name, entry, version })=>new Promise((resolve)=>{
109
+ const pkgDir = external_node_path_default().resolve(root, external_constants_cjs_namespaceObject.TEMP_DIR, CACHE_DIR, name);
110
+ const outDir = external_node_path_default().resolve(pkgDir, version);
111
+ const getResult = ()=>{
112
+ const assets = (0, external_tinyglobby_namespaceObject.globSync)('**/index.{js,css}', {
113
+ cwd: outDir,
114
+ absolute: true
115
+ });
116
+ return {
117
+ name,
118
+ assets
119
+ };
120
+ };
121
+ if (external_node_fs_default().existsSync(outDir)) {
122
+ resolve(getResult());
123
+ return;
124
+ }
125
+ (0, external_utils_cjs_namespaceObject.removeDir)(pkgDir);
126
+ count.total++;
127
+ updateProgress();
128
+ const getSwcOptions = ({ tsx })=>({
129
+ jsc: {
130
+ parser: {
131
+ tsx,
132
+ syntax: "typescript",
133
+ dynamicImport: true,
134
+ decorators: true
135
+ },
136
+ transform: {
137
+ react: {
138
+ runtime: 'automatic'
139
+ }
140
+ }
141
+ }
142
+ });
143
+ const compiler = (0, core_namespaceObject.rspack)({
144
+ entry: {
145
+ index: entry
146
+ },
147
+ context: root,
148
+ mode: 'development',
149
+ output: {
150
+ clean: true,
151
+ path: outDir,
152
+ pathinfo: false,
153
+ library: {
154
+ name: getExternalLibraryName(name),
155
+ type: 'umd',
156
+ umdNamedDefine: true
157
+ },
158
+ globalObject: 'this'
159
+ },
160
+ devtool: false,
161
+ module: {
162
+ rules: [
163
+ {
164
+ test: /\.(j|t)s$/,
165
+ use: [
166
+ {
167
+ loader: 'builtin:swc-loader',
168
+ options: getSwcOptions({
169
+ tsx: false
170
+ })
171
+ }
172
+ ]
173
+ },
174
+ {
175
+ test: /\.(j|t)sx$/,
176
+ use: [
177
+ {
178
+ loader: 'builtin:swc-loader',
179
+ options: getSwcOptions({
180
+ tsx: true
181
+ })
182
+ }
183
+ ]
184
+ },
185
+ {
186
+ test: /\.less$/,
187
+ type: 'css/auto',
188
+ use: [
189
+ {
190
+ loader: (0, external_utils_cjs_namespaceObject.getCompiledPkgPath)('less-loader'),
191
+ options: {
192
+ lessOptions: {
193
+ javascriptEnabled: true
194
+ },
195
+ implementation: (0, external_utils_cjs_namespaceObject.getUserDepPath)(root, 'less')
196
+ }
197
+ }
198
+ ]
199
+ },
200
+ {
201
+ test: /\.s[ac]ss$/i,
202
+ type: 'css/auto',
203
+ use: [
204
+ {
205
+ loader: (0, external_utils_cjs_namespaceObject.getCompiledPkgPath)('sass-loader'),
206
+ options: {
207
+ api: 'modern-compiler',
208
+ implementation: (0, external_utils_cjs_namespaceObject.getUserDepPath)(root, [
209
+ 'sass-embedded',
210
+ 'sass'
211
+ ])
212
+ }
213
+ }
214
+ ]
215
+ }
216
+ ]
217
+ },
218
+ optimization: {
219
+ splitChunks: false
220
+ },
221
+ experiments: {
222
+ css: true
223
+ },
224
+ externals: {
225
+ react: getExternalValue('react'),
226
+ 'react-dom': getExternalValue('react-dom'),
227
+ 'react-router': getExternalValue('react-router'),
228
+ 'react-router-dom': getExternalValue('react-router-dom')
229
+ }
304
230
  });
305
- } else {
306
- jsAssets.push(serverPath);
307
- }
308
- break;
309
- case ".css":
310
- cssAssets.push(serverPath);
311
- break;
312
- default:
313
- break;
314
- }
231
+ compiler.run((_, stats)=>{
232
+ let isFailed = false;
233
+ if (null == stats ? void 0 : stats.hasErrors()) {
234
+ isFailed = true;
235
+ failedDeps.push(name);
236
+ (0, external_utils_cjs_namespaceObject.removeDir)(outDir);
237
+ } else count.bundled++;
238
+ updateProgress();
239
+ compiler.close(()=>{
240
+ resolve(isFailed ? void 0 : getResult());
241
+ });
242
+ });
243
+ });
244
+ const userOptions = (0, external_utils_cjs_namespaceObject.isPlainObject)(null === (_unpackConfig_dev = unpackConfig.dev) || void 0 === _unpackConfig_dev ? void 0 : _unpackConfig_dev.prebundle) ? unpackConfig.dev.prebundle : {};
245
+ const packageJson = JSON.parse(external_node_fs_default().readFileSync(external_node_path_default().resolve(root, 'package.json'), 'utf-8'));
246
+ const existExternals = getExistExternals(unpackConfig.externals);
247
+ const excludeDeps = [
248
+ ...existExternals || [],
249
+ ...userOptions.exclude || []
250
+ ];
251
+ const shouldIncludeDeps = Object.keys(packageJson.dependencies).filter((pkgName)=>!excludeDeps.includes(pkgName));
252
+ const noEntryDeps = [];
253
+ const needBundleDeps = shouldIncludeDeps.map((pkgName)=>{
254
+ const packageJson = JSON.parse(external_node_fs_default().readFileSync(external_node_path_default().resolve(root, 'node_modules', pkgName, 'package.json'), 'utf-8'));
255
+ const entry = getPkgEntry(packageJson);
256
+ if (!entry) {
257
+ noEntryDeps.push(pkgName);
258
+ return;
259
+ }
260
+ return {
261
+ name: pkgName,
262
+ entry: external_node_path_default().resolve(root, 'node_modules', pkgName, entry),
263
+ version: packageJson.version
264
+ };
265
+ }).filter(Boolean);
266
+ if (noEntryDeps[0]) external_logger_cjs_namespaceObject.logger.warn(`Could not find entry for "${external_colors_cjs_default().bold(noEntryDeps.join(', '))}"`);
267
+ const bundledDeps = await Promise.all(needBundleDeps.map((depInfo)=>bundleDep(depInfo)));
268
+ if (failedDeps[0]) external_logger_cjs_namespaceObject.logger.warn(`Something went wrong while optimizing "${external_colors_cjs_default().bold(failedDeps.join(', '))}"`);
269
+ const cachePath = external_node_path_default().resolve(root, external_constants_cjs_namespaceObject.TEMP_DIR, CACHE_DIR);
270
+ const app = external_express_default()();
271
+ app.use(external_cors_default()());
272
+ app.use(`/${CACHE_DIR}`, external_express_default().static(cachePath));
273
+ const port = await (0, external_utils_cjs_namespaceObject.getPort)(3200);
274
+ const staticServer = app.listen(port, ()=>{});
275
+ external_global_cjs_namespaceObject.restartCleaners.push(()=>new Promise((resolve)=>staticServer.close(()=>resolve())));
276
+ const externals = {};
277
+ const jsAssets = [];
278
+ const cssAssets = [];
279
+ const preJsAssets = [];
280
+ const ipv4Interfaces = (0, external_utils_cjs_namespaceObject.getIpv4Interfaces)();
281
+ bundledDeps.filter(Boolean).forEach((dep)=>{
282
+ externals[dep.name] = getExternalValue(dep.name);
283
+ dep.assets.forEach((absPath)=>{
284
+ const relativePath = external_node_path_default().relative(cachePath, absPath);
285
+ const preDeps = [
286
+ 'react',
287
+ 'react-dom',
288
+ 'react-router',
289
+ 'react-router-dom'
290
+ ];
291
+ const serverPath = `//${ipv4Interfaces[1].address}:${port}/${CACHE_DIR}/${relativePath}`;
292
+ switch(external_node_path_default().extname(relativePath)){
293
+ case '.js':
294
+ if (preDeps.includes(dep.name)) preJsAssets.push({
295
+ path: serverPath,
296
+ order: preDeps.indexOf(dep.name)
297
+ });
298
+ else jsAssets.push(serverPath);
299
+ break;
300
+ case '.css':
301
+ cssAssets.push(serverPath);
302
+ break;
303
+ default:
304
+ break;
305
+ }
306
+ });
315
307
  });
316
- });
317
- unpackConfig.externals = Array.isArray(unpackConfig.externals) ? [externals, ...unpackConfig.externals] : { ...externals, ...unpackConfig.externals };
318
- const HtmlPlugin = unpackConfig.bundler === "rspack" ? import_core.rspack.HtmlRspackPlugin : import_html_webpack_plugin.default;
319
- unpackConfig.plugins.push({
320
- name: "unpack:prebundle",
321
- bundlerConfig: (config) => {
322
- const PLUGIN_NAME = "PluginInjectAssets";
323
- config.plugins.push({
324
- apply: (compiler) => {
325
- compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
326
- HtmlPlugin.getCompilationHooks(compilation).beforeAssetTagGeneration.tapPromise(
327
- PLUGIN_NAME,
328
- async (args) => {
329
- args.assets.js.unshift(
330
- ...[
331
- ...preJsAssets.sort((a, b) => a.order - b.order).map((item) => item.path),
332
- ...jsAssets
333
- ]
334
- );
335
- args.assets.css.unshift(...cssAssets);
336
- return args;
337
- }
338
- );
339
- });
308
+ unpackConfig.externals = Array.isArray(unpackConfig.externals) ? [
309
+ externals,
310
+ ...unpackConfig.externals
311
+ ] : {
312
+ ...externals,
313
+ ...unpackConfig.externals
314
+ };
315
+ const HtmlPlugin = 'rspack' === unpackConfig.bundler ? core_namespaceObject.rspack.HtmlRspackPlugin : external_html_webpack_plugin_default();
316
+ unpackConfig.plugins.push({
317
+ name: 'unpack:prebundle',
318
+ bundlerConfig: (config)=>{
319
+ const PLUGIN_NAME = 'PluginInjectAssets';
320
+ config.plugins.push({
321
+ apply: (compiler)=>{
322
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation)=>{
323
+ HtmlPlugin.getCompilationHooks(compilation).beforeAssetTagGeneration.tapPromise(PLUGIN_NAME, async (args)=>{
324
+ args.assets.js.unshift(...preJsAssets.sort((a, b)=>a.order - b.order).map((item)=>item.path), ...jsAssets);
325
+ args.assets.css.unshift(...cssAssets);
326
+ return args;
327
+ });
328
+ });
329
+ }
330
+ });
331
+ return config;
340
332
  }
341
- });
342
- return config;
343
- }
344
- });
345
- return unpackConfig;
333
+ });
334
+ return unpackConfig;
346
335
  };
347
- // Annotate the CommonJS export names for ESM import in node:
348
- 0 && (module.exports = {
349
- prebundleDeps
336
+ var __webpack_export_target__ = exports;
337
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
338
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
339
+ value: true
350
340
  });