diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7bd8d2b4..989953e1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -41,7 +41,7 @@ jobs: displayName: Github Release inputs: gitHubConnection: devongovett - repositoryName: devongovett/fschanges + repositoryName: parcel-bundler/watcher assets: $(System.DefaultWorkingDirectory)/prebuilds/@parcel/* - task: Npm@1 displayName: NPM Release diff --git a/binding.gyp b/binding.gyp index 4381894a..a5ee8665 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "fschanges", + "target_name": "watcher", "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ], "sources": [ "src/binding.cc", "src/Watcher.cc", "src/Backend.cc", "src/DirTree.cc" ], "include_dirs" : [" { - console.log(events); - // fschanges.unsubscribe(dir, fn, {ignore: [dir + '/.git']}); -}; - -fschanges.subscribe(dir, fn, {ignore: [dir + '/.git']}); - -// let w = new Watcher(dir); -// w.getEventsSince(snapshotPath); -// w.writeSnapshot(snapshotPath); -// w.subscribe(events => { - -// }); -// w.unsubscribe(); diff --git a/index.js b/index.js index f04a5c95..8697b5a1 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const binding = require('bindings')('fschanges.node'); +const binding = require('bindings')('watcher.node'); const path = require('path'); function normalizeOptions(dir, opts = {}) { diff --git a/package.json b/package.json index 9bf511bf..aa9c970e 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "name": "@parcel/watcher", "version": "2.0.0-alpha.2", "main": "index.js", - "repository" : { - "type" : "git", - "url": "https://github.com/devongovett/fschanges.git" + "repository": { + "type": "git", + "url": "https://github.com/parcel-bundler/watcher.git" }, "scripts": { "install": "prebuild-install -r napi || node-gyp rebuild", diff --git a/src/binding.cc b/src/binding.cc index 1863f67d..42b13946 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -223,4 +223,4 @@ Object Init(Env env, Object exports) { return exports; } -NODE_API_MODULE(fschanges, Init) +NODE_API_MODULE(watcher, Init) diff --git a/src/watchman/WatchmanBackend.cc b/src/watchman/WatchmanBackend.cc index 324645e1..c2bc8bf1 100644 --- a/src/watchman/WatchmanBackend.cc +++ b/src/watchman/WatchmanBackend.cc @@ -261,7 +261,7 @@ void WatchmanBackend::getEventsSince(Watcher &watcher, std::string *snapshotPath std::string getId(Watcher &watcher) { std::ostringstream id; - id << "fschanges-"; + id << "parcel-"; id << (void *)&watcher; return id.str(); } diff --git a/test/since.js b/test/since.js index 99e3a674..b4481865 100644 --- a/test/since.js +++ b/test/since.js @@ -1,4 +1,4 @@ -const fschanges = require('../'); +const watcher = require('../'); const assert = require('assert'); const fs = require('fs-extra'); const path = require('path'); @@ -42,14 +42,14 @@ describe('since', () => { describe('files', () => { it('should emit when a file is created', async () => { let f = getFilename(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); if (isSecondPrecision) { await sleep(1000); } await fs.writeFile(f, 'hello world'); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'create', path: f} ]); @@ -59,11 +59,11 @@ describe('since', () => { let f = getFilename(); await fs.writeFile(f, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.writeFile(f, 'hi'); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'update', path: f} ]); @@ -74,11 +74,11 @@ describe('since', () => { let f2 = getFilename(); await fs.writeFile(f1, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.rename(f1, f2); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f1}, {type: 'create', path: f2} @@ -89,11 +89,11 @@ describe('since', () => { let f = getFilename(); await fs.writeFile(f, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.unlink(f); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f} ]); @@ -103,11 +103,11 @@ describe('since', () => { describe('directories', () => { it('should emit when a directory is created', async () => { let f1 = getFilename(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.mkdir(f1); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'create', path: f1} ]); @@ -118,11 +118,11 @@ describe('since', () => { let f2 = getFilename(); await fs.mkdir(f1); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.rename(f1, f2); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f1}, @@ -134,11 +134,11 @@ describe('since', () => { let f1 = getFilename(); await fs.mkdir(f1); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.remove(f1); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f1} @@ -152,14 +152,14 @@ describe('since', () => { let f2 = getFilename(path.basename(f1)); await fs.mkdir(f1); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); if (isSecondPrecision) { await sleep(1000); } await fs.writeFile(f2, 'hello world'); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'create', path: f2} ]); @@ -171,11 +171,11 @@ describe('since', () => { await fs.mkdir(f1); await fs.writeFile(f2, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.writeFile(f2, 'hi'); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'update', path: f2} ]); @@ -188,11 +188,11 @@ describe('since', () => { await fs.mkdir(f1); await fs.writeFile(f2, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.rename(f2, f3); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f2}, {type: 'create', path: f3} @@ -205,11 +205,11 @@ describe('since', () => { await fs.mkdir(f1); await fs.writeFile(f2, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.unlink(f2); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f2} ]); @@ -222,11 +222,11 @@ describe('since', () => { let f2 = getFilename(path.basename(f1)); await fs.mkdir(f1); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.mkdir(f2); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'create', path: f2} ]); @@ -239,11 +239,11 @@ describe('since', () => { await fs.mkdir(f1); await fs.mkdir(f2); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.rename(f2, f3); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f2}, @@ -257,11 +257,11 @@ describe('since', () => { await fs.mkdir(f1); await fs.writeFile(f2, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.remove(f1); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f1}, {type: 'delete', path: f2} @@ -275,11 +275,11 @@ describe('since', () => { let f2 = getFilename(); await fs.writeFile(f1, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.symlink(f1, f2); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'create', path: f2} ]); @@ -291,11 +291,11 @@ describe('since', () => { await fs.writeFile(f1, 'hello world'); await fs.symlink(f1, f2); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.writeFile(f2, 'hi'); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'update', path: f1} ]); @@ -308,11 +308,11 @@ describe('since', () => { await fs.writeFile(f1, 'hello world'); await fs.symlink(f1, f2); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.rename(f2, f3); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f2}, {type: 'create', path: f3} @@ -325,11 +325,11 @@ describe('since', () => { await fs.writeFile(f1, 'hello world'); await fs.symlink(f1, f2); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.unlink(f2); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f2} ]); @@ -343,13 +343,13 @@ describe('since', () => { let f1 = getFilename(); let f2 = getFilename(); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.writeFile(f1, 'hello world'); await fs.writeFile(f2, 'hello world'); await fs.unlink(f2); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'create', path: f1} ]); @@ -358,7 +358,7 @@ describe('since', () => { it('should coalese create and update events', async () => { let f1 = getFilename(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); if (isSecondPrecision) { await sleep(1000); } @@ -366,7 +366,7 @@ describe('since', () => { await fs.writeFile(f1, 'updated'); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'create', path: f1} ]); @@ -376,12 +376,12 @@ describe('since', () => { it('should coalese create and rename events', async () => { let f1 = getFilename(); let f2 = getFilename(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.writeFile(f1, 'hello world'); await fs.rename(f1, f2); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'create', path: f2} ]); @@ -392,14 +392,14 @@ describe('since', () => { let f2 = getFilename(); let f3 = getFilename(); let f4 = getFilename(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.writeFile(f1, 'hello world'); await fs.rename(f1, f2); await fs.rename(f2, f3); await fs.rename(f3, f4); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'create', path: f4} ]); @@ -410,14 +410,14 @@ describe('since', () => { let f1 = getFilename(); await fs.writeFile(f1, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.writeFile(f1, 'update'); await fs.writeFile(f1, 'update2'); await fs.writeFile(f1, 'update3'); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'update', path:f1} ]); @@ -427,13 +427,13 @@ describe('since', () => { let f1 = getFilename(); await fs.writeFile(f1, 'hello world'); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend}); await fs.writeFile(f1, 'update'); await fs.unlink(f1); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend}); assert.deepEqual(res, [ {type: 'delete', path: f1} ]); @@ -448,7 +448,7 @@ describe('since', () => { let ignore = [dir]; await fs.mkdir(dir); await sleep(); - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend, ignore}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend, ignore}); if (isSecondPrecision) { await sleep(1000); } @@ -457,7 +457,7 @@ describe('since', () => { await fs.writeFile(f2, 'sup'); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend, ignore}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend, ignore}); assert.deepEqual(res, [ {type: 'create', path: f1} ]); @@ -467,7 +467,7 @@ describe('since', () => { let f1 = getFilename(); let f2 = getFilename(); let ignore = [f2]; - await fschanges.writeSnapshot(tmpDir, snapshotPath, {backend, ignore}); + await watcher.writeSnapshot(tmpDir, snapshotPath, {backend, ignore}); if (isSecondPrecision) { await sleep(1000); } @@ -476,7 +476,7 @@ describe('since', () => { await fs.writeFile(f2, 'sup'); await sleep(); - let res = await fschanges.getEventsSince(tmpDir, snapshotPath, {backend, ignore}); + let res = await watcher.getEventsSince(tmpDir, snapshotPath, {backend, ignore}); assert.deepEqual(res, [ {type: 'create', path: f1} ]); @@ -489,7 +489,7 @@ describe('since', () => { let threw = false; try { - await fschanges.writeSnapshot(dir, snapshotPath, {backend}); + await watcher.writeSnapshot(dir, snapshotPath, {backend}); } catch (err) { threw = true; } @@ -508,7 +508,7 @@ describe('since', () => { let threw = false; try { - await fschanges.writeSnapshot(file, snapshotPath, {backend}); + await watcher.writeSnapshot(file, snapshotPath, {backend}); } catch (err) { threw = true; } diff --git a/test/watcher.js b/test/watcher.js index b4a14d76..b3fee2e7 100644 --- a/test/watcher.js +++ b/test/watcher.js @@ -1,4 +1,4 @@ -const fschanges = require('../'); +const watcher = require('../'); const assert = require('assert'); const fs = require('fs-extra'); const path = require('path'); @@ -49,7 +49,7 @@ describe('watcher', () => { ignoreDir = getFilename(); ignoreFile = getFilename(); await new Promise(resolve => setTimeout(resolve, 100)); - sub = await fschanges.subscribe(tmpDir, fn, {backend, ignore: [ignoreDir, ignoreFile]}); + sub = await watcher.subscribe(tmpDir, fn, {backend, ignore: [ignoreDir, ignoreFile]}); }); after(async () => { @@ -448,7 +448,7 @@ describe('watcher', () => { function listen() { return new Promise(async resolve => { - let sub = await fschanges.subscribe(dir, async (err, events) => { + let sub = await watcher.subscribe(dir, async (err, events) => { setImmediate(() => resolve(events)); await sub.unsubscribe(); }, {backend}); @@ -475,7 +475,7 @@ describe('watcher', () => { function listen(ignore) { return new Promise(async resolve => { - let sub = await fschanges.subscribe(dir, async (err, events) => { + let sub = await watcher.subscribe(dir, async (err, events) => { setImmediate(() => resolve(events)); await sub.unsubscribe(); }, {backend, ignore}); @@ -505,7 +505,7 @@ describe('watcher', () => { function listen(dir) { return new Promise(async resolve => { - let sub = await fschanges.subscribe(dir, async (err, events) => { + let sub = await watcher.subscribe(dir, async (err, events) => { setImmediate(() => resolve(events)); await sub.unsubscribe(); }, {backend}); @@ -534,7 +534,7 @@ describe('watcher', () => { function listen(dir) { return new Promise(async resolve => { - let sub = await fschanges.subscribe(dir, (err, events) => { + let sub = await watcher.subscribe(dir, (err, events) => { setImmediate(() => resolve([events, sub])); }, {backend}); }); @@ -546,7 +546,7 @@ describe('watcher', () => { await fs.writeFile(path.join(dir, 'test1.txt'), 'hello1'); await new Promise(resolve => setTimeout(resolve, 100)); - await fschanges.writeSnapshot(dir, snapshot, {backend}); + await watcher.writeSnapshot(dir, snapshot, {backend}); await new Promise(resolve => setTimeout(resolve, 1000)); await fs.writeFile(path.join(dir, 'test2.txt'), 'hello2'); @@ -557,7 +557,7 @@ describe('watcher', () => { {type: 'create', path: path.join(dir, 'test1.txt')} ]); - let since = await fschanges.getEventsSince(dir, snapshot, {backend}); + let since = await watcher.getEventsSince(dir, snapshot, {backend}); assert.deepEqual(since, [ {type: 'create', path: path.join(dir, 'test2.txt')} ]); @@ -572,7 +572,7 @@ describe('watcher', () => { let threw = false; try { - await fschanges.subscribe(dir, (err, events) => { + await watcher.subscribe(dir, (err, events) => { assert(false, 'Should not get here'); }, {backend}); } catch (err) { @@ -593,7 +593,7 @@ describe('watcher', () => { let threw = false; try { - await fschanges.subscribe(file, (err, events) => { + await watcher.subscribe(file, (err, events) => { assert(false, 'Should not get here'); }, {backend}); } catch (err) { @@ -613,7 +613,7 @@ describe('watcher', () => { await new Promise(resolve => setTimeout(resolve, 100)); let p = new Promise(resolve => { - fschanges.subscribe(dir, (err, events) => { + watcher.subscribe(dir, (err, events) => { setImmediate(() => resolve(err)); }, {backend: 'watchman'}); });