mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
refactor: remove mock-fs from dev dependency
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
import { last, isArray } from '../util/underscore'
|
||||
|
||||
function domResolve (root, path) {
|
||||
const base = document.createElement('base')
|
||||
base.href = root
|
||||
|
||||
const head = document.getElementsByTagName('head')[0]
|
||||
head.insertBefore(base, head.firstChild)
|
||||
|
||||
const a = document.createElement('a')
|
||||
a.href = path
|
||||
const resolved = a.href
|
||||
head.removeChild(base)
|
||||
|
||||
return resolved
|
||||
}
|
||||
|
||||
export function resolve (filepath, root, options) {
|
||||
root = root || options.root
|
||||
if (isArray(root)) {
|
||||
root = root[0]
|
||||
}
|
||||
if (root.length && last(root) !== '/') {
|
||||
root += '/'
|
||||
}
|
||||
const url = domResolve(root, filepath)
|
||||
return url.replace(/^(\w+:\/\/[^/]+)(\/[^?]+)/, (str, origin, path) => {
|
||||
const last = path.split('/').pop()
|
||||
if (/\.\w+$/.test(last)) {
|
||||
return str
|
||||
}
|
||||
return origin + path + options.extname
|
||||
})
|
||||
}
|
||||
|
||||
export async function read (url: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest()
|
||||
xhr.onload = () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
resolve(xhr.responseText as string)
|
||||
} else {
|
||||
reject(new Error(xhr.statusText))
|
||||
}
|
||||
}
|
||||
xhr.onerror = () => {
|
||||
reject(new Error('An error occurred whilst receiving the response.'))
|
||||
}
|
||||
xhr.open('GET', url)
|
||||
xhr.send()
|
||||
})
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import * as _ from '../util/underscore'
|
||||
import * as path from 'path'
|
||||
import { anySeries } from '../util/promise'
|
||||
import { stat, readFile } from 'fs'
|
||||
|
||||
export const fs = {
|
||||
stat: _.promisify(stat) as ((filepath: string) => Promise<object>),
|
||||
readFile: _.promisify(readFile) as ((filepath: string, encoding: string) => Promise<string>)
|
||||
}
|
||||
|
||||
export async function resolve (filepath, root, options) {
|
||||
if (!path.extname(filepath)) {
|
||||
filepath += options.extname
|
||||
}
|
||||
root = options.root.concat(root || [])
|
||||
root = _.uniq(root)
|
||||
const paths = root.map(root => path.resolve(root, filepath))
|
||||
return anySeries(paths, async path => {
|
||||
try {
|
||||
await fs.stat(path)
|
||||
return path
|
||||
} catch (e) {
|
||||
e.message = `${e.code}: Failed to lookup ${filepath} in: ${root}`
|
||||
throw e
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function read (filepath): Promise<string> {
|
||||
return fs.readFile(filepath, 'utf8')
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
import { assign } from 'src/util/underscore'
|
||||
import DelimitedToken from 'src/parser/delimited-token'
|
||||
import Token from 'src/parser/token'
|
||||
import TagToken from 'src/parser/tag-token'
|
||||
import { LiquidOptions } from 'src/liquid-options'
|
||||
|
||||
export default function whiteSpaceCtrl (tokens: Token[], options: LiquidOptions) {
|
||||
options = assign({ greedy: true }, options)
|
||||
options = { greedy: true, ...options }
|
||||
let inRaw = false
|
||||
|
||||
tokens.forEach((token: Token, i: number) => {
|
||||
|
||||
Reference in New Issue
Block a user