@modern-js/core 1.6.0 → 1.7.1-beta.peer.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/CHANGELOG.md +31 -0
- package/dist/js/modern/config/index.js +11 -7
- package/dist/js/modern/config/mergeConfig.js +1 -1
- package/dist/js/modern/config/schema/index.js +1 -1
- package/dist/js/modern/config/types/electron.js +1 -0
- package/dist/js/modern/config/types/index.js +1 -0
- 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 +9 -2
- package/dist/js/modern/index.js +27 -9
- package/dist/js/modern/initWatcher.js +2 -2
- package/dist/js/modern/loadPlugins.js +9 -4
- package/dist/js/modern/utils/commander.js +15 -15
- package/dist/js/node/config/index.js +38 -11
- package/dist/js/node/config/mergeConfig.js +2 -4
- package/dist/js/node/config/schema/index.js +3 -5
- package/dist/js/node/config/types/electron.js +5 -0
- package/dist/js/node/config/types/index.js +5 -0
- 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 +9 -2
- package/dist/js/node/index.js +32 -10
- package/dist/js/node/initWatcher.js +2 -3
- package/dist/js/node/loadPlugins.js +9 -4
- package/dist/js/node/utils/commander.js +16 -19
- package/dist/types/config/index.d.ts +4 -140
- package/dist/types/config/types/electron.d.ts +13 -0
- package/dist/types/config/types/index.d.ts +252 -0
- package/dist/types/config/types/less.d.ts +10 -0
- package/dist/types/config/types/sass.d.ts +8 -0
- package/dist/types/config/types/ssg.d.ts +13 -0
- package/dist/types/config/types/test.d.ts +15 -0
- package/dist/types/config/types/unbundle.d.ts +28 -0
- package/dist/types/context.d.ts +18 -6
- package/dist/types/index.d.ts +28 -1
- package/dist/types/initWatcher.d.ts +1 -2
- package/dist/types/loadPlugins.d.ts +3 -0
- package/dist/types/manager.d.ts +7 -6
- package/dist/types/utils/commander.d.ts +4 -7
- package/jest.config.js +0 -1
- package/package.json +18 -17
- package/tests/.eslintrc.js +0 -6
- package/tests/btsm.test.ts +0 -20
- package/tests/config.test.ts +0 -137
- package/tests/context.test.ts +0 -70
- 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 -69
- 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 -8
package/tests/loadEnv.test.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { loadEnv } from '../src/loadEnv';
|
|
4
|
-
|
|
5
|
-
const fixture = path.resolve(__dirname, './fixtures/load-env');
|
|
6
|
-
|
|
7
|
-
fs.mkdirSync(fixture);
|
|
8
|
-
|
|
9
|
-
const createFixtures = (
|
|
10
|
-
dir: string,
|
|
11
|
-
files: {
|
|
12
|
-
name: string;
|
|
13
|
-
content: string;
|
|
14
|
-
}[],
|
|
15
|
-
) => {
|
|
16
|
-
fs.mkdirSync(path.join(fixture, dir));
|
|
17
|
-
for (const { name, content } of files) {
|
|
18
|
-
fs.writeFileSync(path.join(fixture, dir, name), content, 'utf8');
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
describe('load environment variables', () => {
|
|
23
|
-
const defaultEnv = process.env;
|
|
24
|
-
|
|
25
|
-
beforeEach(() => (process.env = { ...defaultEnv }));
|
|
26
|
-
|
|
27
|
-
afterAll(() => {
|
|
28
|
-
process.env = { ...defaultEnv };
|
|
29
|
-
fs.rmSync(fixture, { force: true, recursive: true });
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test(`support .env file`, () => {
|
|
33
|
-
createFixtures('base', [
|
|
34
|
-
{
|
|
35
|
-
name: '.env',
|
|
36
|
-
content: `DB_HOST=localhost
|
|
37
|
-
DB_USER=root
|
|
38
|
-
DB_PASS=root
|
|
39
|
-
`,
|
|
40
|
-
},
|
|
41
|
-
]);
|
|
42
|
-
loadEnv(path.join(fixture, 'base'));
|
|
43
|
-
|
|
44
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
45
|
-
|
|
46
|
-
expect(process.env.DB_USER).toBe('root');
|
|
47
|
-
|
|
48
|
-
expect(process.env.DB_PASS).toBe('root');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test(`support "environment" .env file`, () => {
|
|
52
|
-
createFixtures('environment', [
|
|
53
|
-
{
|
|
54
|
-
name: '.env',
|
|
55
|
-
content: `DB_HOST=localhost
|
|
56
|
-
DB_USER=root
|
|
57
|
-
DB_PASS=root
|
|
58
|
-
`,
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: '.env.production',
|
|
62
|
-
content: `DB_HOST=localhost
|
|
63
|
-
DB_USER=root-local-dev
|
|
64
|
-
`,
|
|
65
|
-
},
|
|
66
|
-
]);
|
|
67
|
-
|
|
68
|
-
process.env.NODE_ENV = 'production';
|
|
69
|
-
|
|
70
|
-
loadEnv(path.join(fixture, 'environment'));
|
|
71
|
-
|
|
72
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
73
|
-
|
|
74
|
-
expect(process.env.DB_USER).toBe('root-local-dev');
|
|
75
|
-
|
|
76
|
-
expect(process.env.DB_PASS).toBe('root');
|
|
77
|
-
|
|
78
|
-
delete process.env.NODE_ENV;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test(`should have correct priority`, () => {
|
|
82
|
-
createFixtures('priority', [
|
|
83
|
-
{
|
|
84
|
-
name: '.env',
|
|
85
|
-
content: `DB_HOST=localhost
|
|
86
|
-
DB_USER=user
|
|
87
|
-
DB_PASS=pass
|
|
88
|
-
`,
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
name: '.env.production',
|
|
92
|
-
content: `DB_USER=user_production
|
|
93
|
-
DB_PASS=pass_production
|
|
94
|
-
FOO=foo
|
|
95
|
-
BAR=bar
|
|
96
|
-
`,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
name: '.env.local',
|
|
100
|
-
content: `FOO=foo_local
|
|
101
|
-
BAR=bar_local
|
|
102
|
-
`,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: '.env.production.local',
|
|
106
|
-
content: `BAR=bar_production_local`,
|
|
107
|
-
},
|
|
108
|
-
]);
|
|
109
|
-
|
|
110
|
-
process.env.NODE_ENV = 'production';
|
|
111
|
-
|
|
112
|
-
loadEnv(path.join(fixture, 'priority'));
|
|
113
|
-
|
|
114
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
115
|
-
|
|
116
|
-
expect(process.env.DB_USER).toBe('user_production');
|
|
117
|
-
|
|
118
|
-
expect(process.env.DB_PASS).toBe('pass_production');
|
|
119
|
-
|
|
120
|
-
expect(process.env.FOO).toBe('foo_local');
|
|
121
|
-
|
|
122
|
-
expect(process.env.BAR).toBe('bar_production_local');
|
|
123
|
-
|
|
124
|
-
delete process.env.NODE_ENV;
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test(`get custom .env file by MODERN_ENV`, () => {
|
|
128
|
-
createFixtures('custom_environment', [
|
|
129
|
-
{
|
|
130
|
-
name: '.env',
|
|
131
|
-
content: `DB_HOST=localhost
|
|
132
|
-
DB_USER=root
|
|
133
|
-
DB_PASS=root
|
|
134
|
-
`,
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
name: '.env.staging',
|
|
138
|
-
content: `DB_HOST=localhost
|
|
139
|
-
DB_USER=root-local-dev
|
|
140
|
-
`,
|
|
141
|
-
},
|
|
142
|
-
]);
|
|
143
|
-
|
|
144
|
-
loadEnv(path.join(fixture, 'custom_environment'), 'staging');
|
|
145
|
-
|
|
146
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
147
|
-
|
|
148
|
-
expect(process.env.DB_USER).toBe('root-local-dev');
|
|
149
|
-
|
|
150
|
-
expect(process.env.DB_PASS).toBe('root');
|
|
151
|
-
|
|
152
|
-
delete process.env.MODERN_ENV;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test(`support dotenv-expand`, () => {
|
|
156
|
-
createFixtures('expand', [
|
|
157
|
-
{
|
|
158
|
-
name: '.env',
|
|
159
|
-
content: `DB_HOST=localhost
|
|
160
|
-
DB_USER=\${DB_HOST}001
|
|
161
|
-
DB_PASS=root
|
|
162
|
-
`,
|
|
163
|
-
},
|
|
164
|
-
]);
|
|
165
|
-
loadEnv(path.join(fixture, 'expand'));
|
|
166
|
-
|
|
167
|
-
expect(process.env.DB_HOST).toBe('localhost');
|
|
168
|
-
|
|
169
|
-
expect(process.env.DB_USER).toBe('localhost001');
|
|
170
|
-
|
|
171
|
-
expect(process.env.DB_PASS).toBe('root');
|
|
172
|
-
});
|
|
173
|
-
});
|
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