Skip to content

Commit

Permalink
add prebuild script
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmfern committed Dec 19, 2024
1 parent e7790b9 commit d0e896c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/visual-studio-code-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions packages/visual-studio-code-extension/prebuild.mjs
Original file line number Diff line number Diff line change
@@ -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"));

0 comments on commit d0e896c

Please sign in to comment.