-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpostbuild
More file actions
executable file
·57 lines (47 loc) · 1.15 KB
/
postbuild
File metadata and controls
executable file
·57 lines (47 loc) · 1.15 KB
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
#!/usr/bin/env bash
shopt -s globstar
function create_packages() {
cat >cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF
cat >esm/package.json <<!EOF
{
"type": "module"
}
!EOF
}
function copy_esm_dts() {
mkdir types
pushd cjs || exit 1
find . -type f -name "*.d.ts" -exec cp --parents {} ../types \;
rm ./**/*.{d.mts,d.ts}
popd || exit1
}
function copy_esm() {
mv ./cjs/esm ./esm
}
function fix_esm_extensions() {
esm="./esm"
find "$esm" -type f -name "*.js" | while read -r file; do
content=$(cat "$file")
updated_content=$(echo "$content" | sed "s/import \(.*\) from '\(.*\)\.ts'/import \1 from '\2\.js'/g")
updated_content=$(echo "$updated_content" | sed "s/export \(.*\) from '\(.*\)\.ts'/export \1 from '\2\.js'/g")
echo "$updated_content" >"$file"
done
}
function fix_cjs_extensions() {
cjs="./cjs"
find "$cjs" -type f -name "*.js" | while read -r file; do
content=$(cat "$file")
updated_content=$(echo "$content" | sed "s/require('\(.*\)\.ts'/require('\1\.js'/g")
echo "$updated_content" >"$file"
done
}
cd lib/ || exit 1
copy_esm_dts
copy_esm
create_packages
fix_cjs_extensions
fix_esm_extensions