UNPKG

beesbuild

Version:

构建工具链

132 lines (131 loc) 5.07 kB
"use strict"; 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 = (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 __toESM = (mod, isNodeMode, target) => (target = 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(target, "default", { value: mod, enumerable: true }) : target, mod)); var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var stdin_exports = {}; __export(stdin_exports, { FILE_EXT: () => FILE_EXT, handleBuildFiles: () => handleBuildFiles, handleTypeOption: () => handleTypeOption }); module.exports = __toCommonJS(stdin_exports); var import_path = __toESM(require("path")); var import_fast_glob = __toESM(require("fast-glob")); var import_utils = require("@beesbuild/utils"); var import_lodash_unified = require("lodash-unified"); var import_defu = require("defu"); var import_variables = require("../variables.cjs"); const FILE_EXT = ["js", "ts", "mjs", "cjs", "jsx", "vue"]; const handleBuildFiles = (ctx, options) => { var _a; let prefix = typeof (options == null ? void 0 : options.filePrefix) === "string" ? options == null ? void 0 : options.filePrefix : "src/"; if (!prefix.endsWith("/")) { prefix = import_path.default.join(prefix, "/"); } let fileExt = [...FILE_EXT]; if ((0, import_lodash_unified.isString)(options == null ? void 0 : options.ext)) { fileExt.push(...options.ext.split(",")); fileExt = fileExt.filter(value => (0, import_lodash_unified.isString)(value) && Boolean(value.trim())); } const rootDir = ctx.options.rootDir; const ext = fileExt.length > 0 ? `.{${fileExt.join(",")}}` : ""; const source = [`${import_utils.pathExtra.join(prefix)}/**/*${ext}`].concat(import_variables.EXCLUDE_FILES); if (fileExt.length > 0) source.push(`index${ext}`); ((_a = ctx.argv) == null ? void 0 : _a.debug) && import_utils.consola.info(source, "source"); const files = (0, import_lodash_unified.sortBy)(import_fast_glob.default.sync(source, { cwd: ctx.options.rootDir, absolute: true, onlyFiles: true }).filter(Boolean), dir => dir.split("/").length); const entryFiles = fileExt.map(ext2 => `index.${ext2}`).concat(fileExt.map(ext2 => import_path.default.join("src", `index.${ext2}`))).map(str => import_path.default.resolve(rootDir, ".", str)); const fIndex = files.findIndex(dir => entryFiles.includes(dir)); if (fIndex > -1) { const entryFile = files[fIndex]; files.splice(fIndex, 1, { input: entryFile, isEntry: true }); } return files; }; function handleTypeOption(ctx) { const rootDir = ctx.options.rootDir; const output = { path: import_path.default.resolve(rootDir, "types"), name: "types" }; const tsconfigPath = import_path.default.resolve(rootDir, "tsconfig.json"); const typesCacheDir = import_path.default.resolve(rootDir, ".", import_variables.BUILD_CACHE_DIR, output.name); const entries = ctx.options.entries; const entryFile = entries.find(({ isEntry }) => isEntry); const entryFilepath = (entryFile == null ? void 0 : entryFile.input) && import_path.default.resolve(rootDir, ".", entryFile.input); let outRootDir = import_path.default.resolve(rootDir, "src"); const noSrcFiles = entries.find(({ input }) => !input.startsWith(outRootDir)); if (noSrcFiles) outRootDir = import_path.default.join(rootDir); const isVue = false; const compilerOptions = (0, import_defu.defu)({ emitDeclarationOnly: true, preserveSymlinks: true, skipLibCheck: true, noImplicitAny: false, verbatimModuleSyntax: true, forceConsistentCasingInFileNames: true, disableSizeLimit: true, maxNodeModuleJsDepth: 100, rootDir, // rootDir: outRootDir, declarationDir: typesCacheDir }); return { isVue, outRootDir, typesCacheDir, entryFilepath, compilerOptions, tsconfigPath, tsConfigFilePath: tsconfigPath, rootDir, entries, output }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { FILE_EXT, handleBuildFiles, handleTypeOption });