beesbuild
Version:
构建工具链
131 lines (130 loc) • 4.27 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, 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 __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var stdin_exports = {};
__export(stdin_exports, {
arrayIncludes: () => arrayIncludes,
getpkg: () => getpkg,
hasDefaultExport: () => hasDefaultExport,
pathRewriter: () => pathRewriter,
resolveAliases: () => resolveAliases
});
module.exports = __toCommonJS(stdin_exports);
var import_utils = require("@beesbuild/utils");
var import_mlly = require("mlly");
var import_lodash_unified = require("lodash-unified");
var import_variables = require("./variables.cjs");
function pathRewriter(ctx, module2) {
var _a;
const manifest = ctx.pkg;
const config = (_a = (0, import_utils.getBuildConfig)({
rootDir: ctx.options.rootDir,
outDir: ctx.options.outDir,
rollup: ctx.options.rollup,
manifest
}).find(v => v[0] === module2)) == null ? void 0 : _a.at(1);
return id => {
id = id.replaceAll(`${manifest.name}/theme-chalk`, `${ctx.options.name}/theme-chalk`);
id = id.replaceAll(`${manifest.name}/`, `${config == null ? void 0 : config.bundle.path}/`);
return id;
};
}
function arrayIncludes(arr, searchElement) {
return arr.some(entry => entry instanceof RegExp ? entry.test(searchElement) : entry === searchElement);
}
function getpkg(id = "") {
const s = id.split("/");
return s[0][0] === "@" ? `${s[0]}/${s[1]}` : s[0];
}
function resolveAliases(ctx, flag = true) {
var _a;
const rollup = ctx.options.rollup;
const pkg = ctx.pkg;
const rollupAlias = rollup.alias;
const replaceAlias = (_a = ctx.options.replace) == null ? void 0 : _a.alias;
const alias = ctx.options.alias;
const aliases1 = {};
const aliases = [];
if (pkg.name) {
aliases.push({
find: pkg.name,
replacement: ctx.options.rootDir
});
}
function plusAlias(alias2) {
if (alias2 && (0, import_lodash_unified.isPlainObject)(alias2)) {
for (const [find, replacement] of Object.entries(alias2)) {
if ((0, import_lodash_unified.isString)(replacement)) {
aliases.push({
find,
replacement
});
if ((0, import_lodash_unified.isString)(find)) aliases1[find] = replacement;
}
}
} else if (Array.isArray(alias2)) {
for (const value of alias2) {
const {
find,
replacement
} = value;
if ((0, import_lodash_unified.isString)(replacement)) {
aliases.push(value);
if ((0, import_lodash_unified.isString)(find)) {
aliases1[find] = replacement;
}
}
}
}
}
plusAlias(alias);
plusAlias(replaceAlias);
if (rollupAlias && (0, import_lodash_unified.isPlainObject)(rollupAlias)) {
plusAlias((0, import_lodash_unified.omit)(rollupAlias != null ? rollupAlias : {}, "entries", "customResolver"));
plusAlias(rollupAlias.entries);
}
if (flag) {
return aliases1;
}
return aliases.reverse();
}
const hasDefaultExport = async resolvedEntry => {
if (resolvedEntry) {
const namedExports = await (0, import_mlly.resolveModuleExportNames)(resolvedEntry, {
extensions: import_variables.DEFAULT_EXTENSIONS
}).catch(error => {
import_utils.consola.warn(`Cannot analyze ${resolvedEntry} for exports:${error}`);
return [];
});
return namedExports.includes("default") || namedExports.length === 0;
}
return false;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
arrayIncludes,
getpkg,
hasDefaultExport,
pathRewriter,
resolveAliases
});