Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gorakong committed Jul 27, 2021
1 parent 908337f commit 3aa5391
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
8 changes: 2 additions & 6 deletions packages/core/core/src/Parcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default class Parcel {
#requestTracker /*: RequestTracker*/;
#config /*: ParcelConfig*/;
#farm /*: WorkerFarm*/;
#isInitialBuild /*: boolean*/ = true;
#initialized /*: boolean*/ = false;
#disposable /*: Disposable */;
#initialOptions /*: InitialParcelOptions*/;
Expand Down Expand Up @@ -300,7 +299,7 @@ export default class Parcel {
options,
),
buildTime: Date.now() - startTime,
requestBundle: async bundle => {
requestBundle: async (bundle) => {
let bundleNode = bundleGraph._graph.getNodeByContentKey(bundle.id);
invariant(bundleNode?.type === 'bundle', 'Bundle does not exist');

Expand Down Expand Up @@ -378,18 +377,15 @@ export default class Parcel {
}

let isInvalid = this.#requestTracker.respondToFSEvents(
events.map(e => ({
events.map((e) => ({
type: e.type,
path: toProjectPath(resolvedOptions.projectRoot, e.path),
})),
{isInitialBuild: this.#isInitialBuild},
);
if (isInvalid && this.#watchQueue.getNumWaiting() === 0) {
if (this.#watchAbortController) {
this.#watchAbortController.abort();
}

this.#isInitialBuild = false;
this.#watchQueue.add(() => this._startNextBuild());
this.#watchQueue.run();
}
Expand Down
44 changes: 23 additions & 21 deletions packages/core/core/src/RequestTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ type RequestGraphEdgeType =
| 'dirname';

export type RunAPI = {|
invalidateOnFileCreate: InternalFileCreateInvalidation => void,
invalidateOnFileDelete: ProjectPath => void,
invalidateOnFileUpdate: ProjectPath => void,
invalidateOnFileCreate: (InternalFileCreateInvalidation) => void,
invalidateOnFileDelete: (ProjectPath) => void,
invalidateOnFileUpdate: (ProjectPath) => void,
invalidateOnStartup: () => void,
invalidateOnEnvChange: string => void,
invalidateOnOptionChange: string => void,
invalidateOnEnvChange: (string) => void,
invalidateOnOptionChange: (string) => void,
getInvalidations(): Array<RequestInvalidation>,
storeResult: (result: mixed, cacheKey?: string) => void,
getRequestResult<T>(contentKey: ContentKey): Async<?T>,
Expand Down Expand Up @@ -469,7 +469,7 @@ export class RequestGraph extends ContentGraph<
'invalidated_by_update',
);
return invalidations
.map(nodeId => {
.map((nodeId) => {
let node = nullthrows(this.getNode(nodeId));
switch (node.type) {
case 'file':
Expand All @@ -490,7 +490,7 @@ export class RequestGraph extends ContentGraph<

let subRequests = this.getNodeIdsConnectedFrom(requestNodeId, 'subrequest');

return subRequests.map(nodeId => {
return subRequests.map((nodeId) => {
let node = nullthrows(this.getNode(nodeId));
invariant(node.type === 'request');
return node.value;
Expand Down Expand Up @@ -548,7 +548,7 @@ export class RequestGraph extends ContentGraph<

respondToFSEvents(
events: Array<{|path: ProjectPath, type: EventType|}>,
opts: {|isInitialBuild: boolean|},
opts?: {|isInitialBuild: boolean|},
): boolean {
let didInvalidate = false;
for (let {path: _filePath, type} of events) {
Expand All @@ -558,7 +558,7 @@ export class RequestGraph extends ContentGraph<
// If we see a 'create' event for the project root itself,
// this means the project root was moved and we need to
// re-run all requests.
if (opts.isInitialBuild && type === 'create' && filePath === '') {
if (opts?.isInitialBuild && type === 'create' && filePath === '') {
for (let [id, node] of this.nodes) {
if (node.type === 'request') {
this.invalidNodeIds.add(id);
Expand Down Expand Up @@ -600,7 +600,7 @@ export class RequestGraph extends ContentGraph<
let above = this.getNodeIdsConnectedTo(
fileNameNodeId,
'invalidated_by_create_above',
).map(nodeId => {
).map((nodeId) => {
let node = nullthrows(this.getNode(nodeId));
invariant(node.type === 'file');
return node;
Expand Down Expand Up @@ -653,6 +653,7 @@ export default class RequestTracker {
farm: WorkerFarm;
options: ParcelOptions;
signal: ?AbortSignal;
isInitialBuild: boolean;

constructor({
graph,
Expand Down Expand Up @@ -760,9 +761,8 @@ export default class RequestTracker {

respondToFSEvents(
events: Array<{|path: ProjectPath, type: EventType|}>,
opts: {|isInitialBuild: boolean|},
): boolean {
return this.graph.respondToFSEvents(events, opts);
return this.graph.respondToFSEvents(events);
}

hasInvalidRequests(): boolean {
Expand Down Expand Up @@ -858,16 +858,16 @@ export default class RequestTracker {
): {|api: RunAPI, subRequestContentKeys: Set<ContentKey>|} {
let subRequestContentKeys = new Set<ContentKey>();
let api: RunAPI = {
invalidateOnFileCreate: input =>
invalidateOnFileCreate: (input) =>
this.graph.invalidateOnFileCreate(requestId, input),
invalidateOnFileDelete: filePath =>
invalidateOnFileDelete: (filePath) =>
this.graph.invalidateOnFileDelete(requestId, filePath),
invalidateOnFileUpdate: filePath =>
invalidateOnFileUpdate: (filePath) =>
this.graph.invalidateOnFileUpdate(requestId, filePath),
invalidateOnStartup: () => this.graph.invalidateOnStartup(requestId),
invalidateOnEnvChange: env =>
invalidateOnEnvChange: (env) =>
this.graph.invalidateOnEnvChange(requestId, env, this.options.env[env]),
invalidateOnOptionChange: option =>
invalidateOnOptionChange: (option) =>
this.graph.invalidateOnOptionChange(
requestId,
option,
Expand All @@ -883,7 +883,7 @@ export default class RequestTracker {
return this.getRequestResult<T>(contentKey, ifMatch);
},
getRequestResult: <T>(id): Async<?T> => this.getRequestResult<T>(id),
canSkipSubrequest: contentKey => {
canSkipSubrequest: (contentKey) => {
if (
this.graph.hasContentKey(contentKey) &&
this.hasValidResult(this.graph.getNodeIdByContentKey(contentKey))
Expand Down Expand Up @@ -958,7 +958,9 @@ export default class RequestTracker {
}

export function getWatcherOptions(options: ParcelOptions): WatcherOptions {
let vcsDirs = ['.git', '.hg'].map(dir => path.join(options.projectRoot, dir));
let vcsDirs = ['.git', '.hg'].map((dir) =>
path.join(options.projectRoot, dir),
);
let ignore = [options.cacheDir, ...vcsDirs];
return {ignore};
}
Expand All @@ -985,11 +987,11 @@ async function loadRequestGraph(options): Async<RequestGraph> {
requestGraph.invalidateEnvNodes(options.env);
requestGraph.invalidateOptionNodes(options);
requestGraph.respondToFSEvents(
events.map(e => ({
events.map((e) => ({
type: e.type,
path: toProjectPath(options.projectRoot, e.path),
})),
{isInitialBuild: false},
{isInitialBuild: true},
);

return requestGraph;
Expand Down

0 comments on commit 3aa5391

Please sign in to comment.