-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathexport.sh
executable file
·107 lines (78 loc) · 2.77 KB
/
export.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
if [ -n "$NO_EXPORT" ]; then exit; fi
if [ "$1" = "debug" ]; then
DEBUG_ARG="--define:debug=true"
MINIFY_ARG=""
else
DEBUG_ARG="--define:debug=false"
MINIFY_ARG="--minify --line-limit=80"
fi
# == CJS code: index.js ==
npx esbuild export/index.ts \
--format=cjs \
--bundle \
--keep-names \
--inject:shims/shims.js \
--define:BUNDLE_EXT=\"js\" \
--target=es2020 \
--outfile=dist/npm/index.js \
$DEBUG_ARG $MINIFY_ARG
# == ESM code: index.mjs ==
npx esbuild export/index.ts \
--format=esm \
--bundle \
--keep-names \
--inject:shims/shims.js \
--define:BUNDLE_EXT=\"mjs\" \
--target=es2020 \
--outfile=dist/npm/index.mjs \
$DEBUG_ARG $MINIFY_ARG
# == types ==
npx tsc
# remove global declarations from types
sed -i.orig -r \
-e "/^declare global [{]$/,/^[}]$/d" \
dist/dts/shims/net/index.d.ts
# bundle types into one file
npx @microsoft/api-extractor run --local
# remove empty export and private fields
sed -i.orig -r \
-e '/^ *private [^ ]+;$/d' \
-e '/^export [{] *[}]$/d' \
dist/dts/_extracted.d.ts
# copy to .d.ts (for CJS) and .d.mts (for ESM)
cp dist/dts/_extracted.d.ts dist/npm/index.d.ts
cp dist/npm/index.d.ts dist/npm/index.d.mts
# == static assets ==
cp LICENSE README.md CHANGELOG.md CONFIG.md DEPLOY.md DEVELOP.md dist/npm/
# == JSR package ==
cp dist/npm/index.d.ts dist/jsr/
echo "/// <reference types=\"./index.d.ts\" />
" > dist/jsr/index.js
cat dist/npm/index.mjs >> dist/jsr/index.js
cp LICENSE README.md dist/jsr/
# Note: --keep-names for esbuild adds about 10KB to the bundle size, but it
# gives us error messages + stack traces with no short, cryptic variable names
# WITHOUT (see `xe`, `pe`):
# Uncaught:
# xe [NeonDbError]: db error: ERROR: function xnow() does not exist
# HINT: No function matches the given name and argument types. You might need to add explicit type casts.
# Caused by:
# ERROR: function xnow() does not exist
# HINT: No function matches the given name and argument types. You might need to add explicit type casts.
# at processTicksAndRejections (node:internal/process/task_queues:95:5)
# at pe (/Users/george/Development/neon/pgshims/dist/npm/index.js:1459:56) {
# code: '42883',
# sourceError: undefined
# }
# WITH:
# Uncaught NeonDbError: db error: ERROR: function xnow() does not exist
# HINT: No function matches the given name and argument types. You might need to add explicit type casts.
# Caused by:
# ERROR: function xnow() does not exist
# HINT: No function matches the given name and argument types. You might need to add explicit type casts.
# at processTicksAndRejections (node:internal/process/task_queues:95:5)
# at execute (/Users/george/Development/neon/pgshims/dist/npm/index.js:1539:48) {
# code: '42883',
# sourceError: undefined
# }