Skip to content

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Sep 4, 2025

🎉 Thanks for submitting a pull request! 🎉

Summary

Ref: https://netlify.slack.com/archives/C01TKAEBP3Q/p1756940014614849

To easier follow added fixtures - recommend checking them in "file explorer" instead of diff and notice where node_modules are situated in those 2 fixtures:

First commit with failing test that this PR is looking to address - https://github.com/netlify/build/actions/runs/17465897278/job/49601431168?pr=6650#step:12:313
Second commit with the fix


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures
    your code follows our style guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@pieh pieh force-pushed the fix/resolve-site-dependency-version-from-package-path-first branch from 4c22d9e to 9d1f119 Compare September 4, 2025 11:51
@pieh pieh force-pushed the fix/resolve-site-dependency-version-from-package-path-first branch from 9d1f119 to 579c160 Compare September 4, 2025 13:43
Copy link
Contributor

github-actions bot commented Sep 4, 2025

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@pieh pieh changed the title fix: resolve site dependency version from packagePath before checking root of monorepo fix: resolve site dependency version from packagePath if defined Sep 4, 2025
@pieh pieh marked this pull request as ready for review September 4, 2025 14:10
@pieh pieh requested a review from a team as a code owner September 4, 2025 14:10
Comment on lines +34 to +42
const runWithApiMock = async function (
t,
fixtureName,
{ testPlugin, response = getPluginsList(testPlugin), ...flags } = {},
status = 200,
) {
await t.snapshot(await runWithApiMockAndGetNormalizedOutput(fixtureName, { testPlugin, response, ...flags }, status))
}

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

mrstork
mrstork previously approved these changes Sep 4, 2025
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 ?? ''

mrstork
mrstork previously approved these changes Sep 4, 2025
@@ -81,7 +83,7 @@ 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`, join(buildDir, packagePath || ''))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very similar to fix in #6105, where other part of the system was not taking packagePath into consideration

Do note that if dependency is in node_modules in root of monorepo - we still will be able to resolve, because require.resolve is used and not direct FS check. This is also verified with added test case for hoisted node_modules still passing

@pieh pieh force-pushed the fix/resolve-site-dependency-version-from-package-path-first branch from fdeca6f to 596e0b2 Compare September 4, 2025 14:51
@pieh pieh merged commit 5fde543 into main Sep 4, 2025
36 checks passed
@pieh pieh deleted the fix/resolve-site-dependency-version-from-package-path-first branch September 4, 2025 15:06
This was referenced Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants