Skip to content

Commit 2d00dbf

Browse files
authored
Merge pull request #12 from Beyond-Better/dev
Fixed plugin loading of AppleScript files inJSR context
2 parents a328e00 + baa7a7f commit 2d00dbf

5 files changed

Lines changed: 53 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ docs/.obsidian
2020
playground/
2121

2222
# Generated files for JSR (created by build:jsr task)
23+
# - scripts/index.ts files with inlined AppleScript content
24+
# - Modified plugin.ts files with injected static imports
2325
server/src/plugins/**/scripts/index.ts

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@beyondbetter/bb-applescript-mcp-server",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "MCP server interact with macOS applications through AppleScript",
55
"license": "MIT",
66
"copyright": "2025 - Beyond Better <charlie@beyondbetter.app>",

scripts/inline-applescripts.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: [/\/plugin\.ts$/],
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 = /^\/\/ INJECT_STATIC_IMPORT: (.+)$/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(/INJECT_STATIC_IMPORT: (.+)$/);
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+
122166
async 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

139186
if (import.meta.main) {

server/src/plugins/bbedit.plugin/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Provides tools for working with BBEdit notebooks and projects
44
*/
55

6+
// INJECT_STATIC_IMPORT: ./scripts/index.ts
67
import { AppPlugin, ToolRegistration, ToolRegistry, WorkflowBase, WorkflowRegistry } from '@beyondbetter/bb-mcp-server';
78
import { z } from 'zod';
89
import { findAndExecuteScript } from '../../utils/scriptLoader.ts';

server/src/plugins/standard.plugin/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* and Finder operations that don't have simple CLI equivalents
55
*/
66

7+
// INJECT_STATIC_IMPORT: ./scripts/index.ts
78
import { AppPlugin, ToolRegistration, ToolRegistry, WorkflowBase, WorkflowRegistry } from '@beyondbetter/bb-mcp-server';
89
import { getTools as getRunScriptTools } from './tools/runScript.ts';
910
import { getTools as getReadDictionaryTools } from './tools/readDictionary.ts';

0 commit comments

Comments
 (0)