Skip to content

Commit 418914d

Browse files
authored
fix: remove update-notifier as unhelpful (#4856)
Currently build shows a warning when run in the Netlify CLI and `@netlify/build` is not up2date. This can happen when the CLI is outdated, but the CLI already uses update-notifier, so there would be two warnings. This can also happen if the CLI is latest but @netlify/build has just release a new version and it is not included in the CLI yet. In this case the user cannot do anything about this, because the CLI has a shrinkwrap and we force the version of @netlify/build, so updating the lockfile will not help.
1 parent ff37e4c commit 418914d

File tree

9 files changed

+43
-1480
lines changed

9 files changed

+43
-1480
lines changed

package-lock.json

Lines changed: 24 additions & 1402 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/build/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
"tmp-promise": "^3.0.2",
114114
"ts-node": "^10.6.0",
115115
"typescript": "^4.8.4",
116-
"update-notifier": "^5.0.0",
117116
"uuid": "^8.0.0",
118117
"yargs": "^17.6.0"
119118
},
@@ -132,7 +131,6 @@
132131
"get-port": "^6.0.0",
133132
"get-stream": "^6.0.0",
134133
"has-ansi": "^5.0.0",
135-
"is-ci": "^3.0.0",
136134
"moize": "^6.0.0",
137135
"path-key": "^4.0.0",
138136
"process-exists": "^5.0.0",

packages/build/src/core/normalize_flags.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { logFlags } from '../log/messages/config.js'
44
import { removeFalsy } from '../utils/remove_falsy.js'
55

66
import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js'
7-
import { BuildCLIFlags, Mode } from './types.js'
7+
import type { BuildCLIFlags, Mode, TestOptions } from './types.js'
88

