bunup 0.1.6 → 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.
- package/build/cli.js +5 -932
- package/build/cli.mjs +5 -922
- package/build/dtsWorker.mjs +1 -0
- package/build/index.d.mts +124 -121
- package/build/index.d.ts +124 -121
- package/build/index.js +1 -8
- package/build/index.mjs +1 -6
- package/package.json +4 -5
- package/build/dtsWorker.js +0 -1
|
@@ -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,132 +1,135 @@
|
|
|
1
|
-
type WithOptional<
|
|
1
|
+
type WithOptional<
|
|
2
|
+
T,
|
|
3
|
+
K extends keyof T
|
|
4
|
+
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
2
5
|
|
|
3
|
-
type Format =
|
|
4
|
-
type Target =
|
|
6
|
+
type Format = "esm" | "cjs" | "iife";
|
|
7
|
+
type Target = "bun" | "node" | "browser";
|
|
5
8
|
type External = string[];
|
|
6
9
|
type Entry = string[] | Record<string, string>;
|
|
7
10
|
type DtsOptions = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
31
34
|
};
|
|
32
35
|
interface BunupOptions {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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;
|
|
127
130
|
}
|
|
128
131
|
|
|
129
|
-
type DefineConfigOption = WithOptional<BunupOptions,
|
|
132
|
+
type DefineConfigOption = WithOptional<BunupOptions, "outDir" | "format">;
|
|
130
133
|
type DefineConfigOptions = DefineConfigOption | DefineConfigOption[];
|
|
131
134
|
declare function defineConfig(options: DefineConfigOptions): DefineConfigOptions;
|
|
132
135
|
|
package/build/index.d.ts
CHANGED
|
@@ -1,132 +1,135 @@
|
|
|
1
|
-
type WithOptional<
|
|
1
|
+
type WithOptional<
|
|
2
|
+
T,
|
|
3
|
+
K extends keyof T
|
|
4
|
+
> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
2
5
|
|
|
3
|
-
type Format =
|
|
4
|
-
type Target =
|
|
6
|
+
type Format = "esm" | "cjs" | "iife";
|
|
7
|
+
type Target = "bun" | "node" | "browser";
|
|
5
8
|
type External = string[];
|
|
6
9
|
type Entry = string[] | Record<string, string>;
|
|
7
10
|
type DtsOptions = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
31
34
|
};
|
|
32
35
|
interface BunupOptions {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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;
|
|
127
130
|
}
|
|
128
131
|
|
|
129
|
-
type DefineConfigOption = WithOptional<BunupOptions,
|
|
132
|
+
type DefineConfigOption = WithOptional<BunupOptions, "outDir" | "format">;
|
|
130
133
|
type DefineConfigOptions = DefineConfigOption | DefineConfigOption[];
|
|
131
134
|
declare function defineConfig(options: DefineConfigOptions): DefineConfigOptions;
|
|
132
135
|
|
package/build/index.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.1.
|
|
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,11 +18,10 @@
|
|
|
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.
|
|
21
|
+
"bunup": "^0.1.6",
|
|
22
22
|
"eslint": "^8.57.0",
|
|
23
23
|
"husky": "^9.1.6",
|
|
24
24
|
"prettier": "^3.2.5",
|
|
25
|
-
"tsup": "^8.0.2",
|
|
26
25
|
"typescript": "^5.4.3",
|
|
27
26
|
"vitest": "^2.0.5"
|
|
28
27
|
},
|
|
@@ -59,8 +58,8 @@
|
|
|
59
58
|
"rollup-plugin-dts": "^6.1.1"
|
|
60
59
|
},
|
|
61
60
|
"scripts": {
|
|
62
|
-
"build": "
|
|
63
|
-
"dev": "
|
|
61
|
+
"build": "bunup",
|
|
62
|
+
"dev": "bunup --watch",
|
|
64
63
|
"test-build": "pnpm -C tests build",
|
|
65
64
|
"test": "vitest run",
|
|
66
65
|
"tsc": "tsc --noEmit",
|
package/build/dtsWorker.js
DELETED
|
@@ -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 D(r){return r?Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})])):[]}function $(r){return r.map(t=>typeof t=="string"?new RegExp(`^${w(t)}($|\\/|\\\\)`):t)}function v(r,t){return $(r.external||[]).concat(D(t).map(e=>new RegExp(`^${w(e)}($|\\/|\\\\)`)))}function P(r){return $(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 o=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length));return `\x1B[38;5;${r}m[${t}]\x1B[0m ${o}${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),o=this.colors.default;for(let[n,s]of Object.entries(this.colors.progress))if(e.includes(n)){o=s;break}console.log(this.formatMessage(o,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 O(r,t,e,o){let{absoluteRootDir:n,absoluteEntry:s}=q(r,t),i=await L(s),a=await U(i);return J(s,a,e,o,n)}async function L(r){let t=new Set,e=[r];for(;e.length>0;){let o=e.pop();if(!(!o||t.has(o))){t.add(o);try{let n=await y__default.default.promises.readFile(o,"utf8"),s=_(n);for(let i of s){let a=h__default.default.dirname(o),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 ${o}: ${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,o;for(;(o=e.exec(r))!==null;){let i=o[2];i.startsWith(".")&&t.add(i);}let n=/import\s+(["'`])([^'"]+)\1\s*;?/g;for(;(o=n.exec(r))!==null;){let i=o[2];i.startsWith(".")&&t.add(i);}let s=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;for(;(o=s.exec(r))!==null;){let i=o[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 o=e.replace(/\.tsx?$/,".d.ts"),n=await y__default.default.promises.readFile(e,"utf8"),{code:s}=I__default.default.isolatedDeclaration(e,n);s&&t.set(o,s);}catch(o){p.warn(`Failed to generate declaration for ${e}: ${o instanceof Error?o.message:String(o)}`);}})),t}async function J(r,t,e,o,n){let s="\0virtual:",i=r.replace(/\.tsx?$/,".d.ts"),a=`${s}${i}`,c={name:"virtual-dts",resolveId(l,u){if(l.startsWith(s))return l;if(u?.startsWith(s)){let d=u.slice(s.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 `${s}${k}`}}}return null},load(l){if(l.startsWith(s)){let u=l.slice(s.length);return t.get(u)||null}return null}},m=R(n),g=v(o,m),E=P(o),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),o=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(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(h__default.default.relative(e,o).startsWith(".."))throw new Error(`Entry file must be within rootDir: ${o}`);return {absoluteRootDir:e,absoluteEntry:o}}self.onmessage=async r=>{let{name:t,rootDir:e,outDir:o,entry:n,format:s,packageType:i,options:a}=r.data;try{let c=await O(e,n.path,s,a),m=b(s,i),g=`${o}/${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 M=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,o)=>{this.queue.push({task:t,resolve:e,reject:o}),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:o,resolve:n,reject:s}=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}`),s(new Error(a.data.error))),i();},t.onerror=a=>{let c=f(a);p.error(`Worker error: ${c}`),s(a),i();},t.postMessage(o);}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=M;
|