@modern-js/plugin 1.3.2 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +74 -0
  3. package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +12 -0
  4. package/dist/js/modern/farrow-pipeline/context.js +99 -0
  5. package/dist/js/modern/farrow-pipeline/counter.js +18 -0
  6. package/dist/js/modern/farrow-pipeline/hook.js +42 -0
  7. package/dist/js/modern/farrow-pipeline/index.js +19 -0
  8. package/dist/js/modern/farrow-pipeline/pipeline.js +93 -0
  9. package/dist/js/modern/index.js +1 -1
  10. package/dist/js/modern/manager/async.js +1 -1
  11. package/dist/js/modern/manager/runner.js +1 -1
  12. package/dist/js/modern/manager/sync.js +2 -3
  13. package/dist/js/modern/waterfall/async.js +5 -9
  14. package/dist/js/modern/waterfall/sync.js +5 -9
  15. package/dist/js/modern/workflow/async.js +2 -5
  16. package/dist/js/modern/workflow/parallel.js +3 -4
  17. package/dist/js/modern/workflow/sync.js +2 -2
  18. package/dist/js/node/farrow-pipeline/asyncHooks.node.js +93 -0
  19. package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +26 -0
  20. package/dist/js/node/farrow-pipeline/context.js +120 -0
  21. package/dist/js/node/farrow-pipeline/counter.js +27 -0
  22. package/dist/js/node/farrow-pipeline/hook.js +52 -0
  23. package/dist/js/node/farrow-pipeline/index.js +18 -0
  24. package/dist/js/node/farrow-pipeline/pipeline.js +129 -0
  25. package/dist/js/node/index.js +1 -1
  26. package/dist/js/node/manager/async.js +1 -1
  27. package/dist/js/node/manager/runner.js +1 -1
  28. package/dist/js/node/manager/sync.js +2 -3
  29. package/dist/js/node/waterfall/async.js +5 -9
  30. package/dist/js/node/waterfall/sync.js +5 -9
  31. package/dist/js/node/workflow/async.js +2 -5
  32. package/dist/js/node/workflow/parallel.js +3 -4
  33. package/dist/js/node/workflow/sync.js +2 -2
  34. package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +74 -0
  35. package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +12 -0
  36. package/dist/js/treeshaking/farrow-pipeline/context.js +103 -0
  37. package/dist/js/treeshaking/farrow-pipeline/counter.js +23 -0
  38. package/dist/js/treeshaking/farrow-pipeline/hook.js +46 -0
  39. package/dist/js/treeshaking/farrow-pipeline/index.js +19 -0
  40. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +100 -0
  41. package/dist/js/treeshaking/index.js +1 -1
  42. package/dist/js/treeshaking/manager/async.js +5 -26
  43. package/dist/js/treeshaking/manager/runner.js +1 -1
  44. package/dist/js/treeshaking/manager/sync.js +6 -25
  45. package/dist/js/treeshaking/waterfall/async.js +13 -37
  46. package/dist/js/treeshaking/waterfall/sync.js +12 -32
  47. package/dist/js/treeshaking/workflow/async.js +7 -29
  48. package/dist/js/treeshaking/workflow/parallel.js +7 -27
  49. package/dist/js/treeshaking/workflow/sync.js +6 -25
  50. package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +2 -0
  51. package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +19 -0
  52. package/dist/types/farrow-pipeline/context.d.ts +28 -0
  53. package/dist/types/farrow-pipeline/counter.d.ts +11 -0
  54. package/dist/types/farrow-pipeline/hook.d.ts +9 -0
  55. package/dist/types/farrow-pipeline/index.d.ts +19 -0
  56. package/dist/types/farrow-pipeline/pipeline.d.ts +38 -0
  57. package/dist/types/index.d.ts +1 -1
  58. package/dist/types/manager/runner.d.ts +1 -1
  59. package/dist/types/manager/sync.d.ts +1 -1
  60. package/dist/types/manager/types.d.ts +1 -1
  61. package/dist/types/waterfall/async.d.ts +1 -1
  62. package/dist/types/waterfall/sync.d.ts +1 -1
  63. package/dist/types/workflow/async.d.ts +1 -1
  64. package/dist/types/workflow/sync.d.ts +1 -1
  65. package/package.json +37 -8
  66. package/jest.config.js +0 -8
  67. package/modern.config.js +0 -2
  68. package/node.d.ts +0 -1
  69. package/node.js +0 -1
  70. package/tests/.eslintrc.js +0 -6
  71. package/tests/async.test.ts +0 -738
  72. package/tests/fixtures/async/base/bar.ts +0 -22
  73. package/tests/fixtures/async/base/foo.ts +0 -20
  74. package/tests/fixtures/async/base/fooManager.ts +0 -47
  75. package/tests/fixtures/async/core/index.ts +0 -174
  76. package/tests/fixtures/async/dynamic/bar.ts +0 -18
  77. package/tests/fixtures/async/dynamic/foo.ts +0 -27
  78. package/tests/fixtures/sync/base/bar.ts +0 -21
  79. package/tests/fixtures/sync/base/foo.ts +0 -20
  80. package/tests/fixtures/sync/base/fooManager.ts +0 -47
  81. package/tests/fixtures/sync/core/index.ts +0 -171
  82. package/tests/fixtures/sync/dynamic/bar.ts +0 -22
  83. package/tests/fixtures/sync/dynamic/foo.ts +0 -27
  84. package/tests/helpers.ts +0 -4
  85. package/tests/pipeline.test.ts +0 -607
  86. package/tests/sync.test.ts +0 -701
  87. package/tests/tsconfig.json +0 -13
  88. package/tests/waterfall.test.ts +0 -172
  89. package/tests/workflow.test.ts +0 -111
  90. package/tsconfig.json +0 -14
