Skip to content

Commit 6c06474

Browse files
ztannerijjk
andauthored
Backport v14: Static worker fixes (#71564 & #74154) (#74284)
Backports: - #71564 - #74154 --------- Co-authored-by: JJ Kasper <jj@jjsweb.site>
1 parent a7f2879 commit 6c06474

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

packages/next/src/build/type-check.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Span } from '../trace'
44

55
import path from 'path'
66
import * as Log from './output/log'
7-
import { Worker as JestWorker } from 'next/dist/compiled/jest-worker'
7+
import { Worker } from '../lib/worker'
88
import { verifyAndLint } from '../lib/verifyAndLint'
99
import createSpinner from './spinner'
1010
import { eventTypeCheckCompleted } from '../telemetry/events'
@@ -30,20 +30,18 @@ function verifyTypeScriptSetup(
3030
hasAppDir: boolean,
3131
hasPagesDir: boolean
3232
) {
33-
const typeCheckWorker = new JestWorker(
33+
const typeCheckWorker = new Worker(
3434
require.resolve('../lib/verify-typescript-setup'),
3535
{
36+
exposedMethods: ['verifyTypeScriptSetup'],
3637
numWorkers: 1,
3738
enableWorkerThreads,
3839
maxRetries: 0,
3940
}
40-
) as JestWorker & {
41+
) as Worker & {
4142
verifyTypeScriptSetup: typeof import('../lib/verify-typescript-setup').verifyTypeScriptSetup
4243
}
4344

44-
typeCheckWorker.getStdout().pipe(process.stdout)
45-
typeCheckWorker.getStderr().pipe(process.stderr)
46-
4745
return typeCheckWorker
4846
.verifyTypeScriptSetup({
4947
dir,

packages/next/src/lib/verifyAndLint.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { red } from './picocolors'
2-
import { Worker } from 'next/dist/compiled/jest-worker'
2+
import { Worker } from './worker'
33
import { existsSync } from 'fs'
44
import { join } from 'path'
55
import { ESLINT_DEFAULT_DIRS } from './constants'
@@ -15,18 +15,22 @@ export async function verifyAndLint(
1515
enableWorkerThreads: boolean | undefined,
1616
telemetry: Telemetry
1717
): Promise<void> {
18+
let lintWorkers:
19+
| (Worker & {
20+
runLintCheck: typeof import('./eslint/runLintCheck').runLintCheck
21+
})
22+
| undefined
23+
1824
try {
19-
const lintWorkers = new Worker(require.resolve('./eslint/runLintCheck'), {
25+
lintWorkers = new Worker(require.resolve('./eslint/runLintCheck'), {
26+
exposedMethods: ['runLintCheck'],
2027
numWorkers: 1,
2128
enableWorkerThreads,
2229
maxRetries: 0,
2330
}) as Worker & {
2431
runLintCheck: typeof import('./eslint/runLintCheck').runLintCheck
2532
}
2633

27-
lintWorkers.getStdout().pipe(process.stdout)
28-
lintWorkers.getStderr().pipe(process.stderr)
29-
3034
const lintDirs = (configLintDirs ?? ESLINT_DEFAULT_DIRS).reduce(
3135
(res: string[], d: string) => {
3236
const currDir = join(dir, d)
@@ -37,7 +41,7 @@ export async function verifyAndLint(
3741
[]
3842
)
3943

40-
const lintResults = await lintWorkers.runLintCheck(dir, lintDirs, {
44+
const lintResults = await lintWorkers?.runLintCheck(dir, lintDirs, {
4145
lintDuringBuild: true,
4246
eslintOptions: {
4347
cacheLocation,
@@ -63,8 +67,6 @@ export async function verifyAndLint(
6367
if (lintOutput) {
6468
console.log(lintOutput)
6569
}
66-
67-
lintWorkers.end()
6870
} catch (err) {
6971
if (isError(err)) {
7072
if (err.type === 'CompileError' || err instanceof CompileError) {
@@ -77,5 +79,9 @@ export async function verifyAndLint(
7779
}
7880
}
7981
throw err
82+
} finally {
83+
try {
84+
lintWorkers?.end()
85+
} catch {}
8086
}
8187
}

packages/next/src/lib/worker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export class Worker {
3535

3636
this._worker = undefined
3737

38+
// ensure we end workers if they weren't before exit
39+
process.on('exit', () => {
40+
this.close()
41+
})
42+
3843
const createWorker = () => {
3944
this._worker = new JestWorker(workerPath, {
4045
...farmOptions,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy