xhs-mp-compiler-cli 2.0.0-beta.3 → 2.0.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/dist/bin/xhs-mp-cli-build.js +48 -34
- package/dist/bin/xhs-mp-cli-dev.js +44 -44
- package/dist/bin/xhs-mp-cli.js +22 -12
- package/dist/compiler.d.ts +21 -28
- package/dist/compiler.js +327 -327
- package/dist/compilerImpl.d.ts +19 -0
- package/dist/compilerImpl.js +173 -0
- package/dist/config/constant.config.d.ts +24 -0
- package/dist/config/constant.config.js +82 -30
- package/dist/config/dir.config.js +23 -13
- package/dist/index.d.ts +9 -9
- package/dist/index.js +454 -408
- package/dist/packs/index.d.ts +4 -4
- package/dist/packs/index.js +38 -30
- package/dist/packs/mp-pack/index.js +38 -30
- package/dist/packs/webpack/dev-server/index.js +61 -50
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +33 -23
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +28 -18
- package/dist/packs/webpack/index.d.ts +1 -1
- package/dist/packs/webpack/index.js +99 -90
- package/dist/packs/webpack/webpack.d.ts +2 -1
- package/dist/packs/webpack/webpack.js +81 -63
- package/dist/presets/babel.d.ts +0 -1
- package/dist/presets/babel.js +64 -58
- package/dist/presets/common.js +42 -45
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +50 -40
- package/dist/presets/configs/minigame/assets/index.js +62 -52
- package/dist/presets/configs/minigame/service/index.js +49 -30
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +33 -23
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +2 -2
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -60
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +3 -3
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +39 -29
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +120 -113
- package/dist/presets/configs/miniprogram/assets/index.js +45 -43
- package/dist/presets/configs/miniprogram/render/component.js +51 -41
- package/dist/presets/configs/miniprogram/render/index.d.ts +2 -3
- package/dist/presets/configs/miniprogram/render/index.js +85 -68
- package/dist/presets/configs/miniprogram/render/render.js +53 -43
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +84 -49
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +164 -126
- package/dist/presets/configs/miniprogram/service/index.js +82 -65
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +60 -50
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +93 -55
- package/dist/presets/index.js +100 -90
- package/dist/presets/loaders/mg-entry-loader.js +32 -22
- package/dist/presets/loaders/mini-style-loader.js +79 -55
- package/dist/presets/loaders/mp-entry-loader.js +149 -140
- package/dist/presets/loaders/wxss-loader.js +73 -63
- package/dist/presets/plugins/InjectorPlugin.js +23 -13
- package/dist/presets/plugins/SourceMapDevToolPlugin.d.ts +1 -0
- package/dist/presets/plugins/SourceMapDevToolPlugin.js +23 -0
- package/dist/presets/prod.js +88 -78
- package/dist/sharedFs.d.ts +2 -0
- package/dist/sharedFs.js +24 -0
- package/dist/types/index.d.ts +11 -37
- package/dist/types/index.js +23 -13
- package/dist/utils/{apm/index.d.ts → apm.d.ts} +5 -3
- package/dist/utils/apm.js +245 -0
- package/dist/utils/cache.d.ts +28 -0
- package/dist/utils/cache.js +49 -0
- package/dist/utils/common.js +42 -32
- package/dist/utils/css.d.ts +1 -1
- package/dist/utils/css.js +43 -35
- package/dist/utils/depenedHelper.js +95 -85
- package/dist/utils/file.js +39 -29
- package/dist/utils/loader-utils.js +63 -53
- package/dist/utils/postcssRpx2Vw.js +43 -33
- package/dist/utils/project.d.ts +3 -2
- package/dist/utils/project.js +129 -119
- package/dist/utils/projectConfig.js +24 -15
- package/dist/utils/utils.js +51 -42
- package/dist/utils/workerPool.d.ts +29 -0
- package/dist/utils/workerPool.js +125 -0
- package/dist/utils/zip.js +239 -229
- package/package.json +33 -14
- package/dist/compilerCP.d.ts +0 -1
- package/dist/compilerCP.js +0 -175
- package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
- package/dist/presets/loaders/sjs-loader/index.js +0 -605
- package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
- package/dist/presets/loaders/sjs-loader/scope.js +0 -122
- package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
- package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
- package/dist/utils/apm/index.js +0 -198
- package/dist/utils/asyncWebpack.d.ts +0 -3
- package/dist/utils/asyncWebpack.js +0 -38
- package/dist/utils/const.d.ts +0 -27
- package/dist/utils/const.js +0 -47
- package/dist/utils/getSuffixName.d.ts +0 -3
- package/dist/utils/getSuffixName.js +0 -18
- package/dist/utils/tagTransformMap.d.ts +0 -36
- package/dist/utils/tagTransformMap.js +0 -39
|
@@ -1,35 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "postcss", "xhs-mp-compiler-utils"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const postcss_1 = require("postcss");
|
|
13
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
14
|
+
const postcssRpx2Vw = ({ outputUnit = 'vw', baseWidth = 750, unitPrecision = 5, mediaQuery = false, }) => {
|
|
15
|
+
const replacement = (m, $1) => {
|
|
16
|
+
return (0, xhs_mp_compiler_utils_1.calcRpx2Vw)($1, baseWidth, unitPrecision, outputUnit);
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
postcssPlugin: 'postcss-rpx-2-vw',
|
|
20
|
+
// https://astexplorer.net/#/2uBU1BLuJ1
|
|
21
|
+
Root: (root) => {
|
|
22
|
+
root.walkRules(rule => {
|
|
23
|
+
const rpxEntries = [];
|
|
24
|
+
rule.walkDecls(decl => {
|
|
25
|
+
if (!(0, xhs_mp_compiler_utils_1.isRpxValue)(decl.value))
|
|
26
|
+
return;
|
|
27
|
+
rpxEntries.push({ prop: decl.prop, value: decl.value });
|
|
28
|
+
decl.value = decl.value.replace(xhs_mp_compiler_utils_1.RPX_REGEX, replacement);
|
|
29
|
+
});
|
|
30
|
+
rpxEntries.forEach(decl => {
|
|
31
|
+
rule.append(new postcss_1.Declaration({ prop: '--ide-' + decl.prop, value: decl.value }));
|
|
32
|
+
});
|
|
30
33
|
});
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
if (mediaQuery) {
|
|
35
|
+
root.walkAtRules('media', rule => {
|
|
36
|
+
if (!(0, xhs_mp_compiler_utils_1.isRpxValue)(rule.params))
|
|
37
|
+
return;
|
|
38
|
+
rule.params = rule.params.replace(xhs_mp_compiler_utils_1.RPX_REGEX, replacement);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
33
43
|
};
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
exports.default = postcssRpx2Vw;
|
|
45
|
+
});
|
package/dist/utils/project.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export interface IZipFactory {
|
|
2
2
|
outputDir: string;
|
|
3
3
|
ignore: string[];
|
|
4
|
+
pattern?: string;
|
|
4
5
|
prefix: string;
|
|
5
6
|
inputDir: string;
|
|
6
7
|
type: "v0" | "v1" | "v2";
|
|
@@ -18,8 +19,8 @@ export declare const checkSubPackagesLegality: ({ appJsonContent, rootPath, dist
|
|
|
18
19
|
rootPath: string;
|
|
19
20
|
distDir: string;
|
|
20
21
|
}) => Promise<any[]>;
|
|
21
|
-
export declare const zipFactory: ({ outputDir, ignore, prefix, inputDir, type, appendFile, appendBuffer, meta, }: IZipFactory) => Promise<{
|
|
22
|
-
type: "
|
|
22
|
+
export declare const zipFactory: ({ outputDir, ignore, prefix, pattern, inputDir, type, appendFile, appendBuffer, meta, }: IZipFactory) => Promise<{
|
|
23
|
+
type: "v0" | "v1" | "v2";
|
|
23
24
|
zipPath: string;
|
|
24
25
|
zipSize: number;
|
|
25
26
|
root: string;
|
package/dist/utils/project.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
2
|
if (k2 === undefined) k2 = k;
|
|
4
3
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -31,134 +30,145 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
30
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
31
|
});
|
|
33
32
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const zip_1 = require("./zip");
|
|
39
|
-
const file_1 = require("./file");
|
|
40
|
-
const ignoreFiles = ['!node_modules'];
|
|
41
|
-
const _getFolderSize = (rootPath) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, file_1.getFolderSize)([rootPath, ...ignoreFiles]); });
|
|
42
|
-
const getCheckSizeFlag = (rootPath) => {
|
|
43
|
-
const projectConfig = path.resolve(rootPath, 'project.config.json');
|
|
44
|
-
const content = fs.readJSONSync(projectConfig);
|
|
45
|
-
return content.skipCheckSize;
|
|
46
|
-
};
|
|
47
|
-
// const SUB_PACKAGE_MAX_SIZE = 2 * 1024 * 1024; // 2M
|
|
48
|
-
// const TOTAL_PACKAGE_MAX_SIZE = 20 * 1024 * 1024; // 20M
|
|
49
|
-
/* 整个小程序体积不能超过 20M。 */
|
|
50
|
-
const checkProjectSize = (rootPath, distDir) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
-
const totalSize = yield _getFolderSize(distDir);
|
|
52
|
-
/* 微盟先暂时跳过整包体积校验 */
|
|
53
|
-
if (getCheckSizeFlag(rootPath) === true) {
|
|
54
|
-
return totalSize;
|
|
33
|
+
(function (factory) {
|
|
34
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
35
|
+
var v = factory(require, exports);
|
|
36
|
+
if (v !== undefined) module.exports = v;
|
|
55
37
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// throw new Error(`源码包大小 ${fileSize(totalSize)} 超过 20MB 上限 `);
|
|
59
|
-
// }
|
|
60
|
-
return totalSize;
|
|
61
|
-
});
|
|
62
|
-
/* 校验subPagee的root */
|
|
63
|
-
const checkSubPackages = (_a) => __awaiter(void 0, [_a], void 0, function* ({ subPackages, distDir }) {
|
|
64
|
-
let subSize = 0;
|
|
65
|
-
const sizeInfo = [];
|
|
66
|
-
for (let i = 0; i < subPackages.length; i++) {
|
|
67
|
-
const item = subPackages[i];
|
|
68
|
-
const fullPath = path.resolve(distDir, item.root);
|
|
69
|
-
const size = yield _getFolderSize(fullPath);
|
|
70
|
-
/* 跳过体积校验 */
|
|
71
|
-
// if (size > SUB_PACKAGE_MAX_SIZE) {
|
|
72
|
-
// throw new Error(`分包 ${item.root} 大小 ${fileSize(size)} 超出 2MB 上限`);
|
|
73
|
-
// }
|
|
74
|
-
const info = {
|
|
75
|
-
originSize: size,
|
|
76
|
-
root: item.root
|
|
77
|
-
};
|
|
78
|
-
sizeInfo.push(info);
|
|
79
|
-
subSize += size;
|
|
38
|
+
else if (typeof define === "function" && define.amd) {
|
|
39
|
+
define(["require", "exports", "path", "fs-extra", "./zip", "./file"], factory);
|
|
80
40
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
41
|
+
})(function (require, exports) {
|
|
42
|
+
"use strict";
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.zipFactory = exports.checkSubPackagesLegality = void 0;
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const fs = __importStar(require("fs-extra"));
|
|
47
|
+
const zip_1 = require("./zip");
|
|
48
|
+
const file_1 = require("./file");
|
|
49
|
+
const ignoreFiles = ['!node_modules'];
|
|
50
|
+
const _getFolderSize = (rootPath) => __awaiter(void 0, void 0, void 0, function* () { return yield (0, file_1.getFolderSize)([rootPath, ...ignoreFiles]); });
|
|
51
|
+
const getCheckSizeFlag = (rootPath) => {
|
|
52
|
+
const projectConfig = path.resolve(rootPath, 'project.config.json');
|
|
53
|
+
const content = fs.readJSONSync(projectConfig);
|
|
54
|
+
return content.skipCheckSize;
|
|
93
55
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
/*
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
56
|
+
// const SUB_PACKAGE_MAX_SIZE = 2 * 1024 * 1024; // 2M
|
|
57
|
+
// const TOTAL_PACKAGE_MAX_SIZE = 20 * 1024 * 1024; // 20M
|
|
58
|
+
/* 整个小程序体积不能超过 20M。 */
|
|
59
|
+
const checkProjectSize = (rootPath, distDir) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const totalSize = yield _getFolderSize(distDir);
|
|
61
|
+
/* 微盟先暂时跳过整包体积校验 */
|
|
62
|
+
if (getCheckSizeFlag(rootPath) === true) {
|
|
63
|
+
return totalSize;
|
|
64
|
+
}
|
|
65
|
+
/* 跳过体积校验 */
|
|
66
|
+
// if (totalSize > TOTAL_PACKAGE_MAX_SIZE) {
|
|
67
|
+
// throw new Error(`源码包大小 ${fileSize(totalSize)} 超过 20MB 上限 `);
|
|
68
|
+
// }
|
|
69
|
+
return totalSize;
|
|
70
|
+
});
|
|
71
|
+
/* 校验subPagee的root */
|
|
72
|
+
const checkSubPackages = (_a) => __awaiter(void 0, [_a], void 0, function* ({ subPackages, distDir }) {
|
|
73
|
+
let subSize = 0;
|
|
74
|
+
const sizeInfo = [];
|
|
75
|
+
for (let i = 0; i < subPackages.length; i++) {
|
|
76
|
+
const item = subPackages[i];
|
|
77
|
+
const fullPath = path.resolve(distDir, item.root);
|
|
111
78
|
const size = yield _getFolderSize(fullPath);
|
|
112
|
-
useSize += size;
|
|
113
79
|
/* 跳过体积校验 */
|
|
114
|
-
// if (
|
|
115
|
-
// throw new Error(
|
|
116
|
-
// `预加载 ${ruleKey} 包大小 ${fileSize(useSize)} 超出 2MB 上限`
|
|
117
|
-
// );
|
|
80
|
+
// if (size > SUB_PACKAGE_MAX_SIZE) {
|
|
81
|
+
// throw new Error(`分包 ${item.root} 大小 ${fileSize(size)} 超出 2MB 上限`);
|
|
118
82
|
// }
|
|
83
|
+
const info = {
|
|
84
|
+
originSize: size,
|
|
85
|
+
root: item.root
|
|
86
|
+
};
|
|
87
|
+
sizeInfo.push(info);
|
|
88
|
+
subSize += size;
|
|
119
89
|
}
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
/*
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
90
|
+
return { subSize, sizeInfo };
|
|
91
|
+
});
|
|
92
|
+
/* 主包体积:项目移除分包之后的体积 */
|
|
93
|
+
const checkMainPackages = ({ totalSize, subPkgSize }) => {
|
|
94
|
+
const mainSize = totalSize - subPkgSize;
|
|
95
|
+
/* 跳过体积校验 */
|
|
96
|
+
// if (mainSize > SUB_PACKAGE_MAX_SIZE) {
|
|
97
|
+
// throw new Error(`主包大小 ${fileSize(mainSize)} 超出 2MB 上限`);
|
|
98
|
+
// }
|
|
99
|
+
const sizeInfo = {
|
|
100
|
+
originSize: mainSize,
|
|
101
|
+
root: '/'
|
|
102
|
+
};
|
|
103
|
+
return { mainSize, sizeInfo };
|
|
104
|
+
};
|
|
105
|
+
/* 校验preloadRule的预加载的包 */
|
|
106
|
+
const checkPreloadRule = (_a) => __awaiter(void 0, [_a], void 0, function* ({ preloadRule, subPackages, distDir }) {
|
|
107
|
+
for (const ruleKey in preloadRule) {
|
|
108
|
+
let useSize = 0;
|
|
109
|
+
const rulePackages = preloadRule[ruleKey];
|
|
110
|
+
const packages = rulePackages.packages;
|
|
111
|
+
for (let i = 0; i < packages.length; i++) {
|
|
112
|
+
const pkg = packages[i];
|
|
113
|
+
if (pkg === "__APP__") {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const _pathIten = subPackages.find((v) => pkg === v.name || pkg === v.root);
|
|
117
|
+
if (!_pathIten)
|
|
118
|
+
return;
|
|
119
|
+
const fullPath = path.resolve(distDir, _pathIten.root);
|
|
120
|
+
const size = yield _getFolderSize(fullPath);
|
|
121
|
+
useSize += size;
|
|
122
|
+
/* 跳过体积校验 */
|
|
123
|
+
// if (useSize > SUB_PACKAGE_MAX_SIZE) {
|
|
124
|
+
// throw new Error(
|
|
125
|
+
// `预加载 ${ruleKey} 包大小 ${fileSize(useSize)} 超出 2MB 上限`
|
|
126
|
+
// );
|
|
127
|
+
// }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
/* 校验子包体积 */
|
|
132
|
+
const checkSubPackagesLegality = (_a) => __awaiter(void 0, [_a], void 0, function* ({ appJsonContent, rootPath, distDir }) {
|
|
133
|
+
const subPackages = appJsonContent.subPackages || appJsonContent.subpackages;
|
|
134
|
+
const preloadRule = appJsonContent.preloadRule || {};
|
|
135
|
+
const totalSize = yield checkProjectSize(rootPath, distDir);
|
|
136
|
+
if (!subPackages || subPackages.length === 0) {
|
|
137
|
+
/* 未开启分包 */
|
|
138
|
+
/* 微盟先暂时跳过整包体积校验 */
|
|
139
|
+
if (getCheckSizeFlag(rootPath) === true) {
|
|
140
|
+
return [{ originSize: totalSize, root: '' }];
|
|
141
|
+
}
|
|
142
|
+
checkMainPackages({ totalSize, subPkgSize: 0 }); // 校验主包
|
|
131
143
|
return [{ originSize: totalSize, root: '' }];
|
|
132
144
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const { sizeInfo: mainSizeInfo } = checkMainPackages({ totalSize, subPkgSize: subSize });
|
|
138
|
-
yield checkPreloadRule({ preloadRule, subPackages, distDir });
|
|
139
|
-
return [mainSizeInfo, ...sizeInfo];
|
|
140
|
-
});
|
|
141
|
-
exports.checkSubPackagesLegality = checkSubPackagesLegality;
|
|
142
|
-
/* zip包的工厂函数 */
|
|
143
|
-
const zipFactory = (_d) => __awaiter(void 0, [_d], void 0, function* ({ outputDir, ignore, prefix, inputDir, type, appendFile = [], appendBuffer = [], meta, }) {
|
|
144
|
-
const zip = new zip_1.Zip({ outputDir });
|
|
145
|
-
/* 添加文件 */
|
|
146
|
-
appendFile.forEach((file) => {
|
|
147
|
-
zip.archive.file(file, {
|
|
148
|
-
name: path.basename(file),
|
|
149
|
-
prefix,
|
|
150
|
-
});
|
|
145
|
+
const { subSize, sizeInfo } = yield checkSubPackages({ subPackages, distDir });
|
|
146
|
+
const { sizeInfo: mainSizeInfo } = checkMainPackages({ totalSize, subPkgSize: subSize });
|
|
147
|
+
yield checkPreloadRule({ preloadRule, subPackages, distDir });
|
|
148
|
+
return [mainSizeInfo, ...sizeInfo];
|
|
151
149
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
exports.checkSubPackagesLegality = checkSubPackagesLegality;
|
|
151
|
+
/* zip包的工厂函数 */
|
|
152
|
+
const zipFactory = (_a) => __awaiter(void 0, [_a], void 0, function* ({ outputDir, ignore, prefix, pattern = "**/*", inputDir, type, appendFile = [], appendBuffer = [], meta, }) {
|
|
153
|
+
const zip = new zip_1.Zip({ outputDir });
|
|
154
|
+
/* 添加文件 */
|
|
155
|
+
appendFile.forEach((file) => {
|
|
156
|
+
zip.archive.file(file, {
|
|
157
|
+
name: path.basename(file),
|
|
158
|
+
prefix,
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
/* 添加文件buffer */
|
|
162
|
+
appendBuffer.forEach((item) => {
|
|
163
|
+
zip.archive.append(item.buffer, {
|
|
164
|
+
name: item.name,
|
|
165
|
+
prefix,
|
|
166
|
+
});
|
|
157
167
|
});
|
|
168
|
+
zip.archive.glob(pattern, { cwd: inputDir, ignore }, { prefix });
|
|
169
|
+
yield zip.finalize();
|
|
170
|
+
const stat = fs.statSync(outputDir);
|
|
171
|
+
return { type, zipPath: outputDir, zipSize: stat.size, root: meta.root, originSize: 0 };
|
|
158
172
|
});
|
|
159
|
-
|
|
160
|
-
yield zip.finalize();
|
|
161
|
-
const stat = fs.statSync(outputDir);
|
|
162
|
-
return { type, zipPath: outputDir, zipSize: stat.size, root: meta.root, originSize: 0 };
|
|
173
|
+
exports.zipFactory = zipFactory;
|
|
163
174
|
});
|
|
164
|
-
exports.zipFactory = zipFactory;
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
2
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
3
|
};
|
|
5
|
-
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function getProjectConfig(projectPath) {
|
|
10
|
-
const projectJsonPath = path_1.default.join(projectPath, 'project.config.json');
|
|
11
|
-
let projectJson = {};
|
|
12
|
-
try {
|
|
13
|
-
projectJson = fs_extra_1.default.readJSONSync(projectJsonPath);
|
|
4
|
+
(function (factory) {
|
|
5
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
6
|
+
var v = factory(require, exports);
|
|
7
|
+
if (v !== undefined) module.exports = v;
|
|
14
8
|
}
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
else if (typeof define === "function" && define.amd) {
|
|
10
|
+
define(["require", "exports", "path", "fs-extra"], factory);
|
|
17
11
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
exports
|
|
12
|
+
})(function (require, exports) {
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getProjectConfig = getProjectConfig;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
18
|
+
function getProjectConfig(projectPath) {
|
|
19
|
+
const projectJsonPath = path_1.default.join(projectPath, 'project.config.json');
|
|
20
|
+
let projectJson = {};
|
|
21
|
+
try {
|
|
22
|
+
projectJson = fs_extra_1.default.readJSONSync(projectJsonPath);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
// do something
|
|
26
|
+
}
|
|
27
|
+
return projectJson;
|
|
28
|
+
}
|
|
29
|
+
});
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,50 +1,59 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
2
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
3
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const crypto = require('crypto');
|
|
11
|
-
function getMd5(str) {
|
|
12
|
-
const hash = crypto.createHash('md5');
|
|
13
|
-
hash.update(str);
|
|
14
|
-
const md5 = hash.digest('hex');
|
|
15
|
-
return md5;
|
|
16
|
-
}
|
|
17
|
-
exports.getMd5 = getMd5;
|
|
18
|
-
function normalizePath(str) {
|
|
19
|
-
return str.replace(/\\/g, '/');
|
|
20
|
-
}
|
|
21
|
-
exports.normalizePath = normalizePath;
|
|
22
|
-
const hasFile = filepath => {
|
|
23
|
-
try {
|
|
24
|
-
const stat = fs_1.default.statSync(filepath);
|
|
25
|
-
return stat.isFile();
|
|
4
|
+
(function (factory) {
|
|
5
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
6
|
+
var v = factory(require, exports);
|
|
7
|
+
if (v !== undefined) module.exports = v;
|
|
26
8
|
}
|
|
27
|
-
|
|
28
|
-
|
|
9
|
+
else if (typeof define === "function" && define.amd) {
|
|
10
|
+
define(["require", "exports", "path", "fs"], factory);
|
|
29
11
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
})(function (require, exports) {
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getMd5 = getMd5;
|
|
16
|
+
exports.normalizePath = normalizePath;
|
|
17
|
+
// @ts-nocheck
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const crypto = require('crypto');
|
|
21
|
+
function getMd5(str) {
|
|
22
|
+
const hash = crypto.createHash('md5');
|
|
23
|
+
hash.update(str);
|
|
24
|
+
const md5 = hash.digest('hex');
|
|
25
|
+
return md5;
|
|
26
|
+
}
|
|
27
|
+
function normalizePath(str) {
|
|
28
|
+
return str.replace(/\\/g, '/');
|
|
29
|
+
}
|
|
30
|
+
const hasFile = filepath => {
|
|
31
|
+
try {
|
|
32
|
+
const stat = fs_1.default.statSync(filepath);
|
|
33
|
+
return stat.isFile();
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const getTsconfigPath = config => {
|
|
40
|
+
let res = '';
|
|
41
|
+
// 查询距离最近的 tsconfig.json
|
|
42
|
+
if (config.projectPath) {
|
|
43
|
+
res = path_1.default.resolve(process.cwd(), config.projectPath, 'tsconfig.json');
|
|
44
|
+
if (hasFile(res)) {
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// 查询 root 的 tsconfig.json
|
|
49
|
+
res = path_1.default.resolve(process.cwd(), 'tsconfig.json');
|
|
36
50
|
if (hasFile(res)) {
|
|
37
51
|
return res;
|
|
38
52
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
exports.default = {
|
|
48
|
-
hasFile,
|
|
49
|
-
getTsconfigPath,
|
|
50
|
-
};
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
exports.default = {
|
|
56
|
+
hasFile,
|
|
57
|
+
getTsconfigPath,
|
|
58
|
+
};
|
|
59
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare class WorkerPool {
|
|
2
|
+
workerPath: string;
|
|
3
|
+
numberOfThreads: number;
|
|
4
|
+
_queue: any[];
|
|
5
|
+
_workersById: {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
_activeWorkersById: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
11
|
+
constructor(workerPath: any, options?: {}, numberOfThreads?: any);
|
|
12
|
+
/**
|
|
13
|
+
* 检查空闲的 Worker
|
|
14
|
+
*/
|
|
15
|
+
getInactiveWorkerId(): number;
|
|
16
|
+
/**
|
|
17
|
+
* 调用 Worker 执行,目的是在指定的 Worker 里执行指定的任务
|
|
18
|
+
*/
|
|
19
|
+
runWorker(workerId: any, taskObj: any): void;
|
|
20
|
+
/**
|
|
21
|
+
* 运行线程
|
|
22
|
+
*/
|
|
23
|
+
run(data: any): Promise<unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* 销毁
|
|
26
|
+
*/
|
|
27
|
+
destroy(force?: boolean): void;
|
|
28
|
+
}
|
|
29
|
+
export default WorkerPool;
|