Skip to content

Commit 25372f6

Browse files
committed
Fix js ext in ESM
1 parent 737b406 commit 25372f6

File tree

7 files changed

+46
-14
lines changed

7 files changed

+46
-14
lines changed

.github/workflows/main_ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-node@v4
1515
with:
16-
node-version: 18
16+
node-version: 20
1717
registry-url: https://registry.npmjs.org/
1818
- run: npm ci
1919
- run: npm run unit
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@v3
2424
- uses: actions/setup-node@v4
2525
with:
26-
node-version: 18
26+
node-version: 20
2727
registry-url: https://registry.npmjs.org/
2828
- run: npm ci
2929
- run: npm run coverage
@@ -33,7 +33,7 @@ jobs:
3333
- uses: actions/checkout@v3
3434
- uses: actions/setup-node@v4
3535
with:
36-
node-version: 18
36+
node-version: 20
3737
registry-url: https://registry.npmjs.org/
3838
- run: npm ci
3939
- run: npm run format:ci
@@ -43,7 +43,7 @@ jobs:
4343
- uses: actions/checkout@v3
4444
- uses: actions/setup-node@v4
4545
with:
46-
node-version: 18
46+
node-version: 20
4747
registry-url: https://registry.npmjs.org/
4848
- run: npm ci
4949
- run: npm run gitdiff:ci
@@ -53,7 +53,7 @@ jobs:
5353
- uses: actions/checkout@v3
5454
- uses: actions/setup-node@v4
5555
with:
56-
node-version: 18
56+
node-version: 20
5757
registry-url: https://registry.npmjs.org/
5858
- run: npm ci
5959
- run: npm run lint
@@ -63,7 +63,7 @@ jobs:
6363
- uses: actions/checkout@v3
6464
- uses: actions/setup-node@v4
6565
with:
66-
node-version: 18
66+
node-version: 20
6767
registry-url: https://registry.npmjs.org/
6868
- run: npm ci
6969
- run: npm run lint:tests

fixup.cjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@ const updateRequires = (filePath) => {
99
fs.writeFileSync(filePath, content, 'utf8');
1010
};
1111

12+
const updateImports = (filePath) => {
13+
let content = fs.readFileSync(filePath, 'utf8');
14+
//replace local imports eg. from './types'; to from './types.js';
15+
content = content.replace(/from '\.\/([^']*)'/g, "from './$1.js'");
16+
17+
fs.writeFileSync(filePath, content, 'utf8');
18+
};
19+
1220
const processFiles = (dir) => {
1321
fs.readdirSync(dir).forEach((file) => {
1422
const filePath = path.join(dir, file);
1523
if (fs.lstatSync(filePath).isDirectory()) {
1624
processFiles(filePath);
1725
} else if (filePath.endsWith('.cjs')) {
1826
updateRequires(filePath);
27+
} else if (filePath.endsWith('.js')) {
28+
updateImports(filePath);
1929
}
2030
});
2131
};
2232

23-
const dir = path.join(__dirname, 'src', 'cjs');
33+
const dir = path.join(__dirname, 'src');
2434
processFiles(dir);

src/cjs/ecpair.cjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ function ECPairFactory(ecc) {
115115
network: network,
116116
});
117117
}
118+
/**
119+
* Generates a random ECPairInterface.
120+
*
121+
* Uses `crypto.getRandomValues` under the hood for options.rng function, which is still an experimental feature as of Node.js 18.19.0. To work around this you can do one of the following:
122+
* 1. Use a polyfill for crypto.getRandomValues()
123+
* 2. Use the `--experimental-global-webcrypto` flag when running node.js.
124+
* 3. Pass in a custom rng function to generate random values.
125+
*
126+
* @param {ECPairOptions} options - Options for the ECPairInterface.
127+
* @return {ECPairInterface} A random ECPairInterface.
128+
*/
118129
function makeRandom(options) {
119130
v.parse(ECPairOptionsSchema, options);
120131
if (options === undefined) options = {};

src/esm/ecpair.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as networks from './networks';
2-
import * as types from './types';
1+
import * as networks from './networks.js';
2+
import * as types from './types.js';
33
import * as wif from 'wif';
4-
import { testEcc } from './testecc';
4+
import { testEcc } from './testecc.js';
55
export { networks };
66
import * as v from 'valibot';
77
import * as tools from 'uint8array-tools';
@@ -67,6 +67,17 @@ export function ECPairFactory(ecc) {
6767
network: network,
6868
});
6969
}
70+
/**
71+
* Generates a random ECPairInterface.
72+
*
73+
* Uses `crypto.getRandomValues` under the hood for options.rng function, which is still an experimental feature as of Node.js 18.19.0. To work around this you can do one of the following:
74+
* 1. Use a polyfill for crypto.getRandomValues()
75+
* 2. Use the `--experimental-global-webcrypto` flag when running node.js.
76+
* 3. Pass in a custom rng function to generate random values.
77+
*
78+
* @param {ECPairOptions} options - Options for the ECPairInterface.
79+
* @return {ECPairInterface} A random ECPairInterface.
80+
*/
7081
function makeRandom(options) {
7182
v.parse(ECPairOptionsSchema, options);
7283
if (options === undefined) options = {};

src/esm/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { ECPairFactory as default, ECPairFactory, networks } from './ecpair';
1+
export { ECPairFactory as default, ECPairFactory, networks } from './ecpair.js';

test/ecpair.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as assert from 'assert';
22
import { createHash } from 'crypto';
33
import { beforeEach, describe, it } from 'mocha';
4-
import { ECPairFactory, networks as NETWORKS } from 'ecpair';
5-
import type { ECPairInterface, TinySecp256k1Interface } from 'ecpair';
4+
import { ECPairFactory, networks as NETWORKS } from '..';
5+
import type { ECPairInterface, TinySecp256k1Interface } from '..';
66
import fixtures from './fixtures/ecpair.json';
77
import * as tinysecp from 'tiny-secp256k1';
88
import * as tools from 'uint8array-tools';

ts_src/ecpair.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export function ECPairFactory(ecc: TinySecp256k1Interface): ECPairAPI {
157157

158158
/**
159159
* Generates a random ECPairInterface.
160-
*
160+
*
161161
* Uses `crypto.getRandomValues` under the hood for options.rng function, which is still an experimental feature as of Node.js 18.19.0. To work around this you can do one of the following:
162162
* 1. Use a polyfill for crypto.getRandomValues()
163163
* 2. Use the `--experimental-global-webcrypto` flag when running node.js.

0 commit comments

Comments
 (0)