@modern-js/plugin 1.0.0 → 1.1.2

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 (107) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +1 -4
  3. package/dist/js/modern/index.js +2 -3
  4. package/dist/js/modern/manager/async.js +1 -1
  5. package/dist/js/modern/manager/runner.js +1 -1
  6. package/dist/js/modern/manager/sync.js +1 -6
  7. package/dist/js/modern/waterfall/async.js +28 -34
  8. package/dist/js/modern/waterfall/sync.js +29 -36
  9. package/dist/js/modern/workflow/async.js +31 -30
  10. package/dist/js/modern/workflow/parallel.js +20 -29
  11. package/dist/js/modern/workflow/sync.js +20 -27
  12. package/dist/js/node/index.js +12 -25
  13. package/dist/js/node/manager/async.js +4 -4
  14. package/dist/js/node/manager/runner.js +2 -2
  15. package/dist/js/node/manager/sync.js +6 -12
  16. package/dist/js/node/waterfall/async.js +27 -34
  17. package/dist/js/node/waterfall/sync.js +29 -36
  18. package/dist/js/node/workflow/async.js +30 -30
  19. package/dist/js/node/workflow/parallel.js +19 -29
  20. package/dist/js/node/workflow/sync.js +19 -27
  21. package/dist/js/treeshaking/index.js +2 -3
  22. package/dist/js/treeshaking/manager/async.js +1 -1
  23. package/dist/js/treeshaking/manager/runner.js +1 -1
  24. package/dist/js/treeshaking/manager/sync.js +1 -6
  25. package/dist/js/treeshaking/waterfall/async.js +63 -108
  26. package/dist/js/treeshaking/waterfall/sync.js +36 -39
  27. package/dist/js/treeshaking/workflow/async.js +89 -88
  28. package/dist/js/treeshaking/workflow/parallel.js +42 -66
  29. package/dist/js/treeshaking/workflow/sync.js +50 -30
  30. package/dist/types/index.d.ts +2 -3
  31. package/dist/types/manager/runner.d.ts +1 -1
  32. package/dist/types/manager/sync.d.ts +2 -3
  33. package/dist/types/waterfall/async.d.ts +9 -5
  34. package/dist/types/waterfall/sync.d.ts +4 -4
  35. package/dist/types/workflow/async.d.ts +3 -2
  36. package/dist/types/workflow/parallel.d.ts +1 -1
  37. package/dist/types/workflow/sync.d.ts +1 -1
  38. package/node.d.ts +1 -1
  39. package/node.js +1 -1
  40. package/package.json +5 -4
  41. package/src/index.ts +2 -2
  42. package/src/manager/async.ts +1 -1
  43. package/src/manager/runner.ts +1 -1
  44. package/src/manager/sync.ts +12 -16
  45. package/src/waterfall/async.ts +34 -49
  46. package/src/waterfall/sync.ts +26 -45
  47. package/src/workflow/async.ts +29 -33
  48. package/src/workflow/parallel.ts +17 -35
  49. package/src/workflow/sync.ts +13 -35
  50. package/tests/.eslintrc.js +6 -0
  51. package/tests/async.test.ts +7 -3
  52. package/tests/fixtures/async/base/foo.ts +0 -1
  53. package/tests/fixtures/async/base/fooManager.ts +1 -1
  54. package/tests/fixtures/async/core/index.ts +1 -1
  55. package/tests/fixtures/async/dynamic/bar.ts +0 -1
  56. package/tests/fixtures/async/dynamic/foo.ts +1 -1
  57. package/tests/fixtures/sync/base/foo.ts +0 -2
  58. package/tests/fixtures/sync/base/fooManager.ts +1 -1
  59. package/tests/fixtures/sync/core/index.ts +1 -1
  60. package/tests/fixtures/sync/dynamic/bar.ts +0 -1
  61. package/tests/fixtures/sync/dynamic/foo.ts +1 -1
  62. package/tests/pipeline.test.ts +4 -15
  63. package/tests/sync.test.ts +6 -2
  64. package/tests/waterfall.test.ts +1 -2
  65. package/dist/js/modern/asyncHooksImpl.js +0 -63
  66. package/dist/js/modern/asyncHooksInterface.js +0 -16
  67. package/dist/js/modern/context.js +0 -130
  68. package/dist/js/modern/counter.js +0 -40
  69. package/dist/js/modern/hook.js +0 -47
  70. package/dist/js/modern/pipeline/async.js +0 -97
  71. package/dist/js/modern/pipeline/index.js +0 -2
  72. package/dist/js/modern/pipeline/sync.js +0 -97
  73. package/dist/js/node/asyncHooksImpl.js +0 -82
  74. package/dist/js/node/asyncHooksInterface.js +0 -30
  75. package/dist/js/node/context.js +0 -164
  76. package/dist/js/node/counter.js +0 -52
  77. package/dist/js/node/hook.js +0 -57
  78. package/dist/js/node/pipeline/async.js +0 -110
  79. package/dist/js/node/pipeline/index.js +0 -31
  80. package/dist/js/node/pipeline/sync.js +0 -110
  81. package/dist/js/treeshaking/asyncHooksImpl.js +0 -65
  82. package/dist/js/treeshaking/asyncHooksInterface.js +0 -16
  83. package/dist/js/treeshaking/context.js +0 -137
  84. package/dist/js/treeshaking/counter.js +0 -74
  85. package/dist/js/treeshaking/hook.js +0 -51
  86. package/dist/js/treeshaking/pipeline/async.js +0 -165
  87. package/dist/js/treeshaking/pipeline/index.js +0 -2
  88. package/dist/js/treeshaking/pipeline/sync.js +0 -118
  89. package/dist/types/asyncHooksImpl.d.ts +0 -10
  90. package/dist/types/asyncHooksInterface.d.ts +0 -21
  91. package/dist/types/context.d.ts +0 -47
  92. package/dist/types/counter.d.ts +0 -22
  93. package/dist/types/hook.d.ts +0 -13
  94. package/dist/types/pipeline/async.d.ts +0 -35
  95. package/dist/types/pipeline/index.d.ts +0 -2
  96. package/dist/types/pipeline/sync.d.ts +0 -37
  97. package/src/asyncHooksImpl.ts +0 -64
  98. package/src/asyncHooksInterface.ts +0 -34
  99. package/src/context.ts +0 -184
  100. package/src/counter.ts +0 -78
  101. package/src/hook.ts +0 -46
  102. package/src/pipeline/async.ts +0 -155
  103. package/src/pipeline/index.ts +0 -2
  104. package/src/pipeline/sync.ts +0 -152
  105. package/tests/context.test.ts +0 -114
  106. package/tests/counter.test.ts +0 -32
  107. package/tests/hook.test.ts +0 -113
