let BuildCache = require('@ndcode/build_cache')
let acorn = require('./dist/acorn')
+let assert = require('assert')
let astring = require('astring')
let disk_build = require('@ndcode/disk_build')
let fs = require('fs')
arg_values.push(args[i])
}
- let full_built_pathname = require.resolve(
- await disk_build(
- pathname,
- async built_pathname => {
- let text = await fs_readFile(pathname, {encoding: 'utf-8'})
- console.log('building', pathname)
- return /*await*/ fs_writeFile(
- built_pathname,
- astring.generate(
- transform.transform(
- visitors,
- acorn.parse(
- `module.exports = async (${arg_names.join(', ')}) => {${text}}`
- )
- ),
- {} //indent: ''}
+ let render = await disk_build(
+ pathname,
+ async temp_pathname => {
+ let text = await fs_readFile(pathname, {encoding: 'utf-8'})
+ return /*await*/ fs_writeFile(
+ temp_pathname,
+ astring.generate(
+ transform.transform(
+ visitors,
+ acorn.parse(
+ `module.exports = async (${arg_names.join(', ')}) => {${text}}`
+ )
),
- {encoding: 'utf-8'}
- )
- }
- )
+ {} //indent: ''}
+ ),
+ {encoding: 'utf-8'}
+ )
+ },
+ true
)
- delete require.cache[full_built_pathname]
- result.value = await (
- require(full_built_pathname)
- ).apply(null, arg_values)
+ 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, arg_values)
}
)