@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/buildWatch.test.ts
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { fs, logger } from '@modern-js/utils';
|
|
3
|
-
import {
|
|
4
|
-
buildWatch,
|
|
5
|
-
BuildWatchEmitter,
|
|
6
|
-
runBuildWatch,
|
|
7
|
-
BuildWatchEvent,
|
|
8
|
-
} from '../src/buildWatch';
|
|
9
|
-
import { ICompilerResult } from '../src/type';
|
|
10
|
-
|
|
11
|
-
const projectDir = path.join(__dirname, './fixtures/buildWatch');
|
|
12
|
-
const srcDir = path.join(projectDir, 'src');
|
|
13
|
-
const distDir = path.join(projectDir, 'dist');
|
|
14
|
-
|
|
15
|
-
const originalLogInfo = logger.info;
|
|
16
|
-
const originalLogError = logger.error;
|
|
17
|
-
|
|
18
|
-
describe('test build watch', () => {
|
|
19
|
-
let testLogs: any[] = [];
|
|
20
|
-
const mockedLogInfo = (s: string | number | Error | undefined) =>
|
|
21
|
-
testLogs.push(s);
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
logger.info = mockedLogInfo;
|
|
24
|
-
logger.error = mockedLogInfo;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('class BuildWatchEmitter', async () => {
|
|
28
|
-
let run = false;
|
|
29
|
-
const emitter = new BuildWatchEmitter();
|
|
30
|
-
emitter.setInitFn(() => {
|
|
31
|
-
run = true;
|
|
32
|
-
});
|
|
33
|
-
await emitter.watch();
|
|
34
|
-
expect(run).toBe(true);
|
|
35
|
-
|
|
36
|
-
const emitter_1 = new BuildWatchEmitter();
|
|
37
|
-
emitter_1.setInitFn(true as any);
|
|
38
|
-
const ret = await emitter_1.watch();
|
|
39
|
-
expect(ret).toBe(null);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('runBuildWatch and success', async () => {
|
|
43
|
-
let done: any;
|
|
44
|
-
const promise = new Promise(resolve => (done = resolve));
|
|
45
|
-
let compiling = false;
|
|
46
|
-
const emitter = new BuildWatchEmitter();
|
|
47
|
-
emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
|
|
48
|
-
expect(result.code).toBe(0);
|
|
49
|
-
});
|
|
50
|
-
emitter.on(BuildWatchEvent.compiling, () => {
|
|
51
|
-
expect(compiling).toBe(true);
|
|
52
|
-
});
|
|
53
|
-
emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
|
|
54
|
-
expect(result.code).toBe(0);
|
|
55
|
-
watcher.close();
|
|
56
|
-
done();
|
|
57
|
-
});
|
|
58
|
-
const filenames = [path.join(srcDir, 'index.js')];
|
|
59
|
-
compiling = true;
|
|
60
|
-
const watcher = await runBuildWatch(
|
|
61
|
-
{ rootDir: srcDir, filenames, distDir, watchDir: srcDir },
|
|
62
|
-
{},
|
|
63
|
-
emitter,
|
|
64
|
-
);
|
|
65
|
-
compiling = false;
|
|
66
|
-
watcher.on('ready', () => {
|
|
67
|
-
fs.ensureFileSync(path.join(srcDir, 'far.js'));
|
|
68
|
-
compiling = true;
|
|
69
|
-
});
|
|
70
|
-
return promise;
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('runBuildWatch and fail', async () => {
|
|
74
|
-
let done: any;
|
|
75
|
-
const promise = new Promise(resolve => (done = resolve));
|
|
76
|
-
const emitter = new BuildWatchEmitter();
|
|
77
|
-
emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
|
|
78
|
-
expect(result.code).toBe(1);
|
|
79
|
-
expect(result.messageDetails?.length).toBe(1);
|
|
80
|
-
});
|
|
81
|
-
emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
|
|
82
|
-
expect(result.code).toBe(1);
|
|
83
|
-
expect(result.messageDetails?.length).toBe(2);
|
|
84
|
-
watcher.close();
|
|
85
|
-
done();
|
|
86
|
-
});
|
|
87
|
-
const filenames = [path.join(srcDir, 'error')];
|
|
88
|
-
const watcher = await runBuildWatch(
|
|
89
|
-
{ rootDir: srcDir, filenames, distDir, watchDir: srcDir },
|
|
90
|
-
{},
|
|
91
|
-
emitter,
|
|
92
|
-
);
|
|
93
|
-
watcher.on('ready', () => {
|
|
94
|
-
fs.ensureFileSync(path.join(srcDir, 'error1.js'));
|
|
95
|
-
fs.writeFileSync(path.join(srcDir, 'error1.js'), 'conta a = 1');
|
|
96
|
-
});
|
|
97
|
-
return promise;
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('buildWatch and success', async () => {
|
|
101
|
-
let done: any;
|
|
102
|
-
const promise = new Promise(resolve => (done = resolve));
|
|
103
|
-
const emitter = buildWatch({
|
|
104
|
-
rootDir: srcDir,
|
|
105
|
-
watchDir: srcDir,
|
|
106
|
-
filenames: [path.join(srcDir, 'index.js')],
|
|
107
|
-
distDir,
|
|
108
|
-
enableVirtualDist: true,
|
|
109
|
-
clean: true,
|
|
110
|
-
});
|
|
111
|
-
let compiling = false;
|
|
112
|
-
emitter.on(BuildWatchEvent.compiling, () => {
|
|
113
|
-
expect(compiling).toBe(true);
|
|
114
|
-
});
|
|
115
|
-
emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
|
|
116
|
-
expect(result.code).toBe(0);
|
|
117
|
-
expect(result.virtualDists?.length).toBe(1);
|
|
118
|
-
});
|
|
119
|
-
emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
|
|
120
|
-
expect(result.code).toBe(0);
|
|
121
|
-
expect(result.virtualDists?.length).toBe(1);
|
|
122
|
-
expect(result.virtualDists![0].distPath.includes('far.js')).toBe(true);
|
|
123
|
-
watcher?.close();
|
|
124
|
-
done();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
compiling = true;
|
|
128
|
-
const watcher = await emitter.watch();
|
|
129
|
-
compiling = false;
|
|
130
|
-
if (watcher) {
|
|
131
|
-
watcher.on('ready', () => {
|
|
132
|
-
fs.ensureFileSync(path.join(srcDir, 'far.js'));
|
|
133
|
-
compiling = true;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
return promise;
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('buildWatch and fail', async () => {
|
|
140
|
-
let done: any;
|
|
141
|
-
const promise = new Promise(resolve => (done = resolve));
|
|
142
|
-
const emitter = buildWatch({
|
|
143
|
-
rootDir: srcDir,
|
|
144
|
-
watchDir: srcDir,
|
|
145
|
-
filenames: [path.join(srcDir, 'error')],
|
|
146
|
-
distDir,
|
|
147
|
-
enableVirtualDist: true,
|
|
148
|
-
clean: true,
|
|
149
|
-
});
|
|
150
|
-
let compiling = false;
|
|
151
|
-
emitter.on(BuildWatchEvent.compiling, () => {
|
|
152
|
-
expect(compiling).toBe(true);
|
|
153
|
-
});
|
|
154
|
-
emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
|
|
155
|
-
expect(result.code).toBe(1);
|
|
156
|
-
expect(result.messageDetails?.length).toBe(1);
|
|
157
|
-
});
|
|
158
|
-
emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
|
|
159
|
-
expect(result.code).toBe(1);
|
|
160
|
-
expect(result.messageDetails?.length).toBe(2);
|
|
161
|
-
watcher?.close();
|
|
162
|
-
done();
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
compiling = true;
|
|
166
|
-
const watcher = await emitter.watch();
|
|
167
|
-
compiling = false;
|
|
168
|
-
if (watcher) {
|
|
169
|
-
watcher.on('ready', () => {
|
|
170
|
-
fs.ensureFileSync(path.join(srcDir, 'error1.js'));
|
|
171
|
-
fs.writeFileSync(path.join(srcDir, 'error1.js'), 'cast a = 1;');
|
|
172
|
-
compiling = true;
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return promise;
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('buildWatch and remove file', async () => {
|
|
179
|
-
let done: any;
|
|
180
|
-
const promise = new Promise(resolve => (done = resolve));
|
|
181
|
-
const emitter = buildWatch({
|
|
182
|
-
rootDir: srcDir,
|
|
183
|
-
watchDir: srcDir,
|
|
184
|
-
filenames: [path.join(srcDir, 'index.js')],
|
|
185
|
-
distDir,
|
|
186
|
-
enableVirtualDist: true,
|
|
187
|
-
clean: true,
|
|
188
|
-
quiet: true,
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
|
|
192
|
-
expect(result.code).toBe(0);
|
|
193
|
-
expect(result.message.includes('remove file')).toBe(true);
|
|
194
|
-
expect(result.removeFiles?.length).toBe(1);
|
|
195
|
-
watcher?.close();
|
|
196
|
-
done();
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
fs.ensureFileSync(path.join(srcDir, 'far.js'));
|
|
200
|
-
const watcher = await emitter.watch();
|
|
201
|
-
|
|
202
|
-
if (watcher) {
|
|
203
|
-
watcher.on('ready', () => {
|
|
204
|
-
fs.removeSync(path.join(srcDir, 'far.js'));
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
return promise;
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('buildWatch and reRight file', async () => {
|
|
211
|
-
let done: any;
|
|
212
|
-
const promise = new Promise(resolve => (done = resolve));
|
|
213
|
-
fs.ensureFileSync(path.join(srcDir, 'error1.js'));
|
|
214
|
-
fs.writeFileSync(path.join(srcDir, 'error1.js'), 'cast a = 1;');
|
|
215
|
-
const emitter = buildWatch({
|
|
216
|
-
rootDir: srcDir,
|
|
217
|
-
watchDir: srcDir,
|
|
218
|
-
filenames: [path.join(srcDir, 'error'), path.join(srcDir, 'error1.js')],
|
|
219
|
-
distDir,
|
|
220
|
-
enableVirtualDist: true,
|
|
221
|
-
clean: true,
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
emitter.on(BuildWatchEvent.firstCompiler, (result: ICompilerResult) => {
|
|
225
|
-
expect(result.code).toBe(1);
|
|
226
|
-
expect(result.messageDetails?.length).toBe(2);
|
|
227
|
-
});
|
|
228
|
-
emitter.on(BuildWatchEvent.watchingCompiler, (result: ICompilerResult) => {
|
|
229
|
-
expect(result.code).toBe(1);
|
|
230
|
-
expect(result.messageDetails?.length).toBe(1);
|
|
231
|
-
watcher?.close();
|
|
232
|
-
done();
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
const watcher = await emitter.watch();
|
|
236
|
-
if (watcher) {
|
|
237
|
-
watcher.on('ready', () => {
|
|
238
|
-
fs.writeFileSync(path.join(srcDir, 'error1.js'), 'const a = 1;');
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
return promise;
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
afterEach(() => {
|
|
245
|
-
logger.info = originalLogInfo;
|
|
246
|
-
logger.error = originalLogError;
|
|
247
|
-
testLogs = [];
|
|
248
|
-
fs.removeSync(path.join(srcDir, 'far.js'));
|
|
249
|
-
fs.removeSync(path.join(srcDir, 'error1.js'));
|
|
250
|
-
});
|
|
251
|
-
});
|
package/tests/compiler.test.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { fs } from '@modern-js/utils';
|
|
3
|
-
import * as babel from '@babel/core';
|
|
4
|
-
import {
|
|
5
|
-
isRes,
|
|
6
|
-
getDistFilePath,
|
|
7
|
-
resolveSourceMap,
|
|
8
|
-
compiler,
|
|
9
|
-
} from '../src/compiler';
|
|
10
|
-
import { defaultDistFileExtMap } from '../src/constants';
|
|
11
|
-
|
|
12
|
-
describe('compiler', () => {
|
|
13
|
-
it('isRes', () => {
|
|
14
|
-
const res_1 = isRes({ code: '' });
|
|
15
|
-
expect(res_1).toBe(true);
|
|
16
|
-
const res_2 = isRes(null);
|
|
17
|
-
expect(res_2).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('getDistFilePath', () => {
|
|
21
|
-
const distpath_1 = getDistFilePath({
|
|
22
|
-
rootDir: '/project',
|
|
23
|
-
filepath: '/project/src/b.js',
|
|
24
|
-
distDir: '/project/dist',
|
|
25
|
-
extMap: defaultDistFileExtMap,
|
|
26
|
-
});
|
|
27
|
-
expect(path.normalize(distpath_1)).toBe(
|
|
28
|
-
path.normalize('/project/dist/src/b.js'),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const distpath_2 = getDistFilePath({
|
|
32
|
-
rootDir: '/project/src',
|
|
33
|
-
filepath: '/project/src/b.js',
|
|
34
|
-
distDir: '/project/dist',
|
|
35
|
-
extMap: defaultDistFileExtMap,
|
|
36
|
-
});
|
|
37
|
-
expect(path.normalize(distpath_2)).toBe(
|
|
38
|
-
path.normalize('/project/dist/b.js'),
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('resolveSourceMap', () => {
|
|
43
|
-
const projectDir = path.join(__dirname, './fixtures/resolveSourceMap');
|
|
44
|
-
fs.removeSync(path.join(projectDir, 'dist'));
|
|
45
|
-
const babelRes = babel.transformFileSync(
|
|
46
|
-
path.join(projectDir, 'src/index.js'),
|
|
47
|
-
{ sourceMaps: true, cwd: projectDir },
|
|
48
|
-
);
|
|
49
|
-
const distFilePath = path.join(projectDir, 'dist/far.js');
|
|
50
|
-
const sourcemap_1 = resolveSourceMap({
|
|
51
|
-
babelRes: babelRes as babel.BabelFileResult,
|
|
52
|
-
sourceFilePath: path.join(projectDir, 'src/index.js'),
|
|
53
|
-
distFilePath,
|
|
54
|
-
enableVirtualDist: true,
|
|
55
|
-
});
|
|
56
|
-
expect(sourcemap_1.sourceMapPath).toBe(
|
|
57
|
-
path.join(projectDir, 'dist/far.js.map'),
|
|
58
|
-
);
|
|
59
|
-
// TODO test sourcemap content
|
|
60
|
-
|
|
61
|
-
const sourcemap_2 = resolveSourceMap({
|
|
62
|
-
babelRes: babelRes as babel.BabelFileResult,
|
|
63
|
-
sourceFilePath: path.join(projectDir, 'src/index.js'),
|
|
64
|
-
distFilePath,
|
|
65
|
-
});
|
|
66
|
-
expect(fs.readFileSync(sourcemap_2.sourceMapPath, 'utf-8')).toBe(
|
|
67
|
-
sourcemap_2.sourcemap,
|
|
68
|
-
);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('compiler', () => {
|
|
72
|
-
const projectPath = path.join(__dirname, './fixtures/compiler');
|
|
73
|
-
const sourceFilePath = path.join(projectPath, './src/index.js');
|
|
74
|
-
const distPath = path.join(projectPath, 'dist');
|
|
75
|
-
|
|
76
|
-
compiler({
|
|
77
|
-
rootDir: path.join(projectPath, 'src'),
|
|
78
|
-
filepath: sourceFilePath,
|
|
79
|
-
});
|
|
80
|
-
expect(fs.existsSync(path.join(distPath, 'index.js'))).toBe(true);
|
|
81
|
-
fs.removeSync(distPath);
|
|
82
|
-
|
|
83
|
-
const dist1Path = path.join(projectPath, 'dist1');
|
|
84
|
-
compiler({
|
|
85
|
-
rootDir: path.join(projectPath, 'src'),
|
|
86
|
-
filepath: sourceFilePath,
|
|
87
|
-
distDir: dist1Path,
|
|
88
|
-
babelConfig: { sourceMaps: true },
|
|
89
|
-
});
|
|
90
|
-
expect(fs.existsSync(dist1Path)).toBe(true);
|
|
91
|
-
fs.removeSync(dist1Path);
|
|
92
|
-
|
|
93
|
-
compiler({
|
|
94
|
-
rootDir: path.join(projectPath, 'src'),
|
|
95
|
-
filepath: sourceFilePath,
|
|
96
|
-
babelConfig: { sourceMaps: true },
|
|
97
|
-
});
|
|
98
|
-
expect(fs.existsSync(path.join(distPath, 'index.js'))).toBe(true);
|
|
99
|
-
expect(fs.existsSync(path.join(distPath, 'index.js.map'))).toBe(true);
|
|
100
|
-
fs.removeSync(distPath);
|
|
101
|
-
|
|
102
|
-
compiler({
|
|
103
|
-
rootDir: path.join(projectPath, 'src'),
|
|
104
|
-
filepath: sourceFilePath,
|
|
105
|
-
enableVirtualDist: true,
|
|
106
|
-
babelConfig: { sourceMaps: true },
|
|
107
|
-
});
|
|
108
|
-
expect(fs.existsSync(path.join(distPath, 'index.js'))).toBe(false);
|
|
109
|
-
expect(fs.existsSync(path.join(distPath, 'index.js.map'))).toBe(false);
|
|
110
|
-
fs.removeSync(distPath);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { CompilerErrorResult } from '../src/compilerErrorResult';
|
|
2
|
-
|
|
3
|
-
describe('CompilerErrorResult Class', () => {
|
|
4
|
-
it('call constructor without params', () => {
|
|
5
|
-
const cer_1 = new CompilerErrorResult();
|
|
6
|
-
expect(Array.isArray(cer_1._messageDetails)).toBe(true);
|
|
7
|
-
expect(cer_1._messageDetails.length).toBe(0);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('call constructor with params', () => {
|
|
11
|
-
const cer_1 = new CompilerErrorResult({ code: 1, message: 'fail' });
|
|
12
|
-
expect(Array.isArray(cer_1._messageDetails)).toBe(true);
|
|
13
|
-
expect(cer_1._messageDetails.length).toBe(0);
|
|
14
|
-
|
|
15
|
-
const cer_2 = new CompilerErrorResult({
|
|
16
|
-
code: 1,
|
|
17
|
-
message: 'fail',
|
|
18
|
-
messageDetails: [{ content: 'error', filename: 'far.js' }],
|
|
19
|
-
});
|
|
20
|
-
expect(Array.isArray(cer_1._messageDetails)).toBe(true);
|
|
21
|
-
expect(cer_2._messageDetails.length).toBe(1);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('use init', () => {
|
|
25
|
-
const cer_1 = new CompilerErrorResult();
|
|
26
|
-
cer_1.init({ code: 1, message: 'fail' });
|
|
27
|
-
expect(Array.isArray(cer_1._messageDetails)).toBe(true);
|
|
28
|
-
expect(cer_1._messageDetails.length).toBe(0);
|
|
29
|
-
|
|
30
|
-
const cer_2 = new CompilerErrorResult();
|
|
31
|
-
cer_2.init({
|
|
32
|
-
code: 1,
|
|
33
|
-
message: 'fail',
|
|
34
|
-
messageDetails: [{ content: 'error', filename: 'far.js' }],
|
|
35
|
-
});
|
|
36
|
-
expect(Array.isArray(cer_1._messageDetails)).toBe(true);
|
|
37
|
-
expect(cer_2._messageDetails.length).toBe(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('update diff messageDetails', () => {
|
|
41
|
-
const cer_1 = new CompilerErrorResult({ code: 1, message: 'fail' });
|
|
42
|
-
const firstCount = cer_1._messageDetails.length;
|
|
43
|
-
cer_1.update([{ content: 'error', filename: 'far.js' }]);
|
|
44
|
-
const secondCount = cer_1._messageDetails.length;
|
|
45
|
-
cer_1.update([{ content: 'error', filename: 'bar.js' }]);
|
|
46
|
-
const thirdCount = cer_1._messageDetails.length;
|
|
47
|
-
expect(firstCount).toBe(0);
|
|
48
|
-
expect(secondCount).toBe(1);
|
|
49
|
-
expect(thirdCount).toBe(2);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('update same messageDetails', () => {
|
|
53
|
-
const cer_1 = new CompilerErrorResult({ code: 1, message: 'fail' });
|
|
54
|
-
const firstCount = cer_1._messageDetails.length;
|
|
55
|
-
cer_1.update([{ content: 'error-1', filename: 'far.js' }]);
|
|
56
|
-
const secondCount = cer_1._messageDetails.length;
|
|
57
|
-
cer_1.update([{ content: 'error-2', filename: 'far.js' }]);
|
|
58
|
-
const thirdCount = cer_1._messageDetails.length;
|
|
59
|
-
expect(firstCount).toBe(0);
|
|
60
|
-
expect(secondCount).toBe(1);
|
|
61
|
-
expect(thirdCount).toBe(1);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('remove by file name', () => {
|
|
65
|
-
const cer_1 = new CompilerErrorResult({
|
|
66
|
-
code: 1,
|
|
67
|
-
message: 'fail',
|
|
68
|
-
messageDetails: [{ content: 'error-1', filename: 'far.js' }],
|
|
69
|
-
});
|
|
70
|
-
const firstCount = cer_1._messageDetails.length;
|
|
71
|
-
cer_1.removeByFileName('far.js');
|
|
72
|
-
const secondCount = cer_1._messageDetails.length;
|
|
73
|
-
expect(firstCount).toBe(1);
|
|
74
|
-
expect(secondCount).toBe(0);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('check exist error', () => {
|
|
78
|
-
const cer_1 = new CompilerErrorResult();
|
|
79
|
-
expect(cer_1.checkExistError()).toBe(false);
|
|
80
|
-
const cer_2 = new CompilerErrorResult({
|
|
81
|
-
code: 1,
|
|
82
|
-
message: 'fail',
|
|
83
|
-
messageDetails: [{ content: 'error-1', filename: 'far.js' }],
|
|
84
|
-
});
|
|
85
|
-
expect(cer_2.checkExistError()).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('get value', () => {
|
|
89
|
-
const cer_1 = new CompilerErrorResult();
|
|
90
|
-
expect(cer_1.value).toStrictEqual({
|
|
91
|
-
code: 1,
|
|
92
|
-
message: `Compilation failure 0 files with Babel.`,
|
|
93
|
-
messageDetails: [],
|
|
94
|
-
});
|
|
95
|
-
const cer_2 = new CompilerErrorResult({
|
|
96
|
-
code: 1,
|
|
97
|
-
message: 'fail',
|
|
98
|
-
messageDetails: [{ content: 'error-1', filename: 'far.js' }],
|
|
99
|
-
});
|
|
100
|
-
expect(cer_2.value).toStrictEqual({
|
|
101
|
-
code: 1,
|
|
102
|
-
message: `Compilation failure 1 files with Babel.`,
|
|
103
|
-
messageDetails: [{ content: 'error-1', filename: 'far.js' }],
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('_messageDetails', () => {
|
|
108
|
-
const cer_1 = new CompilerErrorResult();
|
|
109
|
-
expect(cer_1._messageDetails).toStrictEqual([]);
|
|
110
|
-
const cer_2 = new CompilerErrorResult({
|
|
111
|
-
code: 1,
|
|
112
|
-
message: 'fail',
|
|
113
|
-
messageDetails: [{ content: 'error-1', filename: 'far.js' }],
|
|
114
|
-
});
|
|
115
|
-
expect(cer_2._messageDetails).toStrictEqual([
|
|
116
|
-
{ content: 'error-1', filename: 'far.js' },
|
|
117
|
-
]);
|
|
118
|
-
});
|
|
119
|
-
});
|
package/tests/constants.test.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { defaultDistFileExtMap } from '../src/constants';
|
|
2
|
-
|
|
3
|
-
describe('constants', () => {
|
|
4
|
-
it('defaultDistFileExtMap', () => {
|
|
5
|
-
expect(defaultDistFileExtMap).toStrictEqual({
|
|
6
|
-
'.js': '.js',
|
|
7
|
-
'.jsx': '.js',
|
|
8
|
-
'.ts': '.js',
|
|
9
|
-
'.tsx': '.js',
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
});
|
package/tests/defaults.test.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { mergeDefaultOption } from '../src/defaults';
|
|
2
|
-
|
|
3
|
-
describe('defaults', () => {
|
|
4
|
-
it('should merge default option', () => {
|
|
5
|
-
const option_1 = mergeDefaultOption({
|
|
6
|
-
rootDir: './',
|
|
7
|
-
distDir: './dist',
|
|
8
|
-
filenames: ['far.js'],
|
|
9
|
-
});
|
|
10
|
-
expect(option_1).toStrictEqual({
|
|
11
|
-
rootDir: './',
|
|
12
|
-
distDir: './dist',
|
|
13
|
-
filenames: ['far.js'],
|
|
14
|
-
enableWatch: false,
|
|
15
|
-
enableVirtualDist: false,
|
|
16
|
-
extensions: [],
|
|
17
|
-
distFileExtMap: {
|
|
18
|
-
'.js': '.js',
|
|
19
|
-
'.jsx': '.js',
|
|
20
|
-
'.ts': '.js',
|
|
21
|
-
'.tsx': '.js',
|
|
22
|
-
},
|
|
23
|
-
ignore: [],
|
|
24
|
-
quiet: false,
|
|
25
|
-
verbose: false,
|
|
26
|
-
clean: false,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
conts a = 1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
conts a = 1;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/tests/fixtures/utils/far
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import { DEFAULT_EXTENSIONS } from '@babel/core';
|
|
3
|
-
import {
|
|
4
|
-
getFinalCompilerOption,
|
|
5
|
-
getFilesFromDir,
|
|
6
|
-
getFinalExtensions,
|
|
7
|
-
getGlobPattern,
|
|
8
|
-
} from '../src/getFinalOption';
|
|
9
|
-
import { defaultDistFileExtMap } from '../src/constants';
|
|
10
|
-
|
|
11
|
-
const projectDir = path.join(__dirname, './fixtures/getFinalOption');
|
|
12
|
-
const sourceDir = path.join(projectDir, 'sourceDir');
|
|
13
|
-
const watchDir = path.join(projectDir, 'watchDir');
|
|
14
|
-
|
|
15
|
-
describe('get final compilerOption', () => {
|
|
16
|
-
it('getGlobPattern', () => {
|
|
17
|
-
const pattern_1 = getGlobPattern(sourceDir, ['.js']);
|
|
18
|
-
expect(pattern_1).toBe(`${sourceDir}/**/*.js`);
|
|
19
|
-
const pattern_2 = getGlobPattern(watchDir, ['.js', '.jsx']);
|
|
20
|
-
expect(pattern_2).toBe(`${watchDir}/**/*{.js,.jsx}`);
|
|
21
|
-
const pattern_3 = getGlobPattern(watchDir, []);
|
|
22
|
-
expect(pattern_3).toBe(`${watchDir}/**/*`);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('getFinalExtensions', () => {
|
|
26
|
-
const finalexts_1 = getFinalExtensions(['.ts', '.tsx']);
|
|
27
|
-
expect(finalexts_1).toStrictEqual(['.ts', '.tsx', ...DEFAULT_EXTENSIONS]);
|
|
28
|
-
const finalexts_2 = getFinalExtensions(defaultExts => [
|
|
29
|
-
'.ts',
|
|
30
|
-
'.tsx',
|
|
31
|
-
...defaultExts,
|
|
32
|
-
]);
|
|
33
|
-
expect(finalexts_2).toStrictEqual(['.ts', '.tsx', ...DEFAULT_EXTENSIONS]);
|
|
34
|
-
const finalexts_3 = getFinalExtensions(() => ['.ts', '.tsx']);
|
|
35
|
-
expect(finalexts_3).toStrictEqual(['.ts', '.tsx']);
|
|
36
|
-
const finalexts_4 = getFinalExtensions(undefined);
|
|
37
|
-
expect(finalexts_4).toStrictEqual(DEFAULT_EXTENSIONS);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('getFilesFromDir', () => {
|
|
41
|
-
const files_1 = getFilesFromDir({ dir: watchDir, finalExt: ['.js'] });
|
|
42
|
-
expect(files_1.length).toBe(1);
|
|
43
|
-
const files_2 = getFilesFromDir({
|
|
44
|
-
dir: watchDir,
|
|
45
|
-
finalExt: ['.js', '.jsx'],
|
|
46
|
-
});
|
|
47
|
-
expect(files_2.length).toBe(2);
|
|
48
|
-
const files_3 = getFilesFromDir({
|
|
49
|
-
dir: watchDir,
|
|
50
|
-
finalExt: ['.js', '.jsx'],
|
|
51
|
-
ignore: ['**/far.js'],
|
|
52
|
-
});
|
|
53
|
-
expect(files_3.length).toBe(1);
|
|
54
|
-
const files_4 = getFilesFromDir({ dir: watchDir });
|
|
55
|
-
expect(files_4.length).toBe(2);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('getFinalCompilerOption', () => {
|
|
59
|
-
const baseOption = {
|
|
60
|
-
rootDir: projectDir,
|
|
61
|
-
distDir: path.join(projectDir, 'dist'),
|
|
62
|
-
};
|
|
63
|
-
const baseFinalOption = {
|
|
64
|
-
...baseOption,
|
|
65
|
-
enableWatch: false,
|
|
66
|
-
enableVirtualDist: false,
|
|
67
|
-
extensions: [],
|
|
68
|
-
distFileExtMap: defaultDistFileExtMap,
|
|
69
|
-
ignore: [],
|
|
70
|
-
quiet: false,
|
|
71
|
-
verbose: false,
|
|
72
|
-
clean: false,
|
|
73
|
-
};
|
|
74
|
-
const option_1 = getFinalCompilerOption({ ...baseOption });
|
|
75
|
-
expect(option_1).toStrictEqual({
|
|
76
|
-
...baseFinalOption,
|
|
77
|
-
filenames: [],
|
|
78
|
-
});
|
|
79
|
-
const option_2 = getFinalCompilerOption({ ...baseOption, sourceDir });
|
|
80
|
-
expect(option_2.filenames.length).toBe(1);
|
|
81
|
-
expect(path.normalize(option_2.filenames[0])).toBe(
|
|
82
|
-
path.normalize(path.join(sourceDir, './bar.js')),
|
|
83
|
-
);
|
|
84
|
-
const option_3 = getFinalCompilerOption({ ...baseOption, watchDir });
|
|
85
|
-
expect(option_3.filenames.length).toBe(0);
|
|
86
|
-
const option_4 = getFinalCompilerOption({
|
|
87
|
-
...baseOption,
|
|
88
|
-
enableWatch: true,
|
|
89
|
-
watchDir,
|
|
90
|
-
});
|
|
91
|
-
expect(option_4.filenames.length).toBe(2);
|
|
92
|
-
expect(
|
|
93
|
-
option_4.filenames.every(filename =>
|
|
94
|
-
[
|
|
95
|
-
path.normalize(path.join(watchDir, './far.js')),
|
|
96
|
-
path.normalize(path.join(watchDir, './foo.jsx')),
|
|
97
|
-
].includes(path.normalize(filename)),
|
|
98
|
-
),
|
|
99
|
-
).toBe(true);
|
|
100
|
-
|
|
101
|
-
const option_5 = getFinalCompilerOption({
|
|
102
|
-
...baseOption,
|
|
103
|
-
filenames: ['./c.js'],
|
|
104
|
-
sourceDir,
|
|
105
|
-
});
|
|
106
|
-
expect(option_5.filenames.length).toBe(2);
|
|
107
|
-
});
|
|
108
|
-
});
|