Skip to content

Commit e9bf419

Browse files
authored
Expose watcher ignore and watcher backend options (#9547)
1 parent 81ef511 commit e9bf419

File tree

6 files changed

+60
-8
lines changed

6 files changed

+60
-8
lines changed

packages/core/core/src/RequestTracker.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -1289,17 +1289,24 @@ export default class RequestTracker {
12891289
}
12901290
}
12911291

1292-
export function getWatcherOptions(options: ParcelOptions): WatcherOptions {
1293-
let vcsDirs = ['.git', '.hg'].map(dir => path.join(options.projectRoot, dir));
1294-
let ignore = [options.cacheDir, ...vcsDirs];
1295-
return {ignore};
1292+
export function getWatcherOptions({
1293+
watchIgnore = [],
1294+
cacheDir,
1295+
projectRoot,
1296+
watchBackend,
1297+
}: ParcelOptions): WatcherOptions {
1298+
const vcsDirs = ['.git', '.hg'];
1299+
const uniqueDirs = [...new Set([...watchIgnore, ...vcsDirs, cacheDir])];
1300+
const ignore = uniqueDirs.map(dir => path.join(projectRoot, dir));
1301+
1302+
return {ignore, backend: watchBackend};
12961303
}
12971304

12981305
function getCacheKey(options) {
12991306
return hashString(
13001307
`${PARCEL_VERSION}:${JSON.stringify(options.entries)}:${options.mode}:${
13011308
options.shouldBuildLazily ? 'lazy' : 'eager'
1302-
}`,
1309+
}:${options.watchBackend ?? ''}`,
13031310
);
13041311
}
13051312

packages/core/core/src/resolveOptions.js

+2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ export default async function resolveOptions(
191191
shouldTrace: initialOptions.shouldTrace ?? false,
192192
cacheDir,
193193
watchDir,
194+
watchBackend: initialOptions.watchBackend,
195+
watchIgnore: initialOptions.watchIgnore,
194196
entries: entries.map(e => toProjectPath(projectRoot, e)),
195197
targets: initialOptions.targets,
196198
logLevel: initialOptions.logLevel ?? 'info',

packages/core/core/src/types.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {PackageManager} from '@parcel/package-manager';
3333
import type {ProjectPath} from './projectPath';
3434
import type {EventType} from '@parcel/watcher';
3535
import type {FeatureFlags} from '@parcel/feature-flags';
36+
import type {BackendType} from '@parcel/watcher';
3637

3738
export type ParcelPluginNode = {|
3839
packageName: PackageName,
@@ -266,16 +267,19 @@ export type DevDepRequest = {|
266267
|}>,
267268
|};
268269

270+
declare type GlobPattern = string;
271+
269272
export type ParcelOptions = {|
270273
entries: Array<ProjectPath>,
271274
config?: DependencySpecifier,
272275
defaultConfig?: DependencySpecifier,
273276
env: EnvMap,
274277
targets: ?(Array<string> | {+[string]: TargetDescriptor, ...}),
275-
276278
shouldDisableCache: boolean,
277279
cacheDir: FilePath,
278280
watchDir: FilePath,
281+
watchIgnore?: Array<FilePath | GlobPattern>,
282+
watchBackend?: BackendType,
279283
mode: BuildMode,
280284
hmrOptions: ?HMROptions,
281285
shouldContentHash: boolean,

packages/core/core/test/test-utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ cache.ensure();
1818
export const DEFAULT_OPTIONS: ParcelOptions = {
1919
cacheDir: path.join(__dirname, '.parcel-cache'),
2020
watchDir: __dirname,
21+
watchIgnore: undefined,
22+
watchBackend: undefined,
2123
entries: [],
2224
logLevel: 'info',
2325
targets: undefined,

packages/core/parcel/src/cli.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,46 @@ process.on('unhandledRejection', handleUncaughtException);
6666
program.storeOptionsAsProperties();
6767
program.version(version);
6868

69+
// Only display choices available to callers OS
70+
let watcherBackendChoices = ['brute-force'];
71+
switch (process.platform) {
72+
case 'darwin': {
73+
watcherBackendChoices.push('watchman', 'fs-events');
74+
break;
75+
}
76+
case 'linux': {
77+
watcherBackendChoices.push('watchman', 'inotify');
78+
break;
79+
}
80+
case 'win32': {
81+
watcherBackendChoices.push('watchman', 'windows');
82+
break;
83+
}
84+
case 'freebsd' || 'openbsd': {
85+
watcherBackendChoices.push('watchman');
86+
break;
87+
}
88+
default:
89+
break;
90+
}
91+
6992
// --no-cache, --cache-dir, --no-source-maps, --no-autoinstall, --global?, --public-url, --log-level
7093
// --no-content-hash, --experimental-scope-hoisting, --detailed-report
71-
7294
const commonOptions = {
7395
'--no-cache': 'disable the filesystem cache',
7496
'--config <path>':
7597
'specify which config to use. can be a path or a package name',
7698
'--cache-dir <path>': 'set the cache directory. defaults to ".parcel-cache"',
7799
'--watch-dir <path>':
78100
'set the root watch directory. defaults to nearest lockfile or source control dir.',
101+
'--watch-ignore [path]': [
102+
`list of directories watcher should not be tracking for changes. defaults to ['.git', '.hg']`,
103+
dirs => dirs.split(','),
104+
],
105+
'--watch-backend': new commander.Option(
106+
'--watch-backend <name>',
107+
'set watcher backend',
108+
).choices(watcherBackendChoices),
79109
'--no-source-maps': 'disable sourcemaps',
80110
'--target [name]': [
81111
'only build given target(s)',
@@ -497,10 +527,13 @@ async function normalizeOptions(
497527
if (typeof input !== 'string') return [];
498528
return input.split(',').map(value => value.trim());
499529
};
530+
500531
return {
501532
shouldDisableCache: command.cache === false,
502533
cacheDir: command.cacheDir,
503534
watchDir: command.watchDir,
535+
watchBackend: command.watchBackend,
536+
watchIgnore: command.watchIgnore,
504537
config: command.config,
505538
mode,
506539
hmrOptions,

packages/core/types/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import type {Cache} from '@parcel/cache';
1414

1515
import type {AST as _AST, ConfigResult as _ConfigResult} from './unsafe';
1616
import type {TraceMeasurement} from '@parcel/profiler';
17-
import type {EventType} from '@parcel/watcher';
1817
import type {FeatureFlags} from '@parcel/feature-flags';
18+
import type {EventType, BackendType} from '@parcel/watcher';
1919

2020
/** Plugin-specific AST, <code>any</code> */
2121
export type AST = _AST;
@@ -286,6 +286,8 @@ export type DetailedReportOptions = {|
286286
assetsPerBundle?: number,
287287
|};
288288

289+
declare type GlobPattern = string;
290+
289291
export type InitialParcelOptions = {|
290292
+entries?: FilePath | Array<FilePath>,
291293
+config?: DependencySpecifier,
@@ -296,6 +298,8 @@ export type InitialParcelOptions = {|
296298
+shouldDisableCache?: boolean,
297299
+cacheDir?: FilePath,
298300
+watchDir?: FilePath,
301+
+watchBackend?: BackendType,
302+
+watchIgnore?: Array<FilePath | GlobPattern>,
299303
+mode?: BuildMode,
300304
+hmrOptions?: ?HMROptions,
301305
+shouldContentHash?: boolean,

0 commit comments

Comments
 (0)