cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v4.2.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

scripts/build

56lines · modeblame

2d51afdcstainless-app[bot]2 years ago1#!/usr/bin/env bash
dbae3674stainless-app[bot]2 years ago2
2d51afdcstainless-app[bot]2 years ago3set -exuo pipefail
4
dbae3674stainless-app[bot]2 years ago5cd "$(dirname "$0")/.."
6
7node scripts/utils/check-version.cjs
2d51afdcstainless-app[bot]2 years ago8
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
20if [ -e "${file}" ]; then cp "${file}" dist; fi
21done
22if [ -e "bin/cli" ]; then
23mkdir dist/bin
24cp -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
dbae3674stainless-app[bot]2 years ago28node scripts/utils/make-dist-package-json.cjs > dist/package.json
2d51afdcstainless-app[bot]2 years ago29
30# build to .js/.mjs/.d.ts files
31npm exec 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
eaf523cdstainless-app[bot]1 years ago35# we need to add exports = module.exports = Cloudflare to index.js;
2d51afdcstainless-app[bot]2 years ago36# No way to get that from index.ts because it would cause compile errors
37# when building .mjs
dbae3674stainless-app[bot]2 years ago38node scripts/utils/fix-index-exports.cjs
2d51afdcstainless-app[bot]2 years ago39# 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
dbae3674stainless-app[bot]2 years ago46node scripts/utils/postprocess-files.cjs
2d51afdcstainless-app[bot]2 years ago47
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 ago53if [ -e ./scripts/build-deno ]
2d51afdcstainless-app[bot]2 years ago54then
dbae3674stainless-app[bot]2 years ago55./scripts/build-deno
2d51afdcstainless-app[bot]2 years ago56fi