@@ -17,11 +17,19 @@ import { useStyleTag } from "@vueuse/core";
17
17
import hash from "hash-sum" ;
18
18
import { transform } from "sucrase" ;
19
19
20
- const log = ( msgs : ( CompilerError | Error | string ) [ ] ) => {
21
- msgs . forEach ( ( msg ) => {
22
- console . log ( msg ) ;
23
- } ) ;
24
- } ;
20
+ const fetchText = async ( url : string ) => {
21
+ try {
22
+ const response = await fetch ( url ) ;
23
+ return response . ok ? response : new Response ( "" ) ;
24
+ } catch {
25
+ return new Response ( "" ) ;
26
+ }
27
+ } ,
28
+ log = ( msgs : ( CompilerError | Error | string ) [ ] ) => {
29
+ msgs . forEach ( ( msg ) => {
30
+ console . log ( msg ) ;
31
+ } ) ;
32
+ } ;
25
33
const addStyle = async (
26
34
id : string ,
27
35
{ filename } : SFCDescriptor ,
@@ -32,7 +40,7 @@ const addStyle = async (
32
40
id,
33
41
modules : ! ! module ,
34
42
scoped,
35
- source : src ? await ( await fetch ( src ) ) . text ( ) : content ,
43
+ source : src ? await ( await fetchText ( src ) ) . text ( ) : content ,
36
44
} ) ;
37
45
log ( errors ) ;
38
46
useStyleTag ( code , scoped ? { id } : undefined ) ;
@@ -42,9 +50,12 @@ const addStyle = async (
42
50
`data:text/javascript;base64,${ btoa ( Array . from ( new TextEncoder ( ) . encode ( code ) , ( byte ) => String . fromCodePoint ( byte ) ) . join ( "" ) ) } `
43
51
) ,
44
52
loadModule = async ( filename : string ) => {
45
- const { descriptor, errors } = parse ( await ( await fetch ( filename ) ) . text ( ) , {
46
- filename,
47
- } ) ;
53
+ const { descriptor, errors } = parse (
54
+ await ( await fetchText ( filename ) ) . text ( ) ,
55
+ {
56
+ filename,
57
+ } ,
58
+ ) ;
48
59
const compilerOptions : CompilerOptions = { expressionPlugins : [ ] } ,
49
60
scriptBlocks = [ "script" , "scriptSetup" ] ,
50
61
contents = await Promise . all (
@@ -56,7 +67,7 @@ const addStyle = async (
56
67
compilerOptions . expressionPlugins ?. push ( "jsx" ) ;
57
68
if ( / t s x ? $ / . test ( lang ) )
58
69
compilerOptions . expressionPlugins ?. push ( "typescript" ) ;
59
- return src && ( await ( await fetch ( src ) ) . text ( ) ) ;
70
+ return src && ( await ( await fetchText ( src ) ) . text ( ) ) ;
60
71
} ) ,
61
72
) ,
62
73
id = `data-v-${ hash ( filename ) } ` ,
@@ -103,7 +114,7 @@ const addStyle = async (
103
114
scoped,
104
115
slotted : descriptor . slotted ,
105
116
source : descriptor . template . src
106
- ? await ( await fetch ( descriptor . template . src ) ) . text ( )
117
+ ? await ( await fetchText ( descriptor . template . src ) ) . text ( )
107
118
: descriptor . template . content ,
108
119
// @ts -expect-error TODO remove expect-error after 3.6
109
120
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
0 commit comments