xhs-mp-compiler-cli 1.1.3 → 1.1.5
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.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-build.js +40 -0
- package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-dev.js +59 -0
- package/dist/bin/xhs-mp-cli.d.ts +2 -0
- package/dist/bin/xhs-mp-cli.js +16 -0
- package/dist/compiler.d.ts +76 -0
- package/dist/compiler.js +361 -0
- package/dist/compilerCP.d.ts +1 -0
- package/dist/compilerCP.js +175 -0
- package/dist/config/constant.config.d.ts +27 -0
- package/dist/config/constant.config.js +30 -0
- package/dist/config/dir.config.d.ts +3 -0
- package/dist/config/dir.config.js +16 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +454 -0
- 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/dev-server/index.d.ts +3 -0
- package/dist/packs/webpack/dev-server/index.js +64 -0
- package/dist/packs/webpack/dev-server/lib/ensurePort.d.ts +2 -0
- package/dist/packs/webpack/dev-server/lib/ensurePort.js +32 -0
- package/dist/packs/webpack/dev-server/lib/openBrowser.d.ts +2 -0
- package/dist/packs/webpack/dev-server/lib/openBrowser.js +23 -0
- package/dist/packs/webpack/dev-server/lib/openChrome.applescript +78 -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/presets/babel.d.ts +8 -0
- package/dist/presets/babel.js +59 -0
- package/dist/presets/common.d.ts +4 -0
- package/dist/presets/common.js +48 -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/presets/configs/minigame/service/resolveLimitPlugin.d.ts +8 -0
- 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/presets/configs/minigame/service/serviceEntryPlugin.d.ts +10 -0
- 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 +71 -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/presets/configs/miniprogram/render/renderChunkPlugin.js +55 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
- package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +163 -0
- 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/presets/configs/miniprogram/service/resolveLimitPlugin.js +66 -0
- 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.d.ts +1 -0
- package/dist/presets/loaders/mg-entry-loader.js +27 -0
- package/dist/presets/loaders/mini-style-loader.d.ts +1 -0
- package/dist/presets/loaders/mini-style-loader.js +72 -0
- package/dist/presets/loaders/mp-entry-loader.d.ts +1 -0
- package/dist/presets/loaders/mp-entry-loader.js +196 -0
- package/dist/presets/loaders/sjs-loader/index.d.ts +12 -0
- package/dist/presets/loaders/sjs-loader/index.js +605 -0
- package/dist/presets/loaders/sjs-loader/scope.d.ts +36 -0
- package/dist/presets/loaders/sjs-loader/scope.js +122 -0
- package/dist/presets/loaders/sjs-loader/tranform.d.ts +2 -0
- package/dist/presets/loaders/sjs-loader/tranform.js +31 -0
- package/dist/presets/loaders/wxss-loader.d.ts +1 -0
- package/dist/presets/loaders/wxss-loader.js +77 -0
- 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 +118 -0
- package/dist/types/index.js +13 -0
- package/dist/utils/asyncWebpack.d.ts +3 -0
- package/dist/utils/asyncWebpack.js +38 -0
- package/dist/utils/common.d.ts +8 -0
- package/dist/utils/common.js +36 -0
- package/dist/utils/const.d.ts +27 -0
- package/dist/utils/const.js +47 -0
- package/dist/utils/css.d.ts +2 -0
- package/dist/utils/css.js +41 -0
- package/dist/utils/depenedHelper.d.ts +31 -0
- package/dist/utils/depenedHelper.js +89 -0
- package/dist/utils/file.d.ts +2 -0
- package/dist/utils/file.js +67 -0
- package/dist/utils/getSuffixName.d.ts +3 -0
- package/dist/utils/getSuffixName.js +18 -0
- package/dist/utils/loader-utils.d.ts +15 -0
- package/dist/utils/loader-utils.js +59 -0
- package/dist/utils/postcssRpx2Vw.d.ts +12 -0
- package/dist/utils/postcssRpx2Vw.js +35 -0
- package/dist/utils/project.d.ts +27 -0
- package/dist/utils/project.js +164 -0
- package/dist/utils/projectConfig.d.ts +1 -0
- package/dist/utils/projectConfig.js +20 -0
- package/dist/utils/tagTransformMap.d.ts +35 -0
- package/dist/utils/tagTransformMap.js +38 -0
- package/dist/utils/utils.d.ts +7 -0
- package/dist/utils/utils.js +50 -0
- package/dist/utils/zip.d.ts +28 -0
- package/dist/utils/zip.js +287 -0
- package/package.json +6 -6
package/dist/index.js
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
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.Compiler = exports.getProcessCompilerClass = exports.COMPILE_ENTRY = void 0;
|
|
16
|
+
const constant_config_1 = require("./config/constant.config");
|
|
17
|
+
Object.defineProperty(exports, "COMPILE_ENTRY", { enumerable: true, get: function () { return constant_config_1.COMPILE_ENTRY; } });
|
|
18
|
+
const xhs_mp_project_1 = require("xhs-mp-project");
|
|
19
|
+
const events_1 = __importDefault(require("events"));
|
|
20
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
21
|
+
const path_1 = __importDefault(require("path"));
|
|
22
|
+
const utils_1 = require("./utils/utils");
|
|
23
|
+
const zip_1 = require("./utils/zip");
|
|
24
|
+
const project_1 = require("./utils/project");
|
|
25
|
+
const dir_config_1 = require("./config/dir.config");
|
|
26
|
+
const compiler_1 = require("./compiler");
|
|
27
|
+
Object.defineProperty(exports, "getProcessCompilerClass", { enumerable: true, get: function () { return compiler_1.getProcessCompilerClass; } });
|
|
28
|
+
class Compiler extends events_1.default {
|
|
29
|
+
constructor(props) {
|
|
30
|
+
super();
|
|
31
|
+
this.compilerImplMap = {};
|
|
32
|
+
this.initSimulatorCompiler = compiler => {
|
|
33
|
+
compiler.on('buildStart', data => {
|
|
34
|
+
this.emit('buildStart', data);
|
|
35
|
+
});
|
|
36
|
+
compiler.on('buildSuccess', data => {
|
|
37
|
+
this.emit('buildSuccess', data);
|
|
38
|
+
});
|
|
39
|
+
compiler.on('buildError', data => {
|
|
40
|
+
this.emit('buildError', data);
|
|
41
|
+
});
|
|
42
|
+
compiler.on('compileFinishWhenFileChange', data => {
|
|
43
|
+
this.emit('compileFinishWhenFileChange', data);
|
|
44
|
+
});
|
|
45
|
+
compiler.on('emitCompileStats', data => {
|
|
46
|
+
this.emit('emitCompileStats', data);
|
|
47
|
+
});
|
|
48
|
+
compiler.on('unexpectedExit', data => {
|
|
49
|
+
this.emit('unexpectedExit', data);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
this.initBuildCompiler = compiler => {
|
|
53
|
+
compiler.on('compilePercent', data => {
|
|
54
|
+
this.emit('compilePercent', data);
|
|
55
|
+
});
|
|
56
|
+
compiler.on('emitCompileStats', data => {
|
|
57
|
+
this.emit('emitCompileStats', data);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
this.getComilerImpl = (entryType = constant_config_1.COMPILE_ENTRY.simulator) => {
|
|
61
|
+
const compilerType = this.getCompilerType(entryType);
|
|
62
|
+
if (!this.compilerImplMap[compilerType]) {
|
|
63
|
+
this.compilerImplMap[compilerType] = this.createCompilerImpl(entryType);
|
|
64
|
+
if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
|
|
65
|
+
this.initSimulatorCompiler(this.compilerImplMap[compilerType]);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.initBuildCompiler(this.compilerImplMap[compilerType]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return this.compilerImplMap[compilerType];
|
|
72
|
+
};
|
|
73
|
+
const { logger } = props;
|
|
74
|
+
this.logger = logger || console;
|
|
75
|
+
this.compilerProps = props;
|
|
76
|
+
this.project = this.createProject(props);
|
|
77
|
+
this.projectPath = this.project.projectPath;
|
|
78
|
+
}
|
|
79
|
+
createProject(props) {
|
|
80
|
+
const { projectPath, project } = props;
|
|
81
|
+
return (project ||
|
|
82
|
+
new xhs_mp_project_1.Project({
|
|
83
|
+
projectPath
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
getCompilerDir() {
|
|
87
|
+
let compileDirPath;
|
|
88
|
+
let compileCachePath;
|
|
89
|
+
const { compileDir } = this.compilerProps;
|
|
90
|
+
if (compileDir) {
|
|
91
|
+
compileDirPath = path_1.default.join(compileDir, 'xhs-mp-baba');
|
|
92
|
+
compileCachePath = path_1.default.join(compileDir, 'xhs-compile-cache');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
compileDirPath = dir_config_1.mpCompileDirPath;
|
|
96
|
+
compileCachePath = dir_config_1.mpCompileCachePath;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
mpCompileDirPath: compileDirPath,
|
|
100
|
+
mpCompileCachePath: compileCachePath
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// 使用的编译目标包类型
|
|
104
|
+
getUsingPackageType() {
|
|
105
|
+
return __awaiter(this, arguments, void 0, function* (entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
const { libFeatures } = this.compilerProps;
|
|
108
|
+
let enableV1 = false;
|
|
109
|
+
let enableV2 = true;
|
|
110
|
+
let enableVDom = false;
|
|
111
|
+
const settings = this.project.settings || {};
|
|
112
|
+
const isUpload = entryType === constant_config_1.COMPILE_ENTRY.upload;
|
|
113
|
+
if (this.project.appMode === constant_config_1.MiniMode.minigame) {
|
|
114
|
+
enableV1 = true;
|
|
115
|
+
enableV2 = false;
|
|
116
|
+
enableVDom = false;
|
|
117
|
+
}
|
|
118
|
+
else if (entryType === constant_config_1.COMPILE_ENTRY.simulator) {
|
|
119
|
+
const supportV2 = (_a = libFeatures === null || libFeatures === void 0 ? void 0 : libFeatures.supportV2) !== null && _a !== void 0 ? _a : true;
|
|
120
|
+
const supportVDom = (_b = libFeatures === null || libFeatures === void 0 ? void 0 : libFeatures.supportVdom) !== null && _b !== void 0 ? _b : true;
|
|
121
|
+
// 模拟器预览模式下,按照基础库是否支持相关功能 + 用户是否勾选进行判断
|
|
122
|
+
enableV2 = supportV2 && settings.enableV2;
|
|
123
|
+
// 开启v2不编译vdom
|
|
124
|
+
enableVDom = !enableV2 && supportVDom && settings.enableVDom;
|
|
125
|
+
// enableVDom = !enableV2 && settings.enableVDom
|
|
126
|
+
enableV1 = !enableV2;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// 上传模式下按照勾选开启
|
|
130
|
+
enableVDom = settings.enableVDom;
|
|
131
|
+
enableV2 = settings.enableV2;
|
|
132
|
+
enableV1 = true;
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
enableV1,
|
|
136
|
+
enableV2,
|
|
137
|
+
enableVDom
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// 根据使用的场景或者配置,采用不同的compiler类型
|
|
142
|
+
getCompilerType(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
143
|
+
const isGame = this.project.appMode === constant_config_1.MiniMode.minigame;
|
|
144
|
+
const settings = this.project.projectJsonContent.setting || {};
|
|
145
|
+
// 使用旧编译
|
|
146
|
+
if (isGame || !settings.useNewCompiler) {
|
|
147
|
+
return entryType === constant_config_1.COMPILE_ENTRY.simulator ? constant_config_1.COMPILER_TYPE.legacy_dev : constant_config_1.COMPILER_TYPE.legacy_build;
|
|
148
|
+
}
|
|
149
|
+
// 使用新编译
|
|
150
|
+
return entryType === constant_config_1.COMPILE_ENTRY.simulator
|
|
151
|
+
? constant_config_1.COMPILER_TYPE.dev
|
|
152
|
+
: entryType === constant_config_1.COMPILE_ENTRY.upload
|
|
153
|
+
? constant_config_1.COMPILER_TYPE.legacy_build
|
|
154
|
+
: constant_config_1.COMPILER_TYPE.build;
|
|
155
|
+
}
|
|
156
|
+
getDistDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
157
|
+
const { mpCompileDirPath } = this.getCompilerDir();
|
|
158
|
+
const compilerType = this.getCompilerType(entryType);
|
|
159
|
+
const basename = path_1.default.basename(this.project.projectPath);
|
|
160
|
+
const hash = (0, utils_1.getMd5)(this.project.projectPath).slice(0, 8);
|
|
161
|
+
const distDir = path_1.default.join(path_1.default.resolve(mpCompileDirPath, `${basename}_${hash}`), compilerType);
|
|
162
|
+
fs_extra_1.default.ensureDirSync(distDir);
|
|
163
|
+
return distDir;
|
|
164
|
+
}
|
|
165
|
+
removeDistDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
166
|
+
const distDir = this.getDistDir(entryType);
|
|
167
|
+
if (fs_extra_1.default.existsSync(distDir)) {
|
|
168
|
+
fs_extra_1.default.removeSync(distDir);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
getCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
172
|
+
const { mpCompileCachePath } = this.getCompilerDir();
|
|
173
|
+
const compilerType = this.getCompilerType(entryType);
|
|
174
|
+
const basename = path_1.default.basename(this.project.projectPath);
|
|
175
|
+
const hash = (0, utils_1.getMd5)(this.project.projectPath).slice(0, 8);
|
|
176
|
+
const distDir = path_1.default.join(path_1.default.resolve(mpCompileCachePath, `${basename}_${hash}`), compilerType);
|
|
177
|
+
fs_extra_1.default.ensureDirSync(distDir);
|
|
178
|
+
return distDir;
|
|
179
|
+
}
|
|
180
|
+
removeCacheDir(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
181
|
+
const cacheDir = this.getCacheDir(entryType);
|
|
182
|
+
if (fs_extra_1.default.existsSync(cacheDir)) {
|
|
183
|
+
fs_extra_1.default.removeSync(cacheDir);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
createCompilerImpl(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
187
|
+
const { nodeJsPath, mpDevJsonPath } = this.compilerProps;
|
|
188
|
+
const { mpCompileDirPath } = this.getCompilerDir();
|
|
189
|
+
const distDir = this.getDistDir(entryType);
|
|
190
|
+
const cacheDir = this.getCacheDir(entryType);
|
|
191
|
+
const compilerType = this.getCompilerType(entryType);
|
|
192
|
+
const packMode = compilerType === constant_config_1.COMPILER_TYPE.legacy_dev || compilerType === constant_config_1.COMPILER_TYPE.legacy_build
|
|
193
|
+
? 'webpack'
|
|
194
|
+
: 'mp-pack';
|
|
195
|
+
const options = {
|
|
196
|
+
packMode,
|
|
197
|
+
projectPath: this.project.projectPath,
|
|
198
|
+
appMode: this.project.appMode,
|
|
199
|
+
extJsonPath: this.project.extJsonDir,
|
|
200
|
+
platform: 'xhs',
|
|
201
|
+
distDir,
|
|
202
|
+
cacheDirectory: cacheDir
|
|
203
|
+
};
|
|
204
|
+
this.removeDistDir(entryType);
|
|
205
|
+
this.removeCacheDir(entryType);
|
|
206
|
+
const CompilerClass = (0, compiler_1.getProcessCompilerClass)(compilerType);
|
|
207
|
+
const compilerImpl = new CompilerClass(options, {
|
|
208
|
+
logger: this.logger,
|
|
209
|
+
nodeJsPath
|
|
210
|
+
});
|
|
211
|
+
return compilerImpl;
|
|
212
|
+
}
|
|
213
|
+
makePkgsReady(config) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
const entryType = constant_config_1.COMPILE_ENTRY.simulator;
|
|
216
|
+
const compilerImpl = this.getComilerImpl(entryType);
|
|
217
|
+
yield compilerImpl.makePkgsReady(config);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
reCompilePkgs(config) {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
const entryType = constant_config_1.COMPILE_ENTRY.simulator;
|
|
223
|
+
const compilerImpl = this.getComilerImpl(entryType);
|
|
224
|
+
yield compilerImpl.reCompilePkgs(config);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
compileProject(config) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
var _a, _b, _c;
|
|
230
|
+
try {
|
|
231
|
+
const { entryType, compressJs, enableSourcemap, enableV2, enableV1, enableVDom } = config;
|
|
232
|
+
this.emit('compile-project-start');
|
|
233
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log('Compile project...');
|
|
234
|
+
const compilerImpl = this.getComilerImpl(entryType);
|
|
235
|
+
yield compilerImpl.build({
|
|
236
|
+
compressJs,
|
|
237
|
+
enableSourcemap,
|
|
238
|
+
enableV2,
|
|
239
|
+
enableV1,
|
|
240
|
+
enableVDom
|
|
241
|
+
});
|
|
242
|
+
this.emit('compile-project-done');
|
|
243
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log('Compile project done');
|
|
244
|
+
}
|
|
245
|
+
catch (stats) {
|
|
246
|
+
let error;
|
|
247
|
+
if (stats instanceof Error) {
|
|
248
|
+
error = stats;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
const { errors } = stats || {};
|
|
252
|
+
error = new Error(errors.join('\n\n'));
|
|
253
|
+
}
|
|
254
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.log('Compile project failed', error);
|
|
255
|
+
this.emit('compile-project-fail', error);
|
|
256
|
+
throw error;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
compileAndZip(opts) {
|
|
261
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
const { can_upload_ext_json, upload_app_id, entryType } = opts;
|
|
263
|
+
try {
|
|
264
|
+
const appJsonContent = this.project.appJsonContent;
|
|
265
|
+
const settings = this.project.settings || {};
|
|
266
|
+
let subPackages = appJsonContent.subPackages || appJsonContent.subpackages || [];
|
|
267
|
+
const formatGameAppJSON = this.project.formatGameAppJSON;
|
|
268
|
+
subPackages =
|
|
269
|
+
this.project.appMode === constant_config_1.MiniMode.miniprogram ? subPackages : formatGameAppJSON(subPackages);
|
|
270
|
+
const { enableV2, enableV1, enableVDom } = yield this.getUsingPackageType(entryType);
|
|
271
|
+
let compressJs = false;
|
|
272
|
+
let enableSourcemap = true;
|
|
273
|
+
if (entryType === constant_config_1.COMPILE_ENTRY.upload || entryType === constant_config_1.COMPILE_ENTRY.preview) {
|
|
274
|
+
compressJs = true;
|
|
275
|
+
enableSourcemap = false;
|
|
276
|
+
}
|
|
277
|
+
else if (settings.hasOwnProperty('minified')) {
|
|
278
|
+
compressJs = settings.minified;
|
|
279
|
+
}
|
|
280
|
+
const buildConfig = {
|
|
281
|
+
entryType,
|
|
282
|
+
compressJs,
|
|
283
|
+
enableSourcemap,
|
|
284
|
+
enableV2,
|
|
285
|
+
enableV1,
|
|
286
|
+
enableVDom
|
|
287
|
+
};
|
|
288
|
+
// 编译
|
|
289
|
+
this.emit('compile-and-zip-status', { status: 'build-start' });
|
|
290
|
+
yield this.compileProject(buildConfig);
|
|
291
|
+
this.emit('compile-and-zip-status', { status: 'build-done' });
|
|
292
|
+
// 生成zip
|
|
293
|
+
this.emit('compile-and-zip-status', { status: 'zip-start' });
|
|
294
|
+
let entryZips = [];
|
|
295
|
+
if (entryType === constant_config_1.COMPILE_ENTRY.preview || entryType === constant_config_1.COMPILE_ENTRY.upload) {
|
|
296
|
+
entryZips = [
|
|
297
|
+
this.zipWithFullPackage(opts, subPackages, 'v0'),
|
|
298
|
+
this.zipWithSubPackage(opts, subPackages, 'v1'),
|
|
299
|
+
// 小程序模式有v2包
|
|
300
|
+
enableV2 && this.zipWithSubPackage(opts, subPackages, 'v2')
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
// 真机调试
|
|
305
|
+
// eslint-disable-next-line no-lonely-if
|
|
306
|
+
if (!subPackages.length) {
|
|
307
|
+
// 真机调试整包zip内产物文件需要放在appid目录下
|
|
308
|
+
entryZips = [this.zipWithFullPackageWithAppId(opts, subPackages, 'v0')];
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
// eslint-disable-next-line no-lonely-if
|
|
312
|
+
if (enableV2) {
|
|
313
|
+
entryZips = [this.zipWithSubPackage(opts, subPackages, 'v2')];
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
entryZips = [this.zipWithSubPackage(opts, subPackages, 'v1')];
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const zipTask = yield Promise.all(entryZips.filter(Boolean));
|
|
321
|
+
const zipResult = zipTask.flat(2);
|
|
322
|
+
this.emit('compile-and-zip-status', { status: 'zip-done' });
|
|
323
|
+
// change ext
|
|
324
|
+
if (entryType === constant_config_1.COMPILE_ENTRY.preview || entryType === constant_config_1.COMPILE_ENTRY.upload) {
|
|
325
|
+
this.project.changeExtJsonPermission(!!can_upload_ext_json);
|
|
326
|
+
}
|
|
327
|
+
resolve(zipResult);
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
reject(error);
|
|
331
|
+
}
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
zipWithFullPackageWithAppId(opts_1) {
|
|
335
|
+
return __awaiter(this, arguments, void 0, function* (opts, subPackages = [], type) {
|
|
336
|
+
const { entryType } = opts;
|
|
337
|
+
const buildDir = this.getDistDir(entryType);
|
|
338
|
+
const distFullZip = path_1.default.resolve(buildDir, 'v0-full-pack.zip');
|
|
339
|
+
const srcDirPath = path_1.default.resolve(buildDir, !subPackages.length ? 'v1' : 'v0'); // 如果没有开启分包,则把v1包当作v0包
|
|
340
|
+
return (0, zip_1.genZip)(srcDirPath, distFullZip, this.project.projectAppId);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
/* 使用v0的入口,zip整包 */
|
|
344
|
+
zipWithFullPackage(opts_1) {
|
|
345
|
+
return __awaiter(this, arguments, void 0, function* (opts, subPackages = [], type) {
|
|
346
|
+
const project = this.project;
|
|
347
|
+
const { upload_app_id, can_upload_ext_json, pkgInfo, entryType } = opts;
|
|
348
|
+
const buildDir = this.getDistDir(entryType);
|
|
349
|
+
const appendFile = [];
|
|
350
|
+
const appendBuffer = [];
|
|
351
|
+
appendFile.push(project.projectJsonPath); // zip添加project.config.json
|
|
352
|
+
/* 是否需要上传ext.json */
|
|
353
|
+
if (can_upload_ext_json && fs_extra_1.default.existsSync(project.extJsonPath)) {
|
|
354
|
+
appendFile.push(project.extJsonPath);
|
|
355
|
+
}
|
|
356
|
+
if (pkgInfo) {
|
|
357
|
+
/* 是否需要额外添加pkgInfo.json信息 */
|
|
358
|
+
const content = { version: pkgInfo.version };
|
|
359
|
+
const contentStr = JSON.stringify(content);
|
|
360
|
+
appendBuffer.push({
|
|
361
|
+
name: 'pkgInfo.json',
|
|
362
|
+
buffer: Buffer.from(contentStr, 'utf-8')
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
const zipConfig = {
|
|
366
|
+
outputDir: path_1.default.resolve(buildDir, `${type}-full-pack.zip`), // 输出的路径
|
|
367
|
+
type,
|
|
368
|
+
inputDir: path_1.default.resolve(buildDir, !subPackages.length ? 'v1' : 'v0' // 如果没有开启分包,则把v1包当作v0包
|
|
369
|
+
), // 输入的路径
|
|
370
|
+
ignore: [],
|
|
371
|
+
prefix: upload_app_id,
|
|
372
|
+
appendFile,
|
|
373
|
+
appendBuffer,
|
|
374
|
+
meta: {
|
|
375
|
+
root: ''
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
return (0, project_1.zipFactory)(zipConfig);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
/* 使用v1的入口。zip主包和分包 */
|
|
382
|
+
zipWithSubPackage(opts, subPackages, type) {
|
|
383
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
384
|
+
const project = this.project;
|
|
385
|
+
const { can_upload_ext_json, pkgInfo, entryType } = opts;
|
|
386
|
+
const isRemoteDebug = entryType === constant_config_1.COMPILE_ENTRY.remotedebug;
|
|
387
|
+
const appendFile = []; // 额外的文件
|
|
388
|
+
const appendBuffer = [];
|
|
389
|
+
appendFile.push(project.projectJsonPath); // zip添加project.config.json
|
|
390
|
+
const buildDir = this.getDistDir(entryType);
|
|
391
|
+
const mainEntry = path_1.default.resolve(buildDir, type);
|
|
392
|
+
const mainIgnore = (subPackages || []).map(item => item.root.endsWith('/') ? `${item.root}**` : `${item.root}/**`); // 主包里需要忽略分包的路径
|
|
393
|
+
/* 是否需要上传ext.json */
|
|
394
|
+
if (can_upload_ext_json && fs_extra_1.default.existsSync(project.extJsonPath)) {
|
|
395
|
+
appendFile.push(project.extJsonPath);
|
|
396
|
+
}
|
|
397
|
+
if (pkgInfo) {
|
|
398
|
+
/* 是否需要额外添加pkgInfo.json信息 */
|
|
399
|
+
const content = { version: pkgInfo.version };
|
|
400
|
+
const contentStr = JSON.stringify(content);
|
|
401
|
+
appendBuffer.push({
|
|
402
|
+
name: 'pkgInfo.json',
|
|
403
|
+
buffer: Buffer.from(contentStr, 'utf-8')
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/* 分包的zip配置 */
|
|
407
|
+
const zipConfig = [
|
|
408
|
+
{
|
|
409
|
+
outputDir: path_1.default.resolve(buildDir, `${type}-main-pack.zip`), // 输出的路径
|
|
410
|
+
type,
|
|
411
|
+
inputDir: mainEntry, // 输入的路径
|
|
412
|
+
ignore: mainIgnore,
|
|
413
|
+
prefix: '',
|
|
414
|
+
appendFile,
|
|
415
|
+
appendBuffer,
|
|
416
|
+
meta: {
|
|
417
|
+
root: '/'
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
...(subPackages || []).map((item, index) => {
|
|
421
|
+
const pkgRoot = item.root.replace(/\//g, constant_config_1.PKG_ROOT_SEP);
|
|
422
|
+
return {
|
|
423
|
+
outputDir: path_1.default.resolve(buildDir, `${type}-sub-pack-${isRemoteDebug ? pkgRoot : index}.zip`),
|
|
424
|
+
type,
|
|
425
|
+
inputDir: path_1.default.resolve(buildDir, type, item.root),
|
|
426
|
+
ignore: [],
|
|
427
|
+
prefix: `${item.root}`,
|
|
428
|
+
meta: {
|
|
429
|
+
root: item.root
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
})
|
|
433
|
+
];
|
|
434
|
+
return Promise.all(zipConfig.map(config => (0, project_1.zipFactory)(config)));
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
close(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
438
|
+
const compilerType = this.getCompilerType(entryType);
|
|
439
|
+
const compiler = this.compilerImplMap[compilerType];
|
|
440
|
+
if (compiler) {
|
|
441
|
+
compiler.close();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
kill(entryType = constant_config_1.COMPILE_ENTRY.simulator) {
|
|
445
|
+
const compilerType = this.getCompilerType(entryType);
|
|
446
|
+
const compiler = this.compilerImplMap[compilerType];
|
|
447
|
+
if (!compiler) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
compiler.kill();
|
|
451
|
+
delete this.compilerImplMap[entryType];
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
exports.Compiler = Compiler;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Compilation, RawSource, CopyPatterns, Config, ConcatSource, MPPackSetting } from 'xhs-mp-pack';
|
|
2
|
+
import { Configuration, WebpackError, library, LoaderContext } from 'webpack';
|
|
3
|
+
import type { Project } from 'xhs-mp-project';
|
|
4
|
+
import { IStart } from '../types';
|
|
5
|
+
export type ICompilation = any;
|
|
6
|
+
export type ICompiler = any;
|
|
7
|
+
export type ILoaderContext = LoaderContext<any> & {
|
|
8
|
+
_compiler: {
|
|
9
|
+
project: Project;
|
|
10
|
+
packSetting: MPPackSetting;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export { Compilation, RawSource, ConcatSource, CopyPatterns, Config, Configuration, WebpackError, library, LoaderContext };
|
|
14
|
+
export declare function createCompiler(startConfig: IStart): ICompiler;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createCompiler = exports.library = exports.WebpackError = exports.Config = exports.CopyPatterns = exports.ConcatSource = exports.RawSource = exports.Compilation = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* 抹平差异:抹平webpack和mp-pack的差异
|
|
9
|
+
* 统一收口,所有对webpack和mp-pack的调用都走这个出口,不可用直接调用
|
|
10
|
+
*/
|
|
11
|
+
const webpack_1 = require("./webpack");
|
|
12
|
+
const mp_pack_1 = require("./mp-pack");
|
|
13
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
14
|
+
Object.defineProperty(exports, "Compilation", { enumerable: true, get: function () { return xhs_mp_pack_1.Compilation; } });
|
|
15
|
+
Object.defineProperty(exports, "RawSource", { enumerable: true, get: function () { return xhs_mp_pack_1.RawSource; } });
|
|
16
|
+
Object.defineProperty(exports, "CopyPatterns", { enumerable: true, get: function () { return xhs_mp_pack_1.CopyPatterns; } });
|
|
17
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return xhs_mp_pack_1.Config; } });
|
|
18
|
+
Object.defineProperty(exports, "ConcatSource", { enumerable: true, get: function () { return xhs_mp_pack_1.ConcatSource; } });
|
|
19
|
+
const webpack_2 = require("webpack");
|
|
20
|
+
Object.defineProperty(exports, "WebpackError", { enumerable: true, get: function () { return webpack_2.WebpackError; } });
|
|
21
|
+
Object.defineProperty(exports, "library", { enumerable: true, get: function () { return webpack_2.library; } });
|
|
22
|
+
const const_1 = __importDefault(require("../utils/const"));
|
|
23
|
+
const { PACK_MODE } = const_1.default;
|
|
24
|
+
function createCompiler(startConfig) {
|
|
25
|
+
const { packMode = PACK_MODE.MPPACK } = startConfig;
|
|
26
|
+
if (packMode === PACK_MODE.WEBPACK) {
|
|
27
|
+
return (0, webpack_1.createCompiler)(startConfig);
|
|
28
|
+
}
|
|
29
|
+
return (0, mp_pack_1.createCompiler)(startConfig);
|
|
30
|
+
}
|
|
31
|
+
exports.createCompiler = createCompiler;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createCompiler = void 0;
|
|
7
|
+
const presets_1 = require("../../presets");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const xhs_mp_pack_1 = require("xhs-mp-pack");
|
|
10
|
+
const dev_server_1 = __importDefault(require("../webpack/dev-server"));
|
|
11
|
+
const createCompiler = (startConfig) => {
|
|
12
|
+
const { action, enableDevServer } = startConfig;
|
|
13
|
+
const mppack = new xhs_mp_pack_1.MPPack(startConfig);
|
|
14
|
+
const compilerOptions = {
|
|
15
|
+
project: mppack.project,
|
|
16
|
+
packSetting: mppack.packSetting
|
|
17
|
+
};
|
|
18
|
+
const mpPackConfigs = (0, presets_1.createConfigs)(compilerOptions);
|
|
19
|
+
mpPackConfigs.forEach(config => {
|
|
20
|
+
var _a, _b, _c, _d;
|
|
21
|
+
/* 修改在ide里的node_modules的路径 */
|
|
22
|
+
(_b = (_a = config.resolve) === null || _a === void 0 ? void 0 : _a.modules) === null || _b === void 0 ? void 0 : _b.push(path_1.default.resolve(__dirname, '../../../'));
|
|
23
|
+
// cli的node_modules路径
|
|
24
|
+
(_d = (_c = config.resolve) === null || _c === void 0 ? void 0 : _c.modules) === null || _d === void 0 ? void 0 : _d.push(path_1.default.resolve(__dirname, '../../'));
|
|
25
|
+
});
|
|
26
|
+
if (action === 'dev' && enableDevServer) {
|
|
27
|
+
return (0, dev_server_1.default)(compilerOptions);
|
|
28
|
+
}
|
|
29
|
+
mppack.createCompiler(mpPackConfigs);
|
|
30
|
+
return mppack;
|
|
31
|
+
};
|
|
32
|
+
exports.createCompiler = createCompiler;
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
17
|
+
const ensurePort_1 = __importDefault(require("./lib/ensurePort"));
|
|
18
|
+
const openBrowser_1 = __importDefault(require("./lib/openBrowser"));
|
|
19
|
+
const presets_1 = require("../../../presets");
|
|
20
|
+
const devServer = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const { packSetting } = config;
|
|
22
|
+
const { devServerPort, distDir } = packSetting;
|
|
23
|
+
const webpackConfigs = (0, presets_1.createConfigs)(config);
|
|
24
|
+
const compiler = (0, webpack_1.default)(webpackConfigs);
|
|
25
|
+
const host = 'localhost';
|
|
26
|
+
const devServerConfig = {
|
|
27
|
+
open: false,
|
|
28
|
+
historyApiFallback: true,
|
|
29
|
+
port: devServerPort || 1388,
|
|
30
|
+
hot: false,
|
|
31
|
+
static: [
|
|
32
|
+
// emulator entry 地址
|
|
33
|
+
path_1.default.resolve('node_modules/@xhs/mp-simulator/dist'),
|
|
34
|
+
path_1.default.resolve('node_modules/@xhs/mp-js-core/dist'),
|
|
35
|
+
...JSON.parse(process.env.XHS_MP_LIB || '[]'), // 自定义地址
|
|
36
|
+
distDir,
|
|
37
|
+
],
|
|
38
|
+
client: {
|
|
39
|
+
logging: 'error',
|
|
40
|
+
overlay: false,
|
|
41
|
+
progress: false,
|
|
42
|
+
},
|
|
43
|
+
// firewall: false,
|
|
44
|
+
headers: {
|
|
45
|
+
'Access-Control-Allow-Origin': '*',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
// 检查端口是否被占用,若占用会修改 devServerConfig.port
|
|
49
|
+
yield (0, ensurePort_1.default)(devServerConfig);
|
|
50
|
+
const Server = require('webpack-dev-server');
|
|
51
|
+
const server = new Server(compiler, Object.assign(Object.assign({}, devServerConfig), { open: false }));
|
|
52
|
+
server.listen(devServerConfig.port, host, () => { });
|
|
53
|
+
let isBrowserOpened = false;
|
|
54
|
+
compiler.hooks.done.tap('xhs-mp-cli', stats => {
|
|
55
|
+
if (stats.hasErrors()) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (devServerConfig.open && !isBrowserOpened) {
|
|
59
|
+
isBrowserOpened = true;
|
|
60
|
+
(0, openBrowser_1.default)(host, devServerConfig.port);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
exports.default = devServer;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// @ts-nocheck
|
|
7
|
+
const net_1 = __importDefault(require("net"));
|
|
8
|
+
const ensurePort = (devServerConfig) => new Promise(res => {
|
|
9
|
+
const checkPort = () => {
|
|
10
|
+
const server = net_1.default.createServer().listen(devServerConfig.port, devServerConfig.client.host);
|
|
11
|
+
server.on('listening', () => {
|
|
12
|
+
server.close();
|
|
13
|
+
res(1);
|
|
14
|
+
});
|
|
15
|
+
server.on('error', err => {
|
|
16
|
+
if (err.code === 'EADDRINUSE') {
|
|
17
|
+
devServerConfig.port += 1;
|
|
18
|
+
checkPort(devServerConfig);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
try {
|
|
23
|
+
checkPort();
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
if (err.code === 'EADDRINUSE') {
|
|
27
|
+
devServerConfig.port += 1;
|
|
28
|
+
checkPort(devServerConfig);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
exports.default = ensurePort;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const open_1 = __importDefault(require("open"));
|
|
8
|
+
// eslint-disable-next-line consistent-return
|
|
9
|
+
const openBrowser = (host, port) => {
|
|
10
|
+
const url = `http://${host}:${port}`;
|
|
11
|
+
try {
|
|
12
|
+
(0, child_process_1.execSync)(`osascript ${__dirname}/openChrome.applescript ${encodeURI(url)}`, {
|
|
13
|
+
stdio: 'ignore',
|
|
14
|
+
});
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
// Ignore errors.
|
|
19
|
+
}
|
|
20
|
+
// fallback to normal open
|
|
21
|
+
(0, open_1.default)(url);
|
|
22
|
+
};
|
|
23
|
+
exports.default = openBrowser;
|