diff --git a/.circleci/config.yml b/.circleci/config.yml index ce95576ce164e..a7d323be7e1b8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -350,9 +350,6 @@ jobs: - run: # Quick upgrade to the v2 (any version, we just need the real set version) command: yarn policies set-version berry working_directory: /tmp/e2e-tests/gatsby-pnp - - run: # TODO: remove pinned version - command: yarn set version 3.1.1 - working_directory: /tmp/e2e-tests/gatsby-pnp - run: # Explicitly set nodeLinker to avoid Yarn selecting node_modules due to the Yarn 1.x lockfile command: yarn config set nodeLinker pnp working_directory: /tmp/e2e-tests/gatsby-pnp diff --git a/packages/gatsby-worker/src/child.ts b/packages/gatsby-worker/src/child.ts index 9947e2bfc655b..23def265ff1c6 100644 --- a/packages/gatsby-worker/src/child.ts +++ b/packages/gatsby-worker/src/child.ts @@ -6,6 +6,7 @@ import { ERROR, RESULT, CUSTOM_MESSAGE, + WORKER_READY, } from "./types" import { isPromise } from "./utils" @@ -102,6 +103,8 @@ if (process.send && process.env.GATSBY_WORKER_MODULE_PATH) { } process.on(`message`, messageHandler) + + ensuredSendToMain([WORKER_READY]) } export { isWorker, getMessenger } diff --git a/packages/gatsby-worker/src/index.ts b/packages/gatsby-worker/src/index.ts index a8ccd07f1881b..d96e1e83710c1 100644 --- a/packages/gatsby-worker/src/index.ts +++ b/packages/gatsby-worker/src/index.ts @@ -7,6 +7,7 @@ import { ERROR, RESULT, CUSTOM_MESSAGE, + WORKER_READY, ParentMessageUnion, ChildMessageUnion, } from "./types" @@ -87,6 +88,7 @@ interface IWorkerInfo { signal: NodeJS.Signals | null }> currentTask?: TaskInfo + ready: Promise } export interface IPublicWorkerInfo { @@ -183,9 +185,13 @@ export class WorkerPool< silent: options && options.silent, }) + let workerReadyResolve: () => void const workerInfo: IWorkerInfo = { workerId, worker, + ready: new Promise(resolve => { + workerReadyResolve = resolve + }), exitedPromise: new Promise(resolve => { worker.on(`exit`, (code, signal) => { if (workerInfo.currentTask) { @@ -247,6 +253,8 @@ export class WorkerPool< for (const listener of this.listeners) { listener(msg[1] as MessagesFromChild, workerId) } + } else if (msg[0] === WORKER_READY) { + workerReadyResolve() } }) @@ -322,14 +330,16 @@ export class WorkerPool< this.idleWorkers.add(workerInfo) } - private doWork( + private async doWork( taskInfo: TaskInfo, workerInfo: IWorkerInfo - ): void { + ): Promise { // block worker workerInfo.currentTask = taskInfo this.idleWorkers.delete(workerInfo) + await workerInfo.ready + const msg: ParentMessageUnion = [ EXECUTE, taskInfo.functionName, diff --git a/packages/gatsby-worker/src/types.ts b/packages/gatsby-worker/src/types.ts index 5a066c7c3af4c..59dc47fa4e4c2 100644 --- a/packages/gatsby-worker/src/types.ts +++ b/packages/gatsby-worker/src/types.ts @@ -3,6 +3,7 @@ export const ERROR = 0b10 export const RESULT = 0b11 export const END = 0b00 export const CUSTOM_MESSAGE = 0b100 +export const WORKER_READY = 0b1000 type CustomMessage = [typeof CUSTOM_MESSAGE, unknown] @@ -11,6 +12,7 @@ type FunctionArgs = Array type ExecuteMessage = [typeof EXECUTE, FunctionName, FunctionArgs] type EndMessage = [typeof END] +type WorkerReadyMessage = [typeof WORKER_READY] export type ParentMessageUnion = ExecuteMessage | EndMessage | CustomMessage @@ -30,4 +32,8 @@ type ResultType = unknown type TaskResult = [typeof RESULT, ResultType] -export type ChildMessageUnion = TaskError | TaskResult | CustomMessage +export type ChildMessageUnion = + | TaskError + | TaskResult + | CustomMessage + | WorkerReadyMessage diff --git a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts index c1d8dce022e71..073fad5de3704 100644 --- a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts +++ b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts @@ -18,9 +18,7 @@ export function constructParcel(siteRoot: string): Parcel { `${siteRoot}/${gatsbyFileRegex}`, `${siteRoot}/plugins/**/${gatsbyFileRegex}`, ], - defaultConfig: require.resolve(`gatsby-parcel-config`, { - paths: [siteRoot], - }), + defaultConfig: require.resolve(`gatsby-parcel-config`), mode: `production`, targets: { root: {