Skip to content

Commit d9f55d3

Browse files
authored
fix: remove code supporting versions of Node < v15 (#6599)
1 parent 6c0a42f commit d9f55d3

File tree

15 files changed

+32
-79
lines changed

15 files changed

+32
-79
lines changed

packages/build/src/log/stream.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promisify } from 'util'
1+
import { setTimeout } from 'timers/promises'
22

33
import type { ChildProcess } from '../plugins/spawn.js'
44

@@ -14,9 +14,6 @@ export type StandardStreams = {
1414
type LogsListener = (logs: string[], outputFlusher: OutputFlusher | undefined, chunk: Buffer) => void
1515
type LogsListeners = { stderrListener: LogsListener; stdoutListener: LogsListener }
1616

17-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
18-
const pSetTimeout = promisify(setTimeout)
19-
2017
// We try to use `stdio: inherit` because it keeps `stdout/stderr` as `TTY`,
2118
// which solves many problems. However we can only do it in build.command.
2219
// Plugins have several events, so need to be switch on and off instead.
@@ -67,7 +64,7 @@ export const unpipePluginOutput = async function (
6764
standardStreams: StandardStreams,
6865
) {
6966
// Let `childProcess` `stdout` and `stderr` flush before stopping redirecting
70-
await pSetTimeout(0)
67+
await setTimeout(0)
7168

7269
if (!logsAreBuffered(logs)) {
7370
return unstreamOutput(childProcess, standardStreams)

packages/build/src/plugins/load.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promisify } from 'util'
1+
import { setTimeout } from 'timers/promises'
22

33
import { addErrorInfo } from '../error/info.js'
44
import { addPluginLoadErrorStatus } from '../status/load_error.js'
@@ -7,8 +7,6 @@ import { measureDuration } from '../time/main.js'
77
import { callChild } from './ipc.js'
88
import { captureStandardError } from './system_log.js'
99

10-
const pSetTimeout = promisify(setTimeout)
11-
1210
// Retrieve all plugins steps
1311
// Can use either a module name or a file path to the plugin.
1412
export const loadPlugins = async function ({
@@ -112,7 +110,7 @@ const loadPlugin = async function (
112110
} catch (error) {
113111
if (featureFlags.netlify_build_plugin_system_log) {
114112
// Wait for stderr to be flushed.
115-
await pSetTimeout(0)
113+
await setTimeout(0)
116114
}
117115

118116
addErrorInfo(error, {

packages/build/src/plugins/spawn.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createRequire } from 'module'
22
import { platform } from 'os'
3+
import { setTimeout } from 'timers/promises'
34
import { fileURLToPath, pathToFileURL } from 'url'
4-
import { promisify } from 'util'
55

66
import { trace } from '@opentelemetry/api'
77
import { type ExecaChildProcess, execaNode } from 'execa'
@@ -30,7 +30,6 @@ import { captureStandardError } from './system_log.js'
3030
export type ChildProcess = ExecaChildProcess<string>
3131

3232
const CHILD_MAIN_FILE = fileURLToPath(new URL('child/main.js', import.meta.url))
33-
const pSetTimeout = promisify(setTimeout)
3433
const require = createRequire(import.meta.url)
3534

3635
// Start child processes used by all plugins
@@ -155,7 +154,7 @@ const startPlugin = async function ({
155154
} catch (error) {
156155
if (featureFlags.netlify_build_plugin_system_log) {
157156
// Wait for stderr to be flushed.
158-
await pSetTimeout(0)
157+
await setTimeout(0)
159158
}
160159

161160
const spawnInfo = getSpawnInfo()
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { env, kill } from 'process'
2-
import { promisify } from 'util'
2+
import { setTimeout } from 'timers/promises'
33

44
import { processExists } from 'process-exists'
55

6-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
7-
const pSetTimeout = promisify(setTimeout)
8-
96
// 100ms
107
const PROCESS_TIMEOUT = 1e2
118

@@ -15,6 +12,6 @@ export const onBuild = async function () {
1512
// Signals are async, so we need to wait for the child process to exit
1613
// The while loop is required due to `await`
1714
while (await processExists(env.TEST_PID)) {
18-
await pSetTimeout(PROCESS_TIMEOUT)
15+
await setTimeout(PROCESS_TIMEOUT)
1916
}
2017
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { promisify } from 'util'
2-
3-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
4-
const pSetTimeout = promisify(setTimeout)
1+
import { setTimeout as setTimeoutPromise } from 'timers/promises'
52

63
export const onPreBuild = async function () {
74
setTimeout(function callback() {
85
throw new Error('test')
96
}, 0)
10-
await pSetTimeout(0)
7+
await setTimeoutPromise(0)
118
}

packages/build/tests/error/fixtures/unhandled_promise/plugin.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { promisify } from 'util'
2-
3-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
4-
const pSetTimeout = promisify(setTimeout)
1+
import { setTimeout } from 'timers/promises'
52

63
export const onPreBuild = async function () {
74
unhandledPromise()
85
console.log('onPreBuild')
9-
await pSetTimeout(0)
6+
await setTimeout(0)
107
}
118

129
const unhandledPromise = function () {
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { emitWarning } from 'process'
2-
import { promisify } from 'util'
3-
4-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
5-
const pSetTimeout = promisify(setTimeout)
2+
import { setTimeout } from 'timers/promises'
63

74
// 1 second
85
const WARNING_TIMEOUT = 1e3
96

107
export const onPreBuild = async function () {
118
emitWarning('test')
129
console.log('onPreBuild')
13-
await pSetTimeout(WARNING_TIMEOUT)
10+
await setTimeout(WARNING_TIMEOUT)
1411
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import { promisify } from 'util'
2-
3-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
4-
const pSetTimeout = promisify(setTimeout)
1+
import { setTimeout } from 'timers/promises'
52

63
// 100ms
74
const LOG_TIMEOUT = 1e2
85

96
export const onPreBuild = async function () {
107
console.log('one')
11-
await pSetTimeout(LOG_TIMEOUT)
8+
await setTimeout(LOG_TIMEOUT)
129
console.error('two')
13-
await pSetTimeout(LOG_TIMEOUT)
10+
await setTimeout(LOG_TIMEOUT)
1411
console.log('three')
1512
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { nextTick } from 'process'
2-
import { promisify } from 'util'
3-
4-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
5-
const pSetTimeout = promisify(setTimeout)
2+
import { setTimeout } from 'timers/promises'
63

74
export const onPreBuild = async function ({
85
utils: {
@@ -12,5 +9,5 @@ export const onPreBuild = async function ({
129
nextTick(() => {
1310
cancelBuild('test')
1411
})
15-
await pSetTimeout(0)
12+
await setTimeout(0)
1613
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { nextTick } from 'process'
2-
import { promisify } from 'util'
3-
4-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
5-
const pSetTimeout = promisify(setTimeout)
2+
import { setTimeout } from 'timers/promises'
63

74
export const onPreBuild = async function ({
85
utils: {
@@ -12,5 +9,5 @@ export const onPreBuild = async function ({
129
nextTick(() => {
1310
failBuild('test')
1411
})
15-
await pSetTimeout(0)
12+
await setTimeout(0)
1613
}

0 commit comments

Comments
 (0)