@@ -1,114 +0,0 @@
1
- import {
2
- createContext,
3
- createContainer,
4
- useContainer,
5
- fromContainer,
6
- runHooks,
7
- isContext,
8
- assertContext,
9
- isContainer,
10
- assertContainer,
11
- } from '@/context';
12
-
13
- describe('context', () => {
14
- it('different values in Containers with same Context', () => {
15
- const Context0 = createContext({ count: 0 });
16
-
17
- const Context1 = createContext({ text: 'test' });
18
-
19
- const container = createContainer();
20
-
21
- expect(container.read(Context0)).toEqual({ count: 0 });
22
-
23
- expect(container.read(Context1)).toEqual({ text: 'test' });
24
-
25
- container.write(Context0, { count: 1 });
26
-
27
- expect(container.read(Context0)).toEqual({ count: 1 });
28
-
29
- container.write(Context1, { text: 'update test' });
30
-
31
- expect(container.read(Context1)).toEqual({ text: 'update test' });
32
- });
33
-
34
- it('inject new Context to Container', () => {
35
- const Context0 = createContext({ count: 0 });
36
-
37
- const Context1 = createContext({ text: 'test' });
38
-
39
- const container = createContainer({
40
- count: Context0.create({ count: 1 }),
41
- text: Context1.create({ text: 'new text' }),
42
- });
43
-
44
- expect(container.read(Context0)).toEqual({ count: 1 });
45
-
46
- expect(container.read(Context1)).toEqual({ text: 'new text' });
47
- });
48
-
49
- it('run hook with container', () => {
50
- const Context0 = createContext({ count: 0 });
51
-
52
- const Context1 = createContext({ text: 'test' });
53
-
54
- const container = createContainer({
55
- count: Context0.create({ count: 1 }),
56
- text: Context1.create({ text: 'new text' }),
57
- });
58
-
59
- runHooks(() => {
60
- const ctn = useContainer();
61
-
62
- expect(container === ctn).toBeTruthy();
63
-
64
- expect(ctn.read(Context0)).toEqual({ count: 1 });
65
-
66
- expect(ctn.read(Context1)).toEqual({ text: 'new text' });
67
- }, fromContainer(container));
68
- });
69
-
70
- it('assert Context', () => {
71
- const context = createContext<number | null>(null);
72
-
73
- const container = createContainer();
74
-
75
- runHooks(() => {
76
- expect(() => context.assert()).toThrowError();
77
-
78
- context.set(0);
79
-
80
- expect(context.assert()).toBe(0);
81
- }, fromContainer(container));
82
- });
83
-
84
- it('isContext', () => {
85
- const context = createContext(0);
86
-
87
- expect(isContext(context)).toBeTruthy();
88
- expect(isContext({})).toBeFalsy();
89
- });
90
-
91
- it('assertContext', () => {
92
- const context = createContext(0);
93
-
94
- assertContext(context);
95
-
96
- expect(() => assertContext({})).toThrowError();
97
- });
98
-
99
- it('isContainer', () => {
100
- const container = createContainer();
101
-
102
- expect(isContainer(container)).toBeTruthy();
103
- expect(isContainer({})).toBeFalsy();
104
- expect(isContainer(null)).toBeFalsy();
105
- });
106
-
107
- it('assertContainer', () => {
108
- const container = createContainer();
109
-
110
- assertContainer(container);
111
-
112
- expect(() => assertContainer({})).toThrowError();
113
- });
114
- });
@@ -1,32 +0,0 @@
1
- import { createCounter, createAsyncCounter } from '@/counter';
2
-
3
- describe('counter', () => {
4
- describe('sync', () => {
5
- it('base usage', () => {
6
- const counter = createCounter<number, number>((index, input, next) => {
7
- if (index >= 10) {
8
- return input;
9
- }
10
- return next(input * 2);
11
- });
12
-
13
- expect(counter.start(1)).toBe(2 ** 10);
14
- });
15
- });
16
-
17
- describe('async', () => {
18
- it('base usage', async () => {
19
- const counter = createAsyncCounter<number, number>(
20
- // eslint-disable-next-line @typescript-eslint/require-await
21
- async (index, input, next) => {
22
- if (index >= 10) {
23
- return input;
24
- }
25
- return next(input * 2);
26
- },
27
- );
28
-
29
- expect(await counter.start(1)).toBe(2 ** 10);
30
- });
31
- });
32
- });
@@ -1,113 +0,0 @@
1
- import { sleep } from './helpers';
2
- import { enable, disable } from '@/asyncHooksImpl';
3
- import { createHooks } from '@/hook';
4
-
5
- describe('hook', () => {
6
- it('should support sync runner', () => {
7
- type Hooks = {
8
- useCount: () => number;
9
- };
10
-
11
- const {
12
- run,
13
- hooks: { useCount },
14
- } = createHooks<Hooks>({
15
- useCount: () => {
16
- throw new Error(`useCount can't not be called after initilizing`);
17
- },
18
- });
19
-
20
- let count = 0;
21
- const implementations: Hooks = { useCount: () => count++ };
22
- run(() => {
23
- expect(useCount()).toBe(0);
24
- expect(useCount()).toBe(1);
25
- expect(useCount()).toBe(2);
26
- expect(useCount()).toBe(3);
27
- }, implementations);
28
- });
29
-
30
- it('should support async runner', async () => {
31
- type Hooks = {
32
- useCount: () => number;
33
- };
34
-
35
- const {
36
- run,
37
- hooks: { useCount },
38
- } = createHooks<Hooks>({
39
- useCount: () => {
40
- throw new Error(`useCount can't not be called after initilizing`);
41
- },
42
- });
43
-
44
- let count = 0;
45
- const implementations: Hooks = { useCount: () => count++ };
46
-
47
- enable();
48
-
49
- await run(async () => {
50
- expect(useCount()).toBe(0);
51
- await sleep(0);
52
- expect(useCount()).toBe(1);
53
- await sleep(0);
54
- expect(useCount()).toBe(2);
55
- await sleep(0);
56
- expect(useCount()).toBe(3);
57
- }, implementations);
58
-
59
- disable();
60
- });
61
-
62
- it('should use default hook with passing new one', () => {
63
- type Hooks = {
64
- useCount: () => number;
65
- };
66
-
67
- const {
68
- run,
69
- hooks: { useCount },
70
- } = createHooks<Hooks>({
71
- useCount: () => {
72
- throw new Error(`useCount can't not be called after initilizing`);
73
- },
74
- });
75
-
76
- enable();
77
-
78
- run(() => {
79
- expect(useCount).toThrowError(
80
- new Error(`useCount can't not be called after initilizing`),
81
- );
82
- });
83
-
84
- disable();
85
- });
86
-
87
- it('should fallback to default hook', () => {
88
- type Hooks = {
89
- useCount: () => number;
90
- };
91
-
92
- const {
93
- run,
94
- hooks: { useCount },
95
- } = createHooks<Hooks>({
96
- useCount: () => {
97
- throw new Error(`useCount can't not be called after initilizing`);
98
- },
99
- });
100
-
101
- const implementations: Hooks = { useCount: '' } as any;
102
-
103
- enable();
104
-
105
- run(() => {
106
- expect(useCount).toThrowError(
107
- new Error(`useCount can't not be called after initilizing`),
108
- );
109
- }, implementations);
110
-
111
- disable();
112
- });
113
- });