@modern-js/core 1.4.4 → 1.4.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.
- package/dist/js/modern/config/mergeConfig.js +8 -6
- package/dist/js/modern/config/schema/deploy.js +0 -3
- package/dist/js/modern/loadPlugins.js +1 -1
- package/dist/js/node/config/mergeConfig.js +8 -6
- package/dist/js/node/config/schema/deploy.js +0 -3
- package/dist/js/node/loadPlugins.js +1 -1
- package/dist/types/config/schema/deploy.d.ts +0 -3
- package/dist/types/config/schema/index.d.ts +0 -3
- package/dist/types/loadPlugins.d.ts +1 -1
- package/package.json +3 -2
- package/tests/loadPlugin.test.ts +8 -1
- package/tests/mergeConfig.test.ts +22 -3
- package/tests/schema.test.ts +2 -4
|
@@ -8,12 +8,14 @@ import { isFunction } from '@modern-js/utils';
|
|
|
8
8
|
* @returns - normalized user config.
|
|
9
9
|
*/
|
|
10
10
|
export const mergeConfig = configs => mergeWith({}, ...configs, (target, source) => {
|
|
11
|
-
if (Array.isArray(target)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
if (Array.isArray(target)) {
|
|
12
|
+
if (Array.isArray(source)) {
|
|
13
|
+
return [...target, ...source];
|
|
14
|
+
} else {
|
|
15
|
+
return typeof source !== 'undefined' ? [...target, source] : target;
|
|
16
|
+
}
|
|
17
|
+
} else if (isFunction(source)) {
|
|
18
|
+
return typeof target !== 'undefined' ? [target, source] : [source];
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
return undefined;
|
|
@@ -82,7 +82,7 @@ export const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
82
82
|
|
|
83
83
|
const plugins = getAppPlugins(appDirectory, userConfig.plugins || [], internalPlugins);
|
|
84
84
|
return plugins.map(plugin => {
|
|
85
|
-
const _plugin = typeof plugin === 'string' ? {
|
|
85
|
+
const _plugin = typeof plugin === 'string' || Array.isArray(plugin) ? {
|
|
86
86
|
cli: plugin
|
|
87
87
|
} : plugin;
|
|
88
88
|
|
|
@@ -18,12 +18,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
* @returns - normalized user config.
|
|
19
19
|
*/
|
|
20
20
|
const mergeConfig = configs => (0, _lodash.default)({}, ...configs, (target, source) => {
|
|
21
|
-
if (Array.isArray(target)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
if (Array.isArray(target)) {
|
|
22
|
+
if (Array.isArray(source)) {
|
|
23
|
+
return [...target, ...source];
|
|
24
|
+
} else {
|
|
25
|
+
return typeof source !== 'undefined' ? [...target, source] : target;
|
|
26
|
+
}
|
|
27
|
+
} else if ((0, _utils.isFunction)(source)) {
|
|
28
|
+
return typeof target !== 'undefined' ? [target, source] : [source];
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
return undefined;
|
|
@@ -92,7 +92,7 @@ const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
92
92
|
|
|
93
93
|
const plugins = getAppPlugins(appDirectory, userConfig.plugins || [], internalPlugins);
|
|
94
94
|
return plugins.map(plugin => {
|
|
95
|
-
const _plugin = typeof plugin === 'string' ? {
|
|
95
|
+
const _plugin = typeof plugin === 'string' || Array.isArray(plugin) ? {
|
|
96
96
|
cli: plugin
|
|
97
97
|
} : plugin;
|
|
98
98
|
|
|
@@ -10,7 +10,7 @@ export declare type LoadedPlugin = {
|
|
|
10
10
|
export declare type PluginConfigItem = {
|
|
11
11
|
cli?: Plugin;
|
|
12
12
|
server?: Plugin;
|
|
13
|
-
} |
|
|
13
|
+
} | Plugin;
|
|
14
14
|
export declare type PluginConfig = Array<PluginConfigItem>;
|
|
15
15
|
export declare type TransformPlugin = (plugin: PluginConfig, resolvedConfig: UserConfig, pluginOptions?: any) => PluginConfig;
|
|
16
16
|
export declare function getAppPlugins(appDirectory: string, pluginConfig: PluginConfig, internalPlugins?: typeof INTERNAL_PLUGINS): PluginConfigItem[];
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.4.
|
|
14
|
+
"version": "1.4.5",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -82,7 +82,8 @@
|
|
|
82
82
|
},
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"registry": "https://registry.npmjs.org/",
|
|
85
|
-
"access": "public"
|
|
85
|
+
"access": "public",
|
|
86
|
+
"types": "./dist/types/index.d.ts"
|
|
86
87
|
},
|
|
87
88
|
"scripts": {
|
|
88
89
|
"new": "modern new",
|
package/tests/loadPlugin.test.ts
CHANGED
|
@@ -53,7 +53,7 @@ describe('load plugins', () => {
|
|
|
53
53
|
);
|
|
54
54
|
|
|
55
55
|
const plugins = loadPlugins(fixture, {
|
|
56
|
-
plugins: [{ cli: ['./test-plugin-c', 'c'] }],
|
|
56
|
+
plugins: [{ cli: ['./test-plugin-c', 'c'] }, ['./test-plugin-c', 'c2']],
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
expect(plugins).toEqual([
|
|
@@ -64,6 +64,13 @@ describe('load plugins', () => {
|
|
|
64
64
|
},
|
|
65
65
|
cliPkg: './test-plugin-c',
|
|
66
66
|
},
|
|
67
|
+
{
|
|
68
|
+
cli: {
|
|
69
|
+
name: 'c2',
|
|
70
|
+
pluginPath: path.join(fixture, './test-plugin-c.js'),
|
|
71
|
+
},
|
|
72
|
+
cliPkg: './test-plugin-c',
|
|
73
|
+
},
|
|
67
74
|
]);
|
|
68
75
|
});
|
|
69
76
|
|
|
@@ -19,7 +19,7 @@ describe('load plugins', () => {
|
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
test(`should set value when property value is undefined `, () => {
|
|
22
|
+
test(`should set value when property value is not undefined `, () => {
|
|
23
23
|
expect(
|
|
24
24
|
mergeConfig([
|
|
25
25
|
{ source: { entries: { app: './App.tsx' } } },
|
|
@@ -37,6 +37,22 @@ describe('load plugins', () => {
|
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
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
|
+
|
|
40
56
|
test(`should merge array value`, () => {
|
|
41
57
|
expect(
|
|
42
58
|
mergeConfig([
|
|
@@ -67,12 +83,15 @@ describe('load plugins', () => {
|
|
|
67
83
|
{ source: { alias: { a: 'b' } } },
|
|
68
84
|
{ source: { alias: () => ({ c: 'd' }) } },
|
|
69
85
|
{ tools: { webpack: () => ({}) } },
|
|
86
|
+
{ tools: { webpack: { name: 'test' } } },
|
|
87
|
+
{ tools: { webpack: () => ({}) } },
|
|
70
88
|
]);
|
|
71
89
|
expect(Array.isArray(config.source.alias)).toBe(true);
|
|
72
90
|
expect(config?.source?.alias?.length).toBe(2);
|
|
73
91
|
expect(typeof (config.source.alias as Array<any>)[1]).toBe('function');
|
|
74
|
-
|
|
75
92
|
expect(Array.isArray(config.tools.webpack)).toBe(true);
|
|
76
|
-
expect(config.tools.webpack?.length).toBe(
|
|
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');
|
|
77
96
|
});
|
|
78
97
|
});
|
package/tests/schema.test.ts
CHANGED
|
@@ -8,16 +8,14 @@ describe('patch schemas', () => {
|
|
|
8
8
|
schema: { type: 'string' },
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
|
-
target: 'deploy.
|
|
11
|
+
target: 'deploy.foo',
|
|
12
12
|
schema: { type: 'number' },
|
|
13
13
|
},
|
|
14
14
|
]);
|
|
15
15
|
|
|
16
16
|
expect(schema.properties).toHaveProperty('foo');
|
|
17
17
|
|
|
18
|
-
expect(
|
|
19
|
-
schema.properties.deploy.properties.microFrontend.properties,
|
|
20
|
-
).toHaveProperty('foo');
|
|
18
|
+
expect(schema.properties.deploy.properties).toHaveProperty('foo');
|
|
21
19
|
});
|
|
22
20
|
|
|
23
21
|
test('should throw error when node is undefined', () => {
|