cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
generated-e2be739c44

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

build

53lines · modecode

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