Skip to content

Commit 8386fa1

Browse files
committed
Added packaging compatibility checks
1 parent 1cdbd12 commit 8386fa1

File tree

7 files changed

+61
-21
lines changed

7 files changed

+61
-21
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"dist/simplex-noise.js.map",
1515
"dist/simplex-noise.mjs",
1616
"dist/simplex-noise.mjs.map",
17-
"dist/index.d.ts"
17+
"dist/types.d.ts"
1818
],
1919
"devDependencies": {
2020
"@parcel/packager-ts": "^2.0.0-rc.0",
@@ -58,9 +58,9 @@
5858
},
5959
"scripts": {
6060
"start": "parcel test/visual.html",
61-
"test": "eslint simplex-noise.ts && mocha",
61+
"test": "eslint simplex-noise.ts && mocha && ./test/module-compatibility.sh",
6262
"build": "parcel build",
6363
"prepare": "npm run-script build",
64-
"benchmark": "node ./perf/benchmark.js"
64+
"benchmark": "parcel build && node ./perf/benchmark.js"
6565
}
66-
}
66+
}

perf/benchmark.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
var Benchmark = this.Benchmark || require('benchmark');
2-
var SimplexNoise = this.SimplexNoise || require('../simplex-noise');
3-
var simplex = new SimplexNoise();
1+
const Benchmark = this.Benchmark || require('benchmark');
2+
const SimplexNoise = this.SimplexNoise || require('..');
3+
const simplex = new SimplexNoise();
44

5-
var suite = new Benchmark.Suite('simplex-noise')
5+
new Benchmark.Suite('simplex-noise')
66
.add('init', function() {
7-
var simplex = new SimplexNoise();
7+
new SimplexNoise();
88
})
99
.add('noise2D', function() {
10-
for (var x = 0; x < 8; x++) {
11-
for (var y = 0; y < 8; y++) {
12-
for (var z = 0; z < 8; z++) {
10+
for (let x = 0; x < 8; x++) {
11+
for (let y = 0; y < 8; y++) {
12+
for (let z = 0; z < 8; z++) {
1313
simplex.noise2D(x / 8, y / 8);
1414
}
1515
}
1616
}
1717
})
1818
.add('noise3D', function() {
19-
for (var x = 0; x < 8; x++) {
20-
for (var y = 0; y < 8; y++) {
21-
for (var z = 0; z < 8; z++) {
19+
for (let x = 0; x < 8; x++) {
20+
for (let y = 0; y < 8; y++) {
21+
for (let z = 0; z < 8; z++) {
2222
simplex.noise3D(x / 8, y / 8, z / 8);
2323
}
2424
}
2525
}
2626
})
2727
.add('noise3D2', function() {
28-
for (var x = 0; x < 8; x++) {
29-
for (var y = 0; y < 8; y++) {
30-
for (var z = 0; z < 8; z++) {
28+
for (let x = 0; x < 8; x++) {
29+
for (let y = 0; y < 8; y++) {
30+
for (let z = 0; z < 8; z++) {
3131
simplex.noise3D(x / 8, y / 8, z / 8);
3232
}
3333
}
3434
}
3535
})
3636
.add('noise4D', function() {
37-
for (var x = 0; x < 8; x++) {
38-
for (var y = 0; y < 8; y++) {
39-
for (var z = 0; z < 8; z++) {
37+
for (let x = 0; x < 8; x++) {
38+
for (let y = 0; y < 8; y++) {
39+
for (let z = 0; z < 8; z++) {
4040
simplex.noise4D(x / 8, y / 8, z / 8, (x + y) / 16);
4141
}
4242
}

simplex-noise.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,9 @@ function masher() {
464464
return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
465465
};
466466
}
467+
468+
// nasty hack to make the default export stay the same as 2.x
469+
// when used in commonjs
470+
if (typeof module !== undefined) {
471+
module.exports = SimplexNoise;
472+
}

test/module-compatibility.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
NAME=$(jq -r .name package.json)
3+
set -e
4+
node_major_version=$(node --version|sed 's/v\([^.]*\).*/\1/g')
5+
rm -rf e2e
6+
mkdir -p e2e
7+
rm -f $($NAME*.tgz)
8+
npm pack
9+
tarball=($NAME*.tgz)
10+
mv "$tarball" e2e
11+
cd e2e
12+
cp -R ../test/module-compatibility .
13+
cd module-compatibility
14+
npm install "../$tarball"
15+
echo "testing node commonjs"
16+
node commonjs.js
17+
if [ "$node_major_version" -ge 14 ]
18+
then
19+
echo "testing typescript"
20+
cp esm.mjs typescript.ts
21+
node --loader ts-node/esm typescript.ts
22+
echo "testing node esm"
23+
node esm.mjs
24+
fi
25+
cd ..
26+
27+
cd ..
28+
rm -rf e2e
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const SimplexNoise = require('simplex-noise');
3+
console.log(new SimplexNoise('seed').noise2D(1, 2));

test/module-compatibility/esm.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import SimplexNoise from 'simplex-noise';
2+
console.log(new SimplexNoise('seed').noise2D(1, 2));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)