Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop pinning plugins with prerelease versions #5554

Merged
merged 3 commits into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/build/src/plugins/pinned_version.js
@@ -1,5 +1,5 @@
import { handleBuildError } from '../error/handle.js'
import { getMajorVersion } from '../utils/semver.js'
import { getMajorVersion, isPrerelease } from '../utils/semver.js'

// Retrieve plugin's pinned major versions by fetching the latest `PluginRun`
// Only applies to `netlify.toml`-only installed plugins.
Expand Down Expand Up @@ -80,10 +80,17 @@
// - the plugin was installed in the UI
// - both the build and the plugin succeeded
const shouldPinVersion = function ({
pluginOptions: { packageName, pinnedVersion, loadedFrom, origin },
pluginOptions: {

Check warning on line 83 in packages/build/src/plugins/pinned_version.js

View check run for this annotation

Codecov / codecov/patch

packages/build/src/plugins/pinned_version.js#L83

Added line #L83 was not covered by tests
packageName,
pinnedVersion,
pluginPackageJson: { version },
loadedFrom,
origin,
},
failedPlugins,
}) {
return (
!isPrerelease(version) &&
pinnedVersion === undefined &&
loadedFrom === 'auto_install' &&
origin === 'ui' &&
Expand Down
6 changes: 6 additions & 0 deletions packages/build/src/utils/semver.js
Expand Up @@ -32,3 +32,9 @@ export const getMajorVersion = function (version) {
const patchVersion = semver.patch(version)
return `${majorVersion}.${minorVersion}.${patchVersion}`
}

export const isPrerelease = function (version) {
// Prerelease versions are excluded from ranges unless `includePrerelease` is
// set to `true`.
return !semver.satisfies(version, '>=0.0.0', { includePrerelease: false })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use semver.prerelease()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You prefer a simpler and more expressive method? FINE, whatever.

(This method is not in the docs, so I had to get creative. Thanks!)

Done in adc65d4.

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,12 @@
{
"name": "netlify-local-plugins",
"description": "This directory contains Build plugins that have been automatically installed by Netlify.",
"version": "1.0.0",
"type": "module",
"private": true,
"author": "Netlify",
"license": "MIT",
"dependencies": {
"netlify-plugin-contextual-env": "1.2.3-rc"
}
}
@@ -0,0 +1,9 @@
{
"name": "module_plugin",
"version": "0.0.1",
"type": "module",
"description": "test",
"license": "MIT",
"repository": "test",
"dependencies": {}
}
59 changes: 59 additions & 0 deletions packages/build/tests/plugins_list/snapshots/tests.js.md
Expand Up @@ -2641,6 +2641,65 @@ Generated by [AVA](https://avajs.dev).
(Netlify Build completed in 1ms)␊
Build step duration: Netlify Build completed in 1ms`

## Do not pin plugin with prerelease versions

> Snapshot 1

`␊
Netlify Build ␊
────────────────────────────────────────────────────────────────␊
> Version␊
@netlify/build 1.0.0␊
> Flags␊
debug: true␊
repositoryRoot: packages/build/tests/plugins_list/fixtures/pin_prerelease␊
sendStatus: true␊
siteId: test␊
testOpts:␊
host: /test/socket␊
pluginsListUrl: /test/socket␊
scheme: http␊
silentLingeringProcesses: true␊
> Current directory␊
packages/build/tests/plugins_list/fixtures/pin_prerelease␊
> Config file␊
No config file was defined: using default values.␊
> Resolved config␊
build:␊
publish: packages/build/tests/plugins_list/fixtures/pin_prerelease␊
publishOrigin: default␊
plugins:␊
- inputs: {}␊
origin: ui␊
package: netlify-plugin-contextual-env␊
> Context␊
production␊
> Available plugins␊
> Loading plugins␊
- netlify-plugin-contextual-env 1-2-3-rc from Netlify app (latest 1-2-3-rc, expected 1-2-3-rc, compatible 1-2-3-rc)␊
netlify-plugin-contextual-env (onPreBuild event) ␊
────────────────────────────────────────────────────────────────␊
test␊
(netlify-plugin-contextual-env onPreBuild completed in 1ms)␊
Build step duration: netlify-plugin-contextual-env onPreBuild completed in 1ms␊
Netlify Build Complete ␊
────────────────────────────────────────────────────────────────␊
(Netlify Build completed in 1ms)␊
Build step duration: Netlify Build completed in 1ms`

## Pin netlify.toml-only plugin versions

> Snapshot 1
Expand Down
Binary file modified packages/build/tests/plugins_list/snapshots/tests.js.snap
Binary file not shown.
6 changes: 6 additions & 0 deletions packages/build/tests/plugins_list/tests.js
Expand Up @@ -411,6 +411,12 @@ test('Pinning plugin versions takes into account the compatibility field', async
})
})

test('Do not pin plugin with prerelease versions', async (t) => {
// By setting the status to 500 we ensure that the endpoint for pinning is
// not being called, otherwise an error would be thrown.
await runWithUpdatePluginMock(t, 'pin_prerelease', { status: 500, testPlugin: { version: '1.2.3-rc' } })
})

const runWithPluginRunsMock = async function (
t,
fixtureName,
Expand Down