Comparing version 0.16.0 to 0.17.0
@@ -0,1 +1,7 @@ | ||
# v0.17.0 | ||
- Tidy API - no need to pass `defiler` instance to user code, as we are now actually tracking the asynchronous context in which `defiler.get` and `defiler.add` are called | ||
- Rename `type` argument to the transform to the clearer `event` | ||
- Require Node.js 8.2+ for the use of `async_hooks` | ||
# v0.16.0 | ||
@@ -2,0 +8,0 @@ |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var EventEmitter = require('events'); | ||
var async_hooks = require('async_hooks'); | ||
var path = require('path'); | ||
@@ -268,2 +269,13 @@ | ||
const contexts = new Map(); | ||
async_hooks.createHook({ | ||
init: (id, _, trigger) => contexts.set(id, contexts.get(trigger)), | ||
destroy: id => contexts.delete(id), | ||
}).enable(); | ||
const create = data => contexts.set(async_hooks.executionAsyncId(), data); | ||
const current = () => contexts.get(async_hooks.executionAsyncId()); | ||
const _origData = Symbol(); | ||
@@ -293,4 +305,2 @@ const _status = Symbol(); | ||
const _checkWave = Symbol(); | ||
const _current = Symbol(); | ||
const _newProxy = Symbol(); | ||
const _processDependents = Symbol(); | ||
@@ -386,4 +396,2 @@ const _markFound = Symbol(); | ||
this[_whenFound] = new Map(); | ||
// (set via proxy) the current immediate dependent (path or generator symbol), for use in _deps, _waitingFor, and the resolver | ||
this[_current] = null; | ||
// array of [dependent, dependency] pairs, specifying changes to which files should trigger re-processing which other files | ||
@@ -447,3 +455,4 @@ this[_deps] = []; | ||
} | ||
const { [_current]: current, [_waitingFor]: waitingFor } = this; | ||
const waitingFor = this[_waitingFor]; | ||
const current$$1 = current(); | ||
path$$1 = this.resolve(path$$1); | ||
@@ -453,8 +462,8 @@ if (typeof path$$1 !== 'string') { | ||
} | ||
if (current) { | ||
this[_deps].push([current, path$$1]); | ||
if (current$$1) { | ||
this[_deps].push([current$$1, path$$1]); | ||
} | ||
if (this[_status] === _during && !this.files.has(path$$1)) { | ||
if (current) { | ||
waitingFor.set(current, (waitingFor.get(current) || 0) + 1); | ||
if (current$$1) { | ||
waitingFor.set(current$$1, (waitingFor.get(current$$1) || 0) + 1); | ||
} | ||
@@ -469,4 +478,4 @@ if (!this[_whenFound].has(path$$1)) { | ||
await this[_whenFound].get(path$$1).promise; | ||
if (current) { | ||
waitingFor.set(current, waitingFor.get(current) - 1); | ||
if (current$$1) { | ||
waitingFor.set(current$$1, waitingFor.get(current$$1) - 1); | ||
} | ||
@@ -492,4 +501,4 @@ } | ||
resolve(path$$1) { | ||
return this[_resolver] && typeof this[_current] === 'string' | ||
? this[_resolver](this[_current], path$$1) | ||
return this[_resolver] && typeof current() === 'string' | ||
? this[_resolver](current(), path$$1) | ||
: path$$1; | ||
@@ -555,7 +564,7 @@ } | ||
// transform a file, store it, and process dependents | ||
async [_processFile](data, type) { | ||
async [_processFile](data, event) { | ||
const file = Object.assign(new File(), data); | ||
const { path: path$$1 } = file; | ||
this[_active].add(path$$1); | ||
await this[_callTransform](file, type); | ||
await this[_callTransform](file, event); | ||
this.files.set(path$$1, file); | ||
@@ -570,10 +579,10 @@ this[_markFound](path$$1); | ||
// call the transform on a file with the given changed and deleted flags, and handle errors | ||
async [_callTransform](file, type) { | ||
let defiler = this[_newProxy](file.path); | ||
// call the transform on a file with the given event string, and handle errors | ||
async [_callTransform](file, event) { | ||
create(file.path); | ||
try { | ||
await this[_transform]({ defiler, file, type }); | ||
await this[_transform]({ file, event }); | ||
} catch (error) { | ||
if (this[_onerror]) { | ||
this[_onerror]({ defiler, file, type, error }); | ||
this[_onerror]({ file, event, error }); | ||
} | ||
@@ -587,8 +596,8 @@ } | ||
const generator = this[_generators].get(symbol); | ||
const defiler = this[_newProxy](symbol); | ||
create(symbol); | ||
try { | ||
await generator({ defiler }); | ||
await generator(); | ||
} catch (error) { | ||
if (this[_onerror]) { | ||
this[_onerror]({ defiler, generator, error }); | ||
this[_onerror]({ generator, error }); | ||
} | ||
@@ -641,9 +650,2 @@ } | ||
// create a defiler Proxy for the given path or generator symbol | ||
[_newProxy](path$$1) { | ||
return new Proxy(this, { | ||
get: (_, key) => (key === _current ? path$$1 : this[key]), | ||
}); | ||
} | ||
// mark a given awaited file as being found | ||
@@ -650,0 +652,0 @@ [_markFound](path$$1) { |
import { readdir, readFile, stat, watch } from 'fs'; | ||
import { promisify } from 'util'; | ||
import EventEmitter from 'events'; | ||
import { createHook, executionAsyncId } from 'async_hooks'; | ||
import { resolve } from 'path'; | ||
@@ -263,2 +264,13 @@ | ||
const contexts = new Map(); | ||
createHook({ | ||
init: (id, _, trigger) => contexts.set(id, contexts.get(trigger)), | ||
destroy: id => contexts.delete(id), | ||
}).enable(); | ||
const create = data => contexts.set(executionAsyncId(), data); | ||
const current = () => contexts.get(executionAsyncId()); | ||
const _origData = Symbol(); | ||
@@ -288,4 +300,2 @@ const _status = Symbol(); | ||
const _checkWave = Symbol(); | ||
const _current = Symbol(); | ||
const _newProxy = Symbol(); | ||
const _processDependents = Symbol(); | ||
@@ -381,4 +391,2 @@ const _markFound = Symbol(); | ||
this[_whenFound] = new Map(); | ||
// (set via proxy) the current immediate dependent (path or generator symbol), for use in _deps, _waitingFor, and the resolver | ||
this[_current] = null; | ||
// array of [dependent, dependency] pairs, specifying changes to which files should trigger re-processing which other files | ||
@@ -442,3 +450,4 @@ this[_deps] = []; | ||
} | ||
const { [_current]: current, [_waitingFor]: waitingFor } = this; | ||
const waitingFor = this[_waitingFor]; | ||
const current$$1 = current(); | ||
path = this.resolve(path); | ||
@@ -448,8 +457,8 @@ if (typeof path !== 'string') { | ||
} | ||
if (current) { | ||
this[_deps].push([current, path]); | ||
if (current$$1) { | ||
this[_deps].push([current$$1, path]); | ||
} | ||
if (this[_status] === _during && !this.files.has(path)) { | ||
if (current) { | ||
waitingFor.set(current, (waitingFor.get(current) || 0) + 1); | ||
if (current$$1) { | ||
waitingFor.set(current$$1, (waitingFor.get(current$$1) || 0) + 1); | ||
} | ||
@@ -464,4 +473,4 @@ if (!this[_whenFound].has(path)) { | ||
await this[_whenFound].get(path).promise; | ||
if (current) { | ||
waitingFor.set(current, waitingFor.get(current) - 1); | ||
if (current$$1) { | ||
waitingFor.set(current$$1, waitingFor.get(current$$1) - 1); | ||
} | ||
@@ -487,4 +496,4 @@ } | ||
resolve(path) { | ||
return this[_resolver] && typeof this[_current] === 'string' | ||
? this[_resolver](this[_current], path) | ||
return this[_resolver] && typeof current() === 'string' | ||
? this[_resolver](current(), path) | ||
: path; | ||
@@ -550,7 +559,7 @@ } | ||
// transform a file, store it, and process dependents | ||
async [_processFile](data, type) { | ||
async [_processFile](data, event) { | ||
const file = Object.assign(new File(), data); | ||
const { path } = file; | ||
this[_active].add(path); | ||
await this[_callTransform](file, type); | ||
await this[_callTransform](file, event); | ||
this.files.set(path, file); | ||
@@ -565,10 +574,10 @@ this[_markFound](path); | ||
// call the transform on a file with the given changed and deleted flags, and handle errors | ||
async [_callTransform](file, type) { | ||
let defiler = this[_newProxy](file.path); | ||
// call the transform on a file with the given event string, and handle errors | ||
async [_callTransform](file, event) { | ||
create(file.path); | ||
try { | ||
await this[_transform]({ defiler, file, type }); | ||
await this[_transform]({ file, event }); | ||
} catch (error) { | ||
if (this[_onerror]) { | ||
this[_onerror]({ defiler, file, type, error }); | ||
this[_onerror]({ file, event, error }); | ||
} | ||
@@ -582,8 +591,8 @@ } | ||
const generator = this[_generators].get(symbol); | ||
const defiler = this[_newProxy](symbol); | ||
create(symbol); | ||
try { | ||
await generator({ defiler }); | ||
await generator(); | ||
} catch (error) { | ||
if (this[_onerror]) { | ||
this[_onerror]({ defiler, generator, error }); | ||
this[_onerror]({ generator, error }); | ||
} | ||
@@ -636,9 +645,2 @@ } | ||
// create a defiler Proxy for the given path or generator symbol | ||
[_newProxy](path) { | ||
return new Proxy(this, { | ||
get: (_, key) => (key === _current ? path : this[key]), | ||
}); | ||
} | ||
// mark a given awaited file as being found | ||
@@ -645,0 +647,0 @@ [_markFound](path) { |
{ | ||
"name": "defiler", | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"description": "A small, strange building block", | ||
@@ -17,3 +17,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=8.2" | ||
}, | ||
@@ -20,0 +20,0 @@ "repository": { |
@@ -11,3 +11,3 @@ # Defiler: A small, strange building block. | ||
- [Node.js](https://nodejs.org/) 8+ | ||
- [Node.js](https://nodejs.org/) 8.2+ | ||
- Insanity | ||
@@ -14,0 +14,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
127001
0
1205
4