fsevents
Advanced tools
Comparing version 1.2.4 to 2.0.0
139
fsevents.js
/* | ||
** © 2014 by Philipp Dunkel <pip@pipobscure.com> | ||
** Licensed under MIT License. | ||
*/ | ||
** © 2018 by Philipp Dunkel, Ben Noordhuis, Elan Shankar | ||
** Licensed under MIT License. | ||
*/ | ||
@@ -9,68 +9,74 @@ /* jshint node:true */ | ||
if (process.platform !== 'darwin') | ||
throw new Error('Module \'fsevents\' is not compatible with platform \'' + process.platform + '\''); | ||
var path = require('path'); | ||
var binary = require('node-pre-gyp'); | ||
var Native = require(binary.find(path.join(__dirname, 'package.json'))); | ||
var EventEmitter = require('events').EventEmitter; | ||
var fs = require('fs'); | ||
var inherits = require('util').inherits; | ||
function FSEvents(path, handler) { | ||
EventEmitter.call(this); | ||
Object.defineProperty(this, '_impl', { | ||
value: new Native.FSEvents(String(path || ''), handler), | ||
enumerable: false, | ||
writable: false | ||
}); | ||
if (process.platform !== 'darwin') { | ||
throw new Error(`Module 'fsevents' is not compatible with platform '${process.platform}'`); | ||
} | ||
inherits(FSEvents, EventEmitter); | ||
proxies(FSEvents, Native.FSEvents); | ||
const { stat } = require('fs'); | ||
const Native = require('./fsevents.node'); | ||
const { EventEmitter } = require('events'); | ||
module.exports = watch; | ||
module.exports.getInfo = getInfo; | ||
module.exports.FSEvents = Native.FSEvents; | ||
module.exports.Constants = Native.Constants; | ||
var defer = global.setImmediate || process.nextTick; | ||
function watch(path) { | ||
var fse = new FSEvents(String(path || ''), handler); | ||
EventEmitter.call(fse); | ||
return fse; | ||
function handler(path, flags, id) { | ||
defer(function() { | ||
fse.emit('fsevent', path, flags, id); | ||
var info = getInfo(path, flags); | ||
info.id = id; | ||
if (info.event === 'moved') { | ||
fs.stat(info.path, function(err, stat) { | ||
info.event = (err || !stat) ? 'moved-out' : 'moved-in'; | ||
fse.emit('change', path, info); | ||
fse.emit(info.event, path, info); | ||
}); | ||
} else { | ||
fse.emit('change', path, info); | ||
fse.emit(info.event, path, info); | ||
} | ||
const native = new WeakMap(); | ||
class FSEvents { | ||
constructor(path, handler) { | ||
if ('string' !== typeof path) throw new TypeError('path must be a string'); | ||
if ('function' !== typeof handler) throw new TypeError('function must be a function'); | ||
Object.defineProperties(this, { | ||
path: { value: path }, | ||
handler: { value: handler } | ||
}); | ||
} | ||
start() { | ||
if (native.has(this)) return; | ||
const instance = Native.start(this.path, this.handler); | ||
native.set(this, instance); | ||
return this; | ||
} | ||
stop() { | ||
const instance = native.get(this); | ||
if (!instance) return; | ||
Native.stop(instance); | ||
native.delete(this); | ||
return this; | ||
} | ||
} | ||
FSEvents.prototype[Symbol.toStringTag] = 'FSEvents'; | ||
function proxies(ctor, target) { | ||
Object.keys(target.prototype).filter(function(key) { | ||
return typeof target.prototype[key] === 'function'; | ||
}).forEach(function(key) { | ||
ctor.prototype[key] = function() { | ||
this._impl[key].apply(this._impl, arguments); | ||
return this; | ||
const fse = Symbol('fsevents'); | ||
class Emitter extends EventEmitter { | ||
constructor(path) { | ||
super(); | ||
this[fse] = new FSEvents(path, (...args) => this.pushEvent(...args)); | ||
} | ||
start() { | ||
this[fse].start(); | ||
return this; | ||
} | ||
stop() { | ||
this[fse].stop(); | ||
return this; | ||
} | ||
pushEvent(path, flags, id) { | ||
this.emit('fsevent', path, flags, id); | ||
const info = getInfo(path, flags, id); | ||
if (info.event === 'moved') { | ||
stat(info.path, (err, stat) => { | ||
info.event = (err || !stat) ? 'moved-out' : 'moved-in'; | ||
this.emit('change', path, info); | ||
this.emit(info.event, path, info); | ||
}); | ||
} else { | ||
Promise.resolve().then(() => { | ||
this.emit('change', path, info); | ||
this.emit(info.event, path, info); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
Emitter.prototype[Symbol.toStringTag] = 'FSEventsEmitter'; | ||
module.exports = (path)=>new Emitter(path); | ||
module.exports.getInfo = getInfo; | ||
module.exports.FSEvents = FSEvents; | ||
module.exports.Constants = Native.Constants; | ||
function getFileType(flags) { | ||
@@ -94,17 +100,16 @@ if (Native.Constants.kFSEventStreamEventFlagItemIsFile & flags) return 'file'; | ||
return { | ||
inode: !! (Native.Constants.kFSEventStreamEventFlagItemInodeMetaMod & flags), | ||
finder: !! (Native.Constants.kFSEventStreamEventFlagItemFinderInfoMod & flags), | ||
access: !! (Native.Constants.kFSEventStreamEventFlagItemChangeOwner & flags), | ||
xattrs: !! (Native.Constants.kFSEventStreamEventFlagItemXattrMod & flags) | ||
inode: !!(Native.Constants.kFSEventStreamEventFlagItemInodeMetaMod & flags), | ||
finder: !!(Native.Constants.kFSEventStreamEventFlagItemFinderInfoMod & flags), | ||
access: !!(Native.Constants.kFSEventStreamEventFlagItemChangeOwner & flags), | ||
xattrs: !!(Native.Constants.kFSEventStreamEventFlagItemXattrMod & flags) | ||
}; | ||
} | ||
function getInfo(path, flags) { | ||
function getInfo(path, flags, id) { | ||
return { | ||
path: path, | ||
path, flags, id, | ||
event: getEventType(flags), | ||
type: getFileType(flags), | ||
changes: getFileChanges(flags), | ||
flags: flags | ||
changes: getFileChanges(flags) | ||
}; | ||
} |
{ | ||
"name": "fsevents", | ||
"version": "1.2.4", | ||
"version": "2.0.0", | ||
"description": "Native Access to Mac OS-X FSEvents", | ||
"main": "fsevents.js", | ||
"dependencies": { | ||
"nan": "^2.9.2", | ||
"node-pre-gyp": "^0.10.0" | ||
}, | ||
"os": [ | ||
@@ -14,17 +10,10 @@ "darwin" | ||
"engines": { | ||
"node": ">=0.8.0" | ||
"node": ">=6.0.0" | ||
}, | ||
"scripts": { | ||
"install": "node install", | ||
"prepublish": "if [ $(npm -v | head -c 1) -lt 3 ]; then exit 1; fi && npm dedupe", | ||
"clean": "node-gyp clean && rm -f fsevents.node", | ||
"install": "[ -f fsevents.node ] || npm run prepare", | ||
"test": "tap ./test", | ||
"node-pre-gyp": "node-pre-gyp" | ||
"prepare": "node-gyp rebuild" | ||
}, | ||
"binary": { | ||
"module_name": "fse", | ||
"module_path": "./lib/binding/{configuration}/{node_abi}-{platform}-{arch}/", | ||
"remote_path": "./v{version}/", | ||
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz", | ||
"host": "https://fsevents-binaries.s3-us-west-2.amazonaws.com" | ||
}, | ||
"repository": { | ||
@@ -38,3 +27,16 @@ "type": "git", | ||
], | ||
"author": "Philipp Dunkel <pip@pipobscure.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Philipp Dunkel", | ||
"email": "pip@pipobscure.com" | ||
}, | ||
{ | ||
"name": "Ben Noordhuis", | ||
"email": "info@bnoordhuis.nl" | ||
}, | ||
{ | ||
"name": "Elan Shankar", | ||
"email": "elan.shanker@gmail.com" | ||
} | ||
], | ||
"license": "MIT", | ||
@@ -44,9 +46,6 @@ "bugs": { | ||
}, | ||
"bundledDependencies": [ | ||
"node-pre-gyp" | ||
], | ||
"homepage": "https://github.com/strongloop/fsevents", | ||
"devDependencies": { | ||
"tap": "~0.4.8" | ||
"tap": "~12.0.1" | ||
} | ||
} |
@@ -60,3 +60,3 @@ # fsevents [![NPM](https://nodei.co/npm/fsevents.png)](https://nodei.co/npm/fsevents/) | ||
Copyright (C) 2010-2014 Philipp Dunkel | ||
Copyright (C) 2010-2018 by Philipp Dunkel, Ben Noordhuis, Elan Shankar | ||
@@ -63,0 +63,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
Known malware
Supply chain riskThis package is malware. We have asked the package registry to remove it.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 36 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 3 instances in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license
Found 4 instances in 1 package
0
1
100
0
3
2
51467
12
213
- Removednan@^2.9.2
- Removednode-pre-gyp@^0.10.0
- Removednan@2.20.0(transitive)