Expose a function rather than a class from option-manager.
This commit is contained in:
parent
86fc4fbc4f
commit
258e82ca13
@ -1,5 +1,5 @@
|
||||
import type Plugin from "./plugin";
|
||||
import OptionManager from "./option-manager";
|
||||
import manageOptions from "./option-manager";
|
||||
|
||||
export type ResolvedConfig = {
|
||||
options: Object,
|
||||
@ -10,7 +10,7 @@ export type ResolvedConfig = {
|
||||
* Standard API for loading Babel configuration data. Not for public consumption.
|
||||
*/
|
||||
export default function loadConfig(opts: Object): ResolvedConfig|null {
|
||||
const mergedOpts = new OptionManager().init(opts);
|
||||
const mergedOpts = manageOptions(opts);
|
||||
if (!mergedOpts) return null;
|
||||
|
||||
let passes = [];
|
||||
|
||||
@ -85,7 +85,11 @@ const ALLOWED_PLUGIN_KEYS = new Set([
|
||||
"inherits",
|
||||
]);
|
||||
|
||||
export default class OptionManager {
|
||||
export default function manageOptions(opts?: Object) {
|
||||
return new OptionManager().init(opts);
|
||||
}
|
||||
|
||||
class OptionManager {
|
||||
constructor() {
|
||||
this.options = OptionManager.createBareOptions();
|
||||
}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import assert from "assert";
|
||||
import OptionManager from "../lib/config/option-manager";
|
||||
import manageOptions from "../lib/config/option-manager";
|
||||
import path from "path";
|
||||
|
||||
describe("option-manager", () => {
|
||||
it("throws for babel 5 plugin", () => {
|
||||
return assert.throws(() => {
|
||||
const opt = new OptionManager();
|
||||
opt.init({
|
||||
manageOptions({
|
||||
plugins: [
|
||||
({ Plugin }) => new Plugin("object-assign", {}),
|
||||
],
|
||||
@ -18,8 +17,7 @@ describe("option-manager", () => {
|
||||
it("throws for removed babel 5 options", () => {
|
||||
return assert.throws(
|
||||
() => {
|
||||
const opt = new OptionManager();
|
||||
opt.init({
|
||||
manageOptions({
|
||||
"randomOption": true,
|
||||
});
|
||||
},
|
||||
@ -30,8 +28,7 @@ describe("option-manager", () => {
|
||||
it("throws for removed babel 5 options", () => {
|
||||
return assert.throws(
|
||||
() => {
|
||||
const opt = new OptionManager();
|
||||
opt.init({
|
||||
manageOptions({
|
||||
"auxiliaryComment": true,
|
||||
"blacklist": true,
|
||||
});
|
||||
@ -44,8 +41,7 @@ describe("option-manager", () => {
|
||||
it("throws for resolved but erroring preset", () => {
|
||||
return assert.throws(
|
||||
() => {
|
||||
const opt = new OptionManager();
|
||||
opt.init({
|
||||
manageOptions({
|
||||
"presets": [path.join(__dirname, "fixtures/option-manager/not-a-preset")],
|
||||
});
|
||||
},
|
||||
@ -57,8 +53,7 @@ describe("option-manager", () => {
|
||||
describe("presets", function () {
|
||||
function presetTest(name) {
|
||||
it(name, function () {
|
||||
const opt = new OptionManager();
|
||||
const options = opt.init({
|
||||
const options = manageOptions({
|
||||
"presets": [path.join(__dirname, "fixtures/option-manager/presets", name)],
|
||||
});
|
||||
|
||||
@ -69,8 +64,7 @@ describe("option-manager", () => {
|
||||
|
||||
function presetThrowsTest(name, msg) {
|
||||
it(name, function () {
|
||||
const opt = new OptionManager();
|
||||
assert.throws(() => opt.init({
|
||||
assert.throws(() => manageOptions({
|
||||
"presets": [path.join(__dirname, "fixtures/option-manager/presets", name)],
|
||||
}), msg);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user