diff --git a/packages/babel-core/src/transformation/file/options/option-manager.js b/packages/babel-core/src/transformation/file/options/option-manager.js index 896e5225ef60..ad4fbf4ed966 100644 --- a/packages/babel-core/src/transformation/file/options/option-manager.js +++ b/packages/babel-core/src/transformation/file/options/option-manager.js @@ -261,6 +261,18 @@ export default class OptionManager { try { if (typeof val === "string") { presetLoc = resolve(`babel-preset-${val}`, dirname) || resolve(val, dirname); + + // trying to resolve @organization shortcat + // @foo/es2015 -> @foo/babel-preset-es2015 + if (!presetLoc) { + let matches = val.match(/^(@[^/]+)\/(.+)$/); + if (matches) { + let [, orgName, presetPath] = matches; + val = `${orgName}/babel-preset-${presetPath}`; + presetLoc = resolve(val, dirname); + } + } + if (!presetLoc) { throw new Error(`Couldn't find preset ${JSON.stringify(val)} relative to directory ` + JSON.stringify(dirname)); diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index 3e79693e2bc3..bae3b506b128 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -185,6 +185,28 @@ suite("api", function () { }); + test("handles preset shortcuts (adds babel-preset-)", function () { + return assert.throws( + function () { + babel.transform("", { + presets: ["@babel/es2015"] + }); + }, + /Couldn\'t find preset \"\@babel\/babel\-preset\-es2015\" relative to directory/ + ); + }); + + test("handles preset shortcuts 2 (adds babel-preset-)", function () { + return assert.throws( + function () { + babel.transform("", { + presets: ["@babel/react/optimizations"] + }); + }, + /Couldn\'t find preset \"\@babel\/babel\-preset\-react\/optimizations\" relative to directory/ + ); + }); + test("source map merging", function () { var result = babel.transform([ 'function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }',