Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

defiler

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defiler - npm Package Compare versions

Comparing version 0.13.4 to 0.13.5

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# v0.13.5
- Support custom `resolver` option to `Defiler` to resolve paths passed to `defiler.get` and `defiler.add` from the transform
# v0.13.4

@@ -2,0 +6,0 @@

102

dist/index.cjs.js

@@ -124,17 +124,13 @@ 'use strict';

// prettier-ignore
let { _dir: _dir$1, _watch, _debounce, _dirs, _files, _timeouts, _queue, _processing, _recurse, _handle, _enqueue } = symbols;
let { _watchers, _stats, _timeouts, _queue, _isProcessing, _recurse, _handle, _enqueue } = symbols;
class Watcher extends EventEmitter {
constructor(dir, watch, debounce) {
constructor(data /* = { dir, watch, debounce } */) {
super();
Object.assign(this, {
[_dir$1]: dir, // directory to recursively watch the contents of
[_watch]: watch, // whether to actually watch for changes (or just walk and retrieve contents and file stats)
[_debounce]: debounce, // fs.watch event debounce, in milliseconds
[_dirs]: new Map(), // paths of all (recursive) directories -> FSWatcher instances
[_files]: new Map(), // paths of all (recursive) files -> file stats
Object.assign(this, data, {
[_watchers]: new Map(), // paths of all (recursive) directories -> FSWatcher instances
[_stats]: new Map(), // paths of all (recursive) files -> file stats
[_timeouts]: new Map(), // paths of (recursive) files with pending debounced events -> setTimeout timer ids
[_queue]: [], // queue of pending FSWatcher events to handle
[_processing]: false, // whether some FSWatcher event is currently already in the process of being handled
[_isProcessing]: false, // whether some FSWatcher event is currently already in the process of being handled
});

@@ -146,4 +142,4 @@ }

async init() {
await this[_recurse](this[_dir$1]);
return [...this[_files].entries()].map(([path$$1, stats]) => ({ path: path$$1, stats }))
await this[_recurse](this.dir);
return [...this[_stats].entries()].map(([path$$1, stats]) => ({ path: path$$1, stats }))
}

@@ -153,8 +149,8 @@

async [_recurse](full) {
let path$$1 = full.slice(this[_dir$1].length + 1);
let path$$1 = full.slice(this.dir.length + 1);
let stats = await stat(full);
if (stats.isFile()) {
this[_files].set(path$$1, stats);
this[_stats].set(path$$1, stats);
} else if (stats.isDirectory()) {
if (this[_watch]) this[_dirs].set(path$$1, fs.watch(full, this[_handle].bind(this, full)));
if (this.watch) this[_watchers].set(path$$1, fs.watch(full, this[_handle].bind(this, full)));
await Promise.all((await readdir(full)).map(sub => this[_recurse](full + '/' + sub)));

@@ -173,3 +169,3 @@ }

this[_enqueue](full);
}, this[_debounce]),
}, this.debounce),
);

@@ -181,7 +177,7 @@ }

