Skip to content

Commit 237f2f8

Browse files
committed
fix: running destroy script from symlinks
1 parent 0d7aae4 commit 237f2f8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

bin/destroy.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env node
22

33
import * as path from 'path'
4-
import { fileURLToPath } from 'url'
4+
import { realpathSync } from 'fs'
5+
import { pathToFileURL } from 'url'
56
import { spawnSync } from 'child_process'
67
import { createRequire } from 'node:module'
78

@@ -45,6 +46,12 @@ export async function main(args: string[]): Promise<void> {
4546
}
4647
}
4748

48-
if (process.argv[1] === fileURLToPath(import.meta.url)) {
49+
function wasCalledAsScript(): boolean {
50+
const realPath = realpathSync(process.argv[1])
51+
const realPathAsUrl = pathToFileURL(realPath).href
52+
return import.meta.url === realPathAsUrl
53+
}
54+
55+
if (wasCalledAsScript()) {
4956
main(process.argv)
5057
}

0 commit comments

Comments
 (0)