Skip to content

Commit 0318c98

Browse files
authored
fix: publish with types in package.json (#166)
* fix: publish with types in package.json Build types to the `types` folder, then copy it to the `dist` folder during the `prepare` step.
1 parent 137a4ad commit 0318c98

File tree

15 files changed

+43
-33
lines changed

15 files changed

+43
-33
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ node_modules
4040

4141
lib
4242
dist
43+
types

.travis.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ before_install:
3939
# allow windows to run scripts with node 14 and npm 7 (may not be necessary when node 14 is no longer lts)
4040
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then npm config set script-shell c:/PROGRA~1/Git/bin/bash.exe ; fi
4141

42+
before_script: npm run build
4243
script: npx nyc -s npm run test -- -- -- -t node --bail
4344
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
4445

@@ -85,10 +86,7 @@ jobs:
8586

8687
- stage: test
8788
name: electron main
88-
addons:
89-
firefox: latest
90-
script:
91-
- npm run build
89+
script:
9290
- npx lerna link # use publishConfig.directory
9391
- npm run test -- -- -- -t electron-main -f dist/cjs/node-test/*js
9492

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"update-contributors": "aegir release --lint=false --test=false --bump=false --build=false --changelog=false --commit=false --tag=false --push=false --ghrelease=false --docs=false --publish=false"
1717
},
1818
"devDependencies": {
19-
"lerna": "^3.22.1",
20-
"json": "^11.0.0"
19+
"lerna": "^3.22.1"
2120
},
2221
"repository": {
2322
"type": "git",

packages/ipfs-unixfs-exporter/.aegir.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ module.exports = {
3232
buildConfig
3333
}
3434
}
35+
},
36+
ts: {
37+
copyTo: 'types'
3538
}
3639
}

packages/ipfs-unixfs-exporter/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
"fs": false
1010
},
1111
"scripts": {
12-
"prepare": "aegir build --no-bundle",
12+
"prepare": "aegir build --no-bundle && cp -R types dist",
13+
"pretest": "aegir build --esm-tests",
1314
"test": "aegir test",
14-
"build": "aegir build --esm-tests",
15+
"build": "aegir build && cp -R types dist",
1516
"preleaseOnly": "npx json -I -f dist/package.json -e this.types='\"src/index.d.ts\"'",
1617
"clean": "rimraf ./dist",
1718
"lint": "aegir ts -p check && aegir lint",
@@ -50,7 +51,6 @@
5051
"it-buffer-stream": "^2.0.0",
5152
"it-first": "^1.0.6",
5253
"merge-options": "^3.0.4",
53-
"murmurhash3js-revisited": "^3.0.0",
5454
"native-abort-controller": "^1.0.3",
5555
"nyc": "^15.0.0",
5656
"readable-stream": "^3.6.0",
@@ -61,16 +61,16 @@
6161
"dependencies": {
6262
"@ipld/dag-cbor": "^6.0.4",
6363
"@ipld/dag-pb": "^2.0.2",
64+
"@multiformats/murmur3": "^1.0.3",
6465
"err-code": "^3.0.1",
6566
"hamt-sharding": "^2.0.0",
6667
"interface-blockstore": "^1.0.0",
6768
"ipfs-unixfs": "^6.0.2",
6869
"it-last": "^1.0.5",
6970
"multiformats": "^9.4.2",
70-
"murmurhash3js-revisited": "^3.0.0",
7171
"uint8arrays": "^3.0.0"
7272
},
73-
"types": "dist/src/index.d.ts",
73+
"types": "types/src/index.d.ts",
7474
"eslintConfig": {
7575
"extends": "ipfs",
7676
"parserOptions": {

packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11

22
import { Bucket, createHAMT } from 'hamt-sharding'
33
import { decode } from '@ipld/dag-pb'
4-
// @ts-ignore - no types available
5-
import mur from 'murmurhash3js-revisited'
6-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
4+
import { murmur3128 } from '@multiformats/murmur3'
75

86
/**
97
* @typedef {import('interface-blockstore').Blockstore} Blockstore
@@ -18,7 +16,13 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
1816
* @param {Uint8Array} buf
1917
*/
2018
const hashFn = async function (buf) {
21-
return uint8ArrayFromString(mur.x64.hash128(buf), 'base16').slice(0, 8).reverse()
19+
return (await murmur3128.encode(buf))
20+
// Murmur3 outputs 128 bit but, accidentally, IPFS Go's
21+
// implementation only uses the first 64, so we must do the same
22+
// for parity..
23+
.slice(0, 8)
24+
// Invert buffer because that's how Go impl does it
25+
.reverse()
2226
}
2327

2428
/**

packages/ipfs-unixfs-exporter/test/importer.spec.js

-2
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,6 @@ describe('configuration', () => {
10941094
path: 'path',
10951095
content: asAsyncIterable(uint8ArrayFromString('content'))
10961096
}], block, {
1097-
/** @type {import('ipfs-unixfs-importer').ChunkValidator} */
10981097
chunkValidator: async function * (source) { // eslint-disable-line require-await
10991098
validated = true
11001099

@@ -1106,7 +1105,6 @@ describe('configuration', () => {
11061105
}
11071106
}
11081107
},
1109-
/** @type {import('ipfs-unixfs-importer').Chunker} */
11101108
chunker: async function * (source) { // eslint-disable-line require-await
11111109
chunked = true
11121110
yield * source

packages/ipfs-unixfs-exporter/tsconfig.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "aegir/src/config/tsconfig.aegir.json",
33
"compilerOptions": {
4-
"outDir": "dist",
4+
"outDir": "types",
55
"module": "es2020",
66
"importsNotUsedAsValues": "preserve"
77
},
@@ -16,6 +16,9 @@
1616
"references": [
1717
{
1818
"path": "../ipfs-unixfs"
19+
},
20+
{
21+
"path": "../ipfs-unixfs-importer"
1922
}
2023
]
2124
}

packages/ipfs-unixfs-importer/.aegir.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ module.exports = {
3232
buildConfig
3333
}
3434
}
35+
},
36+
ts: {
37+
copyTo: 'types'
3538
}
3639
}

