Skip to content

Commit 6579ae0

Browse files
committed
feat: make Base.plugin() accept an array instead of
BREAKING CHANGE: `Base.plugin()` now only accepts a single argument which has to be an array of plugin functions
1 parent 3a30c56 commit 6579ae0

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export declare class Base<TOptions extends Base.Options = Base.Options> {
9191
Plugins extends [Plugin, ...Plugin[]]
9292
>(
9393
this: Class,
94-
...plugins: Plugins
94+
plugins: Plugins
9595
): Class & {
9696
plugins: [...Class["plugins"], ...Plugins];
9797
} & Constructor<UnionToIntersection<ReturnTypeOf<Plugins>>>;

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class Base {
66
});
77
}
88

9-
static plugin(...newPlugins) {
9+
static plugin(newPlugins) {
1010
const currentPlugins = this.plugins;
1111
return class extends this {
1212
static plugins = currentPlugins.concat(

index.test-d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ new BaseWithEmptyDefaults();
3333
// @ts-expect-error
3434
new BaseWithEmptyDefaults({});
3535

36-
const BaseLevelOne = Base.plugin(fooPlugin).defaults({
36+
const BaseLevelOne = Base.plugin([fooPlugin]).defaults({
3737
defaultOne: "value",
3838
required: "1.2.3",
3939
});
@@ -121,15 +121,15 @@ expectType<string>(baseLevelThree.options.required);
121121
// @ts-expect-error unknown properties cannot be used, see #31
122122
baseLevelThree.unknown;
123123

124-
const BaseWithVoidPlugin = Base.plugin(voidPlugin);
124+
const BaseWithVoidPlugin = Base.plugin([voidPlugin]);
125125
const baseWithVoidPlugin = new BaseWithVoidPlugin({
126126
required: "1.2.3",
127127
});
128128

129129
// @ts-expect-error unknown properties cannot be used, see #31
130130
baseWithVoidPlugin.unknown;
131131

132-
const BaseWithFooAndBarPlugins = Base.plugin(barPlugin, fooPlugin);
132+
const BaseWithFooAndBarPlugins = Base.plugin([barPlugin, fooPlugin]);
133133
const baseWithFooAndBarPlugins = new BaseWithFooAndBarPlugins({
134134
required: "1.2.3",
135135
});
@@ -140,11 +140,11 @@ expectType<string>(baseWithFooAndBarPlugins.bar);
140140
// @ts-expect-error unknown properties cannot be used, see #31
141141
baseWithFooAndBarPlugins.unknown;
142142

143-
const BaseWithVoidAndNonVoidPlugins = Base.plugin(
143+
const BaseWithVoidAndNonVoidPlugins = Base.plugin([
144144
barPlugin,
145145
voidPlugin,
146-
fooPlugin
147-
);
146+
fooPlugin,
147+
]);
148148
const baseWithVoidAndNonVoidPlugins = new BaseWithVoidAndNonVoidPlugins({
149149
required: "1.2.3",
150150
});
@@ -155,7 +155,7 @@ expectType<string>(baseWithVoidAndNonVoidPlugins.bar);
155155
// @ts-expect-error unknown properties cannot be used, see #31
156156
baseWithVoidAndNonVoidPlugins.unknown;
157157

158-
const BaseWithOptionsPlugin = Base.plugin(withOptionsPlugin);
158+
const BaseWithOptionsPlugin = Base.plugin([withOptionsPlugin]);
159159
const baseWithOptionsPlugin = new BaseWithOptionsPlugin({
160160
required: "1.2.3",
161161
});
@@ -196,7 +196,7 @@ expectType<{
196196
const BaseWithChainedDefaultsAndPlugins = Base.defaults({
197197
defaultOne: "value",
198198
})
199-
.plugin(fooPlugin)
199+
.plugin([fooPlugin])
200200
.defaults({
201201
defaultTwo: 0,
202202
});
@@ -212,11 +212,11 @@ expectType<string>(baseWithChainedDefaultsAndPlugins.foo);
212212
const BaseWithManyChainedDefaultsAndPlugins = Base.defaults({
213213
defaultOne: "value",
214214
})
215-
.plugin(fooPlugin, barPlugin, voidPlugin)
215+
.plugin([fooPlugin, barPlugin, voidPlugin])
216216
.defaults({
217217
defaultTwo: 0,
218218
})
219-
.plugin(withOptionsPlugin)
219+
.plugin([withOptionsPlugin])
220220
.defaults({
221221
defaultThree: ["a", "b", "c"],
222222
});

test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ import { fooPlugin } from "./plugins/foo/index.js";
66
import { barPlugin } from "./plugins/bar/index.js";
77
import { voidPlugin } from "./plugins/void/index.js";
88

9-
test(".plugin(fooPlugin)", () => {
10-
const FooTest = Base.plugin(fooPlugin);
9+
test(".plugin([fooPlugin])", () => {
10+
const FooTest = Base.plugin([fooPlugin]);
1111
const fooTest = new FooTest();
1212
assert.equal(fooTest.foo, "foo");
1313
});
14-
test(".plugin(fooPlugin, barPlugin)", () => {
15-
const FooBarTest = Base.plugin(fooPlugin, barPlugin);
14+
test(".plugin([fooPlugin, barPlugin])", () => {
15+
const FooBarTest = Base.plugin([fooPlugin, barPlugin]);
1616
const fooBarTest = new FooBarTest();
1717
assert.equal(fooBarTest.foo, "foo");
1818
assert.equal(fooBarTest.bar, "bar");
1919
});
20-
test(".plugin(fooPlugin, barPlugin, voidPlugin)", () => {
21-
const FooBarTest = Base.plugin(fooPlugin, barPlugin, voidPlugin);
20+
test(".plugin([fooPlugin, barPlugin, voidPlugin])", () => {
21+
const FooBarTest = Base.plugin([fooPlugin, barPlugin, voidPlugin]);
2222
const fooBarTest = new FooBarTest();
2323
assert.equal(fooBarTest.foo, "foo");
2424
assert.equal(fooBarTest.bar, "bar");
2525
});
26-
test(".plugin(fooPlugin).plugin(barPlugin)", () => {
27-
const FooBarTest = Base.plugin(fooPlugin).plugin(barPlugin);
26+
test(".plugin([fooPlugin]).plugin(barPlugin)", () => {
27+
const FooBarTest = Base.plugin([fooPlugin]).plugin([barPlugin]);
2828
const fooBarTest = new FooBarTest();
2929
assert.equal(fooBarTest.foo, "foo");
3030
assert.equal(fooBarTest.bar, "bar");
@@ -61,12 +61,12 @@ test(".defaults({foo: 'bar', baz: 'daz' })", () => {
6161
});
6262

6363
test(".plugin().defaults()", () => {
64-
const BaseWithPluginAndDefaults = Base.plugin(fooPlugin).defaults({
64+
const BaseWithPluginAndDefaults = Base.plugin([fooPlugin]).defaults({
6565
baz: "daz",
6666
});
6767
const BaseWithDefaultsAndPlugin = Base.defaults({
6868
baz: "daz",
69-
}).plugin(fooPlugin);
69+
}).plugin([fooPlugin]);
7070

7171
const instance1 = new BaseWithPluginAndDefaults();
7272
const instance2 = new BaseWithDefaultsAndPlugin();

0 commit comments

Comments
 (0)