mirror of
https://github.com/wassname/talk.git
synced 2026-07-03 07:11:27 +08:00
b9a8fdb77b
Merge pull request #1731 from coralproject/next-watcher-flags Watcher --only Use JSDocs comments (#1727) Merge branch 'next' into prevent-compile-loop-relay Merge pull request #1726 from coralproject/prevent-compile-loop-relay [next] Adapt relay watch config [next] Remove nodemon (#1725) * Remove old nodemon configs * Remove nodemon [next] Jest implementation for React Components (#1733) * Make jest testing work with custom path and css modules * Add first test * feat: added unit tests to ci * fix: updated package-lock.json * Update cssTransform.js * Update cssTransform.js * Fix test in ci Adapt files.exclude (#1736) Permalink ui Adding Copy to clipboard functionality WIP clean request wip progress progress work in progress wip ui functionality Translations :/ wip Merge branch 'permalink' of github.com:coralproject/talk into permalink * 'permalink' of github.com:coralproject/talk: (42 commits) [next] Support server side jest testing (#1747) Update snapshots Add comments Remove precss Move react-responsive to dev deps Remove comment Mobile first approach Support standard css variables, dynamically set spacing-unit Add docs Fully implement Flex and MatchMedia Responsive Components <3 fix: linting fix: adjusted pageInfo Remove obsoloe snapshot Move jsdom to dev deps Mark comments as always returning a value Add comment Fix unit tests Translate, concept for translation and id strings Add aria props ... Adding Attachment and Popover Component merge conflicts progress Any Working Support for refs Ready Merge branch 'permalink' of github.com:coralproject/talk into permalink * 'permalink' of github.com:coralproject/talk: (101 commits) Ready Support for refs Working Any progress merge conflicts Make timeagoFormatter optional More colors Colors Short circuit endless respawn fix: new mongo parser Remove jest from watcher config, as it doesnt run well inside Add jest set Apply suggestions Move react-timeago to dev Upgrade docz Cleanup docz scripts Support watcher sets [next] Support server side jest testing (#1747) Make filter only a pure function ...
102 lines
2.6 KiB
TypeScript
102 lines
2.6 KiB
TypeScript
import chalk from "chalk";
|
|
import { execSync } from "child_process";
|
|
import sane from "sane";
|
|
|
|
import { Watcher, WatchOptions } from "./types";
|
|
|
|
interface SaneWatcherOptions {
|
|
/**
|
|
* Set to true to use watchman, false to disabled, and undefined
|
|
* for automatic detection.
|
|
*/
|
|
watchman?: boolean;
|
|
/** Use polling, this might be required for network file systems. */
|
|
poll?: boolean;
|
|
}
|
|
|
|
function canUseWatchman(): boolean {
|
|
try {
|
|
execSync("watchman --version", { stdio: ["ignore"] });
|
|
return true;
|
|
// tslint:disable-next-line:no-empty
|
|
} catch (e) {}
|
|
return false;
|
|
}
|
|
|
|
export default class SaneWatcher implements Watcher {
|
|
private watchman?: boolean;
|
|
private poll: boolean;
|
|
|
|
constructor(options: SaneWatcherOptions = {}) {
|
|
this.watchman = options.watchman;
|
|
this.poll = options.poll || false;
|
|
|
|
// Autodetect watchman.
|
|
if (this.watchman === undefined && canUseWatchman()) {
|
|
this.watchman = true;
|
|
// tslint:disable-next-line:no-console
|
|
console.log(chalk.grey(`Watchman detected`));
|
|
}
|
|
}
|
|
|
|
public watch(
|
|
rootDir: string,
|
|
paths: ReadonlyArray<string>,
|
|
options: WatchOptions = {}
|
|
): AsyncIterable<string> {
|
|
// An array to hold all changes, that has not yet been yield.
|
|
const queue: string[] = [];
|
|
|
|
// If this is set, a pending promise is waiting for the next result.
|
|
let pending: ({ resolve: (result: string) => void }) | null = null;
|
|
|
|
// Only start client if we have something to watch.
|
|
if (paths.length) {
|
|
// Setup client
|
|
const client = sane(rootDir, {
|
|
glob: paths as string[],
|
|
ignored: options.ignore as string[],
|
|
watchman: this.watchman,
|
|
poll: this.poll,
|
|
});
|
|
|
|
// Listen for changes
|
|
client.on("change", (pathFile: string) => {
|
|
// Resolve pending request.
|
|
if (pending) {
|
|
pending.resolve(pathFile);
|
|
pending = null;
|
|
return;
|
|
}
|
|
|
|
// There is no pending request, save it into the queue.
|
|
queue.unshift(pathFile);
|
|
});
|
|
}
|
|
|
|
return {
|
|
[Symbol.asyncIterator]() {
|
|
return {
|
|
next: () =>
|
|
new Promise<IteratorResult<string>>((resolve, reject) => {
|
|
const wrapped = {
|
|
resolve: (pathFile: string) =>
|
|
resolve({
|
|
done: false,
|
|
value: pathFile,
|
|
}),
|
|
};
|
|
|
|
if (queue.length) {
|
|
wrapped.resolve(queue.pop()!);
|
|
return;
|
|
}
|
|
// We need to wait for the next change event.
|
|
pending = wrapped;
|
|
}),
|
|
};
|
|
},
|
|
};
|
|
}
|
|
}
|