@unpackjs/core 2.1.0 → 2.2.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.
- package/compiled/css-loader/index.js +26 -26
- package/compiled/postcss-loader/index.js +11 -11
- package/dist/bundler-config/cache.cjs +105 -0
- package/dist/bundler-config/cache.d.ts +6 -0
- package/dist/bundler-config/cache.d.ts.map +1 -0
- package/dist/bundler-config/cache.js +63 -0
- package/dist/bundler-config/chunkSplit.js +7 -7
- package/dist/bundler-config/css.cjs +4 -3
- package/dist/bundler-config/css.d.ts.map +1 -1
- package/dist/bundler-config/css.js +33 -32
- package/dist/bundler-config/experimentCss.cjs +4 -3
- package/dist/bundler-config/experimentCss.d.ts.map +1 -1
- package/dist/bundler-config/experimentCss.js +29 -28
- package/dist/bundler-config/{helper.cjs → helpers.cjs} +2 -2
- package/dist/bundler-config/{helper.d.ts → helpers.d.ts} +1 -1
- package/dist/bundler-config/helpers.d.ts.map +1 -0
- package/dist/bundler-config/helpers.js +39 -0
- package/dist/bundler-config/index.cjs +28 -17
- package/dist/bundler-config/index.d.ts.map +1 -1
- package/dist/bundler-config/index.js +69 -58
- package/dist/bundler-config/jsMinify.cjs +3 -3
- package/dist/bundler-config/jsMinify.d.ts +1 -9
- package/dist/bundler-config/jsMinify.d.ts.map +1 -1
- package/dist/bundler-config/jsMinify.js +7 -7
- package/dist/bundler-config/oxlint/.oxlintrc.json +30 -0
- package/dist/bundler-config/oxlint/plugin.cjs +143 -0
- package/dist/bundler-config/oxlint/plugin.d.ts +10 -0
- package/dist/bundler-config/oxlint/plugin.d.ts.map +1 -0
- package/dist/bundler-config/oxlint/plugin.js +104 -0
- package/dist/{plugin-progress/helper.cjs → bundler-config/progress/helpers.cjs} +9 -10
- package/dist/{plugin-progress/helper.d.ts → bundler-config/progress/helpers.d.ts} +1 -1
- package/dist/bundler-config/progress/helpers.d.ts.map +1 -0
- package/dist/bundler-config/progress/helpers.js +67 -0
- package/dist/{plugin-progress → bundler-config/progress}/rspack.cjs +10 -10
- package/dist/{plugin-progress → bundler-config/progress}/rspack.d.ts +2 -2
- package/dist/bundler-config/progress/rspack.d.ts.map +1 -0
- package/dist/bundler-config/progress/rspack.js +37 -0
- package/dist/{plugin-progress → bundler-config/progress}/webpack.cjs +13 -11
- package/dist/bundler-config/progress/webpack.d.ts +9 -0
- package/dist/bundler-config/progress/webpack.d.ts.map +1 -0
- package/dist/bundler-config/progress/webpack.js +44 -0
- package/dist/colors.cjs +3 -4
- package/dist/colors.d.ts +1 -2
- package/dist/colors.d.ts.map +1 -1
- package/dist/colors.js +3 -4
- package/dist/config.cjs +5 -2
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +19 -19
- package/dist/constants.cjs +8 -8
- package/dist/constants.js +2 -2
- package/dist/createUnpack.cjs +2 -12
- package/dist/createUnpack.js +19 -19
- package/dist/fs.cjs +82 -0
- package/dist/fs.d.ts +11 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +28 -0
- package/dist/index.cjs +17 -18
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -42
- package/dist/lightningcss/loader.cjs +0 -2
- package/dist/lightningcss/loader.d.ts.map +1 -1
- package/dist/lightningcss/loader.js +4 -6
- package/dist/lightningcss/minimizer.cjs +7 -9
- package/dist/lightningcss/minimizer.d.ts.map +1 -1
- package/dist/lightningcss/minimizer.js +9 -11
- package/dist/logger.cjs +5 -6
- package/dist/logger.js +12 -12
- package/dist/openBrowser.js +7 -7
- package/dist/prebundleDeps.cjs +5 -5
- package/dist/prebundleDeps.d.ts.map +1 -1
- package/dist/prebundleDeps.js +49 -48
- package/dist/progressBar.cjs +1 -11
- package/dist/progressBar.js +3 -3
- package/dist/reporter.cjs +11 -9
- package/dist/reporter.d.ts.map +1 -1
- package/dist/reporter.js +25 -22
- package/dist/run/build.js +8 -8
- package/dist/run/dev.cjs +3 -4
- package/dist/run/dev.d.ts.map +1 -1
- package/dist/run/dev.js +23 -23
- package/dist/typed-css-modules/loader.js +12 -12
- package/dist/typed-css-modules/plugin.cjs +1 -1
- package/dist/typed-css-modules/plugin.js +13 -13
- package/dist/typed-css-modules/utils.js +6 -6
- package/dist/types/config.d.ts +2 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/oxc.cjs +18 -0
- package/dist/types/oxc.d.ts +10 -0
- package/dist/types/oxc.d.ts.map +1 -0
- package/dist/types/oxc.js +2 -0
- package/dist/utils.cjs +26 -27
- package/dist/utils.js +16 -16
- package/dist/watchFiles.js +4 -4
- package/package.json +4 -4
- package/dist/bundler-config/helper.d.ts.map +0 -1
- package/dist/bundler-config/helper.js +0 -39
- package/dist/plugin-progress/helper.d.ts.map +0 -1
- package/dist/plugin-progress/helper.js +0 -67
- package/dist/plugin-progress/rspack.d.ts.map +0 -1
- package/dist/plugin-progress/rspack.js +0 -37
- package/dist/plugin-progress/webpack.d.ts +0 -8
- package/dist/plugin-progress/webpack.d.ts.map +0 -1
- package/dist/plugin-progress/webpack.js +0 -42
package/dist/logger.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
3
|
+
import external_node_readline_default from "node:readline";
|
|
4
|
+
import { colors } from "./colors.js";
|
|
5
|
+
import { LogColor } from "./types/index.js";
|
|
6
|
+
import { isDebug } from "./utils.js";
|
|
7
7
|
const prefixes = {
|
|
8
8
|
wait: "\u25CB",
|
|
9
9
|
error: "\u2A2F",
|
|
@@ -15,7 +15,7 @@ const prefixes = {
|
|
|
15
15
|
};
|
|
16
16
|
const createLogger = ()=>{
|
|
17
17
|
const log = (type, message, ...args)=>{
|
|
18
|
-
const label =
|
|
18
|
+
const label = colors[LogColor[type]](prefixes[type]);
|
|
19
19
|
let text = '';
|
|
20
20
|
switch(type){
|
|
21
21
|
case 'error':
|
|
@@ -25,18 +25,18 @@ const createLogger = ()=>{
|
|
|
25
25
|
name = name.slice(7);
|
|
26
26
|
rest = rest.map((line)=>line.slice(2));
|
|
27
27
|
}
|
|
28
|
-
text = `${
|
|
29
|
-
} else text =
|
|
30
|
-
else text =
|
|
28
|
+
text = `${colors.red(name)}\n${colors.dim(rest.join('\n'))}`;
|
|
29
|
+
} else text = colors.red(message.message);
|
|
30
|
+
else text = colors.red(message);
|
|
31
31
|
break;
|
|
32
32
|
case 'warn':
|
|
33
|
-
text =
|
|
33
|
+
text = colors.yellow(message);
|
|
34
34
|
break;
|
|
35
35
|
default:
|
|
36
36
|
text = message;
|
|
37
37
|
break;
|
|
38
38
|
}
|
|
39
|
-
if ('debug' === type && !
|
|
39
|
+
if ('debug' === type && !isDebug()) return;
|
|
40
40
|
console.log(`${label} ${text}`, ...args);
|
|
41
41
|
};
|
|
42
42
|
const logger = {
|
|
@@ -44,8 +44,8 @@ const createLogger = ()=>{
|
|
|
44
44
|
const repeatCount = process.stdout.rows - 2;
|
|
45
45
|
const blank = repeatCount > 0 ? '\n'.repeat(repeatCount) : '';
|
|
46
46
|
console.log(blank);
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
external_node_readline_default.cursorTo(process.stdout, 0, 0);
|
|
48
|
+
external_node_readline_default.clearScreenDown(process.stdout);
|
|
49
49
|
},
|
|
50
50
|
greet: (msg)=>{
|
|
51
51
|
const { npm_execpath, npm_lifecycle_event } = process.env;
|
package/dist/openBrowser.js
CHANGED
|
@@ -3,9 +3,9 @@ import __rslib_shim_module__ from 'module';
|
|
|
3
3
|
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
4
4
|
import { dirname as __webpack_dirname__ } from "node:path";
|
|
5
5
|
import * as __WEBPACK_EXTERNAL_MODULE_open__ from "open";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
6
|
+
import { exec } from "node:child_process";
|
|
7
|
+
import external_node_path_default from "node:path";
|
|
8
|
+
import { logger } from "./logger.js";
|
|
9
9
|
var __webpack_modules__ = {
|
|
10
10
|
open: function(module) {
|
|
11
11
|
module.exports = __WEBPACK_EXTERNAL_MODULE_open__;
|
|
@@ -39,24 +39,24 @@ async function openBrowser(url) {
|
|
|
39
39
|
const openedBrowser = supportedChromiumBrowsers.find((b)=>ps.includes(b));
|
|
40
40
|
if (openedBrowser) {
|
|
41
41
|
await execAsync(`osascript openChrome.applescript "${encodeURI(url)}" "${openedBrowser}"`, {
|
|
42
|
-
cwd:
|
|
42
|
+
cwd: external_node_path_default.join(openBrowser_dirname, '../bin')
|
|
43
43
|
});
|
|
44
44
|
return true;
|
|
45
45
|
}
|
|
46
46
|
} catch (err) {
|
|
47
|
-
|
|
47
|
+
logger.error(err);
|
|
48
48
|
}
|
|
49
49
|
try {
|
|
50
50
|
openBrowser_open(url).catch(()=>{});
|
|
51
51
|
return true;
|
|
52
52
|
} catch (err) {
|
|
53
|
-
|
|
53
|
+
logger.error(err);
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
function execAsync(command, options) {
|
|
58
58
|
return new Promise((resolve, reject)=>{
|
|
59
|
-
|
|
59
|
+
exec(command, options, (error, stdout)=>{
|
|
60
60
|
if (error) reject(error);
|
|
61
61
|
else resolve(stdout.toString());
|
|
62
62
|
});
|
package/dist/prebundleDeps.cjs
CHANGED
|
@@ -48,7 +48,6 @@ const external_html_webpack_plugin_namespaceObject = require("html-webpack-plugi
|
|
|
48
48
|
var external_html_webpack_plugin_default = /*#__PURE__*/ __webpack_require__.n(external_html_webpack_plugin_namespaceObject);
|
|
49
49
|
const external_tinyglobby_namespaceObject = require("tinyglobby");
|
|
50
50
|
const external_colors_cjs_namespaceObject = require("./colors.cjs");
|
|
51
|
-
var external_colors_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_colors_cjs_namespaceObject);
|
|
52
51
|
const external_constants_cjs_namespaceObject = require("./constants.cjs");
|
|
53
52
|
const external_global_cjs_namespaceObject = require("./global.cjs");
|
|
54
53
|
const external_logger_cjs_namespaceObject = require("./logger.cjs");
|
|
@@ -95,7 +94,7 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
95
94
|
};
|
|
96
95
|
const failedDeps = [];
|
|
97
96
|
const updateProgress = ()=>{
|
|
98
|
-
(0, external_utils_cjs_namespaceObject.logUpdate)(`${
|
|
97
|
+
(0, external_utils_cjs_namespaceObject.logUpdate)(`${external_colors_cjs_namespaceObject.colors.magenta("\xbb")} optimizing dependencies (${count.bundled}/${count.total})`);
|
|
99
98
|
if (count.total === count.bundled + failedDeps.length) console.log();
|
|
100
99
|
};
|
|
101
100
|
const { root } = unpackConfig;
|
|
@@ -252,9 +251,9 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
252
251
|
version: packageJson.version
|
|
253
252
|
};
|
|
254
253
|
}).filter(Boolean);
|
|
255
|
-
if (noEntryDeps[0]) external_logger_cjs_namespaceObject.logger.warn(`could not find entry for "${
|
|
254
|
+
if (noEntryDeps[0]) external_logger_cjs_namespaceObject.logger.warn(`could not find entry for "${external_colors_cjs_namespaceObject.colors.bold(noEntryDeps.join(', '))}"`);
|
|
256
255
|
const bundledDeps = await Promise.all(needBundleDeps.map((depInfo)=>bundleDep(depInfo)));
|
|
257
|
-
if (failedDeps[0]) external_logger_cjs_namespaceObject.logger.warn(`something went wrong while optimizing "${
|
|
256
|
+
if (failedDeps[0]) external_logger_cjs_namespaceObject.logger.warn(`something went wrong while optimizing "${external_colors_cjs_namespaceObject.colors.bold(failedDeps.join(', '))}"`);
|
|
258
257
|
const cachePath = external_node_path_default().resolve(root, external_constants_cjs_namespaceObject.TEMP_DIR, CACHE_DIR);
|
|
259
258
|
const app = external_express_default()();
|
|
260
259
|
app.use(external_cors_default()());
|
|
@@ -309,7 +308,8 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
309
308
|
apply: (compiler)=>{
|
|
310
309
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation)=>{
|
|
311
310
|
HtmlPlugin.getCompilationHooks(compilation).beforeAssetTagGeneration.tapPromise(PLUGIN_NAME, async (args)=>{
|
|
312
|
-
|
|
311
|
+
const sortedPreJsAssets = preJsAssets.sort((a, b)=>a.order - b.order).map((item)=>item.path);
|
|
312
|
+
args.assets.js.unshift(...sortedPreJsAssets, ...jsAssets);
|
|
313
313
|
args.assets.css.unshift(...cssAssets);
|
|
314
314
|
return args;
|
|
315
315
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prebundleDeps.d.ts","sourceRoot":"","sources":["../src/prebundleDeps.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AA2D3C,eAAO,MAAM,aAAa,sBAEvB;IACD,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,OAAO,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"prebundleDeps.d.ts","sourceRoot":"","sources":["../src/prebundleDeps.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AA2D3C,eAAO,MAAM,aAAa,sBAEvB;IACD,YAAY,EAAE,YAAY,CAAA;CAC3B,KAAG,OAAO,CAAC,YAAY,CA6QvB,CAAA"}
|
package/dist/prebundleDeps.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
3
|
+
import external_node_fs_default from "node:fs";
|
|
4
|
+
import external_node_path_default from "node:path";
|
|
5
|
+
import { rspack } from "@rspack/core";
|
|
6
|
+
import external_cors_default from "cors";
|
|
7
|
+
import external_express_default from "express";
|
|
8
|
+
import external_html_webpack_plugin_default from "html-webpack-plugin";
|
|
9
|
+
import { globSync } from "tinyglobby";
|
|
10
|
+
import { colors } from "./colors.js";
|
|
11
|
+
import { TEMP_DIR } from "./constants.js";
|
|
12
|
+
import { restartCleaners } from "./global.js";
|
|
13
|
+
import { logger } from "./logger.js";
|
|
14
|
+
import { getCompiledPkgPath, getPort, getUserDepPath, isPlainObject, isString, logUpdate, removeDir } from "./utils.js";
|
|
15
15
|
const CACHE_DIR = 'umd';
|
|
16
16
|
const getExternalLibraryName = (pkgName)=>{
|
|
17
17
|
const externalAlias = {
|
|
@@ -26,23 +26,23 @@ const getExternalValue = (pkgName)=>`window ${getExternalLibraryName(pkgName)}`;
|
|
|
26
26
|
const getExistExternals = (externals)=>{
|
|
27
27
|
const existExternals = new Set();
|
|
28
28
|
if (Array.isArray(externals)) externals.forEach((item)=>{
|
|
29
|
-
if (
|
|
29
|
+
if (isPlainObject(item)) Object.keys(item).forEach((key)=>existExternals.add(key));
|
|
30
30
|
});
|
|
31
|
-
else if (
|
|
31
|
+
else if (isPlainObject(externals)) Object.keys(externals).forEach((key)=>existExternals.add(key));
|
|
32
32
|
return Array.from(existExternals);
|
|
33
33
|
};
|
|
34
34
|
const getPkgEntry = (packageJson)=>{
|
|
35
35
|
if (packageJson.module) return packageJson.module;
|
|
36
36
|
if (packageJson.exports) {
|
|
37
|
-
if (
|
|
37
|
+
if (isString(packageJson.exports)) return packageJson.exports;
|
|
38
38
|
const defaultExport = packageJson.exports['.'];
|
|
39
39
|
if (defaultExport) {
|
|
40
|
-
if (
|
|
41
|
-
if (
|
|
42
|
-
if (
|
|
43
|
-
if (
|
|
40
|
+
if (isString(defaultExport)) return defaultExport;
|
|
41
|
+
if (isString(defaultExport.import)) return defaultExport.import;
|
|
42
|
+
if (isString(defaultExport.browser)) return defaultExport.browser;
|
|
43
|
+
if (isString(defaultExport.default)) return defaultExport.default;
|
|
44
44
|
}
|
|
45
|
-
if (
|
|
45
|
+
if (isString(packageJson.exports.default)) return packageJson.exports.default;
|
|
46
46
|
}
|
|
47
47
|
if (packageJson.main) return packageJson.main;
|
|
48
48
|
};
|
|
@@ -54,15 +54,15 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
54
54
|
};
|
|
55
55
|
const failedDeps = [];
|
|
56
56
|
const updateProgress = ()=>{
|
|
57
|
-
|
|
57
|
+
logUpdate(`${colors.magenta("\xbb")} optimizing dependencies (${count.bundled}/${count.total})`);
|
|
58
58
|
if (count.total === count.bundled + failedDeps.length) console.log();
|
|
59
59
|
};
|
|
60
60
|
const { root } = unpackConfig;
|
|
61
61
|
const bundleDep = ({ name, entry, version })=>new Promise((resolve)=>{
|
|
62
|
-
const pkgDir =
|
|
63
|
-
const outDir =
|
|
62
|
+
const pkgDir = external_node_path_default.resolve(root, TEMP_DIR, CACHE_DIR, name);
|
|
63
|
+
const outDir = external_node_path_default.resolve(pkgDir, version);
|
|
64
64
|
const getResult = ()=>{
|
|
65
|
-
const assets =
|
|
65
|
+
const assets = globSync('**/index.{js,css}', {
|
|
66
66
|
cwd: outDir,
|
|
67
67
|
absolute: true
|
|
68
68
|
});
|
|
@@ -71,8 +71,8 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
71
71
|
assets
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
|
-
if (
|
|
75
|
-
|
|
74
|
+
if (external_node_fs_default.existsSync(outDir)) return void resolve(getResult());
|
|
75
|
+
removeDir(pkgDir);
|
|
76
76
|
count.total++;
|
|
77
77
|
updateProgress();
|
|
78
78
|
const getSwcOptions = ({ tsx })=>({
|
|
@@ -90,7 +90,7 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
-
const compiler =
|
|
93
|
+
const compiler = rspack({
|
|
94
94
|
entry: {
|
|
95
95
|
index: entry
|
|
96
96
|
},
|
|
@@ -137,12 +137,12 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
137
137
|
type: 'css/auto',
|
|
138
138
|
use: [
|
|
139
139
|
{
|
|
140
|
-
loader:
|
|
140
|
+
loader: getCompiledPkgPath('less-loader'),
|
|
141
141
|
options: {
|
|
142
142
|
lessOptions: {
|
|
143
143
|
javascriptEnabled: true
|
|
144
144
|
},
|
|
145
|
-
implementation:
|
|
145
|
+
implementation: getUserDepPath(root, 'less')
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
]
|
|
@@ -152,10 +152,10 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
152
152
|
type: 'css/auto',
|
|
153
153
|
use: [
|
|
154
154
|
{
|
|
155
|
-
loader:
|
|
155
|
+
loader: getCompiledPkgPath('sass-loader'),
|
|
156
156
|
options: {
|
|
157
157
|
api: 'modern-compiler',
|
|
158
|
-
implementation:
|
|
158
|
+
implementation: getUserDepPath(root, [
|
|
159
159
|
'sass-embedded',
|
|
160
160
|
'sass'
|
|
161
161
|
])
|
|
@@ -183,7 +183,7 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
183
183
|
if (null == stats ? void 0 : stats.hasErrors()) {
|
|
184
184
|
isFailed = true;
|
|
185
185
|
failedDeps.push(name);
|
|
186
|
-
|
|
186
|
+
removeDir(outDir);
|
|
187
187
|
} else count.bundled++;
|
|
188
188
|
updateProgress();
|
|
189
189
|
compiler.close(()=>{
|
|
@@ -191,9 +191,9 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
191
191
|
});
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
|
-
const userOptions =
|
|
194
|
+
const userOptions = isPlainObject(null == (_unpackConfig_dev = unpackConfig.dev) ? void 0 : _unpackConfig_dev.prebundle) ? unpackConfig.dev.prebundle : {};
|
|
195
195
|
const ignoreCssDeps = userOptions.ignoreCss || [];
|
|
196
|
-
const packageJson = JSON.parse(
|
|
196
|
+
const packageJson = JSON.parse(external_node_fs_default.readFileSync(external_node_path_default.resolve(root, 'package.json'), 'utf-8'));
|
|
197
197
|
const existExternals = getExistExternals(unpackConfig.externals);
|
|
198
198
|
const excludeDeps = [
|
|
199
199
|
...existExternals || [],
|
|
@@ -202,25 +202,25 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
202
202
|
const shouldIncludeDeps = Object.keys(packageJson.dependencies).filter((pkgName)=>!excludeDeps.includes(pkgName));
|
|
203
203
|
const noEntryDeps = [];
|
|
204
204
|
const needBundleDeps = shouldIncludeDeps.map((pkgName)=>{
|
|
205
|
-
const packageJson = JSON.parse(
|
|
205
|
+
const packageJson = JSON.parse(external_node_fs_default.readFileSync(external_node_path_default.resolve(root, 'node_modules', pkgName, 'package.json'), 'utf-8'));
|
|
206
206
|
const entry = getPkgEntry(packageJson);
|
|
207
207
|
if (!entry) return void noEntryDeps.push(pkgName);
|
|
208
208
|
return {
|
|
209
209
|
name: pkgName,
|
|
210
|
-
entry:
|
|
210
|
+
entry: external_node_path_default.resolve(root, 'node_modules', pkgName, entry),
|
|
211
211
|
version: packageJson.version
|
|
212
212
|
};
|
|
213
213
|
}).filter(Boolean);
|
|
214
|
-
if (noEntryDeps[0])
|
|
214
|
+
if (noEntryDeps[0]) logger.warn(`could not find entry for "${colors.bold(noEntryDeps.join(', '))}"`);
|
|
215
215
|
const bundledDeps = await Promise.all(needBundleDeps.map((depInfo)=>bundleDep(depInfo)));
|
|
216
|
-
if (failedDeps[0])
|
|
217
|
-
const cachePath =
|
|
218
|
-
const app = (
|
|
219
|
-
app.use((
|
|
220
|
-
app.use(`/${CACHE_DIR}`,
|
|
221
|
-
const port = await
|
|
216
|
+
if (failedDeps[0]) logger.warn(`something went wrong while optimizing "${colors.bold(failedDeps.join(', '))}"`);
|
|
217
|
+
const cachePath = external_node_path_default.resolve(root, TEMP_DIR, CACHE_DIR);
|
|
218
|
+
const app = external_express_default();
|
|
219
|
+
app.use(external_cors_default());
|
|
220
|
+
app.use(`/${CACHE_DIR}`, external_express_default["static"](cachePath));
|
|
221
|
+
const port = await getPort();
|
|
222
222
|
const staticServer = app.listen(port, ()=>{});
|
|
223
|
-
|
|
223
|
+
restartCleaners.push(()=>new Promise((resolve)=>staticServer.close(()=>resolve())));
|
|
224
224
|
const externals = {};
|
|
225
225
|
const jsAssets = [];
|
|
226
226
|
const cssAssets = [];
|
|
@@ -228,7 +228,7 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
228
228
|
bundledDeps.filter(Boolean).forEach((dep)=>{
|
|
229
229
|
externals[dep.name] = getExternalValue(dep.name);
|
|
230
230
|
dep.assets.forEach((absPath)=>{
|
|
231
|
-
const relativePath =
|
|
231
|
+
const relativePath = external_node_path_default.relative(cachePath, absPath);
|
|
232
232
|
const preDeps = [
|
|
233
233
|
'react',
|
|
234
234
|
'react-dom',
|
|
@@ -236,7 +236,7 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
236
236
|
'react-router-dom'
|
|
237
237
|
];
|
|
238
238
|
const serverPath = `//localhost:${port}/${CACHE_DIR}/${relativePath}`;
|
|
239
|
-
switch(
|
|
239
|
+
switch(external_node_path_default.extname(relativePath)){
|
|
240
240
|
case '.js':
|
|
241
241
|
if (preDeps.includes(dep.name)) preJsAssets.push({
|
|
242
242
|
path: serverPath,
|
|
@@ -259,7 +259,7 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
259
259
|
...externals,
|
|
260
260
|
...unpackConfig.externals
|
|
261
261
|
};
|
|
262
|
-
const HtmlPlugin = 'rspack' === unpackConfig.bundler ?
|
|
262
|
+
const HtmlPlugin = 'rspack' === unpackConfig.bundler ? rspack.HtmlRspackPlugin : external_html_webpack_plugin_default;
|
|
263
263
|
unpackConfig.plugins.push({
|
|
264
264
|
name: 'unpack:prebundle',
|
|
265
265
|
bundlerConfig: (config)=>{
|
|
@@ -268,7 +268,8 @@ const prebundleDeps = async ({ unpackConfig })=>{
|
|
|
268
268
|
apply: (compiler)=>{
|
|
269
269
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation)=>{
|
|
270
270
|
HtmlPlugin.getCompilationHooks(compilation).beforeAssetTagGeneration.tapPromise(PLUGIN_NAME, async (args)=>{
|
|
271
|
-
|
|
271
|
+
const sortedPreJsAssets = preJsAssets.sort((a, b)=>a.order - b.order).map((item)=>item.path);
|
|
272
|
+
args.assets.js.unshift(...sortedPreJsAssets, ...jsAssets);
|
|
272
273
|
args.assets.css.unshift(...cssAssets);
|
|
273
274
|
return args;
|
|
274
275
|
});
|
package/dist/progressBar.cjs
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
3
|
(()=>{
|
|
13
4
|
__webpack_require__.d = (exports1, definition)=>{
|
|
14
5
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -36,7 +27,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
36
27
|
ProgressBar: ()=>ProgressBar
|
|
37
28
|
});
|
|
38
29
|
const external_colors_cjs_namespaceObject = require("./colors.cjs");
|
|
39
|
-
var external_colors_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_colors_cjs_namespaceObject);
|
|
40
30
|
const external_utils_cjs_namespaceObject = require("./utils.cjs");
|
|
41
31
|
function _define_property(obj, key, value) {
|
|
42
32
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -54,7 +44,7 @@ class ProgressBar {
|
|
|
54
44
|
const messageWidth = terminalWidth - this.prefix.length - 8;
|
|
55
45
|
let current = originalCurrent;
|
|
56
46
|
if (originalCurrent >= 0.98) current = 1;
|
|
57
|
-
(0, external_utils_cjs_namespaceObject.logUpdate)(`${this.prefix} (${Math.floor(100 * current)}%) ${
|
|
47
|
+
(0, external_utils_cjs_namespaceObject.logUpdate)(`${this.prefix} (${Math.floor(100 * current)}%) ${external_colors_cjs_namespaceObject.colors.dim(message.slice(0, messageWidth).padEnd(messageWidth, ' '))}`);
|
|
58
48
|
}
|
|
59
49
|
done() {
|
|
60
50
|
console.log();
|
package/dist/progressBar.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { colors } from "./colors.js";
|
|
4
|
+
import { logUpdate } from "./utils.js";
|
|
5
5
|
function _define_property(obj, key, value) {
|
|
6
6
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
7
7
|
value: value,
|
|
@@ -18,7 +18,7 @@ class ProgressBar {
|
|
|
18
18
|
const messageWidth = terminalWidth - this.prefix.length - 8;
|
|
19
19
|
let current = originalCurrent;
|
|
20
20
|
if (originalCurrent >= 0.98) current = 1;
|
|
21
|
-
|
|
21
|
+
logUpdate(`${this.prefix} (${Math.floor(100 * current)}%) ${colors.dim(message.slice(0, messageWidth).padEnd(messageWidth, ' '))}`);
|
|
22
22
|
}
|
|
23
23
|
done() {
|
|
24
24
|
console.log();
|
package/dist/reporter.cjs
CHANGED
|
@@ -43,7 +43,6 @@ const external_node_util_namespaceObject = require("node:util");
|
|
|
43
43
|
const external_node_zlib_namespaceObject = require("node:zlib");
|
|
44
44
|
var external_node_zlib_default = /*#__PURE__*/ __webpack_require__.n(external_node_zlib_namespaceObject);
|
|
45
45
|
const external_colors_cjs_namespaceObject = require("./colors.cjs");
|
|
46
|
-
var external_colors_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_colors_cjs_namespaceObject);
|
|
47
46
|
const external_utils_cjs_namespaceObject = require("./utils.cjs");
|
|
48
47
|
const chunkSizeLimit = 500;
|
|
49
48
|
const gzip = (0, external_node_util_namespaceObject.promisify)(external_node_zlib_default().gzip);
|
|
@@ -108,7 +107,10 @@ async function printFileSize({ root, stats }) {
|
|
|
108
107
|
totalCompressedSize += compressedSize;
|
|
109
108
|
compressedCount++;
|
|
110
109
|
(0, external_utils_cjs_namespaceObject.logUpdate)(`computing gzip size (${compressedCount})...`);
|
|
111
|
-
if (compressedCount === origin.assets.length)
|
|
110
|
+
if (compressedCount === origin.assets.length) {
|
|
111
|
+
(0, external_utils_cjs_namespaceObject.logUpdate)(`\u{2713} computed gzip size (${compressedCount})`);
|
|
112
|
+
console.log();
|
|
113
|
+
}
|
|
112
114
|
const chunk = {
|
|
113
115
|
name: external_node_path_default().basename(asset.name),
|
|
114
116
|
path: `${distFolder}/${asset.name}`,
|
|
@@ -139,16 +141,16 @@ async function printFileSize({ root, stats }) {
|
|
|
139
141
|
const isLarge = 'JS' === group.type && chunk.size / 1000 > chunkSizeLimit;
|
|
140
142
|
const sizeColor = isLarge ? 'yellow' : 'dim';
|
|
141
143
|
const relativeOutDir = external_node_path_default().dirname(chunk.path) + '/';
|
|
142
|
-
let log =
|
|
143
|
-
log +=
|
|
144
|
-
log +=
|
|
145
|
-
if (chunk.compressedSize) log +=
|
|
144
|
+
let log = external_colors_cjs_namespaceObject.colors.dim(relativeOutDir);
|
|
145
|
+
log += external_colors_cjs_namespaceObject.colors[group.color](chunk.name.padEnd(longest + 2 - relativeOutDir.length));
|
|
146
|
+
log += external_colors_cjs_namespaceObject.colors[sizeColor](displaySize(chunk.size).padStart(sizePad));
|
|
147
|
+
if (chunk.compressedSize) log += external_colors_cjs_namespaceObject.colors.dim(` \u{2502} gzip: ${displaySize(chunk.compressedSize).padStart(compressPad)}`);
|
|
146
148
|
console.log(log);
|
|
147
149
|
});
|
|
148
150
|
});
|
|
149
|
-
let log =
|
|
150
|
-
log +=
|
|
151
|
-
log +=
|
|
151
|
+
let log = external_colors_cjs_namespaceObject.colors.blue('Total'.padEnd(longest + 2));
|
|
152
|
+
log += external_colors_cjs_namespaceObject.colors.blue(displaySize(totalSize));
|
|
153
|
+
log += external_colors_cjs_namespaceObject.colors.dim(` \u{2502} gzip: ${displaySize(totalCompressedSize)}`);
|
|
152
154
|
console.log(log);
|
|
153
155
|
}
|
|
154
156
|
exports.printFileSize = __webpack_exports__.printFileSize;
|
package/dist/reporter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,KAAK,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,SAAS,CAAA;AAIpD,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,YAAY,GAAG,WAAW,CAAA;CAClC,CAAA;AA2BD,wBAAsB,aAAa,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,KAAK,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,SAAS,CAAA;AAIpD,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,YAAY,GAAG,WAAW,CAAA;CAClC,CAAA;AA2BD,wBAAsB,aAAa,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,iBAgG3D"}
|
package/dist/reporter.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
3
|
+
import external_node_fs_default from "node:fs";
|
|
4
|
+
import external_node_path_default from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import external_node_zlib_default from "node:zlib";
|
|
7
|
+
import { colors } from "./colors.js";
|
|
8
|
+
import { logUpdate } from "./utils.js";
|
|
9
9
|
const chunkSizeLimit = 500;
|
|
10
|
-
const gzip =
|
|
10
|
+
const gzip = promisify(external_node_zlib_default.gzip);
|
|
11
11
|
const numberFormatter = new Intl.NumberFormat('en', {
|
|
12
12
|
maximumFractionDigits: 2,
|
|
13
13
|
minimumFractionDigits: 2
|
|
@@ -45,9 +45,9 @@ async function printFileSize({ root, stats }) {
|
|
|
45
45
|
return acc;
|
|
46
46
|
}, {});
|
|
47
47
|
let compressedCount = 0;
|
|
48
|
-
|
|
48
|
+
logUpdate('computing gzip size (0)...');
|
|
49
49
|
const distPath = stats.compilation.outputOptions.path;
|
|
50
|
-
const distFolder =
|
|
50
|
+
const distFolder = external_node_path_default.relative(root, distPath);
|
|
51
51
|
const origin = stats.toJson({
|
|
52
52
|
all: false,
|
|
53
53
|
assets: true,
|
|
@@ -62,22 +62,25 @@ async function printFileSize({ root, stats }) {
|
|
|
62
62
|
let totalSize = 0;
|
|
63
63
|
let totalCompressedSize = 0;
|
|
64
64
|
await Promise.all(origin.assets.map(async (asset)=>{
|
|
65
|
-
const content = await
|
|
65
|
+
const content = await external_node_fs_default.promises.readFile(external_node_path_default.join(distPath, asset.name));
|
|
66
66
|
const size = content.length;
|
|
67
67
|
const compressedSize = await getCompressedSize(content);
|
|
68
68
|
totalSize += size;
|
|
69
69
|
totalCompressedSize += compressedSize;
|
|
70
70
|
compressedCount++;
|
|
71
|
-
|
|
72
|
-
if (compressedCount === origin.assets.length)
|
|
71
|
+
logUpdate(`computing gzip size (${compressedCount})...`);
|
|
72
|
+
if (compressedCount === origin.assets.length) {
|
|
73
|
+
logUpdate(`\u{2713} computed gzip size (${compressedCount})`);
|
|
74
|
+
console.log();
|
|
75
|
+
}
|
|
73
76
|
const chunk = {
|
|
74
|
-
name:
|
|
77
|
+
name: external_node_path_default.basename(asset.name),
|
|
75
78
|
path: `${distFolder}/${asset.name}`,
|
|
76
79
|
size,
|
|
77
80
|
compressedSize
|
|
78
81
|
};
|
|
79
82
|
if (chunk.path.length > longest) longest = chunk.path.length;
|
|
80
|
-
const ext =
|
|
83
|
+
const ext = external_node_path_default.extname(asset.name);
|
|
81
84
|
switch(ext){
|
|
82
85
|
case '.html':
|
|
83
86
|
chunkGroupMap.HTML.chunks.push(chunk);
|
|
@@ -99,17 +102,17 @@ async function printFileSize({ root, stats }) {
|
|
|
99
102
|
group.chunks.sort((a, b)=>a.size - b.size).forEach((chunk)=>{
|
|
100
103
|
const isLarge = 'JS' === group.type && chunk.size / 1000 > chunkSizeLimit;
|
|
101
104
|
const sizeColor = isLarge ? 'yellow' : 'dim';
|
|
102
|
-
const relativeOutDir =
|
|
103
|
-
let log =
|
|
104
|
-
log +=
|
|
105
|
-
log +=
|
|
106
|
-
if (chunk.compressedSize) log +=
|
|
105
|
+
const relativeOutDir = external_node_path_default.dirname(chunk.path) + '/';
|
|
106
|
+
let log = colors.dim(relativeOutDir);
|
|
107
|
+
log += colors[group.color](chunk.name.padEnd(longest + 2 - relativeOutDir.length));
|
|
108
|
+
log += colors[sizeColor](displaySize(chunk.size).padStart(sizePad));
|
|
109
|
+
if (chunk.compressedSize) log += colors.dim(` \u{2502} gzip: ${displaySize(chunk.compressedSize).padStart(compressPad)}`);
|
|
107
110
|
console.log(log);
|
|
108
111
|
});
|
|
109
112
|
});
|
|
110
|
-
let log =
|
|
111
|
-
log +=
|
|
112
|
-
log +=
|
|
113
|
+
let log = colors.blue('Total'.padEnd(longest + 2));
|
|
114
|
+
log += colors.blue(displaySize(totalSize));
|
|
115
|
+
log += colors.dim(` \u{2502} gzip: ${displaySize(totalCompressedSize)}`);
|
|
113
116
|
console.log(log);
|
|
114
117
|
}
|
|
115
118
|
export { printFileSize };
|
package/dist/run/build.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import __rslib_shim_module__ from 'module';
|
|
2
2
|
/*#__PURE__*/ import.meta.url;
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
3
|
+
import { rspack } from "@rspack/core";
|
|
4
|
+
import { isWatch } from "../utils.js";
|
|
5
|
+
import external_webpack_default from "webpack";
|
|
6
|
+
import { getBundlerConfig } from "../bundler-config/index.js";
|
|
7
7
|
async function bundlerBuild(unpackConfig) {
|
|
8
|
-
const bundler = 'rspack' === unpackConfig.bundler ?
|
|
9
|
-
const config = await
|
|
8
|
+
const bundler = 'rspack' === unpackConfig.bundler ? rspack : external_webpack_default;
|
|
9
|
+
const config = await getBundlerConfig(unpackConfig);
|
|
10
10
|
const compiler = bundler(config);
|
|
11
11
|
const handler = (err, stats)=>{
|
|
12
12
|
if (err) {
|
|
@@ -18,9 +18,9 @@ async function bundlerBuild(unpackConfig) {
|
|
|
18
18
|
colors: true,
|
|
19
19
|
preset: 'errors-only'
|
|
20
20
|
}));
|
|
21
|
-
if (!
|
|
21
|
+
if (!isWatch()) compiler.close(()=>{});
|
|
22
22
|
};
|
|
23
|
-
if (
|
|
23
|
+
if (isWatch()) compiler.watch({}, handler);
|
|
24
24
|
else compiler.run(handler);
|
|
25
25
|
}
|
|
26
26
|
export { bundlerBuild };
|
package/dist/run/dev.cjs
CHANGED
|
@@ -37,7 +37,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
37
37
|
});
|
|
38
38
|
const core_namespaceObject = require("@rspack/core");
|
|
39
39
|
const external_colors_cjs_namespaceObject = require("../colors.cjs");
|
|
40
|
-
var external_colors_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_colors_cjs_namespaceObject);
|
|
41
40
|
const external_global_cjs_namespaceObject = require("../global.cjs");
|
|
42
41
|
const external_logger_cjs_namespaceObject = require("../logger.cjs");
|
|
43
42
|
const external_openBrowser_cjs_namespaceObject = require("../openBrowser.cjs");
|
|
@@ -79,7 +78,7 @@ async function bundlerDev(originalUnpackConfig) {
|
|
|
79
78
|
];
|
|
80
79
|
}
|
|
81
80
|
const server = new (external_webpack_dev_server_default())(devServerOptions, compiler);
|
|
82
|
-
external_logger_cjs_namespaceObject.logger.greet(` ${
|
|
81
|
+
external_logger_cjs_namespaceObject.logger.greet(` ${external_colors_cjs_namespaceObject.colors.green(`${external_colors_cjs_namespaceObject.colors.bold('UNPACK')} v2.2.0`)} ${external_colors_cjs_namespaceObject.colors.dim(`ready in ${external_colors_cjs_namespaceObject.colors.reset(Math.ceil(performance.now() - global.__unpack_start_time))}ms`)}\n`);
|
|
83
82
|
printAddressUrls(port);
|
|
84
83
|
await server.start();
|
|
85
84
|
external_global_cjs_namespaceObject.restartCleaners.push(async ()=>await server.stop(), ()=>new Promise((resolve)=>compiler.close(()=>resolve())));
|
|
@@ -93,9 +92,9 @@ function printAddressUrls(port) {
|
|
|
93
92
|
const addressUrls = (0, external_utils_cjs_namespaceObject.getAddressUrls)({
|
|
94
93
|
port
|
|
95
94
|
});
|
|
96
|
-
const colorUrl = (url)=>
|
|
95
|
+
const colorUrl = (url)=>external_colors_cjs_namespaceObject.colors.cyan(url.replace(/:(\d+)\//, (_, port)=>`:${external_colors_cjs_namespaceObject.colors.bold(port)}/`));
|
|
97
96
|
addressUrls.forEach((addr)=>{
|
|
98
|
-
console.log(` ${
|
|
97
|
+
console.log(` ${external_colors_cjs_namespaceObject.colors.green(external_colors_cjs_namespaceObject.colors.dim("\u279C"))} ${external_colors_cjs_namespaceObject.colors.dim(addr.label)}${colorUrl(addr.url)}`);
|
|
99
98
|
});
|
|
100
99
|
}
|
|
101
100
|
exports.bundlerDev = __webpack_exports__.bundlerDev;
|