@modern-js/core 1.1.5-beta.1 → 1.3.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 +43 -0
- package/dist/js/modern/cli.js +29 -0
- package/dist/js/modern/config/index.js +11 -5
- package/dist/js/modern/index.js +18 -9
- package/dist/js/modern/loadPlugins.js +16 -2
- package/dist/js/node/cli.js +35 -0
- package/dist/js/node/config/index.js +11 -5
- package/dist/js/node/index.js +27 -36
- package/dist/js/node/loadPlugins.js +17 -1
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config/index.d.ts +14 -13
- package/dist/types/index.d.ts +7 -7
- package/dist/types/loadPlugins.d.ts +5 -0
- package/jest.config.js +8 -0
- package/modern.config.js +0 -7
- package/package.json +25 -19
- package/src/cli.ts +36 -0
- package/src/config/index.ts +42 -17
- package/src/index.ts +21 -20
- package/src/loadPlugins.ts +23 -6
- package/tests/btsm.test.ts +20 -0
- package/tests/config.test.ts +137 -0
- package/tests/context.test.ts +28 -0
- package/tests/fixtures/index-test/package.json +3 -0
- package/tests/index.test.ts +74 -0
- package/tests/loadEnv.test.ts +1 -1
- package/tests/loadPlugin.test.ts +36 -1
- package/tests/mergeConfig.test.ts +1 -1
- package/tests/repeatKeyWarning.test.ts +2 -2
- package/tests/schema.test.ts +1 -1
- package/tests/tsconfig.json +1 -3
- package/tests/utils.test.ts +8 -0
- package/tsconfig.json +1 -3
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { cli } from '../src';
|
|
3
|
+
import { resolveConfig, loadUserConfig } from '../src/config';
|
|
4
|
+
import { loadEnv } from '../src/loadEnv';
|
|
5
|
+
|
|
6
|
+
jest.mock('../src/config', () => ({
|
|
7
|
+
__esModule: true,
|
|
8
|
+
...jest.requireActual('../src/config'),
|
|
9
|
+
loadUserConfig: jest.fn(),
|
|
10
|
+
resolveConfig: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock('../src/loadEnv', () => ({
|
|
14
|
+
__esModule: true,
|
|
15
|
+
...jest.requireActual('../src/loadEnv'),
|
|
16
|
+
loadEnv: jest.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
describe('@modern-js/core test', () => {
|
|
20
|
+
let mockResolveConfig: any = {};
|
|
21
|
+
let mockLoadedConfig: any = {};
|
|
22
|
+
const cwdSpy = jest.spyOn(process, 'cwd');
|
|
23
|
+
const cwd = path.join(__dirname, './fixtures/index-test');
|
|
24
|
+
|
|
25
|
+
const resetMock = () => {
|
|
26
|
+
jest.resetAllMocks();
|
|
27
|
+
cwdSpy.mockReturnValue(cwd);
|
|
28
|
+
(resolveConfig as jest.Mock).mockReturnValue(
|
|
29
|
+
Promise.resolve(mockResolveConfig),
|
|
30
|
+
);
|
|
31
|
+
(loadUserConfig as jest.Mock).mockImplementation(() =>
|
|
32
|
+
Promise.resolve(mockLoadedConfig),
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const resetValues = () => {
|
|
37
|
+
mockLoadedConfig = {
|
|
38
|
+
config: {},
|
|
39
|
+
filePath: false,
|
|
40
|
+
dependencies: [],
|
|
41
|
+
pkgConfig: {},
|
|
42
|
+
jsConfig: {},
|
|
43
|
+
};
|
|
44
|
+
mockResolveConfig = {
|
|
45
|
+
server: {
|
|
46
|
+
port: 8080,
|
|
47
|
+
},
|
|
48
|
+
output: {
|
|
49
|
+
path: './my/test/path',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
resetValues();
|
|
56
|
+
resetMock();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('test cli create', () => {
|
|
60
|
+
expect(cli).toBeTruthy();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('test cli init dev', async () => {
|
|
64
|
+
cwdSpy.mockReturnValue(path.join(cwd, 'nested-folder'));
|
|
65
|
+
const options = {
|
|
66
|
+
beforeUsePlugins: jest.fn(),
|
|
67
|
+
};
|
|
68
|
+
options.beforeUsePlugins.mockImplementation((plugins, _) => plugins);
|
|
69
|
+
await cli.init(['dev'], options);
|
|
70
|
+
expect(loadEnv).toHaveBeenCalledWith(cwd);
|
|
71
|
+
expect(options.beforeUsePlugins).toHaveBeenCalledWith([], {});
|
|
72
|
+
// TODO: add more test cases
|
|
73
|
+
});
|
|
74
|
+
});
|
package/tests/loadEnv.test.ts
CHANGED
package/tests/loadPlugin.test.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { loadPlugins } from '
|
|
2
|
+
import { loadPlugins, getAppPlugins } from '../src/loadPlugins';
|
|
3
3
|
|
|
4
4
|
describe('load plugins', () => {
|
|
5
|
+
test('getAppPlugins', () => {
|
|
6
|
+
const appDirectory = path.resolve(
|
|
7
|
+
__dirname,
|
|
8
|
+
'./fixtures/load-plugin/user-plugins',
|
|
9
|
+
);
|
|
10
|
+
const plugins = getAppPlugins(appDirectory, ['foo' as any], {
|
|
11
|
+
x: {
|
|
12
|
+
cli: 'x',
|
|
13
|
+
forced: true,
|
|
14
|
+
} as any,
|
|
15
|
+
});
|
|
16
|
+
expect(plugins).toEqual([{ cli: 'x', forced: true }, 'foo']);
|
|
17
|
+
});
|
|
18
|
+
|
|
5
19
|
test('should load user plugin successfully', () => {
|
|
6
20
|
const fixture = path.resolve(
|
|
7
21
|
__dirname,
|
|
@@ -31,6 +45,27 @@ describe('load plugins', () => {
|
|
|
31
45
|
]);
|
|
32
46
|
});
|
|
33
47
|
|
|
48
|
+
test('should load user string plugin successfully', () => {
|
|
49
|
+
const fixture = path.resolve(
|
|
50
|
+
__dirname,
|
|
51
|
+
'./fixtures/load-plugin/user-plugins',
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const plugins = loadPlugins(fixture, [
|
|
55
|
+
path.join(fixture, './test-plugin-a.js') as any,
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
expect(plugins).toEqual([
|
|
59
|
+
{
|
|
60
|
+
cli: {
|
|
61
|
+
name: 'a',
|
|
62
|
+
pluginPath: path.join(fixture, './test-plugin-a.js'),
|
|
63
|
+
},
|
|
64
|
+
cliPath: path.join(fixture, './test-plugin-a.js'),
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
|
|
34
69
|
test(`should throw error when plugin not found `, () => {
|
|
35
70
|
const fixture = path.resolve(__dirname, './fixtures/load-plugin/not-found');
|
|
36
71
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { repeatKeyWarning } from '
|
|
2
|
-
import { UserConfig } from '
|
|
1
|
+
import { repeatKeyWarning } from '../src/utils/repeatKeyWarning';
|
|
2
|
+
import { UserConfig } from '../src/config';
|
|
3
3
|
|
|
4
4
|
jest.spyOn(process, 'exit').mockImplementation();
|
|
5
5
|
|
package/tests/schema.test.ts
CHANGED
package/tests/tsconfig.json
CHANGED