|
| 1 | +"use strict"; |
| 2 | +var __defProp = Object.defineProperty; |
| 3 | +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 4 | +var __getOwnPropNames = Object.getOwnPropertyNames; |
| 5 | +var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 6 | +var __export = (target, all) => { |
| 7 | + for (var name in all) |
| 8 | + __defProp(target, name, { get: all[name], enumerable: true }); |
| 9 | +}; |
| 10 | +var __copyProps = (to, from, except, desc) => { |
| 11 | + if (from && typeof from === "object" || typeof from === "function") { |
| 12 | + for (let key of __getOwnPropNames(from)) |
| 13 | + if (!__hasOwnProp.call(to, key) && key !== except) |
| 14 | + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 15 | + } |
| 16 | + return to; |
| 17 | +}; |
| 18 | +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
| 19 | + |
| 20 | +// src/builder/main.ts |
| 21 | +var main_exports = {}; |
| 22 | +__export(main_exports, { |
| 23 | + Bundle: () => Bundle, |
| 24 | + GenerateDts: () => GenerateDts |
| 25 | +}); |
| 26 | +module.exports = __toCommonJS(main_exports); |
| 27 | + |
| 28 | +// src/builder/lib/bundle.ts |
| 29 | +var import_esbuild = require("esbuild"); |
| 30 | +async function Bundle(config) { |
| 31 | + if (!config.targets?.length) { |
| 32 | + console.warn("\x1B[33m\u26A0\uFE0F No bundle targets provided.\x1B[0m"); |
| 33 | + return false; |
| 34 | + } |
| 35 | + for (const target of config.targets) { |
| 36 | + const variants = target.variant ?? ["esm"]; |
| 37 | + for (const v of variants) { |
| 38 | + const esbuildOpts = { |
| 39 | + entryPoints: [target.entry], |
| 40 | + outfile: target.outfile.replace(/\.js$/, `.${v}.js`), |
| 41 | + format: v, |
| 42 | + platform: target.options.plateform, |
| 43 | + tsconfig: target.options.tsconfig, |
| 44 | + bundle: true, |
| 45 | + minify: !!target.options.minify, |
| 46 | + minifySyntax: target.options.minifySyntax ?? void 0, |
| 47 | + minifyWhitespace: target.options.minifyWhitespace ?? void 0, |
| 48 | + minifyIdentifiers: target.options.minifyIdentifiers ?? void 0, |
| 49 | + ...target.extraOpts ?? {} |
| 50 | + }; |
| 51 | + console.log( |
| 52 | + `\x1B[36m\u27A1\uFE0F Building\x1B[0m \x1B[1m${target.entry}\x1B[0m \u2192 \x1B[32m${esbuildOpts.outfile}\x1B[0m (\x1B[35m${v}\x1B[0m)` |
| 53 | + ); |
| 54 | + try { |
| 55 | + await (0, import_esbuild.build)(esbuildOpts); |
| 56 | + console.log( |
| 57 | + `\x1B[32m\u2705 Successfully built\x1B[0m ${target.entry} \u2192 ${esbuildOpts.outfile}` |
| 58 | + ); |
| 59 | + } catch (err) { |
| 60 | + console.error("\x1B[31m\u274C Bundle step failed:\x1B[0m", err); |
| 61 | + return false; |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + return true; |
| 66 | +} |
| 67 | + |
| 68 | +// src/builder/lib/dts.ts |
| 69 | +var import_tsup = require("tsup"); |
| 70 | +async function GenerateDts(config) { |
| 71 | + if (!config.entry || !config.outfile) { |
| 72 | + console.warn("\x1B[33m\u26A0\uFE0F DTS step requires entry and outfile.\x1B[0m"); |
| 73 | + return false; |
| 74 | + } |
| 75 | + console.log( |
| 76 | + `\x1B[36m\u27A1\uFE0F Generating DTS\x1B[0m \x1B[1m${config.entry}\x1B[0m \u2192 \x1B[32m${config.outfile}\x1B[0m` |
| 77 | + ); |
| 78 | + const tsupOptions = { |
| 79 | + entry: [config.entry], |
| 80 | + dts: true, |
| 81 | + outDir: config.outfile.replace(/\/?[^/]+$/, ""), |
| 82 | + format: ["cjs", "esm"], |
| 83 | + minify: false, |
| 84 | + clean: false, |
| 85 | + tsconfig: config.tsconfig, |
| 86 | + splitting: false |
| 87 | + // optional, |
| 88 | + }; |
| 89 | + try { |
| 90 | + await (0, import_tsup.build)(tsupOptions); |
| 91 | + console.log(`\x1B[32m\u2705 Declaration file generated:\x1B[0m ${config.outfile}`); |
| 92 | + } catch (err) { |
| 93 | + console.error("\x1B[31m\u274C DTS generation failed:\x1B[0m", err); |
| 94 | + return false; |
| 95 | + } |
| 96 | + return true; |
| 97 | +} |
| 98 | +// Annotate the CommonJS export names for ESM import in node: |
| 99 | +0 && (module.exports = { |
| 100 | + Bundle, |
| 101 | + GenerateDts |
| 102 | +}); |
0 commit comments