@@ -119,6 +119,50 @@ async function processScriptsDirectory(scriptsDir: string): Promise<void> {
119119 console . log ( ` ✓ Generated index.ts with ${ scriptCount } script(s)` ) ;
120120}
121121
122+ /**
123+ * Inject static imports into plugin files for JSR tree-shaking
124+ * Replaces comment markers with actual import statements
125+ */
126+ async function injectStaticImports ( ) : Promise < void > {
127+ console . log ( '\nInjecting static imports into plugin files...' ) ;
128+
129+ // Find all plugin.ts files in the plugins directory
130+ const pluginFiles : string [ ] = [ ] ;
131+ for await (
132+ const entry of walk ( SERVER_ROOT , {
133+ exts : [ '.ts' ] ,
134+ match : [ / \/ p l u g i n \. t s $ / ] ,
135+ } )
136+ ) {
137+ pluginFiles . push ( entry . path ) ;
138+ }
139+
140+ for ( const pluginFile of pluginFiles ) {
141+ const content = await Deno . readTextFile ( pluginFile ) ;
142+
143+ // Check if file contains injection marker
144+ const markerRegex = / ^ \/ \/ I N J E C T _ S T A T I C _ I M P O R T : ( .+ ) $ / gm;
145+ const matches = content . match ( markerRegex ) ;
146+
147+ if ( matches ) {
148+ let modified = content ;
149+
150+ // Replace each marker with actual import
151+ for ( const match of matches ) {
152+ const pathMatch = match . match ( / I N J E C T _ S T A T I C _ I M P O R T : ( .+ ) $ / ) ;
153+ if ( pathMatch ) {
154+ const importPath = pathMatch [ 1 ] ;
155+ const importStatement = `import '${ importPath } ';` ;
156+ modified = modified . replace ( match , importStatement ) ;
157+ }
158+ }
159+
160+ await Deno . writeTextFile ( pluginFile , modified ) ;
161+ console . log ( ` ✓ Injected imports in ${ relative ( '.' , pluginFile ) } ` ) ;
162+ }
163+ }
164+ }
165+
122166async function main ( ) {
123167 console . log ( '\n🔨 Inlining AppleScript files for JSR compatibility...\n' ) ;
124168
@@ -133,7 +177,10 @@ async function main() {
133177 await processScriptsDirectory ( dir ) ;
134178 }
135179
136- console . log ( '\n✅ Done! Generated index.ts files are ready for JSR publishing.\n' ) ;
180+ // Inject static imports into plugin files
181+ await injectStaticImports ( ) ;
182+
183+ console . log ( '\n✅ Done! Generated index.ts files and injected imports are ready for JSR publishing.\n' ) ;
137184}
138185
139186if ( import . meta. main ) {
0 commit comments