xhs-mp-compiler-cli 2.0.33-beta.7 → 2.0.33-beta.8
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 +1 -53
- package/dist/bin/xhs-mp-cli-dev.js +1 -56
- package/dist/bin/xhs-mp-cli.js +1 -24
- package/dist/compiler.js +1 -372
- package/dist/compilerImpl.js +1 -284
- package/dist/compilerManager.js +1 -488
- package/dist/config/constant.config.js +1 -82
- package/dist/config/dir.config.js +1 -26
- package/dist/index.js +1 -27
- package/dist/packs/index.js +1 -35
- package/dist/packs/mp-pack/index.js +1 -39
- package/dist/packs/webpack/dev-server/index.js +1 -71
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +1 -41
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +1 -30
- package/dist/packs/webpack/index.js +1 -97
- package/dist/packs/webpack/webpack.js +1 -91
- package/dist/presets/common.js +1 -75
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +1 -46
- package/dist/presets/configs/minigame/assets/index.js +1 -75
- package/dist/presets/configs/minigame/service/index.js +1 -54
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +1 -41
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +1 -73
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +1 -43
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +1 -125
- package/dist/presets/configs/miniprogram/assets/index.js +1 -62
- package/dist/presets/configs/miniprogram/render/component.js +1 -55
- package/dist/presets/configs/miniprogram/render/index.js +1 -109
- package/dist/presets/configs/miniprogram/render/render.js +1 -59
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +1 -75
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +1 -185
- package/dist/presets/configs/miniprogram/render/sketch.js +1 -45
- package/dist/presets/configs/miniprogram/service/index.js +1 -119
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +1 -1
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +1 -69
- package/dist/presets/configs/miniprogram/service/sanbox.js +1 -1
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +1 -234
- package/dist/presets/dev.js +1 -52
- package/dist/presets/index.js +1 -89
- package/dist/presets/loaders/mg-entry-loader.js +1 -36
- package/dist/presets/loaders/mini-style-loader.js +1 -51
- package/dist/presets/loaders/mp-entry-loader.js +1 -215
- package/dist/presets/loaders/string-loader.js +1 -5
- package/dist/presets/loaders/wxss-loader.js +1 -97
- package/dist/presets/plugins/InjectorPlugin.js +1 -25
- package/dist/presets/plugins/SourceMapDevToolPlugin.js +1 -23
- package/dist/presets/prod.js +1 -91
- package/dist/sharedFs.js +1 -24
- package/dist/types/index.js +1 -23
- package/dist/utils/apm.js +1 -230
- package/dist/utils/cache.js +1 -49
- package/dist/utils/common.js +1 -30
- package/dist/utils/depenedHelper.js +1 -82
- package/dist/utils/file.js +1 -86
- package/dist/utils/loader-utils.js +1 -39
- package/dist/utils/postcssRpx2Vw.js +1 -46
- package/dist/utils/project.js +1 -153
- package/dist/utils/projectConfig.js +1 -28
- package/dist/utils/utils.js +1 -56
- package/dist/utils/workerPool.js +1 -90
- package/dist/utils/zip.js +1 -283
- package/package.json +12 -12
|
@@ -1,54 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __importDefault = (
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
(function (factory) {
|
|
6
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
-
var v = factory(require, exports);
|
|
8
|
-
if (v !== undefined) module.exports = v;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof define === "function" && define.amd) {
|
|
11
|
-
define(["require", "exports", "commander", "path", "../packs"], factory);
|
|
12
|
-
}
|
|
13
|
-
})(function (require, exports) {
|
|
14
|
-
"use strict";
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const commander_1 = require("commander");
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const packs_1 = require("../packs");
|
|
19
|
-
const commander = new commander_1.Command();
|
|
20
|
-
commander.usage('[options]').option('-d, --mpDir <path>', 'set workdir [default: ./]');
|
|
21
|
-
commander.usage('[options]').option('-p, --platform <string>', 'set platform [default: xhs]');
|
|
22
|
-
commander.usage('[options]').option('-l, --lite <string>', '轻量编译器');
|
|
23
|
-
commander.usage('[options]').option('-c, --compressJs <boolean>', 'compressJs');
|
|
24
|
-
commander.usage('[options]').option('-v1, --enableV1 <boolean>', 'package v1');
|
|
25
|
-
commander.usage('[options]').option('-v2, --enableV2 <boolean>', 'package v2');
|
|
26
|
-
commander.usage('[options]').option('-vdom, --enableVDom <boolean>', 'vdom 架构支持');
|
|
27
|
-
commander.parse(process.argv);
|
|
28
|
-
const projectPath = commander.opts().mpDir ? path_1.default.resolve(commander.opts().mpDir) : process.cwd();
|
|
29
|
-
const platform = commander.opts().platform ? commander.opts().platform : 'xhs';
|
|
30
|
-
const enableV1 = commander.opts().enableV1 === "true";
|
|
31
|
-
const enableV2 = commander.opts().enableV2 === "true";
|
|
32
|
-
const enableVDom = commander.opts().enableVDom === "true";
|
|
33
|
-
const compressJs = commander.opts().compressJs === "true";
|
|
34
|
-
const projectPacker = (0, packs_1.createPacker)({
|
|
35
|
-
projectPath,
|
|
36
|
-
action: 'build',
|
|
37
|
-
platform,
|
|
38
|
-
compressJs,
|
|
39
|
-
enableSourcemap: false,
|
|
40
|
-
enableV1,
|
|
41
|
-
enableV2,
|
|
42
|
-
enableVDom,
|
|
43
|
-
packMode: 'webpack',
|
|
44
|
-
});
|
|
45
|
-
projectPacker.on('buildInfo', data => {
|
|
46
|
-
if (data.resource) {
|
|
47
|
-
console.log(`资源编译:${data.resource}`);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
projectPacker.build((err, stats) => {
|
|
51
|
-
console.log('编译完成');
|
|
52
|
-
console.log(stats.toString({ warnings: true, errors: true, all: false }));
|
|
53
|
-
});
|
|
54
|
-
});
|
|
2
|
+
var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","commander","path","../packs"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const commander_1=require("commander"),path_1=__importDefault(require("path")),packs_1=require("../packs"),commander=new commander_1.Command;commander.usage("[options]").option("-d, --mpDir <path>","set workdir [default: ./]"),commander.usage("[options]").option("-p, --platform <string>","set platform [default: xhs]"),commander.usage("[options]").option("-l, --lite <string>","轻量编译器"),commander.usage("[options]").option("-c, --compressJs <boolean>","compressJs"),commander.usage("[options]").option("-v1, --enableV1 <boolean>","package v1"),commander.usage("[options]").option("-v2, --enableV2 <boolean>","package v2"),commander.usage("[options]").option("-vdom, --enableVDom <boolean>","vdom 架构支持"),commander.parse(process.argv);const projectPath=commander.opts().mpDir?path_1.default.resolve(commander.opts().mpDir):process.cwd(),platform=commander.opts().platform?commander.opts().platform:"xhs",enableV1="true"===commander.opts().enableV1,enableV2="true"===commander.opts().enableV2,enableVDom="true"===commander.opts().enableVDom,compressJs="true"===commander.opts().compressJs,projectPacker=(0,packs_1.createPacker)({projectPath:projectPath,action:"build",platform:platform,compressJs:compressJs,enableSourcemap:!1,enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom,packMode:"webpack"});projectPacker.on("buildInfo",(data=>{data.resource&&console.log(`资源编译:${data.resource}`)})),projectPacker.build(((err,stats)=>{console.log("编译完成"),console.log(stats.toString({warnings:!0,errors:!0,all:!1}))}))}));
|
|
@@ -1,57 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __importDefault = (
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
(function (factory) {
|
|
6
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
-
var v = factory(require, exports);
|
|
8
|
-
if (v !== undefined) module.exports = v;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof define === "function" && define.amd) {
|
|
11
|
-
define(["require", "exports", "commander", "path", "../packs"], factory);
|
|
12
|
-
}
|
|
13
|
-
})(function (require, exports) {
|
|
14
|
-
"use strict";
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const commander_1 = require("commander");
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const packs_1 = require("../packs");
|
|
19
|
-
const commander = new commander_1.Command();
|
|
20
|
-
commander.usage('[options]').option('-d, --mpDir <path>', 'set workdir [default: ./]');
|
|
21
|
-
commander.usage('[options]').option('-p, --platform <string>', 'set platform [default: xhs]');
|
|
22
|
-
commander.usage('[options]').option('-P, --port <string>', 'set dev server port [default: 1388]');
|
|
23
|
-
commander.usage('[options]').option('-l, --lite <string>', 'lite compiler');
|
|
24
|
-
commander.usage('[options]').option('-o, --out <string>', '是否输出内容');
|
|
25
|
-
commander.usage('[options]').option('-v1, --enableV1 <boolean>', 'package v1');
|
|
26
|
-
commander.usage('[options]').option('-v2, --enableV2 <boolean>', 'package v2');
|
|
27
|
-
commander.usage('[options]').option('-vdom, --enableVDom <boolean>', 'vdom 架构支持');
|
|
28
|
-
commander.parse(process.argv);
|
|
29
|
-
const projectPath = commander.opts().mpDir ? path_1.default.resolve(commander.opts().mpDir) : process.cwd();
|
|
30
|
-
const platform = commander.opts().platform ? commander.opts().platform : 'xhs';
|
|
31
|
-
const devServerPort = commander.opts().port ? commander.opts().port : 1388;
|
|
32
|
-
const out = commander.opts().out === "true";
|
|
33
|
-
const enableV1 = commander.opts().enableV1 === "true";
|
|
34
|
-
const enableV2 = commander.opts().enableV2 === "true";
|
|
35
|
-
const enableVDom = commander.opts().enableVDom === "true";
|
|
36
|
-
const projectPacker = (0, packs_1.createPacker)({
|
|
37
|
-
projectPath,
|
|
38
|
-
action: 'dev',
|
|
39
|
-
enableDevServer: true,
|
|
40
|
-
platform,
|
|
41
|
-
compressJs: false,
|
|
42
|
-
devServerPort,
|
|
43
|
-
enableSourcemap: true,
|
|
44
|
-
enableV1,
|
|
45
|
-
enableV2,
|
|
46
|
-
enableVDom,
|
|
47
|
-
packMode: 'webpack',
|
|
48
|
-
});
|
|
49
|
-
projectPacker.on('buildInfo', data => {
|
|
50
|
-
if (data.resource) {
|
|
51
|
-
console.log(`资源编译:${data.resource}`);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
projectPacker.watch({}, (err, stats) => {
|
|
55
|
-
console.log(stats.toString({ warnings: true, errors: true, all: false }));
|
|
56
|
-
});
|
|
57
|
-
});
|
|
2
|
+
var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","commander","path","../packs"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const commander_1=require("commander"),path_1=__importDefault(require("path")),packs_1=require("../packs"),commander=new commander_1.Command;commander.usage("[options]").option("-d, --mpDir <path>","set workdir [default: ./]"),commander.usage("[options]").option("-p, --platform <string>","set platform [default: xhs]"),commander.usage("[options]").option("-P, --port <string>","set dev server port [default: 1388]"),commander.usage("[options]").option("-l, --lite <string>","lite compiler"),commander.usage("[options]").option("-o, --out <string>","是否输出内容"),commander.usage("[options]").option("-v1, --enableV1 <boolean>","package v1"),commander.usage("[options]").option("-v2, --enableV2 <boolean>","package v2"),commander.usage("[options]").option("-vdom, --enableVDom <boolean>","vdom 架构支持"),commander.parse(process.argv);const projectPath=commander.opts().mpDir?path_1.default.resolve(commander.opts().mpDir):process.cwd(),platform=commander.opts().platform?commander.opts().platform:"xhs",devServerPort=commander.opts().port?commander.opts().port:1388,enableV1=(commander.opts().out,"true"===commander.opts().enableV1),enableV2="true"===commander.opts().enableV2,enableVDom="true"===commander.opts().enableVDom,projectPacker=(0,packs_1.createPacker)({projectPath:projectPath,action:"dev",enableDevServer:!0,platform:platform,compressJs:!1,devServerPort:devServerPort,enableSourcemap:!0,enableV1:enableV1,enableV2:enableV2,enableVDom:enableVDom,packMode:"webpack"});projectPacker.on("buildInfo",(data=>{data.resource&&console.log(`资源编译:${data.resource}`)})),projectPacker.watch({},((err,stats)=>{console.log(stats.toString({warnings:!0,errors:!0,all:!1}))}))}));
|
package/dist/bin/xhs-mp-cli.js
CHANGED
|
@@ -1,25 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __importDefault
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
(function (factory) {
|
|
6
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
-
var v = factory(require, exports);
|
|
8
|
-
if (v !== undefined) module.exports = v;
|
|
9
|
-
}
|
|
10
|
-
else if (typeof define === "function" && define.amd) {
|
|
11
|
-
define(["require", "exports", "commander", "../../package.json"], factory);
|
|
12
|
-
}
|
|
13
|
-
})(function (require, exports) {
|
|
14
|
-
"use strict";
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const commander_1 = require("commander");
|
|
17
|
-
const package_json_1 = __importDefault(require("../../package.json"));
|
|
18
|
-
const commander = new commander_1.Command();
|
|
19
|
-
commander
|
|
20
|
-
.version(package_json_1.default.version)
|
|
21
|
-
.usage('<command> [options]')
|
|
22
|
-
.command('dev', '启动开发服务')
|
|
23
|
-
.command('build', '打包小程序')
|
|
24
|
-
.parse(process.argv);
|
|
25
|
-
});
|
|
2
|
+
var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","commander","../../package.json"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const commander_1=require("commander"),package_json_1=__importDefault(require("../../package.json"));(new commander_1.Command).version(package_json_1.default.version).usage("<command> [options]").command("dev","启动开发服务").command("build","打包小程序").parse(process.argv)}));
|
package/dist/compiler.js
CHANGED
|
@@ -1,372 +1 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
(function (factory) {
|
|
14
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
15
|
-
var v = factory(require, exports);
|
|
16
|
-
if (v !== undefined) module.exports = v;
|
|
17
|
-
}
|
|
18
|
-
else if (typeof define === "function" && define.amd) {
|
|
19
|
-
define(["require", "exports", "stream", "fs-extra", "./config/constant.config", "xhs-mp-workerpool"], factory);
|
|
20
|
-
}
|
|
21
|
-
})(function (require, exports) {
|
|
22
|
-
"use strict";
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.prepareDevPool = exports.BuildCompiler = exports.WebPackDevCompiler = exports.MPPackDevCompiler = exports.AbstractCompiler = void 0;
|
|
25
|
-
exports.getProjectCompilerClass = getProjectCompilerClass;
|
|
26
|
-
const stream_1 = require("stream");
|
|
27
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
28
|
-
const constant_config_1 = require("./config/constant.config");
|
|
29
|
-
const xhs_mp_workerpool_1 = __importDefault(require("xhs-mp-workerpool"));
|
|
30
|
-
let preparedDevPool = null;
|
|
31
|
-
class AbstractCompiler extends stream_1.EventEmitter {
|
|
32
|
-
constructor(opts, args) {
|
|
33
|
-
super();
|
|
34
|
-
this.workerType = 'process';
|
|
35
|
-
this.call = (method, data, options) => {
|
|
36
|
-
data = Object.assign(Object.assign({}, (this.compilerOpts || {})), data);
|
|
37
|
-
return this.pool.exec(method, [data], options);
|
|
38
|
-
};
|
|
39
|
-
this.compilerOpts = opts;
|
|
40
|
-
this.logger = args.logger || console;
|
|
41
|
-
this.workerType = args.workerType || 'process';
|
|
42
|
-
}
|
|
43
|
-
get pool() {
|
|
44
|
-
if (!this._pool) {
|
|
45
|
-
this.makePoolReady();
|
|
46
|
-
}
|
|
47
|
-
return this._pool;
|
|
48
|
-
}
|
|
49
|
-
set pool(val) {
|
|
50
|
-
this._pool = val;
|
|
51
|
-
}
|
|
52
|
-
static prepareDevPool() {
|
|
53
|
-
preparedDevPool = AbstractCompiler.createPool('web', {
|
|
54
|
-
minWorkers: 1,
|
|
55
|
-
maxWorkers: 1
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
static createPool(workerType, poolOpts = {}, processArgs = {}) {
|
|
59
|
-
let workerThreadOpts = {};
|
|
60
|
-
let forkOpts = {};
|
|
61
|
-
let workerOpts = {};
|
|
62
|
-
if (workerType === 'process') {
|
|
63
|
-
forkOpts = AbstractCompiler.createProcessOps(processArgs);
|
|
64
|
-
}
|
|
65
|
-
const pool = xhs_mp_workerpool_1.default.pool(__dirname + '/compilerImpl.js', Object.assign({ workerType: workerType, workerThreadOpts,
|
|
66
|
-
forkOpts,
|
|
67
|
-
workerOpts }, poolOpts));
|
|
68
|
-
let messageBuffers = [];
|
|
69
|
-
const handlerWorker = workerIns => {
|
|
70
|
-
workerIns.worker.on('message', payload => {
|
|
71
|
-
if (payload === null || payload === void 0 ? void 0 : payload.customMessage) {
|
|
72
|
-
if (!pool.emitWorkerMessage) {
|
|
73
|
-
messageBuffers.push(payload);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (messageBuffers.length) {
|
|
77
|
-
messageBuffers.forEach(payload => {
|
|
78
|
-
pool === null || pool === void 0 ? void 0 : pool.emitWorkerMessage(payload.event, payload.data);
|
|
79
|
-
});
|
|
80
|
-
messageBuffers = [];
|
|
81
|
-
}
|
|
82
|
-
pool === null || pool === void 0 ? void 0 : pool.emitWorkerMessage(payload.event, payload.data);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
workerIns.worker.on('error', (err) => {
|
|
86
|
-
pool === null || pool === void 0 ? void 0 : pool.emitWorkerMessage('uncaughtException', err);
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
pool.workers.forEach(workerIns => {
|
|
90
|
-
handlerWorker(workerIns);
|
|
91
|
-
});
|
|
92
|
-
const push = pool.workers.push.bind(pool.workers);
|
|
93
|
-
pool.workers.push = workerIns => {
|
|
94
|
-
handlerWorker(workerIns);
|
|
95
|
-
push(workerIns);
|
|
96
|
-
};
|
|
97
|
-
return pool;
|
|
98
|
-
}
|
|
99
|
-
close() {
|
|
100
|
-
if (this.pool) {
|
|
101
|
-
this.pool.exec('close');
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
kill() {
|
|
105
|
-
if (this.pool) {
|
|
106
|
-
this.pool.terminate(true);
|
|
107
|
-
this.pool = null;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
exports.AbstractCompiler = AbstractCompiler;
|
|
112
|
-
AbstractCompiler.createProcessOps = processArgs => {
|
|
113
|
-
const { type = 'keepalive', inspectPort, nodeJsPath } = processArgs;
|
|
114
|
-
const execArgv = ['--expose-gc'];
|
|
115
|
-
const customNodeJs = nodeJsPath && fs_extra_1.default.existsSync(nodeJsPath);
|
|
116
|
-
if (process.env.DEV_IDE_SP) {
|
|
117
|
-
execArgv.push(`--inspect=${inspectPort}`);
|
|
118
|
-
}
|
|
119
|
-
if (customNodeJs) {
|
|
120
|
-
try {
|
|
121
|
-
fs_extra_1.default.chmodSync(nodeJsPath, 755);
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const options = {
|
|
127
|
-
stdio: 'pipe',
|
|
128
|
-
execArgv,
|
|
129
|
-
windowsHide: true
|
|
130
|
-
};
|
|
131
|
-
if (customNodeJs) {
|
|
132
|
-
options.execPath = nodeJsPath;
|
|
133
|
-
}
|
|
134
|
-
return options;
|
|
135
|
-
};
|
|
136
|
-
class MPPackDevCompiler extends AbstractCompiler {
|
|
137
|
-
constructor(props, args) {
|
|
138
|
-
super(props, args);
|
|
139
|
-
this.pending = false;
|
|
140
|
-
this.pendingPkgs = {};
|
|
141
|
-
this.readyPkgs = [];
|
|
142
|
-
this.watching = false;
|
|
143
|
-
this.workerType = (args === null || args === void 0 ? void 0 : args.workerType) || 'web';
|
|
144
|
-
this.inspectPort = 9227;
|
|
145
|
-
this.makePoolReady();
|
|
146
|
-
}
|
|
147
|
-
makePoolReady() {
|
|
148
|
-
if (preparedDevPool) {
|
|
149
|
-
this._pool = preparedDevPool;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
this._pool = AbstractCompiler.createPool(this.workerType, {
|
|
153
|
-
minWorkers: 1,
|
|
154
|
-
maxWorkers: 1
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
this._pool.emitWorkerMessage = this.emit.bind(this);
|
|
158
|
-
}
|
|
159
|
-
reset() {
|
|
160
|
-
this.pendingPkgs = {};
|
|
161
|
-
this.readyPkgs = [];
|
|
162
|
-
this.watching = false;
|
|
163
|
-
this.pending = false;
|
|
164
|
-
}
|
|
165
|
-
doCompilePkgs(opts) {
|
|
166
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
const { compilePkgs = [constant_config_1.MAIN_PKG_ROOT] } = opts;
|
|
168
|
-
const todoPkgs = [];
|
|
169
|
-
let allReady = true;
|
|
170
|
-
compilePkgs.forEach(pkg => {
|
|
171
|
-
var _a, _b;
|
|
172
|
-
if (this.readyPkgs.includes(pkg)) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
allReady = false;
|
|
176
|
-
if (this.pendingPkgs[pkg]) {
|
|
177
|
-
(_a = this.pendingPkgs[pkg].resolve) === null || _a === void 0 ? void 0 : _a.push(resolve);
|
|
178
|
-
(_b = this.pendingPkgs[pkg].reject) === null || _b === void 0 ? void 0 : _b.push(reject);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
this.pendingPkgs[pkg] = {
|
|
182
|
-
resolve: [resolve],
|
|
183
|
-
reject: [reject]
|
|
184
|
-
};
|
|
185
|
-
todoPkgs.push(pkg);
|
|
186
|
-
});
|
|
187
|
-
if (allReady) {
|
|
188
|
-
return resolve(null);
|
|
189
|
-
}
|
|
190
|
-
if (!todoPkgs.length) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
try {
|
|
194
|
-
if (!this.pending && !this.watching) {
|
|
195
|
-
yield this.compilePkgsAndWatch(Object.assign({ compilePkgs: todoPkgs }, opts));
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
yield this.addPkgsToWatch(Object.assign({ compilePkgs }, opts));
|
|
199
|
-
}
|
|
200
|
-
todoPkgs.forEach(pkg => {
|
|
201
|
-
var _a, _b;
|
|
202
|
-
(_b = (_a = this.pendingPkgs[pkg].resolve) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, fn => fn());
|
|
203
|
-
delete this.pendingPkgs[pkg];
|
|
204
|
-
this.readyPkgs.push(pkg);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
todoPkgs.forEach(pkg => {
|
|
209
|
-
var _a, _b, _c;
|
|
210
|
-
(_c = (_b = (_a = this.pendingPkgs[pkg]) === null || _a === void 0 ? void 0 : _a.reject) === null || _b === void 0 ? void 0 : _b.forEach) === null || _c === void 0 ? void 0 : _c.call(_b, fn => fn(error));
|
|
211
|
-
delete this.pendingPkgs[pkg];
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}));
|
|
215
|
-
}
|
|
216
|
-
compilePkgsAndWatch(opts) {
|
|
217
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
-
try {
|
|
219
|
-
this.pending = true;
|
|
220
|
-
this.emit('buildStart');
|
|
221
|
-
yield this.call('runTask', Object.assign({ action: 'dev' }, opts));
|
|
222
|
-
this.watching = true;
|
|
223
|
-
this.emit('buildEnd');
|
|
224
|
-
}
|
|
225
|
-
catch (error) {
|
|
226
|
-
this.watching = false;
|
|
227
|
-
throw error;
|
|
228
|
-
}
|
|
229
|
-
finally {
|
|
230
|
-
this.pending = false;
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
addPkgsToWatch(opts) {
|
|
235
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
-
const { compilePkgs = [] } = opts;
|
|
237
|
-
try {
|
|
238
|
-
this.pending = true;
|
|
239
|
-
this.emit('buildStart');
|
|
240
|
-
yield this.call('activatePkgs', { compilePkgs });
|
|
241
|
-
this.emit('buildEnd');
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
throw error;
|
|
245
|
-
}
|
|
246
|
-
finally {
|
|
247
|
-
this.pending = false;
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
changeCompileOptions(options) {
|
|
252
|
-
this.call('changeCompileOptions', options);
|
|
253
|
-
}
|
|
254
|
-
makePkgsReady(opts) {
|
|
255
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
yield this.doCompilePkgs(opts);
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
reCompilePkgs(options) {
|
|
260
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
261
|
-
this.readyPkgs = [];
|
|
262
|
-
this.pendingPkgs = {};
|
|
263
|
-
this.pending = false;
|
|
264
|
-
this.watching = false;
|
|
265
|
-
this.close();
|
|
266
|
-
yield this.doCompilePkgs(options);
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
exports.MPPackDevCompiler = MPPackDevCompiler;
|
|
271
|
-
class WebPackDevCompiler extends AbstractCompiler {
|
|
272
|
-
constructor(props, args) {
|
|
273
|
-
super(props, args);
|
|
274
|
-
this.watching = false;
|
|
275
|
-
this.workerType = (args === null || args === void 0 ? void 0 : args.workerType) || 'web';
|
|
276
|
-
this.inspectPort = 9230;
|
|
277
|
-
this.makePoolReady(args);
|
|
278
|
-
}
|
|
279
|
-
makePoolReady(args) {
|
|
280
|
-
if (preparedDevPool) {
|
|
281
|
-
this.pool = preparedDevPool;
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
this.pool = AbstractCompiler.createPool(this.workerType, {
|
|
285
|
-
minWorkers: 1,
|
|
286
|
-
maxWorkers: 1
|
|
287
|
-
}, args);
|
|
288
|
-
}
|
|
289
|
-
this.pool.emitWorkerMessage = this.emit.bind(this);
|
|
290
|
-
}
|
|
291
|
-
doCompilePkgs(opts) {
|
|
292
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
293
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
294
|
-
if (this.watching) {
|
|
295
|
-
return resolve(null);
|
|
296
|
-
}
|
|
297
|
-
if (this.pendingTask) {
|
|
298
|
-
(_b = (_a = this.pendingTask) === null || _a === void 0 ? void 0 : _a.resolve) === null || _b === void 0 ? void 0 : _b.push(resolve);
|
|
299
|
-
(_d = (_c = this.pendingTask) === null || _c === void 0 ? void 0 : _c.reject) === null || _d === void 0 ? void 0 : _d.push(reject);
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
this.pendingTask = {
|
|
303
|
-
resolve: [resolve],
|
|
304
|
-
reject: [reject]
|
|
305
|
-
};
|
|
306
|
-
try {
|
|
307
|
-
this.emit('buildStart');
|
|
308
|
-
yield this.call('runTask', Object.assign({ action: 'dev' }, opts));
|
|
309
|
-
this.watching = true;
|
|
310
|
-
(_f = (_e = this.pendingTask) === null || _e === void 0 ? void 0 : _e.resolve) === null || _f === void 0 ? void 0 : _f.forEach(fn => fn());
|
|
311
|
-
this.emit('buildEnd');
|
|
312
|
-
}
|
|
313
|
-
catch (error) {
|
|
314
|
-
this.watching = false;
|
|
315
|
-
(_h = (_g = this.pendingTask) === null || _g === void 0 ? void 0 : _g.reject) === null || _h === void 0 ? void 0 : _h.forEach(fn => fn(error));
|
|
316
|
-
}
|
|
317
|
-
finally {
|
|
318
|
-
this.pendingTask = undefined;
|
|
319
|
-
}
|
|
320
|
-
}));
|
|
321
|
-
}
|
|
322
|
-
makePkgsReady(opts) {
|
|
323
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
324
|
-
yield this.doCompilePkgs(opts);
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
reCompilePkgs(opts) {
|
|
328
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
-
this.pendingTask = undefined;
|
|
330
|
-
this.watching = false;
|
|
331
|
-
this.close();
|
|
332
|
-
yield this.doCompilePkgs(opts);
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
exports.WebPackDevCompiler = WebPackDevCompiler;
|
|
337
|
-
class BuildCompiler extends AbstractCompiler {
|
|
338
|
-
constructor(props, args) {
|
|
339
|
-
super(props, args);
|
|
340
|
-
this.cps = [];
|
|
341
|
-
this.workerType = (args === null || args === void 0 ? void 0 : args.workerType) || 'process';
|
|
342
|
-
this.inspectPort = 9228;
|
|
343
|
-
this.makePoolReady(args);
|
|
344
|
-
}
|
|
345
|
-
makePoolReady(args) {
|
|
346
|
-
this.pool = AbstractCompiler.createPool(this.workerType, {
|
|
347
|
-
minWorkers: 1
|
|
348
|
-
}, args);
|
|
349
|
-
this.pool.emitWorkerMessage = this.emit.bind(this);
|
|
350
|
-
}
|
|
351
|
-
build(option) {
|
|
352
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
353
|
-
try {
|
|
354
|
-
const res = yield this.call('runTask', Object.assign({ action: 'build' }, option));
|
|
355
|
-
return res;
|
|
356
|
-
}
|
|
357
|
-
finally {
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
exports.BuildCompiler = BuildCompiler;
|
|
363
|
-
function getProjectCompilerClass(compilerType) {
|
|
364
|
-
const CompilerClass = compilerType === constant_config_1.COMPILER_TYPE.legacy_dev
|
|
365
|
-
? WebPackDevCompiler
|
|
366
|
-
: compilerType === constant_config_1.COMPILER_TYPE.dev
|
|
367
|
-
? MPPackDevCompiler
|
|
368
|
-
: BuildCompiler;
|
|
369
|
-
return CompilerClass;
|
|
370
|
-
}
|
|
371
|
-
exports.prepareDevPool = AbstractCompiler.prepareDevPool;
|
|
372
|
-
});
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):function adopt(value){return value instanceof P?value:new P((function(resolve){resolve(value)}))}(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))},__importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};!function(factory){if("object"==typeof module&&"object"==typeof module.exports){var v=factory(require,exports);void 0!==v&&(module.exports=v)}else{"function"==typeof define&&define.amd&&define(["require","exports","stream","fs-extra","./config/constant.config","xhs-mp-workerpool"],factory)}}((function(require,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.prepareDevPool=exports.BuildCompiler=exports.WebPackDevCompiler=exports.MPPackDevCompiler=exports.AbstractCompiler=void 0,exports.getProjectCompilerClass=function getProjectCompilerClass(compilerType){return compilerType===constant_config_1.COMPILER_TYPE.legacy_dev?WebPackDevCompiler:compilerType===constant_config_1.COMPILER_TYPE.dev?MPPackDevCompiler:BuildCompiler};const stream_1=require("stream"),fs_extra_1=__importDefault(require("fs-extra")),constant_config_1=require("./config/constant.config"),xhs_mp_workerpool_1=__importDefault(require("xhs-mp-workerpool"));let preparedDevPool=null;class AbstractCompiler extends stream_1.EventEmitter{constructor(opts,args){super(),this.workerType="process",this.call=(method,data,options)=>(data=Object.assign(Object.assign({},this.compilerOpts||{}),data),this.pool.exec(method,[data],options)),this.compilerOpts=opts,this.logger=args.logger||console,this.workerType=args.workerType||"process"}get pool(){return this._pool||this.makePoolReady(),this._pool}set pool(val){this._pool=val}static prepareDevPool(){preparedDevPool=AbstractCompiler.createPool("web",{minWorkers:1,maxWorkers:1})}static createPool(workerType,poolOpts={},processArgs={}){let forkOpts={};"process"===workerType&&(forkOpts=AbstractCompiler.createProcessOps(processArgs));const pool=xhs_mp_workerpool_1.default.pool(__dirname+"/compilerImpl.js",Object.assign({workerType:workerType,workerThreadOpts:{},forkOpts:forkOpts,workerOpts:{}},poolOpts));let messageBuffers=[];const handlerWorker=workerIns=>{workerIns.worker.on("message",(payload=>{if(null==payload?void 0:payload.customMessage){if(!pool.emitWorkerMessage){return void messageBuffers.push(payload)}messageBuffers.length&&(messageBuffers.forEach((payload=>{null==pool||pool.emitWorkerMessage(payload.event,payload.data)})),messageBuffers=[]),null==pool||pool.emitWorkerMessage(payload.event,payload.data)}})),workerIns.worker.on("error",(err=>{null==pool||pool.emitWorkerMessage("uncaughtException",err)}))};pool.workers.forEach((workerIns=>{handlerWorker(workerIns)}));const push=pool.workers.push.bind(pool.workers);return pool.workers.push=workerIns=>{handlerWorker(workerIns),push(workerIns)},pool}close(){this.pool&&this.pool.exec("close")}kill(){this.pool&&(this.pool.terminate(!0),this.pool=null)}}exports.AbstractCompiler=AbstractCompiler,AbstractCompiler.createProcessOps=processArgs=>{const{type:type="keepalive",inspectPort:inspectPort,nodeJsPath:nodeJsPath}=processArgs,execArgv=["--expose-gc"],customNodeJs=nodeJsPath&&fs_extra_1.default.existsSync(nodeJsPath);if(process.env.DEV_IDE_SP&&execArgv.push(`--inspect=${inspectPort}`),customNodeJs){try{fs_extra_1.default.chmodSync(nodeJsPath,755)}catch(error){}}const options={stdio:"pipe",execArgv:execArgv,windowsHide:!0};return customNodeJs&&(options.execPath=nodeJsPath),options};class MPPackDevCompiler extends AbstractCompiler{constructor(props,args){super(props,args),this.pending=!1,this.pendingPkgs={},this.readyPkgs=[],this.watching=!1,this.workerType=(null==args?void 0:args.workerType)||"web",this.inspectPort=9227,this.makePoolReady()}makePoolReady(){this._pool=preparedDevPool||AbstractCompiler.createPool(this.workerType,{minWorkers:1,maxWorkers:1}),this._pool.emitWorkerMessage=this.emit.bind(this)}reset(){this.pendingPkgs={},this.readyPkgs=[],this.watching=!1,this.pending=!1}doCompilePkgs(opts){return new Promise(((resolve,reject)=>__awaiter(this,void 0,void 0,(function*(){const{compilePkgs:compilePkgs=[constant_config_1.MAIN_PKG_ROOT]}=opts,todoPkgs=[];let allReady=!0;if(compilePkgs.forEach((pkg=>{var _a,_b;if(!this.readyPkgs.includes(pkg)){if(allReady=!1,this.pendingPkgs[pkg]){return null===(_a=this.pendingPkgs[pkg].resolve)||void 0===_a||_a.push(resolve),void(null===(_b=this.pendingPkgs[pkg].reject)||void 0===_b||_b.push(reject))}this.pendingPkgs[pkg]={resolve:[resolve],reject:[reject]},todoPkgs.push(pkg)}})),allReady){return resolve(null)}if(todoPkgs.length){try{this.pending||this.watching?yield this.addPkgsToWatch(Object.assign({compilePkgs:compilePkgs},opts)):yield this.compilePkgsAndWatch(Object.assign({compilePkgs:todoPkgs},opts)),todoPkgs.forEach((pkg=>{var _a,_b;null===(_b=null===(_a=this.pendingPkgs[pkg].resolve)||void 0===_a?void 0:_a.forEach)||void 0===_b||_b.call(_a,(fn=>fn())),delete this.pendingPkgs[pkg],this.readyPkgs.push(pkg)}))}catch(error){todoPkgs.forEach((pkg=>{var _a,_b,_c;null===(_c=null===(_b=null===(_a=this.pendingPkgs[pkg])||void 0===_a?void 0:_a.reject)||void 0===_b?void 0:_b.forEach)||void 0===_c||_c.call(_b,(fn=>fn(error))),delete this.pendingPkgs[pkg]}))}}}))))}compilePkgsAndWatch(opts){return __awaiter(this,void 0,void 0,(function*(){try{this.pending=!0,this.emit("buildStart"),yield this.call("runTask",Object.assign({action:"dev"},opts)),this.watching=!0,this.emit("buildEnd")}catch(error){throw this.watching=!1,error}finally{this.pending=!1}}))}addPkgsToWatch(opts){return __awaiter(this,void 0,void 0,(function*(){const{compilePkgs:compilePkgs=[]}=opts;try{this.pending=!0,this.emit("buildStart"),yield this.call("activatePkgs",{compilePkgs:compilePkgs}),this.emit("buildEnd")}catch(error){throw error}finally{this.pending=!1}}))}changeCompileOptions(options){this.call("changeCompileOptions",options)}makePkgsReady(opts){return __awaiter(this,void 0,void 0,(function*(){yield this.doCompilePkgs(opts)}))}reCompilePkgs(options){return __awaiter(this,void 0,void 0,(function*(){this.readyPkgs=[],this.pendingPkgs={},this.pending=!1,this.watching=!1,this.close(),yield this.doCompilePkgs(options)}))}}exports.MPPackDevCompiler=MPPackDevCompiler;class WebPackDevCompiler extends AbstractCompiler{constructor(props,args){super(props,args),this.watching=!1,this.workerType=(null==args?void 0:args.workerType)||"web",this.inspectPort=9230,this.makePoolReady(args)}makePoolReady(args){this.pool=preparedDevPool||AbstractCompiler.createPool(this.workerType,{minWorkers:1,maxWorkers:1},args),this.pool.emitWorkerMessage=this.emit.bind(this)}doCompilePkgs(opts){return new Promise(((resolve,reject)=>__awaiter(this,void 0,void 0,(function*(){var _a,_b,_c,_d,_e,_f,_g,_h;if(this.watching){return resolve(null)}if(this.pendingTask){return null===(_b=null===(_a=this.pendingTask)||void 0===_a?void 0:_a.resolve)||void 0===_b||_b.push(resolve),void(null===(_d=null===(_c=this.pendingTask)||void 0===_c?void 0:_c.reject)||void 0===_d||_d.push(reject))}this.pendingTask={resolve:[resolve],reject:[reject]};try{this.emit("buildStart"),yield this.call("runTask",Object.assign({action:"dev"},opts)),this.watching=!0,null===(_f=null===(_e=this.pendingTask)||void 0===_e?void 0:_e.resolve)||void 0===_f||_f.forEach((fn=>fn())),this.emit("buildEnd")}catch(error){this.watching=!1,null===(_h=null===(_g=this.pendingTask)||void 0===_g?void 0:_g.reject)||void 0===_h||_h.forEach((fn=>fn(error)))}finally{this.pendingTask=void 0}}))))}makePkgsReady(opts){return __awaiter(this,void 0,void 0,(function*(){yield this.doCompilePkgs(opts)}))}reCompilePkgs(opts){return __awaiter(this,void 0,void 0,(function*(){this.pendingTask=void 0,this.watching=!1,this.close(),yield this.doCompilePkgs(opts)}))}}exports.WebPackDevCompiler=WebPackDevCompiler;class BuildCompiler extends AbstractCompiler{constructor(props,args){super(props,args),this.cps=[],this.workerType=(null==args?void 0:args.workerType)||"process",this.inspectPort=9228,this.makePoolReady(args)}makePoolReady(args){this.pool=AbstractCompiler.createPool(this.workerType,{minWorkers:1},args),this.pool.emitWorkerMessage=this.emit.bind(this)}build(option){return __awaiter(this,void 0,void 0,(function*(){try{return yield this.call("runTask",Object.assign({action:"build"},option))}finally{}}))}}exports.BuildCompiler=BuildCompiler,exports.prepareDevPool=AbstractCompiler.prepareDevPool}));
|