refactor: remove mock-fs from dev dependency

This commit is contained in:
harttle
2019-02-19 22:28:27 +08:00
parent f432aade6a
commit 852c6ad453
70 changed files with 711 additions and 795 deletions
-52
View File
@@ -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()
})
}
-31
View File
@@ -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 -2
View File
@@ -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) => {