Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cbor-web replaces cbor #754

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
"@polkadot/types": "^10.0.0",
"@polkadot/util": "^11.0.0",
"@polkadot/util-crypto": "^11.0.0",
"cbor": "^8.1.0"
"cbor-web": "^8.0.0"
}
}
1 change: 1 addition & 0 deletions packages/core/src/cbor-web.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'cbor-web'
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
PublicCredentialsCredentialsCredentialEntry,
} from '@kiltprotocol/augment-api'

import { encode as cborEncode, decode as cborDecode } from 'cbor'
import { encode as cborEncode, decode as cborDecode } from 'cbor-web'

import { HexString } from '@polkadot/util/types'
import { ConfigService } from '@kiltprotocol/config'
Expand Down
2 changes: 1 addition & 1 deletion packages/did/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
"@polkadot/types-codec": "^10.0.0",
"@polkadot/util": "^11.0.0",
"@polkadot/util-crypto": "^11.0.0",
"cbor": "^8.1.0"
"cbor-web": "^8.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/did/src/DidDetails/LightDidDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import { decode as cborDecode, encode as cborEncode } from 'cbor'
import { decode as cborDecode, encode as cborEncode } from 'cbor-web'
import {
base58Decode,
base58Encode,
Expand Down
1 change: 1 addition & 0 deletions packages/did/src/cbor-web.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'cbor-web'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm debating - is an empty declaration file better than a @ts-expect-error in front of the import? The result is the same - it's treated as any

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I guess there is also an option to keep cbor as a dependency and make this module definition re-export the actual cbor types. This should be doable, though I doubt I will pull it off quickly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's the solution, this way we'll still keep the dependency on cbor - extracting type definitions from another package and adding it to your build is not really what tsc is made for I think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also it wouldn't really help us much with anything, we're just importing two functions and do not plan to re-export them, there's not that much we can do wrong

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 changes: 0 additions & 6 deletions packages/sdk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,9 @@
"bugs": "https://github.com/KILTprotocol/sdk-js/issues",
"homepage": "https://github.com/KILTprotocol/sdk-js#readme",
"devDependencies": {
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"process": "^0.11.10",
"rimraf": "^3.0.2",
"stream-browserify": "^3.0.0",
"terser-webpack-plugin": "^5.1.1",
"typescript": "^4.8.3",
"url": "^0.11.0",
"util": "^0.12.4",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2"
},
Expand Down
15 changes: 0 additions & 15 deletions packages/sdk-js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
const webpack = require('webpack')

module.exports = {
mode: 'production',
Expand All @@ -27,14 +26,6 @@ module.exports = {
resolve: {
extensions: ['.ts', '.js', '.d.ts', '.mjs', '.json'],
symlinks: false,
// Explicit fallbacks to include these in bundle
fallback: {
buffer: require.resolve('buffer'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
url: require.resolve('url'),
util: require.resolve('util'),
},
},
stats: {
errorDetails: true,
Expand All @@ -44,10 +35,4 @@ module.exports = {
// only minimize the *.min* bundle output
minimizer: [new TerserPlugin({ include: /\.min\.umd\.js$/ })],
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
],
}
1 change: 1 addition & 0 deletions tests/cbor-web.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'cbor-web'
2 changes: 1 addition & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "../tsconfig.json",
"include": ["bundle-test.ts", "types.d.ts"],
"include": ["bundle-test.ts", "types.d.ts", "cbor-web.d.ts"],
"compilerOptions": {
"module": "None",
"resolveJsonModule": false,
Expand Down
Loading