Skip to content

Commit

Permalink
chore: restore browser builds
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Jun 12, 2024
1 parent 651a959 commit fcf627d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
16 changes: 3 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,14 @@
"import": "./wrapper.mjs"
},
"browser": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
"import": "./dist/esm-browser/index.js",
"require": "./dist/cjs-browser/index.js"
},
"default": "./dist/esm/index.js"
"default": "./dist/esm-browser/index.js"
},
"./package.json": "./package.json"
},
"module": "./dist/esm/index.js",
"browser": {
"./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",
"CONTRIBUTING.md",
Expand Down
32 changes: 26 additions & 6 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,31 @@ DIR="$ROOT/dist"
rm -rf "$DIR"
mkdir -p "$DIR"

# Build CKS version
tsc -p tsconfig.cjs.json
for MODULE_TYPE in esm cjs; do
echo "Building ${MODULE_TYPE}"

# Build ESM version
tsc -p tsconfig.esm.json
DIST_DIR="$DIR/${MODULE_TYPE}"
BROWSER_DIR="$DIR/${MODULE_TYPE}-browser"

# Copy CLI files
cp -pr "$DIR/../src/bin" "$DIR/esm"
tsc -p tsconfig.${MODULE_TYPE}.json

# Clone files for browser builds
cp -pr ${DIST_DIR} ${BROWSER_DIR}

# Remove browser files from non-browser builds
for FILE in ${DIST_DIR}/*-browser*;do
rm -f $FILE
done

# Move browser files into place for browser builds
for FILE in ${BROWSER_DIR}/*-browser*;do
mv $FILE ${FILE/-browser/}
done

# If MODULE_TYPE is esm, copy bin files to dist
if [ "$MODULE_TYPE" = "esm" ]; then
cp -pr "$DIR/../src/bin" "$DIST_DIR"
fi
done

echo "-- fin --"
2 changes: 1 addition & 1 deletion src/uuid-bin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert';
import * as assert from 'assert';

import { UUIDString } from './_types.js';
import v1 from './v1.js';
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "Node16",
"moduleResolution": "Node16",
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "./dist/cjs"
}
}
2 changes: 1 addition & 1 deletion tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"moduleResolution": "Node",
"outDir": "./dist/esm"
}
}

0 comments on commit fcf627d

Please sign in to comment.