From 9ea471fb0f652aefa3fd5742324dec0e0c1c4901 Mon Sep 17 00:00:00 2001 From: John Wright Date: Wed, 19 Jun 2019 17:13:02 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20use=20ECMAScript=20syntax?= =?UTF-8?q?=20to=20import=20ajv=20if=20allowSyntheticDefaultImports=20is?= =?UTF-8?q?=20true=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [fixes #17] --- .gitignore | 6 +- package.json | 7 +- src/__tests__/build-parameters.test.ts | 66 +++++++++++++++++++ src/__tests__/build-parameters/src/Example.ts | 11 ++++ src/__tests__/build-parameters/src/index.ts | 1 + .../tsconfig.commonjs-interop.json | 26 ++++++++ .../build-parameters/tsconfig.commonjs.json | 25 +++++++ .../tsconfig.es2015-interop.json | 26 ++++++++ .../build-parameters/tsconfig.es2015.json | 25 +++++++ .../tsconfig.esnext-interop.json | 26 ++++++++ .../build-parameters/tsconfig.esnext.json | 25 +++++++ .../tsconfig.system-interop.json | 26 ++++++++ .../build-parameters/tsconfig.system.json | 25 +++++++ .../tsconfig.umd-interop.json | 26 ++++++++ .../build-parameters/tsconfig.umd.json | 25 +++++++ src/__tests__/index.test.ts | 1 + src/__tests__/parse.test.ts | 12 ++-- src/__tests__/printValidator.test.ts | 16 +++-- src/index.ts | 7 +- src/loadTsConfig.ts | 2 +- src/parse.ts | 7 +- src/parseArgs.ts | 2 +- src/printValidator.ts | 8 ++- src/template.ts | 13 +++- tsconfig.json | 3 +- yarn.lock | 38 ++++++++++- 26 files changed, 425 insertions(+), 30 deletions(-) create mode 100644 src/__tests__/build-parameters.test.ts create mode 100644 src/__tests__/build-parameters/src/Example.ts create mode 100644 src/__tests__/build-parameters/src/index.ts create mode 100644 src/__tests__/build-parameters/tsconfig.commonjs-interop.json create mode 100644 src/__tests__/build-parameters/tsconfig.commonjs.json create mode 100644 src/__tests__/build-parameters/tsconfig.es2015-interop.json create mode 100644 src/__tests__/build-parameters/tsconfig.es2015.json create mode 100644 src/__tests__/build-parameters/tsconfig.esnext-interop.json create mode 100644 src/__tests__/build-parameters/tsconfig.esnext.json create mode 100644 src/__tests__/build-parameters/tsconfig.system-interop.json create mode 100644 src/__tests__/build-parameters/tsconfig.system.json create mode 100644 src/__tests__/build-parameters/tsconfig.umd-interop.json create mode 100644 src/__tests__/build-parameters/tsconfig.umd.json diff --git a/.gitignore b/.gitignore index 6d2d43e..45371f6 100644 --- a/.gitignore +++ b/.gitignore @@ -20,8 +20,10 @@ node_modules .lock-wscript # Babel build output -/lib +lib # Config files environment.toml -.env \ No newline at end of file +.env + +src/__tests__/**/*.validator.ts \ No newline at end of file diff --git a/package.json b/package.json index 675098a..d22d94e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/__tests__/build-parameters.test.ts b/src/__tests__/build-parameters.test.ts new file mode 100644 index 0000000..c61a841 --- /dev/null +++ b/src/__tests__/build-parameters.test.ts @@ -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 => + 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')); diff --git a/src/__tests__/build-parameters/src/Example.ts b/src/__tests__/build-parameters/src/Example.ts new file mode 100644 index 0000000..36f73d5 --- /dev/null +++ b/src/__tests__/build-parameters/src/Example.ts @@ -0,0 +1,11 @@ +export default interface ExampleType { + value: string; + /** + * @TJS-format email + */ + email?: string; + /** + * @default 42 + */ + answer: number; +} diff --git a/src/__tests__/build-parameters/src/index.ts b/src/__tests__/build-parameters/src/index.ts new file mode 100644 index 0000000..42a7bb3 --- /dev/null +++ b/src/__tests__/build-parameters/src/index.ts @@ -0,0 +1 @@ +import '../../../../Example.validator'; diff --git a/src/__tests__/build-parameters/tsconfig.commonjs-interop.json b/src/__tests__/build-parameters/tsconfig.commonjs-interop.json new file mode 100644 index 0000000..6f7fab4 --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.commonjs-interop.json @@ -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"] +} diff --git a/src/__tests__/build-parameters/tsconfig.commonjs.json b/src/__tests__/build-parameters/tsconfig.commonjs.json new file mode 100644 index 0000000..999ce9f --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.commonjs.json @@ -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"] +} diff --git a/src/__tests__/build-parameters/tsconfig.es2015-interop.json b/src/__tests__/build-parameters/tsconfig.es2015-interop.json new file mode 100644 index 0000000..9e5769c --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.es2015-interop.json @@ -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"] +} diff --git a/src/__tests__/build-parameters/tsconfig.es2015.json b/src/__tests__/build-parameters/tsconfig.es2015.json new file mode 100644 index 0000000..1e2d58f --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.es2015.json @@ -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"] +} diff --git a/src/__tests__/build-parameters/tsconfig.esnext-interop.json b/src/__tests__/build-parameters/tsconfig.esnext-interop.json new file mode 100644 index 0000000..274ace4 --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.esnext-interop.json @@ -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"] +} diff --git a/src/__tests__/build-parameters/tsconfig.esnext.json b/src/__tests__/build-parameters/tsconfig.esnext.json new file mode 100644 index 0000000..40202ed --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.esnext.json @@ -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"] +} diff --git a/src/__tests__/build-parameters/tsconfig.system-interop.json b/src/__tests__/build-parameters/tsconfig.system-interop.json new file mode 100644 index 0000000..274026c --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.system-interop.json @@ -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"] +} diff --git a/src/__tests__/build-parameters/tsconfig.system.json b/src/__tests__/build-parameters/tsconfig.system.json new file mode 100644 index 0000000..23559dd --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.system.json @@ -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"] +} diff --git a/src/__tests__/build-parameters/tsconfig.umd-interop.json b/src/__tests__/build-parameters/tsconfig.umd-interop.json new file mode 100644 index 0000000..3e1f6e7 --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.umd-interop.json @@ -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"] +} diff --git a/src/__tests__/build-parameters/tsconfig.umd.json b/src/__tests__/build-parameters/tsconfig.umd.json new file mode 100644 index 0000000..99fa704 --- /dev/null +++ b/src/__tests__/build-parameters/tsconfig.umd.json @@ -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"] +} diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 3fc9392..2f3185f 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -1,4 +1,5 @@ import run from '../'; + // let validate: any; test('run', () => { diff --git a/src/__tests__/parse.test.ts b/src/__tests__/parse.test.ts index 37a9e35..bd73914 100644 --- a/src/__tests__/parse.test.ts +++ b/src/__tests__/parse.test.ts @@ -1,9 +1,11 @@ import parse from '../parse'; -import Ajv = require('ajv'); +import Ajv from 'ajv'; +import loadTsConfig from '../loadTsConfig'; test('parse', () => { - expect(parse([__dirname + '/../ComplexExample.ts']).getAllTypes()) - .toMatchInlineSnapshot(` + expect( + parse([__dirname + '/../ComplexExample.ts'], loadTsConfig()).getAllTypes(), + ).toMatchInlineSnapshot(` Object { "schema": Object { "$schema": "http://json-schema.org/draft-07/schema#", @@ -99,7 +101,9 @@ Object { }); test('ajv', () => { - const parsed = parse([__dirname + '/../ComplexExample.ts'], {titles: true}); + const parsed = parse([__dirname + '/../ComplexExample.ts'], loadTsConfig(), { + titles: true, + }); const {schema} = parsed.getAllTypes(); const ajv = new Ajv({coerceTypes: false, allErrors: true, useDefaults: true}); ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json')); diff --git a/src/__tests__/printValidator.test.ts b/src/__tests__/printValidator.test.ts index f5a1332..cae3f63 100644 --- a/src/__tests__/printValidator.test.ts +++ b/src/__tests__/printValidator.test.ts @@ -2,16 +2,24 @@ import parse from '../parse'; import {printTypeCollectionValidator} from '../printValidator'; import {writeFileSync} from 'fs'; import prettierFile from '../prettierFile'; +import loadTsConfig from '../loadTsConfig'; let validate: typeof import('./output/ComplexExample.validator') = undefined as any; test('print', () => { - const {symbols, schema} = parse([ - __dirname + '/../ComplexExample.ts', - ]).getAllTypes(); + const tsConfig = loadTsConfig(); + const {symbols, schema} = parse( + [__dirname + '/../ComplexExample.ts'], + tsConfig, + ).getAllTypes(); writeFileSync( __dirname + '/output/ComplexExample.validator.ts', - printTypeCollectionValidator(symbols, schema, '../../ComplexExample'), + printTypeCollectionValidator( + symbols, + schema, + '../../ComplexExample', + tsConfig, + ), ); prettierFile(__dirname + '/output/ComplexExample.validator.ts'); writeFileSync( diff --git a/src/index.ts b/src/index.ts index c31bd04..6797272 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { printTypeCollectionValidator, } from './printValidator'; import prettierFile from './prettierFile'; +import loadTsConfig from './loadTsConfig'; export { parse, @@ -17,8 +18,8 @@ export { export default function run(args?: string[]) { const {files, options} = parseArgs(args); - - const parsed = parse(files.map(f => f.fileName), options.schema); + const tsConfig = loadTsConfig(); + const parsed = parse(files.map(f => f.fileName), tsConfig, options.schema); files.forEach(({fileName, typeName}) => { const outputFileName = fileName.replace(/\.tsx?$/, '.validator.ts'); @@ -30,6 +31,7 @@ export default function run(args?: string[]) { options.useNamedExport, schema, `./${basename(fileName, /\.ts$/.test(fileName) ? '.ts' : '.tsx')}`, + tsConfig, options.ajv, ); } else { @@ -38,6 +40,7 @@ export default function run(args?: string[]) { symbols, schema, `./${basename(fileName, /\.ts$/.test(fileName) ? '.ts' : '.tsx')}`, + tsConfig, options.ajv, ); } diff --git a/src/loadTsConfig.ts b/src/loadTsConfig.ts index 8784eb3..9a6deb0 100644 --- a/src/loadTsConfig.ts +++ b/src/loadTsConfig.ts @@ -1,6 +1,6 @@ import {loadSync} from 'tsconfig'; -export default function loadTsConfig(cwd: string): any { +export default function loadTsConfig(cwd: string = process.cwd()): any { const result = loadSync(cwd); const compilerOptions = (result.config && result.config.compilerOptions) || {}; diff --git a/src/parse.ts b/src/parse.ts index 471bad1..fc203f3 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -1,16 +1,13 @@ import {resolve} from 'path'; import * as TJS from 'typescript-json-schema'; -import loadTsConfig from './loadTsConfig'; export default function parse( filenames: string[], + tsConfig: any, settings: TJS.PartialArgs = {}, ) { filenames = filenames.map(f => resolve(f)); - const program = TJS.getProgramFromFiles( - filenames, - loadTsConfig(process.cwd()), - ); + const program = TJS.getProgramFromFiles(filenames, tsConfig); const generator = TJS.buildGenerator(program, { rejectDateType: true, diff --git a/src/parseArgs.ts b/src/parseArgs.ts index 0422e17..fe40cd1 100644 --- a/src/parseArgs.ts +++ b/src/parseArgs.ts @@ -4,7 +4,7 @@ import { getDefaultArgs, Args as TypeScriptJsonSchemaArgs, } from 'typescript-json-schema'; -import Ajv = require('ajv'); +import Ajv from 'ajv'; export interface Options { schema: Pick< diff --git a/src/printValidator.ts b/src/printValidator.ts index 1a655b9..cd3617b 100644 --- a/src/printValidator.ts +++ b/src/printValidator.ts @@ -1,4 +1,4 @@ -import Ajv = require('ajv'); +import Ajv from 'ajv'; import * as TJS from 'typescript-json-schema'; import * as t from './template'; @@ -17,6 +17,7 @@ export function printTypeCollectionValidator( symbols: string[], schema: TJS.Definition, relativePath: string, + tsConfig: any, options: Ajv.Options = {}, ) { const koaTypes = symbols.filter(typeName => { @@ -25,7 +26,7 @@ export function printTypeCollectionValidator( return [ t.TSLINT_DISABLE, t.GENERATED_COMMENT, - t.IMPORT_AJV, + t.IMPORT_AJV(tsConfig), t.importNamedTypes(symbols, relativePath), ...(koaTypes.length ? [t.IMPORT_INSPECT, t.DECLARE_KOA_CONTEXT] : []), t.declareAJV(options), @@ -46,6 +47,7 @@ export function printSingleTypeValidator( isNamedExport: boolean, schema: TJS.Definition, relativePath: string, + tsConfig: any, options: Ajv.Options = {}, ) { if (isNamedExport !== false) { @@ -55,7 +57,7 @@ export function printSingleTypeValidator( t.TSLINT_DISABLE, t.GENERATED_COMMENT, t.IMPORT_INSPECT, - t.IMPORT_AJV, + t.IMPORT_AJV(tsConfig), t.importType(typeName, relativePath, {isNamedExport}), t.declareAJV(options), t.exportNamed([typeName]), diff --git a/src/template.ts b/src/template.ts index 33cc1ef..3833606 100644 --- a/src/template.ts +++ b/src/template.ts @@ -1,12 +1,19 @@ -import Ajv = require('ajv'); -import stringify = require('json-stable-stringify'); +import Ajv from 'ajv'; +import stringify from 'json-stable-stringify'; import * as TJS from 'typescript-json-schema'; export const TSLINT_DISABLE = `/* tslint:disable */`; export const GENERATED_COMMENT = `// generated by typescript-json-validator`; export const IMPORT_INSPECT = `import {inspect} from 'util';`; -export const IMPORT_AJV = `import Ajv = require('ajv');`; + +export const IMPORT_AJV = (tsConfig: any): string => { + return tsConfig.allowSyntheticDefaultImports || + (tsConfig.esModuleInterop && /^es/.test(tsConfig.module)) || + tsConfig.module === 'system' + ? `import Ajv from 'ajv';` + : `import Ajv = require('ajv');`; +}; export const DECLARE_KOA_CONTEXT = `export interface KoaContext { readonly request?: unknown; // {body?: unknown} diff --git a/tsconfig.json b/tsconfig.json index d7497bb..81aafd3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,5 +23,6 @@ "lib": ["es2018"], "incremental": true }, - "include": ["src"] + "include": ["src"], + "exclude": ["src/__tests__/build-parameters"] } diff --git a/yarn.lock b/yarn.lock index 1bbc2d3..bcb9b7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -86,7 +86,7 @@ "@types/express-serve-static-core" "*" "@types/serve-static" "*" -"@types/glob@^7.1.1": +"@types/glob@*", "@types/glob@^7.1.1": version "7.1.1" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w== @@ -166,6 +166,14 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c" integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA== +"@types/rimraf@^2.0.2": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-2.0.2.tgz#7f0fc3cf0ff0ad2a99bb723ae1764f30acaf8b6e" + integrity sha512-Hm/bnWq0TCy7jmjeN5bKYij9vw5GrDFWME4IuxV08278NtU/VdGbzsBohcCUJ7+QMqmUq5hpRKB39HeQWJjztQ== + dependencies: + "@types/glob" "*" + "@types/node" "*" + "@types/serve-static@*": version "1.13.2" resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.2.tgz#f5ac4d7a6420a99a6a45af4719f4dcd8cd907a48" @@ -287,6 +295,11 @@ are-we-there-yet@~1.1.2: delegates "^1.0.0" readable-stream "^2.0.6" +arg@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.0.tgz#583c518199419e0037abb74062c37f8519e575f0" + integrity sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg== + argparse@^1.0.7: version "1.0.10" resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" @@ -991,6 +1004,11 @@ diff@^3.2.0: resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA== +diff@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff" + integrity sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q== + domexception@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/domexception/-/domexception-1.0.1.tgz#937442644ca6a31261ef36e3ec677fe805582c90" @@ -2488,7 +2506,7 @@ lru-cache@^4.0.1: pseudomap "^1.0.2" yallist "^2.1.2" -make-error@1.x: +make-error@1.x, make-error@^1.1.1: version "1.3.5" resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8" integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g== @@ -3858,6 +3876,17 @@ ts-jest@^23.0.0: semver "^5.5" yargs-parser "10.x" +ts-node@^8.3.0: + version "8.3.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.3.0.tgz#e4059618411371924a1fb5f3b125915f324efb57" + integrity sha512-dyNS/RqyVTDcmNM4NIBAeDMpsAdaQ+ojdf0GOLqE6nwJOgzEkdRNzJywhDfwnuvB10oa6NLVG1rUJQCpRN7qoQ== + dependencies: + arg "^4.1.0" + diff "^4.0.1" + make-error "^1.1.1" + source-map-support "^0.5.6" + yn "^3.0.0" + tsconfig@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/tsconfig/-/tsconfig-7.0.0.tgz#84538875a4dc216e5c4a5432b3a4dec3d54e91b7" @@ -4216,3 +4245,8 @@ yargs@^13.2.4: which-module "^2.0.0" y18n "^4.0.0" yargs-parser "^13.1.0" + +yn@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.0.tgz#fcbe2db63610361afcc5eb9e0ac91e976d046114" + integrity sha512-kKfnnYkbTfrAdd0xICNFw7Atm8nKpLcLv9AZGEt+kczL/WQVai4e2V6ZN8U/O+iI6WrNuJjNNOyu4zfhl9D3Hg==