@@ -7,6 +7,7 @@ import { typescriptPaths } from 'rollup-plugin-typescript-paths';
77
88import commonjs from '@rollup/plugin-commonjs' ;
99import resolve from '@rollup/plugin-node-resolve' ;
10+ import fs from 'fs' ;
1011
1112const isProduction = process . env . BUILD === 'prod' ;
1213
@@ -52,54 +53,38 @@ const config = {
5253 ] ,
5354} ;
5455
55- const devConfig = {
56- input : './src/index.ts' ,
56+ const isCJS = true ;
57+ // Zero-dependency standalone bundle configuration (No optimizations)
58+ const zeroDepConfig = {
59+ input : {
60+ index : 'src/index.ts' ,
61+ 'commands/agent' : 'src/commands/agent/agent.index.ts' ,
62+ 'commands/create' : 'src/commands/create/create.index.ts' ,
63+ 'commands/update' : 'src/commands/update.ts' ,
64+ 'hooks/preparse' : 'src/hooks/preparse.ts' ,
65+ } ,
5766 output : {
58- file : './dist/cli.cjs' , // CommonJS output
59- format : 'cjs' , // Specify the CommonJS format
60- sourcemap : true ,
61- inlineDynamicImports : true , // Inline all dynamic imports into one file
67+ dir : 'dist' ,
68+ format : isCJS ? 'cjs' : 'es' ,
69+ sourcemap : false , // Enable sourcemaps for debugging
6270 banner : '#!/usr/bin/env node' ,
71+ entryFileNames : isCJS ? '[name].cjs' : '[name].js' ,
72+ chunkFileNames : isCJS ? 'chunks/[name].cjs' : 'chunks/[name].js' , // Use predictable chunk names
73+ inlineDynamicImports : false , // Keep separate files
74+ exports : 'auto' , // Handle mixed exports
75+ // manualChunks: (id) => {
76+ // if (id.includes('node_modules')) {
77+ // return 'vendor';
78+ // }
79+ // },
6380 } ,
64- plugins : [
65- resolve ( {
66- browser : false , // Explicitly disable browser field resolution
67- preferBuiltins : true , // Prefer Node.js built-in modules
68- mainFields : [ 'main' , 'module' ] , // Prioritize 'main' field for Node.js packages
69- extensions : [ '.js' , '.ts' , '.json' ] , // Resolve these extensions
70- exportConditions : [ 'node' ] , // Use Node.js export conditions
71- } ) ,
72- commonjs ( {
73- // Handle mixed ES modules and CommonJS
74- transformMixedEsModules : true ,
75- // Ignore browser-specific globals
76- ignore : [ 'electron' ] ,
77- } ) ,
78- json ( ) ,
79-
80- typescriptPaths ( {
81- tsconfig : './tsconfig.json' ,
82- preserveExtensions : true ,
83- nonRelative : false ,
84- } ) ,
85- esbuild ( {
86- sourceMap : true ,
87- minify : false ,
88- treeShaking : false ,
89- target : 'node18' ,
90- platform : 'node' , // Explicitly set platform to node
91- define : {
92- // Define Node.js environment
93- 'process.env.NODE_ENV' : '"development"' ,
94- global : 'globalThis' ,
95- } ,
96- } ) ,
97- sourcemaps ( ) ,
98- ] ,
81+ // Only keep essential Node.js built-ins external
9982 external : [
100- // Keep Node.js built-ins external
10183 'fs' ,
84+ 'fs/promises' ,
10285 'path' ,
86+ 'path/posix' ,
87+ 'path/win32' ,
10388 'os' ,
10489 'util' ,
10590 'crypto' ,
@@ -128,10 +113,53 @@ const devConfig = {
128113 'worker_threads' ,
129114 'perf_hooks' ,
130115 'async_hooks' ,
116+ 'inspector' ,
117+ 'v8' ,
118+ 'constants' ,
119+ 'assert' ,
120+ 'process' ,
121+ ] ,
122+ plugins : [
123+ deleteFolder ( 'dist' ) ,
124+ colorfulLogs ( 'CLI Zero-Dep Builder' ) ,
125+ resolve ( {
126+ browser : false ,
127+ preferBuiltins : true ,
128+ mainFields : [ 'module' , 'main' ] ,
129+ extensions : [ '.js' , '.ts' , '.json' ] ,
130+ exportConditions : isCJS ? [ 'node' ] : [ 'node' , 'import' ] ,
131+ } ) ,
132+ commonjs ( {
133+ transformMixedEsModules : true ,
134+ ignore : [ 'electron' ] ,
135+ requireReturnsDefault : 'auto' ,
136+ ignoreDynamicRequires : isCJS , // Handle dynamic requires properly
137+ dynamicRequireTargets : [ 'node_modules/**/*.js' ] ,
138+ } ) ,
139+ json ( ) ,
140+ typescriptPaths ( {
141+ tsconfig : './tsconfig.json' ,
142+ preserveExtensions : true ,
143+ nonRelative : false ,
144+ } ) ,
145+ esbuild ( {
146+ sourceMap : false ,
147+ minify : true , // No minification
148+ treeShaking : true , // No tree-shaking
149+ target : 'node18' ,
150+ platform : 'node' ,
151+ format : isCJS ? undefined : 'esm' ,
152+ define : {
153+ 'process.env.NODE_ENV' : '"development"' ,
154+ global : 'globalThis' ,
155+ } ,
156+ keepNames : true , // Keep all names
157+ } ) ,
158+ // No terser plugin - no compression at all
131159 ] ,
132160} ;
133161
134- export default config ;
162+ export default zeroDepConfig ;
135163
136164//#region [Custom Plugins] =====================================================
137165
@@ -151,6 +179,12 @@ const colors = {
151179 bgBlue : '\x1b[44m' ,
152180} ;
153181
182+ function deleteFolder ( folderPath ) {
183+ if ( fs . existsSync ( folderPath ) ) {
184+ fs . rmSync ( folderPath , { recursive : true } ) ;
185+ }
186+ }
187+
154188// Custom colorful logging plugin
155189function colorfulLogs ( title = 'CLI Builder' ) {
156190 function formatBytes ( bytes , decimals = 2 ) {
@@ -214,8 +248,8 @@ function colorfulLogs(title = 'CLI Builder') {
214248 return null ;
215249 } ,
216250 transform ( code , id ) {
251+ processedFiles ++ ;
217252 if ( ! id . includes ( 'node_modules' ) ) {
218- processedFiles ++ ;
219253 const relativePath = path . relative ( process . cwd ( ) , id ) ;
220254 currentFile = relativePath ;
221255 }
0 commit comments