Skip to content

Commit

Permalink
Fix ESM type import when moduleResolution is set to Nodenext (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
sikanhe authored Dec 5, 2023
1 parent 8cac6ce commit c6b228e
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
yarn-error.log
.vscode
dist
tsconfig.tsbuildinfo
tsconfig.tsbuildinfo
install-state.gz
Binary file removed .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"type": "commonjs"
"type": "module"
}
10 changes: 5 additions & 5 deletions examples/starwars.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { InterfaceType } from '../src';
import type { Connection, ConnectionArguments, Edge } from '../src/relay';
import { buildGraphQLSchema, Gql } from '../src';
import type { InterfaceType } from '../src/index.js';
import type { Connection, ConnectionArguments, Edge } from '../src/relay.js';
import { buildGraphQLSchema, Gql } from '../src/index.js';
import {
connectionArgs,
connectionDefinitions,
nodeDefinitions,
} from '../src/relay';
} from '../src/relay.js';
import express = require('express');
import graphqlHTTP = require('express-graphql');

declare module '../src/types' {
declare module '../src/types.js' {
interface GqlContext {
contextContent: string;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"files": ["./starwars.ts"],
"compilerOptions": {
"target": "ES2019",
"module": "commonjs"
"module": "NodeNext"
}
}
3 changes: 3 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "gqtx",
"version": "0.9.0",
"type": "module",
"main": "cjs/index.js",
"main": "cjs/index.cjs",
"module": "index.js",
"types": "index.d.ts",
"exports": {
".": {
"import": "./index.js",
"require": "./cjs/index.js"
"require": "./cjs/index.cjs"
},
"./relay": {
"import": "./relay.js",
"require": "./cjs/relay.js"
"require": "./cjs/relay.cjs"
},
"./package.json": "./package.json",
"./": "./"
Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default {
{
dir: isCJSBuild ? 'dist/cjs' : 'dist',
format: isCJSBuild ? 'cjs' : 'esm',
entryFileNames: isCJSBuild ? '[name].cjs' : '[name].js',
},
],
plugins: [
Expand Down
4 changes: 2 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as graphql from 'graphql';
import {
import type {
Schema,
InputType,
OutputType,
Expand All @@ -11,7 +11,7 @@ import {
GqlContext,
UnionType,
InterfaceType,
} from './types';
} from './types.js';

export function buildGraphQLSchema<RootSrc>(
schema: Schema<RootSrc>
Expand Down
4 changes: 2 additions & 2 deletions src/define.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as graphql from 'graphql';
import {
import type {
ScalarType,
EnumType,
EnumValue,
Expand All @@ -20,7 +20,7 @@ import {
SubscriptionObjectType,
PromiseOrValue,
GqlContext,
} from './types';
} from './types.js';

type ExtensionsMap = {
field?: {
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './types';
export * from './define';
export * from './types.js';
export * from './define.js';
export {
buildGraphQLSchema,
toGraphQLInputType,
toGraphQLOutputType,
} from './build';
} from './build.js';
4 changes: 2 additions & 2 deletions src/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type {
TOfArgMap,
GqlContext,
ObjectType,
} from './types';
import { Gql } from './define';
} from './types.js';
import { Gql } from './define.js';
import { GraphQLResolveInfo } from 'graphql';

// Adapted from
Expand Down
4 changes: 2 additions & 2 deletions test-api/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Gql, ObjectType } from '../src';
import { Gql, ObjectType } from '../src/index.js';

declare module '../src/types' {
declare module '../src/types.js' {
interface Context {
contextContent: string;
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ES2019",
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "NodeNext",
"rootDir": "src",
"outDir": "dist",
"declaration": true,
Expand Down

1 comment on commit c6b228e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes have been published to npm.

yarn add -E gqtx@0.9.1-c6b228ee.0

Please sign in to comment.