Skip to content

Commit a7bcffb

Browse files
claude: Simplify import map and add external dependencies support
Remove Deno std entries from import map since esbuild cannot bundle external URL schemes (jsr:, npm:, https:). Add externals support for marking imports as external (not bundled). Changes to quarto-cli: - Simplify import-map.json: only @quarto/types remains - Simplify updateImportMap(): just path transformation, no version syncing - Add externals?: string[] to quartoExtension interface - Implement --external flag handling in bundle function - Add default externals to deno.json: ["jsr:*", "npm:*", "https:*", "http:*"] Rationale: - esbuild binary only bundles relative file paths - External URL schemes must be resolved at runtime by Deno - Import map now serves single purpose: @quarto/types aliasing - Extension authors use full JSR URLs in source code - Default externals cover all non-bundleable schemes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4068ca1 commit a7bcffb

File tree

4 files changed

+15
-34
lines changed

4 files changed

+15
-34
lines changed

package/src/common/prepare-dist.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -237,32 +237,8 @@ function updateImportMap(config: Configuration) {
237237
);
238238
const importMapContent = JSON.parse(Deno.readTextFileSync(importMapPath));
239239

240-
// Read the source import map to get current Deno std versions
241-
const sourceImportMapPath = join(config.directoryInfo.src, "import_map.json");
242-
const sourceImportMap = JSON.parse(Deno.readTextFileSync(sourceImportMapPath));
243-
const sourceImports = sourceImportMap.imports as Record<string, string>;
244-
245-
// Update the import map for distribution:
246-
// 1. Change @quarto/types path from dev (../../../packages/...) to dist (./quarto-types.d.ts)
247-
// 2. Update all other imports (Deno std versions) from source import map
248-
const updatedImports: Record<string, string> = {
249-
"@quarto/types": "./quarto-types.d.ts",
250-
};
251-
252-
// Copy all other imports from source, updating versions
253-
for (const key in importMapContent.imports) {
254-
if (key !== "@quarto/types") {
255-
const sourceValue = sourceImports[key];
256-
if (!sourceValue) {
257-
throw new Error(
258-
`Import map key "${key}" not found in source import_map.json`,
259-
);
260-
}
261-
updatedImports[key] = sourceValue;
262-
}
263-
}
264-
265-
importMapContent.imports = updatedImports;
240+
// Update @quarto/types path from dev (../../../packages/...) to dist (./quarto-types.d.ts)
241+
importMapContent.imports["@quarto/types"] = "./quarto-types.d.ts";
266242

267243
// Write back the updated import map
268244
Deno.writeTextFileSync(

src/command/dev-call/build-ts-extension/cmd.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface DenoConfig {
2525
minify?: boolean;
2626
sourcemap?: boolean;
2727
target?: string;
28+
externals?: string[];
2829
};
2930
}
3031

@@ -281,6 +282,13 @@ async function bundle(
281282
args.push("--sourcemap");
282283
}
283284

285+
// Add external dependencies (not bundled)
286+
if (config.quartoExtension?.externals) {
287+
for (const external of config.quartoExtension.externals) {
288+
args.push(`--external:${external}`);
289+
}
290+
}
291+
284292
const result = await execProcess({
285293
cmd: esbuildBinary,
286294
args,

src/resources/extension-build/deno.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"strict": true,
44
"lib": ["deno.ns", "DOM", "ES2021"]
55
},
6-
"importMap": "./import-map.json"
6+
"importMap": "./import-map.json",
7+
"quartoExtension": {
8+
"externals": ["jsr:*", "npm:*", "https:*", "http:*"]
9+
}
710
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
{
22
"imports": {
3-
"@quarto/types": "../../../packages/quarto-types/dist/index.d.ts",
4-
"path": "jsr:@std/path@1.0.8",
5-
"path/posix": "jsr:@std/path@1.0.8/posix",
6-
"log": "jsr:/@std/log@0.224.0",
7-
"log/": "jsr:/@std/log@0.224.0/",
8-
"fs/": "jsr:/@std/fs@1.0.16/",
9-
"encoding/": "jsr:/@std/encoding@1.0.9/"
3+
"@quarto/types": "../../../packages/quarto-types/dist/index.d.ts"
104
}
115
}

0 commit comments

Comments
 (0)