Skip to content

Commit 5620002

Browse files
authored
fix: api.js in typescript version (#40)
Hi, I got this error: ``` The requested module 'multiformats' does not provide an export named 'Block' from pail ``` this was happening because, besides api.js, the .d.ts was not in the same directory, which confused tsx. To fix it I changed the exports in package.json and the emitRule of tsc to only use the emitted file structure. SideTrack: I updated the package.json, and with that, the test infra to use vitest. I hope that is not a problem -- if you want to stick with mocha and coverage -> I am not happy but could rewind -> but than the typescript is required to the test infra -> due to the removal of the api.js which causes this problem in the first place. I run standard --fix, which also fixes the formatting that's why so much files.
1 parent dfc8ac0 commit 5620002

27 files changed

+3487
-1680
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ jobs:
2222
strategy:
2323
matrix:
2424
node-version:
25+
# for the sake of it
2526
- 18
2627
- 20
28+
- 22
2729
os:
2830
- ubuntu-latest
2931
runs-on: ${{ matrix.os }}
3032
steps:
3133
- name: Checkout
32-
uses: actions/checkout@v2
33-
- uses: pnpm/action-setup@v2
34+
uses: actions/checkout@v4
35+
- uses: pnpm/action-setup@v4
3436
with:
3537
version: 'latest'
3638
- name: Setup node ${{ matrix.node-version }}
37-
uses: actions/setup-node@v2
39+
uses: actions/setup-node@v4
3840
with:
3941
node-version: ${{ matrix.node-version }}
4042
cache: 'pnpm'

bench/util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Readable } from 'stream'
33
import { CarWriter } from '@ipld/car'
44
// eslint-disable-next-line no-unused-vars
55
import * as API from '../src/api.js'
6+
// eslint-disable-next-line no-unused-vars
67
import { get, entries } from '../src/index.js'
8+
// eslint-disable-next-line no-unused-vars
79
import { MemoryBlockstore } from '../src/block.js'
810
import { ShardFetcher } from '../src/shard.js'
911

