@modern-js/core 1.4.6 → 1.6.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 +8 -0
- package/CHANGELOG.md +47 -0
- package/dist/js/modern/config/defaults.js +4 -1
- package/dist/js/modern/config/index.js +2 -1
- package/dist/js/modern/config/types/index.js +0 -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 +18 -0
- package/dist/js/modern/index.js +9 -28
- package/dist/js/modern/initWatcher.js +1 -0
- package/dist/js/modern/loadPlugins.js +43 -48
- package/dist/js/modern/manager.js +28 -0
- package/dist/js/modern/pluginAPI.js +11 -0
- package/dist/js/node/config/defaults.js +4 -1
- package/dist/js/node/config/index.js +22 -1
- package/dist/js/node/config/types/index.js +0 -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 +22 -1
- package/dist/js/node/index.js +78 -67
- package/dist/js/node/initWatcher.js +1 -0
- package/dist/js/node/loadPlugins.js +42 -47
- package/dist/js/node/manager.js +45 -0
- package/dist/js/node/pluginAPI.js +54 -0
- package/dist/types/config/defaults.d.ts +3 -0
- package/dist/types/config/index.d.ts +3 -129
- package/dist/types/config/types/index.d.ts +231 -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 +19 -1
- package/dist/types/index.d.ts +6 -95
- package/dist/types/initWatcher.d.ts +1 -1
- package/dist/types/loadPlugins.d.ts +24 -13
- package/dist/types/manager.d.ts +74 -0
- package/dist/types/pluginAPI.d.ts +13 -0
- package/jest.config.js +0 -1
- package/package.json +13 -8
- package/tests/config.test.ts +1 -1
- package/tests/initWatcher.test.ts +1 -1
- package/tests/loadPlugin.test.ts +32 -43
- package/tests/pluginAPI.test.ts +19 -0
package/tests/config.test.ts
CHANGED
|
@@ -26,7 +26,7 @@ jest.mock('@modern-js/utils', () => ({
|
|
|
26
26
|
|
|
27
27
|
describe('config', () => {
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* TypeScript Type annotations cannot be used for esbuild-jest
|
|
30
30
|
* test files that use jest.mock('@some/module')
|
|
31
31
|
* refer to this esbuild-jest issue:
|
|
32
32
|
* https://github.com/aelbore/esbuild-jest/issues/57
|
|
@@ -8,7 +8,7 @@ const mockAppDirectory = path.join(__dirname, './fixtures/index-test');
|
|
|
8
8
|
const mockConfigDir = './config';
|
|
9
9
|
const mockSrcDirectory = path.join(mockAppDirectory, './src');
|
|
10
10
|
|
|
11
|
-
describe('initWatcher', () => {
|
|
11
|
+
describe.skip('initWatcher', () => {
|
|
12
12
|
afterAll(() => {
|
|
13
13
|
const file = path.join(mockSrcDirectory, './index.ts');
|
|
14
14
|
if (fs.existsSync(file)) {
|
package/tests/loadPlugin.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import { CliPlugin } from '../src';
|
|
2
3
|
import { loadPlugins, getAppPlugins } from '../src/loadPlugins';
|
|
3
4
|
|
|
4
5
|
describe('load plugins', () => {
|
|
@@ -33,14 +34,10 @@ describe('load plugins', () => {
|
|
|
33
34
|
{
|
|
34
35
|
cli: {
|
|
35
36
|
name: 'a',
|
|
36
|
-
pluginPath: path.join(fixture, './test-plugin-a.js'),
|
|
37
37
|
},
|
|
38
|
-
cliPkg: path.join(fixture, './test-plugin-a.js'),
|
|
39
38
|
},
|
|
40
39
|
{
|
|
41
|
-
server:
|
|
42
|
-
pluginPath: path.join(fixture, './test-plugin-b.js'),
|
|
43
|
-
},
|
|
40
|
+
server: './test-plugin-b',
|
|
44
41
|
serverPkg: './test-plugin-b',
|
|
45
42
|
},
|
|
46
43
|
]);
|
|
@@ -56,22 +53,8 @@ describe('load plugins', () => {
|
|
|
56
53
|
plugins: [{ cli: ['./test-plugin-c', 'c'] }, ['./test-plugin-c', 'c2']],
|
|
57
54
|
});
|
|
58
55
|
|
|
59
|
-
expect(plugins).toEqual(
|
|
60
|
-
|
|
61
|
-
cli: {
|
|
62
|
-
name: 'c',
|
|
63
|
-
pluginPath: path.join(fixture, './test-plugin-c.js'),
|
|
64
|
-
},
|
|
65
|
-
cliPkg: './test-plugin-c',
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
cli: {
|
|
69
|
-
name: 'c2',
|
|
70
|
-
pluginPath: path.join(fixture, './test-plugin-c.js'),
|
|
71
|
-
},
|
|
72
|
-
cliPkg: './test-plugin-c',
|
|
73
|
-
},
|
|
74
|
-
]);
|
|
56
|
+
expect(plugins[0].cli!.name).toEqual('c');
|
|
57
|
+
expect(plugins[1].cli!.name).toEqual('c2');
|
|
75
58
|
});
|
|
76
59
|
|
|
77
60
|
test('should load user string plugin successfully', () => {
|
|
@@ -88,33 +71,11 @@ describe('load plugins', () => {
|
|
|
88
71
|
{
|
|
89
72
|
cli: {
|
|
90
73
|
name: 'a',
|
|
91
|
-
pluginPath: path.join(fixture, './test-plugin-a.js'),
|
|
92
74
|
},
|
|
93
|
-
cliPkg: path.join(fixture, './test-plugin-a.js'),
|
|
94
75
|
},
|
|
95
76
|
]);
|
|
96
77
|
});
|
|
97
78
|
|
|
98
|
-
test('should call transformPlugin', () => {
|
|
99
|
-
const fixture = path.resolve(
|
|
100
|
-
__dirname,
|
|
101
|
-
'./fixtures/load-plugin/user-plugins',
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const options = {
|
|
105
|
-
transformPlugin: jest.fn(),
|
|
106
|
-
};
|
|
107
|
-
options.transformPlugin.mockImplementation((plugins, _) => plugins);
|
|
108
|
-
|
|
109
|
-
loadPlugins(
|
|
110
|
-
fixture,
|
|
111
|
-
{ plugins: [{ cli: path.join(fixture, './test-plugin-a.js') }] },
|
|
112
|
-
options,
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
expect(options.transformPlugin).toHaveBeenCalled();
|
|
116
|
-
});
|
|
117
|
-
|
|
118
79
|
test(`should throw error when plugin not found `, () => {
|
|
119
80
|
const fixture = path.resolve(__dirname, './fixtures/load-plugin/not-found');
|
|
120
81
|
|
|
@@ -124,4 +85,32 @@ describe('load plugins', () => {
|
|
|
124
85
|
});
|
|
125
86
|
}).toThrowError(/^Can not find plugin /);
|
|
126
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
|
+
});
|
|
127
116
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
});
|