@modern-js/core 1.7.1 → 1.9.1

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 (215) hide show
  1. package/.eslintrc.js +1 -0
  2. package/CHANGELOG.md +47 -0
  3. package/bin/modern-js.js +1 -1
  4. package/compiled/ajv/codegen.js +1 -0
  5. package/compiled/ajv/dist/ajv.d.ts +16 -0
  6. package/compiled/ajv/dist/compile/codegen/code.d.ts +40 -0
  7. package/compiled/ajv/dist/compile/codegen/index.d.ts +79 -0
  8. package/compiled/ajv/dist/compile/codegen/scope.d.ts +79 -0
  9. package/compiled/ajv/dist/compile/errors.d.ts +13 -0
  10. package/compiled/ajv/dist/compile/index.d.ts +80 -0
  11. package/compiled/ajv/dist/compile/ref_error.d.ts +6 -0
  12. package/compiled/ajv/dist/compile/resolve.d.ts +12 -0
  13. package/compiled/ajv/dist/compile/rules.d.ts +28 -0
  14. package/compiled/ajv/dist/compile/util.d.ts +40 -0
  15. package/compiled/ajv/dist/compile/validate/index.d.ts +42 -0
  16. package/compiled/ajv/dist/compile/validate/subschema.d.ts +47 -0
  17. package/compiled/ajv/dist/core.d.ts +173 -0
  18. package/compiled/ajv/dist/runtime/validation_error.d.ts +7 -0
  19. package/compiled/ajv/dist/types/index.d.ts +183 -0
  20. package/compiled/ajv/dist/types/json-schema.d.ts +124 -0
  21. package/compiled/ajv/dist/types/jtd-schema.d.ts +169 -0
  22. package/compiled/ajv/index.js +9 -0
  23. package/compiled/ajv/license +22 -0
  24. package/compiled/ajv/package.json +1 -0
  25. package/compiled/ajv/uri-js/dist/es5/uri.all.d.ts +59 -0
  26. package/compiled/ajv-keywords/ajv/dist/ajv.d.ts +16 -0
  27. package/compiled/ajv-keywords/ajv/dist/compile/codegen/code.d.ts +40 -0
  28. package/compiled/ajv-keywords/ajv/dist/compile/codegen/index.d.ts +79 -0
  29. package/compiled/ajv-keywords/ajv/dist/compile/codegen/scope.d.ts +79 -0
  30. package/compiled/ajv-keywords/ajv/dist/compile/errors.d.ts +13 -0
  31. package/compiled/ajv-keywords/ajv/dist/compile/index.d.ts +80 -0
  32. package/compiled/ajv-keywords/ajv/dist/compile/ref_error.d.ts +6 -0
  33. package/compiled/ajv-keywords/ajv/dist/compile/resolve.d.ts +12 -0
  34. package/compiled/ajv-keywords/ajv/dist/compile/rules.d.ts +28 -0
  35. package/compiled/ajv-keywords/ajv/dist/compile/util.d.ts +40 -0
  36. package/compiled/ajv-keywords/ajv/dist/compile/validate/index.d.ts +42 -0
  37. package/compiled/ajv-keywords/ajv/dist/compile/validate/subschema.d.ts +47 -0
  38. package/compiled/ajv-keywords/ajv/dist/core.d.ts +173 -0
  39. package/compiled/ajv-keywords/ajv/dist/runtime/validation_error.d.ts +7 -0
  40. package/compiled/ajv-keywords/ajv/dist/types/index.d.ts +183 -0
  41. package/compiled/ajv-keywords/ajv/dist/types/json-schema.d.ts +124 -0
  42. package/compiled/ajv-keywords/ajv/dist/types/jtd-schema.d.ts +169 -0
  43. package/compiled/ajv-keywords/dist/index.d.ts +4 -0
  44. package/compiled/ajv-keywords/index.js +1 -0
  45. package/compiled/ajv-keywords/license +21 -0
  46. package/compiled/ajv-keywords/package.json +1 -0
  47. package/compiled/ajv-keywords/uri-js/dist/es5/uri.all.d.ts +59 -0
  48. package/compiled/better-ajv-errors/ajv/dist/ajv.d.ts +16 -0
  49. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/code.d.ts +40 -0
  50. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/index.d.ts +79 -0
  51. package/compiled/better-ajv-errors/ajv/dist/compile/codegen/scope.d.ts +79 -0
  52. package/compiled/better-ajv-errors/ajv/dist/compile/errors.d.ts +13 -0
  53. package/compiled/better-ajv-errors/ajv/dist/compile/index.d.ts +80 -0
  54. package/compiled/better-ajv-errors/ajv/dist/compile/ref_error.d.ts +6 -0
  55. package/compiled/better-ajv-errors/ajv/dist/compile/resolve.d.ts +12 -0
  56. package/compiled/better-ajv-errors/ajv/dist/compile/rules.d.ts +28 -0
  57. package/compiled/better-ajv-errors/ajv/dist/compile/util.d.ts +40 -0
  58. package/compiled/better-ajv-errors/ajv/dist/compile/validate/index.d.ts +42 -0
  59. package/compiled/better-ajv-errors/ajv/dist/compile/validate/subschema.d.ts +47 -0
  60. package/compiled/better-ajv-errors/ajv/dist/core.d.ts +173 -0
  61. package/compiled/better-ajv-errors/ajv/dist/runtime/validation_error.d.ts +7 -0
  62. package/compiled/better-ajv-errors/ajv/dist/types/index.d.ts +183 -0
  63. package/compiled/better-ajv-errors/ajv/dist/types/json-schema.d.ts +124 -0
  64. package/compiled/better-ajv-errors/ajv/dist/types/jtd-schema.d.ts +169 -0
  65. package/compiled/better-ajv-errors/index.js +1 -0
  66. package/compiled/better-ajv-errors/license +13 -0
  67. package/compiled/better-ajv-errors/package.json +1 -0
  68. package/compiled/better-ajv-errors/typings.d.ts +24 -0
  69. package/compiled/better-ajv-errors/uri-js/dist/es5/uri.all.d.ts +59 -0
  70. package/compiled/v8-compile-cache/index.js +1 -0
  71. package/compiled/v8-compile-cache/license +21 -0
  72. package/compiled/v8-compile-cache/package.json +1 -0
  73. package/dist/cli.d.ts +1 -0
  74. package/dist/cli.js +33 -0
  75. package/dist/config/defaults.d.ts +28 -0
  76. package/dist/config/defaults.js +98 -0
  77. package/dist/{types/config → config}/index.d.ts +2 -2
  78. package/dist/config/index.js +120 -0
  79. package/dist/config/mergeConfig.d.ts +30 -0
  80. package/dist/config/mergeConfig.js +26 -0
  81. package/dist/config/schema/deploy.d.ts +16 -0
  82. package/dist/config/schema/deploy.js +16 -0
  83. package/dist/config/schema/index.d.ts +466 -0
  84. package/dist/config/schema/index.js +95 -0
  85. package/dist/config/schema/output.d.ts +146 -0
  86. package/dist/config/schema/output.js +68 -0
  87. package/dist/config/schema/server.d.ts +182 -0
  88. package/dist/config/schema/server.js +107 -0
  89. package/dist/config/schema/source.d.ts +58 -0
  90. package/dist/config/schema/source.js +36 -0
  91. package/dist/config/schema/tools.d.ts +36 -0
  92. package/dist/config/schema/tools.js +19 -0
  93. package/dist/config/types/electron.d.ts +13 -0
  94. package/dist/config/types/electron.js +2 -0
  95. package/dist/config/types/index.d.ts +240 -0
  96. package/dist/config/types/index.js +2 -0
  97. package/dist/config/types/less.d.ts +10 -0
  98. package/dist/config/types/less.js +2 -0
  99. package/dist/config/types/sass.d.ts +8 -0
  100. package/dist/config/types/sass.js +2 -0
  101. package/dist/{types/config → config}/types/ssg.d.ts +8 -8
  102. package/dist/config/types/ssg.js +2 -0
  103. package/dist/config/types/test.d.ts +14 -0
  104. package/dist/config/types/test.js +2 -0
  105. package/dist/config/types/unbundle.d.ts +25 -0
  106. package/dist/config/types/unbundle.js +2 -0
  107. package/dist/{types/context.d.ts → context.d.ts} +12 -22
  108. package/dist/context.js +59 -0
  109. package/dist/index.d.ts +64 -0
  110. package/dist/index.js +177 -0
  111. package/dist/{types/initWatcher.d.ts → initWatcher.d.ts} +1 -1
  112. package/dist/initWatcher.js +75 -0
  113. package/dist/{types/loadEnv.d.ts → loadEnv.d.ts} +1 -1
  114. package/dist/loadEnv.js +21 -0
  115. package/dist/{types/loadPlugins.d.ts → loadPlugins.d.ts} +15 -15
  116. package/dist/loadPlugins.js +109 -0
  117. package/dist/manager.d.ts +72 -0
  118. package/dist/manager.js +24 -0
  119. package/dist/{types/pluginAPI.d.ts → pluginAPI.d.ts} +5 -6
  120. package/dist/pluginAPI.js +16 -0
  121. package/dist/{types/utils → utils}/commander.d.ts +1 -1
  122. package/dist/utils/commander.js +20 -0
  123. package/dist/{types/utils → utils}/repeatKeyWarning.d.ts +1 -1
  124. package/dist/utils/repeatKeyWarning.js +22 -0
  125. package/package.json +16 -29
  126. package/tsconfig.json +3 -4
  127. package/dist/js/modern/cli.js +0 -29
  128. package/dist/js/modern/config/defaults.js +0 -103
  129. package/dist/js/modern/config/index.js +0 -115
  130. package/dist/js/modern/config/mergeConfig.js +0 -22
  131. package/dist/js/modern/config/schema/deploy.js +0 -17
  132. package/dist/js/modern/config/schema/index.js +0 -107
  133. package/dist/js/modern/config/schema/output.js +0 -147
  134. package/dist/js/modern/config/schema/server.js +0 -170
  135. package/dist/js/modern/config/schema/source.js +0 -59
  136. package/dist/js/modern/config/schema/tools.js +0 -36
  137. package/dist/js/modern/config/types/index.js +0 -1
  138. package/dist/js/modern/config/types/less.js +0 -0
  139. package/dist/js/modern/config/types/sass.js +0 -0
  140. package/dist/js/modern/config/types/ssg.js +0 -0
  141. package/dist/js/modern/config/types/test.js +0 -0
  142. package/dist/js/modern/config/types/unbundle.js +0 -0
  143. package/dist/js/modern/context.js +0 -63
  144. package/dist/js/modern/index.js +0 -168
  145. package/dist/js/modern/initWatcher.js +0 -62
  146. package/dist/js/modern/loadEnv.js +0 -14
  147. package/dist/js/modern/loadPlugins.js +0 -117
  148. package/dist/js/modern/manager.js +0 -28
  149. package/dist/js/modern/pluginAPI.js +0 -11
  150. package/dist/js/modern/utils/commander.js +0 -19
  151. package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
  152. package/dist/js/node/cli.js +0 -35
  153. package/dist/js/node/config/defaults.js +0 -110
  154. package/dist/js/node/config/index.js +0 -182
  155. package/dist/js/node/config/mergeConfig.js +0 -32
  156. package/dist/js/node/config/schema/deploy.js +0 -26
  157. package/dist/js/node/config/schema/index.js +0 -127
  158. package/dist/js/node/config/schema/output.js +0 -156
  159. package/dist/js/node/config/schema/server.js +0 -179
  160. package/dist/js/node/config/schema/source.js +0 -68
  161. package/dist/js/node/config/schema/tools.js +0 -43
  162. package/dist/js/node/config/types/index.js +0 -5
  163. package/dist/js/node/config/types/less.js +0 -0
  164. package/dist/js/node/config/types/sass.js +0 -0
  165. package/dist/js/node/config/types/ssg.js +0 -0
  166. package/dist/js/node/config/types/test.js +0 -0
  167. package/dist/js/node/config/types/unbundle.js +0 -0
  168. package/dist/js/node/context.js +0 -93
  169. package/dist/js/node/index.js +0 -328
  170. package/dist/js/node/initWatcher.js +0 -82
  171. package/dist/js/node/loadEnv.js +0 -30
  172. package/dist/js/node/loadPlugins.js +0 -129
  173. package/dist/js/node/manager.js +0 -45
  174. package/dist/js/node/pluginAPI.js +0 -54
  175. package/dist/js/node/utils/commander.js +0 -32
  176. package/dist/js/node/utils/repeatKeyWarning.js +0 -31
  177. package/dist/types/cli.d.ts +0 -1
  178. package/dist/types/config/defaults.d.ts +0 -28
  179. package/dist/types/config/mergeConfig.d.ts +0 -31
  180. package/dist/types/config/schema/deploy.d.ts +0 -16
  181. package/dist/types/config/schema/index.d.ts +0 -466
  182. package/dist/types/config/schema/output.d.ts +0 -146
  183. package/dist/types/config/schema/server.d.ts +0 -182
  184. package/dist/types/config/schema/source.d.ts +0 -58
  185. package/dist/types/config/schema/tools.d.ts +0 -36
  186. package/dist/types/config/types/index.d.ts +0 -239
  187. package/dist/types/config/types/less.d.ts +0 -10
  188. package/dist/types/config/types/sass.d.ts +0 -8
  189. package/dist/types/config/types/test.d.ts +0 -15
  190. package/dist/types/config/types/unbundle.d.ts +0 -28
  191. package/dist/types/index.d.ts +0 -61
  192. package/dist/types/manager.d.ts +0 -74
  193. package/modern.config.js +0 -6
  194. package/tests/.eslintrc.js +0 -6
  195. package/tests/btsm.test.ts +0 -20
  196. package/tests/config.test.ts +0 -146
  197. package/tests/context.test.ts +0 -85
  198. package/tests/fixtures/index-test/modern.server-runtime.config.js +0 -0
  199. package/tests/fixtures/index-test/package.json +0 -3
  200. package/tests/fixtures/load-plugin/not-found/package.json +0 -3
  201. package/tests/fixtures/load-plugin/not-found/test-plugin-a.js +0 -1
  202. package/tests/fixtures/load-plugin/user-plugins/package.json +0 -3
  203. package/tests/fixtures/load-plugin/user-plugins/test-plugin-a.js +0 -1
  204. package/tests/fixtures/load-plugin/user-plugins/test-plugin-b.js +0 -3
  205. package/tests/fixtures/load-plugin/user-plugins/test-plugin-c.js +0 -3
  206. package/tests/index.test.ts +0 -83
  207. package/tests/initWatcher.test.ts +0 -63
  208. package/tests/loadEnv.test.ts +0 -173
  209. package/tests/loadPlugin.test.ts +0 -116
  210. package/tests/mergeConfig.test.ts +0 -97
  211. package/tests/pluginAPI.test.ts +0 -19
  212. package/tests/repeatKeyWarning.test.ts +0 -68
  213. package/tests/schema.test.ts +0 -107
  214. package/tests/tsconfig.json +0 -11
  215. package/tests/utils.test.ts +0 -7
