1
Fork 0

include origPath in events, and fix tracking renamed dependencies

This commit is contained in:
Conduitry 2017-05-20 11:34:12 -04:00
parent 0735cd570b
commit 01d0717d31
2 changed files with 15 additions and 14 deletions

14
API.md
View file

@ -138,18 +138,18 @@ Close all of the attached Gazes.
`Defiler` extends Node's `EventEmitter`, and emits four events.
### `origFile(file)`
### `origFile(origPath, file)`
An `origFile` event is emitted when the original version of a physical file has been read in. It's emitted with one argument, the `File` instance.
An `origFile` event is emitted when the original version of a physical file has been read in. It's emitted with two arguments: the file's original relative path and the `File` instance.
### `file(file)`
### `file(origPath, file)`
A `file` event is emitted after all transforms on a file are complete. It's emitted with one argument, the fully transformed `File` instance.
A `file` event is emitted after all transforms on a file are complete. It's emitted with two arguments: the file's original relative path and the fully transformed `File` instance.
### `deleted(path)`
A `deleted` event is emitted when a watched physical file has been deleted. It's emitted with one argument, the relative `path` to the file.
A `deleted` event is emitted when a watched physical file has been deleted. It's emitted with one argument: the relative `path` to the file.
### `error(file, err)`
### `error(origPath, file, err)`
An `error` event is emitted if a file transform or a file generator throws an exception or returns a promise that rejects. It's emitted with two arguments, the `File` instance in question and the thrown `err`.
An `error` event is emitted if a file transform or a file generator throws an exception or returns a promise that rejects. It's emitted with three arguments: the file's original relative path, the `File` instance that caused the error, and the thrown error.

View file

@ -134,10 +134,10 @@ export default class Defiler extends EventEmitter {
await Promise.all(promises)
this.on('file', file => {
this.on('file', origPath => {
let origins = new Set()
for (let [origin, deps] of this._dependencies.entries()) {
if (deps.has(file.path)) {
if (deps.has(origPath)) {
origins.add(origin)
this._dependencies.delete(origin)
}
@ -189,7 +189,7 @@ export default class Defiler extends EventEmitter {
let { path } = file
await this._transformFile(file)
this._files.set(path, file)
this.emit('file', file)
this.emit('file', path, file)
}
close() {
@ -244,7 +244,7 @@ export default class Defiler extends EventEmitter {
origFile.bytes = await new Promise((res, rej) => readFile(absolutePath, (err, data) => (err ? rej(err) : res(data))))
}
this._origFiles.set(path, origFile)
this.emit('origFile', origFile)
this.emit('origFile', path, origFile)
await this._processFile(origFile)
}
@ -252,12 +252,13 @@ export default class Defiler extends EventEmitter {
let file = Object.assign(new File(), origFile)
await this._transformFile(file)
this._files.set(origFile.path, file)
this.emit('file', file)
this.emit('file', origFile.path, file)
}
async _transformFile(file) {
let depth = 0
let skipDepth = null
let { path } = file
try {
for (let { type, transform, condition } of this._transforms) {
if (type === TRANSFORM) {
@ -283,7 +284,7 @@ export default class Defiler extends EventEmitter {
}
}
} catch (err) {
this.emit('error', file, err)
this.emit('error', path, file, err)
}
}
@ -294,7 +295,7 @@ export default class Defiler extends EventEmitter {
await this._customGenerators.get(path).call(this, file)
await this.addFile(file)
} catch (err) {
this.emit('error', file, err)
this.emit('error', path, file, err)
}
}