-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathtsup.config.ts
More file actions
79 lines (75 loc) · 3.13 KB
/
tsup.config.ts
File metadata and controls
79 lines (75 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { readFile } from "node:fs/promises";
import { defineConfig } from "tsup";
import type { Plugin } from "esbuild";
import { cpSync, rmSync } from "node:fs";
/**
* Shim the SDK's getBundledCliPath() which calls import.meta.resolve() and
* createRequire(__filename). In ESM bundles the bare specifier can't be
* resolved; in CJS bundles esbuild replaces import.meta with {}. AgentRC
* always passes an explicit cliPath so this function is dead code, but the
* SDK constructor evaluates it as a default value.
*
* Identical to the shim in vscode-extension/esbuild.mjs — update both together
* if the SDK changes getBundledCliPath internals.
*/
const SDK_FN_RE = /function getBundledCliPath\(\) \{[\s\S]*?\n\}/;
const shimSdkImportMeta: Plugin = {
name: "shim-sdk-import-meta",
setup(build) {
build.onLoad({ filter: /copilot-sdk[\\/]dist[\\/]client\.js$/ }, async (args) => {
const original = await readFile(args.path, "utf8");
const contents = original.replace(
SDK_FN_RE,
'function getBundledCliPath() {\n return "bundled-cli-unavailable";\n}'
);
if (contents === original) {
throw new Error(
"[shim-sdk-import-meta] SDK internals changed — getBundledCliPath() " +
"not found in " +
args.path +
". Update the shim in tsup.config.ts and vscode-extension/esbuild.mjs."
);
}
return { contents, loader: "js" };
});
}
};
export default defineConfig({
entry: ["src/index.ts"],
format: ["esm"],
target: "node20",
outDir: "dist",
clean: true,
splitting: false,
sourcemap: true,
dts: false,
banner: {
// vscode-jsonrpc is CJS and uses require("util") etc. When bundled into
// ESM, esbuild's __require polyfill throws because `require` is undefined.
// Providing a real require via createRequire fixes this for Node built-ins.
// Use alias (__bannerCreateRequire) to avoid colliding with cli.ts's own
// `import { createRequire } from "node:module"` in the bundled output.
js: '#!/usr/bin/env node\nimport { createRequire as __bannerCreateRequire } from "node:module";\nconst require = __bannerCreateRequire(import.meta.url);'
},
// Keep node_modules as external — they'll be installed via npm
external: [/^[^./]/],
// Bundle workspace package (source .ts files) and the Copilot SDK.
// The SDK uses dynamic import() so it won't be present in a stale npx
// cache; bundling it avoids ERR_MODULE_NOT_FOUND in that scenario.
// vscode-jsonrpc is a transitive dep of the SDK whose subpath exports
// lack the .js extension, breaking ESM resolution at runtime.
noExternal: [/@agentrc\/core/, /@github\/copilot-sdk/, /vscode-jsonrpc/],
esbuildPlugins: [shimSdkImportMeta],
esbuildOptions(options) {
options.jsx = "automatic";
// Resolve @agentrc/core subpath imports to source files
options.alias = {
"@agentrc/core": "./packages/core/src"
};
},
async onSuccess() {
// Remove stale skills and copy fresh assets alongside the bundled JS
rmSync("dist/skills", { recursive: true, force: true });
cpSync("plugin/skills", "dist/skills", { recursive: true });
}
});