bunup 0.1.5 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import X from"path";import E from"fs";import $ from"path";import _ from"oxc-transform";import{rollup as T}from"rollup";import q from"rollup-plugin-dts";var h=(r)=>{if(r instanceof Error)return r.message;return String(r)};function v(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function p(r,s){switch(r){case"esm":return".d.mts";case"cjs":return N(s)?".d.cts":".d.ts";case"iife":return".d.ts"}}function N(r){return r==="module"}function x(r){if(!r)return[];return Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})]))}function C(r){return r.map((s)=>typeof s==="string"?new RegExp(`^${v(s)}($|\\/|\\\\)`):s)}function j(r,s){return C(r.external||[]).concat(x(s).map((e)=>new RegExp(`^${v(e)}($|\\/|\\\\)`)))}function m(r){return C(r.noExternal||[])}import B from"fs";import y from"path";var f={MAX_LABEL_LENGTH:5,colors:{cli:"183",info:"240",warn:"221",error:"203",progress:{ESM:"214",CJS:"114",IIFE:"105",DTS:"75"},default:"255"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(r,s,e){let o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-s.length));return`\x1B[38;5;${r}m[${s}]\x1B[0m ${o}${e}`},cli(r){let s=this.labels.cli;console.log(this.formatMessage(this.colors.cli,s,r))},info(r){let s=this.labels.info;console.log(this.formatMessage(this.colors.info,s,r))},warn(r){let s=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,s,r))},error(r){let s=this.labels.error;console.error(this.formatMessage(this.colors.error,s,r))},progress(r,s){let e=String(r),o=this.colors.default;for(let[t,i]of Object.entries(this.colors.progress))if(e.includes(t)){o=i;break}console.log(this.formatMessage(o,e,s))}};function O(r,s){return`${s?`${s.replace(/-/g,"_")}_`:""}${r}`.toUpperCase()}function D(r){let s=y.join(r,"package.json");try{if(!B.existsSync(s))return null;let e=B.readFileSync(s,"utf8");return JSON.parse(e)}catch(e){return f.error(`Failed to load package.json at ${s}: ${h(e)}`),null}}async function A(r,s,e,o){let{absoluteRootDir:t,absoluteEntry:i}=H(r,s),n=await U(i),k=await Q(n);return G(i,k,e,o,t)}async function U(r){let s=new Set,e=[r];while(e.length>0){let o=e.pop();if(!o||s.has(o))continue;s.add(o);try{let t=await E.promises.readFile(o,"utf8"),i=z(t);for(let n of i){let k=$.dirname(o),g=$.resolve(k,n),l=[g,`${g}.ts`,`${g}.tsx`,`${g}/index.ts`,`${g}/index.tsx`];for(let u of l)if(E.existsSync(u)&&u.endsWith(".ts")&&!s.has(u)){e.push(u);break}}}catch(t){f.warn(`Error processing ${o}: ${t instanceof Error?t.message:String(t)}`)}}return s}function z(r){let s=new Set;try{let e=/(?:import|export)(?:(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*)|[\s\n]+)(["'`])([^'"]+)\1/g,o;while((o=e.exec(r))!==null){let n=o[2];if(n.startsWith("."))s.add(n)}let t=/import\s+(["'`])([^'"]+)\1\s*;?/g;while((o=t.exec(r))!==null){let n=o[2];if(n.startsWith("."))s.add(n)}let i=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;while((o=i.exec(r))!==null){let n=o[2];if(n.startsWith("."))s.add(n)}}catch(e){f.warn(`Error extracting imports: ${e instanceof Error?e.message:String(e)}`)}return Array.from(s)}async function Q(r){let s=new Map;return await Promise.all(Array.from(r).map(async(e)=>{try{let o=e.replace(/\.tsx?$/,".d.ts"),t=await E.promises.readFile(e,"utf8"),{code:i}=_.isolatedDeclaration(e,t);if(i)s.set(o,i)}catch(o){f.warn(`Failed to generate declaration for ${e}: ${o instanceof Error?o.message:String(o)}`)}})),s}async function G(r,s,e,o,t){let k=`\x00virtual:${r.replace(/\.tsx?$/,".d.ts")}`,g={name:"virtual-dts",resolveId(c,a){if(c.startsWith("\x00virtual:"))return c;if(a?.startsWith("\x00virtual:")){let W=a.slice(9),M=$.dirname(W);if(c.startsWith(".")){let R=$.resolve(M,c);for(let L of["",".d.ts","/index.d.ts"]){let d=`${R}${L}`;if(s.has(d))return`\x00virtual:${d}`}}}return null},load(c){if(c.startsWith("\x00virtual:")){let a=c.slice(9);return s.get(a)||null}return null}},l=D(t),u=j(o,l),S=m(o),w;try{w=await T({input:k,onwarn(a,W){if(a.code==="UNRESOLVED_IMPORT"||a.code==="CIRCULAR_DEPENDENCY"||a.code==="EMPTY_BUNDLE")return;W(a)},plugins:[g,q()],external:(a)=>u.some((W)=>W.test(a))&&!S.some((W)=>W.test(a))});let{output:c}=await w.generate({format:e});if(!c[0]?.code)throw new Error("Generated bundle is empty");return c[0].code}catch(c){throw new Error(`DTS bundling failed: ${h(c)}`)}finally{if(w)await w.close()}}function H(r,s){let e=$.resolve(r),o=$.resolve(e,s);if(!E.existsSync(e))throw new Error(`Root directory does not exist: ${e}`);if(!E.existsSync(o))throw new Error(`Entry file does not exist: ${o}`);if(!o.endsWith(".ts"))throw new Error(`Entry file must be a TypeScript file (.ts): ${o}`);if($.relative(e,o).startsWith(".."))throw new Error(`Entry file must be within rootDir: ${o}`);return{absoluteRootDir:e,absoluteEntry:o}}var __dirname="/home/runner/work/bunup/bunup/src/dts";self.onmessage=async(r)=>{let{name:s,rootDir:e,outDir:o,entry:t,format:i,packageType:n,options:k}=r.data;try{let g=await A(e,t.path,i,k),l=p(i,n),u=`${o}/${t.name}${l}`,S=`${e}/${u}`;await Bun.write(S,g);let w={name:s,success:!0,outputRelativePath:u};self.postMessage(w)}catch(g){let l={success:!1,error:h(g)};self.postMessage(l)}};class K{workers=[];queue=[];maxWorkers;busyWorkers=new Set;isShuttingDown=!1;constructor(r=navigator.hardwareConcurrency||4){this.maxWorkers=r}async process(r){if(this.isShuttingDown)throw new Error("Worker pool is shutting down");return new Promise((s,e)=>{this.queue.push({task:r,resolve:s,reject:e}),this.processQueue()})}processQueue(){if(this.queue.length===0||this.isShuttingDown)return;if(this.workers.length<this.maxWorkers){let r=new Worker(X.join(__dirname,"./dtsWorker.js"));this.workers.push(r),this.assignTaskToWorker(r)}else{let r=this.workers.find((s)=>!this.busyWorkers.has(s));if(r)this.assignTaskToWorker(r)}}assignTaskToWorker(r){let s=this.queue.shift();if(!s)return;let{task:e,resolve:o,reject:t}=s;this.busyWorkers.add(r);let i=()=>{if(this.busyWorkers.delete(r),this.isShuttingDown&&this.busyWorkers.size===0)this.terminateAllWorkers();else this.processQueue()};r.onmessage=(n)=>{if(n.data.success)f.progress(O("DTS",n.data.name),n.data.outputRelativePath),o();else f.error(`DTS generation failed: ${n.data.error}`),t(new Error(n.data.error));i()},r.onerror=(n)=>{let k=h(n);f.error(`Worker error: ${k}`),t(n),i()},r.postMessage(e)}terminateAllWorkers(){this.workers.forEach((r)=>{try{r.terminate()}catch(s){f.error(`Error terminating worker: ${h(s)}`)}}),this.workers=[],this.busyWorkers.clear()}async cleanup(){if(this.isShuttingDown=!0,this.busyWorkers.size===0){this.terminateAllWorkers();return}return new Promise((r)=>{let s=setInterval(()=>{if(this.busyWorkers.size===0)clearInterval(s),this.terminateAllWorkers(),r()},100);setTimeout(()=>{clearInterval(s),this.terminateAllWorkers(),r()},5000)})}}export{K as DtsWorker};
package/build/index.d.mts CHANGED
@@ -1,89 +1,135 @@
1
- type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
1
+ type WithOptional<
2
+ T,
3
+ K extends keyof T
4
+ > = Omit<T, K> & Partial<Pick<T, K>>;
2
5
 