@@ -50,7 +52,7 @@ export const collectMetrics = async (blocks, root) => {
5052
if (!Array.isArray(v)) {
5153
totalEntries++
5254
maxDepth = depth > maxDepth ? depth : maxDepth
53-
totalDepth += depth
55+
totalDepth += depth
5456
return
5557
}
5658
if (v[1]) totalEntries++

cli.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ async function openPail (path) {
173173
if (!isShardLink(header.roots[0])) throw new Error(`not a shard: ${header.roots[0]}`)
174174
return { root: header.roots[0], blocks }
175175
} catch (err) {
176+
// @ts-ignore
176177
if (err.code !== 'ENOENT') throw new Error('failed to open bucket', { cause: err })
177178
const rootblk = await ShardBlock.create()
178179
blocks.put(rootblk.cid, rootblk.bytes)
@@ -207,12 +208,14 @@ async function updatePail (path, blocks, root, { additions, removals }) {
207208
try {
208209
await fs.promises.rename(path, old)
209210
} catch (err) {
211+
// @ts-ignore
210212
if (err.code !== 'ENOENT') throw err
211213
}
212214
await fs.promises.rename(tmp, path)
213215
try {
214216
await fs.promises.rm(old)
215217
} catch (err) {
218+
// @ts-ignore
216219
if (err.code !== 'ENOENT') throw err
217220
}
218221
}

package.json

Lines changed: 49 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,130 +2,77 @@
22
"name": "@web3-storage/pail",
33
"version": "0.6.0",
44
"description": "DAG based key value store.",
5-
"main": "src/index.js",
5+
"main": "./dist/src/index.js",
66
"type": "module",
77
"types": "./dist/src/index.d.ts",
8-
"typesVersions": {
9-
"*": {
10-
"*": [
11-
"dist/*"
12-
],
13-
"dist/src/index.d.ts": [
14-
"dist/src/index.d.ts"
15-
],
16-
"api": [
17-
"dist/src/api.d.ts"
18-
],
19-
"batch": [
20-
"dist/src/batch/index.d.ts"
21-
],
22-
"batch/api": [
23-
"dist/src/batch/api.d.ts"
24-
],
25-
"block": [
26-
"dist/src/block.d.ts"
27-
],
28-
"clock": [
29-
"dist/src/clock/index.d.ts"
30-
],
31-
"clock/api": [
32-
"dist/src/clock/api.d.ts"
33-
],
34-
"crdt": [
35-
"dist/src/crdt/index.d.ts"
36-
],
37-
"crdt/api": [
38-
"dist/src/crdt/api.d.ts"
39-
],
40-
"crdt/batch": [
41-
"dist/src/crdt/batch/index.d.ts"
42-
],
43-
"crdt/batch/api": [
44-
"dist/src/crdt/batch/api.d.ts"
45-
],
46-
"diff": [
47-
"dist/src/diff.d.ts"
48-
],
49-
"link": [
50-
"dist/src/link.d.ts"
51-
],
52-
"merge": [
53-
"dist/src/merge.d.ts"
54-
],
55-
"shard": [
56-
"dist/src/shard.d.ts"
57-
]
58-
}
59-
},
608
"exports": {
619
".": {
6210
"types": "./dist/src/index.d.ts",
63-
"import": "./src/index.js"
11+
"import": "./dist/src/index.js"
6412
},
6513
"./api": {
6614
"types": "./dist/src/api.d.ts",
67-
"import": "./src/api.js"
15+
"import": "./dist/src/api.js"
6816
},
6917
"./batch": {
7018
"types": "./dist/src/batch/index.d.ts",
71-
"import": "./src/batch/index.js"
19+
"import": "./dist/src/batch/index.js"
7220
},
7321
"./batch/api": {
7422
"types": "./dist/src/batch/api.d.ts",
75-
"import": "./src/batch/api.js"
23+
"import": "./dist/src/batch/api.js"
7624
},
7725
"./block": {
7826
"types": "./dist/src/block.d.ts",
79-
"import": "./src/block.js"
27+
"import": "./dist/src/block.js"
8028
},
8129
"./clock": {
8230
"types": "./dist/src/clock/index.d.ts",
83-
"import": "./src/clock/index.js"
31+
"import": "./dist/src/clock/index.js"
8432
},
8533
"./clock/api": {
8634
"types": "./dist/src/clock/api.d.ts",
87-
"import": "./src/clock/api.js"
35+
"import": "./dist/src/clock/api.js"
8836
},
8937
"./crdt": {
9038
"types": "./dist/src/crdt/index.d.ts",
91-
"import": "./src/crdt/index.js"
39+
"import": "./dist/src/crdt/index.js"
9240
},
9341
"./crdt/api": {
9442
"types": "./dist/src/crdt/api.d.ts",
95-
"import": "./src/crdt/api.js"
43+
"import": "./dist/src/crdt/api.js"
9644
},
9745
"./crdt/batch": {
9846
"types": "./dist/src/crdt/batch/index.d.ts",
99-
"import": "./src/crdt/batch/index.js"
47+
"import": "./dist/src/crdt/batch/index.js"
10048
},
10149
"./crdt/batch/api": {
10250
"types": "./dist/src/crdt/batch/api.d.ts",
103-
"import": "./src/crdt/batch/api.js"
51+
"import": "./dist/src/crdt/batch/api.js"
10452
},
10553
"./diff": {
10654
"types": "./dist/src/diff.d.ts",
107-
"import": "./src/diff.js"
108-
},
109-
"./link": {
110-
"types": "./dist/src/link.d.ts",
111-
"import": "./src/link.js"
55+
"import": "./dist/src/diff.js"
11256
},
11357
"./merge": {
11458
"types": "./dist/src/merge.d.ts",
115-
"import": "./src/merge.js"
59+
"import": "./dist/src/merge.js"
11660
},
11761
"./shard": {
11862
"types": "./dist/src/shard.d.ts",
119-
"import": "./src/shard.js"
63+
"import": "./dist/src/shard.js"
12064
}
12165
},
12266
"bin": {
123-
"pail": "./cli.js"
67+
"pail": "./dist/cli.js",
68+
"pail-propernames": "./scripts/propernames/gen.sh",
69+
"pail-gen": "./dist/scripts/words/gen.js",
70+
"pail-randomcid": "./dist/scripts/randomcid.js"
12471
},
12572
"scripts": {
12673
"build": "tsc --build",
127-
"test": "mocha test/*.test.js",
128-
"coverage": "c8 -r html -r text npm test",
74+
"test": "vitest --run",
75+
"coverage": "vitest --run --coverage",
12976
"lint": "standard"
13077
},
13178
"keywords": [
@@ -139,23 +86,25 @@
13986
"author": "Alan Shaw",
14087
"license": "Apache-2.0 OR MIT",
14188
"files": [
142-
"src",
14389
"dist"
14490
],
14591
"dependencies": {
146-
"@ipld/dag-cbor": "^9.2.0",
147-
"multiformats": "^13.1.0"
148-
},
149-
"devDependencies": {
92+
"@ipld/dag-cbor": "^9.2.2",
93+
"cli-color": "^2.0.3",
94+
"@ipld/car": "^5.4.0",
15095
"archy": "^1.0.0",
151-
"c8": "^8.0.1",
15296
"carstream": "^2.0.0",
153-
"cli-color": "^2.0.3",
154-
"mocha": "^10.2.0",
155-
"nanoid": "^4.0.0",
156-
"sade": "^1.8.1",
157-
"standard": "^17.0.0",
158-
"typescript": "^5.0.2"
97+
"multiformats": "^13.3.2",
98+
"sade": "^1.8.1"
99+
},
100+
"devDependencies": {
101+
"@types/archy": "^0.0.36",
102+
"@types/cli-color": "^2.0.6",
103+
"@types/node": "^22.13.17",
104+
"@vitest/coverage-v8": "^3.1.1",
105+
"standard": "^17.1.2",
106+
"typescript": "^5.8.2",
107+
"vitest": "^3.1.1"
159108
},
160109
"repository": {
161110
"type": "git",
@@ -166,8 +115,20 @@
166115
},
167116
"homepage": "https://github.com/web3-storage/pail#readme",
168117
"standard": {
169-
"ignore": [
170-
"*.ts"
118+
"globals": [
119+
"describe",
120+
"before",
121+
"after",
122+
"beforeEach",
123+
"afterEach",
124+
"it",
125+
"assert"
126+
]
127+
},
128+
"pnpm": {
129+
"onlyBuiltDependencies": [
130+
"es5-ext",
131+
"esbuild"
171132
]
172133
}
173134
}

0 commit comments

Comments
 (0)