From 55d0faf0d90350bac3e0ea4b2da7741986f89b64 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 22 Mar 2022 10:33:49 +0100 Subject: [PATCH 1/6] don't resovle gatsby-parcel-config in context of site --- packages/gatsby/src/utils/parcel/compile-gatsby-files.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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: { From 3432e34fb140f50597d3eb1f7470bfea41192fec Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 22 Mar 2022 10:34:22 +0100 Subject: [PATCH 2/6] unpin yarn version in pnp tests --- .circleci/config.yml | 3 --- 1 file changed, 3 deletions(-) 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 From 4e4bc6dafc986d5b83e8321088155d47a1b4d2c0 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 22 Mar 2022 10:35:00 +0100 Subject: [PATCH 3/6] debug: log query extraction->babel parsing error --- packages/gatsby/src/query/file-parser.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/gatsby/src/query/file-parser.js b/packages/gatsby/src/query/file-parser.js index c163177573363..e5b7bc8098d9d 100644 --- a/packages/gatsby/src/query/file-parser.js +++ b/packages/gatsby/src/query/file-parser.js @@ -156,6 +156,8 @@ async function parseToAst(filePath, fileStr, { parentSpan, addError } = {}) { }) ) + console.error({ error, fileStr, filePath }) + addError({ id: `85911`, filePath, From 97273a78e57d0204670e2982f552078db2adcd51 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 22 Mar 2022 12:18:31 +0100 Subject: [PATCH 4/6] wait for worker to be ready before sending message (?) --- packages/gatsby-worker/src/child.ts | 3 +++ packages/gatsby-worker/src/index.ts | 13 +++++++++++-- packages/gatsby-worker/src/types.ts | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) 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..0deee704cf841 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,10 +330,11 @@ export class WorkerPool< this.idleWorkers.add(workerInfo) } - private doWork( + private async doWork( taskInfo: TaskInfo, workerInfo: IWorkerInfo - ): void { + ): Promise { + await workerInfo.ready // block worker workerInfo.currentTask = taskInfo this.idleWorkers.delete(workerInfo) 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 From cea6dd61c281026fc1b64453da2e5a3fd81b3d26 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 22 Mar 2022 12:35:36 +0100 Subject: [PATCH 5/6] block worker before waiting for it to be ready --- packages/gatsby-worker/src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-worker/src/index.ts b/packages/gatsby-worker/src/index.ts index 0deee704cf841..d96e1e83710c1 100644 --- a/packages/gatsby-worker/src/index.ts +++ b/packages/gatsby-worker/src/index.ts @@ -334,11 +334,12 @@ export class WorkerPool< taskInfo: TaskInfo, workerInfo: IWorkerInfo ): Promise { - await workerInfo.ready // block worker workerInfo.currentTask = taskInfo this.idleWorkers.delete(workerInfo) + await workerInfo.ready + const msg: ParentMessageUnion = [ EXECUTE, taskInfo.functionName, From 4fba853fb9615b74a961332d875dec36e2ad971d Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 22 Mar 2022 12:58:24 +0100 Subject: [PATCH 6/6] drop debug log --- packages/gatsby/src/query/file-parser.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/gatsby/src/query/file-parser.js b/packages/gatsby/src/query/file-parser.js index e5b7bc8098d9d..c163177573363 100644 --- a/packages/gatsby/src/query/file-parser.js +++ b/packages/gatsby/src/query/file-parser.js @@ -156,8 +156,6 @@ async function parseToAst(filePath, fileStr, { parentSpan, addError } = {}) { }) ) - console.error({ error, fileStr, filePath }) - addError({ id: `85911`, filePath,