forked from openai/openai-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·60 lines (52 loc) · 2.25 KB
/
build
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
#!/usr/bin/env bash
set -exuo pipefail
node scripts/check-version.cjs
# Build into dist and will publish the package from there,
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
# This way importing from `"openai/resources/foo"` works
# even with `"moduleResolution": "node"`
rm -rf dist; mkdir dist
# Copy src to dist/src and build from dist/src into dist, so that
# the source map for index.js.map will refer to ./src/index.ts etc
cp -rp src README.md dist
rm dist/src/_shims/*-deno.*
for file in LICENSE CHANGELOG.md; do
if [ -e "${file}" ]; then cp "${file}" dist; fi
done
if [ -e "bin/cli" ]; then
mkdir dist/bin
cp -p "bin/cli" dist/bin/;
fi
# this converts the export map paths for the dist directory
# and does a few other minor things
node scripts/make-dist-package-json.cjs > dist/package.json
# build to .js/.mjs/.d.ts files
npm exec tsc-multi
# copy over handwritten .js/.mjs/.d.ts files
cp src/_shims/*.{d.ts,js,mjs} dist/_shims
npm exec tsc-alias -- -p tsconfig.build.json
# we need to add exports = module.exports = OpenAI Node to index.js;
# No way to get that from index.ts because it would cause compile errors
# when building .mjs
node scripts/fix-index-exports.cjs
# with "moduleResolution": "nodenext", if ESM resolves to index.d.ts,
# it'll have TS errors on the default import. But if it resolves to
# index.d.mts the default import will work (even though both files have
# the same export default statement)
cp dist/index.d.ts dist/index.d.mts
cp tsconfig.dist-src.json dist/src/tsconfig.json
# strip out lib="dom" and types="node" references; these are needed at build time,
# but would pollute the user's TS environment
find dist -type f -exec node scripts/remove-triple-slash-references.js {} +
# strip out `unknown extends RequestInit ? never :` from dist/src/_shims;
# these cause problems when viewing the .ts source files in go to definition
find dist/src/_shims -type f -exec node scripts/replace-shim-guards.js {} +
npm exec prettier -- --loglevel=warn --write .
# make sure that nothing crashes when we require the output CJS or
# import the output ESM
(cd dist && node -e 'require("openai")')
(cd dist && node -e 'import("openai")' --input-type=module)
if command -v deno &> /dev/null && [ -e ./build-deno ]
then
./build-deno
fi