1- import { build } from 'tsup' ;
2- import {
3- CompilerPlugin ,
4- CompilerPluginRuntime ,
5- fromEsbuildPlugin ,
6- } from '../plugins' ;
1+ import { build } from 'tsdown' ;
2+ import { CompilerPlugin , CompilerPluginRuntime } from '../plugins' ;
73import { loadConfigFile } from '../config/loader' ;
84import { writeFile } from 'node:fs/promises' ;
95import { join } from 'node:path' ;
@@ -15,14 +11,14 @@ import { MaybeArray } from '../components';
1511
1612export interface ApplicationBuildOptions {
1713 plugins ?: MaybeArray < CompilerPlugin > [ ] | Array < CompilerPlugin > ;
18- esbuildPlugins ?: any [ ] ;
14+ rolldownPlugins ?: any [ ] ;
1915 isDev ?: boolean ;
2016 configPath ?: string ;
2117}
2218
2319export async function buildApplication ( {
2420 plugins,
25- esbuildPlugins ,
21+ rolldownPlugins ,
2622 isDev,
2723 configPath,
2824} : ApplicationBuildOptions ) {
@@ -35,45 +31,40 @@ export async function buildApplication({
3531 const pluginRuntime = new CompilerPluginRuntime (
3632 ( plugins || [ ] ) as CompilerPlugin [ ] ,
3733 ) ;
38- const esbuildPluginList : any [ ] = pluginRuntime . isEmpty ( )
39- ? [ ]
40- : [ pluginRuntime . toEsbuildPlugin ( ) ] ;
4134
42- if ( esbuildPlugins ?. length ) {
43- esbuildPluginList . push ( ... esbuildPlugins . map ( fromEsbuildPlugin ) ) ;
44- }
35+ rolldownPlugins ??= [ ] ;
36+
37+ rolldownPlugins . push ( pluginRuntime . toJSON ( ) ) ;
4538
4639 try {
4740 const dest = isDev ? '.commandkit' : config . distDir ;
4841
4942 // Clean the destination directory
5043 await rimraf ( dest ) ;
5144
45+ await pluginRuntime . init ( ) ;
46+
5247 await build ( {
53- esbuildPlugins : esbuildPluginList ,
5448 watch : false ,
55- banner : {
56- js : ! isDev
57- ? '/* Optimized production build generated by commandkit */'
58- : '' ,
59- } ,
60- cjsInterop : true ,
6149 dts : false ,
6250 clean : true ,
6351 format : [ 'esm' ] ,
6452 shims : true ,
65- keepNames : true ,
6653 minify : false ,
67- esbuildOptions : ( options ) => {
68- options . jsx = 'automatic' ;
69- options . jsxImportSource = 'commandkit' ;
70-
71- return options ;
72- } ,
73- minifyIdentifiers : false ,
74- minifySyntax : false ,
7554 silent : ! ! isDev ,
76- splitting : true ,
55+ inputOptions : {
56+ transform : {
57+ jsx : {
58+ runtime : 'automatic' ,
59+ importSource : 'commandkit' ,
60+ } ,
61+ } ,
62+ moduleTypes : {
63+ '.json' : 'js' ,
64+ } ,
65+ } ,
66+ plugins : rolldownPlugins ,
67+ platform : 'node' ,
7768 skipNodeModulesBundle : true ,
7869 name : 'CommandKit' ,
7970 sourcemap : true ,
@@ -87,6 +78,7 @@ export async function buildApplication({
8778 '!**/*.test.*' ,
8879 '!**/*.spec.*' ,
8980 ] ,
81+ unbundle : false ,
9082 } ) ;
9183
9284 await copyLocaleFiles ( 'src' , dest ) ;
@@ -99,7 +91,7 @@ export async function buildApplication({
9991 process . exit ( 1 ) ; // Force exit on error
10092 } finally {
10193 // Ensure plugins are cleaned up
102- await pluginRuntime . cleanup ( ) ;
94+ await pluginRuntime . destroy ( ) ;
10395 }
10496}
10597
@@ -113,23 +105,6 @@ for (const file of $env) {
113105}
114106` ;
115107
116- const requireScript = [
117- '// --- CommandKit require() polyfill ---' ,
118- ' if (typeof require === "undefined") {' ,
119- ' const { createRequire } = await import("node:module");' ,
120- ' const __require = createRequire(import.meta.url);' ,
121- ' Object.defineProperty(globalThis, "require", {' ,
122- ' value: (id) => {' ,
123- ' return __require(id);' ,
124- ' },' ,
125- ' configurable: true,' ,
126- ' enumerable: false,' ,
127- ' writable: true,' ,
128- ' });' ,
129- ' }' ,
130- '// --- CommandKit require() polyfill ---' ,
131- ] . join ( '\n' ) ;
132-
133108const antiCrashScript = [
134109 '// --- CommandKit Anti-Crash Monitor ---' ,
135110 " // 'uncaughtException' event is supposed to be used to perform synchronous cleanup before shutting down the process" ,
@@ -156,7 +131,7 @@ async function injectEntryFile(
156131 distDir ?: string ,
157132) {
158133 const code = `/* Entrypoint File Generated By CommandKit */
159- ${ isDev ? `\n\n// Injected for development\n${ wrapInAsyncIIFE ( [ envScript ( isDev ) , antiCrashScript , requireScript ] ) } \n\n` : wrapInAsyncIIFE ( [ envScript ( isDev ) , requireScript ] ) }
134+ ${ isDev ? `\n\n// Injected for development\n${ wrapInAsyncIIFE ( [ envScript ( isDev ) , antiCrashScript ] ) } \n\n` : wrapInAsyncIIFE ( [ envScript ( isDev ) ] ) }
160135
161136import { CommandKit } from 'commandkit';
162137
0 commit comments