cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
scripts/build
56lines · modecode
| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -exuo pipefail |
| 4 | |
| 5 | cd "$(dirname "$0")/.." |
| 6 | |
| 7 | node scripts/utils/check-version.cjs |
| 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 |
| 28 | node scripts/utils/make-dist-package-json.cjs > dist/package.json |
| 29 | |
| 30 | # build to .js/.mjs/.d.ts files |
| 31 | ./node_modules/.bin/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 |
| 35 | # we need to add exports = module.exports = Cloudflare to index.js; |
| 36 | # No way to get that from index.ts because it would cause compile errors |
| 37 | # when building .mjs |
| 38 | node scripts/utils/fix-index-exports.cjs |
| 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 | |
| 46 | node scripts/utils/postprocess-files.cjs |
| 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 | |
| 53 | if [ -e ./scripts/build-deno ] |
| 54 | then |
| 55 | ./scripts/build-deno |
| 56 | fi |