xhs-mp-compiler-cli 1.0.2 → 1.1.0-beta.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 +3 -3
- package/dist/bin/xhs-mp-cli-dev.js +9 -31
- package/dist/compiler.d.ts +76 -0
- package/dist/compiler.js +361 -0
- package/dist/compilerCP.js +175 -0
- package/dist/config/constant.config.d.ts +7 -0
- package/dist/config/constant.config.js +10 -0
- package/dist/dev-server/index.d.ts +2 -2
- package/dist/dev-server/index.js +7 -5
- package/dist/index.d.ts +1 -11
- package/dist/index.js +3 -112
- package/dist/packs/index.d.ts +14 -0
- package/dist/packs/index.js +31 -0
- package/dist/packs/mp-pack/index.d.ts +3 -0
- package/dist/packs/mp-pack/index.js +32 -0
- package/dist/packs/webpack/index.d.ts +3 -0
- package/dist/packs/webpack/index.js +92 -0
- package/dist/packs/webpack/webpack.d.ts +21 -0
- package/dist/packs/webpack/webpack.js +79 -0
- package/dist/{webpack-config/presets → presets}/babel.d.ts +3 -3
- package/dist/{webpack-config/presets → presets}/babel.js +13 -11
- package/dist/presets/common.d.ts +4 -0
- package/dist/presets/common.js +46 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +10 -0
- package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +46 -0
- package/dist/presets/configs/minigame/assets/index.d.ts +3 -0
- package/dist/presets/configs/minigame/assets/index.js +65 -0
- package/dist/presets/configs/minigame/service/index.d.ts +3 -0
- package/dist/presets/configs/minigame/service/index.js +34 -0
- package/dist/{webpack-config/presets/service/XhsResolveLimitPlugin.d.ts → presets/configs/minigame/service/resolveLimitPlugin.d.ts} +3 -3
- package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +35 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -0
- package/dist/{webpack-config/presets/service/ServiceEntryPlugin.d.ts → presets/configs/minigame/service/serviceEntryPlugin.d.ts} +3 -1
- package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +32 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +12 -0
- package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +132 -0
- package/dist/presets/configs/miniprogram/assets/index.d.ts +4 -0
- package/dist/presets/configs/miniprogram/assets/index.js +47 -0
- package/dist/presets/configs/miniprogram/render/component.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/component.js +47 -0
- package/dist/presets/configs/miniprogram/render/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/render/index.js +70 -0
- package/dist/presets/configs/miniprogram/render/render.d.ts +3 -0
- package/dist/presets/configs/miniprogram/render/render.js +49 -0
- package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +8 -0
- package/dist/{webpack-config/presets/render/RenderChunkPlugin.js → presets/configs/miniprogram/render/renderChunkPlugin.js} +13 -8
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/{webpack-config/presets/render/SjsEntryPlugin.js → presets/configs/miniprogram/render/sjsEntryPlugin.js} +24 -21
- package/dist/presets/configs/miniprogram/service/index.d.ts +5 -0
- package/dist/presets/configs/miniprogram/service/index.js +72 -0
- package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +8 -0
- package/dist/{webpack-config/presets/service/XhsResolveLimitPlugin.js → presets/configs/miniprogram/service/resolveLimitPlugin.js} +11 -10
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +9 -0
- package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +65 -0
- package/dist/presets/index.d.ts +2 -0
- package/dist/presets/index.js +95 -0
- package/dist/presets/loaders/mg-entry-loader.js +27 -0
- package/dist/{webpack-config → presets}/loaders/mini-style-loader.js +13 -10
- package/dist/presets/loaders/mp-entry-loader.js +196 -0
- package/dist/{webpack-config → presets}/loaders/sjs-loader/index.js +0 -4
- package/dist/{webpack-config → presets}/loaders/wxss-loader.js +7 -6
- package/dist/presets/plugins/InjectorPlugin.d.ts +7 -0
- package/dist/presets/plugins/InjectorPlugin.js +14 -0
- package/dist/presets/prod.d.ts +4 -0
- package/dist/presets/prod.js +80 -0
- package/dist/types/index.d.ts +18 -6
- package/dist/utils/common.d.ts +2 -1
- package/dist/utils/common.js +7 -6
- package/dist/utils/const.d.ts +27 -0
- package/dist/utils/const.js +47 -0
- package/dist/{webpack-config/lib → utils}/css.js +6 -6
- package/dist/utils/getSuffixName.d.ts +3 -0
- package/dist/utils/getSuffixName.js +18 -0
- package/dist/{webpack-config/loaders/utils.d.ts → utils/loader-utils.d.ts} +2 -0
- package/dist/{webpack-config/loaders/utils.js → utils/loader-utils.js} +19 -1
- package/dist/utils/projectConfig.d.ts +1 -1
- package/dist/utils/projectConfig.js +2 -2
- package/dist/{webpack-config/lib → utils}/utils.js +2 -2
- package/package.json +10 -9
- package/dist/build/index.d.ts +0 -3
- package/dist/build/index.js +0 -22
- package/dist/globalData/SjsModule.d.ts +0 -32
- package/dist/globalData/SjsModule.js +0 -34
- package/dist/utils/combineExtJson.d.ts +0 -3
- package/dist/utils/combineExtJson.js +0 -74
- package/dist/utils/getCssSuffixName.d.ts +0 -1
- package/dist/utils/getCssSuffixName.js +0 -9
- package/dist/utils/getMlSuffixName.d.ts +0 -1
- package/dist/utils/getMlSuffixName.js +0 -6
- package/dist/utils/getPrefixName.d.ts +0 -1
- package/dist/utils/getPrefixName.js +0 -6
- package/dist/utils/transformAppJson.d.ts +0 -16
- package/dist/utils/transformAppJson.js +0 -199
- package/dist/utils/validateAppJson.d.ts +0 -4
- package/dist/utils/validateAppJson.js +0 -111
- package/dist/webpack-config/index.d.ts +0 -4
- package/dist/webpack-config/index.js +0 -41
- package/dist/webpack-config/lib/const.d.ts +0 -13
- package/dist/webpack-config/lib/const.js +0 -15
- package/dist/webpack-config/loaders/component-entry-loader.js +0 -31
- package/dist/webpack-config/loaders/component-entry-requirements-loader.js +0 -24
- package/dist/webpack-config/loaders/render-entry-loader.js +0 -50
- package/dist/webpack-config/loaders/service-entry-loader.d.ts +0 -1
- package/dist/webpack-config/loaders/service-entry-loader.js +0 -51
- package/dist/webpack-config/plugins/VueLoaderPlugin.d.ts +0 -19
- package/dist/webpack-config/plugins/VueLoaderPlugin.js +0 -205
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.d.ts +0 -8
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.js +0 -40
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.d.ts +0 -36
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.js +0 -71
- package/dist/webpack-config/presets/common.d.ts +0 -4
- package/dist/webpack-config/presets/common.js +0 -40
- package/dist/webpack-config/presets/mp/MpEntryPlugin.d.ts +0 -23
- package/dist/webpack-config/presets/mp/MpEntryPlugin.js +0 -87
- package/dist/webpack-config/presets/mp/index.d.ts +0 -4
- package/dist/webpack-config/presets/mp/index.js +0 -48
- package/dist/webpack-config/presets/prod.d.ts +0 -4
- package/dist/webpack-config/presets/prod.js +0 -83
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.d.ts +0 -18
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.js +0 -77
- package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +0 -5
- package/dist/webpack-config/presets/render/RenderEntryPlugin.d.ts +0 -14
- package/dist/webpack-config/presets/render/RenderEntryPlugin.js +0 -42
- package/dist/webpack-config/presets/render/SjsEntryPlugin.d.ts +0 -31
- package/dist/webpack-config/presets/render/index.d.ts +0 -4
- package/dist/webpack-config/presets/render/index.js +0 -62
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.js +0 -36
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.d.ts +0 -6
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +0 -46
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.d.ts +0 -5
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.js +0 -27
- package/dist/webpack-config/presets/service/index.d.ts +0 -4
- package/dist/webpack-config/presets/service/index.js +0 -39
- /package/dist/{webpack-config/loaders/component-entry-loader.d.ts → compilerCP.d.ts} +0 -0
- /package/dist/{webpack-config/loaders/component-entry-requirements-loader.d.ts → presets/loaders/mg-entry-loader.d.ts} +0 -0
- /package/dist/{webpack-config → presets}/loaders/mini-style-loader.d.ts +0 -0
- /package/dist/{webpack-config/loaders/render-entry-loader.d.ts → presets/loaders/mp-entry-loader.d.ts} +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/index.d.ts +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/scope.d.ts +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/scope.js +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/tranform.d.ts +0 -0
- /package/dist/{webpack-config → presets}/loaders/sjs-loader/tranform.js +0 -0
- /package/dist/{webpack-config → presets}/loaders/wxss-loader.d.ts +0 -0
- /package/dist/{webpack-config/lib → utils}/css.d.ts +0 -0
- /package/dist/{webpack-config/lib → utils}/postcssRpx2Vw.d.ts +0 -0
- /package/dist/{webpack-config/lib → utils}/postcssRpx2Vw.js +0 -0
- /package/dist/{webpack-config/lib → utils}/tagTransformMap.d.ts +0 -0
- /package/dist/{webpack-config/lib → utils}/tagTransformMap.js +0 -0
- /package/dist/{webpack-config/lib → utils}/utils.d.ts +0 -0
|
@@ -16,14 +16,14 @@ commander.usage('[options]').option('-v1, --enableV1 <boolean>', 'package v1');
|
|
|
16
16
|
commander.usage('[options]').option('-v2, --enableV2 <boolean>', 'package v2');
|
|
17
17
|
commander.usage('[options]').option('-vdom, --enableVDom <boolean>', 'vdom 架构支持');
|
|
18
18
|
commander.parse(process.argv);
|
|
19
|
-
const
|
|
19
|
+
const projectPath = commander.opts().mpDir ? path_1.default.resolve(commander.opts().mpDir) : process.cwd();
|
|
20
20
|
const platform = commander.opts().platform ? commander.opts().platform : 'xhs';
|
|
21
21
|
const enableV1 = commander.opts().enableV1 === "true";
|
|
22
22
|
const enableV2 = commander.opts().enableV2 === "true";
|
|
23
23
|
const enableVDom = commander.opts().enableVDom === "true";
|
|
24
24
|
const compressJs = commander.opts().compressJs === "true";
|
|
25
|
-
const multiCompiler = (0, index_1.
|
|
26
|
-
|
|
25
|
+
const multiCompiler = (0, index_1.createCompiler)({
|
|
26
|
+
projectPath,
|
|
27
27
|
action: 'build',
|
|
28
28
|
platform,
|
|
29
29
|
compressJs,
|
|
@@ -1,35 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
5
|
};
|
|
29
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
7
|
const commander_1 = require("commander");
|
|
31
8
|
const path_1 = __importDefault(require("path"));
|
|
32
|
-
const index_1 =
|
|
9
|
+
const index_1 = require("../index");
|
|
33
10
|
const commander = new commander_1.Command();
|
|
34
11
|
commander.usage('[options]').option('-d, --mpDir <path>', 'set workdir [default: ./]');
|
|
35
12
|
commander.usage('[options]').option('-p, --platform <string>', 'set platform [default: xhs]');
|
|
@@ -40,17 +17,17 @@ commander.usage('[options]').option('-v1, --enableV1 <boolean>', 'package v1');
|
|
|
40
17
|
commander.usage('[options]').option('-v2, --enableV2 <boolean>', 'package v2');
|
|
41
18
|
commander.usage('[options]').option('-vdom, --enableVDom <boolean>', 'vdom 架构支持');
|
|
42
19
|
commander.parse(process.argv);
|
|
43
|
-
const
|
|
20
|
+
const projectPath = commander.opts().mpDir ? path_1.default.resolve(commander.opts().mpDir) : process.cwd();
|
|
44
21
|
const platform = commander.opts().platform ? commander.opts().platform : 'xhs';
|
|
45
|
-
const
|
|
22
|
+
const devServerPort = commander.opts().port ? commander.opts().port : 1388;
|
|
46
23
|
const out = commander.opts().out === "true";
|
|
47
24
|
const enableV1 = commander.opts().enableV1 === "true";
|
|
48
25
|
const enableV2 = commander.opts().enableV2 === "true";
|
|
49
26
|
const enableVDom = commander.opts().enableVDom === "true";
|
|
50
27
|
process.env.PRETTIER_XHSML = "true";
|
|
51
28
|
if (out) {
|
|
52
|
-
const multiCompiler = (0, index_1.
|
|
53
|
-
|
|
29
|
+
const multiCompiler = (0, index_1.createCompiler)({
|
|
30
|
+
projectPath,
|
|
54
31
|
action: 'dev',
|
|
55
32
|
platform,
|
|
56
33
|
compressJs: false,
|
|
@@ -67,12 +44,13 @@ if (out) {
|
|
|
67
44
|
});
|
|
68
45
|
}
|
|
69
46
|
else {
|
|
70
|
-
(0, index_1.
|
|
71
|
-
|
|
47
|
+
(0, index_1.createCompiler)({
|
|
48
|
+
projectPath,
|
|
72
49
|
action: 'dev',
|
|
50
|
+
enableDevServer: true,
|
|
73
51
|
platform,
|
|
74
52
|
compressJs: false,
|
|
75
|
-
|
|
53
|
+
devServerPort,
|
|
76
54
|
enableSourcemap: true,
|
|
77
55
|
enableV1,
|
|
78
56
|
enableV2,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/// <reference types="node/child_process" />
|
|
2
|
+
/// <reference types="node/stream" />
|
|
3
|
+
/**
|
|
4
|
+
* 在子进程执行编译
|
|
5
|
+
*/
|
|
6
|
+
import { ChildProcess } from 'child_process';
|
|
7
|
+
import { EventEmitter } from 'stream';
|
|
8
|
+
type Platform = 'wx' | 'xhs';
|
|
9
|
+
export interface ICompilerOption {
|
|
10
|
+
projectPath: string;
|
|
11
|
+
appMode: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ICompilerArgs {
|
|
14
|
+
logger?: any;
|
|
15
|
+
type?: string;
|
|
16
|
+
inspectPort?: number;
|
|
17
|
+
maxSpaceSaze?: number;
|
|
18
|
+
nodeJsPath?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ForkWebpackOption {
|
|
21
|
+
platform: Platform;
|
|
22
|
+
extJsonPath: string;
|
|
23
|
+
distDir: string;
|
|
24
|
+
cacheDirectory: string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface ICheckOptions {
|
|
27
|
+
compilePkgs?: string[];
|
|
28
|
+
compressJs: boolean;
|
|
29
|
+
enableV2?: boolean;
|
|
30
|
+
enableV1?: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare abstract class AbstractCompiler extends EventEmitter {
|
|
33
|
+
protected inspectPort: any;
|
|
34
|
+
private _cp;
|
|
35
|
+
private compilerOpts;
|
|
36
|
+
private cpArgs;
|
|
37
|
+
private logger;
|
|
38
|
+
private _handlerMap;
|
|
39
|
+
constructor(opts: ICompilerOption, args?: ICompilerArgs);
|
|
40
|
+
get cp(): any;
|
|
41
|
+
protected createSp: (passData?: {}) => any;
|
|
42
|
+
protected create: (passData?: {}) => ChildProcess;
|
|
43
|
+
close(): void;
|
|
44
|
+
kill(): void;
|
|
45
|
+
private handleMessage;
|
|
46
|
+
call: (method: any, data: any) => Promise<unknown>;
|
|
47
|
+
send: (method: any, data: any) => void;
|
|
48
|
+
}
|
|
49
|
+
declare class MPPackDevCompiler extends AbstractCompiler {
|
|
50
|
+
private pending;
|
|
51
|
+
private pendingPkgs;
|
|
52
|
+
private readyPkgs;
|
|
53
|
+
private watching;
|
|
54
|
+
constructor(props: any, args: any);
|
|
55
|
+
reset(): void;
|
|
56
|
+
doCompilePkgs(opts: ICheckOptions): Promise<unknown>;
|
|
57
|
+
private compilePkgsAndWatch;
|
|
58
|
+
private addPkgsToWatch;
|
|
59
|
+
changeCompileOptions(options: any): void;
|
|
60
|
+
makePkgsReady(opts: ICheckOptions): Promise<void>;
|
|
61
|
+
reCompilePkgs(options: any): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
declare class WebPackDevCompiler extends AbstractCompiler {
|
|
64
|
+
private watching;
|
|
65
|
+
private pendingTask?;
|
|
66
|
+
constructor(props: any);
|
|
67
|
+
makePkgsReady(opts: any): Promise<unknown>;
|
|
68
|
+
reCompilePkgs(opts: any): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
declare class BuildCompiler extends AbstractCompiler {
|
|
71
|
+
cps: any;
|
|
72
|
+
constructor(props: any, args: any);
|
|
73
|
+
build(option: ICheckOptions): Promise<unknown>;
|
|
74
|
+
}
|
|
75
|
+
export declare function getProcessCompilerClass(compilerType: any): typeof MPPackDevCompiler | typeof WebPackDevCompiler | typeof BuildCompiler;
|
|
76
|
+
export {};
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getProcessCompilerClass = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* 在子进程执行编译
|
|
18
|
+
*/
|
|
19
|
+
const child_process_1 = require("child_process");
|
|
20
|
+
const path_1 = require("path");
|
|
21
|
+
const stream_1 = require("stream");
|
|
22
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
23
|
+
const constant_config_1 = require("./config/constant.config");
|
|
24
|
+
const uuid = require('uuid');
|
|
25
|
+
const isMac = process.platform === 'darwin';
|
|
26
|
+
class AbstractCompiler extends stream_1.EventEmitter {
|
|
27
|
+
constructor(opts, args = {}) {
|
|
28
|
+
super();
|
|
29
|
+
this._handlerMap = {};
|
|
30
|
+
this.createSp = (passData = {}) => {
|
|
31
|
+
if (!this._cp) {
|
|
32
|
+
this._cp = this.create(Object.assign({}, passData));
|
|
33
|
+
this._cp.on('exit', code => {
|
|
34
|
+
this._cp = null;
|
|
35
|
+
});
|
|
36
|
+
this._cp.on('message', this.handleMessage);
|
|
37
|
+
}
|
|
38
|
+
return this._cp;
|
|
39
|
+
};
|
|
40
|
+
this.create = (passData = {}) => {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const { type = 'keepalive', inspectPort = this.inspectPort, maxSpaceSaze = 12288, nodeJsPath, } = this.cpArgs;
|
|
43
|
+
// const presistent = type === 'keepalive'
|
|
44
|
+
const entry = (0, path_1.join)(__dirname, './compilerCP.js');
|
|
45
|
+
const execArgv = [`--max-old-space-size=${maxSpaceSaze}`, '--expose-gc'];
|
|
46
|
+
const customNodeJs = nodeJsPath && fs_extra_1.default.existsSync(nodeJsPath);
|
|
47
|
+
if (process.env.DEV_IDE_SP) {
|
|
48
|
+
execArgv.push(`--inspect=${inspectPort}`);
|
|
49
|
+
}
|
|
50
|
+
if (customNodeJs) {
|
|
51
|
+
try {
|
|
52
|
+
fs_extra_1.default.chmodSync(nodeJsPath, 755);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
// do something
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const options = {
|
|
59
|
+
stdio: 'pipe',
|
|
60
|
+
execArgv,
|
|
61
|
+
// detached: presistent,
|
|
62
|
+
windowsHide: true,
|
|
63
|
+
};
|
|
64
|
+
if (customNodeJs) {
|
|
65
|
+
options.execPath = nodeJsPath;
|
|
66
|
+
}
|
|
67
|
+
const child = (0, child_process_1.fork)(entry, [JSON.stringify(passData)], options);
|
|
68
|
+
// if (presistent) {
|
|
69
|
+
// child.unref()
|
|
70
|
+
// }
|
|
71
|
+
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', msg => {
|
|
72
|
+
this.logger.debug('[compiler stdout]', msg.toString());
|
|
73
|
+
});
|
|
74
|
+
(_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', msg => {
|
|
75
|
+
this.logger.error('[compiler stderr]', msg.toString());
|
|
76
|
+
});
|
|
77
|
+
child.on('error', err => {
|
|
78
|
+
this.logger.error('sp error:', err);
|
|
79
|
+
});
|
|
80
|
+
child.on('exit', code => {
|
|
81
|
+
if (code !== 0 && code !== null) {
|
|
82
|
+
this.logger.error('sp exit:', code);
|
|
83
|
+
this.emit('unexpectedExit', code);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return child;
|
|
87
|
+
};
|
|
88
|
+
this.handleMessage = msg => {
|
|
89
|
+
var _a, _b, _c, _d;
|
|
90
|
+
let data = {};
|
|
91
|
+
try {
|
|
92
|
+
data = JSON.parse(`${msg}`);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
// do something
|
|
96
|
+
}
|
|
97
|
+
const { uuid, method, success, stats } = data;
|
|
98
|
+
if (method === 'callback') {
|
|
99
|
+
if (uuid && this._handlerMap[uuid]) {
|
|
100
|
+
if (success) {
|
|
101
|
+
(_b = (_a = this._handlerMap[uuid]).resolve) === null || _b === void 0 ? void 0 : _b.call(_a, data.data);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
(_d = (_c = this._handlerMap[uuid]).reject) === null || _d === void 0 ? void 0 : _d.call(_c, stats);
|
|
105
|
+
}
|
|
106
|
+
delete this._handlerMap[uuid];
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.emit(method, data);
|
|
111
|
+
};
|
|
112
|
+
this.call = (method, data) => new Promise((resolve, reject) => {
|
|
113
|
+
const id = uuid.v4();
|
|
114
|
+
const final = {
|
|
115
|
+
uuid: id,
|
|
116
|
+
method,
|
|
117
|
+
data: Object.assign(Object.assign({}, (this.compilerOpts || {})), data),
|
|
118
|
+
};
|
|
119
|
+
this._handlerMap[id] = {
|
|
120
|
+
resolve,
|
|
121
|
+
reject,
|
|
122
|
+
};
|
|
123
|
+
this.cp.send(JSON.stringify(final));
|
|
124
|
+
});
|
|
125
|
+
this.send = (method, data) => {
|
|
126
|
+
const final = {
|
|
127
|
+
method,
|
|
128
|
+
data: Object.assign(Object.assign({}, (this.compilerOpts || {})), data),
|
|
129
|
+
};
|
|
130
|
+
this.cp.send(JSON.stringify(final));
|
|
131
|
+
};
|
|
132
|
+
this.compilerOpts = opts;
|
|
133
|
+
this.cpArgs = args;
|
|
134
|
+
this.logger = args.logger || console;
|
|
135
|
+
}
|
|
136
|
+
get cp() {
|
|
137
|
+
return this.createSp();
|
|
138
|
+
}
|
|
139
|
+
close() {
|
|
140
|
+
if (this._cp) {
|
|
141
|
+
this._cp.send(JSON.stringify({ method: 'close' }));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
kill() {
|
|
145
|
+
if (this._cp) {
|
|
146
|
+
this._cp.kill();
|
|
147
|
+
this._cp = null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
class MPPackDevCompiler extends AbstractCompiler {
|
|
152
|
+
constructor(props, args) {
|
|
153
|
+
super(props, args);
|
|
154
|
+
this.pending = false;
|
|
155
|
+
this.pendingPkgs = {};
|
|
156
|
+
this.readyPkgs = [];
|
|
157
|
+
this.watching = false;
|
|
158
|
+
this.inspectPort = 9227;
|
|
159
|
+
this.createSp();
|
|
160
|
+
}
|
|
161
|
+
reset() {
|
|
162
|
+
this.pendingPkgs = {};
|
|
163
|
+
this.readyPkgs = [];
|
|
164
|
+
this.watching = false;
|
|
165
|
+
this.pending = false;
|
|
166
|
+
}
|
|
167
|
+
doCompilePkgs(opts) {
|
|
168
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
169
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
const { compilePkgs = [constant_config_1.MAIN_PKG_ROOT] } = opts;
|
|
171
|
+
const todoPkgs = [];
|
|
172
|
+
let allReady = true;
|
|
173
|
+
compilePkgs.forEach(pkg => {
|
|
174
|
+
var _a, _b;
|
|
175
|
+
if (this.readyPkgs.includes(pkg)) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
allReady = false;
|
|
179
|
+
if (this.pendingPkgs[pkg]) {
|
|
180
|
+
(_a = this.pendingPkgs[pkg].resolve) === null || _a === void 0 ? void 0 : _a.push(resolve);
|
|
181
|
+
(_b = this.pendingPkgs[pkg].reject) === null || _b === void 0 ? void 0 : _b.push(reject);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.pendingPkgs[pkg] = {
|
|
185
|
+
resolve: [resolve],
|
|
186
|
+
reject: [reject],
|
|
187
|
+
};
|
|
188
|
+
todoPkgs.push(pkg);
|
|
189
|
+
});
|
|
190
|
+
if (allReady) {
|
|
191
|
+
return resolve(null);
|
|
192
|
+
}
|
|
193
|
+
if (!todoPkgs.length) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
if (!this.pending && !this.watching) {
|
|
198
|
+
yield this.compilePkgsAndWatch(Object.assign({ compilePkgs: todoPkgs }, opts));
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
yield this.addPkgsToWatch(Object.assign({ compilePkgs }, opts));
|
|
202
|
+
}
|
|
203
|
+
todoPkgs.forEach(pkg => {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
(_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());
|
|
206
|
+
delete this.pendingPkgs[pkg];
|
|
207
|
+
this.readyPkgs.push(pkg);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
todoPkgs.forEach(pkg => {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
(_b = (_a = this.pendingPkgs[pkg].reject) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, fn => fn());
|
|
214
|
+
delete this.pendingPkgs[pkg];
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
compilePkgsAndWatch(opts) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
try {
|
|
222
|
+
// if (this.pending || this.watching) {
|
|
223
|
+
// return
|
|
224
|
+
// }
|
|
225
|
+
this.pending = true;
|
|
226
|
+
this.emit('buildStart');
|
|
227
|
+
yield this.call('runTask', Object.assign({ scene: 'watch', action: 'dev' }, opts));
|
|
228
|
+
this.watching = true;
|
|
229
|
+
this.emit('buildSuccess');
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
this.watching = false;
|
|
233
|
+
this.emit('buildError', error);
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
this.pending = false;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
addPkgsToWatch(opts) {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
const { compilePkgs = [] } = opts;
|
|
243
|
+
try {
|
|
244
|
+
this.pending = true;
|
|
245
|
+
this.emit('buildStart');
|
|
246
|
+
yield this.call('activatePkgs', { compilePkgs });
|
|
247
|
+
this.emit('buildSuccess');
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
this.emit('buildError', error);
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
this.pending = false;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
changeCompileOptions(options) {
|
|
258
|
+
this.call('changeCompileOptions', options);
|
|
259
|
+
}
|
|
260
|
+
makePkgsReady(opts) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
yield this.doCompilePkgs(opts);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
reCompilePkgs(options) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
this.readyPkgs = [];
|
|
268
|
+
this.changeCompileOptions(options);
|
|
269
|
+
if (!this.pending && !this.watching) {
|
|
270
|
+
this.pendingPkgs = {};
|
|
271
|
+
}
|
|
272
|
+
yield this.doCompilePkgs(options);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
class WebPackDevCompiler extends AbstractCompiler {
|
|
277
|
+
constructor(props) {
|
|
278
|
+
super(props);
|
|
279
|
+
this.watching = false;
|
|
280
|
+
this.inspectPort = 9230;
|
|
281
|
+
this.createSp();
|
|
282
|
+
}
|
|
283
|
+
makePkgsReady(opts) {
|
|
284
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
285
|
+
var _a, _b, _c, _d;
|
|
286
|
+
if (this.watching) {
|
|
287
|
+
return resolve(null);
|
|
288
|
+
}
|
|
289
|
+
if (this.pendingTask) {
|
|
290
|
+
(_a = this.pendingTask.resolve) === null || _a === void 0 ? void 0 : _a.push(resolve);
|
|
291
|
+
(_b = this.pendingTask.reject) === null || _b === void 0 ? void 0 : _b.push(reject);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
this.pendingTask = {
|
|
295
|
+
resolve: [resolve],
|
|
296
|
+
reject: [reject]
|
|
297
|
+
};
|
|
298
|
+
try {
|
|
299
|
+
this.emit('buildStart');
|
|
300
|
+
yield this.call('runTask', Object.assign({ scene: 'watch', action: 'dev' }, opts));
|
|
301
|
+
this.watching = true;
|
|
302
|
+
(_c = this.pendingTask.resolve) === null || _c === void 0 ? void 0 : _c.forEach((fn) => fn());
|
|
303
|
+
this.emit('buildSuccess');
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
this.watching = false;
|
|
307
|
+
(_d = this.pendingTask.reject) === null || _d === void 0 ? void 0 : _d.forEach((fn) => fn());
|
|
308
|
+
this.kill();
|
|
309
|
+
this.emit('buildError', error);
|
|
310
|
+
}
|
|
311
|
+
finally {
|
|
312
|
+
this.pendingTask = undefined;
|
|
313
|
+
}
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
316
|
+
reCompilePkgs(opts) {
|
|
317
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
318
|
+
if (!this.watching) {
|
|
319
|
+
yield this.makePkgsReady(opts);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
this.emit('buildStart');
|
|
324
|
+
yield this.call('runTask', Object.assign({ action: 'dev', scene: 'reWatch' }, opts));
|
|
325
|
+
this.emit('buildSuccess');
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
this.emit('buildError', error);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
class BuildCompiler extends AbstractCompiler {
|
|
334
|
+
constructor(props, args) {
|
|
335
|
+
super(props, args);
|
|
336
|
+
this.cps = [];
|
|
337
|
+
this.inspectPort = 9228;
|
|
338
|
+
this.createSp();
|
|
339
|
+
}
|
|
340
|
+
build(option) {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
try {
|
|
343
|
+
const res = yield this.call('runTask', Object.assign({ action: 'build' }, option));
|
|
344
|
+
return res;
|
|
345
|
+
}
|
|
346
|
+
finally {
|
|
347
|
+
// 进程不退出,手动kill下
|
|
348
|
+
this.kill();
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function getProcessCompilerClass(compilerType) {
|
|
354
|
+
const CompilerClass = compilerType === constant_config_1.COMPILER_TYPE.legacy_dev
|
|
355
|
+
? WebPackDevCompiler
|
|
356
|
+
: compilerType === constant_config_1.COMPILER_TYPE.dev
|
|
357
|
+
? MPPackDevCompiler
|
|
358
|
+
: BuildCompiler;
|
|
359
|
+
return CompilerClass;
|
|
360
|
+
}
|
|
361
|
+
exports.getProcessCompilerClass = getProcessCompilerClass;
|