Skip to content

Commit 9ea471f

Browse files
johngeorgewrightForbes Lindesay
authored and
Forbes Lindesay
committed
fix: 🐛 use ECMAScript syntax to import ajv if allowSyntheticDefaultImports is true (#19)
[fixes #17]
1 parent 757331b commit 9ea471f

26 files changed

+425
-30
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ node_modules
2020
.lock-wscript
2121

2222
# Babel build output
23-
/lib
23+
lib
2424

2525
# Config files
2626
environment.toml
27-
.env
27+
.env
28+
29+
src/__tests__/**/*.validator.ts

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,22 @@
3333
"@types/koa": "^2.0.48",
3434
"@types/koa-router": "^7.0.39",
3535
"@types/node": "^10.5.2",
36+
"@types/rimraf": "^2.0.2",
3637
"husky": "^0.14.3",
3738
"jest": "^23.3.0",
3839
"prettier": "^1.13.7",
3940
"pretty-quick": "^1.6.0",
4041
"rimraf": "^2.6.2",
4142
"ts-jest": "^23.0.0",
43+
"ts-node": "^8.3.0",
4244
"tslint": "^5.10.0",
4345
"typescript": "^3.4.5"
4446
},
4547
"jest": {
4648
"watchPathIgnorePatterns": [
47-
"src/Example.validator.ts",
48-
"src/__tests__/output/*"
49+
".*/lib/.*",
50+
".*/src/Example.validator\\.ts",
51+
".*/src/__tests__/output/.*"
4952
],
5053
"moduleFileExtensions": [
5154
"ts",
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import rimrafCB from 'rimraf';
2+
import {exec as execCB, ExecOptions} from 'child_process';
3+
import * as path from 'path';
4+
import {promisify} from 'util';
5+
6+
const rimraf = promisify(rimrafCB);
7+
8+
const testDir = path.join(__dirname, 'build-parameters');
9+
10+
const exec = (cmd: string, options: ExecOptions): Promise<string> =>
11+
new Promise((resolve, reject) => {
12+
execCB(cmd, options, (error, stdout, stderr) => {
13+
if (error) {
14+
reject(stderr || stdout || error.message);
15+
} else {
16+
resolve(stdout);
17+
}
18+
});
19+
});
20+
21+
const buildProject = async (project: string) => {
22+
await exec(`cp tsconfig.${project}.json tsconfig.json`, {cwd: testDir});
23+
24+
await exec(`node ../../../lib/cli ./src/Example.ts ExampleType`, {
25+
cwd: testDir,
26+
});
27+
28+
await exec(`npx tsc --project ./tsconfig.json`, {
29+
cwd: testDir,
30+
});
31+
};
32+
33+
beforeAll(() => exec('yarn build', {cwd: process.cwd()}));
34+
35+
afterEach(() =>
36+
Promise.all([
37+
rimraf(path.join(testDir, 'lib')),
38+
exec('rm tsconfig.json', {cwd: testDir}),
39+
exec('rm src/Example.validator.ts', {cwd: testDir}),
40+
]),
41+
);
42+
43+
test('ESNext module settings', () =>
44+
// We expect a project not to build correctly if it has ES module
45+
// target and no esModuleInterop.
46+
expect(buildProject('esnext')).rejects.toMatch('TS1202:'));
47+
48+
test('ESNext interop module settings', () => buildProject('esnext-interop'));
49+
50+
test('ES2015 module settings', () =>
51+
expect(buildProject('es2015')).rejects.toMatch('TS1202:'));
52+
53+
test('ES2015 interop module settings', () => buildProject('es2015-interop'));
54+
55+
test('UMD module settings', () => buildProject('umd'));
56+
57+
test('UMD interop module settings', () => buildProject('umd-interop'));
58+
59+
test('System module settings', () => buildProject('system'));
60+
61+
test('System interop module settings', () => buildProject('system-interop'));
62+
63+
test('Common JS module settings', () => buildProject('commonjs'));
64+
65+
test('Common JS interop module settings', () =>
66+
buildProject('commonjs-interop'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default interface ExampleType {
2+
value: string;
3+
/**
4+
* @TJS-format email
5+
*/
6+
email?: string;
7+
/**
8+
* @default 42
9+
*/
10+
answer: number;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../../../../Example.validator';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "commonjs",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"],
23+
"esModuleInterop": true
24+
},
25+
"include": ["src"]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "commonjs",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"]
23+
},
24+
"include": ["src"]
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "es2015",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"],
23+
"esModuleInterop": true
24+
},
25+
"include": ["src"]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "es2015",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"]
23+
},
24+
"include": ["src"]
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "esnext",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"],
23+
"esModuleInterop": true
24+
},
25+
"include": ["src"]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "esnext",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"]
23+
},
24+
"include": ["src"]
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "system",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"],
23+
"esModuleInterop": true
24+
},
25+
"include": ["src"]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "system",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"]
23+
},
24+
"include": ["src"]
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "umd",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"],
23+
"esModuleInterop": true
24+
},
25+
"include": ["src"]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "umd",
5+
"moduleResolution": "Node",
6+
"noImplicitAny": true,
7+
"skipLibCheck": true,
8+
"experimentalDecorators": false,
9+
"importHelpers": false,
10+
"pretty": true,
11+
"sourceMap": true,
12+
"strict": true,
13+
"outDir": "lib",
14+
"forceConsistentCasingInFileNames": true,
15+
"noEmitOnError": false,
16+
"noErrorTruncation": true,
17+
"noFallthroughCasesInSwitch": false,
18+
"noImplicitReturns": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"declaration": true,
22+
"lib": ["es2018"]
23+
},
24+
"include": ["src"]
25+
}

src/__tests__/index.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import run from '../';
2+
23
// let validate: any;
34

45
test('run', () => {

0 commit comments

Comments
 (0)