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
package/dist/presets/prod.js
CHANGED
|
@@ -1,80 +1,90 @@
|
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
.options({
|
|
44
|
-
sourceType: 'unambiguous',
|
|
45
|
-
presets: [
|
|
46
|
-
[
|
|
47
|
-
require.resolve('@babel/preset-typescript'),
|
|
48
|
-
{
|
|
49
|
-
allExtensions: true,
|
|
50
|
-
isTSX: true
|
|
51
|
-
}
|
|
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", "../config/constant.config"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const constant_config_1 = require("../config/constant.config");
|
|
13
|
+
// import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
|
14
|
+
const getProdConfig = (chain, options) => {
|
|
15
|
+
const { project, packSetting, otherSetting = {} } = options;
|
|
16
|
+
const { compressJs } = packSetting;
|
|
17
|
+
chain.mode('production');
|
|
18
|
+
if (!otherSetting.noJs) {
|
|
19
|
+
// 生产环境使用 babel-loader
|
|
20
|
+
if (project.appMode === 'miniprogram') {
|
|
21
|
+
chain.module
|
|
22
|
+
.rule('js')
|
|
23
|
+
.test(/\.js$/)
|
|
24
|
+
.use('js-loader')
|
|
25
|
+
.loader(require.resolve('babel-loader'))
|
|
26
|
+
.options({
|
|
27
|
+
configFile: false,
|
|
28
|
+
babelrc: false,
|
|
29
|
+
sourceType: 'unambiguous',
|
|
30
|
+
presets: [
|
|
31
|
+
[
|
|
32
|
+
require.resolve('@babel/preset-env'),
|
|
33
|
+
{
|
|
34
|
+
useBuiltIns: false,
|
|
35
|
+
corejs: {
|
|
36
|
+
version: 3,
|
|
37
|
+
proposals: true
|
|
38
|
+
},
|
|
39
|
+
shippedProposals: true,
|
|
40
|
+
targets: constant_config_1.PROD_BROWSERSLIST
|
|
41
|
+
}
|
|
42
|
+
]
|
|
52
43
|
],
|
|
53
|
-
[
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
44
|
+
plugins: [[require.resolve('@babel/plugin-transform-runtime'), { corejs: false }]]
|
|
45
|
+
});
|
|
46
|
+
chain.module.rule('js').exclude.clear();
|
|
47
|
+
chain.module
|
|
48
|
+
.rule('ts')
|
|
49
|
+
.test(/\.ts$/)
|
|
50
|
+
.use('ts-loader')
|
|
51
|
+
.loader(require.resolve('babel-loader'))
|
|
52
|
+
.options({
|
|
53
|
+
sourceType: 'unambiguous',
|
|
54
|
+
presets: [
|
|
55
|
+
[
|
|
56
|
+
require.resolve('@babel/preset-typescript'),
|
|
57
|
+
{
|
|
58
|
+
allExtensions: true,
|
|
59
|
+
isTSX: true
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
require.resolve('@babel/preset-env'),
|
|
64
|
+
{
|
|
65
|
+
useBuiltIns: false,
|
|
66
|
+
corejs: {
|
|
67
|
+
version: 3,
|
|
68
|
+
proposals: true
|
|
69
|
+
},
|
|
70
|
+
shippedProposals: true,
|
|
71
|
+
targets: constant_config_1.PROD_BROWSERSLIST
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
],
|
|
75
|
+
plugins: [[require.resolve('@babel/plugin-transform-runtime'), { corejs: false }]]
|
|
76
|
+
});
|
|
77
|
+
chain.module.rule('ts').exclude.clear();
|
|
75
78
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
79
|
+
chain.optimization.minimizer('js').use(require.resolve('terser-webpack-plugin'), [
|
|
80
|
+
{
|
|
81
|
+
terserOptions: {
|
|
82
|
+
compress: { drop_console: false }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
chain.optimization.minimize(!!compressJs);
|
|
88
|
+
};
|
|
89
|
+
exports.default = getProdConfig;
|
|
90
|
+
});
|
package/dist/sharedFs.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const SharedFs = require('xhs-mp-shared-fs');
|
|
13
|
+
let sharedFs;
|
|
14
|
+
function getFS(isThread) {
|
|
15
|
+
if (isThread) {
|
|
16
|
+
if (!sharedFs) {
|
|
17
|
+
sharedFs = new SharedFs();
|
|
18
|
+
}
|
|
19
|
+
return sharedFs;
|
|
20
|
+
}
|
|
21
|
+
return require('fs-extra');
|
|
22
|
+
}
|
|
23
|
+
exports.default = getFS;
|
|
24
|
+
});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { MPPackSetting } from "xhs-mp-pack";
|
|
1
|
+
import type { MPPackSetting, ICompileActionOptions } from "xhs-mp-pack";
|
|
2
2
|
import type { Project } from "xhs-mp-project";
|
|
3
|
-
import { FeatureReporter } from 'xhs-mp-
|
|
3
|
+
import { FeatureReporter } from 'xhs-mp-shared';
|
|
4
4
|
export declare enum ENV {
|
|
5
5
|
development = 0,
|
|
6
6
|
production = 1
|
|
@@ -47,7 +47,7 @@ export interface AppJSON {
|
|
|
47
47
|
[key: string]: string | boolean;
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
export
|
|
50
|
+
export type ICompilerConfig = ICompileActionOptions & {
|
|
51
51
|
/**
|
|
52
52
|
* 小程序入口目录
|
|
53
53
|
*/
|
|
@@ -57,56 +57,30 @@ export interface ICompilerConfig {
|
|
|
57
57
|
* 构建产物目录
|
|
58
58
|
*/
|
|
59
59
|
distDir?: string;
|
|
60
|
-
|
|
61
|
-
watch?: boolean;
|
|
62
|
-
env: ENV;
|
|
63
|
-
tsConfigPath?: string;
|
|
64
|
-
/**
|
|
65
|
-
* ext json path
|
|
66
|
-
*/
|
|
67
|
-
extJsonPath?: string;
|
|
60
|
+
enablePersistCache?: boolean;
|
|
68
61
|
cacheDirectory?: string;
|
|
69
|
-
/**
|
|
70
|
-
* 是否开启 Js 编译压缩
|
|
71
|
-
*/
|
|
72
|
-
compressJs?: boolean;
|
|
73
62
|
/**
|
|
74
63
|
* 打包是否包含 js 文件
|
|
75
64
|
*/
|
|
76
65
|
noJs?: boolean;
|
|
77
|
-
|
|
78
|
-
* dev 模式是否开启 sourcemap,默认开启
|
|
79
|
-
*/
|
|
80
|
-
enableSourcemap?: boolean;
|
|
66
|
+
mpUploadOptions?: any;
|
|
81
67
|
/**
|
|
82
68
|
* 服务端口
|
|
83
69
|
*/
|
|
84
70
|
port?: number;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
enableVDom?: boolean;
|
|
88
|
-
mpUploadOptions?: any;
|
|
89
|
-
}
|
|
90
|
-
type CliPick = 'projectPath' | 'distDir' | 'watch' | 'tsConfigPath' | 'extJsonPath' | 'cacheDirectory' | 'compressJs' | 'enableSourcemap' | 'enableV1' | 'enableV2' | 'enableVDom' | 'mpUploadOptions';
|
|
71
|
+
};
|
|
72
|
+
type CliPick = 'action' | 'projectPath' | 'distDir' | 'tsConfigPath' | 'cacheDirectory' | 'compressCss' | 'compressJs' | 'enableSourcemap' | 'appendSourcemapComment' | 'runInServiceSandbox' | 'enableV1' | 'enableV2' | 'enableVDom' | 'mpUploadOptions';
|
|
91
73
|
export interface IStart extends Pick<ICompilerConfig, CliPick> {
|
|
92
74
|
packMode?: 'webpack' | 'mp-pack';
|
|
93
|
-
/**
|
|
94
|
-
* 调用的能力,dev 还是 build
|
|
95
|
-
*/
|
|
96
|
-
action: 'dev' | 'build';
|
|
97
|
-
/**
|
|
98
|
-
* 是否启动dev-server
|
|
99
|
-
*/
|
|
100
|
-
enableDevServer?: boolean;
|
|
101
75
|
/**
|
|
102
76
|
* 每次构建完毕的回调函数
|
|
103
77
|
*/
|
|
104
78
|
callback?: () => void;
|
|
105
|
-
/**
|
|
106
|
-
* 构建产物目录
|
|
107
|
-
*/
|
|
108
|
-
distDir?: string;
|
|
109
79
|
platform?: 'wx' | 'xhs';
|
|
80
|
+
/**
|
|
81
|
+
* 是否启动dev-server
|
|
82
|
+
*/
|
|
83
|
+
enableDevServer?: boolean;
|
|
110
84
|
/**
|
|
111
85
|
* 服务端口
|
|
112
86
|
*/
|
package/dist/types/index.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
CodePackageMode
|
|
13
|
-
|
|
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"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CodePackageMode = exports.ENV = void 0;
|
|
13
|
+
var ENV;
|
|
14
|
+
(function (ENV) {
|
|
15
|
+
ENV[ENV["development"] = 0] = "development";
|
|
16
|
+
ENV[ENV["production"] = 1] = "production";
|
|
17
|
+
})(ENV || (exports.ENV = ENV = {}));
|
|
18
|
+
var CodePackageMode;
|
|
19
|
+
(function (CodePackageMode) {
|
|
20
|
+
CodePackageMode["default"] = "default";
|
|
21
|
+
CodePackageMode["requiredComponents"] = "requiredComponents";
|
|
22
|
+
})(CodePackageMode || (exports.CodePackageMode = CodePackageMode = {}));
|
|
23
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { APM, FeatureReporter } from 'xhs-mp-
|
|
1
|
+
import { APM, FeatureReporter } from 'xhs-mp-shared';
|
|
2
2
|
import { Project } from 'xhs-mp-project';
|
|
3
|
-
import type { ICompileAndZipOptions } from '
|
|
3
|
+
import type { ICompileAndZipOptions } from '..';
|
|
4
4
|
/**
|
|
5
5
|
* 上报过程中,除去 WebComponent 因为标签种类有很多需要上报多次之外,其余的项目维度上均只上报一次
|
|
6
6
|
*/
|
|
@@ -12,7 +12,9 @@ declare class Reporter implements FeatureReporter.IReporter {
|
|
|
12
12
|
reportMlWebComponent(value: string): void;
|
|
13
13
|
reportJSONComponent(name: FeatureReporter.JSONComponent): void;
|
|
14
14
|
reportStyleIsolation(value: string): void;
|
|
15
|
-
|
|
15
|
+
reportAppJSON(name: FeatureReporter.AppExtJSON): void;
|
|
16
|
+
reportExtJSON(name: FeatureReporter.AppExtJSON): void;
|
|
17
|
+
reportDevelopMode(name: FeatureReporter.DevelopMode): void;
|
|
16
18
|
}
|
|
17
19
|
export declare function createReporter(project: Project, option: ICompileAndZipOptions): Reporter | undefined;
|
|
18
20
|
export {};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
(function (factory) {
|
|
11
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
12
|
+
var v = factory(require, exports);
|
|
13
|
+
if (v !== undefined) module.exports = v;
|
|
14
|
+
}
|
|
15
|
+
else if (typeof define === "function" && define.amd) {
|
|
16
|
+
define(["require", "exports", "path", "lodash", "xhs-mp-shared", "fs-extra"], factory);
|
|
17
|
+
}
|
|
18
|
+
})(function (require, exports) {
|
|
19
|
+
"use strict";
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.createReporter = createReporter;
|
|
22
|
+
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const lodash_1 = require("lodash");
|
|
24
|
+
const xhs_mp_shared_1 = require("xhs-mp-shared");
|
|
25
|
+
const fs_extra_1 = require("fs-extra");
|
|
26
|
+
const pkg = require('../../package.json');
|
|
27
|
+
function debug(...data) {
|
|
28
|
+
// return process.send?.(JSON.stringify({ method: 'debugger', data }))
|
|
29
|
+
}
|
|
30
|
+
const cacheMap = {};
|
|
31
|
+
function onceByParams(target, key, descriptor) {
|
|
32
|
+
const originalMethod = descriptor.value;
|
|
33
|
+
descriptor.value = function (...args) {
|
|
34
|
+
try {
|
|
35
|
+
const argsStr = JSON.stringify(args);
|
|
36
|
+
if (cacheMap[key + argsStr])
|
|
37
|
+
return;
|
|
38
|
+
cacheMap[key + argsStr] = true;
|
|
39
|
+
debug(key, ...args);
|
|
40
|
+
return originalMethod.apply(this, args);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error(`call ${key} error`, error.message);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return descriptor;
|
|
47
|
+
}
|
|
48
|
+
// const APMKEY = 'test_cli_apm'
|
|
49
|
+
const APMKEY = 'xhsmp_compiler_basic_ability';
|
|
50
|
+
/**
|
|
51
|
+
* 上报过程中,除去 WebComponent 因为标签种类有很多需要上报多次之外,其余的项目维度上均只上报一次
|
|
52
|
+
*/
|
|
53
|
+
class Reporter {
|
|
54
|
+
constructor(apm) {
|
|
55
|
+
this.apm = apm;
|
|
56
|
+
}
|
|
57
|
+
reportThirdFramework(name) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
(_b = (_a = this.apm) === null || _a === void 0 ? void 0 : _a.report) === null || _b === void 0 ? void 0 : _b.call(_a, APMKEY, {
|
|
60
|
+
type: xhs_mp_shared_1.FeatureReporter.MODULE.thirdFramework,
|
|
61
|
+
name,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
reportMlFeature(feature) {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
(_b = (_a = this.apm) === null || _a === void 0 ? void 0 : _a.report) === null || _b === void 0 ? void 0 : _b.call(_a, APMKEY, {
|
|
67
|
+
type: xhs_mp_shared_1.FeatureReporter.MODULE.ml,
|
|
68
|
+
name: feature
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
reportMlWebComponent(value) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
(_b = (_a = this.apm) === null || _a === void 0 ? void 0 : _a.report) === null || _b === void 0 ? void 0 : _b.call(_a, APMKEY, {
|
|
74
|
+
type: xhs_mp_shared_1.FeatureReporter.MODULE.ml,
|
|
75
|
+
name: xhs_mp_shared_1.FeatureReporter.ML.WebComponent,
|
|
76
|
+
value,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
// 在reporter 创建阶段即可根据传入project信息进行上报
|
|
80
|
+
reportJSONComponent(name) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
(_b = (_a = this.apm) === null || _a === void 0 ? void 0 : _a.report) === null || _b === void 0 ? void 0 : _b.call(_a, APMKEY, {
|
|
83
|
+
type: xhs_mp_shared_1.FeatureReporter.MODULE.componentJSON,
|
|
84
|
+
name,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
reportStyleIsolation(value) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
(_b = (_a = this.apm) === null || _a === void 0 ? void 0 : _a.report) === null || _b === void 0 ? void 0 : _b.call(_a, APMKEY, {
|
|
90
|
+
type: xhs_mp_shared_1.FeatureReporter.MODULE.componentJSON,
|
|
91
|
+
name: xhs_mp_shared_1.FeatureReporter.JSONComponent.styleIsolation,
|
|
92
|
+
value,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
reportAppJSON(name) {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
(_b = (_a = this.apm) === null || _a === void 0 ? void 0 : _a.report) === null || _b === void 0 ? void 0 : _b.call(_a, APMKEY, {
|
|
98
|
+
type: xhs_mp_shared_1.FeatureReporter.MODULE.appJSON,
|
|
99
|
+
name,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
reportExtJSON(name) {
|
|
103
|
+
var _a, _b;
|
|
104
|
+
(_b = (_a = this.apm) === null || _a === void 0 ? void 0 : _a.report) === null || _b === void 0 ? void 0 : _b.call(_a, APMKEY, {
|
|
105
|
+
type: xhs_mp_shared_1.FeatureReporter.MODULE.extJSON,
|
|
106
|
+
name,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
reportDevelopMode(name) {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
(_b = (_a = this.apm) === null || _a === void 0 ? void 0 : _a.report) === null || _b === void 0 ? void 0 : _b.call(_a, APMKEY, {
|
|
112
|
+
type: xhs_mp_shared_1.FeatureReporter.MODULE.developMode,
|
|
113
|
+
name,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
__decorate([
|
|
118
|
+
onceByParams
|
|
119
|
+
], Reporter.prototype, "reportThirdFramework", null);
|
|
120
|
+
__decorate([
|
|
121
|
+
onceByParams
|
|
122
|
+
], Reporter.prototype, "reportMlFeature", null);
|
|
123
|
+
__decorate([
|
|
124
|
+
onceByParams
|
|
125
|
+
], Reporter.prototype, "reportMlWebComponent", null);
|
|
126
|
+
__decorate([
|
|
127
|
+
onceByParams
|
|
128
|
+
], Reporter.prototype, "reportJSONComponent", null);
|
|
129
|
+
__decorate([
|
|
130
|
+
onceByParams
|
|
131
|
+
], Reporter.prototype, "reportStyleIsolation", null);
|
|
132
|
+
__decorate([
|
|
133
|
+
onceByParams
|
|
134
|
+
], Reporter.prototype, "reportAppJSON", null);
|
|
135
|
+
__decorate([
|
|
136
|
+
onceByParams
|
|
137
|
+
], Reporter.prototype, "reportExtJSON", null);
|
|
138
|
+
__decorate([
|
|
139
|
+
onceByParams
|
|
140
|
+
], Reporter.prototype, "reportDevelopMode", null);
|
|
141
|
+
function createReporter(project, option) {
|
|
142
|
+
var _a, _b, _c;
|
|
143
|
+
try {
|
|
144
|
+
const app_id = option === null || option === void 0 ? void 0 : option.upload_app_id;
|
|
145
|
+
// 上传时有version
|
|
146
|
+
const version = (_a = option === null || option === void 0 ? void 0 : option.pkgInfo) === null || _a === void 0 ? void 0 : _a.version;
|
|
147
|
+
if (!app_id || !version) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const apm = new xhs_mp_shared_1.APM(`mp-compiler-${pkg.version}`);
|
|
151
|
+
(_b = apm === null || apm === void 0 ? void 0 : apm.setContext) === null || _b === void 0 ? void 0 : _b.call(apm, app_id, {
|
|
152
|
+
app_id,
|
|
153
|
+
app_name: app_id,
|
|
154
|
+
third_name: app_id,
|
|
155
|
+
page_key: '0',
|
|
156
|
+
app_env: 0,
|
|
157
|
+
app_type: 0,
|
|
158
|
+
bundle_version: version,
|
|
159
|
+
base_version: ((_c = project.projectJsonContent) === null || _c === void 0 ? void 0 : _c.libVersion) || ''
|
|
160
|
+
});
|
|
161
|
+
const reporter = new Reporter(apm);
|
|
162
|
+
function reportAppJSON() {
|
|
163
|
+
var _a, _b, _c, _d, _e;
|
|
164
|
+
// 分包
|
|
165
|
+
if (!(0, lodash_1.isEmpty)(((_a = project.appJsonContent) === null || _a === void 0 ? void 0 : _a.subPackages) || ((_b = project.appJsonContent) === null || _b === void 0 ? void 0 : _b.subpackages))) {
|
|
166
|
+
reporter.reportAppJSON(xhs_mp_shared_1.FeatureReporter.AppExtJSON.subPackages);
|
|
167
|
+
}
|
|
168
|
+
// tabbar
|
|
169
|
+
if (!(0, lodash_1.isEmpty)((_c = project.appJsonContent) === null || _c === void 0 ? void 0 : _c.tabBar)) {
|
|
170
|
+
reporter.reportAppJSON(xhs_mp_shared_1.FeatureReporter.AppExtJSON.tabBar);
|
|
171
|
+
}
|
|
172
|
+
// 按需注入
|
|
173
|
+
if ((_d = project.appJsonContent) === null || _d === void 0 ? void 0 : _d.lazyCodeLoading) {
|
|
174
|
+
reporter.reportAppJSON(xhs_mp_shared_1.FeatureReporter.AppExtJSON.lazyCodeLoading);
|
|
175
|
+
}
|
|
176
|
+
// 预载
|
|
177
|
+
if (!(0, lodash_1.isEmpty)((_e = project.appJsonContent) === null || _e === void 0 ? void 0 : _e.preloadRule)) {
|
|
178
|
+
reporter.reportAppJSON(xhs_mp_shared_1.FeatureReporter.AppExtJSON.preloadRule);
|
|
179
|
+
}
|
|
180
|
+
const componentsMap = project.getComponentsMap();
|
|
181
|
+
if (!(0, lodash_1.isEmpty)(componentsMap)) {
|
|
182
|
+
// debug(componentsMap)
|
|
183
|
+
for (let key in componentsMap) {
|
|
184
|
+
const style = componentsMap[key].styleIsolation;
|
|
185
|
+
// 样式隔离类型
|
|
186
|
+
if (style) {
|
|
187
|
+
reporter.reportStyleIsolation(style);
|
|
188
|
+
}
|
|
189
|
+
// 占位组件
|
|
190
|
+
const componentPlaceholder = componentsMap[key].componentPlaceholder;
|
|
191
|
+
if (!(0, lodash_1.isEmpty)(componentPlaceholder)) {
|
|
192
|
+
reporter.reportJSONComponent(xhs_mp_shared_1.FeatureReporter.JSONComponent.componentPlaceholder);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function reportExtJSON() {
|
|
198
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
199
|
+
if ((0, lodash_1.isEmpty)(project.extJsonContent) || !((_a = project.extJsonContent) === null || _a === void 0 ? void 0 : _a.extEnable)) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// pages
|
|
203
|
+
if (!(0, lodash_1.isEmpty)((_b = project.extJsonContent) === null || _b === void 0 ? void 0 : _b.pages)) {
|
|
204
|
+
reporter.reportExtJSON(xhs_mp_shared_1.FeatureReporter.AppExtJSON.pages);
|
|
205
|
+
}
|
|
206
|
+
// 分包
|
|
207
|
+
if (!(0, lodash_1.isEmpty)(((_c = project.extJsonContent) === null || _c === void 0 ? void 0 : _c.subPackages) || ((_d = project.extJsonContent) === null || _d === void 0 ? void 0 : _d.subpackages))) {
|
|
208
|
+
reporter.reportExtJSON(xhs_mp_shared_1.FeatureReporter.AppExtJSON.subPackages);
|
|
209
|
+
}
|
|
210
|
+
// tabbar
|
|
211
|
+
if (!(0, lodash_1.isEmpty)((_e = project.extJsonContent) === null || _e === void 0 ? void 0 : _e.tabBar)) {
|
|
212
|
+
reporter.reportExtJSON(xhs_mp_shared_1.FeatureReporter.AppExtJSON.tabBar);
|
|
213
|
+
}
|
|
214
|
+
// extPages
|
|
215
|
+
if (!(0, lodash_1.isEmpty)((_f = project.extJsonContent) === null || _f === void 0 ? void 0 : _f.extPages)) {
|
|
216
|
+
reporter.reportExtJSON(xhs_mp_shared_1.FeatureReporter.AppExtJSON.extPages);
|
|
217
|
+
}
|
|
218
|
+
if ((_g = project.extJsonContent) === null || _g === void 0 ? void 0 : _g.extEnable) {
|
|
219
|
+
// 开发模式
|
|
220
|
+
reporter.reportDevelopMode(((_h = project.extJsonContent) === null || _h === void 0 ? void 0 : _h.directCommit)
|
|
221
|
+
? xhs_mp_shared_1.FeatureReporter.DevelopMode.customDevelopment
|
|
222
|
+
: xhs_mp_shared_1.FeatureReporter.DevelopMode.templateDevelopment);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
reportAppJSON();
|
|
226
|
+
reportExtJSON();
|
|
227
|
+
// 统计taro版本
|
|
228
|
+
const vendor = path_1.default.join(project.miniprogramDir, 'vendors.js.LICENSE.txt');
|
|
229
|
+
const taro = path_1.default.join(project.miniprogramDir, 'taro.js');
|
|
230
|
+
if ((0, fs_extra_1.pathExistsSync)(taro) && (0, fs_extra_1.pathExistsSync)(vendor)) {
|
|
231
|
+
const txt = (0, fs_extra_1.readFileSync)(vendor, { encoding: 'utf-8' });
|
|
232
|
+
if (txt.includes('React') || txt.includes('react')) {
|
|
233
|
+
reporter.reportThirdFramework(xhs_mp_shared_1.FeatureReporter.ThirdFramework.taroReact);
|
|
234
|
+
}
|
|
235
|
+
else if (txt.includes('@vue') || txt.includes('Vue')) {
|
|
236
|
+
reporter.reportThirdFramework(xhs_mp_shared_1.FeatureReporter.ThirdFramework.taroVue);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return reporter;
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
debug('[create reporter error]');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IPresetOptions } from '../types';
|
|
2
|
+
export declare const getCacheConfig: (cacheDirectory: any, options: IPresetOptions) => {
|
|
3
|
+
cache?: undefined;
|
|
4
|
+
snapshot?: undefined;
|
|
5
|
+
} | {
|
|
6
|
+
cache: {
|
|
7
|
+
type: string;
|
|
8
|
+
cacheDirectory: any;
|
|
9
|
+
};
|
|
10
|
+
snapshot: {
|
|
11
|
+
buildDependencies: {
|
|
12
|
+
hash: boolean;
|
|
13
|
+
timestamp: boolean;
|
|
14
|
+
};
|
|
15
|
+
module: {
|
|
16
|
+
hash: boolean;
|
|
17
|
+
timestamp: boolean;
|
|
18
|
+
};
|
|
19
|
+
resolve: {
|
|
20
|
+
hash: boolean;
|
|
21
|
+
timestamp: boolean;
|
|
22
|
+
};
|
|
23
|
+
resolveBuildDependencies: {
|
|
24
|
+
hash: boolean;
|
|
25
|
+
timestamp: boolean;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
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", "../config/constant.config"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getCacheConfig = void 0;
|
|
13
|
+
const constant_config_1 = require("../config/constant.config");
|
|
14
|
+
const getCacheConfig = (cacheDirectory, options) => {
|
|
15
|
+
const { packMode } = options;
|
|
16
|
+
if (packMode === constant_config_1.PACK_MODE.WEBPACK) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
const { enablePersistCache } = options.packSetting;
|
|
20
|
+
if (!enablePersistCache) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
cache: {
|
|
25
|
+
type: 'filesystem',
|
|
26
|
+
cacheDirectory
|
|
27
|
+
},
|
|
28
|
+
snapshot: {
|
|
29
|
+
buildDependencies: {
|
|
30
|
+
hash: true,
|
|
31
|
+
timestamp: true
|
|
32
|
+
},
|
|
33
|
+
module: {
|
|
34
|
+
hash: true,
|
|
35
|
+
timestamp: true
|
|
36
|
+
},
|
|
37
|
+
resolve: {
|
|
38
|
+
hash: true,
|
|
39
|
+
timestamp: true
|
|
40
|
+
},
|
|
41
|
+
resolveBuildDependencies: {
|
|
42
|
+
hash: true,
|
|
43
|
+
timestamp: true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.getCacheConfig = getCacheConfig;
|
|
49
|
+
});
|