/
linker.js
58 lines (52 loc) · 1.28 KB
/
linker.js
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
// @ts-check
// All of this is derived from the main functionality of bin-links that unfortunately would not allow for absolute path links
const binTarget = require('bin-links/lib/bin-target.js')
const isWindows = require('bin-links/lib/is-windows.js')
const linkBin = isWindows
? require('bin-links/lib/shim-bin.js')
: require('bin-links/lib/link-bin.js')
const { dirname, resolve, relative } = require('node:path')
/**
* @param {LinkBinOpts} opts
*/
const linkBinRelative = ({
path,
bin,
link,
top = undefined,
force = true,
}) => {
const target = binTarget({ path, top })
const to = resolve(target, bin)
const absFrom = resolve(path, link)
const from = relative(dirname(to), absFrom)
return linkBin({ path, from, to, absFrom, force })
}
/**
* @param {LinkBinOpts} opts
*/
const linkBinAbsolute = ({
path,
bin,
link,
top = undefined,
force = true,
}) => {
const target = binTarget({ path, top })
const to = resolve(target, bin)
const absFrom = link
const from = link
return linkBin({ path, from, to, absFrom, force })
}
module.exports = {
linkBinRelative,
linkBinAbsolute,
}
/**
* @typedef LinkBinOpts
* @property {string} path
* @property {string} bin
* @property {string} link
* @property {string} [top]
* @property {boolean} [force]
*/