Skip to content

Commit

Permalink
Make package hybrid cjs-esm
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Mar 24, 2024
1 parent 4796b85 commit f94c719
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 119 deletions.
10 changes: 10 additions & 0 deletions lib/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "module",
"sideEffects": false,
"browser": {
"node:crypto": false
},
"node": {
"./crypto": "./esm/cryptoNode.js"
}
}
66 changes: 15 additions & 51 deletions package-lock.json

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

50 changes: 16 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,60 @@
"main": "index.js",
"module": "index.js",
"files": [
"index.js",
"index.d.ts",
"index.d.ts.map",
"ipns.js",
"ipns.d.ts",
"ipns.d.ts.map",
"hdkey.js",
"hdkey.d.ts",
"hdkey.d.ts.map",
"pgp.js",
"pgp.d.ts",
"pgp.d.ts.map",
"ssh.js",
"ssh.d.ts",
"ssh.d.ts.map",
"tor.js",
"tor.d.ts",
"tor.d.ts.map",
"utils.js",
"utils.d.ts",
"utils.d.ts.map",
"src/index.ts",
"src/ipns.ts",
"src/hdkey.ts",
"src/pgp.ts",
"src/ssh.ts",
"src/tor.ts",
"src/utils.ts"
"lib",
"src"
],
"dependencies": {
"@noble/curves": "~1.4.0",
"@noble/hashes": "~1.4.0",
"@scure/base": "~1.1.5",
"@scure/base": "~1.1.6",
"micro-packed": "~0.5.3"
},
"devDependencies": {
"@paulmillr/jsbt": "0.1.0",
"micro-should": "0.4.0",
"prettier": "3.1.1",
"typescript": "5.3.2"
},
"exports": {
".": {
"types": "./index.d.ts",
"default": "./index.js"
"types": "./lib/index.d.ts",
"import": "./lib/esm/index.js",
"default": "./lib/index.js"
},
"./ipns": {
"types": "./ipns.d.ts",
"default": "./ipns.js"
"types": "./lib/ipns.d.ts",
"import": "./lib/esm/ipns.js",
"default": "./lib/ipns.js"
},
"./hdkey": {
"types": "./hdkey.d.ts",
"import": "./lib/esm/hdkey.js",
"default": "./hdkey.js"
},
"./ssh": {
"types": "./ssh.d.ts",
"import": "./lib/esm/ssh.js",
"default": "./ssh.js"
},
"./pgp": {
"types": "./pgp.d.ts",
"import": "./lib/esm/pgp.js",
"default": "./pgp.js"
},
"./tor": {
"types": "./tor.d.ts",
"import": "./lib/esm/tor.js",
"default": "./tor.js"
},
"./utils": {
"types": "./utils.d.ts",
"import": "./lib/esm/utils.js",
"default": "./utils.js"
}
},
"scripts": {
"build": "tsc",
"build": "tsc && tsc -p tsconfig.esm.json",
"lint": "prettier --check src",
"format": "prettier --write 'src/**/*.{js,ts}' 'test/*.js'",
"test": "node test/index.js"
Expand Down
3 changes: 3 additions & 0 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
4 changes: 2 additions & 2 deletions test/hdkey/index.test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HDKey } from '../../hdkey.js';
import { deepStrictEqual, throws } from 'assert';
import { deepStrictEqual, throws } from 'node:assert';
import { HDKey } from '../../lib/esm/hdkey.js';
import { should } from 'micro-should';
import { bytesToHex } from '@noble/hashes/utils';
import { fixtures } from './slip-0010.fixture.mjs';
Expand Down
4 changes: 2 additions & 2 deletions test/ipns.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepStrictEqual } from 'assert';
import { deepStrictEqual } from 'node:assert';
import { should } from 'micro-should';
import * as ipns from '../ipns.js';
import * as ipns from '../lib/esm/ipns.js';
import { hex } from '@scure/base';

should('ipns: basic', async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/pgp.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepStrictEqual } from 'assert';
import { deepStrictEqual } from 'node:assert';
import { should } from 'micro-should';
import * as pgp from '../pgp.js';
import * as pgp from '../lib/esm/pgp.js';
import { hex } from '@scure/base';

// Generated by gpg (GnuPG) 2.3.3, libgcrypt 1.9.4
Expand Down
8 changes: 4 additions & 4 deletions test/pgp_keygen.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import cp from 'child_process';
import fs from 'fs';
import { deepStrictEqual } from 'node:assert';
import cp from 'node:child_process';
import fs from 'node:fs';
import { randomBytes } from '@noble/hashes/utils';
import pgp from '../pgp.js';
import { deepStrictEqual } from 'assert';
import pgp from '../lib/esm/pgp.js';
import { should } from 'micro-should';

// Warning: this test will execute system command `gpg`
Expand Down
4 changes: 2 additions & 2 deletions test/ssh.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepStrictEqual } from 'assert';
import { deepStrictEqual } from 'node:assert';
import { should } from 'micro-should';
import * as ssh from '../ssh.js';
import * as ssh from '../lib/esm/ssh.js';
import { hex } from '@scure/base';

// Real key from the internet
Expand Down
4 changes: 2 additions & 2 deletions test/tor.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepStrictEqual } from 'assert';
import { deepStrictEqual } from 'node:assert';
import { should } from 'micro-should';
import * as tor from '../tor.js';
import * as tor from '../lib/esm/tor.js';
import { hex } from '@scure/base';

should('tor: basic', async () => {
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@paulmillr/jsbt/tsconfigs/esm.json",
"compilerOptions": {
"outDir": "lib/esm"
},
"include": ["index.ts", "src"],
"exclude": ["node_modules", "lib"]
}
23 changes: 3 additions & 20 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
{
"extends": "@paulmillr/jsbt/tsconfigs/cjs.json",
"compilerOptions": {
"target": "es2020",
"lib": ["es2020"],
"strict": true,
"sourceMap": false,
"allowSyntheticDefaultImports": false,
"allowUnreachableCode": false,
"esModuleInterop": false,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUncheckedIndexedAccess": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"baseUrl": ".",

"module": "es2020",
"outDir": ".",
"moduleResolution": "bundler",
"declaration": true,
"declarationMap": true
"outDir": "lib"
},
"include": ["src"],
"include": ["index.ts", "src"],
"exclude": ["node_modules", "lib"]
}

0 comments on commit f94c719

Please sign in to comment.