Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/build/src/plugins/plugin_conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const siteDependenciesTest = async function (
return (
await Promise.all(
Object.entries(allowedSiteDependencies).map(async ([dependencyName, allowedVersion]) =>
siteDependencyTest({ dependencyName, allowedVersion, siteDependencies, buildDir }),
siteDependencyTest({ dependencyName, allowedVersion, siteDependencies, buildDir, packagePath }),
),
)
).every(Boolean)
Expand All @@ -63,10 +63,12 @@ const siteDependencyTest = async function ({
allowedVersion,
siteDependencies,
buildDir,
packagePath,
}: {
dependencyName: string
allowedVersion: string
buildDir: string
packagePath?: string
siteDependencies: Record<string, string | undefined>
}): Promise<boolean> {
const siteDependency = siteDependencies[dependencyName]
Expand All @@ -81,7 +83,10 @@ const siteDependencyTest = async function ({

try {
// if this is a range we need to get the exact version
const packageJsonPath = await resolvePath(`${dependencyName}/package.json`, buildDir)
const packageJsonPath = await resolvePath(
`${dependencyName}/package.json`,
packagePath ? join(buildDir, packagePath) : buildDir,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit - we seem to mostly be using join(buildDir, packagePath || '') or packagePath ?? ''

)
const { version } = await importJsonFile(packageJsonPath)
if (!version) {
return false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[plugins]]
package = "netlify-plugin-contextual-env"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "module_plugin",
"version": "0.0.1",
"type": "module",
"description": "test",
"license": "MIT",
"repository": "test",
"dependencies": {
"@netlify/dependency-with-range": "^9.5.4"
}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"workspaces": [
"apps/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[plugins]]
package = "netlify-plugin-contextual-env"

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "module_plugin",
"version": "0.0.1",
"type": "module",
"description": "test",
"license": "MIT",
"repository": "test",
"dependencies": {
"@netlify/dependency-with-range": "^9.5.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"workspaces": [
"apps/*"
]
}
74 changes: 71 additions & 3 deletions packages/build/tests/plugins_list/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import cpy from 'cpy'

const FIXTURES_DIR = fileURLToPath(new URL('fixtures', import.meta.url))

const runWithApiMock = async function (
t,
const runWithApiMockAndGetNormalizedOutput = async function (
fixtureName,
{ testPlugin, response = getPluginsList(testPlugin), ...flags } = {},
status = 200,
Expand All @@ -26,12 +25,21 @@ const runWithApiMock = async function (
...flags,
})
.runWithBuild()
await t.snapshot(normalizeOutput(output))
return normalizeOutput(output)
} finally {
await stopServer()
}
}

const runWithApiMock = async function (
t,
fixtureName,
{ testPlugin, response = getPluginsList(testPlugin), ...flags } = {},
status = 200,
) {
await t.snapshot(await runWithApiMockAndGetNormalizedOutput(fixtureName, { testPlugin, response, ...flags }, status))
}

Comment on lines +34 to +42
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All existing tests in this suite use snapshots which is not something I wanted to continue and wanted something a bit more concrete, so I moved most of this to another helper that just returns normalized output instead of snapshotting it.

Would be nice to convert existing tests to explicit assertions, but I don't have bandwidth for that right now

// We use a specific plugin in tests. We hardcode its version to keep the tests
// stable even when new versions of that plugin are published.
const getPluginsList = function (testPlugin = DEFAULT_TEST_PLUGIN) {
Expand Down Expand Up @@ -289,6 +297,66 @@ test.serial('Plugins can specify non-matching compatibility.siteDependencies ran
})
})

test.serial(
'Plugins can specify matching compatibility.siteDependencies range in monorepo with hoisted node_modules',
async (t) => {
await removeDir(`${FIXTURES_DIR}/plugins_compat_site_dependencies_range_monorepo_hoisted/apps/web/.netlify`)
const normalizedOutput = await runWithApiMockAndGetNormalizedOutput(
'plugins_compat_site_dependencies_range_monorepo_hoisted',
{
testPlugin: {
compatibility: [
{ version: '0.3.0' },
{
version: '0.2.0',
siteDependencies: {
// this is satisfied, so this version should be selected
'@netlify/dependency-with-range': '<10',
},
},
],
},
packagePath: 'apps/web',
},
)
t.true(
normalizedOutput.includes(
'netlify-plugin-contextual-env 0-2-0 from netlify.toml (latest 0-3-0, expected 0-2-0, compatible 0-2-0)',
),
)
},
)

test.serial(
'Plugins can specify matching compatibility.siteDependencies range in monorepo without hoisted node_modules',
async (t) => {
await removeDir(`${FIXTURES_DIR}/plugins_compat_site_dependencies_range_monorepo_not_hoisted/apps/web/.netlify`)
const normalizedOutput = await runWithApiMockAndGetNormalizedOutput(
'plugins_compat_site_dependencies_range_monorepo_not_hoisted',
{
testPlugin: {
compatibility: [
{ version: '0.3.0' },
{
version: '0.2.0',
siteDependencies: {
// this is satisfied, so this version should be selected
'@netlify/dependency-with-range': '<10',
},
},
],
},
packagePath: 'apps/web',
},
)
t.true(
normalizedOutput.includes(
'netlify-plugin-contextual-env 0-2-0 from netlify.toml (latest 0-3-0, expected 0-2-0, compatible 0-2-0)',
),
)
},
)

test.serial('Plugin versions can be feature flagged', async (t) => {
await removeDir(`${FIXTURES_DIR}/plugins_compat_node_version/.netlify`)
await runWithApiMock(t, 'plugins_compat_node_version', {
Expand Down
Loading