3
- type Format = 'esm' | 'cjs' | 'iife';
4
- type Target = 'bun' | 'node' | 'browser';
6
+ type Format = "esm" | "cjs" | "iife";
7
+ type Target = "bun" | "node" | "browser";
5
8
  type External = string[];
6
- type Entry = string | Record<string, string>;
9
+ type Entry = string[] | Record<string, string>;
10
+ type DtsOptions = {
11
+ /**
12
+ * Entry point files for TypeScript declaration file generation
13
+ *
14
+ * This can be:
15
+ * - An array of file paths
16
+ * - An object where keys are output names and values are input file paths
17
+ *
18
+ * The key names are used for the generated declaration files.
19
+ * For example, {custom: './src/index.ts'} will generate custom.d.ts
20
+ *
21
+ * If not specified, the main entry points will be used for declaration file generation.
22
+ *
23
+ * If a string path is provided in an array, the file name (without extension)
24
+ * will be used as the name for the output declaration file.
25
+ *
26
+ * @example
27
+ * // Using string paths in an array
28
+ * entry: ['./src/index.ts'] // Generates index.d.ts
29
+ *
30
+ * // Using named outputs as an object
31
+ * entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
32
+ */
33
+ entry: Entry
34
+ };
7
35
  interface BunupOptions {
8
- /**
9
- * Name of the build configuration
10
- * Used for logging and identification purposes
11
- */
12
- name?: string;
13
- /**
14
- * Entry point files for the build
15
- * These are the files that will be processed and bundled
16
- */
17
- entry: Entry[];
18
- /**
19
- * Output directory for the bundled files
20
- * Defaults to 'dist' if not specified
21
- */
22
- outDir: string;
23
- /**
24
- * Output formats for the bundle
25
- * Can include 'esm', 'cjs', and/or 'iife'
26
- * Defaults to ['esm'] if not specified
27
- */
28
- format: Format[];
29
- /**
30
- * Whether to enable all minification options
31
- * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
32
- */
33
- minify?: boolean;
34
- /**
35
- * Whether to enable code splitting
36
- * Defaults to true for ESM format, false for CJS format
37
- */
38
- splitting?: boolean;
39
- /**
40
- * Whether to minify whitespace in the output
41
- * Removes unnecessary whitespace to reduce file size
42
- */
43
- minifyWhitespace?: boolean;
44
- /**
45
- * Whether to minify identifiers in the output
46
- * Renames variables and functions to shorter names
47
- */
48
- minifyIdentifiers?: boolean;
49
- /**
50
- * Whether to minify syntax in the output
51
- * Optimizes code structure for smaller file size
52
- */
53
- minifySyntax?: boolean;
54
- /**
55
- * Whether to watch for file changes and rebuild automatically
56
- */
57
- watch?: boolean;
58
- /**
59
- * Whether to generate TypeScript declaration files (.d.ts)
60
- */
61
- dts?: boolean;
62
- /**
63
- * External packages that should not be bundled
64
- * Useful for dependencies that should be kept as external imports
65
- */
66
- external?: External;
67
- /**
68
- * Packages that should be bundled even if they are in external
69
- * Useful for dependencies that should be included in the bundle
70
- */
71
- noExternal?: External;
72
- /**
73
- * The target environment for the bundle
74
- * Can be 'browser', 'bun', 'node', etc.
75
- * Defaults to 'node' if not specified
76
- */
77
- target?: Target;
78
- /**
79
- * Whether to clean the output directory before building
80
- * When true, removes all files in the outDir before starting a new build
81
- * Defaults to true if not specified
82
- */
83
- clean?: boolean;
36
+ /**
37
+ * Name of the build configuration
38
+ * Used for logging and identification purposes
39
+ */
40
+ name?: string;
41
+ /**
42
+ * Entry point files for the build
43
+ *
44
+ * This can be:
45
+ * - An array of file paths
46
+ * - An object where keys are output names and values are input file paths
47
+ *
48
+ * The key names are used for the generated output files.
49
+ * For example, {custom: './src/index.ts'} will generate custom.js
50
+ *
51
+ * If a string path is provided in an array, the file name (without extension)
52
+ * will be used as the name for the output file.
53
+ *
54
+ * @example
55
+ * // Using string paths in an array
56
+ * entry: ['./src/index.ts'] // Generates index.js
57
+ *
58
+ * // Using named outputs as an object
59
+ * entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.js and utils.js
60
+ */
61
+ entry: Entry;
62
+ /**
63
+ * Output directory for the bundled files
64
+ * Defaults to 'dist' if not specified
65
+ */
66
+ outDir: string;
67
+ /**
68
+ * Output formats for the bundle
69
+ * Can include 'esm', 'cjs', and/or 'iife'
70
+ * Defaults to ['esm'] if not specified
71
+ */
72
+ format: Format[];
73
+ /**
74
+ * Whether to enable all minification options
75
+ * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
76
+ */
77
+ minify?: boolean;
78
+ /**
79
+ * Whether to enable code splitting
80
+ * Defaults to true for ESM format, false for CJS format
81
+ */
82
+ splitting?: boolean;
83
+ /**
84
+ * Whether to minify whitespace in the output
85
+ * Removes unnecessary whitespace to reduce file size
86
+ */
87
+ minifyWhitespace?: boolean;
88
+ /**
89
+ * Whether to minify identifiers in the output
90
+ * Renames variables and functions to shorter names
91
+ */
92
+ minifyIdentifiers?: boolean;
93
+ /**
94
+ * Whether to minify syntax in the output
95
+ * Optimizes code structure for smaller file size
96
+ */
97
+ minifySyntax?: boolean;
98
+ /**
99
+ * Whether to watch for file changes and rebuild automatically
100
+ */
101
+ watch?: boolean;
102
+ /**
103
+ * Whether to generate TypeScript declaration files (.d.ts)
104
+ * When set to true, generates declaration files for all entry points
105
+ * Can also be configured with DtsOptions for more control
106
+ */
107
+ dts?: boolean | DtsOptions;
108
+ /**
109
+ * External packages that should not be bundled
110
+ * Useful for dependencies that should be kept as external imports
111
+ */
112
+ external?: External;
113
+ /**
114
+ * Packages that should be bundled even if they are in external
115
+ * Useful for dependencies that should be included in the bundle
116
+ */
117
+ noExternal?: External;
118
+ /**
119
+ * The target environment for the bundle
120
+ * Can be 'browser', 'bun', 'node', etc.
121
+ * Defaults to 'node' if not specified
122
+ */
123
+ target?: Target;
124
+ /**
125
+ * Whether to clean the output directory before building
126
+ * When true, removes all files in the outDir before starting a new build
127
+ * Defaults to true if not specified
128
+ */
129
+ clean?: boolean;
84
130
  }
