diff --git a/.gitignore b/.gitignore index 7fb9ee4..c1a02d8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules yarn-error.log .vscode dist -tsconfig.tsbuildinfo \ No newline at end of file +tsconfig.tsbuildinfo +install-state.gz diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz deleted file mode 100644 index bbfa25c..0000000 Binary files a/.yarn/install-state.gz and /dev/null differ diff --git a/examples/package.json b/examples/package.json index 5bbefff..3dbc1ca 100644 --- a/examples/package.json +++ b/examples/package.json @@ -1,3 +1,3 @@ { - "type": "commonjs" + "type": "module" } diff --git a/examples/starwars.ts b/examples/starwars.ts index 81cdcc7..6dc1bc3 100644 --- a/examples/starwars.ts +++ b/examples/starwars.ts @@ -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; } diff --git a/examples/tsconfig.json b/examples/tsconfig.json index fd20472..8cb0eec 100644 --- a/examples/tsconfig.json +++ b/examples/tsconfig.json @@ -3,6 +3,6 @@ "files": ["./starwars.ts"], "compilerOptions": { "target": "ES2019", - "module": "commonjs" + "module": "NodeNext" } } diff --git a/jest.config.cjs b/jest.config.cjs index 4a5b465..7c426d6 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -1,4 +1,7 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', + moduleNameMapper: { + '^(\\.{1,2}/.*)\\.js$': '$1', + }, }; diff --git a/package.json b/package.json index 76ac739..42b73b3 100644 --- a/package.json +++ b/package.json @@ -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", "./": "./" diff --git a/rollup.config.js b/rollup.config.js index 6d071ae..008f09c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -28,6 +28,7 @@ export default { { dir: isCJSBuild ? 'dist/cjs' : 'dist', format: isCJSBuild ? 'cjs' : 'esm', + entryFileNames: isCJSBuild ? '[name].cjs' : '[name].js', }, ], plugins: [ diff --git a/src/build.ts b/src/build.ts index 3af9a0a..51f2133 100644 --- a/src/build.ts +++ b/src/build.ts @@ -1,5 +1,5 @@ import * as graphql from 'graphql'; -import { +import type { Schema, InputType, OutputType, @@ -11,7 +11,7 @@ import { GqlContext, UnionType, InterfaceType, -} from './types'; +} from './types.js'; export function buildGraphQLSchema( schema: Schema diff --git a/src/define.ts b/src/define.ts index 252d909..a07ef26 100644 --- a/src/define.ts +++ b/src/define.ts @@ -1,5 +1,5 @@ import * as graphql from 'graphql'; -import { +import type { ScalarType, EnumType, EnumValue, @@ -20,7 +20,7 @@ import { SubscriptionObjectType, PromiseOrValue, GqlContext, -} from './types'; +} from './types.js'; type ExtensionsMap = { field?: { diff --git a/src/index.ts b/src/index.ts index 6532a3d..6996044 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/src/relay.ts b/src/relay.ts index 1eb6db9..c84bc4e 100644 --- a/src/relay.ts +++ b/src/relay.ts @@ -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 diff --git a/test-api/api.ts b/test-api/api.ts index 4a7586e..5a209d2 100644 --- a/test-api/api.ts +++ b/test-api/api.ts @@ -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; } diff --git a/tsconfig.json b/tsconfig.json index 9513569..c4a0ac2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "ES2019", "module": "ESNext", - "moduleResolution": "node", + "moduleResolution": "NodeNext", "rootDir": "src", "outDir": "dist", "declaration": true,