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 {
6464 script : ScriptOptions
6565 style : StyleOptions
6666 template : TemplateOptions
67+ resolve : RequireResolve
6768
6869 constructor (
6970 script : ScriptOptions ,
7071 style : StyleOptions ,
71- template : TemplateOptions
72+ template : TemplateOptions ,
73+ resolve : RequireResolve = require . resolve
7274 ) {
7375 this . template = template
7476 this . style = style
7577 this . script = script
78+ this . resolve = resolve
7679 }
7780
7881 compileToDescriptor (
@@ -193,8 +196,20 @@ export class SFCCompiler {
193196 }
194197
195198 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+ }
199214 }
200215}
You can’t perform that action at this time.
0 commit comments