packages/ipfs-unixfs-importer/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
"fs": false
1010
},
1111
"scripts": {
12-
"prepare": "aegir build --no-bundle",
12+
"prepare": "aegir build --no-bundle && cp -R types dist",
13+
"pretest": "aegir build --esm-tests",
1314
"test": "aegir test",
14-
"build": "aegir build --esm-tests",
15+
"build": "aegir build && cp -R types dist",
1516
"preleaseOnly": "npx json -I -f dist/package.json -e this.types='\"src/index.d.ts\"'",
1617
"clean": "rimraf ./dist",
1718
"lint": "aegir ts -p check && aegir lint",
@@ -52,6 +53,7 @@
5253
},
5354
"dependencies": {
5455
"@ipld/dag-pb": "^2.0.2",
56+
"@multiformats/murmur3": "^1.0.3",
5557
"bl": "^5.0.0",
5658
"err-code": "^3.0.1",
5759
"hamt-sharding": "^2.0.0",
@@ -63,11 +65,10 @@
6365
"it-parallel-batch": "^1.0.9",
6466
"merge-options": "^3.0.4",
6567
"multiformats": "^9.4.2",
66-
"murmurhash3js-revisited": "^3.0.0",
6768
"rabin-wasm": "^0.1.4",
6869
"uint8arrays": "^3.0.0"
6970
},
70-
"types": "dist/src/index.d.ts",
71+
"types": "types/src/index.d.ts",
7172
"eslintConfig": {
7273
"extends": "ipfs",
7374
"parserOptions": {

packages/ipfs-unixfs-importer/src/options.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import mergeOptions from 'merge-options'
22
import { sha256 } from 'multiformats/hashes/sha2'
3-
// @ts-ignore - no types available
4-
import mur from 'murmurhash3js-revisited'
5-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
3+
import { murmur3128 } from '@multiformats/murmur3'
64

75
mergeOptions.bind({ ignoreUndefined: true })
86

97
/**
108
* @param {Uint8Array} buf
119
*/
1210
async function hamtHashFn (buf) {
13-
return uint8ArrayFromString(mur.x64.hash128(buf), 'base16')
11+
return (await murmur3128.encode(buf))
1412
// Murmur3 outputs 128 bit but, accidentally, IPFS Go's
1513
// implementation only uses the first 64, so we must do the same
1614
// for parity..

packages/ipfs-unixfs-importer/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "aegir/src/config/tsconfig.aegir.json",
33
"compilerOptions": {
4-
"outDir": "dist",
4+
"outDir": "types",
55
"module": "es2020",
66
"importsNotUsedAsValues": "preserve"
77
},

packages/ipfs-unixfs/.aegir.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
module.exports = {
55
build: {
66
bundlesizeMax: '11KB'
7+
},
8+
ts: {
9+
copyTo: 'types'
710
}
811
}

packages/ipfs-unixfs/package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
"fs": false
1010
},
1111
"scripts": {
12-
"prepare": "aegir build",
12+
"prepare": "aegir build --no-bundle && cp -R types dist",
1313
"prepare:proto": "pbjs -t static-module -w es6 -r ipfs-unixfs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/unixfs.js ./src/unixfs.proto",
1414
"prepare:proto-types": "pbts -o src/unixfs.d.ts src/unixfs.js",
15-
"prepare:types": "aegir build --no-bundle",
15+
"pretest": "aegir build --esm-tests",
1616
"test": "aegir test",
17-
"build": "aegir build --esm-tests",
18-
"preleaseOnly": "npx json -I -f dist/package.json -e this.types='\"src/index.d.ts\"'",
17+
"build": "aegir build && cp -R types dist",
1918
"clean": "rimraf ./dist",
2019
"lint": "aegir ts -p check && aegir lint",
2120
"coverage": "nyc -s aegir test -t node && nyc report --reporter=html",
@@ -54,7 +53,7 @@
5453
"err-code": "^3.0.1",
5554
"protobufjs": "^6.10.2"
5655
},
57-
"types": "dist/src/index.d.ts",
56+
"types": "types/src/index.d.ts",
5857
"eslintConfig": {
5958
"extends": "ipfs",
6059
"parserOptions": {

packages/ipfs-unixfs/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "aegir/src/config/tsconfig.aegir.json",
33
"compilerOptions": {
4-
"outDir": "dist"
4+
"outDir": "types"
55
},
66
"include": [
77
"src",

0 commit comments

Comments
 (0)