85
131
 
86
- type DefineConfigOption = WithOptional<BunupOptions, 'outDir' | 'format'>;
132
+ type DefineConfigOption = WithOptional<BunupOptions, "outDir" | "format">;
87
133
  type DefineConfigOptions = DefineConfigOption | DefineConfigOption[];
88
134
  declare function defineConfig(options: DefineConfigOptions): DefineConfigOptions;
89
135
 
package/build/index.d.ts CHANGED
@@ -1,89 +1,135 @@
1
- type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
1
+ type WithOptional<
2
+ T,
3
+ K extends keyof T
4
+ > = Omit<T, K> & Partial<Pick<T, K>>;
2
5
 
3
- type Format = 'esm' | 'cjs' | 'iife';
4
- type Target = 'bun' | 'node' | 'browser';
6
+ type Format = "esm" | "cjs" | "iife";
7
+ type Target = "bun" | "node" | "browser";
5
8
  type External = string[];
6
- type Entry = string | Record<string, string>;
9
+ type Entry = string[] | Record<string, string>;
10
+ type DtsOptions = {
11
+ /**
12
+ * Entry point files for TypeScript declaration file generation
13
+ *
14
+ * This can be:
15
+ * - An array of file paths
16
+ * - An object where keys are output names and values are input file paths
17
+ *
18
+ * The key names are used for the generated declaration files.
19
+ * For example, {custom: './src/index.ts'} will generate custom.d.ts
20
+ *
21
+ * If not specified, the main entry points will be used for declaration file generation.
22
+ *
23
+ * If a string path is provided in an array, the file name (without extension)
24
+ * will be used as the name for the output declaration file.
25
+ *
26
+ * @example
27
+ * // Using string paths in an array
28
+ * entry: ['./src/index.ts'] // Generates index.d.ts
29
+ *
30
+ * // Using named outputs as an object
31
+ * entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
32
+ */
33
+ entry: Entry
34
+ };
7
35
  interface BunupOptions {
8
- /**
9
- * Name of the build configuration
10
- * Used for logging and identification purposes
11
- */
12
- name?: string;
13
- /**
14
- * Entry point files for the build
15
- * These are the files that will be processed and bundled
16
- */
17
- entry: Entry[];
18
- /**
19
- * Output directory for the bundled files
20
- * Defaults to 'dist' if not specified
21
- */
22
- outDir: string;
23
- /**
24
- * Output formats for the bundle
25
- * Can include 'esm', 'cjs', and/or 'iife'
26
- * Defaults to ['esm'] if not specified
27
- */
28
- format: Format[];
29
- /**
30
- * Whether to enable all minification options
31
- * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
32
- */
33
- minify?: boolean;
34
- /**
35
- * Whether to enable code splitting
36
- * Defaults to true for ESM format, false for CJS format
37
- */
38
- splitting?: boolean;
39
- /**
40
- * Whether to minify whitespace in the output
41
- * Removes unnecessary whitespace to reduce file size
42
- */
43
- minifyWhitespace?: boolean;
44
- /**
45
- * Whether to minify identifiers in the output
46
- * Renames variables and functions to shorter names
47
- */
48
- minifyIdentifiers?: boolean;
49
- /**
50
- * Whether to minify syntax in the output
51
- * Optimizes code structure for smaller file size
52
- */
53
- minifySyntax?: boolean;
54
- /**
55
- * Whether to watch for file changes and rebuild automatically
56
- */
57
- watch?: boolean;
58
- /**
59
- * Whether to generate TypeScript declaration files (.d.ts)
60
- */
61
- dts?: boolean;
62
- /**
63
- * External packages that should not be bundled
64
- * Useful for dependencies that should be kept as external imports
65
- */
66
- external?: External;
67
- /**
68
- * Packages that should be bundled even if they are in external
69
- * Useful for dependencies that should be included in the bundle
70
- */
71
- noExternal?: External;
72
- /**
73
- * The target environment for the bundle
74
- * Can be 'browser', 'bun', 'node', etc.
75
- * Defaults to 'node' if not specified
76
- */
77
- target?: Target;
78
- /**
79
- * Whether to clean the output directory before building
80
- * When true, removes all files in the outDir before starting a new build
81
- * Defaults to true if not specified
82
- */
83
- clean?: boolean;
36
+ /**
37
+ * Name of the build configuration
38
+ * Used for logging and identification purposes
39
+ */
40
+ name?: string;
41
+ /**
42
+ * Entry point files for the build
43
+ *
44
+ * This can be:
45
+ * - An array of file paths
46
+ * - An object where keys are output names and values are input file paths
47
+ *
48
+ * The key names are used for the generated output files.
49
+ * For example, {custom: './src/index.ts'} will generate custom.js
50
+ *
51
+ * If a string path is provided in an array, the file name (without extension)
52
+ * will be used as the name for the output file.
53
+ *
54
+ * @example
55
+ * // Using string paths in an array
56
+ * entry: ['./src/index.ts'] // Generates index.js
57
+ *
58
+ * // Using named outputs as an object
59
+ * entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.js and utils.js
60
+ */
61
+ entry: Entry;
62
+ /**
63
+ * Output directory for the bundled files
64
+ * Defaults to 'dist' if not specified
65
+ */
66
+ outDir: string;
67
+ /**
68
+ * Output formats for the bundle
69
+ * Can include 'esm', 'cjs', and/or 'iife'
70
+ * Defaults to ['esm'] if not specified
71
+ */
72
+ format: Format[];
73
+ /**
74
+ * Whether to enable all minification options
75
+ * When true, enables minifyWhitespace, minifyIdentifiers, and minifySyntax
76
+ */
77
+ minify?: boolean;
78
+ /**
79
+ * Whether to enable code splitting
80
+ * Defaults to true for ESM format, false for CJS format
81
+ */
82
+ splitting?: boolean;
83
+ /**
84
+ * Whether to minify whitespace in the output
85
+ * Removes unnecessary whitespace to reduce file size
86
+ */
87
+ minifyWhitespace?: boolean;
88
+ /**
89
+ * Whether to minify identifiers in the output
90
+ * Renames variables and functions to shorter names
91
+ */
92
+ minifyIdentifiers?: boolean;
93
+ /**
94
+ * Whether to minify syntax in the output
95
+ * Optimizes code structure for smaller file size
96
+ */
97
+ minifySyntax?: boolean;
98
+ /**
99
+ * Whether to watch for file changes and rebuild automatically
100
+ */
101
+ watch?: boolean;
102
+ /**
103
+ * Whether to generate TypeScript declaration files (.d.ts)
104
+ * When set to true, generates declaration files for all entry points
105
+ * Can also be configured with DtsOptions for more control
106
+ */
107
+ dts?: boolean | DtsOptions;
108
+ /**
109
+ * External packages that should not be bundled
110
+ * Useful for dependencies that should be kept as external imports
111
+ */
112
+ external?: External;
113
+ /**
114
+ * Packages that should be bundled even if they are in external
115
+ * Useful for dependencies that should be included in the bundle
116
+ */
117
+ noExternal?: External;
118
+ /**
119
+ * The target environment for the bundle
120
+ * Can be 'browser', 'bun', 'node', etc.
121
+ * Defaults to 'node' if not specified
122
+ */
123
+ target?: Target;
124
+ /**
125
+ * Whether to clean the output directory before building
126
+ * When true, removes all files in the outDir before starting a new build
127
+ * Defaults to true if not specified
128
+ */
129
+ clean?: boolean;
84
130
  }
