Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix watch mode when using presets #2072

Merged
merged 1 commit into from Jul 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/graphql-codegen-cli/src/utils/watcher.ts
Expand Up @@ -6,6 +6,7 @@ import * as isGlob from 'is-glob';
import * as logSymbols from 'log-symbols';
import { debugLog } from './debugging';
import { getLogger } from './logger';
import path from 'path';

function log(msg: string) {
// double spaces to inline the message with Listr
Expand Down Expand Up @@ -56,6 +57,20 @@ export const createWatcher = (config: Types.Config, onNext: (result: Types.FileO
const chokidar = await import('chokidar');
emitWatching();

const ignored: string[] = [];
Object.keys(config.generates)
.map(filename => ({ filename, config: normalizeOutputParam(config.generates[filename]) }))
.forEach(entry => {
if (entry.config.preset) {
const extension = entry.config.presetConfig && entry.config.presetConfig.extension;
if (extension) {
ignored.push(path.join(entry.filename, '**', '*' + extension));
}
} else {
ignored.push(entry.filename);
}
});

watcher = chokidar.watch(files, {
persistent: true,
ignoreInitial: true,
Expand All @@ -69,7 +84,7 @@ export const createWatcher = (config: Types.Config, onNext: (result: Types.FileO
awaitWriteFinish: true,
ignorePermissionErrors: false,
atomic: true,
ignored: Object.keys(config.generates),
ignored,
});

debugLog(`[Watcher] Started`);
Expand Down