@@ -1,116 +0,0 @@
1
- import path from 'path';
2
- import { CliPlugin } from '../src';
3
- import { loadPlugins, getAppPlugins } from '../src/loadPlugins';
4
-
5
- describe('load plugins', () => {
6
- test('getAppPlugins', () => {
7
- const appDirectory = path.resolve(
8
- __dirname,
9
- './fixtures/load-plugin/user-plugins',
10
- );
11
- const plugins = getAppPlugins(appDirectory, ['foo' as any], {
12
- x: {
13
- cli: 'x',
14
- forced: true,
15
- } as any,
16
- });
17
- expect(plugins).toEqual([{ cli: 'x', forced: true }, 'foo']);
18
- });
19
-
20
- test('should load user plugin successfully', () => {
21
- const fixture = path.resolve(
22
- __dirname,
23
- './fixtures/load-plugin/user-plugins',
24
- );
25
-
26
- const plugins = loadPlugins(fixture, {
27
- plugins: [
28
- { cli: path.join(fixture, './test-plugin-a.js') },
29
- { server: './test-plugin-b' },
30
- ],
31
- });
32
-
33
- expect(plugins).toEqual([
34
- {
35
- cli: {
36
- name: 'a',
37
- },
38
- },
39
- {
40
- server: './test-plugin-b',
41
- serverPkg: './test-plugin-b',
42
- },
43
- ]);
44
- });
45
-
46
- test('should pass options to Plugin', () => {
47
- const fixture = path.resolve(
48
- __dirname,
49
- './fixtures/load-plugin/user-plugins',
50
- );
51
-
52
- const plugins = loadPlugins(fixture, {
53
- plugins: [{ cli: ['./test-plugin-c', 'c'] }, ['./test-plugin-c', 'c2']],
54
- });
55
-
56
- expect(plugins[0].cli!.name).toEqual('c');
57
- expect(plugins[1].cli!.name).toEqual('c2');
58
- });
59
-
60
- test('should load user string plugin successfully', () => {
61
- const fixture = path.resolve(
62
- __dirname,
63
- './fixtures/load-plugin/user-plugins',
64
- );
65
-
66
- const plugins = loadPlugins(fixture, {
67
- plugins: [path.join(fixture, './test-plugin-a.js') as any],
68
- });
69
-
70
- expect(plugins).toEqual([
71
- {
72
- cli: {
73
- name: 'a',
74
- },
75
- },
76
- ]);
77
- });
78
-
79
- test(`should throw error when plugin not found `, () => {
80
- const fixture = path.resolve(__dirname, './fixtures/load-plugin/not-found');
81
-
82
- expect(() => {
83
- loadPlugins(fixture, {
84
- plugins: [{ cli: './test-plugin-a' }, { cli: './plugin-b' }],
85
- });
86
- }).toThrowError(/^Can not find plugin /);
87
- });
88
-
89
- test(`should load new plugin array correctly`, () => {
90
- const appDirectory = path.resolve(
91
- __dirname,
92
- './fixtures/load-plugin/user-plugins',
93
- );
94
- const plugin = (): CliPlugin => ({
95
- name: 'foo',
96
- });
97
- const userConfig = { plugins: [plugin()] };
98
- const loadedPlugins = loadPlugins(appDirectory, userConfig);
99
-
100
- expect(loadedPlugins[0].cli?.name).toEqual('foo');
101
- });
102
-
103
- test(`should load new plugin object correctly`, () => {
104
- const appDirectory = path.resolve(
105
- __dirname,
106
- './fixtures/load-plugin/user-plugins',
107
- );
108
- const plugin = (): CliPlugin => ({
109
- name: 'foo',
110
- });
111
- const userConfig = { plugins: { cli: [plugin()] } };
112
- const loadedPlugins = loadPlugins(appDirectory, userConfig);
113
-
114
- expect(loadedPlugins[0].cli?.name).toEqual('foo');
115
- });
116
- });
@@ -1,97 +0,0 @@
1
- import { mergeConfig } from '../src/config/mergeConfig';
2
-
3
- describe('load plugins', () => {
4
- test('should replace property deeply', () => {
5
- expect(
6
- mergeConfig([
7
- {
8
- source: { disableDefaultEntries: false },
9
- output: { polyfill: 'usage' },
10
- },
11
- {
12
- source: { disableDefaultEntries: true },
13
- output: { polyfill: 'entry' },
14
- },
15
- ]),
16
- ).toEqual({
17
- source: { disableDefaultEntries: true },
18
- output: { polyfill: 'entry' },
19
- });
20
- });
21
-
22
- test(`should set value when property value is not undefined `, () => {
23
- expect(
24
- mergeConfig([
25
- { source: { entries: { app: './App.tsx' } } },
26
- { source: { entries: { app2: './src/App2.tsx' } } },
27
- { server: { baseUrl: './a' } },
28
- ]),
29
- ).toEqual({
30
- source: {
31
- entries: {
32
- app: './App.tsx',
33
- app2: './src/App2.tsx',
34
- },
35
- },
36
- server: { baseUrl: './a' },
37
- });
38
- });
39
-
40
- test(`should ignore undefined property`, () => {
41
- const config = mergeConfig([
42
- { source: { entries: { app: './App.tsx' } } },
43
- { source: { entries: undefined } },
44
- { tools: { webpack: () => ({}) } },
45
- { tools: { webpack: undefined } },
46
- ]);
47
- expect(config.source).toEqual({
48
- entries: {
49
- app: './App.tsx',
50
- },
51
- });
52
- expect(Array.isArray(config.tools.webpack)).toBe(true);
53
- expect(config.tools.webpack?.length).toBe(1);
54
- });
55
-
56
- test(`should merge array value`, () => {
57
- expect(
58
- mergeConfig([
59
- { source: { envVars: ['a', 'b'] } },
60
- { source: { globalVars: { A: '1' } } },
61
- {
62
- source: {
63
- disableDefaultEntries: true,
64
- envVars: ['c', 'd'],
65
- globalVars: { B: '2' },
66
- },
67
- },
68
- ]),
69
- ).toEqual({
70
- source: {
71
- disableDefaultEntries: true,
72
- envVars: ['a', 'b', 'c', 'd'],
73
- globalVars: {
74
- A: '1',
75
- B: '2',
76
- },
77
- },
78
- });
79
- });
80
-
81
- test(`should merge function and object value`, () => {
82
- const config = mergeConfig([
83
- { source: { alias: { a: 'b' } } },
84
- { source: { alias: () => ({ c: 'd' }) } },
85
- { tools: { webpack: () => ({}) } },
86
- { tools: { webpack: { name: 'test' } } },
87
- { tools: { webpack: () => ({}) } },
88
- ]);
89
- expect(Array.isArray(config.source.alias)).toBe(true);
90
- expect(config?.source?.alias?.length).toBe(2);
91
- expect(typeof (config.source.alias as Array<any>)[1]).toBe('function');
92
- expect(Array.isArray(config.tools.webpack)).toBe(true);
93
- expect(config.tools.webpack?.length).toBe(3);
94
- expect(typeof (config.tools.webpack as Array<any>)[0]).toBe('function');
95
- expect(typeof (config.tools.webpack as Array<any>)[2]).toBe('function');
96
- });
97
- });
@@ -1,19 +0,0 @@
1
- import { CliPlugin, manager } from '../src';
2
-
3
- describe('pluginAPI', () => {
4
- it('api.setAppContext', done => {
5
- const plugin = (): CliPlugin => ({
6
- setup(api) {
7
- api.setAppContext({
8
- ...api.useAppContext(),
9
- packageName: 'foo',
10
- });
11
-
12
- expect(api.useAppContext().packageName).toEqual('foo');
13
- done();
14
- },
15
- });
16
-
17
- manager.clone().usePlugin(plugin).init();
18
- });
19
- });
@@ -1,68 +0,0 @@
1
- import { repeatKeyWarning } from '../src/utils/repeatKeyWarning';
2
- import { UserConfig } from '../src/config';
3
-
4
- jest.spyOn(process, 'exit').mockImplementation();
5
-
6
- describe('check repeated keys in user config', () => {
7
- test(`should exit with error`, () => {
8
- expect(() => {
9
- repeatKeyWarning(
10
- {
11
- type: 'object',
12
- properties: {
13
- a: {
14
- type: 'object',
15
- properties: {
16
- b: {
17
- type: 'object',
18
- properties: { c: { type: ['boolean', 'object'] } },
19
- },
20
- },
21
- },
22
- },
23
- },
24
- { a: { b: { c: true } } } as UserConfig,
25
- { a: { b: { c: false } } } as UserConfig,
26
- );
27
- }).toThrowError(
28
- 'The same configuration a.b.c exists in modern.config.js and package.json.',
29
- );
30
- });
31
-
32
- test(`should exit succcessfully`, () => {
33
- expect(
34
- repeatKeyWarning(
35
- {
36
- type: 'object',
37
- properties: {
38
- a: {
39
- type: 'object',
40
- properties: { b: { type: 'string' } },
41
- },
42
- },
43
- c: {
44
- type: 'object',
45
- proeperties: {
46
- d: {
47
- type: 'object',
48
- properties: { e: { type: 'string' } },
49
- },
50
- f: { type: 'string' },
51
- },
52
- },
53
- },
54
- {
55
- a: { b: 'name' },
56
- c: { d: { e: 's' } },
57
- } as UserConfig,
58
- {
59
- a: {},
60
- c: {
61
- d: {},
62
- f: 'ss',
63
- },
64
- } as UserConfig,
65
- ),
66
- ).toBeUndefined();
67
- });
68
- });
@@ -1,107 +0,0 @@
1
- import { patchSchema, traverseSchema } from '../src/config/schema';
2
-
3
- describe('patch schemas', () => {
4
- test('should add schema succcessfully', () => {
5
- const schema = patchSchema([
6
- {
7
- target: 'foo',
8
- schema: { type: 'string' },
9
- },
10
- {
11
- target: 'deploy.foo',
12
- schema: { type: 'number' },
13
- },
14
- ]);
15
-
16
- expect(schema.properties).toHaveProperty('foo');
17
-
18
- expect(schema.properties.deploy.properties).toHaveProperty('foo');
19
- });
20
-
21
- test('should throw error when node is undefined', () => {
22
- expect(() => {
23
- patchSchema([
24
- {
25
- target: 'deploy.a.foo',
26
- schema: { type: 'string' },
27
- },
28
- ]);
29
- }).toThrowError(/^add schema deploy\.a error$/);
30
- });
31
-
32
- test(`should throw error on empty target property`, () => {
33
- expect(() => {
34
- patchSchema([
35
- {
36
- target: '',
37
- schema: { type: 'object' },
38
- },
39
- ]);
40
- }).toThrowError('should return target property in plugin schema.');
41
- });
42
-
43
- test(`support schema array in one schema`, () => {
44
- const schema = patchSchema([
45
- [
46
- {
47
- target: 'foo',
48
- schema: { type: 'string' },
49
- },
50
- {
51
- target: 'tools.foo',
52
- schema: { type: 'number' },
53
- },
54
- ],
55
- {
56
- target: 'bar',
57
- schema: { type: 'string' },
58
- },
59
- ]);
60
-
61
- expect(schema.properties).toHaveProperty('foo');
62
- expect(schema.properties).toHaveProperty('bar');
63
- expect(schema.properties.tools.properties).toHaveProperty('foo');
64
- });
65
- });
66
-
67
- describe(`traverse schema`, () => {
68
- test(`should return all avaliable keys of current schema`, () => {
69
- const schema = {
70
- type: 'object',
71
- properties: {
72
- source: {
73
- type: 'object',
74
- properties: { alias: { type: ['object', 'function'] } },
75
- },
76
- a: {
77
- type: 'object',
78
- properties: {
79
- b: {
80
- type: 'object',
81
- properties: { c: { type: 'object' } },
82
- },
83
- d: { type: 'string' },
84
- },
85
- },
86
- runtime: {
87
- type: 'object',
88
- properties: {
89
- router: { type: ['object', 'boolean'] },
90
- state: { type: ['object', 'boolean'] },
91
- },
92
- },
93
- runtimeByEntries: { patternProperties: { '^$': { type: 'string' } } },
94
- dev: { type: ['function', 'string'] },
95
- },
96
- };
97
- expect(traverseSchema(schema as any)).toEqual([
98
- 'source.alias',
99
- 'a.b.c',
100
- 'a.d',
101
- 'runtime.router',
102
- 'runtime.state',
103
- 'runtimeByEntries',
104
- 'dev',
105
- ]);
106
- });
107
- });
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": false,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "isolatedModules": true,
8
- "esModuleInterop": true,
9
- "paths": {}
10
- }
11
- }
@@ -1,7 +0,0 @@
1
- import { program } from '../src/utils/commander';
2
-
3
- describe('utils', () => {
4
- it('default', () => {
5
- expect(program).toBeDefined();
6
- });
7
- });