Socket
Socket
Sign inDemoInstall

fsevents

Package Overview
Dependencies
0
Maintainers
4
Versions
67
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.4 to 2.0.0

fsevents.node

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc