Skip to content

Commit

Permalink
fix: 🐛 use ECMAScript syntax to import ajv if allowSyntheticDefaultIm…
Browse files Browse the repository at this point in the history
…ports is true (#19)

[fixes #17]
  • Loading branch information
johngeorgewright authored and Forbes Lindesay committed Jun 19, 2019
1 parent 757331b commit 9ea471f
Show file tree
Hide file tree
Showing 26 changed files with 425 additions and 30 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ node_modules
.lock-wscript

# Babel build output
/lib
lib

# Config files
environment.toml
.env
.env

src/__tests__/**/*.validator.ts
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@
"@types/koa": "^2.0.48",
"@types/koa-router": "^7.0.39",
"@types/node": "^10.5.2",
"@types/rimraf": "^2.0.2",
"husky": "^0.14.3",
"jest": "^23.3.0",
"prettier": "^1.13.7",
"pretty-quick": "^1.6.0",
"rimraf": "^2.6.2",
"ts-jest": "^23.0.0",
"ts-node": "^8.3.0",
"tslint": "^5.10.0",
"typescript": "^3.4.5"
},
"jest": {
"watchPathIgnorePatterns": [
"src/Example.validator.ts",
"src/__tests__/output/*"
".*/lib/.*",
".*/src/Example.validator\\.ts",
".*/src/__tests__/output/.*"
],
"moduleFileExtensions": [
"ts",
Expand Down
66 changes: 66 additions & 0 deletions src/__tests__/build-parameters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import rimrafCB from 'rimraf';
import {exec as execCB, ExecOptions} from 'child_process';
import * as path from 'path';
import {promisify} from 'util';

const rimraf = promisify(rimrafCB);

const testDir = path.join(__dirname, 'build-parameters');

const exec = (cmd: string, options: ExecOptions): Promise<string> =>
new Promise((resolve, reject) => {
execCB(cmd, options, (error, stdout, stderr) => {
if (error) {
reject(stderr || stdout || error.message);
} else {
resolve(stdout);
}
});
});

const buildProject = async (project: string) => {
await exec(`cp tsconfig.${project}.json tsconfig.json`, {cwd: testDir});

await exec(`node ../../../lib/cli ./src/Example.ts ExampleType`, {
cwd: testDir,
});

await exec(`npx tsc --project ./tsconfig.json`, {
cwd: testDir,
});
};

beforeAll(() => exec('yarn build', {cwd: process.cwd()}));

afterEach(() =>
Promise.all([
rimraf(path.join(testDir, 'lib')),
exec('rm tsconfig.json', {cwd: testDir}),
exec('rm src/Example.validator.ts', {cwd: testDir}),
]),
);

test('ESNext module settings', () =>
// We expect a project not to build correctly if it has ES module
// target and no esModuleInterop.
expect(buildProject('esnext')).rejects.toMatch('TS1202:'));

test('ESNext interop module settings', () => buildProject('esnext-interop'));

test('ES2015 module settings', () =>
expect(buildProject('es2015')).rejects.toMatch('TS1202:'));

test('ES2015 interop module settings', () => buildProject('es2015-interop'));

test('UMD module settings', () => buildProject('umd'));

test('UMD interop module settings', () => buildProject('umd-interop'));

test('System module settings', () => buildProject('system'));

test('System interop module settings', () => buildProject('system-interop'));

test('Common JS module settings', () => buildProject('commonjs'));

test('Common JS interop module settings', () =>
buildProject('commonjs-interop'));
11 changes: 11 additions & 0 deletions src/__tests__/build-parameters/src/Example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default interface ExampleType {
value: string;
/**
* @TJS-format email
*/
email?: string;
/**
* @default 42
*/
answer: number;
}
1 change: 1 addition & 0 deletions src/__tests__/build-parameters/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../../../Example.validator';
26 changes: 26 additions & 0 deletions src/__tests__/build-parameters/tsconfig.commonjs-interop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"],
"esModuleInterop": true
},
"include": ["src"]
}
25 changes: 25 additions & 0 deletions src/__tests__/build-parameters/tsconfig.commonjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"]
},
"include": ["src"]
}
26 changes: 26 additions & 0 deletions src/__tests__/build-parameters/tsconfig.es2015-interop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es2018",
"module": "es2015",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"],
"esModuleInterop": true
},
"include": ["src"]
}
25 changes: 25 additions & 0 deletions src/__tests__/build-parameters/tsconfig.es2015.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es2018",
"module": "es2015",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"]
},
"include": ["src"]
}
26 changes: 26 additions & 0 deletions src/__tests__/build-parameters/tsconfig.esnext-interop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es2018",
"module": "esnext",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"],
"esModuleInterop": true
},
"include": ["src"]
}
25 changes: 25 additions & 0 deletions src/__tests__/build-parameters/tsconfig.esnext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es2018",
"module": "esnext",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"]
},
"include": ["src"]
}
26 changes: 26 additions & 0 deletions src/__tests__/build-parameters/tsconfig.system-interop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es2018",
"module": "system",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"],
"esModuleInterop": true
},
"include": ["src"]
}
25 changes: 25 additions & 0 deletions src/__tests__/build-parameters/tsconfig.system.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es2018",
"module": "system",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"]
},
"include": ["src"]
}
26 changes: 26 additions & 0 deletions src/__tests__/build-parameters/tsconfig.umd-interop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es2018",
"module": "umd",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"],
"esModuleInterop": true
},
"include": ["src"]
}
25 changes: 25 additions & 0 deletions src/__tests__/build-parameters/tsconfig.umd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es2018",
"module": "umd",
"moduleResolution": "Node",
"noImplicitAny": true,
"skipLibCheck": true,
"experimentalDecorators": false,
"importHelpers": false,
"pretty": true,
"sourceMap": true,
"strict": true,
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"declaration": true,
"lib": ["es2018"]
},
"include": ["src"]
}
1 change: 1 addition & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import run from '../';

// let validate: any;

test('run', () => {
Expand Down
Loading

0 comments on commit 9ea471f

Please sign in to comment.