cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
jhutchings1-patch-1

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/build

56lines · modecode

1#!/usr/bin/env bash
2
3set -exuo pipefail
4
5cd "$(dirname "$0")/.."
6
7node 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
14rm -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
17cp -rp src README.md dist
18rm dist/src/_shims/*-deno.ts dist/src/_shims/auto/*-deno.ts
19for file in LICENSE CHANGELOG.md; do
20 if [ -e "${file}" ]; then cp "${file}" dist; fi
21done
22if [ -e "bin/cli" ]; then
23 mkdir dist/bin
24 cp -p "bin/cli" dist/bin/;
25fi
26# this converts the export map paths for the dist directory
27# and does a few other minor things
28node 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
33cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims
34cp 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
38node 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)
43cp dist/index.d.ts dist/index.d.mts
44cp tsconfig.dist-src.json dist/src/tsconfig.json
45
46node 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
53if [ -e ./scripts/build-deno ]
54then
55 ./scripts/build-deno
56fi
57