Skip to content

Commit

Permalink
fix: stop pinning plugins with prerelease versions (#5554)
Browse files Browse the repository at this point in the history
* fix: stop pinning plugins with prerelease versions

* refactor: simplify things
  • Loading branch information
eduardoboucas committed Mar 21, 2024
1 parent 664052b commit 3e0670f
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 8 deletions.
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 @@ export const pinPlugins = async function ({
// - the plugin was installed in the UI
// - both the build and the plugin succeeded
const shouldPinVersion = function ({
pluginOptions: { packageName, pinnedVersion, loadedFrom, origin },
pluginOptions: {
packageName,
pinnedVersion,
pluginPackageJson: { version },
loadedFrom,
origin,
},
failedPlugins,
}) {
return (
!isPrerelease(version) &&
pinnedVersion === undefined &&
loadedFrom === 'auto_install' &&
origin === 'ui' &&
Expand Down
4 changes: 4 additions & 0 deletions packages/build/src/utils/semver.js
Expand Up @@ -32,3 +32,7 @@ export const getMajorVersion = function (version) {
const patchVersion = semver.patch(version)
return `${majorVersion}.${minorVersion}.${patchVersion}`
}

export const isPrerelease = function (version) {
return semver.prerelease(version)
}

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
Expand Up @@ -9,17 +9,17 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
`Validation of Edge Functions manifest failed␊
[31m[1mTYPE[22m[39m[31m must be object[39m
TYPE must be object␊
[0m[31m[1m>[22m[39m[90m 1 |[39m [32m"json"[39m[0m
[0m [90m |[39m [31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m [31m[1m👈🏽 [95mtype[31m must be object[22m[39m[0m`
> 1 | "json"␊
| ^^^^^^ 👈🏽 type must be object`

## should print error on empty manifest

> Snapshot 1
`Validation of Edge Functions manifest failed␊
[31m[1mREQUIRED[22m[39m[31m must have required property 'bundler_version'[39m
REQUIRED must have required property 'bundler_version'␊
[0m[31m[1m>[22m[39m[90m 1 |[39m {}[0m
[0m [90m |[39m [31m[1m^[22m[39m [31m[1m☹️ [95mbundler_version[31m is missing here![22m[39m[0m`
> 1 | {}␊
| ^ ☹️ bundler_version is missing here!`
Binary file not shown.
5 changes: 5 additions & 0 deletions packages/build/tests/unit/validate_edge_manifest/tests.js
@@ -1,6 +1,7 @@
import test from 'ava'

import { validateEdgeFunctionsManifest } from '../../../lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js'
import { removeErrorColors } from '../../../src/error/colors.js'

test('should validate valid manifest', async (t) => {
const manifest = {
Expand Down Expand Up @@ -35,11 +36,15 @@ test('should print error on invalid manifest', async (t) => {

const error = await t.throwsAsync(validateEdgeFunctionsManifest(manifest))

removeErrorColors(error)

t.snapshot(error.message)
})

test('should print error on empty manifest', async (t) => {
const error = await t.throwsAsync(validateEdgeFunctionsManifest({}))

removeErrorColors(error)

t.snapshot(error.message)
})

0 comments on commit 3e0670f

Please sign in to comment.