Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: Resolve src values on style blocks with require.resolve (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
znck authored May 25, 2018
1 parent 26bda04 commit 0e8e005
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ export class SFCCompiler {
script: ScriptOptions
style: StyleOptions
template: TemplateOptions
resolve: RequireResolve

constructor(
script: ScriptOptions,
style: StyleOptions,
template: TemplateOptions
template: TemplateOptions,
resolve: RequireResolve = require.resolve
) {
this.template = template
this.style = style
this.script = script
this.resolve = resolve
}

compileToDescriptor(
Expand Down Expand Up @@ -193,8 +196,20 @@ export class SFCCompiler {
}

private read(filename: string, context: string): string {
return fs
.readFileSync(path.resolve(path.dirname(context), filename))
.toString()
try {
return fs
.readFileSync(
filename.startsWith('.')
? path.resolve(path.dirname(context), filename)
: this.resolve(filename, { paths: [path.dirname(context)] })
)
.toString()
} catch (e) {
if (/cannot find module/i.test(e.message)) {
throw Error(`Cannot find '${filename}' in '${context}'`)
}

throw e
}
}
}

0 comments on commit 0e8e005

Please sign in to comment.