This repository was archived by the owner on Aug 16, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -64,15 +64,18 @@ export class SFCCompiler {
64
64
script : ScriptOptions
65
65
style : StyleOptions
66
66
template : TemplateOptions
67
+ resolve : RequireResolve
67
68
68
69
constructor (
69
70
script : ScriptOptions ,
70
71
style : StyleOptions ,
71
- template : TemplateOptions
72
+ template : TemplateOptions ,
73
+ resolve : RequireResolve = require . resolve
72
74
) {
73
75
this . template = template
74
76
this . style = style
75
77
this . script = script
78
+ this . resolve = resolve
76
79
}
77
80
78
81
compileToDescriptor (
@@ -193,8 +196,20 @@ export class SFCCompiler {
193
196
}
194
197
195
198
private read ( filename : string , context : string ) : string {
196
- return fs
197
- . readFileSync ( path . resolve ( path . dirname ( context ) , filename ) )
198
- . toString ( )
199
+ try {
200
+ return fs
201
+ . readFileSync (
202
+ filename . startsWith ( '.' )
203
+ ? path . resolve ( path . dirname ( context ) , filename )
204
+ : this . resolve ( filename , { paths : [ path . dirname ( context ) ] } )
205
+ )
206
+ . toString ( )
207
+ } catch ( e ) {
208
+ if ( / c a n n o t f i n d m o d u l e / i. test ( e . message ) ) {
209
+ throw Error ( `Cannot find '${ filename } ' in '${ context } '` )
210
+ }
211
+
212
+ throw e
213
+ }
199
214
}
200
215
}
You can’t perform that action at this time.
0 commit comments