Skip to content

Commit

Permalink
Suggest -transform- when resolving missing plugins (#15683)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jun 8, 2023
1 parent 69e83d5 commit 17162e5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/babel-core/src/config/files/plugins.ts
Expand Up @@ -111,6 +111,22 @@ function* resolveAlternativesHelper(
error.message += `\n- Did you accidentally pass a ${oppositeType} as a ${type}?`;
}

if (type === "plugin") {
const transformName = standardizedName.replace("-proposal-", "-transform-");
if (transformName !== standardizedName && !(yield transformName).error) {
error.message += `\n- Did you mean "${transformName}"?`;
}
}

error.message += `\n
Make sure that all the Babel plugins and presets you are using
are defined as dependencies or devDependencies in your package.json
file. It's possible that the missing plugin is loaded by a preset
you are using that forgot to add the plugin to its dependencies: you
can workaround this problem by explicitly adding the missing package
to your top-level package.json.
`;

throw error;
}

Expand Down

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

16 changes: 16 additions & 0 deletions packages/babel-core/test/resolution.js
Expand Up @@ -466,6 +466,22 @@ describe("addon resolution", function () {

const nodeGte12 = parseInt(process.versions.node, 10) >= 12 ? it : it.skip;

nodeGte12(
"should suggest -transform- as an alternative to -proposal-",
function () {
process.chdir("throw-proposal-to-transform");

expect(() => {
babel.transformSync("", {
filename: "filename.js",
configFile: false,
plugins: ["@babel/proposal-halting-functions"],
});
}).toThrow(
/Cannot (?:find|resolve) module '@babel\/plugin-proposal-halting-functions'.*\n- Did you mean "@babel\/plugin-transform-halting-functions"\?/s,
);
},
);
nodeGte12("should respect package.json#exports", async function () {
process.chdir("pkg-exports");

Expand Down

0 comments on commit 17162e5

Please sign in to comment.