Unverified Commit 73b34cc1 authored by Renée Kooi's avatar Renée Kooi Committed by GitHub
Browse files

Fixed + more consistent basedir handling (#467)

* Fix getting basedir name if entry point is a directory.

* fix

* better dir check

* Add asset path test

* TODO comment about fs.stat
parent 260b3e6c
......@@ -44,7 +44,10 @@ function Bankai (entry, opts) {
// Initialize data structures.
var key = Buffer.from('be intolerant of intolerance')
this.dirname = utils.dirname(entry) // The base directory.
// TODO maybe use fs.stat here to check if it's a directory?
// That would be best but we may have to do a sync call, because graph nodes depend on this
// value being available immediately, which is less great.
this.dirname = path.extname(entry) === '' ? entry : utils.dirname(entry) // The base directory.
this.queue = queue(methods) // The queue caches requests until ready.
this.graph = graph(key) // The graph manages relations between deps.
......
var trackDir = require('./track-dir')
var utils = require('./utils')
var path = require('path')
var dirs = [
......@@ -21,7 +20,7 @@ var dirs = [
module.exports = node
function node (state, createEdge) {
var basedir = utils.dirname(state.metadata.entry)
var basedir = state.metadata.dirname
var self = this
if (state.tracker) return
......
......@@ -22,7 +22,7 @@ var filenames = [
module.exports = node
function node (state, createEdge, emit) {
var basedir = utils.dirname(state.metadata.entry)
var basedir = state.metadata.dirname
var self = this
if (state.metadata.watch && !state.metadata.watchers.manifest) {
......
......@@ -26,7 +26,7 @@ function node (state, createEdge) {
assert.equal(typeof entry, 'string', 'bankai.service-worker: state.metadata.entries should be type string')
var basedir = utils.dirname(state.metadata.entry)
var basedir = state.metadata.dirname
if (state.metadata.watch && !state.metadata.watchers.serviceWorker) {
state.metadata.watchers.serviceWorker = true
......
......@@ -9,7 +9,7 @@
"bankai": "bin.js"
},
"scripts": {
"build": "./bin.js build example",
"build": "./bin.js build example dist",
"test": "standard && node test",
"start": "NODE_NO_WARNINGS=1 ./bin.js start example",
"debug": "DEBUG='*' ./bin.js start -q example"
......
......@@ -23,7 +23,7 @@ tape('run an asset pipeline', function (assert) {
hello planet
`
var dirname = 'manifest-pipeline-' + (Math.random() * 1e4).toFixed()
var dirname = 'asset-pipeline-' + (Math.random() * 1e4).toFixed()
tmpDirname = path.join(os.tmpdir(), dirname)
var assetDirname = path.join(os.tmpdir(), dirname, 'assets')
......@@ -51,3 +51,43 @@ tape('run an asset pipeline', function (assert) {
assert.ok(buf, 'buffer is fine fine fine')
})
})
tape('use correct asset dir when entry point is a dir', function (assert) {
assert.on('end', cleanup)
var script = dedent`
document.body.textContent = 'Whatever'
`
var file = dedent`
a file!!!
`
var dirname = 'asset-pipeline-' + (Math.random() * 1e4).toFixed()
tmpDirname = path.join(os.tmpdir(), dirname)
var assetDirname = path.join(os.tmpdir(), dirname, 'assets')
var tmpScriptname = path.join(tmpDirname, 'index.js')
var tmpFilename = path.join(assetDirname, 'file.txt')
fs.mkdirSync(tmpDirname)
fs.mkdirSync(assetDirname)
fs.writeFileSync(tmpScriptname, script)
fs.writeFileSync(tmpFilename, file)
var compiler = bankai(tmpDirname, { watch: false })
compiler.on('error', function (name, sub, err) {
assert.error(err, 'no error')
})
compiler.assets('assets/file.txt', function (err, buf) {
assert.error(err, 'no error reading file')
assert.ok(buf, 'buffer is fine fine fine')
assert.equal(buf, tmpFilename)
})
compiler.on('change', function (nodeName, second) {
if (nodeName !== 'documents' || second !== 'list') return
assert.end()
})
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment