Skip to content

Commit bd9cb6f

Browse files
authored
chore: refactor hash() (#2062)
1 parent fb9656c commit bd9cb6f

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

Diff for: package.json

-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
},
3838
"dependencies": {
3939
"chalk": "^4.1.0",
40-
"hash-sum": "^2.0.0",
4140
"watchpack": "^2.4.0"
4241
},
4342
"peerDependencies": {
@@ -56,7 +55,6 @@
5655
"@babel/preset-env": "^7.11.5",
5756
"@intlify/vue-i18n-loader": "^3.0.0",
5857
"@types/estree": "^0.0.45",
59-
"@types/hash-sum": "^1.0.0",
6058
"@types/jest": "^26.0.13",
6159
"@types/jsdom": "^16.2.13",
6260
"@types/mini-css-extract-plugin": "^0.9.1",

Diff for: src/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { LoaderContext } from 'webpack'
22
import * as path from 'path'
3+
import * as crypto from 'crypto'
34
import * as qs from 'querystring'
45

5-
import hash = require('hash-sum')
6-
76
import { compiler } from './compiler'
87
import type {
98
TemplateCompiler,
@@ -66,6 +65,10 @@ let errorEmitted = false
6665
const { parse } = compiler
6766
const exportHelperPath = require.resolve('./exportHelper')
6867

68+
function hash(text: string): string {
69+
return crypto.createHash('sha256').update(text).digest('hex').substring(0, 8)
70+
}
71+
6972
export default function loader(
7073
this: LoaderContext<VueLoaderOptions>,
7174
source: string

Diff for: test/utils.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
/* env jest */
22
import * as path from 'path'
3+
import * as crypto from 'crypto'
34
import webpack from 'webpack'
45
import merge from 'webpack-merge'
5-
import hash from 'hash-sum'
66
// import MiniCssExtractPlugin from 'mini-css-extract-plugin'
77
import { fs as mfs } from 'memfs'
88
import { JSDOM, VirtualConsole } from 'jsdom'
99
import { VueLoaderPlugin } from '..'
1010
import type { VueLoaderOptions } from '..'
1111

12+
function hash(text: string): string {
13+
return crypto.createHash('sha256').update(text).digest('hex').substring(0, 8)
14+
}
15+
1216
export const DEFAULT_VUE_USE = {
1317
loader: 'vue-loader',
1418
options: {

Diff for: yarn.lock

-10
Original file line numberDiff line numberDiff line change
@@ -1317,11 +1317,6 @@
13171317
dependencies:
13181318
"@types/node" "*"
13191319

1320-
"@types/hash-sum@^1.0.0":
1321-
version "1.0.0"
1322-
resolved "https://registry.yarnpkg.com/@types/hash-sum/-/hash-sum-1.0.0.tgz#838f4e8627887d42b162d05f3d96ca636c2bc504"
1323-
integrity sha512-FdLBT93h3kcZ586Aee66HPCVJ6qvxVjBlDWNmxSGSbCZe9hTsjRKdSsl4y1T+3zfujxo9auykQMnFsfyHWD7wg==
1324-
13251320
"@types/html-minifier-terser@^5.0.0":
13261321
version "5.1.1"
13271322
resolved "https://registry.yarnpkg.com/@types/html-minifier-terser/-/html-minifier-terser-5.1.1.tgz#3c9ee980f1a10d6021ae6632ca3e79ca2ec4fb50"
@@ -4925,11 +4920,6 @@ hash-base@^3.0.0:
49254920
readable-stream "^3.6.0"
49264921
safe-buffer "^5.2.0"
49274922

4928-
hash-sum@^2.0.0:
4929-
version "2.0.0"
4930-
resolved "https://registry.yarnpkg.com/hash-sum/-/hash-sum-2.0.0.tgz#81d01bb5de8ea4a214ad5d6ead1b523460b0b45a"
4931-
integrity sha512-WdZTbAByD+pHfl/g9QSsBIIwy8IT+EsPiKDs0KNX+zSHhdDLFKdZu0BQHljvO+0QI/BasbMSUa8wYNCZTvhslg==
4932-
49334923
hash.js@^1.0.0, hash.js@^1.0.3:
49344924
version "1.1.7"
49354925
resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42"

0 commit comments

Comments
 (0)