@@ -1,701 +0,0 @@
1
- // eslint-disable-next-line eslint-comments/disable-enable-pair
2
- /* eslint-disable max-lines */
3
- import {
4
- createPipeline,
5
- createAsyncPipeline,
6
- createContext,
7
- createContainer,
8
- } from 'farrow-pipeline';
9
- import type { PluginOptions, Setup } from '../src';
10
- import { createManager, createAsyncManager, useRunner } from '../src/manager';
11
- import { createWaterfall, createAsyncWaterfall } from '../src/waterfall';
12
- import {
13
- createWorkflow,
14
- createAsyncWorkflow,
15
- createParallelWorkflow,
16
- } from '../src/workflow';
17
- import { main, TestHooks, TestPlugin } from './fixtures/sync/core';
18
- import foo from './fixtures/sync/base/foo';
19
- import bar, { getBar } from './fixtures/sync/base/bar';
20
- import dFoo from './fixtures/sync/dynamic/foo';
21
- import dBar, { getNumber, setNumber } from './fixtures/sync/dynamic/bar';
22
-
23
- describe('sync manager', () => {
24
- it('base useage', () => {
25
- const countContext = createContext(0);
26
- const useCount = () => countContext.use().value;
27
- const manager = createManager();
28
-
29
- manager.usePlugin(
30
- manager.createPlugin(() => {
31
- expect(useCount()).toBe(1);
32
- }),
33
- );
34
-
35
- manager.run(() => {
36
- countContext.set(1);
37
- });
38
-
39
- expect(manager.run(() => countContext.get())).toBe(1);
40
- });
41
-
42
- it('with sub waterfall', () => {
43
- type Context = {
44
- count: number;
45
- };
46
-
47
- type Config = {
48
- mode: string;
49
- };
50
-
51
- const prepare = createWaterfall<{
52
- config: Config;
53
- }>();
54
-
55
- const preDev = createWaterfall<{
56
- context: Context;
57
- }>();
58
-
59
- const postDev = createWaterfall<{
60
- context: Context;
61
- }>();
62
-
63
- const manager = createManager({ prepare, preDev, postDev });
64
-
65
- const runner = manager.init();
66
-
67
- const prepareResult = runner.prepare({ config: { mode: 'test' } });
68
- const preDevResult = runner.preDev({ context: { count: 0 } });
69
- const postDevResult = runner.postDev({ context: { count: 1 } });
70
-
71
- expect(prepareResult).toStrictEqual({ config: { mode: 'test' } });
72
- expect(preDevResult).toStrictEqual({ context: { count: 0 } });
73
- expect(postDevResult).toStrictEqual({ context: { count: 1 } });
74
- });
75
-
76
- it('could without progress hook in plugin', () => {
77
- // eslint-disable-next-line @typescript-eslint/no-shadow
78
- const foo = createWaterfall<number>();
79
- const manager = createManager({ foo });
80
-
81
- // eslint-disable-next-line @typescript-eslint/no-empty-function
82
- const plugin = manager.createPlugin(() => {});
83
- manager.usePlugin(plugin);
84
-
85
- const runner = manager.init();
86
-
87
- expect(runner.foo(0)).toBe(0);
88
- });
89
-
90
- describe('pre order plugin', () => {
91
- it('default order is right order', () => {
92
- const manager = createManager();
93
-
94
- const list: number[] = [];
95
- const plugin0 = manager.createPlugin(
96
- () => {
97
- list.push(0);
98
- },
99
- { name: 'plugin0' },
100
- );
101
- const plugin1 = manager.createPlugin(
102
- () => {
103
- list.push(1);
104
- },
105
- {
106
- name: 'plugin1',
107
- pre: ['plugin0'],
108
- },
109
- );
110
- const plugin2 = manager.createPlugin(
111
- () => {
112
- list.push(2);
113
- },
114
- { name: 'plugin2' },
115
- );
116
-
117
- manager.usePlugin(plugin0, plugin1, plugin2);
118
-
119
- manager.init();
120
-
121
- expect(list).toStrictEqual([0, 1, 2]);
122
- });
123
-
124
- it('default order is incorrect order', () => {
125
- const manager = createManager();
126
-
127
- const list: number[] = [];
128
- const plugin0 = manager.createPlugin(
129
- () => {
130
- list.push(0);
131
- },
132
- {
133
- name: 'plugin0',
134
- pre: ['plugin1'],
135
- },
136
- );
137
- const plugin1 = manager.createPlugin(
138
- () => {
139
- list.push(1);
140
- },
141
- { name: 'plugin1' },
142
- );
143
- const plugin2 = manager.createPlugin(
144
- () => {
145
- list.push(2);
146
- },
147
- { name: 'plugin2' },
148
- );
149
-
150
- manager.usePlugin(plugin0, plugin1, plugin2);
151
-
152
- manager.init();
153
-
154
- expect(list).toStrictEqual([1, 0, 2]);
155
- });
156
- });
157
-
158
- describe('post order plugin', () => {
159
- it('default order is right order', () => {
160
- const manager = createManager();
161
-
162
- const list: number[] = [];
163
- const plugin0 = manager.createPlugin(
164
- () => {
165
- list.push(0);
166
- },
167
- {
168
- name: 'plugin0',
169
- post: ['plugin1'],
170
- },
171
- );
172
- const plugin1 = manager.createPlugin(
173
- () => {
174
- list.push(1);
175
- },
176
- { name: 'plugin1' },
177
- );
178
- const plugin2 = manager.createPlugin(
179
- () => {
180
- list.push(2);
181
- },
182
- { name: 'plugin2' },
183
- );
184
-
185
- manager.usePlugin(plugin0, plugin1, plugin2);
186
-
187
- manager.init();
188
-
189
- expect(list).toStrictEqual([0, 1, 2]);
190
- });
191
-
192
- it('default order is incorrect order', () => {
193
- const manager = createManager();
194
-
195
- const list: number[] = [];
196
- const plugin0 = manager.createPlugin(
197
- () => {
198
- list.push(0);
199
- },
200
- { name: 'plugin0' },
201
- );
202
- const plugin1 = manager.createPlugin(
203
- () => {
204
- list.push(1);
205
- },
206
- {
207
- name: 'plugin1',
208
- post: ['plugin0'],
209
- },
210
- );
211
- const plugin2 = manager.createPlugin(
212
- () => {
213
- list.push(2);
214
- },
215
- { name: 'plugin2' },
216
- );
217
-
218
- manager.usePlugin(plugin0, plugin1, plugin2);
219
-
220
- manager.init();
221
-
222
- expect(list).toStrictEqual([1, 0, 2]);
223
- });
224
-
225
- it('should support more plugin', () => {
226
- const manager = createManager();
227
-
228
- let status = 0;
229
- const plugin1 = manager.createPlugin(
230
- () => {
231
- status = 1;
232
- },
233
- { name: 'plugin1' },
234
- );
235
-
236
- const plugin2 = manager.createPlugin(() => {
237
- status = 2;
238
- });
239
-
240
- const plugin3 = manager.createPlugin(() => {
241
- status = 3;
242
- });
243
-
244
- const plugin4 = manager.createPlugin(
245
- () => {
246
- status = 4;
247
- },
248
- { post: ['plugin1'] },
249
- );
250
-
251
- manager.usePlugin(plugin1);
252
- manager.usePlugin(plugin2);
253
- manager.usePlugin(plugin3);
254
- manager.usePlugin(plugin4);
255
-
256
- manager.init({});
257
-
258
- expect(status).toBe(1);
259
- });
260
- });
261
-
262
- describe('rivals plugin', () => {
263
- it('should throw error when attaching rival plugin', () => {
264
- const manager = createManager();
265
-
266
- // eslint-disable-next-line @typescript-eslint/no-empty-function
267
- const plugin1 = manager.createPlugin(() => {}, { name: 'plugin1' });
268
-
269
- // eslint-disable-next-line @typescript-eslint/no-empty-function
270
- const plugin2 = manager.createPlugin(() => {}, { rivals: ['plugin1'] });
271
-
272
- manager.usePlugin(plugin1);
273
- manager.usePlugin(plugin2);
274
-
275
- expect(() => manager.init({})).toThrowError();
276
- });
277
-
278
- it('should not throw error without attaching rival plugin', () => {
279
- const manager = createManager();
280
-
281
- let count = 0;
282
- const plugin0 = manager.createPlugin(
283
- () => {
284
- count = 0;
285
- },
286
- { name: 'plugin0' },
287
- );
288
- const plugin1 = manager.createPlugin(
289
- () => {
290
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
291
- count += 1;
292
- },
293
- {
294
- name: 'plugin1',
295
- rivals: ['plugin2'],
296
- },
297
- );
298
-
299
- manager.usePlugin(plugin0, plugin1);
300
-
301
- manager.init();
302
- });
303
- });
304
-
305
- describe('required plugin', () => {
306
- it('should throw error when it is without required plugin', () => {
307
- const manager = createManager();
308
-
309
- // eslint-disable-next-line @typescript-eslint/no-empty-function
310
- const plugin0 = manager.createPlugin(() => {}, {
311
- name: 'plugin0',
312
- required: ['plugin1'],
313
- });
314
-
315
- manager.usePlugin(plugin0);
316
-
317
- expect(manager.init).toThrowError();
318
- });
319
-
320
- it('should not throw error without attaching rival plugin', () => {
321
- const manager = createManager();
322
-
323
- let count = 0;
324
- const plugin0 = manager.createPlugin(
325
- () => {
326
- count = 0;
327
- },
328
- {
329
- name: 'plugin0',
330
- required: ['plugin1'],
331
- },
332
- );
333
- const plugin1 = manager.createPlugin(
334
- () => {
335
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
336
- count += 1;
337
- },
338
- { name: 'plugin1' },
339
- );
340
-
341
- manager.usePlugin(plugin0, plugin1);
342
-
343
- manager.init();
344
- });
345
- });
346
-
347
- it('common attach plugin', () => {
348
- const manager = main.clone().usePlugin(foo).usePlugin(bar);
349
-
350
- expect(getBar()).toBe(0);
351
-
352
- const runner = manager.init();
353
-
354
- expect(getBar()).toBe(1);
355
-
356
- runner.preDev();
357
-
358
- expect(getBar()).toBe(2);
359
-
360
- runner.postDev();
361
-
362
- expect(getBar()).toBe(3);
363
- });
364
-
365
- it('should support dynamic register', () => {
366
- const manager = main.clone().usePlugin(dFoo).usePlugin(dBar);
367
-
368
- expect(getNumber()).toBe(0);
369
-
370
- const runner = manager.init();
371
-
372
- expect(getNumber()).toBe(1);
373
-
374
- runner.preDev();
375
-
376
- expect(getNumber()).toBe(2);
377
- });
378
-
379
- it('should de-duplicate plugins', () => {
380
- const manager = createManager();
381
-
382
- let count = 0;
383
- const plugin = manager.createPlugin(() => {
384
- count += 1;
385
- });
386
-
387
- manager.usePlugin(plugin, plugin);
388
- manager.usePlugin(plugin);
389
-
390
- manager.init();
391
-
392
- expect(count).toBe(1);
393
- });
394
-
395
- it('should support manager clone and override pluginAPI', done => {
396
- const myAPI = { hello: () => 1 };
397
- const manager = createManager({}, myAPI);
398
- const plugin = {
399
- setup(api: typeof myAPI) {
400
- expect(api.hello()).toEqual(2);
401
- done();
402
- },
403
- };
404
- const clonedManager = manager.clone({
405
- hello: () => 2,
406
- });
407
-
408
- clonedManager.usePlugin(plugin).init();
409
- });
410
-
411
- it('isPlugin: exclusive plugins of manager', () => {
412
- const manager0 = createAsyncManager();
413
- const manager1 = createManager();
414
-
415
- // eslint-disable-next-line @typescript-eslint/no-empty-function
416
- const plugin = manager0.createPlugin(() => {});
417
-
418
- expect(manager0.isPlugin(plugin)).toBeTruthy();
419
- expect(manager1.isPlugin(plugin)).toBeFalsy();
420
- expect(manager1.isPlugin({})).toBeFalsy();
421
- expect(manager1.isPlugin('' as any)).toBeFalsy();
422
- });
423
-
424
- it('should support clear plugins', () => {
425
- setNumber(0);
426
-
427
- const manager = main.clone().usePlugin(dFoo).usePlugin(dBar);
428
-
429
- manager.clear();
430
-
431
- expect(getNumber()).toBe(0);
432
-
433
- const runner = manager.init();
434
-
435
- expect(getNumber()).toBe(0);
436
-
437
- runner.preDev();
438
-
439
- expect(getNumber()).toBe(0);
440
- });
441
-
442
- it('should run under the internal container', () => {
443
- const manager = createManager();
444
- const Count = createContext(0);
445
-
446
- const plugin = manager.createPlugin(() => {
447
- Count.set(1);
448
- });
449
-
450
- manager.usePlugin(plugin);
451
-
452
- manager.init();
453
- expect(manager.run(Count.get)).toBe(1);
454
-
455
- const container = createContainer();
456
-
457
- manager.init({ container });
458
- expect(manager.run(Count.get, { container })).toBe(1);
459
- });
460
-
461
- it('should support all progress', async () => {
462
- const manager = createManager({
463
- pipeline: createPipeline(),
464
- asyncPipeline: createAsyncPipeline(),
465
- waterfall: createWaterfall(),
466
- asyncWaterfall: createAsyncWaterfall(),
467
- workflow: createWorkflow(),
468
- asyncWorkflow: createAsyncWorkflow(),
469
- parallelWorkflow: createParallelWorkflow(),
470
- });
471
-
472
- const list: string[] = [];
473
- const plugin = manager.createPlugin(() => ({
474
- pipeline: () => {
475
- list.push('pipeline');
476
- },
477
- asyncPipeline: () => {
478
- list.push('asyncPipeline');
479
- },
480
- waterfall: () => {
481
- list.push('waterfall');
482
- },
483
- asyncWaterfall: () => {
484
- list.push('asyncWaterfall');
485
- },
486
- workflow: () => {
487
- list.push('workflow');
488
- },
489
- asyncWorkflow: () => {
490
- list.push('asyncWorkflow');
491
- },
492
- parallelWorkflow: () => {
493
- list.push('parallelWorkflow');
494
- },
495
- }));
496
- manager.usePlugin(plugin);
497
-
498
- const runner = manager.init();
499
-
500
- runner.pipeline({});
501
- await runner.asyncPipeline({});
502
- runner.waterfall();
503
- await runner.asyncWaterfall();
504
- runner.workflow();
505
- await runner.asyncWorkflow();
506
- await runner.parallelWorkflow();
507
-
508
- expect(list).toStrictEqual([
509
- 'pipeline',
510
- 'asyncPipeline',
511
- 'waterfall',
512
- 'asyncWaterfall',
513
- 'workflow',
514
- 'asyncWorkflow',
515
- 'parallelWorkflow',
516
- ]);
517
- });
518
-
519
- it('should throw error when progress is illegal', () => {
520
- const manager = createManager({ test: '' as any });
521
-
522
- // eslint-disable-next-line @typescript-eslint/no-empty-function
523
- const plugin = manager.createPlugin(() => {});
524
-
525
- manager.usePlugin(plugin);
526
-
527
- expect(manager.init).toThrowError();
528
- });
529
-
530
- describe('useRunner', () => {
531
- it('base usage', () => {
532
- // eslint-disable-next-line @typescript-eslint/no-shadow
533
- const foo = createPipeline();
534
- // eslint-disable-next-line @typescript-eslint/no-shadow
535
- const bar = createPipeline();
536
- const manager = createManager({ foo, bar });
537
-
538
- let count = 0;
539
-
540
- const plugin = manager.createPlugin(() => ({
541
- foo: () => {
542
- // eslint-disable-next-line react-hooks/rules-of-hooks
543
- const runner = useRunner();
544
- runner.bar();
545
- },
546
- bar: () => {
547
- count = 1;
548
- },
549
- }));
550
- manager.usePlugin(plugin);
551
-
552
- const runner = manager.init();
553
- runner.foo({});
554
-
555
- expect(count).toBe(1);
556
- });
557
-
558
- it('can not use useRunner out plugin hook', () => {
559
- expect(useRunner).toThrowError(
560
- new Error(
561
- `Can't call useContainer out of scope, it should be placed on top of the function`,
562
- ),
563
- );
564
- });
565
- });
566
-
567
- describe('setup api', () => {
568
- it('should allow to access api.useHookRunners by default', done => {
569
- const manager = createManager<TestHooks>();
570
- const plugin: TestPlugin = {
571
- name: 'plugin',
572
- setup: api => {
573
- expect(api.useHookRunners).toBeTruthy();
574
- done();
575
- },
576
- };
577
- manager.usePlugin(plugin);
578
- manager.init();
579
- });
580
-
581
- it('should allow to register extra api', done => {
582
- type API = { foo: () => void };
583
-
584
- const manager = createAsyncManager<TestHooks, API>(
585
- {},
586
- // eslint-disable-next-line @typescript-eslint/no-empty-function
587
- { foo: () => {} },
588
- );
589
-
590
- const plugin: PluginOptions<TestHooks, Setup<TestHooks, API>> = {
591
- name: 'plugin',
592
- setup: api => {
593
- expect(api.foo).toBeTruthy();
594
- done();
595
- },
596
- };
597
-
598
- manager.usePlugin(plugin);
599
- manager.init();
600
- });
601
- });
602
-
603
- describe('usePlugins option', () => {
604
- it('should allow to use single plugin', async () => {
605
- const manager = createManager<TestHooks>();
606
-
607
- const list: number[] = [];
608
- const plugin0: TestPlugin = {
609
- name: 'plugin0',
610
- setup: () => {
611
- list.push(0);
612
- },
613
- };
614
-
615
- const plugin1: TestPlugin = {
616
- name: 'plugin1',
617
- usePlugins: [plugin0],
618
- setup: () => {
619
- list.push(1);
620
- },
621
- };
622
-
623
- manager.usePlugin(plugin1);
624
- manager.init();
625
-
626
- expect(list).toStrictEqual([0, 1]);
627
- });
628
-
629
- it('should allow to use multiple plugins', async () => {
630
- const manager = createManager<TestHooks>();
631
-
632
- const list: number[] = [];
633
- const plugin0: TestPlugin = {
634
- name: 'plugin0',
635
- setup: () => {
636
- list.push(0);
637
- },
638
- };
639
-
640
- const plugin1: TestPlugin = {
641
- name: 'plugin1',
642
- usePlugins: [plugin0],
643
- setup: () => {
644
- list.push(1);
645
- },
646
- };
647
-
648
- const plugin2: TestPlugin = {
649
- name: 'plugin2',
650
- usePlugins: [plugin1],
651
- setup: () => {
652
- list.push(2);
653
- },
654
- };
655
-
656
- manager.usePlugin(plugin2);
657
- manager.init();
658
-
659
- expect(list).toStrictEqual([0, 1, 2]);
660
- });
661
-
662
- it('should allow to use plugin without setup function', async () => {
663
- const manager = createManager<TestHooks>();
664
-
665
- const list: number[] = [];
666
- const plugin0: TestPlugin = {
667
- name: 'plugin0',
668
- setup: () => {
669
- list.push(0);
670
- },
671
- };
672
-
673
- const plugin1: TestPlugin = {
674
- name: 'plugin1',
675
- usePlugins: [plugin0],
676
- };
677
-
678
- manager.usePlugin(plugin1);
679
- manager.init();
680
-
681
- expect(list).toStrictEqual([0]);
682
- });
683
-
684
- it('should allow to use function plugin', async () => {
685
- const manager = createManager<TestHooks>();
686
-
687
- const list: number[] = [];
688
- const plugin0: TestPlugin = {
689
- name: 'plugin0',
690
- setup: () => {
691
- list.push(0);
692
- },
693
- };
694
-
695
- manager.usePlugin(() => plugin0);
696
- manager.init();
697
-
698
- expect(list).toStrictEqual([0]);
699
- });
700
- });
701
- });
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": false,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "isolatedModules": true,
8
- "target": "ES5",
9
- "esModuleInterop": true,
10
- "paths": {},
11
- "types": ["node", "jest"]
12
- }
13
- }