diff --git a/packages/visual-studio-code-extension/package.json b/packages/visual-studio-code-extension/package.json index c114e587cf..262f1dff01 100644 --- a/packages/visual-studio-code-extension/package.json +++ b/packages/visual-studio-code-extension/package.json @@ -40,7 +40,7 @@ }, "scripts": { "publish": "vsce publish", - "package": "vsce package", + "package": "node ./prebuild.mjs && vsce package", "vscode:prepublish": "pnpm build --minify", "build": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --tsconfig=./tsconfig.json --external:vscode --external:esbuild --format=cjs --platform=node", "pretest": "pnpm build && pnpm lint", diff --git a/packages/visual-studio-code-extension/prebuild.mjs b/packages/visual-studio-code-extension/prebuild.mjs new file mode 100644 index 0000000000..9ba27b7afa --- /dev/null +++ b/packages/visual-studio-code-extension/prebuild.mjs @@ -0,0 +1,31 @@ +import fs from "node:fs/promises"; +import path from "node:path"; + +async function dereferenceSymlinks(directory) { + async function traverse(dir) { + const entries = await fs.readdir(dir, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = path.resolve(entry.path, entry.name); + const stats = await fs.lstat(fullPath); + + if (stats.isSymbolicLink()) { + const realPath = await fs.realpath(fullPath); + + await fs.rm(fullPath, { force: true, recursive: true }); + await fs.cp(realPath, fullPath, { + recursive: true, + dereference: true, + }); + } + + if (entry.isDirectory()) { + await traverse(fullPath); + } + } + } + + await traverse(directory); +} + +await dereferenceSymlinks(path.resolve(import.meta.dirname, "node_modules"));