fix(core): pass the list of ingored files to parcel watcher
This commit is contained in:
parent
9c77096b15
commit
a78d43189a
@ -278,6 +278,7 @@ export async function startServer(): Promise<Server> {
|
|||||||
|
|
||||||
if (!watcherSubscription) {
|
if (!watcherSubscription) {
|
||||||
watcherSubscription = await subscribeToWorkspaceChanges(
|
watcherSubscription = await subscribeToWorkspaceChanges(
|
||||||
|
server,
|
||||||
handleWorkspaceChanges
|
handleWorkspaceChanges
|
||||||
);
|
);
|
||||||
serverLogger.watcherLog(
|
serverLogger.watcherLog(
|
||||||
|
|||||||
@ -9,9 +9,11 @@ import { normalizePath } from '@nrwl/devkit';
|
|||||||
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
|
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
|
||||||
import type { AsyncSubscription, Event } from '@parcel/watcher';
|
import type { AsyncSubscription, Event } from '@parcel/watcher';
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import ignore from 'ignore';
|
|
||||||
import { join, relative } from 'path';
|
import { join, relative } from 'path';
|
||||||
import { FULL_OS_SOCKET_PATH } from '../socket-utils';
|
import { FULL_OS_SOCKET_PATH } from '../socket-utils';
|
||||||
|
import { serverLogger } from '@nrwl/workspace/src/core/project-graph/daemon/server/logger';
|
||||||
|
import { handleServerProcessTermination } from '@nrwl/workspace/src/core/project-graph/daemon/server/shutdown-utils';
|
||||||
|
import { Server } from 'net';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This configures the files and directories which we always want to ignore as part of file watching
|
* This configures the files and directories which we always want to ignore as part of file watching
|
||||||
@ -27,24 +29,28 @@ import { FULL_OS_SOCKET_PATH } from '../socket-utils';
|
|||||||
*/
|
*/
|
||||||
const ALWAYS_IGNORE = [
|
const ALWAYS_IGNORE = [
|
||||||
join(appRootPath, 'node_modules'),
|
join(appRootPath, 'node_modules'),
|
||||||
join(appRootPath, 'dist'),
|
|
||||||
join(appRootPath, '.git'),
|
join(appRootPath, '.git'),
|
||||||
FULL_OS_SOCKET_PATH,
|
FULL_OS_SOCKET_PATH,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
function getIgnoredGlobs() {
|
||||||
* TODO: This utility has been implemented multiple times across the Nx codebase,
|
return [
|
||||||
* discuss whether it should be moved to a shared location.
|
...ALWAYS_IGNORE,
|
||||||
*/
|
...getIgnoredGlobsFromFile(join(appRootPath, '.nxignore')),
|
||||||
function getIgnoredGlobs(root: string) {
|
...getIgnoredGlobsFromFile(join(appRootPath, '.gitignore')),
|
||||||
const ig = ignore();
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIgnoredGlobsFromFile(file: string): string[] {
|
||||||
try {
|
try {
|
||||||
ig.add(readFileSync(`${root}/.gitignore`, 'utf-8'));
|
return readFileSync(file, 'utf-8')
|
||||||
} catch {}
|
.split('\n')
|
||||||
try {
|
.map((i) => i.trim())
|
||||||
ig.add(readFileSync(`${root}/.nxignore`, 'utf-8'));
|
.filter((i) => !!i && !i.startsWith('#'))
|
||||||
} catch {}
|
.map((i) => (i.startsWith('/') ? join(appRootPath, i) : i));
|
||||||
return ig;
|
} catch (e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WatcherSubscription = AsyncSubscription;
|
export type WatcherSubscription = AsyncSubscription;
|
||||||
@ -54,6 +60,7 @@ export type SubscribeToWorkspaceChangesCallback = (
|
|||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
|
|
||||||
export async function subscribeToWorkspaceChanges(
|
export async function subscribeToWorkspaceChanges(
|
||||||
|
server: Server,
|
||||||
cb: SubscribeToWorkspaceChangesCallback
|
cb: SubscribeToWorkspaceChangesCallback
|
||||||
): Promise<AsyncSubscription> {
|
): Promise<AsyncSubscription> {
|
||||||
/**
|
/**
|
||||||
@ -63,8 +70,6 @@ export async function subscribeToWorkspaceChanges(
|
|||||||
*/
|
*/
|
||||||
const watcher = await import('@parcel/watcher');
|
const watcher = await import('@parcel/watcher');
|
||||||
|
|
||||||
let cachedIgnoreGlobs = getIgnoredGlobs(appRootPath);
|
|
||||||
|
|
||||||
const subscription = await watcher.subscribe(
|
const subscription = await watcher.subscribe(
|
||||||
appRootPath,
|
appRootPath,
|
||||||
(err, events) => {
|
(err, events) => {
|
||||||
@ -93,21 +98,17 @@ export async function subscribeToWorkspaceChanges(
|
|||||||
|
|
||||||
// If the ignore files themselves have changed we need to dynamically update our cached ignoreGlobs
|
// If the ignore files themselves have changed we need to dynamically update our cached ignoreGlobs
|
||||||
if (hasIgnoreFileUpdate) {
|
if (hasIgnoreFileUpdate) {
|
||||||
cachedIgnoreGlobs = getIgnoredGlobs(appRootPath);
|
handleServerProcessTermination({
|
||||||
|
server,
|
||||||
|
reason: 'Stopping the daemon the set of ignored files changed.',
|
||||||
|
watcherSubscription: subscription,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const nonIgnoredEvents = workspaceRelativeEvents
|
cb(null, workspaceRelativeEvents);
|
||||||
.filter(({ path }) => !!path)
|
|
||||||
.filter(({ path }) => !cachedIgnoreGlobs.ignores(path));
|
|
||||||
|
|
||||||
if (!nonIgnoredEvents || !nonIgnoredEvents.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cb(null, nonIgnoredEvents);
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ignore: ALWAYS_IGNORE,
|
ignore: getIgnoredGlobs(),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user