From 10b0857e040ceb399ed53eba264544c08a9e2c09 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Mon, 19 Jan 2026 15:44:51 +1100 Subject: [PATCH] fix: use Type.equals() for bundler-safe type comparisons Updates cborg to ^4.4.0 and replaces direct === comparisons on Type instances with Type.equals() to handle cases where bundlers create duplicate copies of the cborg module. Ref: https://github.com/rvagg/cborg/pull/159 Ref: https://github.com/rvagg/cborg/pull/136 Closes: https://github.com/ipld/js-dag-json/pull/134 --- package.json | 2 +- src/index.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 8c4f8bd..b93dc94 100644 --- a/package.json +++ b/package.json @@ -169,7 +169,7 @@ "dep-check": "aegir dep-check" }, "dependencies": { - "cborg": "^4.0.0", + "cborg": "^4.4.0", "multiformats": "^13.1.0" }, "devDependencies": { diff --git a/src/index.js b/src/index.js index 2346b7c..71beb32 100644 --- a/src/index.js +++ b/src/index.js @@ -195,26 +195,26 @@ class DagJsonTokenizer extends cborgJson.Tokenizer { next () { const token = this._next() - if (token.type === Type.map) { + if (Type.equals(token.type, Type.map)) { const keyToken = this._next() - if (keyToken.type === Type.string && keyToken.value === '/') { + if (Type.equals(keyToken.type, Type.string) && keyToken.value === '/') { const valueToken = this._next() - if (valueToken.type === Type.string) { // *must* be a CID + if (Type.equals(valueToken.type, Type.string)) { // *must* be a CID const breakToken = this._next() // swallow the end-of-map token - if (breakToken.type !== Type.break) { + if (!Type.equals(breakToken.type, Type.break)) { throw new Error('Invalid encoded CID form') } this.tokenBuffer.push(valueToken) // CID.parse will pick this up after our tag token return new Token(Type.tag, 42, 0) } - if (valueToken.type === Type.map) { + if (Type.equals(valueToken.type, Type.map)) { const innerKeyToken = this._next() - if (innerKeyToken.type === Type.string && innerKeyToken.value === 'bytes') { + if (Type.equals(innerKeyToken.type, Type.string) && innerKeyToken.value === 'bytes') { const innerValueToken = this._next() - if (innerValueToken.type === Type.string) { // *must* be Bytes + if (Type.equals(innerValueToken.type, Type.string)) { // *must* be Bytes for (let i = 0; i < 2; i++) { const breakToken = this._next() // swallow two end-of-map tokens - if (breakToken.type !== Type.break) { + if (!Type.equals(breakToken.type, Type.break)) { throw new Error('Invalid encoded Bytes form') } }