Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support node 18 again. This may break some bundlers, in which case t… #5

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [20.x, 22.x]
node-version: [18.x, 20.x, 22.x]
platform: [ubuntu-latest]

runs-on: ${{ matrix.platform }}
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@
},
"devDependencies": {
"@cto.af/eslint-config": "4.1.6",
"@types/node": "22.5.4",
"c8": "10.1.2",
"eslint-plugin-jsdoc": "50.2.2",
"eslint-plugin-markdown": "5.1.0",
"rimraf": "6.0.1",
"typedoc": "0.26.7",
"typescript-eslint": "8.5.0",
"typescript": "5.6.2"
"typescript": "5.6.2",
"typescript-eslint": "8.5.0"
},
"packageManager": "pnpm@9.10.0",
"engines": {
"node": ">=20"
"node": ">=18"
}
}
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export type FreqArray<T> = T[] & {
[FREQ_SYM]?: number[];
};

interface GRV {
getRandomValues<T extends ArrayBufferView | null>(array: T): T;
}

const ourCrypto = (
// eslint-disable-next-line n/no-unsupported-features/node-builtins
(typeof crypto === 'undefined') ? (await import('node:crypto')) : crypto
) as GRV;

/**
* Default RNG that uses crypto.randomBytes.
* @param size Number of bytes.
Expand All @@ -25,8 +34,7 @@ export const randBytes: RandBytes = (
assert(reason);
const array = new Uint8Array(size);

// eslint-disable-next-line n/no-unsupported-features/node-builtins
return crypto.getRandomValues(array);
return ourCrypto.getRandomValues(array);
};

/**
Expand Down
1 change: 1 addition & 0 deletions test/assert.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {assert} from '../lib/assert.js';
// eslint-disable-next-line n/no-unsupported-features/node-builtins
import {test} from 'node:test';
import {throws} from 'node:assert/strict';

Expand Down
3 changes: 3 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import {deepEqual, equal, ok, throws} from 'node:assert/strict';
import {Buffer} from 'node:buffer';
import {Modnar} from './fixtures/modnar.js';
import {Random} from '../lib/index.js';
// eslint-disable-next-line n/no-unsupported-features/node-builtins
import {test} from 'node:test';

// eslint-disable-next-line n/no-unsupported-features/node-builtins
test.beforeEach(t => {
const m = new Modnar();
const r = new Random(m.source);
t.context = {m, r};
});

// eslint-disable-next-line n/no-unsupported-features/node-builtins
test.afterEach(t => {
ok(t.context.m.isDone);
});
Expand Down
1 change: 1 addition & 0 deletions test/vose.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {equal, ok, throws} from 'node:assert/strict';
import {Random} from '../lib/index.js';
import {Vose} from '../lib/vose.js';
// eslint-disable-next-line n/no-unsupported-features/node-builtins
import test from 'node:test';

test('vose', () => {
Expand Down