let fs_readFile = util.promisify(fs.readFile)
let fs_writeFile = util.promisify(fs.writeFile)
-let JSTCache = function(root, args, diag) {
+let JSTCache = function(root, args, diag1, diag) {
if (!this instanceof JSTCache)
- throw Error('JSTCache is a constructor')
+ throw new Error('JSTCache is a constructor')
+ BuildCache.call(this, diag)
+ this.diag1 = diag1
this.root = root || '.'
this.arg_names = []
this.arg_values = []
this.arg_names.push(i)
this.arg_values.push(args[i])
}
- this.diag = diag || false
-
- this.build_cache = new BuildCache()
}
-JSTCache.prototype.get = function(key) {
- return /*await*/ this.build_cache.get(
+JSTCache.prototype = Object.create(BuildCache.prototype)
+
+JSTCache.prototype.build = async function(key, result) {
+ let render = await disk_build(
key,
- async result => {
- let render = await disk_build(
- key,
- async temp_pathname => /*await*/ fs_writeFile(
- temp_pathname,
- jst(
- `module.exports = async (${['_require', '_pathname', '_root'].concat(this.arg_names).join(', ')}) => {${await fs_readFile(key, {encoding: 'utf-8'})}}\n`
- ),
- {encoding: 'utf-8'}
- ),
- this.diag
- )
- assert(render.deps.length === 0)
- let full_pathname = require.resolve(render.pathname)
- delete require.cache[full_pathname]
- result.value = await (require(full_pathname)).apply(
- null,
- [
- async pathname => {
- let temp = path.posix.dirname(key)
- while (pathname.charAt(0) === '/') {
- temp = this.root
- pathname = pathname.slice(1)
- }
- pathname = path.posix.resolve(temp, pathname)
- return this.get(pathname)
- },
- key,
- this.root
- ].concat(this.arg_values)
- )
- }
+ async temp_pathname => /*await*/ fs_writeFile(
+ temp_pathname,
+ jst(
+ `module.exports = async (${['_require', '_pathname', '_root'].concat(this.arg_names).join(', ')}) => {${await fs_readFile(key, {encoding: 'utf-8'})}}\n`
+ ),
+ {encoding: 'utf-8'}
+ ),
+ this.diag1
+ )
+ assert(render.deps.length === 0)
+ let full_pathname = require.resolve(render.pathname)
+ delete require.cache[full_pathname]
+ result.value = await (require(full_pathname)).apply(
+ null,
+ [
+ async pathname => {
+ let temp = path.posix.dirname(key)
+ while (pathname.charAt(0) === '/') {
+ temp = this.root
+ pathname = pathname.slice(1)
+ }
+ pathname = path.posix.resolve(temp, pathname)
+ return this.get(pathname)
+ },
+ key,
+ this.root
+ ].concat(this.arg_values)
)
}