Skip to content

Commit

Permalink
chore: add tsconfig and update build script
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Jun 11, 2024
1 parent 17675e8 commit 95f9d5e
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 76 deletions.
30 changes: 17 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "uuid",
"version": "10.0.0",
"description": "RFC9562 UUIDs",
"type": "module",
"funding": [
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
Expand All @@ -19,32 +20,35 @@
],
"license": "MIT",
"bin": {
"uuid": "./dist/bin/uuid"
"uuid": "./dist/esm/bin/uuid"
},
"sideEffects": false,
"main": "./dist/index.js",
"main": "./dist/cjs/index.js",
"exports": {
".": {
"node": {
"module": "./dist/esm-node/index.js",
"require": "./dist/index.js",
"module": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"import": "./wrapper.mjs"
},
"browser": {
"import": "./dist/esm-browser/index.js",
"require": "./dist/commonjs-browser/index.js"
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"default": "./dist/esm-browser/index.js"
"default": "./dist/esm/index.js"
},
"./package.json": "./package.json"
},
"module": "./dist/esm-node/index.js",
"module": "./dist/esm/index.js",
"browser": {
"./dist/esm-node/index.js": "./dist/esm-browser/index.js",
"./dist/md5.js": "./dist/md5-browser.js",
"./dist/native.js": "./dist/native-browser.js",
"./dist/rng.js": "./dist/rng-browser.js",
"./dist/sha1.js": "./dist/sha1-browser.js"
"./dist/cjs/md5.js": "./dist/cjs/md5-browser.js",
"./dist/cjs/native.js": "./dist/cjs/native-browser.js",
"./dist/cjs/rng.js": "./dist/cjs/rng-browser.js",
"./dist/cjs/sha1.js": "./dist/cjs/sha1-browser.js",
"./dist/esm/md5.js": "./dist/esm/md5-browser.js",
"./dist/esm/native.js": "./dist/esm/native-browser.js",
"./dist/esm/rng.js": "./dist/esm/rng-browser.js",
"./dist/esm/sha1.js": "./dist/esm/sha1-browser.js"
},
"files": [
"CHANGELOG.md",
Expand Down
2 changes: 1 addition & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
arrowParens: 'always',
printWidth: 100,
proseWrap: 'never',
Expand Down
53 changes: 6 additions & 47 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,11 @@ DIR="$ROOT/dist"
rm -rf "$DIR"
mkdir -p "$DIR"

# We ship 4 builds of this library: ESM and CommonJS, each for Node.js and the Browser.
# In ./src, code that uses browser APIs lives in `-browser.js` files, while code for node APIs
# lives in files without suffix.
# For historical reasons, the Node.js CommonJS build lives in the top level ./dist directory while
# the other 3 builds live in their respective ./dist/{commonjs,esm}-{node,browser}/ subdirectories.
#
# The code below produces this layout:
#
# dist (<-- the commonjs-node build)
# ├── commonjs-browser
# ├── esm-node
# ├── esm-node
# └── bin (<-- Node.js CLI)
# Build CKS version
tsc -p tsconfig.cjs.json

# Transpile CommonJS versions of files for node
npx babel --env-name commonjsNode src --source-root src --out-dir "$DIR" --copy-files --quiet
# Build ESM version
tsc -p tsconfig.esm.json

# Transpile CommonJS versions of files for the browser
npx babel --env-name commonjsBrowser src --source-root src --out-dir "$DIR/commonjs-browser" \
--copy-files --quiet

# Transpile ESM versions of files for the browser
npx babel --env-name esmBrowser src --source-root src --out-dir "$DIR/esm-browser" --copy-files --quiet

# Transpile ESM versions of files for node
npx babel --env-name esmNode src --source-root src --out-dir "$DIR/esm-node" --copy-files --quiet

# No need to have the CLI files in the esm build
rm -rf "$DIR/commonjs-browser/bin"
rm -rf "$DIR/commonjs-browser/uuid-bin.js"
rm -rf "$DIR/esm-browser/bin"
rm -rf "$DIR/esm-browser/uuid-bin.js"
rm -rf "$DIR/esm-node/bin"
rm -rf "$DIR/esm-node/uuid-bin.js"

for FILE in "$DIR"/commonjs-browser/*-browser.js
do
echo "Replacing node-specific file for commonjs-browser: $FILE"
mv "$FILE" "${FILE/-browser.js/.js}"
done

for FILE in "$DIR"/esm-browser/*-browser.js
do
echo "Replacing node-specific file for esm-browser: $FILE"
mv "$FILE" "${FILE/-browser.js/.js}"
done

echo "Removing browser-specific files from esm-node"
rm -f "$DIR"/esm-node/*-browser.js
# Copy CLI files
cp -pr "$DIR/../src/bin" "$DIR/esm"
2 changes: 1 addition & 1 deletion src/bin/uuid
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('../uuid-bin');
import '../uuid-bin.js';
10 changes: 10 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"declaration": true,
"removeComments": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "ES2022"
}
}
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "Node16",
"moduleResolution": "Node16",
"outDir": "./dist/cjs"
}
}
8 changes: 8 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"outDir": "./dist/esm"
}
}
13 changes: 0 additions & 13 deletions tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion wrapper.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import uuid from './dist/index.js';
import uuid from './dist/esm/index.js';
export const v1 = uuid.v1;
export const v1ToV6 = uuid.v1ToV6;
export const v3 = uuid.v3;
Expand Down

0 comments on commit 95f9d5e

Please sign in to comment.