@modern-js/module-tools 1.4.3 → 1.4.6
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 +80 -0
- package/dist/js/modern/features/build/build-platform.js +1 -2
- package/dist/js/modern/features/build/build-watch.js +1 -2
- package/dist/js/modern/features/build/build.js +2 -5
- package/dist/js/modern/features/dev/index.js +1 -2
- package/dist/js/modern/hooks/build.js +20 -0
- package/dist/js/modern/hooks/dev.js +11 -0
- package/dist/js/modern/hooks/index.js +14 -0
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/tasks/build-source-code.js +1 -2
- package/dist/js/modern/tasks/build-style.js +2 -3
- package/dist/js/modern/tasks/build-watch-style.js +3 -6
- package/dist/js/modern/tasks/copy-assets.js +1 -2
- package/dist/js/modern/tasks/generator-dts/index.js +8 -11
- package/dist/js/modern/tasks/generator-dts/utils.js +11 -3
- package/dist/js/modern/utils/babel.js +2 -19
- package/dist/js/modern/utils/copy.js +1 -2
- package/dist/js/modern/utils/logger.js +1 -2
- package/dist/js/node/features/build/build-platform.js +2 -3
- package/dist/js/node/features/build/build-watch.js +1 -3
- package/dist/js/node/features/build/build.js +1 -6
- package/dist/js/node/features/dev/index.js +2 -6
- package/dist/js/node/hooks/build.js +37 -0
- package/dist/js/node/hooks/dev.js +25 -0
- package/dist/js/node/hooks/index.js +39 -0
- package/dist/js/node/index.js +2 -2
- package/dist/js/node/tasks/build-source-code.js +3 -3
- package/dist/js/node/tasks/build-style.js +2 -4
- package/dist/js/node/tasks/build-watch-style.js +3 -7
- package/dist/js/node/tasks/copy-assets.js +1 -3
- package/dist/js/node/tasks/generator-dts/index.js +8 -16
- package/dist/js/node/tasks/generator-dts/utils.js +18 -8
- package/dist/js/node/utils/babel.js +1 -18
- package/dist/js/node/utils/copy.js +1 -2
- package/dist/js/node/utils/logger.js +5 -7
- package/dist/types/cli/build.d.ts +1 -1
- package/dist/types/cli/dev.d.ts +1 -1
- package/dist/types/cli/new.d.ts +1 -1
- package/dist/types/hooks/build.d.ts +46 -0
- package/dist/types/hooks/dev.d.ts +18 -0
- package/dist/types/hooks/index.d.ts +26 -0
- package/dist/types/tasks/generator-dts/utils.d.ts +2 -1
- package/dist/types/utils/babel.d.ts +2 -3
- package/jest.config.js +0 -3
- package/package.json +22 -25
- package/tests/dev-cli.test.ts +0 -59
- package/tests/dev-command.test.ts +0 -70
- package/tests/dev-feature.test.ts +0 -78
- package/tests/fixtures/tspaths/a.ts +0 -1
- package/tests/fixtures/tspaths/b.ts +0 -1
- package/tests/generator-dts-utils.test.ts +0 -10
- package/tests/generator-dts.test.ts +0 -48
- package/tests/index.test.ts +0 -7
- package/tests/tsconfig.json +0 -11
- package/tests/tspaths-transform.test.ts +0 -21
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { manager } from '@modern-js/core';
|
|
2
|
-
import { runSubCmd } from '../src/features/dev';
|
|
3
|
-
|
|
4
|
-
const mockModuleToolsMenu = jest.fn();
|
|
5
|
-
const mockDevMeta = jest.fn();
|
|
6
|
-
const exit = jest.spyOn(process, 'exit').mockImplementation();
|
|
7
|
-
const mockAPI = {
|
|
8
|
-
useAppContext: jest.fn((): any => ({})),
|
|
9
|
-
useResolvedConfigContext: jest.fn(),
|
|
10
|
-
useHookRunners: (): any => ({
|
|
11
|
-
moduleToolsMenu: mockModuleToolsMenu,
|
|
12
|
-
}),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
describe('dev feature with subCmd', () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
jest.clearAllMocks();
|
|
18
|
-
});
|
|
19
|
-
it('should run task with "storybook" params when storybook plugin exist', async () => {
|
|
20
|
-
mockModuleToolsMenu.mockReturnValue([
|
|
21
|
-
{ value: 'storybook', runTask: mockDevMeta },
|
|
22
|
-
]);
|
|
23
|
-
const cloned = manager.clone(mockAPI);
|
|
24
|
-
cloned.usePlugin({
|
|
25
|
-
async setup(api) {
|
|
26
|
-
await runSubCmd(api, 'storybook', {
|
|
27
|
-
isTsProject: true,
|
|
28
|
-
appDirectory: '',
|
|
29
|
-
});
|
|
30
|
-
expect(mockDevMeta.mock.calls.length).toBe(1);
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
await cloned.init();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should run task with "storybook" params when storybook plugin not exist', async () => {
|
|
37
|
-
mockModuleToolsMenu.mockReturnValue([]);
|
|
38
|
-
const cloned = manager.clone(mockAPI);
|
|
39
|
-
cloned.usePlugin({
|
|
40
|
-
async setup(api) {
|
|
41
|
-
await runSubCmd(api, 'storybook', {
|
|
42
|
-
isTsProject: true,
|
|
43
|
-
appDirectory: '',
|
|
44
|
-
});
|
|
45
|
-
expect(exit).toHaveBeenCalled();
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
await cloned.init();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should run task with alias name "story" params when storybook plugin exist', async () => {
|
|
52
|
-
mockModuleToolsMenu.mockReturnValue([
|
|
53
|
-
{ value: 'storybook', aliasValues: ['story'], runTask: mockDevMeta },
|
|
54
|
-
]);
|
|
55
|
-
const cloned = manager.clone(mockAPI);
|
|
56
|
-
cloned.usePlugin({
|
|
57
|
-
async setup(api) {
|
|
58
|
-
await runSubCmd(api, 'story', { isTsProject: true, appDirectory: '' });
|
|
59
|
-
expect(mockDevMeta.mock.calls.length).toBe(1);
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
await cloned.init();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should run task with alias name "story1" params when storybook plugin exist', async () => {
|
|
66
|
-
mockModuleToolsMenu.mockReturnValue([
|
|
67
|
-
{ value: 'storybook', aliasValues: ['story'], runTask: mockDevMeta },
|
|
68
|
-
]);
|
|
69
|
-
const cloned = manager.clone(mockAPI);
|
|
70
|
-
cloned.usePlugin({
|
|
71
|
-
async setup(api) {
|
|
72
|
-
await runSubCmd(api, 'story1', { isTsProject: true, appDirectory: '' });
|
|
73
|
-
expect(mockDevMeta.mock.calls.length).toBe(0);
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
await cloned.init();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@/b.ts';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const b = 10;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { generatorTsConfig } from '../src/tasks/generator-dts/utils';
|
|
3
|
-
|
|
4
|
-
describe('test generator dts utils', () => {
|
|
5
|
-
it('test generatorTsConfig', () => {
|
|
6
|
-
const appDir = path.join(__dirname, './fixtures/tsconfig');
|
|
7
|
-
const ret = generatorTsConfig({}, { appDirectory: appDir, distDir: '' });
|
|
8
|
-
expect(ret).toContain('tsconfig.temp.json');
|
|
9
|
-
});
|
|
10
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
jest.mock('@modern-js/core', () => ({
|
|
2
|
-
manager: {
|
|
3
|
-
run: async (fn: any) => {
|
|
4
|
-
await fn();
|
|
5
|
-
},
|
|
6
|
-
},
|
|
7
|
-
cli: {
|
|
8
|
-
init: () => ({}),
|
|
9
|
-
},
|
|
10
|
-
}));
|
|
11
|
-
jest.mock('process.argv', () => () => (o: any) => ({ ...o, tsCheck: false }));
|
|
12
|
-
jest.mock('execa', () => () => {
|
|
13
|
-
// eslint-disable-next-line prefer-promise-reject-errors
|
|
14
|
-
const fn = Promise.reject('error');
|
|
15
|
-
(fn as any).stdout = {
|
|
16
|
-
on: () => 0,
|
|
17
|
-
};
|
|
18
|
-
(fn as any).stderr = {
|
|
19
|
-
on: () => 0,
|
|
20
|
-
};
|
|
21
|
-
return fn;
|
|
22
|
-
});
|
|
23
|
-
jest.mock('../src/tasks/generator-dts/utils');
|
|
24
|
-
jest.mock('@modern-js/utils', () => {
|
|
25
|
-
const originalModule = jest.requireActual('@modern-js/utils');
|
|
26
|
-
return {
|
|
27
|
-
__esModule: true, // Use it when dealing with esModules
|
|
28
|
-
...originalModule,
|
|
29
|
-
fs: {
|
|
30
|
-
...originalModule.fs,
|
|
31
|
-
removeSync: jest.fn(),
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
process.argv = [];
|
|
36
|
-
|
|
37
|
-
describe('generator dts test', () => {
|
|
38
|
-
it('test tsCheck is true', () => {
|
|
39
|
-
console.info = jest.fn(str => {
|
|
40
|
-
expect(str).toBe(
|
|
41
|
-
"There are some type warnings, which can be checked by configuring 'output.disableTsChecker = false'",
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
require('../src/tasks/generator-dts');
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
export {};
|
package/tests/index.test.ts
DELETED
package/tests/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { transformDtsAlias } from '../src/utils/tspaths-transform';
|
|
3
|
-
|
|
4
|
-
describe('tspaths-transform', () => {
|
|
5
|
-
it('transformDtsAlias', () => {
|
|
6
|
-
const filepath = path.join(__dirname, 'fixtures/tspaths/a.ts');
|
|
7
|
-
const options = {
|
|
8
|
-
filenames: [filepath],
|
|
9
|
-
baseUrl: './',
|
|
10
|
-
paths: {
|
|
11
|
-
'@/*': ['./*'],
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
expect(transformDtsAlias(options)).toEqual([
|
|
15
|
-
{
|
|
16
|
-
path: filepath,
|
|
17
|
-
content: "import '@/b.ts';",
|
|
18
|
-
},
|
|
19
|
-
]);
|
|
20
|
-
});
|
|
21
|
-
});
|