2
2
3
3
set -e
4
4
5
- rm -rf dist assets
6
- mkdir -p dist assets
5
+ rm -rf dist assets test/tmp
6
+ mkdir -p dist assets test/tmp
7
7
8
8
# Store package version
9
9
PACKAGE_VERSION=$( node -p -e ' require("./package.json").version' )
10
10
echo " ${PACKAGE_VERSION} " > assets/VERSION
11
11
12
12
# 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
15
15
16
16
# Test against snapshot before continuing
17
17
node test/test.mjs
18
18
19
19
# 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
22
22
23
23
# Build d.ts file
24
24
npx tsc src/hsluv.ts --outDir dist --declaration --emitDeclarationOnly
25
25
26
26
# 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
28
28
npx esbuild dist/browser-entry.js --bundle --minify --outfile=" assets/hsluv-${PACKAGE_VERSION} .min.js"
29
29
30
30
# Sanity check hsluv.min.js window export
@@ -37,9 +37,20 @@ node dist/browser-test.js
37
37
TARBALL=$( cd assets && npm pack ../)
38
38
39
39
# Test that both commonjs and esm imports work
40
- rm -rf test/tmp
41
- mkdir test/tmp
42
40
echo " {}" > 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
+
43
45
(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