Skip to content

Commit 6263d87

Browse files
fix: limit logging to authoritative plugin version (#5579)
* chore: add system logging * fix: limit logs to authoritative plugin version * fix: add missing property
1 parent 9b8ed35 commit 6263d87

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

packages/build/src/plugins/compatibility.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ describe(`getExpectedVersion`, () => {
282282
systemLog: (message: string) => {
283283
logMessages.push(message)
284284
},
285+
authoritative: true,
285286
})
286287

287288
expect(logMessages.length).toBe(1)
@@ -322,6 +323,7 @@ describe(`getExpectedVersion`, () => {
322323
featureFlags: {
323324
netlify_build_updated_plugin_compatibility: true,
324325
},
326+
authoritative: true,
325327
})
326328

327329
expect(logMessages.length).toBe(1)

packages/build/src/plugins/compatibility.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const getExpectedVersion = async function ({
3333
pinnedVersion,
3434
featureFlags,
3535
systemLog,
36+
authoritative,
3637
}: {
3738
versions: PluginVersion[]
3839
/** The package.json of the repository */
@@ -44,6 +45,11 @@ export const getExpectedVersion = async function ({
4445
pinnedVersion?: string
4546
featureFlags?: FeatureFlags
4647
systemLog: SystemLogger
48+
/* Defines whether the version returned from this method is the authoritative
49+
version that will be used for the plugin; if not, the method may be called
50+
just to get information about other compatible versions that will not be
51+
selected */
52+
authoritative?: boolean
4753
}) {
4854
const { version, conditions = [] } = await getCompatibleEntry({
4955
versions,
@@ -54,7 +60,7 @@ export const getExpectedVersion = async function ({
5460
buildDir,
5561
pinnedVersion,
5662
featureFlags,
57-
systemLog,
63+
systemLog: authoritative ? systemLog : undefined,
5864
})
5965

6066
// Retrieve warning message shown when using an older version with `compatibility`
@@ -87,7 +93,9 @@ const getCompatibleEntry = async function ({
8793
buildDir,
8894
pinnedVersion,
8995
featureFlags,
90-
systemLog,
96+
systemLog = () => {
97+
// no-op
98+
},
9199
}: {
92100
versions: PluginVersion[]
93101
packageJson: PackageJson
@@ -97,7 +105,7 @@ const getCompatibleEntry = async function ({
97105
packagePath?: string
98106
pinnedVersion?: string
99107
featureFlags?: FeatureFlags
100-
systemLog: SystemLogger
108+
systemLog?: SystemLogger
101109
}): Promise<Pick<PluginVersion, 'conditions' | 'version'>> {
102110
const compatibleEntry = await pLocate(versions, async ({ version, overridePinnedVersion, conditions }) => {
103111
// When there's a `pinnedVersion`, we typically pick the first version that
@@ -126,10 +134,16 @@ const getCompatibleEntry = async function ({
126134
})
127135

128136
if (compatibleEntry) {
137+
systemLog(
138+
`Used compatible version '${compatibleEntry.version}' for plugin '${packageName}' (pinned version is ${pinnedVersion})`,
139+
)
140+
129141
return compatibleEntry
130142
}
131143

132144
if (pinnedVersion) {
145+
systemLog(`Used pinned version '${pinnedVersion}' for plugin '${packageName}'`)
146+
133147
return { version: pinnedVersion, conditions: [] }
134148
}
135149

packages/build/src/plugins/expected_version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const addExpectedVersion = async function ({
9494
pinnedVersion,
9595
featureFlags,
9696
systemLog,
97+
authoritative: true,
9798
}),
9899
getExpectedVersion({
99100
versions,

0 commit comments

Comments
 (0)