diff --git a/src/fs/fs.ts b/src/fs/fs.ts index 7526f80b3..5bd5131c6 100644 --- a/src/fs/fs.ts +++ b/src/fs/fs.ts @@ -1,5 +1,3 @@ -import { LoaderOptions } from './loader' - export interface FS { /** check if a file exists asynchronously */ exists: (filepath: string) => Promise; @@ -10,7 +8,7 @@ export interface FS { /** read a file synchronously */ readFileSync: (filepath: string) => string; /** resolve a file against directory, for given `ext` option */ - resolve: (dir: string, file: string, ext: string, options?: LoaderOptions) => string; + resolve: (dir: string, file: string, ext: string) => string; /** defaults to "/", will be used for "within roots" check */ sep?: string; /** dirname for a filepath, used when resolving relative path */ diff --git a/src/fs/loader.ts b/src/fs/loader.ts index bc383a9b7..dd078fb0e 100644 --- a/src/fs/loader.ts +++ b/src/fs/loader.ts @@ -35,10 +35,14 @@ export class Loader { throw this.lookupError(file, dirs) } + public shouldLoadRelative (referencedFile: string) { + return this.options.relativeReference && this.rRelativePath.test(referencedFile) + } + public * candidates (file: string, dirs: string[], currentFile?: string, enforceRoot?: boolean) { const { fs, extname } = this.options if (this.shouldLoadRelative(file) && currentFile) { - const referenced = fs.resolve(this.dirname(currentFile), file, extname, this.options) + const referenced = fs.resolve(this.dirname(currentFile), file, extname) for (const dir of dirs) { if (!enforceRoot || this.withinDir(referenced, dir)) { // the relatively referenced file is within one of root dirs @@ -64,10 +68,6 @@ export class Loader { return file.startsWith(dir) } - private shouldLoadRelative (referencedFile: string) { - return this.options.relativeReference && this.rRelativePath.test(referencedFile) - } - private dirname (path: string) { const fs = this.options.fs assert(fs.dirname, '`fs.dirname` is required for relative reference') diff --git a/src/fs/node.ts b/src/fs/node.ts index ce1d32f7c..29255381c 100644 --- a/src/fs/node.ts +++ b/src/fs/node.ts @@ -1,7 +1,6 @@ import * as _ from '../util/underscore' import { resolve as nodeResolve, extname, dirname as nodeDirname } from 'path' import { stat, statSync, readFile as nodeReadFile, readFileSync as nodeReadFileSync } from 'fs' -import { LiquidOptions } from '../liquid-options' const statAsync = _.promisify(stat) const readFileAsync = _.promisify(nodeReadFile) @@ -28,7 +27,7 @@ export function existsSync (filepath: string) { export function readFileSync (filepath: string) { return nodeReadFileSync(filepath, 'utf8') } -export function resolve (root: string, file: string, ext: string, opts: LiquidOptions) { +export function resolve (root: string, file: string, ext: string) { if (!extname(file)) file += ext return nodeResolve(root, file) } diff --git a/test/e2e/render-file.ts b/test/e2e/render-file.ts index 4caa04da1..edacaba8f 100644 --- a/test/e2e/render-file.ts +++ b/test/e2e/render-file.ts @@ -55,6 +55,6 @@ describe('#renderFile()', function () { extname: '.html' }) return expect(engine.renderFile('/not/exist.html')).to - .be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo\/,\/root\/"/) + .be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/) }) })