Skip to content

Commit 4f05f7c

Browse files
committed
wip(vue3): add script setup to template cache key
1 parent 96eed02 commit 4f05f7c

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"vm-browserify": "^1.1.2"
6767
},
6868
"devDependencies": {
69+
"@types/spark-md5": "^3.0.2",
6970
"@vue/component-compiler-utils": "^3.2.0",
7071
"babel-loader": "^8.2.2",
7172
"caniuse-api": "^3.0.0",

src/createVue3SFCModule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export async function createSFCModule(source : string, filename : string, option
120120

121121
// eg: https://github.com/vuejs/vue-loader/blob/6ed553f70b163031457acc961901313390cde9ef/src/index.ts#L136
122122

123-
const [ depsList, transformedScriptSource ] = await withCache(compiledCache, [ componentHash, descriptor.script.content ], async ({ preventCache }) => {
123+
const [ depsList, transformedScriptSource ] = await withCache(compiledCache, [ componentHash, descriptor.script?.content, descriptor.scriptSetup?.content ], async ({ preventCache }) => {
124124

125125
const babelParserPlugins : babel_ParserPlugin[] = [];
126126

src/tools.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import {
2222
import babelPluginTransformModulesCommonjs from '@babel/plugin-transform-modules-commonjs'
2323

2424

25-
// @ts-ignore (TS7016: Could not find a declaration file for module 'spark-md5')
26-
import SparkMD5 from 'spark-md5'
25+
import * as SparkMD5 from 'spark-md5'
2726

2827
import {
2928
Cache,
@@ -86,11 +85,9 @@ export function formatErrorStartEnd(message : string, path : string, source : st
8685
/**
8786
* @internal
8887
*/
89-
export function hash(...valueList : any[]) : string {
90-
88+
export function hash(...valueList : string[]) : string {
9189
const hashInstance = new SparkMD5();
92-
for ( const val of valueList )
93-
hashInstance.append( typeof val === 'string' ? val : JSON.stringify(val) );
90+
valueList.forEach(val => hashInstance.append(val ? val : ""))
9491
return hashInstance.end().slice(0, 8);
9592
}
9693

@@ -101,7 +98,7 @@ export function hash(...valueList : any[]) : string {
10198
* preventCache usage: non-fatal error
10299
* @internal
103100
*/
104-
export async function withCache( cacheInstance : Cache, key : any[], valueFactory : ValueFactory ) {
101+
export async function withCache( cacheInstance : Cache, key : string[], valueFactory : ValueFactory ) {
105102

106103
let cachePrevented = false;
107104

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,11 @@
12261226
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.2.1.tgz#374e31645d58cb18a07b3ecd8e9dede4deb2cccd"
12271227
integrity sha512-DxZZbyMAM9GWEzXL+BMZROWz9oo6A9EilwwOMET2UVu2uZTqMWS5S69KVtuVKaRjCUpcrOXRalet86/OpG4kqw==
12281228

1229+
"@types/spark-md5@^3.0.2":
1230+
version "3.0.2"
1231+
resolved "https://registry.yarnpkg.com/@types/spark-md5/-/spark-md5-3.0.2.tgz#da2e8a778a20335fc4f40b6471c4b0d86b70da55"
1232+
integrity sha512-82E/lVRaqelV9qmRzzJ1PKTpyrpnT7mwdneKNJB9hUtypZDMggloDfFUCIqRRx3lYRxteCwXSq9c+W71Vf0QnQ==
1233+
12291234
"@types/stack-utils@^2.0.0":
12301235
version "2.0.0"
12311236
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff"

0 commit comments

Comments
 (0)