cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
scripts/build
56lines · modeblame
2d51afdcstainless-app[bot]2 years ago | 1 | #!/usr/bin/env bash |
dbae3674stainless-app[bot]2 years ago | 2 | |
2d51afdcstainless-app[bot]2 years ago | 3 | set -exuo pipefail |
| 4 | | |
dbae3674stainless-app[bot]2 years ago | 5 | cd "$(dirname "$0")/.." |
| 6 | | |
| 7 | node scripts/utils/check-version.cjs | |
2d51afdcstainless-app[bot]2 years ago | 8 | |
| 9 | # Build into dist and will publish the package from there, | |
| 10 | # so that src/resources/foo.ts becomes <package root>/resources/foo.js | |
| 11 | # This way importing from `"cloudflare/resources/foo"` works | |
| 12 | # even with `"moduleResolution": "node"` | |
| 13 | | |
| 14 | rm -rf dist; mkdir dist | |
| 15 | # Copy src to dist/src and build from dist/src into dist, so that | |
| 16 | # the source map for index.js.map will refer to ./src/index.ts etc | |
| 17 | cp -rp src README.md dist | |
| 18 | rm dist/src/_shims/*-deno.ts dist/src/_shims/auto/*-deno.ts | |
| 19 | for file in LICENSE CHANGELOG.md; do | |
| 20 | if [ -e "${file}" ]; then cp "${file}" dist; fi | |
| 21 | done | |
| 22 | if [ -e "bin/cli" ]; then | |
| 23 | mkdir dist/bin | |
| 24 | cp -p "bin/cli" dist/bin/; | |
| 25 | fi | |
| 26 | # this converts the export map paths for the dist directory | |
| 27 | # and does a few other minor things | |
dbae3674stainless-app[bot]2 years ago | 28 | node scripts/utils/make-dist-package-json.cjs > dist/package.json |
2d51afdcstainless-app[bot]2 years ago | 29 | |
| 30 | # build to .js/.mjs/.d.ts files | |
| 31 | npm exec tsc-multi | |
| 32 | # copy over handwritten .js/.mjs/.d.ts files | |
| 33 | cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims | |
| 34 | cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto | |
eaf523cdstainless-app[bot]1 years ago | 35 | # we need to add exports = module.exports = Cloudflare to index.js; |
2d51afdcstainless-app[bot]2 years ago | 36 | # No way to get that from index.ts because it would cause compile errors |
| 37 | # when building .mjs | |
dbae3674stainless-app[bot]2 years ago | 38 | node scripts/utils/fix-index-exports.cjs |
2d51afdcstainless-app[bot]2 years ago | 39 | # with "moduleResolution": "nodenext", if ESM resolves to index.d.ts, |
| 40 | # it'll have TS errors on the default import. But if it resolves to | |
| 41 | # index.d.mts the default import will work (even though both files have | |
| 42 | # the same export default statement) | |
| 43 | cp dist/index.d.ts dist/index.d.mts | |
| 44 | cp tsconfig.dist-src.json dist/src/tsconfig.json | |
| 45 | | |
dbae3674stainless-app[bot]2 years ago | 46 | node scripts/utils/postprocess-files.cjs |
2d51afdcstainless-app[bot]2 years ago | 47 | |
| 48 | # make sure that nothing crashes when we require the output CJS or | |
| 49 | # import the output ESM | |
| 50 | (cd dist && node -e 'require("cloudflare")') | |
| 51 | (cd dist && node -e 'import("cloudflare")' --input-type=module) | |
| 52 | | |
0340ab0bstainless-app[bot]1 years ago | 53 | if [ -e ./scripts/build-deno ] |
2d51afdcstainless-app[bot]2 years ago | 54 | then |
dbae3674stainless-app[bot]2 years ago | 55 | ./scripts/build-deno |
2d51afdcstainless-app[bot]2 years ago | 56 | fi |