85
131
 
86
- type DefineConfigOption = WithOptional<BunupOptions, 'outDir' | 'format'>;
132
+ type DefineConfigOption = WithOptional<BunupOptions, "outDir" | "format">;
87
133
  type DefineConfigOptions = DefineConfigOption | DefineConfigOption[];
88
134
  declare function defineConfig(options: DefineConfigOptions): DefineConfigOptions;
89
135
 
package/build/index.js CHANGED
@@ -1,8 +1 @@
1
- 'use strict';
2
-
3
- // src/define-config.ts
4
- function defineConfig(options) {
5
- return options;
6
- }
7
-
8
- exports.defineConfig = defineConfig;
1
+ var D=require("node:module");var{defineProperty:e,getOwnPropertyNames:r,getOwnPropertyDescriptor:O}=Object,g=Object.prototype.hasOwnProperty;var f=new WeakMap,C=(i)=>{var n=f.get(i),o;if(n)return n;if(n=e({},"__esModule",{value:!0}),i&&typeof i==="object"||typeof i==="function")r(i).map((t)=>!g.call(n,t)&&e(n,t,{get:()=>i[t],enumerable:!(o=O(i,t))||o.enumerable}));return f.set(i,n),n};var u=(i,n)=>{for(var o in n)e(i,o,{get:n[o],enumerable:!0,configurable:!0,set:(t)=>n[o]=()=>t})};var m={};u(m,{defineConfig:()=>p});module.exports=C(m);function p(i){return i}
package/build/index.mjs CHANGED
@@ -1,6 +1 @@
1
- // src/define-config.ts
2
- function defineConfig(options) {
3
- return options;
4
- }
5
-
6
- export { defineConfig };
1
+ function n(i){return i}export{n as defineConfig};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
4
4
  "description": "A extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -18,13 +18,12 @@
