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

Warn when the version specified in transform-runtime doesn't match #10325

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Aug 12, 2019

Q                       A
Fixed Issues? Fixes #10261
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

We can't automatically infer the version of @babel/runtime, because there is a too high risk of introducing a breaking change by inferring the wrong version because of a dependency depending on @babel/runtime, but we can at least warn explaining the problem.
I suspect that currently almost everyone isn't using the verison option, leading to many helpers to be inlined.

I will extract e700f31 to another PR, since it will be useful for testing other warning messages, to clean up our tests console output and to remove the distinction between fixtures and debug-fixtures in preset-env.

@nicolo-ribaudo nicolo-ribaudo added PR: New Feature 🚀 A type of pull request used for our changelog categories area: errors labels Aug 12, 2019
const pkg = JSON.parse(fs.readFileSync(pkgFilename, "utf8"));

return (
pkg.dependencies?.[moduleName] ||
Copy link
Member Author

Choose a reason for hiding this comment

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

It is stage 3 now 🙏

@babel-bot
Copy link
Collaborator

babel-bot commented Aug 12, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11330/

@nicolo-ribaudo
Copy link
Member Author

Rebased to include #10326

basedir: dirname,
}),
);
const pkgFilename = path.resolve(runtimeDir, "../../../package.json");
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I'm not sure this is what I'd recommend for verifying this. Could we consider looking for the package.json in a parent directory starting from dirname? It seems like treating the root as relative to the plugin usage location might be safer than using the location of the plugin, since that could be in an unknown place.

const minActualVersion = semver.minVersion(actualRuntimeVersion).version;
const minVersion = semver.minVersion(runtimeVersion).version;

if (minActualVersion === minVersion) return;
Copy link
Member

Choose a reason for hiding this comment

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

Treating semver ranges as anything other than ranges is asking for trouble I think. Avoiding logic like this is why I lean toward intersects for things in

!semver.intersects(`<${minVersion}`, versionRange) &&
.

What we really want to know in this context is whether every possible version in actualRuntimeVersion is contained within runtimeVersion, I think? As in, every possible version of the runtime that could be installed by this package.json is valid given the semver range passed to the Babel plugin.

This current logic would pass if for instance we had

runtimeVersion: "^7.2.0",
actualRuntimeVersion: "~7.2.0"

since the minimum for both is 7.2.0.

I'm not sure if the semver module actually exposes and API for doing the comparison we need to do here, but we can certainly check.

).replace(/^/gm, " ".repeat(2));

if (semver.gt(minActualVersion, minVersion)) {
console.warn(
Copy link
Member

Choose a reason for hiding this comment

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

I'd be very hesitant to add new logging to a plugin in a non-major if it isn't opt-in. Some tools will treat any stderr output as an indication that something in the build has failed.

@JLHwung
Copy link
Contributor

JLHwung commented Jul 16, 2020

I'd be very hesitant to add new logging to a plugin in a non-major if it isn't opt-in

I think the concern here is valid, @nicolo-ribaudo Can you rebase this one onto next-8-dev? We can target this change to Babel 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: errors PR: New Feature 🚀 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transform-runtime regression, not requiring _objectSpread helper
4 participants