Skip to content

Commit a56b652

Browse files
gatsbybotpieh
andauthored
fix(gatsby): PnP fixes (#35194) (#35199)
(cherry picked from commit 79c5598) Co-authored-by: Michal Piechowiak <[email protected]>
1 parent 0b6067a commit a56b652

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

.circleci/config.yml

-3
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,6 @@ jobs:
350350
- run: # Quick upgrade to the v2 (any version, we just need the real set version)
351351
command: yarn policies set-version berry
352352
working_directory: /tmp/e2e-tests/gatsby-pnp
353-
- run: # TODO: remove pinned version
354-
command: yarn set version 3.1.1
355-
working_directory: /tmp/e2e-tests/gatsby-pnp
356353
- run: # Explicitly set nodeLinker to avoid Yarn selecting node_modules due to the Yarn 1.x lockfile
357354
command: yarn config set nodeLinker pnp
358355
working_directory: /tmp/e2e-tests/gatsby-pnp

packages/gatsby-worker/src/child.ts

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ERROR,
77
RESULT,
88
CUSTOM_MESSAGE,
9+
WORKER_READY,
910
} from "./types"
1011
import { isPromise } from "./utils"
1112

@@ -102,6 +103,8 @@ if (process.send && process.env.GATSBY_WORKER_MODULE_PATH) {
102103
}
103104

104105
process.on(`message`, messageHandler)
106+
107+
ensuredSendToMain([WORKER_READY])
105108
}
106109

107110
export { isWorker, getMessenger }

packages/gatsby-worker/src/index.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ERROR,
88
RESULT,
99
CUSTOM_MESSAGE,
10+
WORKER_READY,
1011
ParentMessageUnion,
1112
ChildMessageUnion,
1213
} from "./types"
@@ -87,6 +88,7 @@ interface IWorkerInfo<T> {
8788
signal: NodeJS.Signals | null
8889
}>
8990
currentTask?: TaskInfo<T>
91+
ready: Promise<void>
9092
}
9193

9294
export interface IPublicWorkerInfo {
@@ -183,9 +185,13 @@ export class WorkerPool<
183185
silent: options && options.silent,
184186
})
185187

188+
let workerReadyResolve: () => void
186189
const workerInfo: IWorkerInfo<keyof WorkerModuleExports> = {
187190
workerId,
188191
worker,
192+
ready: new Promise<void>(resolve => {
193+
workerReadyResolve = resolve
194+
}),
189195
exitedPromise: new Promise(resolve => {
190196
worker.on(`exit`, (code, signal) => {
191197
if (workerInfo.currentTask) {
@@ -247,6 +253,8 @@ export class WorkerPool<
247253
for (const listener of this.listeners) {
248254
listener(msg[1] as MessagesFromChild, workerId)
249255
}
256+
} else if (msg[0] === WORKER_READY) {
257+
workerReadyResolve()
250258
}
251259
})
252260

@@ -322,14 +330,16 @@ export class WorkerPool<
322330
this.idleWorkers.add(workerInfo)
323331
}
324332

325-
private doWork<T extends keyof WorkerModuleExports>(
333+
private async doWork<T extends keyof WorkerModuleExports>(
326334
taskInfo: TaskInfo<T>,
327335
workerInfo: IWorkerInfo<T>
328-
): void {
336+
): Promise<void> {
329337
// block worker
330338
workerInfo.currentTask = taskInfo
331339
this.idleWorkers.delete(workerInfo)
332340

341+
await workerInfo.ready
342+
333343
const msg: ParentMessageUnion = [
334344
EXECUTE,
335345
taskInfo.functionName,

packages/gatsby-worker/src/types.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const ERROR = 0b10
33
export const RESULT = 0b11
44
export const END = 0b00
55
export const CUSTOM_MESSAGE = 0b100
6+
export const WORKER_READY = 0b1000
67

78
type CustomMessage = [typeof CUSTOM_MESSAGE, unknown]
89

@@ -11,6 +12,7 @@ type FunctionArgs = Array<any>
1112

1213
type ExecuteMessage = [typeof EXECUTE, FunctionName, FunctionArgs]
1314
type EndMessage = [typeof END]
15+
type WorkerReadyMessage = [typeof WORKER_READY]
1416

1517
export type ParentMessageUnion = ExecuteMessage | EndMessage | CustomMessage
1618

@@ -30,4 +32,8 @@ type ResultType = unknown
3032

3133
type TaskResult = [typeof RESULT, ResultType]
3234

33-
export type ChildMessageUnion = TaskError | TaskResult | CustomMessage
35+
export type ChildMessageUnion =
36+
| TaskError
37+
| TaskResult
38+
| CustomMessage
39+
| WorkerReadyMessage

packages/gatsby/src/utils/parcel/compile-gatsby-files.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export function constructParcel(siteRoot: string): Parcel {
1818
`${siteRoot}/${gatsbyFileRegex}`,
1919
`${siteRoot}/plugins/**/${gatsbyFileRegex}`,
2020
],
21-
defaultConfig: require.resolve(`gatsby-parcel-config`, {
22-
paths: [siteRoot],
23-
}),
21+
defaultConfig: require.resolve(`gatsby-parcel-config`),
2422
mode: `production`,
2523
targets: {
2624
root: {

0 commit comments

Comments
 (0)