99
const REQUIRE_MODE: Mode = 'require'
1010
const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/'
@@ -30,7 +30,7 @@ export type ResolvedFlags = {
3030
saveConfig: boolean
3131
/** Netlify API endpoint @default `api.netlify.com` */
3232
apiHost?: string
33-
testOpts: Record<string, unknown>
33+
testOpts: TestOptions
3434
statsd: { port: number }
3535
timeline: 'build' | string
3636
cachedConfig: Record<string, unknown>

packages/build/src/core/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ export enum SeverityCode {
5151
systemError,
5252
}
5353

54+
export type TestOptions = {
55+
errorMonitor?: any
56+
}
57+
5458
export type ErrorParam = {
5559
errorMonitor: any
5660
mode: Mode
5761
logs: string[]
5862
debug: any
59-
testOpts?: any
63+
testOpts?: TestOptions
6064
childEnv?: any
6165
netlifyConfig?: NetlifyConfig
6266
}

packages/build/src/error/handle.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { pathExists } from 'path-exists'
44

55
import { ErrorParam } from '../core/types.js'
66
import { logBuildError } from '../log/messages/core.js'
7-
import { logOldCliVersionError } from '../log/old_version.js'
87

98
import { removeErrorColors } from './colors.js'
109
import { getErrorInfo } from './info.js'
@@ -14,7 +13,7 @@ import { parseErrorInfo } from './parse/parse.js'
1413
// Logs and reports a build failure
1514
export const handleBuildError = async function (
1615
error: Error,
17-
{ errorMonitor, netlifyConfig, childEnv, mode, logs, debug, testOpts }: ErrorParam,
16+
{ errorMonitor, netlifyConfig, childEnv, logs, debug, testOpts }: ErrorParam,
1817
) {
1918
const basicErrorInfo = parseErrorInfo(error)
2019

@@ -25,9 +24,8 @@ export const handleBuildError = async function (
2524
removeErrorColors(error)
2625
// Some errors, such as telemetry ones, should not be logged
2726
if (basicErrorInfo.showInBuildLog) {
28-
logBuildError({ error, netlifyConfig, mode, logs, debug, testOpts })
27+
logBuildError({ error, netlifyConfig, logs, debug })
2928
}
30-
logOldCliVersionError({ mode, testOpts })
3129
await reportBuildError({ error, errorMonitor, childEnv, logs, testOpts })
3230

3331
return basicErrorInfo

packages/build/src/log/messages/core.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { roundTimerToMillisecs } from '../../time/measure.js'
77
import { ROOT_PACKAGE_JSON } from '../../utils/json.js'
88
import { getLogHeaderFunc } from '../header_func.js'
99
import { log, logMessage, logWarning, logHeader, logSubHeader, logWarningArray, BufferedLogs } from '../logger.js'
10-
import { logOldCliVersionError } from '../old_version.js'
1110
import { THEME } from '../theme.js'
1211

1312
import { logConfigOnError } from './config.js'
@@ -18,15 +17,14 @@ export const logBuildStart = function (logs?: BufferedLogs) {
1817
logMessage(logs, `${ROOT_PACKAGE_JSON.name} ${ROOT_PACKAGE_JSON.version}`)
1918
}
2019

21-
export const logBuildError = function ({ error, netlifyConfig, mode, logs, debug, testOpts }) {
20+
export const logBuildError = function ({ error, netlifyConfig, logs, debug }) {
2221
const fullErrorInfo = getFullErrorInfo({ error, colors: true, debug })
2322
const { severity } = fullErrorInfo
2423
const { title, body } = serializeLogError({ fullErrorInfo })
2524
const logHeaderFunc = getLogHeaderFunc(error)
2625
logHeaderFunc(logs, title)
2726
logMessage(logs, `\n${body}\n`)
2827
logConfigOnError({ logs, netlifyConfig, severity })
29-
logOldCliVersionError({ mode, testOpts })
3028
}
3129

3230
export const logBuildSuccess = function (logs) {

packages/build/src/log/old_version.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/build/src/utils/json.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
import { promises as fs, readFileSync } from 'fs'
1+
import { readFile } from 'fs/promises'
22
import { fileURLToPath } from 'url'
33

4-
import { PackageJson } from 'read-pkg-up'
4+
import type { PackageJson } from 'read-pkg-up'
5+
6+
// We know how our package.json looks like, so we can be very specific with the type
7+
// and only add the properties we want to use
8+
export type RootPackageJson = { name: string; version: string }
59

610
const ROOT_PACKAGE_JSON_PATH = fileURLToPath(new URL('../../package.json', import.meta.url))
711

812
// TODO: Replace with dynamic `import()` once it is supported without
913
// experimental flags
10-
export const importJsonFile = async function (filePath: string) {
11-
const fileContents = await fs.readFile(filePath, 'utf-8')
12-
return JSON.parse(fileContents)
13-
}
14+
export const importJsonFile = async function (filePath: string): Promise<PackageJson> {
15+
const fileContents = await readFile(filePath, 'utf-8')
1416

15-
const importJsonFileSync = function (filePath: string) {
16-
// Use sync I/O so it is easier to migrate to `import()` later on
17-
const fileContents = readFileSync(filePath, 'utf-8')
1817
return JSON.parse(fileContents)
1918
}
2019

21-
export const ROOT_PACKAGE_JSON: PackageJson = importJsonFileSync(ROOT_PACKAGE_JSON_PATH)
20+
export const ROOT_PACKAGE_JSON = (await importJsonFile(ROOT_PACKAGE_JSON_PATH)) as RootPackageJson

packages/build/tests/log/tests.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Fixture, normalizeOutput } from '@netlify/testing'
22
import test from 'ava'
33
import chalk from 'chalk'
44
import hasAnsi from 'has-ansi'
5-
// import isCI from 'is-ci'
65

76
test('Colors in parent process', async (t) => {
87
const { output } = await new Fixture('./fixtures/parent')
@@ -33,20 +32,6 @@ test('No TTY', async (t) => {
3332
t.false(hasAnsi(output))
3433
})
3534

36-
// In GitHub actions, `update-notifier` is never enabled
37-
// @todo: uncomment after upgrading to Ava v4.
38-
// See https://github.com/netlify/build/issues/3615
39-
// if (!isCI) {
40-
// test('Print a warning when using an old version through Netlify CLI', async (t) => {
41-
// // We need to unset some environment variables which would otherwise disable `update-notifier`
42-
// const { output } = await new Fixture('./fixtures/error')
43-
// .withFlags({ mode: 'cli', testOpts: { oldCliLogs: true } })
44-
// .withEnv({ NODE_ENV: '' })
45-
// .runBuildBinary()
46-
// t.snapshot(normalizeOutput(output))
47-
// })
48-
// }
49-
5035
test('Logs whether the build commands came from the UI', async (t) => {
5136
const output = await new Fixture('./fixtures/empty')
5237
.withFlags({ defaultConfig: { build: { command: 'node --invalid' } } })

0 commit comments

Comments
 (0)