Compare commits

...

4 Commits

Author SHA1 Message Date
Rich Harris
b1a9be2dc3 -> v0.17.0 2018-08-19 22:07:04 -04:00
Rich Harris
c5456d3033 Merge pull request #365 from sveltejs/cheap-watch
Use cheap-watch
2018-08-19 22:05:33 -04:00
Rich Harris
9b33dad589 merge master -> cheap-watch 2018-08-19 19:03:12 -04:00
Rich Harris
f9bf23dc43 use cheap-watch instead of chokidar (#364) 2018-08-19 18:52:01 -04:00
4 changed files with 319 additions and 86 deletions

View File

@@ -1,5 +1,9 @@
# sapper changelog # sapper changelog
## 0.17.0
* Use `cheap-watch` instead of `chokidar` ([#364](https://github.com/sveltejs/sapper/issues/364))
## 0.16.1 ## 0.16.1
* Fix file watching regression in previous version * Fix file watching regression in previous version

333
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "sapper", "name": "sapper",
"version": "0.16.1", "version": "0.17.0",
"description": "Military-grade apps, engineered by Svelte", "description": "Military-grade apps, engineered by Svelte",
"main": "dist/middleware.ts.js", "main": "dist/middleware.ts.js",
"bin": { "bin": {
@@ -19,7 +19,6 @@
"test": "test" "test": "test"
}, },
"dependencies": { "dependencies": {
"chokidar": "^2.0.4",
"html-minifier": "^3.5.16", "html-minifier": "^3.5.16",
"source-map-support": "^0.5.6", "source-map-support": "^0.5.6",
"tslib": "^1.9.1" "tslib": "^1.9.1"
@@ -30,6 +29,7 @@
"@types/mocha": "^5.2.5", "@types/mocha": "^5.2.5",
"@types/node": "^10.7.1", "@types/node": "^10.7.1",
"@types/rimraf": "^2.0.2", "@types/rimraf": "^2.0.2",
"cheap-watch": "^0.3.0",
"compression": "^1.7.1", "compression": "^1.7.1",
"cookie": "^0.3.1", "cookie": "^0.3.1",
"devalue": "^1.0.4", "devalue": "^1.0.4",

View File

@@ -119,21 +119,30 @@ class Watcher extends EventEmitter {
this.dev_server = new DevServer(dev_port); this.dev_server = new DevServer(dev_port);
this.filewatchers.push( this.filewatchers.push(
watch_files(locations.routes(), ['add', 'unlink'], () => { watch_dir(
const routes = create_routes(); locations.routes(),
create_main_manifests({ routes, dev_port }); ({ path: file, stats }) => {
if (stats.isDirectory()) {
try { return path.basename(file)[0] !== '_';
}
return true;
},
() => {
const routes = create_routes(); const routes = create_routes();
create_main_manifests({ routes, dev_port }); create_main_manifests({ routes, dev_port });
} catch (err) {
this.emit('error', <events.ErrorEvent>{
message: err.message
});
}
}),
watch_files(`${locations.app()}/template.html`, ['change'], () => { try {
const routes = create_routes();
create_main_manifests({ routes, dev_port });
} catch (err) {
this.emit('error', <events.ErrorEvent>{
message: err.message
});
}
}
),
fs.watch(`${locations.app()}/template.html`, () => {
this.dev_server.send({ this.dev_server.send({
action: 'reload' action: 'reload'
}); });
@@ -453,25 +462,32 @@ class DevServer {
function noop() {} function noop() {}
function watch_files(pattern: string, events: string[], callback: () => void) { function watch_dir(
let watcher; dir: string,
filter: ({ path, stats }: { path: string, stats: fs.Stats }) => boolean,
callback: () => void
) {
let watch;
let closed = false; let closed = false;
import('chokidar').then((chokidar) => { import('cheap-watch').then(CheapWatch => {
if (closed) return; if (closed) return;
watcher = chokidar.watch(pattern, { watch = new CheapWatch({ dir, filter, debounce: 50 });
persistent: true,
ignoreInitial: true, watch.on('+', ({ isNew }) => {
disableGlobbing: true if (isNew) callback();
}); });
events.forEach(event => { watch.on('-', callback);
watcher.on(event, callback);
}); watch.init();
}); });
return { return {
close: () => watcher && watcher.close() close: () => {
if (watch) watch.close();
closed = true;
}
}; };
} }