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