Skip to content

Commit 183d54f

Browse files
committed
build: fix native postinstall
The last iteration did not account for flattened node_modules. This checks our own node_modules and then the parent node_modules.
1 parent 7129d16 commit 183d54f

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
const fs = require('fs')
22
const path = require('path')
3-
const mkdir = name => fs.existsSync(name) || fs.mkdirSync(name)
3+
const mkdir = dir => fs.existsSync(dir) || fs.mkdirSync(dir)
4+
const checkPath = file => fs.existsSync(file) && file
45

5-
process.chdir(__dirname)
6-
mkdir('node_modules')
6+
// Link "node_modules/shared" to wherever "@react-spring/shared" can be found.
7+
createAlias('shared', '@react-spring/shared')
78

8-
// Link "node_modules/shared" to "node_modules/@react-spring/shared"
9-
const target = '@react-spring/shared'
10-
fs.symlinkSync(target, 'node_modules/shared')
9+
function createAlias(alias, target) {
10+
target =
11+
// Look for "node_modules/@react-spring/{self}/node_modules/{target}"
12+
checkPath(path.join(__dirname, 'node_modules', target)) ||
13+
// Look for "node_modules/{target}"
14+
checkPath(path.resolve(__dirname, '../..', target))
15+
16+
if (target) {
17+
let origin = path.join(__dirname, 'node_modules')
18+
mkdir(origin)
19+
target = path.relative(origin, target)
20+
origin = path.join(origin, alias)
21+
fs.symlinkSync(target, origin)
22+
}
23+
}

0 commit comments

Comments
 (0)