Skip to content

Commit

Permalink
updating ts-jest for esm
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbarbour committed Oct 15, 2023
1 parent 687c1f4 commit 249d251
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 739 deletions.
686 changes: 1 addition & 685 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"license": "Apache-2.0",
"version": "1.0.0",
"bin": {
"schema-api-ts": "dist/cli.mjs"
"schema-api-ts": "src/cli.ts"
},
"exports": {
".": "./dist/index.mjs",
"./cli": "./dist/cli.mjs"
".": "./dist/index.mjs"
},
"main": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
"dist",
"src"
],
"exclude": [
"node_modules",
"dist"
],
"scripts": {
"build": "rollup -c --configPlugin @rollup/plugin-typescript",
"build": "tsc --project tsconfig.json",
"test": "jest --ci --runInBand --coverage --reporters=default --reporters=jest-junit --passWithNoTests",
"lint": "eslint **/*.ts",
"start": "node dist/cli.js generate -h $(pwd)/test/schema-example.ts v=1.0.0"
"start": "./src/cli.ts generate -h $(pwd)/test/schema-example.ts v=1.0.0"
},
"eslintConfig": {
"extends": [
Expand Down Expand Up @@ -69,7 +69,13 @@
},
"jest": {
"transform": {
".(ts)": "ts-jest"
".(ts)": [
"ts-jest", { "useESM": true }
]
},
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"reporters": [
"default",
Expand All @@ -88,10 +94,6 @@
},
"devDependencies": {
"@hexlabs/http-api-ts": "^1.1.33",
"@rollup/plugin-commonjs": "^25.0.5",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.5",
"@types/aws-lambda": "^8.10.40",
"@types/jest": "^24.9.1",
"@types/node": "^18.18.5",
Expand All @@ -102,7 +104,6 @@
"husky": "^3.1.0",
"jest": "^29.7.0",
"jest-junit": "^10.0.0",
"rollup": "^4.1.0",
"ts-jest": "^29.1.1",
"tslib": "^2.6.2",
"typescript": "^4.7.4"
Expand Down
19 changes: 0 additions & 19 deletions rollup.config.ts

This file was deleted.

16 changes: 7 additions & 9 deletions src/cli.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env node
#!/usr/bin/env ts-node
import {compile, JSONSchema} from "json-schema-to-typescript";
import {PathFinder} from "./mapper";
import {PathFinder} from "./mapper.js";
import * as fs from 'fs';
import {OAS} from "./oas";
import {OAS} from "./oas.js";
import chalk from 'chalk';
// eslint-disable-next-line @typescript-eslint/no-var-requires
(await import('ts-node')).register({typeCheck: false});
import { Command } from 'commander';
import {generateSdkFrom} from "./sdk-mapper";
import {generateMockFrom} from "./mock-mapper";
import {generateSdkFrom} from "./sdk-mapper.js";
import {generateMockFrom} from "./mock-mapper.js";

const program = new Command();

Expand All @@ -24,7 +22,7 @@ export async function types(oas: OAS): Promise<string> {
async function generateFromSchema(schemaLocation: string, command: any) {
const {hydra, aws} = command;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const schema: OAS = schemaLocation.endsWith('.ts') ? (await import(schemaLocation)).default : require(schemaLocation);
const schema: OAS = schemaLocation.endsWith('.ts') ? (await import(schemaLocation)).default : (await import(schemaLocation));
const pathFinder = PathFinder.from(schema, hydra, aws);
const args = process.argv;
const version = args.find(it => it.startsWith('v='))?.substring(2);
Expand All @@ -43,7 +41,7 @@ async function generateFromSchema(schemaLocation: string, command: any) {

async function generateMockFromSchema(schemaLocation: string) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const schema: OAS = schemaLocation.endsWith('.ts') ? require(schemaLocation).default : require(schemaLocation);
const schema: OAS = schemaLocation.endsWith('.ts') ? (await import(schemaLocation)).default : (await import(schemaLocation));
const dir = 'generated/' + schema.info.title.toLowerCase().replace(/ /g, '-') + '/';
fs.writeFileSync(dir + 'mock.ts', generateMockFrom(schema));
}
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './hydra';
export * from './oas';
export * from './schema-type';
export * from './validator';
export * from './hydra.js';
export * from './oas.js';
export * from './schema-type.js';
export * from './validator.js';
4 changes: 2 additions & 2 deletions src/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
OASRequestBody,
OASResponse,
OASSecurityScheme
} from "./oas";
} from "./oas.js";

export interface PathInfo {
paths?: {
Expand Down Expand Up @@ -231,7 +231,7 @@ ${this.aws ? "import {APIGatewayProxyEvent, APIGatewayProxyResult} from 'aws-lam
${this.hydra ? "import {ResourceApiDefinition, CollectionApiDefinition, ScopedOperation} from '@hexlabs/lambda-api-ts';" : ""}
// eslint-disable-next-line @typescript-eslint/no-var-requires
import schema from './schema.json';
import * as Model from "./model";
import * as Model from "./model.js";
import {Validator} from '@hexlabs/schema-api-ts';
${this.aws ? `export interface Parts<Q extends Record<string, string>,MQ extends Record<string, string[]>,P extends Record<string, string>,H extends Record<string, string>,MH extends Record<string, string[]>> {
Expand Down
4 changes: 2 additions & 2 deletions src/mock-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {OAS, OASOperation, OASRef, OASResponse} from "./oas";
import {methodOperations, pathsFrom, traversePath} from "./sdk-mapper";
import {OAS, OASOperation, OASRef, OASResponse} from "./oas.js";
import {methodOperations, pathsFrom, traversePath} from "./sdk-mapper.js";

interface Method {
method: string
Expand Down
2 changes: 1 addition & 1 deletion src/schema-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
OASResponse,
OASSecurityScheme
} from "./oas";
import {OAS, OASComponents} from "./oas";
import {OAS, OASComponents} from "./oas.js";

type UnionToTuple<T> = (
(
Expand Down
4 changes: 2 additions & 2 deletions src/sdk-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JSONSchema } from "json-schema-to-typescript";
import { OASParameter, OASPath, OASRef, OASRequestBody, OASResponse } from "./oas";
import { OAS, OASOperation } from "./oas";
import { OASParameter, OASPath, OASRef, OASRequestBody, OASResponse } from "./oas.js";
import { OAS, OASOperation } from "./oas.js";

function capitilize(name: string): string {
return name.substring(0, 1).toUpperCase() + name.substring(1);
Expand Down
2 changes: 1 addition & 1 deletion src/validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {JSONSchema} from "json-schema-to-typescript";
import {traversePath} from "./sdk-mapper";
import {traversePath} from "./sdk-mapper.js";


interface Invalid {
Expand Down
3 changes: 1 addition & 2 deletions test/validator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {JSONSchema} from "json-schema-to-typescript";
import {SchemaBuilder} from "../src";
import {Validator} from "../src/validator";
import {SchemaBuilder, Validator} from "../src";

const s = SchemaBuilder.create();
describe('Validation', () => {
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"esm": true,
"experimentalSpecifierResolution": "node"
},
"exclude": [
"src/cli.ts"
],
"include": [
"src/**/*",
]
Expand Down

0 comments on commit 249d251

Please sign in to comment.