forked from devartifex/copilot-unleashed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch-sdk.mjs
More file actions
34 lines (29 loc) · 1.12 KB
/
Copy pathpatch-sdk.mjs
File metadata and controls
34 lines (29 loc) · 1.12 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
/**
* Patches @github/copilot-sdk/dist/session.js to fix a missing `.js` extension
* on the `vscode-jsonrpc/node` import, which causes ERR_MODULE_NOT_FOUND on
* Node 24 in ESM mode.
*
* Bug: import ... from "vscode-jsonrpc/node"
* Fix: import ... from "vscode-jsonrpc/node.js"
*/
import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
const root = resolve(fileURLToPath(import.meta.url), '..', '..');
const target = resolve(root, 'node_modules/@github/copilot-sdk/dist/session.js');
let src;
try {
src = readFileSync(target, 'utf8');
} catch {
console.log('[patch-sdk] @github/copilot-sdk/dist/session.js not found, skipping.');
process.exit(0);
}
const BAD = '"vscode-jsonrpc/node"';
const GOOD = '"vscode-jsonrpc/node.js"';
if (!src.includes(BAD)) {
console.log('[patch-sdk] already patched or import not present, nothing to do.');
process.exit(0);
}
const patched = src.replaceAll(BAD, GOOD);
writeFileSync(target, patched, 'utf8');
console.log('[patch-sdk] patched vscode-jsonrpc/node → vscode-jsonrpc/node.js in @github/copilot-sdk/dist/session.js');