Skip to content

Commit

Permalink
Restore public API of resolvePlugin/resolvePreset (#16888)
Browse files Browse the repository at this point in the history
* Restore public API of `resolvePlugin`/`resolvePreset`

* Prettier

* Add test
  • Loading branch information
nicolo-ribaudo authored Oct 9, 2024
1 parent cad088b commit 2570cfd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
29 changes: 18 additions & 11 deletions packages/babel-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ export const version = PACKAGE_JSON.version;
export { default as File } from "./transformation/file/file.ts";
export type { default as PluginPass } from "./transformation/plugin-pass.ts";
export { default as buildExternalHelpers } from "./tools/build-external-helpers.ts";
export { resolvePlugin, resolvePreset } from "./config/files/index.ts";

import * as resolvers from "./config/files/index.ts";
// For backwards-compatibility, we expose the resolvers
// with the old API.
export const resolvePlugin = (name: string, dirname: string) =>
resolvers.resolvePlugin(name, dirname, false).filepath;
export const resolvePreset = (name: string, dirname: string) =>
resolvers.resolvePreset(name, dirname, false).filepath;

export { getEnv } from "./config/helpers/environment.ts";

Expand All @@ -30,47 +37,47 @@ export type Visitor<S = unknown> = import("@babel/traverse").Visitor<S>;

export {
createConfigItem,
createConfigItemSync,
createConfigItemAsync,
createConfigItemSync,
} from "./config/index.ts";

export {
loadPartialConfig,
loadPartialConfigSync,
loadPartialConfigAsync,
loadOptions,
loadOptionsAsync,
loadPartialConfig,
loadPartialConfigAsync,
loadPartialConfigSync,
} from "./config/index.ts";
import { loadOptionsSync } from "./config/index.ts";
export { loadOptionsSync };

export type {
CallerMetadata,
ConfigItem,
InputOptions,
PluginAPI,
PluginObject,
PresetAPI,
PresetObject,
ConfigItem,
} from "./config/index.ts";

export {
type FileResult,
transform,
transformSync,
transformAsync,
type FileResult,
transformSync,
} from "./transform.ts";
export {
transformFile,
transformFileSync,
transformFileAsync,
transformFileSync,
} from "./transform-file.ts";
export {
transformFromAst,
transformFromAstSync,
transformFromAstAsync,
transformFromAstSync,
} from "./transform-ast.ts";
export { parse, parseSync, parseAsync } from "./parse.ts";
export { parse, parseAsync, parseSync } from "./parse.ts";

/**
* Recommended set of compilable extensions. Not used in @babel/core directly, but meant as
Expand Down
16 changes: 16 additions & 0 deletions packages/babel-core/test/resolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,20 @@ describe("addon resolution", function () {
).code,
).toBe(`"ESM"`);
});

it("resolvePreset", function () {
expect(
babel.resolvePreset("@babel/foo", path.join(base, "babel-org-paths")),
).toMatch(
/babel-org-paths[\\/]node_modules[\\/]@babel[\\/]preset-foo[\\/]index.js/,
);
});

it("resolvePlugin", function () {
expect(
babel.resolvePlugin("@babel/foo", path.join(base, "babel-org-paths")),
).toMatch(
/babel-org-paths[\\/]node_modules[\\/]@babel[\\/]plugin-foo[\\/]index.js/,
);
});
});

0 comments on commit 2570cfd

Please sign in to comment.