Skip to content

Commit 01dc5f0

Browse files
size(core): replace crypto md5 module with spark-md5 and remove crypto-browserify (crypto fallback)
1 parent e8ff24d commit 01dc5f0

File tree

4 files changed

+18
-295
lines changed

4 files changed

+18
-295
lines changed

build/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ ${ pkg.name } v${ pkg.version }
180180
'path': require.resolve('path-browserify'),
181181
'buffer': require.resolve('buffer/'),
182182
'url': require.resolve('url/'),
183-
'crypto': require.resolve('crypto-browserify'),
183+
'crypto': false,
184184
'stream': require.resolve('stream-browserify'),
185185
'assert': require.resolve('assert/'),
186186
'util': require.resolve('util/'),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
"bn.js": "5",
5353
"buffer": "^6.0.3",
5454
"core-js": "^3.9.1",
55-
"crypto-browserify": "^3.12.0",
5655
"lru-cache": "^6.0.0",
5756
"path-browserify": "^1.0.1",
5857
"process": "^0.11.10",
5958
"safe-buffer": "^5.2.1",
6059
"semver": "^7.3.4",
60+
"spark-md5": "^3.0.1",
6161
"stream-browserify": "^3.0.0",
6262
"url": "^0.11.0",
6363
"util": "^0.12.3",

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { posix as Path } from 'path'
2-
import { createHash } from 'crypto'
2+
3+
// @ts-ignore (TS7016: Could not find a declaration file for module 'spark-md5')
4+
import SparkMD5 from 'spark-md5'
35

46
// astexplorer: https://astexplorer.net/
57
// babel-core doc: https://babeljs.io/docs/en/babel-core
@@ -408,10 +410,10 @@ function formatError(message : string, path : string, source : string, line : nu
408410
*/
409411
function hash(...valueList : any[]) : string {
410412

411-
const hashInstance = createHash('md5');
413+
const hashInstance = new SparkMD5();
412414
for ( const val of valueList )
413-
hashInstance.update( typeof val === 'string' ? val : JSON.stringify(val) );
414-
return hashInstance.digest('hex').slice(0, 8);
415+
hashInstance.append( typeof val === 'string' ? val : JSON.stringify(val) );
416+
return hashInstance.end().slice(0, 8);
415417
}
416418

417419

0 commit comments

Comments
 (0)