beesbuild
Version:
构建工具链
152 lines (151 loc) • 5.34 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target2, all) => {
for (var name in all) __defProp(target2, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", {
value: mod,
enumerable: true
}) : target2, mod));
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var stdin_exports = {};
__export(stdin_exports, {
getBuildContext: () => getBuildContext
});
module.exports = __toCommonJS(stdin_exports);
var import_path = __toESM(require("path"));
var import_node_module = __toESM(require("node:module"));
var import_defu = require("defu");
var import_lodash_unified = require("lodash-unified");
var import_hookable = require("hookable");
var import_utils = require("@beesbuild/utils");
function beesBuildOption() {
return {
name: "default",
rootDir: process.cwd(),
entries: [],
clean: false,
declaration: false,
sourcemap: false,
minify: false,
stub: false,
outDir: ".",
externals: [...import_node_module.default.builtinModules, ...import_node_module.default.builtinModules.map(m => `node:${m}`)],
dependencies: [],
devDependencies: [],
peerDependencies: [],
alias: {},
replace: {},
stubOptions: {
jiti: {
esmResolve: true,
interopDefault: true,
alias: {}
}
},
failOnWarn: true,
rollup: {
vue: false,
emitCJS: true,
cjsBridge: true,
inlineDependencies: false,
preserveDynamicImports: true,
// Plugins
replace: {
preventAssignment: true
},
alias: {},
resolve: {
preferBuiltins: true
},
json: {
preferConst: true
},
commonjs: {
ignoreTryCatch: true
},
esbuild: {
target: import_utils.target,
minify: false,
drop: ["console", "debugger"]
},
dts: {
// https://github.com/Swatinem/rollup-plugin-dts/issues/143
compilerOptions: {
preserveSymlinks: false
},
respectExternal: true
}
}
};
}
async function getBuildContext(buildConfig, pkg) {
var _a, _b, _c, _d, _e;
const _options = beesBuildOption();
const rootDir = (pkg == null ? void 0 : pkg.path) || (buildConfig == null ? void 0 : buildConfig.rootDir) || _options.rootDir;
if (!(pkg == null ? void 0 : pkg.buildConfig) || !(pkg == null ? void 0 : pkg.bin)) {
const pkgPath = (_a = pkg == null ? void 0 : pkg.path) != null ? _a : rootDir;
pkg = (0, import_defu.defu)((0, import_utils.getPackageManifest)(import_path.default.resolve(pkgPath, ".", "package.json")), pkg != null ? pkg : {});
}
const _buildConfig = (0, import_utils.tryRequire)("./build.config", rootDir) || {};
const buildConfig_ = (Array.isArray(_buildConfig) ? _buildConfig : [_buildConfig]).find(Boolean);
const name = pkg.name.split("/").pop() || _options.name;
const options = (0, import_lodash_unified.mergeWith)(_options, buildConfig != null ? buildConfig : {}, (_b = pkg.unbuild || pkg.buildConfig || pkg.build) != null ? _b : {}, (0, import_lodash_unified.omit)(buildConfig_, "entries"), {
rootDir,
name
});
if (!((_c = options == null ? void 0 : options.rollup) == null ? void 0 : _c.vue)) {
const dependencies = [...Object.keys((_d = pkg.dependencies) != null ? _d : {}), ...Object.keys((_e = pkg.peerDependencies) != null ? _e : {})];
options.rollup.vue = dependencies.includes("vue");
}
if (!options.rootDir) {
options.rootDir = process.cwd();
}
if (options.rollup.esbuild && options.rollup.esbuild.minify) {
options.minify = false;
}
if (options.minify && options.rollup.esbuild) {
options.rollup.esbuild.minify = false;
}
options.outDir = import_path.default.resolve(rootDir, (options == null ? void 0 : options.outDir) || ".");
const ctx = {
uid: Symbol((0, import_lodash_unified.uniqueId)(name)),
options,
argv: buildConfig,
warnings: /* @__PURE__ */new Set(),
pkg,
buildEntries: [],
usedImports: /* @__PURE__ */new Set(),
hooks: (0, import_hookable.createHooks)(),
caches: /* @__PURE__ */new Set()
};
return ctx;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getBuildContext
});