UNPKG

@tarojs/service

Version:
73 lines 2.9 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Transaction = void 0; const VALID_COMPILER = ['webpack5', 'vite']; const DEFAULT_COMPILER = 'webpack5'; class Transaction { constructor() { this.wrappers = []; } perform(fn, scope, ...args) { return __awaiter(this, void 0, void 0, function* () { this.initAll(scope); yield fn.call(scope, ...args); this.closeAll(scope); }); } initAll(scope) { const wrappers = this.wrappers; wrappers.forEach(wrapper => { var _a; return (_a = wrapper.init) === null || _a === void 0 ? void 0 : _a.call(scope); }); } closeAll(scope) { const wrappers = this.wrappers; wrappers.forEach(wrapper => { var _a; return (_a = wrapper.close) === null || _a === void 0 ? void 0 : _a.call(scope); }); } addWrapper(wrapper) { this.wrappers.push(wrapper); } } exports.Transaction = Transaction; class TaroPlatform { constructor(ctx, config) { this.setupTransaction = new Transaction(); this.buildTransaction = new Transaction(); this.ctx = ctx; this.helper = ctx.helper; this.config = config; this.updateOutputPath(config); const _compiler = config.compiler; this.compiler = typeof _compiler === 'object' ? _compiler.type : _compiler; // Note: 兼容 webpack4 和不填写 compiler 的情况,默认使用 webpack5 if (!VALID_COMPILER.includes(this.compiler)) { this.compiler = DEFAULT_COMPILER; } } getConfig() { return this.config; } emptyOutputDir(excludes = []) { const { outputPath } = this.ctx.paths; this.helper.emptyDirectory(outputPath, { excludes }); } /** * 如果分端编译详情 webpack 配置了 output 则需更新 outputPath 位置 */ updateOutputPath(config) { var _a; const platformPath = (_a = config.output) === null || _a === void 0 ? void 0 : _a.path; if (platformPath) { this.ctx.paths.outputPath = platformPath; } } } exports.default = TaroPlatform; //# sourceMappingURL=platform.js.map