22
33set -e
44
5- rm -rf dist assets
6- mkdir -p dist assets
5+ rm -rf dist assets test/tmp
6+ mkdir -p dist assets test/tmp
77
88# Store package version
99PACKAGE_VERSION=$( node -p -e ' require("./package.json").version' )
1010echo " ${PACKAGE_VERSION} " > assets/VERSION
1111
1212# First build ESM version that is used for testing
13- npx tsc src/hsluv.ts --outDir dist/esm --module es6 --target es6
14- echo ' {"type": "module"} ' > dist/esm/package.json
13+ npx tsc src/hsluv.ts --outDir dist --module es6 --target es6
14+ mv dist/hsluv.js dist/hsluv.mjs
1515
1616# Test against snapshot before continuing
1717node test/test.mjs
1818
1919# Build CommonJS version
20- npx tsc src/hsluv.ts --outDir dist/cjs --module commonjs --target es6
21- echo ' {"type": "commonjs"} ' > dist/cjs/package.json
20+ npx tsc src/hsluv.ts --outDir dist --module commonjs --target es6
21+ mv dist/hsluv.js dist/hsluv.cjs
2222
2323# Build d.ts file
2424npx tsc src/hsluv.ts --outDir dist --declaration --emitDeclarationOnly
2525
2626# Build hsluv.min.js
27- echo ' import {Hsluv} from "./esm/ hsluv.js ";window.Hsluv = Hsluv;' > dist/browser-entry.js
27+ echo ' import {Hsluv} from "./hsluv.mjs ";window.Hsluv = Hsluv;' > dist/browser-entry.js
2828npx esbuild dist/browser-entry.js --bundle --minify --outfile=" assets/hsluv-${PACKAGE_VERSION} .min.js"
2929
3030# Sanity check hsluv.min.js window export
@@ -37,9 +37,20 @@ node dist/browser-test.js
3737TARBALL=$( cd assets && npm pack ../)
3838
3939# Test that both commonjs and esm imports work
40- rm -rf test/tmp
41- mkdir test/tmp
4240echo " {}" > test/tmp/package.json
41+ echo ' import {Hsluv} from "hsluv";' > test/tmp/test.ts
42+ echo ' import {Hsluv} from "hsluv";' > test/tmp/test.mjs
43+ echo ' const {Hsluv} = require("hsluv");' > test/tmp/test.cjs
44+
4345(cd test/tmp && npm install " ../../assets/${TARBALL} " )
44- (cd test/tmp && node --input-type=module -e ' import {Hsluv} from "hsluv"; console.log("ESM OK")' )
45- (cd test/tmp && node --input-type=commonjs -e ' const {Hsluv} = require("hsluv"); console.log("CommonJS OK")' )
46+ node test/tmp/test.mjs
47+ echo " ESM import OK"
48+ node test/tmp/test.cjs
49+ echo " CommonJS require OK"
50+
51+ # Test that TypeScript can discover types with various configurations
52+ # Discussion: https://github.com/hsluv/hsluv-javascript/pull/4
53+ for m in " node10" " node16" " bundler" ; do
54+ (cd test/tmp && npx tsc --strict true --module es2020 --moduleResolution " $m " test.ts)
55+ echo " tsc (--moduleResolution $m ) OK"
56+ done
0 commit comments