forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbun-install.sh
85 lines (60 loc) · 1.97 KB
/
bun-install.sh
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -euo pipefail
dir=$(mktemp -d --suffix=bun-install-test-1)
cd $dir
${NPM_CLIENT:-$(which bun)} add react react-dom @types/react @babel/parser esbuild
echo "console.log(typeof require(\"react\").createElement);" >index.js
chmod +x index.js
JS_RUNTIME=${JS_RUNTIME:-"$(which bun)"}
if [ "$JS_RUNTIME" == "node" ]; then
result="$(node ./index.js)"
fi
if [ "$JS_RUNTIME" != "node" ]; then
result="$($JS_RUNTIME run ./index.js)"
fi
echo "console.log(typeof require(\"react-dom\").render);" >index.js
chmod +x index.js
JS_RUNTIME=${JS_RUNTIME:-"$(which bun)"}
# If this fails to run, it means we didn't link @babel/parser correctly
realpath -e ./node_modules/.bin/parser
# If this fails to run, it means we didn't link esbuild correctly
./node_modules/.bin/esbuild --version >/dev/null
if [ "$JS_RUNTIME" == "node" ]; then
result="$(node ./index.js)"
fi
if [ "$JS_RUNTIME" != "node" ]; then
result="$($JS_RUNTIME run ./index.js)"
fi
if [ "$result" != "function" ]; then
echo "ERR: Expected 'function', got '$result'"
exit 1
fi
${NPM_CLIENT:-$(which bun)} remove react-dom
if [ -d "node_modules/react-dom" ]; then
echo "ERR: react-dom module still exists in $dir"
exit 1
fi
yarn_dot_lock=$(${NPM_CLIENT:-$(which bun)} bun.lockb)
if echo "$yarn_dot_lock" | grep -q "react-dom"; then
echo "ERR: react-dom module still exists in lockfile"
exit 1
fi
${NPM_CLIENT:-$(which bun)} remove @types/react
yarn_dot_lock=$(${NPM_CLIENT:-$(which bun)} bun.lockb)
if echo "$yarn_dot_lock" | grep -q "@types/react"; then
echo "ERR: @types/react module still exists in lockfile"
exit 1
fi
if echo "$yarn_dot_lock" | grep -q "@types/react"; then
echo "ERR: @types/react module still exists in $dir"
exit 1
fi
${NPM_CLIENT:-$(which bun)} remove react
if [ -d "node_modules/react" ]; then
echo "ERR: react module still exists in $dir"
exit 1
fi
if [ -d "bun.lockb" ]; then
echo "ERR: empty bun.lockb should be deleted"
exit 1
fi