@modern-js/babel-compiler 1.2.2 → 1.2.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/CHANGELOG.md +35 -0
- package/dist/js/modern/buildWatch.js +6 -5
- package/dist/js/modern/compilerErrorResult.js +4 -1
- package/dist/js/modern/getFinalOption.js +1 -1
- package/dist/js/modern/type.js +0 -1
- package/dist/js/node/buildWatch.js +6 -5
- package/dist/js/node/compilerErrorResult.js +4 -1
- package/dist/js/node/getFinalOption.js +2 -6
- package/dist/js/node/type.js +0 -5
- package/dist/types/buildWatch.d.ts +1 -1
- package/dist/types/getFinalOption.d.ts +2 -2
- package/dist/types/type.d.ts +5 -5
- package/package.json +28 -8
- package/jest.config.js +0 -8
- package/modern.config.js +0 -6
- package/tests/.eslintrc.js +0 -6
- package/tests/build.test.ts +0 -122
- package/tests/buildWatch.test.ts +0 -251
- package/tests/compiler.test.ts +0 -112
- package/tests/compilerErrorResult.test.ts +0 -119
- package/tests/constants.test.ts +0 -12
- package/tests/defaults.test.ts +0 -29
- package/tests/fixtures/build/src/error +0 -1
- package/tests/fixtures/build/src/error1 +0 -1
- package/tests/fixtures/build/src/far.js +0 -0
- package/tests/fixtures/build/src/index.js +0 -0
- package/tests/fixtures/buildWatch/src/error +0 -2
- package/tests/fixtures/buildWatch/src/index.js +0 -0
- package/tests/fixtures/compiler/src/index.js +0 -2
- package/tests/fixtures/getFinalOption/sourceDir/bar.js +0 -0
- package/tests/fixtures/getFinalOption/watchDir/far.js +0 -0
- package/tests/fixtures/getFinalOption/watchDir/foo.jsx +0 -0
- package/tests/fixtures/lib/src/index.js +0 -0
- package/tests/fixtures/resolveSourceMap/src/index.js +0 -2
- package/tests/fixtures/utils/far +0 -2
- package/tests/getFinalOption.test.ts +0 -108
- package/tests/index.test.ts +0 -89
- package/tests/tsconfig.json +0 -13
- package/tests/utils.test.ts +0 -20
- package/tests/validate.test.ts +0 -68
- package/tsconfig.json +0 -14
package/tests/index.test.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { logger } from '@modern-js/utils';
|
|
3
|
-
import { compiler } from '../src';
|
|
4
|
-
import {
|
|
5
|
-
sourceDirAndFileNamesValidMessage,
|
|
6
|
-
watchDirValidMessage,
|
|
7
|
-
} from '../src/validate';
|
|
8
|
-
|
|
9
|
-
const projectDir = path.join(__dirname, './fixtures/lib');
|
|
10
|
-
const srcDir = path.join(projectDir, 'src');
|
|
11
|
-
const distDir = path.join(projectDir, 'dist');
|
|
12
|
-
|
|
13
|
-
const originalLogInfo = logger.info;
|
|
14
|
-
const originalLogError = logger.error;
|
|
15
|
-
|
|
16
|
-
describe('babel compiler', () => {
|
|
17
|
-
let testLogs: any[] = [];
|
|
18
|
-
const mockedLogInfo = (s: string | number | Error | undefined) =>
|
|
19
|
-
testLogs.push(s);
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
logger.info = mockedLogInfo;
|
|
22
|
-
logger.error = mockedLogInfo;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('normal compiler', async () => {
|
|
26
|
-
const ret = await compiler(
|
|
27
|
-
{
|
|
28
|
-
rootDir: srcDir,
|
|
29
|
-
filenames: [path.join(srcDir, 'index.js')],
|
|
30
|
-
distDir,
|
|
31
|
-
enableVirtualDist: true,
|
|
32
|
-
},
|
|
33
|
-
{},
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
expect(ret.code).toBe(0);
|
|
37
|
-
expect(ret.virtualDists?.length).toBe(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('compiler with valid', async () => {
|
|
41
|
-
const ret = await compiler(
|
|
42
|
-
{
|
|
43
|
-
rootDir: srcDir,
|
|
44
|
-
distDir,
|
|
45
|
-
enableVirtualDist: true,
|
|
46
|
-
},
|
|
47
|
-
{},
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
expect(ret.code).toBe(1);
|
|
51
|
-
expect(ret.message).toBe(sourceDirAndFileNamesValidMessage);
|
|
52
|
-
|
|
53
|
-
const ret_1 = await compiler(
|
|
54
|
-
{
|
|
55
|
-
rootDir: srcDir,
|
|
56
|
-
distDir,
|
|
57
|
-
filenames: [path.join(srcDir, 'index.js')],
|
|
58
|
-
enableWatch: true,
|
|
59
|
-
enableVirtualDist: true,
|
|
60
|
-
},
|
|
61
|
-
{},
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
expect((ret_1 as any).code).toBe(1);
|
|
65
|
-
expect((ret_1 as any).message).toBe(watchDirValidMessage);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('compiler in watch mode', async () => {
|
|
69
|
-
const emitter = await compiler(
|
|
70
|
-
{
|
|
71
|
-
rootDir: srcDir,
|
|
72
|
-
filenames: [path.join(srcDir, 'index.js')],
|
|
73
|
-
distDir,
|
|
74
|
-
enableWatch: true,
|
|
75
|
-
watchDir: srcDir,
|
|
76
|
-
enableVirtualDist: true,
|
|
77
|
-
},
|
|
78
|
-
{},
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
expect('on' in emitter).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
afterEach(() => {
|
|
85
|
-
logger.info = originalLogInfo;
|
|
86
|
-
logger.error = originalLogError;
|
|
87
|
-
testLogs = [];
|
|
88
|
-
});
|
|
89
|
-
});
|
package/tests/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@modern-js/tsconfig/base",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"jsx": "preserve",
|
|
6
|
-
"baseUrl": "./",
|
|
7
|
-
"outDir": "./out",
|
|
8
|
-
"emitDeclarationOnly": true,
|
|
9
|
-
"isolatedModules": true,
|
|
10
|
-
"paths": {},
|
|
11
|
-
"types": ["node", "jest"]
|
|
12
|
-
}
|
|
13
|
-
}
|
package/tests/utils.test.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// import * as path from 'path';
|
|
2
|
-
// import { fs } from '@modern-js/utils';
|
|
3
|
-
// import { addSourceMappingUrl } from '../src/utils';
|
|
4
|
-
|
|
5
|
-
describe('utils test', () => {
|
|
6
|
-
it('addSourceMappingUrl should right', () => {
|
|
7
|
-
// const code = 'const far = 1;';
|
|
8
|
-
// const mapLoc = `far.js.map`;
|
|
9
|
-
// const codeWithSourceMappingUrl = addSourceMappingUrl(code, mapLoc);
|
|
10
|
-
// const rightCodeWithSourceMappingUrl = fs.readFileSync(
|
|
11
|
-
// path.join(__dirname, './fixtures/utils/far'),
|
|
12
|
-
// 'utf-8',
|
|
13
|
-
// );
|
|
14
|
-
// expect(rightCodeWithSourceMappingUrl.trim()).toMatch(
|
|
15
|
-
// codeWithSourceMappingUrl.trim(),
|
|
16
|
-
// );
|
|
17
|
-
// FIXME: git 回车在 Windows 与 Unix 下不一致
|
|
18
|
-
expect(0).toBe(0);
|
|
19
|
-
});
|
|
20
|
-
});
|
package/tests/validate.test.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
validate,
|
|
3
|
-
validateWatchDir,
|
|
4
|
-
validateSourceDirAndFileNames,
|
|
5
|
-
sourceDirAndFileNamesValidMessage,
|
|
6
|
-
watchDirValidMessage,
|
|
7
|
-
} from '../src/validate';
|
|
8
|
-
|
|
9
|
-
describe('valide', () => {
|
|
10
|
-
const baseOption = { rootDir: './', distDir: './dist', quiet: true };
|
|
11
|
-
|
|
12
|
-
it('valide sourceDir and filenams config', () => {
|
|
13
|
-
const ret_1 = validateSourceDirAndFileNames({
|
|
14
|
-
...baseOption,
|
|
15
|
-
sourceDir: './src',
|
|
16
|
-
});
|
|
17
|
-
expect(ret_1).toBe(null);
|
|
18
|
-
const ret_2 = validateSourceDirAndFileNames({
|
|
19
|
-
...baseOption,
|
|
20
|
-
filenames: ['./far.js'],
|
|
21
|
-
});
|
|
22
|
-
expect(ret_2).toBe(null);
|
|
23
|
-
|
|
24
|
-
const ret_3 = validateSourceDirAndFileNames({
|
|
25
|
-
...baseOption,
|
|
26
|
-
sourceDir: './src',
|
|
27
|
-
filenames: ['./far.js'],
|
|
28
|
-
});
|
|
29
|
-
expect(ret_3).toBe(null);
|
|
30
|
-
|
|
31
|
-
const ret_4 = validateSourceDirAndFileNames({ ...baseOption });
|
|
32
|
-
expect(ret_4).toStrictEqual({
|
|
33
|
-
code: 1,
|
|
34
|
-
message: sourceDirAndFileNamesValidMessage,
|
|
35
|
-
virtualDists: [],
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('valid watchDir config', () => {
|
|
40
|
-
const ret_1 = validateWatchDir({ ...baseOption, enableWatch: true });
|
|
41
|
-
expect(ret_1).toStrictEqual({
|
|
42
|
-
code: 1,
|
|
43
|
-
message: watchDirValidMessage,
|
|
44
|
-
virtualDists: [],
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const ret_2 = validateWatchDir({
|
|
48
|
-
...baseOption,
|
|
49
|
-
enableWatch: true,
|
|
50
|
-
watchDir: './src',
|
|
51
|
-
});
|
|
52
|
-
expect(ret_2).toBe(null);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('validate', () => {
|
|
56
|
-
const ret_1 = validate({ ...baseOption, sourceDir: './src' });
|
|
57
|
-
expect(ret_1).toBe(null);
|
|
58
|
-
const ret_2 = validate({ ...baseOption, filenames: ['./far.js'] });
|
|
59
|
-
expect(ret_2).toBe(null);
|
|
60
|
-
const ret_3 = validate({
|
|
61
|
-
...baseOption,
|
|
62
|
-
sourceDir: './src',
|
|
63
|
-
enableWatch: true,
|
|
64
|
-
watchDir: './src',
|
|
65
|
-
});
|
|
66
|
-
expect(ret_3).toBe(null);
|
|
67
|
-
});
|
|
68
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@modern-js/tsconfig/base",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"jsx": "preserve",
|
|
6
|
-
"baseUrl": "./",
|
|
7
|
-
"outDir": "./out",
|
|
8
|
-
"emitDeclarationOnly": true,
|
|
9
|
-
"isolatedModules": true,
|
|
10
|
-
"paths": {},
|
|
11
|
-
"types": ["node", "jest"]
|
|
12
|
-
},
|
|
13
|
-
"include": ["src"]
|
|
14
|
-
}
|