Unverified Commit 6c06474a authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

Backport v14: Static worker fixes (#71564 & #74154) (#74284)

Backports:
- #71564
- #74154

---------
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent a7f2879b
...@@ -4,7 +4,7 @@ import type { Span } from '../trace' ...@@ -4,7 +4,7 @@ import type { Span } from '../trace'
import path from 'path' import path from 'path'
import * as Log from './output/log' import * as Log from './output/log'
import { Worker as JestWorker } from 'next/dist/compiled/jest-worker' import { Worker } from '../lib/worker'
import { verifyAndLint } from '../lib/verifyAndLint' import { verifyAndLint } from '../lib/verifyAndLint'
import createSpinner from './spinner' import createSpinner from './spinner'
import { eventTypeCheckCompleted } from '../telemetry/events' import { eventTypeCheckCompleted } from '../telemetry/events'
...@@ -30,20 +30,18 @@ function verifyTypeScriptSetup( ...@@ -30,20 +30,18 @@ function verifyTypeScriptSetup(
hasAppDir: boolean, hasAppDir: boolean,
hasPagesDir: boolean hasPagesDir: boolean
) { ) {
const typeCheckWorker = new JestWorker( const typeCheckWorker = new Worker(
require.resolve('../lib/verify-typescript-setup'), require.resolve('../lib/verify-typescript-setup'),
{ {
exposedMethods: ['verifyTypeScriptSetup'],
numWorkers: 1, numWorkers: 1,
enableWorkerThreads, enableWorkerThreads,
maxRetries: 0, maxRetries: 0,
} }
) as JestWorker & { ) as Worker & {
verifyTypeScriptSetup: typeof import('../lib/verify-typescript-setup').verifyTypeScriptSetup verifyTypeScriptSetup: typeof import('../lib/verify-typescript-setup').verifyTypeScriptSetup
} }
typeCheckWorker.getStdout().pipe(process.stdout)
typeCheckWorker.getStderr().pipe(process.stderr)
return typeCheckWorker return typeCheckWorker
.verifyTypeScriptSetup({ .verifyTypeScriptSetup({
dir, dir,
......
import { red } from './picocolors' import { red } from './picocolors'
import { Worker } from 'next/dist/compiled/jest-worker' import { Worker } from './worker'
import { existsSync } from 'fs' import { existsSync } from 'fs'
import { join } from 'path' import { join } from 'path'
import { ESLINT_DEFAULT_DIRS } from './constants' import { ESLINT_DEFAULT_DIRS } from './constants'
...@@ -15,8 +15,15 @@ export async function verifyAndLint( ...@@ -15,8 +15,15 @@ export async function verifyAndLint(
enableWorkerThreads: boolean | undefined, enableWorkerThreads: boolean | undefined,
telemetry: Telemetry telemetry: Telemetry
): Promise<void> { ): Promise<void> {
let lintWorkers:
| (Worker & {
runLintCheck: typeof import('./eslint/runLintCheck').runLintCheck
})
| undefined
try { try {
const lintWorkers = new Worker(require.resolve('./eslint/runLintCheck'), { lintWorkers = new Worker(require.resolve('./eslint/runLintCheck'), {
exposedMethods: ['runLintCheck'],
numWorkers: 1, numWorkers: 1,
enableWorkerThreads, enableWorkerThreads,
maxRetries: 0, maxRetries: 0,
...@@ -24,9 +31,6 @@ export async function verifyAndLint( ...@@ -24,9 +31,6 @@ export async function verifyAndLint(
runLintCheck: typeof import('./eslint/runLintCheck').runLintCheck runLintCheck: typeof import('./eslint/runLintCheck').runLintCheck
} }
lintWorkers.getStdout().pipe(process.stdout)
lintWorkers.getStderr().pipe(process.stderr)
const lintDirs = (configLintDirs ?? ESLINT_DEFAULT_DIRS).reduce( const lintDirs = (configLintDirs ?? ESLINT_DEFAULT_DIRS).reduce(
(res: string[], d: string) => { (res: string[], d: string) => {
const currDir = join(dir, d) const currDir = join(dir, d)
...@@ -37,7 +41,7 @@ export async function verifyAndLint( ...@@ -37,7 +41,7 @@ export async function verifyAndLint(
[] []
) )
const lintResults = await lintWorkers.runLintCheck(dir, lintDirs, { const lintResults = await lintWorkers?.runLintCheck(dir, lintDirs, {
lintDuringBuild: true, lintDuringBuild: true,
eslintOptions: { eslintOptions: {
cacheLocation, cacheLocation,
...@@ -63,8 +67,6 @@ export async function verifyAndLint( ...@@ -63,8 +67,6 @@ export async function verifyAndLint(
if (lintOutput) { if (lintOutput) {
console.log(lintOutput) console.log(lintOutput)
} }
lintWorkers.end()
} catch (err) { } catch (err) {
if (isError(err)) { if (isError(err)) {
if (err.type === 'CompileError' || err instanceof CompileError) { if (err.type === 'CompileError' || err instanceof CompileError) {
...@@ -77,5 +79,9 @@ export async function verifyAndLint( ...@@ -77,5 +79,9 @@ export async function verifyAndLint(
} }
} }
throw err throw err
} finally {
try {
lintWorkers?.end()
} catch {}
} }
} }
...@@ -35,6 +35,11 @@ export class Worker { ...@@ -35,6 +35,11 @@ export class Worker {
this._worker = undefined this._worker = undefined
// ensure we end workers if they weren't before exit
process.on('exit', () => {
this.close()
})
const createWorker = () => { const createWorker = () => {
this._worker = new JestWorker(workerPath, { this._worker = new JestWorker(workerPath, {
...farmOptions, ...farmOptions,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment