flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
13
BACK_BACK/node_modules/@parcel/watcher/.babelrc
generated
vendored
Executable file
13
BACK_BACK/node_modules/@parcel/watcher/.babelrc
generated
vendored
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"targets": {
|
||||
"node": "6"
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": ["@babel/plugin-transform-runtime"]
|
||||
}
|
||||
21
BACK_BACK/node_modules/@parcel/watcher/LICENSE
generated
vendored
Executable file
21
BACK_BACK/node_modules/@parcel/watcher/LICENSE
generated
vendored
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017-present Devon Govett
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
5
BACK_BACK/node_modules/@parcel/watcher/index.js
generated
vendored
Executable file
5
BACK_BACK/node_modules/@parcel/watcher/index.js
generated
vendored
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
// Node 8 supports native async functions - no need to use compiled code!
|
||||
module.exports =
|
||||
parseInt(process.versions.node, 10) < 8
|
||||
? require('./lib/Watcher')
|
||||
: require('./src/Watcher');
|
||||
415
BACK_BACK/node_modules/@parcel/watcher/lib/Watcher.js
generated
vendored
Executable file
415
BACK_BACK/node_modules/@parcel/watcher/lib/Watcher.js
generated
vendored
Executable file
|
|
@ -0,0 +1,415 @@
|
|||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
||||
|
||||
const fork = require('child_process').fork;
|
||||
|
||||
const optionsTransfer = require('./options');
|
||||
|
||||
const Path = require('path');
|
||||
|
||||
const _require = require('events'),
|
||||
EventEmitter = _require.EventEmitter;
|
||||
|
||||
const _require2 = require('@parcel/utils'),
|
||||
errorUtils = _require2.errorUtils;
|
||||
/**
|
||||
* This watcher wraps chokidar so that we watch directories rather than individual files on macOS.
|
||||
* This prevents us from hitting EMFILE errors when running out of file descriptors.
|
||||
* Chokidar does not have support for watching directories on non-macOS platforms, so we disable
|
||||
* this behavior in order to prevent watching more individual files than necessary (e.g. node_modules).
|
||||
*/
|
||||
|
||||
|
||||
class Watcher extends EventEmitter {
|
||||
constructor(options = {
|
||||
// FS events on macOS are flakey in the tests, which write lots of files very quickly
|
||||
// See https://github.com/paulmillr/chokidar/issues/612
|
||||
useFsEvents: process.platform === 'darwin' && process.env.NODE_ENV !== 'test',
|
||||
ignoreInitial: true,
|
||||
ignorePermissionErrors: true,
|
||||
ignored: /(^|[/\\])\.(git|cache)/
|
||||
}) {
|
||||
super();
|
||||
this.options = optionsTransfer.encode(options);
|
||||
this.watchedPaths = new Set();
|
||||
this.child = null;
|
||||
this.ready = false;
|
||||
this.readyQueue = [];
|
||||
this.watchedDirectories = new Map();
|
||||
this.stopped = false;
|
||||
this.on('ready', () => {
|
||||
this.ready = true;
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = this.readyQueue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
let func = _step.value;
|
||||
func();
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.readyQueue = [];
|
||||
});
|
||||
this.startchild();
|
||||
}
|
||||
|
||||
startchild() {
|
||||
if (this.child) return;
|
||||
let filteredArgs = process.execArgv.filter(v => !/^--(debug|inspect)/.test(v));
|
||||
let options = {
|
||||
execArgv: filteredArgs,
|
||||
env: process.env,
|
||||
cwd: process.cwd()
|
||||
};
|
||||
this.child = fork(Path.join(__dirname, 'child'), process.argv, options);
|
||||
|
||||
if (this.watchedPaths.size > 0) {
|
||||
this.sendCommand('add', [Array.from(this.watchedPaths)]);
|
||||
}
|
||||
|
||||
this.child.send({
|
||||
type: 'init',
|
||||
options: this.options
|
||||
});
|
||||
this.child.on('message', msg => this.handleEmit(msg.event, msg.path));
|
||||
this.child.on('error', () => {});
|
||||
this.child.on('exit', () => this.handleClosed()); // this.child.on('close', () => this.handleClosed());
|
||||
}
|
||||
|
||||
handleClosed() {
|
||||
if (!this.stopped) {
|
||||
// Restart the child
|
||||
this.child = null;
|
||||
this.ready = false;
|
||||
this.startchild();
|
||||
}
|
||||
|
||||
this.emit('childDead');
|
||||
}
|
||||
|
||||
handleEmit(event, data) {
|
||||
if (event === 'watcherError') {
|
||||
data = errorUtils.jsonToError(data);
|
||||
}
|
||||
|
||||
this.emit(event, data);
|
||||
}
|
||||
|
||||
sendCommand(func, args) {
|
||||
if (!this.ready) {
|
||||
return this.readyQueue.push(() => this.sendCommand(func, args));
|
||||
}
|
||||
|
||||
this.child.send({
|
||||
type: 'function',
|
||||
name: func,
|
||||
args: args
|
||||
});
|
||||
}
|
||||
|
||||
_addPath(path) {
|
||||
if (!this.watchedPaths.has(path)) {
|
||||
this.watchedPaths.add(path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
add(paths) {
|
||||
let added = false;
|
||||
|
||||
if (Array.isArray(paths)) {
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = paths[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
let path = _step2.value;
|
||||
added = !added ? this._addPath(path) : true;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
added = this._addPath(paths);
|
||||
}
|
||||
|
||||
if (added) this.sendCommand('add', [paths]);
|
||||
}
|
||||
|
||||
_closePath(path) {
|
||||
if (this.watchedPaths.has(path)) {
|
||||
this.watchedPaths.delete(path);
|
||||
}
|
||||
|
||||
this.sendCommand('_closePath', [path]);
|
||||
}
|
||||
|
||||
_emulateChildDead() {
|
||||
if (!this.child) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.child.send({
|
||||
type: 'die'
|
||||
});
|
||||
}
|
||||
|
||||
_emulateChildError() {
|
||||
if (!this.child) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.child.send({
|
||||
type: 'emulate_error'
|
||||
});
|
||||
}
|
||||
|
||||
getWatched() {
|
||||
let watchList = {};
|
||||
var _iteratorNormalCompletion3 = true;
|
||||
var _didIteratorError3 = false;
|
||||
var _iteratorError3 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator3 = this.watchedPaths[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
||||
let path = _step3.value;
|
||||
let key = this.options.cwd ? Path.relative(this.options.cwd, path) : path;
|
||||
watchList[key || '.'] = [];
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError3 = true;
|
||||
_iteratorError3 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
||||
_iterator3.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError3) {
|
||||
throw _iteratorError3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return watchList;
|
||||
}
|
||||
/**
|
||||
* Find a parent directory of `path` which is already watched
|
||||
*/
|
||||
|
||||
|
||||
getWatchedParent(path) {
|
||||
path = Path.dirname(path);
|
||||
let root = Path.parse(path).root;
|
||||
|
||||
while (path !== root) {
|
||||
if (this.watchedDirectories.has(path)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
path = Path.dirname(path);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Find a list of child directories of `path` which are already watched
|
||||
*/
|
||||
|
||||
|
||||
getWatchedChildren(path) {
|
||||
path = Path.dirname(path) + Path.sep;
|
||||
let res = [];
|
||||
var _iteratorNormalCompletion4 = true;
|
||||
var _didIteratorError4 = false;
|
||||
var _iteratorError4 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator4 = this.watchedDirectories.keys()[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
||||
let dir = _step4.value;
|
||||
|
||||
if (dir.startsWith(path)) {
|
||||
res.push(dir);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError4 = true;
|
||||
_iteratorError4 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
||||
_iterator4.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError4) {
|
||||
throw _iteratorError4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* Add a path to the watcher
|
||||
*/
|
||||
|
||||
|
||||
watch(path) {
|
||||
if (this.shouldWatchDirs) {
|
||||
// If there is no parent directory already watching this path, add a new watcher.
|
||||
let parent = this.getWatchedParent(path);
|
||||
|
||||
if (!parent) {
|
||||
// Find watchers on child directories, and remove them. They will be handled by the new parent watcher.
|
||||
let children = this.getWatchedChildren(path);
|
||||
let count = 1;
|
||||
var _iteratorNormalCompletion5 = true;
|
||||
var _didIteratorError5 = false;
|
||||
var _iteratorError5 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator5 = children[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
||||
let dir = _step5.value;
|
||||
count += this.watchedDirectories.get(dir);
|
||||
|
||||
this._closePath(dir);
|
||||
|
||||
this.watchedDirectories.delete(dir);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError5 = true;
|
||||
_iteratorError5 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
|
||||
_iterator5.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError5) {
|
||||
throw _iteratorError5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let dir = Path.dirname(path);
|
||||
this.add(dir);
|
||||
this.watchedDirectories.set(dir, count);
|
||||
} else {
|
||||
// Otherwise, increment the reference count of the parent watcher.
|
||||
this.watchedDirectories.set(parent, this.watchedDirectories.get(parent) + 1);
|
||||
}
|
||||
} else {
|
||||
this.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
_unwatch(paths) {
|
||||
let removed = false;
|
||||
|
||||
if (Array.isArray(paths)) {
|
||||
var _iteratorNormalCompletion6 = true;
|
||||
var _didIteratorError6 = false;
|
||||
var _iteratorError6 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator6 = paths[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
||||
let p = _step6.value;
|
||||
removed = !removed ? this.watchedPaths.delete(p) : true;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError6 = true;
|
||||
_iteratorError6 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
|
||||
_iterator6.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError6) {
|
||||
throw _iteratorError6;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
removed = this.watchedPaths.delete(paths);
|
||||
}
|
||||
|
||||
if (removed) this.sendCommand('unwatch', [paths]);
|
||||
}
|
||||
/**
|
||||
* Remove a path from the watcher
|
||||
*/
|
||||
|
||||
|
||||
unwatch(path) {
|
||||
if (this.shouldWatchDirs) {
|
||||
let dir = this.getWatchedParent(path);
|
||||
|
||||
if (dir) {
|
||||
// When the count of files watching a directory reaches zero, unwatch it.
|
||||
let count = this.watchedDirectories.get(dir) - 1;
|
||||
|
||||
if (count === 0) {
|
||||
this.watchedDirectories.delete(dir);
|
||||
|
||||
this._unwatch(dir);
|
||||
} else {
|
||||
this.watchedDirectories.set(dir, count);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this._unwatch(path);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Stop watching all paths
|
||||
*/
|
||||
|
||||
|
||||
stop() {
|
||||
var _this = this;
|
||||
|
||||
return (0, _asyncToGenerator2.default)(function* () {
|
||||
_this.stopped = true;
|
||||
|
||||
if (_this.child) {
|
||||
_this.child.kill();
|
||||
|
||||
return new Promise(resolve => _this.once('childDead', resolve));
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Watcher;
|
||||
61
BACK_BACK/node_modules/@parcel/watcher/lib/child.js
generated
vendored
Executable file
61
BACK_BACK/node_modules/@parcel/watcher/lib/child.js
generated
vendored
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
"use strict";
|
||||
|
||||
const _require = require('chokidar'),
|
||||
FSWatcher = _require.FSWatcher;
|
||||
|
||||
const _require2 = require('@parcel/utils'),
|
||||
errorUtils = _require2.errorUtils;
|
||||
|
||||
const optionsTransfer = require('./options');
|
||||
|
||||
let watcher;
|
||||
|
||||
function sendEvent(event, path) {
|
||||
process.send({
|
||||
event: event,
|
||||
path: path
|
||||
});
|
||||
}
|
||||
|
||||
function handleError(e) {
|
||||
sendEvent('watcherError', errorUtils.errorToJson(e));
|
||||
}
|
||||
|
||||
function init(options) {
|
||||
options = optionsTransfer.decode(options);
|
||||
watcher = new FSWatcher(options);
|
||||
watcher.on('all', sendEvent);
|
||||
sendEvent('ready');
|
||||
}
|
||||
|
||||
function executeFunction(functionName, args) {
|
||||
try {
|
||||
watcher[functionName](...args);
|
||||
} catch (e) {
|
||||
handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
process.on('message', msg => {
|
||||
switch (msg.type) {
|
||||
case 'init':
|
||||
init(msg.options);
|
||||
break;
|
||||
|
||||
case 'function':
|
||||
executeFunction(msg.name, msg.args);
|
||||
break;
|
||||
|
||||
case 'die':
|
||||
process.exit();
|
||||
break;
|
||||
|
||||
case 'emulate_error':
|
||||
throw new Error('this is an emulated error');
|
||||
}
|
||||
});
|
||||
process.on('error', handleError);
|
||||
process.on('uncaughtException', handleError);
|
||||
process.on('disconnect', () => {
|
||||
process.exit();
|
||||
});
|
||||
66
BACK_BACK/node_modules/@parcel/watcher/lib/options.js
generated
vendored
Executable file
66
BACK_BACK/node_modules/@parcel/watcher/lib/options.js
generated
vendored
Executable file
|
|
@ -0,0 +1,66 @@
|
|||
"use strict";
|
||||
|
||||
function type(options) {
|
||||
return Object.prototype.toString.call(options).slice(8, -1);
|
||||
}
|
||||
|
||||
function encode(options) {
|
||||
if (options && options.ignored) {
|
||||
const ignoredType = type(options.ignored);
|
||||
|
||||
if (ignoredType !== 'Array') {
|
||||
options.ignored = [options.ignored];
|
||||
}
|
||||
|
||||
options.ignored.forEach((value, index) => {
|
||||
const valueType = type(value);
|
||||
|
||||
if (valueType === 'RegExp') {
|
||||
options.ignored[index] = value.source;
|
||||
|
||||
if (!options._regIndexs) {
|
||||
options._regIndexs = [];
|
||||
}
|
||||
|
||||
options._regIndexs.push(index);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
function decode(options) {
|
||||
if (options && options.ignored && options._regIndexs) {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = options._regIndexs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
let index = _step.value;
|
||||
options.ignored[index] = new RegExp(options.ignored[index]);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete options._regIndexs;
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
exports.encode = encode;
|
||||
exports.decode = decode;
|
||||
33
BACK_BACK/node_modules/@parcel/watcher/package.json
generated
vendored
Executable file
33
BACK_BACK/node_modules/@parcel/watcher/package.json
generated
vendored
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"name": "@parcel/watcher",
|
||||
"version": "1.12.1",
|
||||
"description": "Blazing fast, zero configuration web application bundler",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/parcel-bundler/parcel.git"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "cross-env NODE_ENV=test mocha",
|
||||
"test-ci": "yarn build && yarn test",
|
||||
"format": "prettier --write \"./{src,bin,test}/**/*.{js,json,md}\"",
|
||||
"lint": "eslint . && prettier \"./{src,bin,test}/**/*.{js,json,md}\" --list-different",
|
||||
"build": "babel src -d lib",
|
||||
"prepublish": "yarn build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@parcel/utils": "^1.11.0",
|
||||
"chokidar": "^2.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@parcel/babel-register": "^1.11.1",
|
||||
"@parcel/fs": "^1.11.0",
|
||||
"@parcel/test-utils": "^1.12.0",
|
||||
"mocha": "^5.2.0"
|
||||
},
|
||||
"gitHead": "d9ec7af22f85134dc1a97fe00f35950f2fe1f57a"
|
||||
}
|
||||
275
BACK_BACK/node_modules/@parcel/watcher/src/Watcher.js
generated
vendored
Executable file
275
BACK_BACK/node_modules/@parcel/watcher/src/Watcher.js
generated
vendored
Executable file
|
|
@ -0,0 +1,275 @@
|
|||
const fork = require('child_process').fork;
|
||||
const optionsTransfer = require('./options');
|
||||
const Path = require('path');
|
||||
const {EventEmitter} = require('events');
|
||||
const {errorUtils} = require('@parcel/utils');
|
||||
|
||||
/**
|
||||
* This watcher wraps chokidar so that we watch directories rather than individual files on macOS.
|
||||
* This prevents us from hitting EMFILE errors when running out of file descriptors.
|
||||
* Chokidar does not have support for watching directories on non-macOS platforms, so we disable
|
||||
* this behavior in order to prevent watching more individual files than necessary (e.g. node_modules).
|
||||
*/
|
||||
class Watcher extends EventEmitter {
|
||||
constructor(
|
||||
options = {
|
||||
// FS events on macOS are flakey in the tests, which write lots of files very quickly
|
||||
// See https://github.com/paulmillr/chokidar/issues/612
|
||||
useFsEvents:
|
||||
process.platform === 'darwin' && process.env.NODE_ENV !== 'test',
|
||||
ignoreInitial: true,
|
||||
ignorePermissionErrors: true,
|
||||
ignored: /(^|[/\\])\.(git|cache)/
|
||||
}
|
||||
) {
|
||||
super();
|
||||
this.options = optionsTransfer.encode(options);
|
||||
this.watchedPaths = new Set();
|
||||
this.child = null;
|
||||
this.ready = false;
|
||||
this.readyQueue = [];
|
||||
this.watchedDirectories = new Map();
|
||||
this.stopped = false;
|
||||
|
||||
this.on('ready', () => {
|
||||
this.ready = true;
|
||||
for (let func of this.readyQueue) {
|
||||
func();
|
||||
}
|
||||
this.readyQueue = [];
|
||||
});
|
||||
|
||||
this.startchild();
|
||||
}
|
||||
|
||||
startchild() {
|
||||
if (this.child) return;
|
||||
|
||||
let filteredArgs = process.execArgv.filter(
|
||||
v => !/^--(debug|inspect)/.test(v)
|
||||
);
|
||||
|
||||
let options = {
|
||||
execArgv: filteredArgs,
|
||||
env: process.env,
|
||||
cwd: process.cwd()
|
||||
};
|
||||
|
||||
this.child = fork(Path.join(__dirname, 'child'), process.argv, options);
|
||||
|
||||
if (this.watchedPaths.size > 0) {
|
||||
this.sendCommand('add', [Array.from(this.watchedPaths)]);
|
||||
}
|
||||
|
||||
this.child.send({
|
||||
type: 'init',
|
||||
options: this.options
|
||||
});
|
||||
|
||||
this.child.on('message', msg => this.handleEmit(msg.event, msg.path));
|
||||
this.child.on('error', () => {});
|
||||
this.child.on('exit', () => this.handleClosed());
|
||||
// this.child.on('close', () => this.handleClosed());
|
||||
}
|
||||
|
||||
handleClosed() {
|
||||
if (!this.stopped) {
|
||||
// Restart the child
|
||||
this.child = null;
|
||||
this.ready = false;
|
||||
this.startchild();
|
||||
}
|
||||
|
||||
this.emit('childDead');
|
||||
}
|
||||
|
||||
handleEmit(event, data) {
|
||||
if (event === 'watcherError') {
|
||||
data = errorUtils.jsonToError(data);
|
||||
}
|
||||
|
||||
this.emit(event, data);
|
||||
}
|
||||
|
||||
sendCommand(func, args) {
|
||||
if (!this.ready) {
|
||||
return this.readyQueue.push(() => this.sendCommand(func, args));
|
||||
}
|
||||
|
||||
this.child.send({
|
||||
type: 'function',
|
||||
name: func,
|
||||
args: args
|
||||
});
|
||||
}
|
||||
|
||||
_addPath(path) {
|
||||
if (!this.watchedPaths.has(path)) {
|
||||
this.watchedPaths.add(path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
add(paths) {
|
||||
let added = false;
|
||||
if (Array.isArray(paths)) {
|
||||
for (let path of paths) {
|
||||
added = !added ? this._addPath(path) : true;
|
||||
}
|
||||
} else {
|
||||
added = this._addPath(paths);
|
||||
}
|
||||
if (added) this.sendCommand('add', [paths]);
|
||||
}
|
||||
|
||||
_closePath(path) {
|
||||
if (this.watchedPaths.has(path)) {
|
||||
this.watchedPaths.delete(path);
|
||||
}
|
||||
this.sendCommand('_closePath', [path]);
|
||||
}
|
||||
|
||||
_emulateChildDead() {
|
||||
if (!this.child) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.child.send({
|
||||
type: 'die'
|
||||
});
|
||||
}
|
||||
|
||||
_emulateChildError() {
|
||||
if (!this.child) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.child.send({
|
||||
type: 'emulate_error'
|
||||
});
|
||||
}
|
||||
|
||||
getWatched() {
|
||||
let watchList = {};
|
||||
for (let path of this.watchedPaths) {
|
||||
let key = this.options.cwd ? Path.relative(this.options.cwd, path) : path;
|
||||
watchList[key || '.'] = [];
|
||||
}
|
||||
return watchList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a parent directory of `path` which is already watched
|
||||
*/
|
||||
getWatchedParent(path) {
|
||||
path = Path.dirname(path);
|
||||
|
||||
let root = Path.parse(path).root;
|
||||
while (path !== root) {
|
||||
if (this.watchedDirectories.has(path)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
path = Path.dirname(path);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a list of child directories of `path` which are already watched
|
||||
*/
|
||||
getWatchedChildren(path) {
|
||||
path = Path.dirname(path) + Path.sep;
|
||||
|
||||
let res = [];
|
||||
for (let dir of this.watchedDirectories.keys()) {
|
||||
if (dir.startsWith(path)) {
|
||||
res.push(dir);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path to the watcher
|
||||
*/
|
||||
watch(path) {
|
||||
if (this.shouldWatchDirs) {
|
||||
// If there is no parent directory already watching this path, add a new watcher.
|
||||
let parent = this.getWatchedParent(path);
|
||||
if (!parent) {
|
||||
// Find watchers on child directories, and remove them. They will be handled by the new parent watcher.
|
||||
let children = this.getWatchedChildren(path);
|
||||
let count = 1;
|
||||
|
||||
for (let dir of children) {
|
||||
count += this.watchedDirectories.get(dir);
|
||||
this._closePath(dir);
|
||||
this.watchedDirectories.delete(dir);
|
||||
}
|
||||
|
||||
let dir = Path.dirname(path);
|
||||
this.add(dir);
|
||||
this.watchedDirectories.set(dir, count);
|
||||
} else {
|
||||
// Otherwise, increment the reference count of the parent watcher.
|
||||
this.watchedDirectories.set(
|
||||
parent,
|
||||
this.watchedDirectories.get(parent) + 1
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
_unwatch(paths) {
|
||||
let removed = false;
|
||||
if (Array.isArray(paths)) {
|
||||
for (let p of paths) {
|
||||
removed = !removed ? this.watchedPaths.delete(p) : true;
|
||||
}
|
||||
} else {
|
||||
removed = this.watchedPaths.delete(paths);
|
||||
}
|
||||
if (removed) this.sendCommand('unwatch', [paths]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a path from the watcher
|
||||
*/
|
||||
unwatch(path) {
|
||||
if (this.shouldWatchDirs) {
|
||||
let dir = this.getWatchedParent(path);
|
||||
if (dir) {
|
||||
// When the count of files watching a directory reaches zero, unwatch it.
|
||||
let count = this.watchedDirectories.get(dir) - 1;
|
||||
if (count === 0) {
|
||||
this.watchedDirectories.delete(dir);
|
||||
this._unwatch(dir);
|
||||
} else {
|
||||
this.watchedDirectories.set(dir, count);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this._unwatch(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop watching all paths
|
||||
*/
|
||||
async stop() {
|
||||
this.stopped = true;
|
||||
|
||||
if (this.child) {
|
||||
this.child.kill();
|
||||
|
||||
return new Promise(resolve => this.once('childDead', resolve));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Watcher;
|
||||
52
BACK_BACK/node_modules/@parcel/watcher/src/child.js
generated
vendored
Executable file
52
BACK_BACK/node_modules/@parcel/watcher/src/child.js
generated
vendored
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
const {FSWatcher} = require('chokidar');
|
||||
const {errorUtils} = require('@parcel/utils');
|
||||
const optionsTransfer = require('./options');
|
||||
|
||||
let watcher;
|
||||
function sendEvent(event, path) {
|
||||
process.send({
|
||||
event: event,
|
||||
path: path
|
||||
});
|
||||
}
|
||||
|
||||
function handleError(e) {
|
||||
sendEvent('watcherError', errorUtils.errorToJson(e));
|
||||
}
|
||||
|
||||
function init(options) {
|
||||
options = optionsTransfer.decode(options);
|
||||
watcher = new FSWatcher(options);
|
||||
watcher.on('all', sendEvent);
|
||||
sendEvent('ready');
|
||||
}
|
||||
|
||||
function executeFunction(functionName, args) {
|
||||
try {
|
||||
watcher[functionName](...args);
|
||||
} catch (e) {
|
||||
handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
process.on('message', msg => {
|
||||
switch (msg.type) {
|
||||
case 'init':
|
||||
init(msg.options);
|
||||
break;
|
||||
case 'function':
|
||||
executeFunction(msg.name, msg.args);
|
||||
break;
|
||||
case 'die':
|
||||
process.exit();
|
||||
break;
|
||||
case 'emulate_error':
|
||||
throw new Error('this is an emulated error');
|
||||
}
|
||||
});
|
||||
|
||||
process.on('error', handleError);
|
||||
process.on('uncaughtException', handleError);
|
||||
process.on('disconnect', () => {
|
||||
process.exit();
|
||||
});
|
||||
39
BACK_BACK/node_modules/@parcel/watcher/src/options.js
generated
vendored
Executable file
39
BACK_BACK/node_modules/@parcel/watcher/src/options.js
generated
vendored
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
function type(options) {
|
||||
return Object.prototype.toString.call(options).slice(8, -1);
|
||||
}
|
||||
|
||||
function encode(options) {
|
||||
if (options && options.ignored) {
|
||||
const ignoredType = type(options.ignored);
|
||||
if (ignoredType !== 'Array') {
|
||||
options.ignored = [options.ignored];
|
||||
}
|
||||
|
||||
options.ignored.forEach((value, index) => {
|
||||
const valueType = type(value);
|
||||
if (valueType === 'RegExp') {
|
||||
options.ignored[index] = value.source;
|
||||
if (!options._regIndexs) {
|
||||
options._regIndexs = [];
|
||||
}
|
||||
options._regIndexs.push(index);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
function decode(options) {
|
||||
if (options && options.ignored && options._regIndexs) {
|
||||
for (let index of options._regIndexs) {
|
||||
options.ignored[index] = new RegExp(options.ignored[index]);
|
||||
}
|
||||
delete options._regIndexs;
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
exports.encode = encode;
|
||||
exports.decode = decode;
|
||||
8
BACK_BACK/node_modules/@parcel/watcher/test/.babelrc
generated
vendored
Executable file
8
BACK_BACK/node_modules/@parcel/watcher/test/.babelrc
generated
vendored
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"presets": [["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": "current"
|
||||
}
|
||||
}]],
|
||||
"plugins": ["@babel/plugin-transform-runtime"]
|
||||
}
|
||||
6
BACK_BACK/node_modules/@parcel/watcher/test/.eslintrc.json
generated
vendored
Executable file
6
BACK_BACK/node_modules/@parcel/watcher/test/.eslintrc.json
generated
vendored
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"extends": "../../../../.eslintrc.json",
|
||||
"env": {
|
||||
"mocha": true
|
||||
}
|
||||
}
|
||||
104
BACK_BACK/node_modules/@parcel/watcher/test/changeEvent.js
generated
vendored
Executable file
104
BACK_BACK/node_modules/@parcel/watcher/test/changeEvent.js
generated
vendored
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
const Watcher = require('../index');
|
||||
const fs = require('@parcel/fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
const {sleep} = require('@parcel/test-utils');
|
||||
|
||||
describe('change event', function() {
|
||||
let tmpFolder = path.join(__dirname, './tmp/');
|
||||
|
||||
before(() => {
|
||||
fs.mkdirp(tmpFolder);
|
||||
});
|
||||
|
||||
it('Should emit event on filechange', async () => {
|
||||
let watcher = new Watcher({});
|
||||
|
||||
let filepath = path.join(tmpFolder, 'file1.txt');
|
||||
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
|
||||
let changed = false;
|
||||
watcher.once('change', () => {
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert(changed, 'File should be flagged as changed.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
|
||||
it('Should emit event on filechange using arrays', async () => {
|
||||
let watcher = new Watcher({});
|
||||
|
||||
let filepath = path.join(tmpFolder, 'file1.txt');
|
||||
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add([filepath]);
|
||||
|
||||
let changed = false;
|
||||
watcher.once('change', () => {
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert(changed, 'File should be flagged as changed.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
|
||||
it('Should not emit event if file has been added and removed', async () => {
|
||||
let watcher = new Watcher({});
|
||||
|
||||
let filepath = path.join(tmpFolder, 'file1.txt');
|
||||
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
await sleep(250);
|
||||
|
||||
watcher.add(filepath);
|
||||
|
||||
let changed = false;
|
||||
watcher.once('change', () => {
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
watcher.unwatch(filepath);
|
||||
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert(!changed, 'Should not have emitted a change event.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
});
|
||||
84
BACK_BACK/node_modules/@parcel/watcher/test/errorHandling.js
generated
vendored
Executable file
84
BACK_BACK/node_modules/@parcel/watcher/test/errorHandling.js
generated
vendored
Executable file
|
|
@ -0,0 +1,84 @@
|
|||
const Watcher = require('../index');
|
||||
const fs = require('@parcel/fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
const {sleep} = require('@parcel/test-utils');
|
||||
|
||||
describe('error handling', function() {
|
||||
let tmpFolder = path.join(__dirname, './tmp/');
|
||||
|
||||
before(() => {
|
||||
fs.mkdirp(tmpFolder);
|
||||
});
|
||||
|
||||
it('Should restart child process if it dies', async () => {
|
||||
let watcher = new Watcher({});
|
||||
|
||||
let filepath = path.join(tmpFolder, 'file1.txt');
|
||||
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
|
||||
let changed = false;
|
||||
watcher.once('change', () => {
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
watcher._emulateChildDead();
|
||||
|
||||
await sleep(1000);
|
||||
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert(changed, 'Should have emitted a change event.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
|
||||
it('Should restart child process on errors', async () => {
|
||||
let watcher = new Watcher({});
|
||||
|
||||
let filepath = path.join(tmpFolder, 'file1.txt');
|
||||
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
|
||||
let hasThrown = false;
|
||||
watcher.on('watcherError', () => (hasThrown = true));
|
||||
|
||||
let changed = false;
|
||||
watcher.once('change', () => {
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
watcher._emulateChildError();
|
||||
|
||||
await sleep(1000);
|
||||
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert(changed, 'Should have emitted a change event.');
|
||||
|
||||
await watcher.stop();
|
||||
|
||||
assert(hasThrown, 'Should have emitted an error event.');
|
||||
});
|
||||
});
|
||||
31
BACK_BACK/node_modules/@parcel/watcher/test/fswatcher.js
generated
vendored
Executable file
31
BACK_BACK/node_modules/@parcel/watcher/test/fswatcher.js
generated
vendored
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
const Watcher = require('../index');
|
||||
const {sleep} = require('@parcel/test-utils');
|
||||
const assert = require('assert');
|
||||
|
||||
describe('Watcher', function() {
|
||||
it('Should be able to create a new watcher', async () => {
|
||||
let watcher = new Watcher();
|
||||
|
||||
assert(!!watcher.child);
|
||||
assert(!watcher.ready);
|
||||
|
||||
await sleep(1000);
|
||||
|
||||
assert(!!watcher.child);
|
||||
assert(watcher.ready);
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
|
||||
it('Should be able to properly destroy the watcher', async () => {
|
||||
let watcher = new Watcher();
|
||||
|
||||
await sleep(1000);
|
||||
|
||||
assert(!!watcher.child);
|
||||
assert(watcher.ready);
|
||||
|
||||
await watcher.stop();
|
||||
assert(watcher.child.killed);
|
||||
});
|
||||
});
|
||||
3
BACK_BACK/node_modules/@parcel/watcher/test/mocha.opts
generated
vendored
Executable file
3
BACK_BACK/node_modules/@parcel/watcher/test/mocha.opts
generated
vendored
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
--require @parcel/babel-register
|
||||
--timeout 10000
|
||||
--exit
|
||||
124
BACK_BACK/node_modules/@parcel/watcher/test/options.js
generated
vendored
Executable file
124
BACK_BACK/node_modules/@parcel/watcher/test/options.js
generated
vendored
Executable file
|
|
@ -0,0 +1,124 @@
|
|||
const Watcher = require('../index');
|
||||
const fs = require('@parcel/fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
const {sleep} = require('@parcel/test-utils');
|
||||
|
||||
describe('options', function() {
|
||||
let tmpFolder = path.join(__dirname, './tmp/');
|
||||
|
||||
before(() => {
|
||||
fs.mkdirp(tmpFolder);
|
||||
});
|
||||
|
||||
it('Should pass init options with correct ignored regex', async () => {
|
||||
let watcher = new Watcher({
|
||||
ignored: /file/
|
||||
});
|
||||
|
||||
let filepath = path.join(tmpFolder, 'file1.txt');
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
|
||||
let changed = false;
|
||||
watcher.once('change', () => {
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert(!changed, 'File should not be flagged as changed.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
|
||||
it('Should pass init options with a more complex ignored regex', async () => {
|
||||
let watcher = new Watcher({
|
||||
ignored: /file|config/
|
||||
});
|
||||
|
||||
let filepaths = [
|
||||
path.join(tmpFolder, 'file1.txt'),
|
||||
path.join(tmpFolder, 'config.json')
|
||||
];
|
||||
|
||||
for (let filepath of filepaths) {
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
}
|
||||
|
||||
let changed = false;
|
||||
watcher.once('change', () => {
|
||||
changed = true;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
for (let filepath of filepaths) {
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
}
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert(!changed, 'File should not be flagged as changed.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
|
||||
it('Should not ignore any files outside of the regex', async () => {
|
||||
let watcher = new Watcher({
|
||||
ignored: /file|config/
|
||||
});
|
||||
|
||||
let filepaths = [
|
||||
path.join(tmpFolder, 'file1.txt'),
|
||||
path.join(tmpFolder, 'config.json'),
|
||||
path.join(tmpFolder, 'something')
|
||||
];
|
||||
|
||||
for (let filepath of filepaths) {
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
}
|
||||
|
||||
let changed = 0;
|
||||
watcher.once('change', () => {
|
||||
changed++;
|
||||
});
|
||||
|
||||
if (!watcher.ready) {
|
||||
await new Promise(resolve => watcher.once('ready', resolve));
|
||||
}
|
||||
|
||||
await sleep(250);
|
||||
|
||||
for (let filepath of filepaths) {
|
||||
await fs.writeFile(filepath, 'this is not a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
}
|
||||
|
||||
await sleep(500);
|
||||
|
||||
assert.equal(changed, 1, 'One file should have changed once.');
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
});
|
||||
1
BACK_BACK/node_modules/@parcel/watcher/test/tmp/config.json
generated
vendored
Executable file
1
BACK_BACK/node_modules/@parcel/watcher/test/tmp/config.json
generated
vendored
Executable file
|
|
@ -0,0 +1 @@
|
|||
this is not a text document
|
||||
1
BACK_BACK/node_modules/@parcel/watcher/test/tmp/file1.txt
generated
vendored
Executable file
1
BACK_BACK/node_modules/@parcel/watcher/test/tmp/file1.txt
generated
vendored
Executable file
|
|
@ -0,0 +1 @@
|
|||
this is a text document
|
||||
1
BACK_BACK/node_modules/@parcel/watcher/test/tmp/something
generated
vendored
Executable file
1
BACK_BACK/node_modules/@parcel/watcher/test/tmp/something
generated
vendored
Executable file
|
|
@ -0,0 +1 @@
|
|||
this is not a text document
|
||||
28
BACK_BACK/node_modules/@parcel/watcher/test/watched.js
generated
vendored
Executable file
28
BACK_BACK/node_modules/@parcel/watcher/test/watched.js
generated
vendored
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
const Watcher = require('../index');
|
||||
const fs = require('@parcel/fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
describe('watched paths', function() {
|
||||
let tmpFolder = path.join(__dirname, './tmp/');
|
||||
|
||||
before(() => {
|
||||
fs.mkdirp(tmpFolder);
|
||||
});
|
||||
|
||||
it('Should return watched paths', async () => {
|
||||
let watcher = new Watcher({});
|
||||
|
||||
let filepath = path.join(tmpFolder, 'file1.txt');
|
||||
await fs.writeFile(filepath, 'this is a text document');
|
||||
|
||||
watcher.add(filepath);
|
||||
|
||||
assert(
|
||||
Object.keys(watcher.getWatched())[0] === filepath,
|
||||
'getWatched should return all the watched paths.'
|
||||
);
|
||||
|
||||
await watcher.stop();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue