@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.
- package/.eslintrc.js +1 -0
- package/CHANGELOG.md +47 -0
- package/bin/modern-js.js +1 -1
- package/compiled/ajv/codegen.js +1 -0
- package/compiled/ajv/dist/ajv.d.ts +16 -0
- package/compiled/ajv/dist/compile/codegen/code.d.ts +40 -0
- package/compiled/ajv/dist/compile/codegen/index.d.ts +79 -0
- package/compiled/ajv/dist/compile/codegen/scope.d.ts +79 -0
- package/compiled/ajv/dist/compile/errors.d.ts +13 -0
- package/compiled/ajv/dist/compile/index.d.ts +80 -0
- package/compiled/ajv/dist/compile/ref_error.d.ts +6 -0
- package/compiled/ajv/dist/compile/resolve.d.ts +12 -0
- package/compiled/ajv/dist/compile/rules.d.ts +28 -0
- package/compiled/ajv/dist/compile/util.d.ts +40 -0
- package/compiled/ajv/dist/compile/validate/index.d.ts +42 -0
- package/compiled/ajv/dist/compile/validate/subschema.d.ts +47 -0
- package/compiled/ajv/dist/core.d.ts +173 -0
- package/compiled/ajv/dist/runtime/validation_error.d.ts +7 -0
- package/compiled/ajv/dist/types/index.d.ts +183 -0
- package/compiled/ajv/dist/types/json-schema.d.ts +124 -0
- package/compiled/ajv/dist/types/jtd-schema.d.ts +169 -0
- package/compiled/ajv/index.js +9 -0
- package/compiled/ajv/license +22 -0
- package/compiled/ajv/package.json +1 -0
- package/compiled/ajv/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/compiled/ajv-keywords/ajv/dist/ajv.d.ts +16 -0
- package/compiled/ajv-keywords/ajv/dist/compile/codegen/code.d.ts +40 -0
- package/compiled/ajv-keywords/ajv/dist/compile/codegen/index.d.ts +79 -0
- package/compiled/ajv-keywords/ajv/dist/compile/codegen/scope.d.ts +79 -0
- package/compiled/ajv-keywords/ajv/dist/compile/errors.d.ts +13 -0
- package/compiled/ajv-keywords/ajv/dist/compile/index.d.ts +80 -0
- package/compiled/ajv-keywords/ajv/dist/compile/ref_error.d.ts +6 -0
- package/compiled/ajv-keywords/ajv/dist/compile/resolve.d.ts +12 -0
- package/compiled/ajv-keywords/ajv/dist/compile/rules.d.ts +28 -0
- package/compiled/ajv-keywords/ajv/dist/compile/util.d.ts +40 -0
- package/compiled/ajv-keywords/ajv/dist/compile/validate/index.d.ts +42 -0
- package/compiled/ajv-keywords/ajv/dist/compile/validate/subschema.d.ts +47 -0
- package/compiled/ajv-keywords/ajv/dist/core.d.ts +173 -0
- package/compiled/ajv-keywords/ajv/dist/runtime/validation_error.d.ts +7 -0
- package/compiled/ajv-keywords/ajv/dist/types/index.d.ts +183 -0
- package/compiled/ajv-keywords/ajv/dist/types/json-schema.d.ts +124 -0
- package/compiled/ajv-keywords/ajv/dist/types/jtd-schema.d.ts +169 -0
- package/compiled/ajv-keywords/dist/index.d.ts +4 -0
- package/compiled/ajv-keywords/index.js +1 -0
- package/compiled/ajv-keywords/license +21 -0
- package/compiled/ajv-keywords/package.json +1 -0
- package/compiled/ajv-keywords/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/compiled/better-ajv-errors/ajv/dist/ajv.d.ts +16 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/codegen/code.d.ts +40 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/codegen/index.d.ts +79 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/codegen/scope.d.ts +79 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/errors.d.ts +13 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/index.d.ts +80 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/ref_error.d.ts +6 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/resolve.d.ts +12 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/rules.d.ts +28 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/util.d.ts +40 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/validate/index.d.ts +42 -0
- package/compiled/better-ajv-errors/ajv/dist/compile/validate/subschema.d.ts +47 -0
- package/compiled/better-ajv-errors/ajv/dist/core.d.ts +173 -0
- package/compiled/better-ajv-errors/ajv/dist/runtime/validation_error.d.ts +7 -0
- package/compiled/better-ajv-errors/ajv/dist/types/index.d.ts +183 -0
- package/compiled/better-ajv-errors/ajv/dist/types/json-schema.d.ts +124 -0
- package/compiled/better-ajv-errors/ajv/dist/types/jtd-schema.d.ts +169 -0
- package/compiled/better-ajv-errors/index.js +1 -0
- package/compiled/better-ajv-errors/license +13 -0
- package/compiled/better-ajv-errors/package.json +1 -0
- package/compiled/better-ajv-errors/typings.d.ts +24 -0
- package/compiled/better-ajv-errors/uri-js/dist/es5/uri.all.d.ts +59 -0
- package/compiled/v8-compile-cache/index.js +1 -0
- package/compiled/v8-compile-cache/license +21 -0
- package/compiled/v8-compile-cache/package.json +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +33 -0
- package/dist/config/defaults.d.ts +28 -0
- package/dist/config/defaults.js +98 -0
- package/dist/{types/config → config}/index.d.ts +2 -2
- package/dist/config/index.js +120 -0
- package/dist/config/mergeConfig.d.ts +30 -0
- package/dist/config/mergeConfig.js +26 -0
- package/dist/config/schema/deploy.d.ts +16 -0
- package/dist/config/schema/deploy.js +16 -0
- package/dist/config/schema/index.d.ts +466 -0
- package/dist/config/schema/index.js +95 -0
- package/dist/config/schema/output.d.ts +146 -0
- package/dist/config/schema/output.js +68 -0
- package/dist/config/schema/server.d.ts +182 -0
- package/dist/config/schema/server.js +107 -0
- package/dist/config/schema/source.d.ts +58 -0
- package/dist/config/schema/source.js +36 -0
- package/dist/config/schema/tools.d.ts +36 -0
- package/dist/config/schema/tools.js +19 -0
- package/dist/config/types/electron.d.ts +13 -0
- package/dist/config/types/electron.js +2 -0
- package/dist/config/types/index.d.ts +240 -0
- package/dist/config/types/index.js +2 -0
- package/dist/config/types/less.d.ts +10 -0
- package/dist/config/types/less.js +2 -0
- package/dist/config/types/sass.d.ts +8 -0
- package/dist/config/types/sass.js +2 -0
- package/dist/{types/config → config}/types/ssg.d.ts +8 -8
- package/dist/config/types/ssg.js +2 -0
- package/dist/config/types/test.d.ts +14 -0
- package/dist/config/types/test.js +2 -0
- package/dist/config/types/unbundle.d.ts +25 -0
- package/dist/config/types/unbundle.js +2 -0
- package/dist/{types/context.d.ts → context.d.ts} +12 -22
- package/dist/context.js +59 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +177 -0
- package/dist/{types/initWatcher.d.ts → initWatcher.d.ts} +1 -1
- package/dist/initWatcher.js +75 -0
- package/dist/{types/loadEnv.d.ts → loadEnv.d.ts} +1 -1
- package/dist/loadEnv.js +21 -0
- package/dist/{types/loadPlugins.d.ts → loadPlugins.d.ts} +15 -15
- package/dist/loadPlugins.js +109 -0
- package/dist/manager.d.ts +72 -0
- package/dist/manager.js +24 -0
- package/dist/{types/pluginAPI.d.ts → pluginAPI.d.ts} +5 -6
- package/dist/pluginAPI.js +16 -0
- package/dist/{types/utils → utils}/commander.d.ts +1 -1
- package/dist/utils/commander.js +20 -0
- package/dist/{types/utils → utils}/repeatKeyWarning.d.ts +1 -1
- package/dist/utils/repeatKeyWarning.js +22 -0
- package/package.json +16 -29
- package/tsconfig.json +3 -4
- package/dist/js/modern/cli.js +0 -29
- package/dist/js/modern/config/defaults.js +0 -103
- package/dist/js/modern/config/index.js +0 -115
- package/dist/js/modern/config/mergeConfig.js +0 -22
- package/dist/js/modern/config/schema/deploy.js +0 -17
- package/dist/js/modern/config/schema/index.js +0 -107
- package/dist/js/modern/config/schema/output.js +0 -147
- package/dist/js/modern/config/schema/server.js +0 -170
- package/dist/js/modern/config/schema/source.js +0 -59
- package/dist/js/modern/config/schema/tools.js +0 -36
- package/dist/js/modern/config/types/index.js +0 -1
- package/dist/js/modern/config/types/less.js +0 -0
- package/dist/js/modern/config/types/sass.js +0 -0
- package/dist/js/modern/config/types/ssg.js +0 -0
- package/dist/js/modern/config/types/test.js +0 -0
- package/dist/js/modern/config/types/unbundle.js +0 -0
- package/dist/js/modern/context.js +0 -63
- package/dist/js/modern/index.js +0 -168
- package/dist/js/modern/initWatcher.js +0 -62
- package/dist/js/modern/loadEnv.js +0 -14
- package/dist/js/modern/loadPlugins.js +0 -117
- package/dist/js/modern/manager.js +0 -28
- package/dist/js/modern/pluginAPI.js +0 -11
- package/dist/js/modern/utils/commander.js +0 -19
- package/dist/js/modern/utils/repeatKeyWarning.js +0 -18
- package/dist/js/node/cli.js +0 -35
- package/dist/js/node/config/defaults.js +0 -110
- package/dist/js/node/config/index.js +0 -182
- package/dist/js/node/config/mergeConfig.js +0 -32
- package/dist/js/node/config/schema/deploy.js +0 -26
- package/dist/js/node/config/schema/index.js +0 -127
- package/dist/js/node/config/schema/output.js +0 -156
- package/dist/js/node/config/schema/server.js +0 -179
- package/dist/js/node/config/schema/source.js +0 -68
- package/dist/js/node/config/schema/tools.js +0 -43
- package/dist/js/node/config/types/index.js +0 -5
- package/dist/js/node/config/types/less.js +0 -0
- package/dist/js/node/config/types/sass.js +0 -0
- package/dist/js/node/config/types/ssg.js +0 -0
- package/dist/js/node/config/types/test.js +0 -0
- package/dist/js/node/config/types/unbundle.js +0 -0
- package/dist/js/node/context.js +0 -93
- package/dist/js/node/index.js +0 -328
- package/dist/js/node/initWatcher.js +0 -82
- package/dist/js/node/loadEnv.js +0 -30
- package/dist/js/node/loadPlugins.js +0 -129
- package/dist/js/node/manager.js +0 -45
- package/dist/js/node/pluginAPI.js +0 -54
- package/dist/js/node/utils/commander.js +0 -32
- package/dist/js/node/utils/repeatKeyWarning.js +0 -31
- package/dist/types/cli.d.ts +0 -1
- package/dist/types/config/defaults.d.ts +0 -28
- package/dist/types/config/mergeConfig.d.ts +0 -31
- package/dist/types/config/schema/deploy.d.ts +0 -16
- package/dist/types/config/schema/index.d.ts +0 -466
- package/dist/types/config/schema/output.d.ts +0 -146
- package/dist/types/config/schema/server.d.ts +0 -182
- package/dist/types/config/schema/source.d.ts +0 -58
- package/dist/types/config/schema/tools.d.ts +0 -36
- package/dist/types/config/types/index.d.ts +0 -239
- package/dist/types/config/types/less.d.ts +0 -10
- package/dist/types/config/types/sass.d.ts +0 -8
- package/dist/types/config/types/test.d.ts +0 -15
- package/dist/types/config/types/unbundle.d.ts +0 -28
- package/dist/types/index.d.ts +0 -61
- package/dist/types/manager.d.ts +0 -74
- package/modern.config.js +0 -6
- package/tests/.eslintrc.js +0 -6
- package/tests/btsm.test.ts +0 -20
- package/tests/config.test.ts +0 -146
- package/tests/context.test.ts +0 -85
- package/tests/fixtures/index-test/modern.server-runtime.config.js +0 -0
- package/tests/fixtures/index-test/package.json +0 -3
- package/tests/fixtures/load-plugin/not-found/package.json +0 -3
- package/tests/fixtures/load-plugin/not-found/test-plugin-a.js +0 -1
- package/tests/fixtures/load-plugin/user-plugins/package.json +0 -3
- package/tests/fixtures/load-plugin/user-plugins/test-plugin-a.js +0 -1
- package/tests/fixtures/load-plugin/user-plugins/test-plugin-b.js +0 -3
- package/tests/fixtures/load-plugin/user-plugins/test-plugin-c.js +0 -3
- package/tests/index.test.ts +0 -83
- package/tests/initWatcher.test.ts +0 -63
- package/tests/loadEnv.test.ts +0 -173
- package/tests/loadPlugin.test.ts +0 -116
- package/tests/mergeConfig.test.ts +0 -97
- package/tests/pluginAPI.test.ts +0 -19
- package/tests/repeatKeyWarning.test.ts +0 -68
- package/tests/schema.test.ts +0 -107
- package/tests/tsconfig.json +0 -11
- package/tests/utils.test.ts +0 -7
package/tests/loadPlugin.test.ts
DELETED
|
@@ -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
|
-
});
|
package/tests/pluginAPI.test.ts
DELETED
|
@@ -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
|
-
});
|
package/tests/schema.test.ts
DELETED
|
@@ -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
|
-
});
|
package/tests/tsconfig.json
DELETED