Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move to src directory, improve ecosystem compatibility #122

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions _shims/fetch.node.ts

This file was deleted.

32 changes: 0 additions & 32 deletions _shims/fetch.ts

This file was deleted.

22 changes: 0 additions & 22 deletions _shims/formdata.ts

This file was deleted.

94 changes: 0 additions & 94 deletions _shims/newFileArgs.ts

This file was deleted.

25 changes: 0 additions & 25 deletions _shims/toFile.node.ts

This file was deleted.

26 changes: 0 additions & 26 deletions _shims/toFile.ts

This file was deleted.

21 changes: 0 additions & 21 deletions _shims/uploadable.node.ts

This file was deleted.

82 changes: 0 additions & 82 deletions _shims/uploadable.ts

This file was deleted.

5 changes: 4 additions & 1 deletion bin/publish-npm
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
set -eux

npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
yarn publish --build --access public

yarn build
cd dist
yarn publish --access public
52 changes: 39 additions & 13 deletions build
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
#!/usr/bin/env bash
set -exuo pipefail

rm -rf dist/*
node scripts/check-version.cjs

yarn ts-node --transpileOnly check-version.ts
# Build into dist and will publish the package from there,
# so that src/resources/foo.ts becomes <package root>/resources/foo.js
# This way importing from `"modern-treasury/resources/foo"` works
# even with `"moduleResolution": "node"`

# build node:
node scripts/prepare-cjs-build.mjs
yarn tsc -p tsconfig.cjs.json
yarn tsc-alias -p tsconfig.cjs.json
rm -rf dist
mkdir dist
# Copy src to dist/src and build from dist/src into dist, so that
# the source map for index.js.map will refer to ./src/index.ts etc
cp -rp src dist
# this converts the export map paths for the dist directory
# and does a few other minor things
node scripts/make-dist-package-json.cjs > dist/package.json

node scripts/prepare-esm-build.mjs
yarn tsc -p tsconfig.esm.json
yarn tsc-alias -p tsconfig.esm.json --resolve-full-paths true
# build to .js/.mjs/.d.ts files
tsc-multi
# copy over handwritten .js/.mjs/.d.ts files
cp src/_shims/*.{d.ts,js,mjs} dist/_shims
tsc-alias -p tsconfig.json --resolve-full-paths
# we need to add exports = module.exports = Modern Treasury Node to index.js;
# No way to get that from index.ts because it would cause compile errors
# when building .mjs
node scripts/fix-index-exports.cjs
# with "moduleResolution": "nodenext", if ESM resolves to index.d.ts,
# it'll have TS errors on the default import. But if it resolves to
# index.d.mts the default import will work (even though both files have
# the same export default statement)
cp dist/index.d.ts dist/index.d.mts

echo '{"type": "module"}' > dist/esm/package.json
# strip out lib="dom" and types="node" references; these are needed at build time,
# but would pollute the user's TS environment
REFERENCE_SUBS='s/^ *\/\/\/ *<reference *lib="dom".*//g;s/^ *\/\/\/ *<reference *types="node".*//g'
if [[ "$OSTYPE" == "darwin"* ]]; then
find dist -type f -exec sed -i '' "${REFERENCE_SUBS}" {} +
else
find dist -type f -exec sed -i "${REFERENCE_SUBS}" {} +
fi

yarn prettier --loglevel=warn --write .

# smoke test cjs export
# make sure that nothing crashes when we require the output CJS or
# import the output ESM
cd dist
node -e 'require("modern-treasury")'
# smoke test esm export
node -e 'import("modern-treasury")'
node -e 'import("modern-treasury")' --input-type=module
Loading