18
18
  "@types/bun": "^1.2.5",
19
19
  "@typescript-eslint/eslint-plugin": "^7.3.1",
20
20
  "bumpp": "^10.1.0",
21
+ "bunup": "^0.1.6",
21
22
  "eslint": "^8.57.0",
22
23
  "husky": "^9.1.6",
23
24
  "prettier": "^3.2.5",
24
- "tsup": "^8.0.2",
25
25
  "typescript": "^5.4.3",
26
- "vitest": "^2.0.5",
27
- "bunup": "0.1.5"
26
+ "vitest": "^2.0.5"
28
27
  },
29
28
  "peerDependencies": {
30
29
  "typescript": ">=4.5.0"
@@ -59,9 +58,9 @@
59
58
  "rollup-plugin-dts": "^6.1.1"
60
59
  },
61
60
  "scripts": {
62
- "build": "tsup",
63
- "dev": "tsup --watch",
64
- "test-build": "bunup",
61
+ "build": "bunup",
62
+ "dev": "bunup --watch",
63
+ "test-build": "pnpm -C tests build",
65
64
  "test": "vitest run",
66
65
  "tsc": "tsc --noEmit",
67
66
  "lint": "eslint src --fix",
@@ -1 +0,0 @@
1
- 'use strict';var h=require('path'),y=require('fs'),I=require('oxc-transform'),rollup=require('rollup'),N=require('rollup-plugin-dts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var h__default=/*#__PURE__*/_interopDefault(h);var y__default=/*#__PURE__*/_interopDefault(y);var I__default=/*#__PURE__*/_interopDefault(I);var N__default=/*#__PURE__*/_interopDefault(N);var f=r=>r instanceof Error?r.message:String(r);function w(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function b(r,t){switch(r){case "esm":return ".d.mts";case "cjs":return j(t)?".d.cts":".d.ts";case "iife":return ".d.ts"}}function j(r){return r==="module"}function $(r){return r?Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})])):[]}function D(r){return r.map(t=>typeof t=="string"?new RegExp(`^${w(t)}($|\\/|\\\\)`):t)}function v(r,t){return D(r.external||[]).concat($(t).map(e=>new RegExp(`^${w(e)}($|\\/|\\\\)`)))}function P(r){return D(r.noExternal||[])}var p={MAX_LABEL_LENGTH:5,colors:{cli:"183",info:"240",warn:"221",error:"203",progress:{ESM:"214",CJS:"114",IIFE:"105",DTS:"75"},default:"255"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(r,t,e){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length));return `\x1B[38;5;${r}m[${t}]\x1B[0m ${s}${e}`},cli(r){let t=this.labels.cli;console.log(this.formatMessage(this.colors.cli,t,r));},info(r){let t=this.labels.info;console.log(this.formatMessage(this.colors.info,t,r));},warn(r){let t=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,t,r));},error(r){let t=this.labels.error;console.error(this.formatMessage(this.colors.error,t,r));},progress(r,t){let e=String(r),s=this.colors.default;for(let[n,o]of Object.entries(this.colors.progress))if(e.includes(n)){s=o;break}console.log(this.formatMessage(s,e,t));}};function S(r,t){return `${t?`${t.replace(/-/g,"_")}_`:""}${r}`.toUpperCase()}function R(r){let t=h__default.default.join(r,"package.json");try{if(!y__default.default.existsSync(t))return null;let e=y__default.default.readFileSync(t,"utf8");return JSON.parse(e)}catch(e){return p.error(`Failed to load package.json at ${t}: ${f(e)}`),null}}async function M(r,t,e,s){let{absoluteRootDir:n,absoluteEntry:o}=q(r,t),i=await L(o),a=await U(i);return J(o,a,e,s,n)}async function L(r){let t=new Set,e=[r];for(;e.length>0;){let s=e.pop();if(!(!s||t.has(s))){t.add(s);try{let n=await y__default.default.promises.readFile(s,"utf8"),o=_(n);for(let i of o){let a=h__default.default.dirname(s),c=h__default.default.resolve(a,i),m=[c,`${c}.ts`,`${c}.tsx`,`${c}/index.ts`,`${c}/index.tsx`];for(let g of m)if(y__default.default.existsSync(g)&&g.endsWith(".ts")&&!t.has(g)){e.push(g);break}}}catch(n){p.warn(`Error processing ${s}: ${n instanceof Error?n.message:String(n)}`);}}}return t}function _(r){let t=new Set;try{let e=/(?:import|export)(?:(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*)|[\s\n]+)(["'`])([^'"]+)\1/g,s;for(;(s=e.exec(r))!==null;){let i=s[2];i.startsWith(".")&&t.add(i);}let n=/import\s+(["'`])([^'"]+)\1\s*;?/g;for(;(s=n.exec(r))!==null;){let i=s[2];i.startsWith(".")&&t.add(i);}let o=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;for(;(s=o.exec(r))!==null;){let i=s[2];i.startsWith(".")&&t.add(i);}}catch(e){p.warn(`Error extracting imports: ${e instanceof Error?e.message:String(e)}`);}return Array.from(t)}async function U(r){let t=new Map;return await Promise.all(Array.from(r).map(async e=>{try{let s=e.replace(/\.tsx?$/,".d.ts"),n=await y__default.default.promises.readFile(e,"utf8"),{code:o}=I__default.default.isolatedDeclaration(e,n);o&&t.set(s,o);}catch(s){p.warn(`Failed to generate declaration for ${e}: ${s instanceof Error?s.message:String(s)}`);}})),t}async function J(r,t,e,s,n){let o="\0virtual:",i=r.replace(/\.tsx?$/,".d.ts"),a=`${o}${i}`,c={name:"virtual-dts",resolveId(l,u){if(l.startsWith(o))return l;if(u?.startsWith(o)){let d=u.slice(o.length),B=h__default.default.dirname(d);if(l.startsWith(".")){let T=h__default.default.resolve(B,l);for(let F of ["",".d.ts","/index.d.ts"]){let k=`${T}${F}`;if(t.has(k))return `${o}${k}`}}}return null},load(l){if(l.startsWith(o)){let u=l.slice(o.length);return t.get(u)||null}return null}},m=R(n),g=v(s,m),E=P(s),x;try{x=await rollup.rollup({input:a,onwarn(u,d){u.code==="UNRESOLVED_IMPORT"||u.code==="CIRCULAR_DEPENDENCY"||u.code==="EMPTY_BUNDLE"||d(u);},plugins:[c,N__default.default()],external:u=>g.some(d=>d.test(u))&&!E.some(d=>d.test(u))});let{output:l}=await x.generate({format:e});if(!l[0]?.code)throw new Error("Generated bundle is empty");return l[0].code}catch(l){throw new Error(`DTS bundling failed: ${f(l)}`)}finally{x&&await x.close();}}function q(r,t){let e=h__default.default.resolve(r),s=h__default.default.resolve(e,t);if(!y__default.default.existsSync(e))throw new Error(`Root directory does not exist: ${e}`);if(!y__default.default.existsSync(s))throw new Error(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new Error(`Entry file must be a TypeScript file (.ts): ${s}`);if(h__default.default.relative(e,s).startsWith(".."))throw new Error(`Entry file must be within rootDir: ${s}`);return {absoluteRootDir:e,absoluteEntry:s}}self.onmessage=async r=>{let{name:t,rootDir:e,outDir:s,entry:n,format:o,packageType:i,options:a}=r.data;try{let c=await M(e,n.path,o,a),m=b(o,i),g=`${s}/${n.name}${m}`,E=`${e}/${g}`;await Bun.write(E,c);let x={name:t,success:!0,outputRelativePath:g};self.postMessage(x);}catch(c){let m={success:false,error:f(c)};self.postMessage(m);}};var O=class{constructor(t=navigator.hardwareConcurrency||4){this.workers=[];this.queue=[];this.busyWorkers=new Set;this.isShuttingDown=false;this.maxWorkers=t;}async process(t){if(this.isShuttingDown)throw new Error("Worker pool is shutting down");return new Promise((e,s)=>{this.queue.push({task:t,resolve:e,reject:s}),this.processQueue();})}processQueue(){if(!(this.queue.length===0||this.isShuttingDown))if(this.workers.length<this.maxWorkers){let t=new Worker(h__default.default.join(__dirname,"./dtsWorker.js"));this.workers.push(t),this.assignTaskToWorker(t);}else {let t=this.workers.find(e=>!this.busyWorkers.has(e));t&&this.assignTaskToWorker(t);}}assignTaskToWorker(t){let e=this.queue.shift();if(!e)return;let{task:s,resolve:n,reject:o}=e;this.busyWorkers.add(t);let i=()=>{this.busyWorkers.delete(t),this.isShuttingDown&&this.busyWorkers.size===0?this.terminateAllWorkers():this.processQueue();};t.onmessage=a=>{a.data.success?(p.progress(S("DTS",a.data.name),a.data.outputRelativePath),n()):(p.error(`DTS generation failed: ${a.data.error}`),o(new Error(a.data.error))),i();},t.onerror=a=>{let c=f(a);p.error(`Worker error: ${c}`),o(a),i();},t.postMessage(s);}terminateAllWorkers(){this.workers.forEach(t=>{try{t.terminate();}catch(e){p.error(`Error terminating worker: ${f(e)}`);}}),this.workers=[],this.busyWorkers.clear();}async cleanup(){if(this.isShuttingDown=true,this.busyWorkers.size===0){this.terminateAllWorkers();return}return new Promise(t=>{let e=setInterval(()=>{this.busyWorkers.size===0&&(clearInterval(e),this.terminateAllWorkers(),t());},100);setTimeout(()=>{clearInterval(e),this.terminateAllWorkers(),t();},5e3);})}};exports.DtsWorker=O;