@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.
Files changed (50) hide show
  1. package/.eslintrc.js +8 -0
  2. package/CHANGELOG.md +47 -0
  3. package/dist/js/modern/config/defaults.js +4 -1
  4. package/dist/js/modern/config/index.js +2 -1
  5. package/dist/js/modern/config/types/index.js +0 -0
  6. package/dist/js/modern/config/types/less.js +0 -0
  7. package/dist/js/modern/config/types/sass.js +0 -0
  8. package/dist/js/modern/config/types/ssg.js +0 -0
  9. package/dist/js/modern/config/types/test.js +0 -0
  10. package/dist/js/modern/config/types/unbundle.js +0 -0
  11. package/dist/js/modern/context.js +18 -0
  12. package/dist/js/modern/index.js +9 -28
  13. package/dist/js/modern/initWatcher.js +1 -0
  14. package/dist/js/modern/loadPlugins.js +43 -48
  15. package/dist/js/modern/manager.js +28 -0
  16. package/dist/js/modern/pluginAPI.js +11 -0
  17. package/dist/js/node/config/defaults.js +4 -1
  18. package/dist/js/node/config/index.js +22 -1
  19. package/dist/js/node/config/types/index.js +0 -0
  20. package/dist/js/node/config/types/less.js +0 -0
  21. package/dist/js/node/config/types/sass.js +0 -0
  22. package/dist/js/node/config/types/ssg.js +0 -0
  23. package/dist/js/node/config/types/test.js +0 -0
  24. package/dist/js/node/config/types/unbundle.js +0 -0
  25. package/dist/js/node/context.js +22 -1
  26. package/dist/js/node/index.js +78 -67
  27. package/dist/js/node/initWatcher.js +1 -0
  28. package/dist/js/node/loadPlugins.js +42 -47
  29. package/dist/js/node/manager.js +45 -0
  30. package/dist/js/node/pluginAPI.js +54 -0
  31. package/dist/types/config/defaults.d.ts +3 -0
  32. package/dist/types/config/index.d.ts +3 -129
  33. package/dist/types/config/types/index.d.ts +231 -0
  34. package/dist/types/config/types/less.d.ts +10 -0
  35. package/dist/types/config/types/sass.d.ts +8 -0
  36. package/dist/types/config/types/ssg.d.ts +13 -0
  37. package/dist/types/config/types/test.d.ts +15 -0
  38. package/dist/types/config/types/unbundle.d.ts +28 -0
  39. package/dist/types/context.d.ts +19 -1
  40. package/dist/types/index.d.ts +6 -95
  41. package/dist/types/initWatcher.d.ts +1 -1
  42. package/dist/types/loadPlugins.d.ts +24 -13
  43. package/dist/types/manager.d.ts +74 -0
  44. package/dist/types/pluginAPI.d.ts +13 -0
  45. package/jest.config.js +0 -1
  46. package/package.json +13 -8
  47. package/tests/config.test.ts +1 -1
  48. package/tests/initWatcher.test.ts +1 -1
  49. package/tests/loadPlugin.test.ts +32 -43
  50. package/tests/pluginAPI.test.ts +19 -0
@@ -26,7 +26,7 @@ jest.mock('@modern-js/utils', () => ({
26
26
 
27
27
  describe('config', () => {
28
28
  /**
29
- * Typescript Type annotations cannot be used for esbuild-jest
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)) {
@@ -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
+ });