this[_queue].push(full);
if (this[_processing]) return
this[_processing] = true;
if (this[_isProcessing]) return
this[_isProcessing] = true;
while (this[_queue].length) {
let full = this[_queue].shift();
let path$$1 = full.slice(this[_dir$1].length + 1);
let path$$1 = full.slice(this.dir.length + 1);
try {

@@ -191,8 +187,8 @@ let stats = await stat(full);

// note the new/changed file
this[_files].set(path$$1, stats);
this[_stats].set(path$$1, stats);
this.emit('', { event: '+', path: path$$1, stats });
} else if (stats.isDirectory() && !this[_dirs].has(path$$1)) {
} else if (stats.isDirectory() && !this[_watchers].has(path$$1)) {
// note the new directory: start watching it, and report any files in it
await this[_recurse](full);
for (let [newPath, stats] of this[_files].entries()) {
for (let [newPath, stats] of this[_stats].entries()) {
if (newPath.startsWith(path$$1 + '/')) {

@@ -205,17 +201,17 @@ this.emit('', { event: '+', path: newPath, stats });

// probably this was a deleted file/directory
if (this[_files].has(path$$1)) {
if (this[_stats].has(path$$1)) {
// note the deleted file
this[_files].delete(path$$1);
this[_stats].delete(path$$1);
this.emit('', { event: '-', path: path$$1 });
} else if (this[_dirs].has(path$$1)) {
} else if (this[_watchers].has(path$$1)) {
// note the deleted directory: stop watching it, and report any files that were in it
for (let old of this[_dirs].keys()) {
for (let old of this[_watchers].keys()) {
if (old === path$$1 || old.startsWith(path$$1 + '/')) {
this[_dirs].get(old).close();
this[_dirs].delete(old);
this[_watchers].get(old).close();
this[_watchers].delete(old);
}
}
for (let old of this[_files].keys()) {
for (let old of this[_stats].keys()) {
if (old.startsWith(path$$1 + '/')) {
this[_files].delete(old);
this[_stats].delete(old);
this.emit('', { event: '-', path: old });

@@ -227,3 +223,3 @@ }

}
this[_processing] = false;
this[_isProcessing] = false;
}

@@ -233,3 +229,3 @@ }

// prettier-ignore
let { _origData, _status, _watcher, _transform, _generators, _active, _waitingFor, _whenFound, _dependencies, _queue: _queue$1, _isProcessing, _startWave, _endWave, _enqueue: _enqueue$1, _processPhysicalFile, _processFile, _processGenerator, _cur, _newProxy, _processDependents, _markFound } = symbols;
let { _origData, _status, _watcher, _transform, _generators, _resolver, _active, _waitingFor, _whenFound, _dependencies, _queue: _queue$1, _isProcessing: _isProcessing$1, _startWave, _endWave, _enqueue: _enqueue$1, _processPhysicalFile, _processFile, _processGenerator, _cur, _newProxy, _processDependents, _markFound } = symbols;

@@ -245,2 +241,3 @@ class Defiler extends EventEmitter {

generators = [],
resolver,
}) {

@@ -262,3 +259,2 @@ if (typeof dir !== 'string') throw new TypeError('defiler: dir must be a string')

super();
dir = path.resolve(dir);
Object.assign(this, {

@@ -269,5 +265,6 @@ paths: new Set(), // set of original paths for all physical files

[_status]: null, // null = exec not called; false = exec pending; true = exec finished
[_watcher]: { watcher: new Watcher(dir, watch, debounce), dir, read, enc, watch }, // information about the directory to watch
[_watcher]: new Watcher({ dir: path.resolve(dir), read, enc, watch, debounce }), // Watcher instance
[_transform]: transform, // the transform to run on all files
[_generators]: new Map(generators.map(generator => [Symbol(), generator])), // unique symbols -> registered generators
[_resolver]: resolver, // (base, path) => path resolver function, used in defiler.get and defiler.add from transform
[_active]: new Set(), // original paths of all files currently undergoing transformation and symbols of all generators currently running

@@ -279,3 +276,3 @@ [_waitingFor]: new Map(), // original paths -> number of other files they're currently waiting on to exist

[_queue$1]: [], // queue of pending Watcher events to handle
[_isProcessing]: false, // whether some Watcher event is currently already in the process of being handled
[_isProcessing$1]: false, // whether some Watcher event is currently already in the process of being handled
});

@@ -288,8 +285,7 @@ }

this[_status] = false;
this[_isProcessing] = true;
this[_isProcessing$1] = true;
let done = this[_startWave]();
// init the Watcher instance
let { watcher, watch } = this[_watcher];
if (watch) watcher.on('', event => this[_enqueue$1](event));
let files = await watcher.init();
this[_watcher].on('', event => this[_enqueue$1](event));
let files = await this[_watcher].init();
// note that all files are pending transformation

@@ -308,3 +304,3 @@ for (let { path: path$$1 } of files) {

this[_status] = true;
this[_isProcessing] = false;
this[_isProcessing$1] = false;
this[_enqueue$1]();

@@ -323,17 +319,16 @@ }

let { [_cur]: cur, [_waitingFor]: waitingFor } = this;
if (this[_resolver] && typeof cur.dep === 'string') {
path$$1 = this[_resolver](cur.dep, path$$1);
}
if (cur.root) {
this[_dependencies].has(cur.root)
? this[_dependencies].get(cur.root).add(path$$1)
: this[_dependencies].set(cur.root, new Set([path$$1]));
if (!this[_dependencies].has(cur.root)) this[_dependencies].set(cur.root, new Set());
this[_dependencies].get(cur.root).add(path$$1);
}
if (!this[_status] && !this.files.has(path$$1)) {
if (cur.dep) waitingFor.set(cur.dep, (waitingFor.get(cur.dep) || 0) + 1);
if (this[_whenFound].has(path$$1)) {
await this[_whenFound].get(path$$1).promise;
} else {
if (!this[_whenFound].has(path$$1)) {
let resolve;
let promise = new Promise(res => (resolve = res));
this[_whenFound].set(path$$1, { promise, resolve });
await promise;
this[_whenFound].set(path$$1, { promise: new Promise(res => (resolve = res)), resolve });
}
await this[_whenFound].get(path$$1).promise;
if (cur.dep) waitingFor.set(cur.dep, waitingFor.get(cur.dep) - 1);

@@ -348,2 +343,5 @@ }

if (typeof file !== 'object') throw new TypeError('defiler.add: file must be an object')
if (this[_resolver] && typeof this[_cur].dep === 'string') {
file.path = this[_resolver](this[_cur].dep, file.path);
}
this[_processFile](file);

@@ -362,4 +360,4 @@ }

if (event) this[_queue$1].push(event);
if (this[_isProcessing]) return
this[_isProcessing] = true;
if (this[_isProcessing$1]) return
this[_isProcessing$1] = true;
while (this[_queue$1].length) {

@@ -380,3 +378,3 @@ let { event, path: path$$1, stats } = this[_queue$1].shift();

}
this[_isProcessing] = false;
this[_isProcessing$1] = false;
}

@@ -383,0 +381,0 @@

@@ -118,17 +118,13 @@ import { readdir, readFile, stat, watch } from 'fs';

// prettier-ignore
let { _dir: _dir$1, _watch, _debounce, _dirs, _files, _timeouts, _queue, _processing, _recurse, _handle, _enqueue } = symbols;
let { _watchers, _stats, _timeouts, _queue, _isProcessing, _recurse, _handle, _enqueue } = symbols;
class Watcher extends EventEmitter {
constructor(dir, watch$$1, debounce) {
constructor(data /* = { dir, watch, debounce } */) {
super();
Object.assign(this, {
[_dir$1]: dir, // directory to recursively watch the contents of
[_watch]: watch$$1, // whether to actually watch for changes (or just walk and retrieve contents and file stats)
[_debounce]: debounce, // fs.watch event debounce, in milliseconds
[_dirs]: new Map(), // paths of all (recursive) directories -> FSWatcher instances
[_files]: new Map(), // paths of all (recursive) files -> file stats
Object.assign(this, data, {
[_watchers]: new Map(), // paths of all (recursive) directories -> FSWatcher instances
[_stats]: new Map(), // paths of all (recursive) files -> file stats
[_timeouts]: new Map(), // paths of (recursive) files with pending debounced events -> setTimeout timer ids
[_queue]: [], // queue of pending FSWatcher events to handle
[_processing]: false, // whether some FSWatcher event is currently already in the process of being handled
[_isProcessing]: false, // whether some FSWatcher event is currently already in the process of being handled
});

@@ -140,4 +136,4 @@ }

async init() {
await this[_recurse](this[_dir$1]);
return [...this[_files].entries()].map(([path, stats]) => ({ path, stats }))
await this[_recurse](this.dir);
return [...this[_stats].entries()].map(([path, stats]) => ({ path, stats }))
}

@@ -147,8 +143,8 @@

async [_recurse](full) {
let path = full.slice(this[_dir$1].length + 1);
let path = full.slice(this.dir.length + 1);
let stats = await stat$1(full);
if (stats.isFile()) {
this[_files].set(path, stats);
this[_stats].set(path, stats);
} else if (stats.isDirectory()) {
if (this[_watch]) this[_dirs].set(path, watch(full, this[_handle].bind(this, full)));
if (this.watch) this[_watchers].set(path, watch(full, this[_handle].bind(this, full)));
await Promise.all((await readdir$1(full)).map(sub => this[_recurse](full + '/' + sub)));

@@ -167,3 +163,3 @@ }

this[_enqueue](full);
}, this[_debounce]),
}, this.debounce),
);

@@ -175,7 +171,7 @@ }

this[_queue].push(full);
if (this[_processing]) return
this[_processing] = true;
if (this[_isProcessing]) return
this[_isProcessing] = true;
while (this[_queue].length) {
let full = this[_queue].shift();
let path = full.slice(this[_dir$1].length + 1);
let path = full.slice(this.dir.length + 1);
try {

@@ -185,8 +181,8 @@ let stats = await stat$1(full);

// note the new/changed file
this[_files].set(path, stats);
this[_stats].set(path, stats);
this.emit('', { event: '+', path, stats });
} else if (stats.isDirectory() && !this[_dirs].has(path)) {
} else if (stats.isDirectory() && !this[_watchers].has(path)) {
// note the new directory: start watching it, and report any files in it
await this[_recurse](full);
for (let [newPath, stats] of this[_files].entries()) {
for (let [newPath, stats] of this[_stats].entries()) {
if (newPath.startsWith(path + '/')) {

@@ -199,17 +195,17 @@ this.emit('', { event: '+', path: newPath, stats });

// probably this was a deleted file/directory
if (this[_files].has(path)) {
if (this[_stats].has(path)) {
// note the deleted file
this[_files].delete(path);
this[_stats].delete(path);
this.emit('', { event: '-', path });
} else if (this[_dirs].has(path)) {
} else if (this[_watchers].has(path)) {
// note the deleted directory: stop watching it, and report any files that were in it
for (let old of this[_dirs].keys()) {
for (let old of this[_watchers].keys()) {
if (old === path || old.startsWith(path + '/')) {
this[_dirs].get(old).close();
this[_dirs].delete(old);
this[_watchers].get(old).close();
this[_watchers].delete(old);
}
}
for (let old of this[_files].keys()) {
for (let old of this[_stats].keys()) {
if (old.startsWith(path + '/')) {
this[_files].delete(old);
this[_stats].delete(old);
this.emit('', { event: '-', path: old });

@@ -221,3 +217,3 @@ }

}
this[_processing] = false;
this[_isProcessing] = false;
}

@@ -227,3 +223,3 @@ }

// prettier-ignore
let { _origData, _status, _watcher, _transform, _generators, _active, _waitingFor, _whenFound, _dependencies, _queue: _queue$1, _isProcessing, _startWave, _endWave, _enqueue: _enqueue$1, _processPhysicalFile, _processFile, _processGenerator, _cur, _newProxy, _processDependents, _markFound } = symbols;
let { _origData, _status, _watcher, _transform, _generators, _resolver, _active, _waitingFor, _whenFound, _dependencies, _queue: _queue$1, _isProcessing: _isProcessing$1, _startWave, _endWave, _enqueue: _enqueue$1, _processPhysicalFile, _processFile, _processGenerator, _cur, _newProxy, _processDependents, _markFound } = symbols;

@@ -239,2 +235,3 @@ class Defiler extends EventEmitter {

generators = [],
resolver,
}) {

@@ -256,3 +253,2 @@ if (typeof dir !== 'string') throw new TypeError('defiler: dir must be a string')

super();
dir = resolve(dir);
Object.assign(this, {

@@ -263,5 +259,6 @@ paths: new Set(), // set of original paths for all physical files

[_status]: null, // null = exec not called; false = exec pending; true = exec finished
[_watcher]: { watcher: new Watcher(dir, watch$$1, debounce), dir, read, enc, watch: watch$$1 }, // information about the directory to watch
[_watcher]: new Watcher({ dir: resolve(dir), read, enc, watch: watch$$1, debounce }), // Watcher instance
[_transform]: transform, // the transform to run on all files
[_generators]: new Map(generators.map(generator => [Symbol(), generator])), // unique symbols -> registered generators
[_resolver]: resolver, // (base, path) => path resolver function, used in defiler.get and defiler.add from transform
[_active]: new Set(), // original paths of all files currently undergoing transformation and symbols of all generators currently running

@@ -273,3 +270,3 @@ [_waitingFor]: new Map(), // original paths -> number of other files they're currently waiting on to exist

[_queue$1]: [], // queue of pending Watcher events to handle
[_isProcessing]: false, // whether some Watcher event is currently already in the process of being handled
[_isProcessing$1]: false, // whether some Watcher event is currently already in the process of being handled
});

@@ -282,8 +279,7 @@ }

this[_status] = false;
this[_isProcessing] = true;
this[_isProcessing$1] = true;
let done = this[_startWave]();
// init the Watcher instance
let { watcher, watch: watch$$1 } = this[_watcher];
if (watch$$1) watcher.on('', event => this[_enqueue$1](event));
let files = await watcher.init();
this[_watcher].on('', event => this[_enqueue$1](event));
let files = await this[_watcher].init();
// note that all files are pending transformation

@@ -302,3 +298,3 @@ for (let { path } of files) {

this[_status] = true;
this[_isProcessing] = false;
this[_isProcessing$1] = false;
this[_enqueue$1]();

@@ -317,17 +313,16 @@ }

let { [_cur]: cur, [_waitingFor]: waitingFor } = this;
if (this[_resolver] && typeof cur.dep === 'string') {
path = this[_resolver](cur.dep, path);
}
if (cur.root) {
this[_dependencies].has(cur.root)
? this[_dependencies].get(cur.root).add(path)
: this[_dependencies].set(cur.root, new Set([path]));
if (!this[_dependencies].has(cur.root)) this[_dependencies].set(cur.root, new Set());
this[_dependencies].get(cur.root).add(path);
}
if (!this[_status] && !this.files.has(path)) {
if (cur.dep) waitingFor.set(cur.dep, (waitingFor.get(cur.dep) || 0) + 1);
if (this[_whenFound].has(path)) {
await this[_whenFound].get(path).promise;
} else {
if (!this[_whenFound].has(path)) {
let resolve$$1;
let promise = new Promise(res => (resolve$$1 = res));
this[_whenFound].set(path, { promise, resolve: resolve$$1 });
await promise;
this[_whenFound].set(path, { promise: new Promise(res => (resolve$$1 = res)), resolve: resolve$$1 });
}
await this[_whenFound].get(path).promise;
if (cur.dep) waitingFor.set(cur.dep, waitingFor.get(cur.dep) - 1);

@@ -342,2 +337,5 @@ }

if (typeof file !== 'object') throw new TypeError('defiler.add: file must be an object')
if (this[_resolver] && typeof this[_cur].dep === 'string') {
file.path = this[_resolver](this[_cur].dep, file.path);
}
this[_processFile](file);

@@ -356,4 +354,4 @@ }

if (event) this[_queue$1].push(event);
if (this[_isProcessing]) return
this[_isProcessing] = true;
if (this[_isProcessing$1]) return
this[_isProcessing$1] = true;
while (this[_queue$1].length) {

@@ -374,3 +372,3 @@ let { event, path, stats } = this[_queue$1].shift();

}
this[_isProcessing] = false;
this[_isProcessing$1] = false;
}

@@ -377,0 +375,0 @@

{
"name": "defiler",
"version": "0.13.4",
"version": "0.13.5",
"description": "A small, strange building block",

@@ -5,0 +5,0 @@ "keywords": ["build", "framework", "async", "watch"],

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc