Skip to content

Commit

Permalink
feat: output both esm and cjs; upgrade dependencies (#226)
Browse files Browse the repository at this point in the history
* chore: upgrade dependencies

* fix lint script

* build for esm and cjs

* eslintignore

* remove ts-node
  • Loading branch information
boopathi authored Sep 15, 2023
1 parent 6eb03f8 commit eac7fe3
Show file tree
Hide file tree
Showing 15 changed files with 2,097 additions and 2,862 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
.stryker-tmp
examples/
node_modules
6 changes: 1 addition & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
},
"extends": [
"eslint:recommended",
"standard",
"prettier",
"plugin:@typescript-eslint/recommended"
],
Expand Down Expand Up @@ -40,8 +39,5 @@
}
}
],
"ignorePatterns": [
"dist",
"node_modules"
]
"ignorePatterns": ["dist", "node_modules"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist
node_modules
/coverage
*.log
.stryker-tmp/
80 changes: 45 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,40 @@
"name": "graphql-jit",
"version": "0.8.4",
"description": "GraphQL JIT Compiler to JS",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"author": "Rui Araujo",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/zalando-incubator/graphql-jit.git"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"scripts": {
"precommit": "lint-staged",
"prepublishOnly": "yarn && yarn build",
"format": "prettier --write 'src/**/*.ts' '*.js'",
"check-format": "prettier -l 'src/**/*.ts' '*.js'",
"format": "prettier --write 'src/**/*.ts'",
"check-format": "prettier -l 'src/**/*.ts'",
"lint": "eslint --ext .ts .",
"lint-fix": "eslint --ext .ts . --fix",
"build": "tsc --project tsconfig.build.json",
"build": "yarn build:esm && yarn build:cjs",
"build:esm": "tsc --project tsconfig.esm.json",
"build:cjs": "tsc --project tsconfig.cjs.json",
"test": "jest",
"mutation-test": "stryker run",
"codecov": "codecov",
"benchmark": "NODE_ENV=production ts-node -T ./src/__benchmarks__/benchmarks.ts"
"benchmark": "NODE_ENV=production ./src/__benchmarks__/benchmarks.ts"
},
"files": [
"dist/*"
],
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"moduleFileExtensions": [
"ts",
"js",
Expand All @@ -35,7 +44,9 @@
"testEnvironment": "node",
"testRegex": "(/tests/.*|(\\.|/)test)\\.ts$",
"transform": {
"^.+\\.ts$": "ts-jest"
"^.+\\.ts$": [
"@swc/jest"
]
},
"coverageThreshold": {
"global": {
Expand All @@ -50,35 +61,31 @@
"graphql": ">=15"
},
"devDependencies": {
"@graphql-tools/schema": "^9.0.8",
"@stryker-mutator/core": "^2.0.0",
"@stryker-mutator/jest-runner": "^2.0.0",
"@stryker-mutator/typescript": "^2.0.0",
"@types/benchmark": "^1.0.31",
"@types/jest": "^29.5.2",
"@types/json-schema": "^7.0.1",
"@types/lodash.memoize": "^4.1.6",
"@types/lodash.merge": "^4.6.6",
"@types/lodash.mergewith": "^4.6.6",
"@types/node": "^10.17.26",
"@typescript-eslint/eslint-plugin": "5.2.0",
"@typescript-eslint/parser": "5.2.0",
"@graphql-tools/schema": "^10.0.0",
"@stryker-mutator/core": "^7.1.1",
"@stryker-mutator/jest-runner": "^7.1.1",
"@stryker-mutator/typescript": "^4.0.0",
"@swc-node/register": "^1.6.7",
"@swc/core": "^1.3.84",
"@swc/jest": "^0.2.29",
"@types/benchmark": "^2.1.2",
"@types/jest": "^29.5.4",
"@types/json-schema": "^7.0.12",
"@types/lodash.memoize": "^4.1.7",
"@types/lodash.merge": "^4.6.7",
"@types/lodash.mergewith": "^4.6.7",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "6.7.0",
"@typescript-eslint/parser": "6.7.0",
"benchmark": "^2.1.4",
"codecov": "^3.3.0",
"eslint": "^8.1.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.1",
"eslint-plugin-standard": "^5.0.0",
"graphql": "^16.0.0",
"jest": "^29.5.0",
"lint-staged": "^8.1.5",
"prettier": "^2.4.1",
"ts-jest": "^29.1.0",
"ts-node": "^8.0.3",
"typescript": "^4.4.4"
"codecov": "^3.8.2",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"graphql": "^16.8.0",
"jest": "^29.7.0",
"lint-staged": "^14.0.1",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
},
"dependencies": {
"@graphql-typed-document-node/core": "^3.2.0",
Expand All @@ -100,5 +107,8 @@
"git add"
]
}
},
"resolutions": {
"jest/jest-cli/yargs/**/wrap-ansi": "7.0.0"
}
}
2 changes: 2 additions & 0 deletions src/__benchmarks__/benchmarks.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node -r @swc-node/register

import Benchmark from "benchmark";
import {
DocumentNode,
Expand Down
16 changes: 13 additions & 3 deletions src/__tests__/abstract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,27 @@ function graphql(schema: GraphQLSchema, query: string) {

class Dog {
// eslint-disable-next-line no-useless-constructor
constructor(public name: string, public woofs: boolean, public other?: any) {}
constructor(
public name: string,
public woofs: boolean,
public other?: any
) {}
}

class Cat {
// eslint-disable-next-line no-useless-constructor
constructor(public name: string, public meows: boolean) {}
constructor(
public name: string,
public meows: boolean
) {}
}

class Human {
// eslint-disable-next-line no-useless-constructor
constructor(public name: string, public pets?: any) {}
constructor(
public name: string,
public pets?: any
) {}
}

// eslint-disable-next-line
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/mutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Root {
}

promiseAndFailToChangeTheNumber(): Promise<NumberHolder> {
// eslint-disable-next-line promise/param-names
return new Promise((_, reject) => {
process.nextTick(() => {
reject(new Error("Cannot change the number"));
Expand Down
10 changes: 8 additions & 2 deletions src/__tests__/union-interface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ import {
import { compileQuery } from "../index";

class Dog {
constructor(public name: string, public barks: boolean) {}
constructor(
public name: string,
public barks: boolean
) {}
}

class Cat {
constructor(public name: string, public meows: boolean) {}
constructor(
public name: string,
public meows: boolean
) {}
}

class Person {
Expand Down
38 changes: 19 additions & 19 deletions src/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,39 +1017,39 @@ function compileAbstractType(
{
if (err != null) {
${errorDestination}.push(${createErrorObject(
context,
fieldNodes,
previousPath,
"err.message != null ? err.message : err",
"err"
)});
context,
fieldNodes,
previousPath,
"err.message != null ? err.message : err",
"err"
)});
return null;
}
if (nodeType == null) {
${errorDestination}.push(${createErrorObject(
context,
fieldNodes,
previousPath,
nullTypeError
)})
context,
fieldNodes,
previousPath,
nullTypeError
)})
return null;
}
const ${finalTypeName} = typeof nodeType === "string" ? nodeType : nodeType.name;
switch(${finalTypeName}) {
${collectedTypes}
default:
${errorDestination}.push(${createErrorObject(
context,
fieldNodes,
previousPath,
noTypeError
)})
context,
fieldNodes,
previousPath,
noTypeError
)})
return null;
}
})(
${GLOBAL_EXECUTION_CONTEXT}.typeResolvers.${typeResolverName}(${originPaths.join(
"."
)},
"."
)},
${GLOBAL_CONTEXT_NAME},
${getExecutionInfo(
context,
Expand Down Expand Up @@ -1557,7 +1557,7 @@ function buildCompilationContext(
operationName?: string
): CompilationContext {
const errors: GraphQLError[] = [];
let operation: OperationDefinitionNode | void;
let operation: OperationDefinitionNode | undefined = undefined;
let hasMultipleAssumedOperations = false;
const fragments: { [key: string]: FragmentDefinitionNode } =
Object.create(null);
Expand Down
12 changes: 0 additions & 12 deletions stryker.conf.js

This file was deleted.

10 changes: 10 additions & 0 deletions stryker.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"mutator": "typescript",
"packageManager": "yarn",
"reporters": ["clear-text", "progress"],
"testRunner": "jest",
"transpilers": [],
"coverageAnalysis": "off",
"tsconfigFile": "tsconfig.json",
"mutate": ["src/**/*.ts", "!src/__benchmarks__/*.ts", "!src/__tests__/*.ts"]
}
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"outDir": "dist/cjs"
}
}
8 changes: 8 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist/esm"
}
}
13 changes: 7 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2021",
"module": "NodeNext",
"target": "ES2022",
"outDir": "./dist",
"noEmitOnError": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": false,
"moduleResolution": "node",
"moduleResolution": "NodeNext",
"sourceMap": true,
"strict": true,
"declaration": true,
"alwaysStrict": true,
"strictPropertyInitialization": true,
"esModuleInterop": true,
"outDir": "./dist",
"lib": ["esnext.asynciterable", "es2018"],
"lib": ["esnext.asynciterable", "ES2022"],
"typeRoots": ["./types", "./node_modules/@types"]
}
},
"include": ["src/**/*", "types/**/*"]
}
Loading

0 comments on commit eac7fe3

Please sign in to comment.