Skip to content

Commit

Permalink
fix: add "browser" field, remove named local imports
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 12, 2022
1 parent f2ae077 commit d60ea06
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 45 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
"import": "./src/traversal.js"
}
},
"browser": {
"./hashes/sha2": "./src/hashes/sha2-browser.js",
"./src/hashes/sha2.js": "./src/hashes/sha2-browser.js"
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
Expand Down Expand Up @@ -244,7 +248,6 @@
"test:browser": "aegir test --target browser"
},
"devDependencies": {
"@ipld/dag-pb": "^2.1.14",
"@stablelib/sha256": "^1.0.1",
"@stablelib/sha512": "^1.0.1",
"@types/chai": "^4.3.0",
Expand Down
8 changes: 4 additions & 4 deletions test/test-block.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* globals describe, it */
import * as codec from 'multiformats/codecs/json'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
import * as main from 'multiformats/block'
import { CID, bytes } from 'multiformats'
import * as codec from '../src/codecs/json.js'
import { sha256 as hasher } from '../src/hashes/sha2.js'
import * as main from '../src/block.js'
import { CID, bytes } from '../src/index.js'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'

Expand Down
2 changes: 1 addition & 1 deletion test/test-bytes.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* globals describe, it */
import * as bytes from 'multiformats/bytes'
import * as bytes from '../src/bytes.js'
import { assert } from 'chai'

describe('bytes', () => {
Expand Down
14 changes: 7 additions & 7 deletions test/test-cid.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* globals describe, it */

import OLDCID from 'cids'
import { fromHex, toHex, equals } from 'multiformats/bytes'
import { varint, CID } from 'multiformats'
import { base58btc } from 'multiformats/bases/base58'
import { base32 } from 'multiformats/bases/base32'
import { base64 } from 'multiformats/bases/base64'
import { sha256, sha512 } from 'multiformats/hashes/sha2'
import { fromHex, toHex, equals } from '../src/bytes.js'
import { varint, CID } from '../src/index.js'
import { base58btc } from '../src/bases/base58.js'
import { base32 } from '../src/bases/base32.js'
import { base64 } from '../src/bases/base64.js'
import { sha256, sha512 } from '../src/hashes/sha2.js'
import invalidMultihash from './fixtures/invalid-multihash.js'
import OLDCID from 'cids'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
// Linter can see that API is used in types.
Expand Down
6 changes: 3 additions & 3 deletions test/test-link.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* globals describe, it */

import * as Link from 'multiformats/link'
import { CID } from 'multiformats'
import * as Link from '../src/link.js'
import { CID } from '../src/cid.js'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { sha256 } from 'multiformats/hashes/sha2'
import { sha256 } from '../src/hashes/sha2.js'

chai.use(chaiAsPromised)
const { assert } = chai
Expand Down
4 changes: 2 additions & 2 deletions test/test-multibase-spec.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */

import { bases } from 'multiformats/basics'
import { fromString } from 'multiformats/bytes'
import { bases } from '../src/basics.js'
import { fromString } from '../src/bytes.js'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'

Expand Down
18 changes: 9 additions & 9 deletions test/test-multibase.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* globals describe, it */
import * as bytes from 'multiformats/bytes'
import * as b2 from 'multiformats/bases/base2'
import * as b8 from 'multiformats/bases/base8'
import * as b10 from 'multiformats/bases/base10'
import * as b16 from 'multiformats/bases/base16'
import * as b32 from 'multiformats/bases/base32'
import * as b36 from 'multiformats/bases/base36'
import * as b58 from 'multiformats/bases/base58'
import * as b64 from 'multiformats/bases/base64'
import * as bytes from '../src/bytes.js'
import * as b2 from '../src/bases/base2.js'
import * as b8 from '../src/bases/base8.js'
import * as b10 from '../src/bases/base10.js'
import * as b16 from '../src/bases/base16.js'
import * as b32 from '../src/bases/base32.js'
import * as b36 from '../src/bases/base36.js'
import * as b58 from '../src/bases/base58.js'
import * as b64 from '../src/bases/base64.js'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'

Expand Down
6 changes: 3 additions & 3 deletions test/test-multicodec.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* globals describe, it */
import * as bytes from 'multiformats/bytes'
import * as raw from 'multiformats/codecs/raw'
import * as json from 'multiformats/codecs/json'
import * as bytes from '../src/bytes.js'
import * as raw from '../src/codecs/raw.js'
import * as json from '../src/codecs/json.js'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'

Expand Down
12 changes: 6 additions & 6 deletions test/test-multihash.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* globals describe, it */
import { fromHex, fromString } from 'multiformats/bytes'
import { hash as slSha256 } from '@stablelib/sha256'
import { hash as slSha512 } from '@stablelib/sha512'
import { fromHex, fromString } from '../src/bytes.js'
import { sha256, sha512 } from '../src/hashes/sha2.js'
import { identity } from '../src/hashes/identity.js'
import { decode as decodeDigest, create as createDigest } from '../src/hashes/digest.js'
import valid from './fixtures/valid-multihash.js'
import invalid from './fixtures/invalid-multihash.js'
import { sha256, sha512 } from 'multiformats/hashes/sha2'
import { identity } from 'multiformats/hashes/identity'
import { decode as decodeDigest, create as createDigest } from 'multiformats/hashes/digest'
import { hash as slSha256 } from '@stablelib/sha256'
import { hash as slSha512 } from '@stablelib/sha512'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'

Expand Down
37 changes: 28 additions & 9 deletions test/test-traversal.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
/* globals describe, it */
import * as codec from 'multiformats/codecs/json'
import * as dagPB from '@ipld/dag-pb'
import { sha256 as hasher } from 'multiformats/hashes/sha2'
import * as main from 'multiformats/block'
import { walk } from 'multiformats/traversal'
import * as codec from '../src/codecs/json.js'
import { sha256 as hasher } from '../src/hashes/sha2.js'
import * as main from '../src/block.js'
import { walk } from '../src/traversal.js'
import { fromString } from '../src/bytes.js'
import { assert } from 'chai'
import { fromString } from 'multiformats/bytes'

const { createLink, createNode } = dagPB
/** @typedef {import('../src/cid.js').CID} CID */

// from dag-pb, simplified
/**
* @param {Uint8Array} data
* @param {{Hash:CID, Name:string, Tsize:number}[]} links
* @returns {{Data:Uint8Array, Links:{Hash:CID, Name:string, Tsize:number}[]}}
*/
function createNode (data, links) {
return { Data: data, Links: links }
}

/**
* @param {string} name
* @param {number} size
* @param {CID} cid
* @returns {{Hash:CID, Name:string, Tsize:number}}
*/
function createLink (name, size, cid) {
return { Hash: cid, Name: name, Tsize: size }
}

describe('traversal', () => {
describe('walk', async () => {
Expand Down Expand Up @@ -43,7 +62,7 @@ describe('traversal', () => {
const cidA = blockA.cid

/**
* @param {import('multiformats').CID} cid
* @param {CID} cid
*/
const load = async (cid) => {
if (cid.equals(cidE)) {
Expand All @@ -70,7 +89,7 @@ describe('traversal', () => {
*/
const loadWrapper = (load, arr = []) =>
/**
* @param {import('multiformats').CID} cid
* @param {CID} cid
*/
(cid) => {
arr.push(cid.toString())
Expand Down

0 comments on commit d60ea06

Please sign in to comment.