Skip to content

Commit

Permalink
Issue/vcs toggle vcs modes (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
pancaspe87 authored Feb 21, 2025
1 parent cbcb436 commit e962cd7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-teachers-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@atlaspack/feature-flags': minor
---

Introduced new method to return feature flag value
5 changes: 5 additions & 0 deletions .changeset/rude-keys-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@atlaspack/fs': minor
---

Introduced ability to toggle vcs mode under a flag
7 changes: 7 additions & 0 deletions packages/core/feature-flags/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
fixQuadraticCacheInvalidation: 'OLD',
useLmdbJsLite: false,
conditionalBundlingApi: false,
vcsMode: 'OLD',
};

let featureFlagValues: FeatureFlags = {...DEFAULT_FEATURE_FLAGS};
Expand All @@ -27,6 +28,12 @@ export function getFeatureFlag(flagName: $Keys<FeatureFlags>): boolean {
return value === true || value === 'NEW';
}

export function getFeatureFlagValue(
flagName: $Keys<FeatureFlags>,
): boolean | string | number {
return featureFlagValues[flagName];
}

export type DiffResult<CustomDiagnostic> = {|
isDifferent: boolean,
custom: CustomDiagnostic,
Expand Down
7 changes: 7 additions & 0 deletions packages/core/feature-flags/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export type FeatureFlags = {|
* and requires server-side support.
*/
conditionalBundlingApi: boolean,
/**
* Enable VCS mode. Expected values are:
* - OLD - default value, return watchman result
* - NEW_AND_CHECK - Return VCS result but still call watchman
* - NEW: Return VCS result, but don't call watchman
*/
vcsMode: ConsistencyCheckFeatureFlagValue,
|};

export type ConsistencyCheckFeatureFlagValue =
Expand Down
29 changes: 21 additions & 8 deletions packages/core/fs/src/NodeVCSAwareFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {FilePath} from '@atlaspack/types-internal';
import type {Event, Options as WatcherOptions} from '@parcel/watcher';
import {registerSerializableClass} from '@atlaspack/build-cache';
import {instrument, instrumentAsync} from '@atlaspack/logger';
import {getFeatureFlagValue} from '@atlaspack/feature-flags';

// $FlowFixMe
import packageJSON from '../package.json';
Expand Down Expand Up @@ -34,16 +35,27 @@ export class NodeVCSAwareFS extends NodeFS {
const snapshotFile = await this.readFile(snapshot);
const snapshotFileContent = snapshotFile.toString();
const {nativeSnapshotPath, vcsState} = JSON.parse(snapshotFileContent);
let watcherEventsSince = [];

const watcherEventsSince = await instrumentAsync(
'NodeVCSAwareFS::watchman.getEventsSince',
() => this.watcher().getEventsSince(dir, nativeSnapshotPath, opts),
);
const vcsEventsSince = instrument(
'NodeVCSAwareFS::rust.getEventsSince',
() => getEventsSince(this.#options.gitRepoPath, vcsState.gitHash),
).map((e) => ({path: e.path, type: e.changeType}));
this.#options.logEventDiff(watcherEventsSince, vcsEventsSince);
).map((e) => ({
path: e.path,
type: e.changeType,
}));

if (getFeatureFlagValue('vcsMode') !== 'NEW') {
watcherEventsSince = await instrumentAsync(
'NodeVCSAwareFS::watchman.getEventsSince',
() => this.watcher().getEventsSince(dir, nativeSnapshotPath, opts),
);
this.#options.logEventDiff(watcherEventsSince, vcsEventsSince);
}

if (['NEW_AND_CHECK', 'NEW'].includes(getFeatureFlagValue('vcsMode'))) {
return vcsEventsSince;
}

return watcherEventsSince;
}
Expand All @@ -59,9 +71,10 @@ export class NodeVCSAwareFS extends NodeFS {
snapshotDirectory,
`${filename}.native-snapshot.txt`,
);
await this.watcher().writeSnapshot(dir, nativeSnapshotPath, opts);
if (getFeatureFlagValue('vcsMode') !== 'NEW') {
await this.watcher().writeSnapshot(dir, nativeSnapshotPath, opts);
}

// TODO: we need the git repo path, pass the exclude patterns
const vcsState = await getVcsStateSnapshot(
this.#options.gitRepoPath,
this.#options.excludePatterns,
Expand Down

0 comments on commit e962cd7

Please sign in to comment.