diff --git a/examples/apollo-server/Query.ts b/examples/apollo-server/Query.ts index da4db98f..611d5fbd 100644 --- a/examples/apollo-server/Query.ts +++ b/examples/apollo-server/Query.ts @@ -1,5 +1,5 @@ -import IPerson from "./interfaces/IPerson"; -import User from "./models/User"; +import IPerson from "./interfaces/IPerson.js"; +import User from "./models/User.js"; /** @gqlQueryField */ export function person(): IPerson { diff --git a/examples/apollo-server/models/Group.ts b/examples/apollo-server/models/Group.ts index 9e672ad3..083ed7a9 100644 --- a/examples/apollo-server/models/Group.ts +++ b/examples/apollo-server/models/Group.ts @@ -1,4 +1,4 @@ -import User from "./User"; +import User from "./User.js"; /** @gqlType */ export default class Group { diff --git a/examples/apollo-server/models/User.ts b/examples/apollo-server/models/User.ts index e529f742..9528528d 100644 --- a/examples/apollo-server/models/User.ts +++ b/examples/apollo-server/models/User.ts @@ -1,5 +1,5 @@ -import IPerson from "../interfaces/IPerson"; -import Group from "./Group"; +import IPerson from "../interfaces/IPerson.js"; +import Group from "./Group.js"; /** @gqlType User */ export default class UserResolver implements IPerson { diff --git a/examples/apollo-server/package.json b/examples/apollo-server/package.json index 22047c24..f88c1a43 100644 --- a/examples/apollo-server/package.json +++ b/examples/apollo-server/package.json @@ -2,6 +2,7 @@ "name": "grats-example-apollo-server", "version": "0.0.0", "description": "Example server showcasing Grats used with Apollo Server", + "type": "module", "main": "index.js", "scripts": { "start": "tsc && node dist/server.js", diff --git a/examples/apollo-server/schema.ts b/examples/apollo-server/schema.ts index 0b003593..02f6597b 100644 --- a/examples/apollo-server/schema.ts +++ b/examples/apollo-server/schema.ts @@ -3,11 +3,11 @@ * Do not manually edit. Regenerate by running `npx grats`. */ -import UserClass from "./models/User"; -import queryAllUsersResolver from "./models/User"; -import queryMeResolver from "./models/User"; +import UserClass from "./models/User.js"; +import queryAllUsersResolver from "./models/User.js"; +import queryMeResolver from "./models/User.js"; import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLString, GraphQLInterfaceType } from "graphql"; -import { person as queryPersonResolver } from "./Query"; +import { person as queryPersonResolver } from "./Query.js"; export function getSchema(): GraphQLSchema { const GroupType: GraphQLObjectType = new GraphQLObjectType({ name: "Group", diff --git a/examples/apollo-server/server.ts b/examples/apollo-server/server.ts index a1a80e98..e2276d3d 100644 --- a/examples/apollo-server/server.ts +++ b/examples/apollo-server/server.ts @@ -1,6 +1,6 @@ import { ApolloServer } from "@apollo/server"; import { startStandaloneServer } from "@apollo/server/standalone"; -import { getSchema } from "./schema"; +import { getSchema } from "./schema.js"; async function main() { const server = new ApolloServer({ schema: getSchema() }); diff --git a/examples/apollo-server/tsconfig.json b/examples/apollo-server/tsconfig.json index b481663c..a0de5f60 100644 --- a/examples/apollo-server/tsconfig.json +++ b/examples/apollo-server/tsconfig.json @@ -1,6 +1,7 @@ { "grats": { - "nullableByDefault": false + "nullableByDefault": false, + "importModuleSpecifierEnding": ".js" }, "compilerOptions": { "outDir": "dist", diff --git a/examples/express-graphql-http/interfaces/IPerson.ts b/examples/express-graphql-http/interfaces/IPerson.ts index 21cbc43c..1be795f1 100644 --- a/examples/express-graphql-http/interfaces/IPerson.ts +++ b/examples/express-graphql-http/interfaces/IPerson.ts @@ -1,4 +1,4 @@ -import User from "../models/User"; +import User from "../models/User.js"; /** @gqlInterface */ export default interface IPerson { diff --git a/examples/express-graphql-http/models/Group.ts b/examples/express-graphql-http/models/Group.ts index 9e672ad3..083ed7a9 100644 --- a/examples/express-graphql-http/models/Group.ts +++ b/examples/express-graphql-http/models/Group.ts @@ -1,4 +1,4 @@ -import User from "./User"; +import User from "./User.js"; /** @gqlType */ export default class Group { diff --git a/examples/express-graphql-http/models/User.ts b/examples/express-graphql-http/models/User.ts index cea29b75..858b38e5 100644 --- a/examples/express-graphql-http/models/User.ts +++ b/examples/express-graphql-http/models/User.ts @@ -1,5 +1,5 @@ -import IPerson from "../interfaces/IPerson"; -import Group from "./Group"; +import IPerson from "../interfaces/IPerson.js"; +import Group from "./Group.js"; /** @gqlType */ export default class User implements IPerson { diff --git a/examples/express-graphql-http/package.json b/examples/express-graphql-http/package.json index 5fefda47..d8abb5ec 100644 --- a/examples/express-graphql-http/package.json +++ b/examples/express-graphql-http/package.json @@ -2,6 +2,7 @@ "name": "grats-example-express-graphql-http", "version": "0.0.0", "description": "Example server showcasing Grats used with Express and graphql-http ", + "type": "module", "main": "index.js", "scripts": { "start": "tsc && node dist/server.js", diff --git a/examples/express-graphql-http/schema.ts b/examples/express-graphql-http/schema.ts index c0446b29..ea09bc5e 100644 --- a/examples/express-graphql-http/schema.ts +++ b/examples/express-graphql-http/schema.ts @@ -3,11 +3,11 @@ * Do not manually edit. Regenerate by running `npx grats`. */ -import UserClass from "./models/User"; -import queryAllUsersResolver from "./models/User"; -import queryMeResolver from "./models/User"; +import UserClass from "./models/User.js"; +import queryAllUsersResolver from "./models/User.js"; +import queryMeResolver from "./models/User.js"; import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLString, GraphQLInterfaceType } from "graphql"; -import { person as queryPersonResolver } from "./interfaces/IPerson"; +import { person as queryPersonResolver } from "./interfaces/IPerson.js"; export function getSchema(): GraphQLSchema { const GroupType: GraphQLObjectType = new GraphQLObjectType({ name: "Group", diff --git a/examples/express-graphql-http/server.ts b/examples/express-graphql-http/server.ts index e2d6830e..db9645f3 100644 --- a/examples/express-graphql-http/server.ts +++ b/examples/express-graphql-http/server.ts @@ -1,6 +1,6 @@ -import * as express from "express"; +import express from "express"; import { createHandler } from "graphql-http/lib/use/express"; -import { getSchema } from "./schema"; +import { getSchema } from "./schema.js"; const app = express(); diff --git a/examples/express-graphql-http/tsconfig.json b/examples/express-graphql-http/tsconfig.json index 3b3157a9..7e1447a3 100644 --- a/examples/express-graphql-http/tsconfig.json +++ b/examples/express-graphql-http/tsconfig.json @@ -1,17 +1,15 @@ { - // Most ts-node options can be specified here using their programmatic names. - "ts-node": { - "files": true, - // It is faster to skip typechecking. - // Remove if you want ts-node to do typechecking. - "transpileOnly": false - }, "grats": { - "nullableByDefault": false + "nullableByDefault": false, + "importModuleSpecifierEnding": ".js" }, "compilerOptions": { "outDir": "dist", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "target": "esnext", "lib": ["esnext"], - "strict": true + "strict": true, + "skipLibCheck": true } } diff --git a/examples/incremental-migration/package.json b/examples/incremental-migration/package.json index 0ad24d75..8b3e818d 100644 --- a/examples/incremental-migration/package.json +++ b/examples/incremental-migration/package.json @@ -2,6 +2,7 @@ "name": "grats-example-migration", "version": "0.0.0", "description": "Example server showcasing an incremental migration from Pothos to Grats", + "type": "module", "main": "index.js", "scripts": { "start": "tsc && node dist/server.js", diff --git a/examples/incremental-migration/schemas/gratsGeneratedSchema.ts b/examples/incremental-migration/schemas/gratsGeneratedSchema.ts index 8f8a52c9..ab41ce35 100644 --- a/examples/incremental-migration/schemas/gratsGeneratedSchema.ts +++ b/examples/incremental-migration/schemas/gratsGeneratedSchema.ts @@ -1,7 +1,7 @@ // DO NOT USE DIRECTLY. Prefer the merged schema in `./mergedSchema.ts`. import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLString, GraphQLID } from "graphql"; -import { user as queryUserResolver } from "./../models"; +import { user as queryUserResolver } from "./../models.js"; export function getSchema(): GraphQLSchema { const UserType: GraphQLObjectType = new GraphQLObjectType({ name: "User", diff --git a/examples/incremental-migration/schemas/mergedSchema.ts b/examples/incremental-migration/schemas/mergedSchema.ts index 1a28fffc..6ad656e5 100644 --- a/examples/incremental-migration/schemas/mergedSchema.ts +++ b/examples/incremental-migration/schemas/mergedSchema.ts @@ -1,9 +1,13 @@ -import { schema as legacySchema } from "./pothosSchema"; -import { getSchema as getGratsSchema } from "./gratsGeneratedSchema"; +import { schema as legacySchema } from "./pothosSchema.js"; +import { getSchema as getGratsSchema } from "./gratsGeneratedSchema.js"; import { mergeSchemas } from "@graphql-tools/schema"; import { printSchema, lexicographicSortSchema } from "graphql"; import fs from "fs"; import path from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); /** * Merges the Pothos (legacy) and Grats (new) schemas into a single schema for diff --git a/examples/incremental-migration/schemas/pothosSchema.ts b/examples/incremental-migration/schemas/pothosSchema.ts index 91baa0b4..57454492 100644 --- a/examples/incremental-migration/schemas/pothosSchema.ts +++ b/examples/incremental-migration/schemas/pothosSchema.ts @@ -1,4 +1,4 @@ -import { Users, Posts, Comments, User, Post, Comment } from "../models"; +import { Users, Posts, Comments, User, Post, Comment } from "../models.js"; import SchemaBuilder from "@pothos/core"; const builder = new SchemaBuilder({}); diff --git a/examples/incremental-migration/server.ts b/examples/incremental-migration/server.ts index b6c89556..74a0d60e 100644 --- a/examples/incremental-migration/server.ts +++ b/examples/incremental-migration/server.ts @@ -1,6 +1,6 @@ import { createServer } from "node:http"; import { createYoga } from "graphql-yoga"; -import { schema } from "./schemas/mergedSchema"; +import { schema } from "./schemas/mergedSchema.js"; const yoga = createYoga({ schema }); diff --git a/examples/incremental-migration/tsconfig.json b/examples/incremental-migration/tsconfig.json index d28abac2..a05563ce 100644 --- a/examples/incremental-migration/tsconfig.json +++ b/examples/incremental-migration/tsconfig.json @@ -4,7 +4,8 @@ "tsSchema": "./schemas/gratsGeneratedSchema.ts", "graphqlSchema": "gratsSchema.graphql", "tsSchemaHeader": "// DO NOT USE DIRECTLY. Prefer the merged schema in `./mergedSchema.ts`.", - "schemaHeader": "# DO NOT USE DIRECTLY. Prefer the merged schema in `../schema.graphql`." + "schemaHeader": "# DO NOT USE DIRECTLY. Prefer the merged schema in `../schema.graphql`.", + "importModuleSpecifierEnding": ".js" }, "compilerOptions": { "outDir": "dist", diff --git a/examples/next-js/tsconfig.json b/examples/next-js/tsconfig.json index a1f82ceb..2dc730ae 100644 --- a/examples/next-js/tsconfig.json +++ b/examples/next-js/tsconfig.json @@ -1,6 +1,7 @@ { "grats": { - "nullableByDefault": false + "nullableByDefault": false, + "importModuleSpecifierEnding": "" }, "compilerOptions": { "target": "es5", diff --git a/examples/production-app/Database.ts b/examples/production-app/Database.ts index f5422715..2f94aa71 100644 --- a/examples/production-app/Database.ts +++ b/examples/production-app/Database.ts @@ -1,8 +1,8 @@ -import { PubSub } from "./PubSub"; -import { VC } from "./ViewerContext"; -import { Like } from "./models/Like"; -import { Post } from "./models/Post"; -import { User } from "./models/User"; +import { PubSub } from "./PubSub.js"; +import { VC } from "./ViewerContext.js"; +import { Like } from "./models/Like.js"; +import { Post } from "./models/Post.js"; +import { User } from "./models/User.js"; /** * This module is intended to represent a database. diff --git a/examples/production-app/ViewerContext.ts b/examples/production-app/ViewerContext.ts index 77969684..3fccc2e3 100644 --- a/examples/production-app/ViewerContext.ts +++ b/examples/production-app/ViewerContext.ts @@ -1,9 +1,9 @@ import DataLoader from "dataloader"; -import { getPostsByIds, getUsersByIds, getLikesByIds } from "./Database"; +import { getPostsByIds, getUsersByIds, getLikesByIds } from "./Database.js"; import { YogaInitialContext } from "graphql-yoga"; -import { Post } from "./models/Post"; -import { User } from "./models/User"; -import { Like } from "./models/Like"; +import { Post } from "./models/Post.js"; +import { User } from "./models/User.js"; +import { Like } from "./models/Like.js"; /** * Viewer Context diff --git a/examples/production-app/graphql/CustomScalars.ts b/examples/production-app/graphql/CustomScalars.ts index c6989f3a..21aada62 100644 --- a/examples/production-app/graphql/CustomScalars.ts +++ b/examples/production-app/graphql/CustomScalars.ts @@ -1,5 +1,5 @@ import { Kind } from "graphql"; -import type { SchemaConfig } from "../schema"; +import type { SchemaConfig } from "../schema.js"; // TODO: Consider switching serialization to follow https://ibm.github.io/graphql-specs/custom-scalars/date.html diff --git a/examples/production-app/graphql/Node.ts b/examples/production-app/graphql/Node.ts index 739807dd..602dccf4 100644 --- a/examples/production-app/graphql/Node.ts +++ b/examples/production-app/graphql/Node.ts @@ -1,6 +1,6 @@ import { fromGlobalId, toGlobalId } from "graphql-relay"; import { ID } from "grats"; -import { VC } from "../ViewerContext"; +import { VC } from "../ViewerContext.js"; /** * Converts a globally unique ID into a local ID asserting diff --git a/examples/production-app/graphql/directives.ts b/examples/production-app/graphql/directives.ts index 9778b5ac..2530f56e 100644 --- a/examples/production-app/graphql/directives.ts +++ b/examples/production-app/graphql/directives.ts @@ -1,6 +1,6 @@ import { defaultFieldResolver, GraphQLError, GraphQLSchema } from "graphql"; import { Int } from "grats"; -import { Ctx } from "../ViewerContext"; +import { Ctx } from "../ViewerContext.js"; import { getDirective, MapperKind, mapSchema } from "@graphql-tools/utils"; /** diff --git a/examples/production-app/models/Like.ts b/examples/production-app/models/Like.ts index 8c5f99e7..4f7ae6cd 100644 --- a/examples/production-app/models/Like.ts +++ b/examples/production-app/models/Like.ts @@ -1,11 +1,11 @@ -import * as DB from "../Database"; -import { VC } from "../ViewerContext"; -import { GraphQLNode, getLocalTypeAssert } from "../graphql/Node"; -import { User } from "./User"; -import { Model } from "./Model"; -import { ID } from "../../../dist/src"; -import { GqlDate } from "../graphql/CustomScalars"; -import { Post } from "./Post"; +import * as DB from "../Database.js"; +import { VC } from "../ViewerContext.js"; +import { GraphQLNode, getLocalTypeAssert } from "../graphql/Node.js"; +import { User } from "./User.js"; +import { Model } from "./Model.js"; +import { ID } from "../../../dist/src/index.js"; +import { GqlDate } from "../graphql/CustomScalars.js"; +import { Post } from "./Post.js"; /** * A reaction from a user indicating that they like a post. diff --git a/examples/production-app/models/LikeConnection.ts b/examples/production-app/models/LikeConnection.ts index 0ccf9dae..d34047df 100644 --- a/examples/production-app/models/LikeConnection.ts +++ b/examples/production-app/models/LikeConnection.ts @@ -1,11 +1,11 @@ import { GqlInfo, Int } from "grats"; -import * as DB from "../Database"; -import { VC } from "../ViewerContext"; -import { Like } from "./Like"; -import { PageInfo } from "../graphql/Connection"; -import { PubSub } from "../PubSub"; +import * as DB from "../Database.js"; +import { VC } from "../ViewerContext.js"; +import { Like } from "./Like.js"; +import { PageInfo } from "../graphql/Connection.js"; +import { PubSub } from "../PubSub.js"; import { filter, map, pipe } from "graphql-yoga"; -import { getLocalTypeAssert } from "../graphql/Node"; +import { getLocalTypeAssert } from "../graphql/Node.js"; import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js"; /** @gqlType */ diff --git a/examples/production-app/models/Model.ts b/examples/production-app/models/Model.ts index 71061319..a990f9c9 100644 --- a/examples/production-app/models/Model.ts +++ b/examples/production-app/models/Model.ts @@ -1,4 +1,4 @@ -import { VC } from "../ViewerContext"; +import { VC } from "../ViewerContext.js"; /** * Generic model class built around a database row diff --git a/examples/production-app/models/Post.ts b/examples/production-app/models/Post.ts index f39fa42f..50d1711b 100644 --- a/examples/production-app/models/Post.ts +++ b/examples/production-app/models/Post.ts @@ -1,11 +1,11 @@ -import * as DB from "../Database"; -import { VC } from "../ViewerContext"; -import { GraphQLNode, getLocalTypeAssert } from "../graphql/Node"; -import { User } from "./User"; -import { Model } from "./Model"; -import { GqlInfo, ID, Int } from "../../../dist/src"; -import { GqlDate } from "../graphql/CustomScalars"; -import { LikeConnection } from "./LikeConnection"; +import * as DB from "../Database.js"; +import { VC } from "../ViewerContext.js"; +import { GraphQLNode, getLocalTypeAssert } from "../graphql/Node.js"; +import { User } from "./User.js"; +import { Model } from "./Model.js"; +import { GqlInfo, ID, Int } from "../../../dist/src/index.js"; +import { GqlDate } from "../graphql/CustomScalars.js"; +import { LikeConnection } from "./LikeConnection.js"; import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js"; /** diff --git a/examples/production-app/models/PostConnection.ts b/examples/production-app/models/PostConnection.ts index 8c4db6d7..90f449dc 100644 --- a/examples/production-app/models/PostConnection.ts +++ b/examples/production-app/models/PostConnection.ts @@ -1,8 +1,8 @@ import { GqlInfo, Int } from "grats"; -import * as DB from "../Database"; -import { VC } from "../ViewerContext"; -import { Post } from "./Post"; -import { Connection } from "../graphql/Connection"; +import * as DB from "../Database.js"; +import { VC } from "../ViewerContext.js"; +import { Post } from "./Post.js"; +import { Connection } from "../graphql/Connection.js"; import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js"; /** diff --git a/examples/production-app/models/User.ts b/examples/production-app/models/User.ts index f0f526de..eee087c3 100644 --- a/examples/production-app/models/User.ts +++ b/examples/production-app/models/User.ts @@ -1,9 +1,9 @@ -import * as DB from "../Database"; -import { VC } from "../ViewerContext"; -import { GraphQLNode } from "../graphql/Node"; -import { Model } from "./Model"; -import { Post } from "./Post"; -import { Connection } from "../graphql/Connection"; +import * as DB from "../Database.js"; +import { VC } from "../ViewerContext.js"; +import { GraphQLNode } from "../graphql/Node.js"; +import { Model } from "./Model.js"; +import { Post } from "./Post.js"; +import { Connection } from "../graphql/Connection.js"; import { GqlInfo, Int } from "../../../dist/src/Types.js"; import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js"; diff --git a/examples/production-app/models/UserConnection.ts b/examples/production-app/models/UserConnection.ts index ed4289ba..d5d7b14e 100644 --- a/examples/production-app/models/UserConnection.ts +++ b/examples/production-app/models/UserConnection.ts @@ -1,8 +1,8 @@ import { GqlInfo, Int } from "grats"; -import * as DB from "../Database"; -import { VC } from "../ViewerContext"; -import { User } from "./User"; -import { Connection } from "../graphql/Connection"; +import * as DB from "../Database.js"; +import { VC } from "../ViewerContext.js"; +import { User } from "./User.js"; +import { Connection } from "../graphql/Connection.js"; import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js"; /** diff --git a/examples/production-app/models/Viewer.ts b/examples/production-app/models/Viewer.ts index 95474948..c7162488 100644 --- a/examples/production-app/models/Viewer.ts +++ b/examples/production-app/models/Viewer.ts @@ -1,7 +1,7 @@ -import * as DB from "../Database"; -import { VC } from "../ViewerContext"; -import { Post } from "./Post"; -import { User } from "./User"; +import * as DB from "../Database.js"; +import { VC } from "../ViewerContext.js"; +import { Post } from "./Post.js"; +import { User } from "./User.js"; /** * The currently authenticated viewer. diff --git a/examples/production-app/package.json b/examples/production-app/package.json index e923ea9d..9aedf230 100644 --- a/examples/production-app/package.json +++ b/examples/production-app/package.json @@ -2,6 +2,7 @@ "name": "grats-production-app-example", "version": "0.0.0", "description": "Example server showcasing Grats in a feature complete server", + "type": "module", "main": "index.js", "scripts": { "start": "tsc && node dist/server.js", diff --git a/examples/production-app/schema.ts b/examples/production-app/schema.ts index df085a55..b77fe4fb 100644 --- a/examples/production-app/schema.ts +++ b/examples/production-app/schema.ts @@ -4,17 +4,17 @@ */ import type { GqlScalar } from "grats"; -import type { GqlDate as DateInternal } from "./graphql/CustomScalars"; +import type { GqlDate as DateInternal } from "./graphql/CustomScalars.js"; import { GraphQLSchema, GraphQLDirective, DirectiveLocation, GraphQLNonNull, GraphQLInt, specifiedDirectives, GraphQLObjectType, GraphQLList, GraphQLString, GraphQLScalarType, GraphQLID, GraphQLInterfaceType, GraphQLBoolean, GraphQLInputObjectType } from "graphql"; -import { id as likeIdResolver, id as userIdResolver, id as postIdResolver, node as queryNodeResolver, nodes as queryNodesResolver } from "./graphql/Node"; -import { nodes as postConnectionNodesResolver, posts as queryPostsResolver } from "./models/PostConnection"; -import { nodes as likeConnectionNodesResolver, likes as queryLikesResolver, postLikes as subscriptionPostLikesResolver } from "./models/LikeConnection"; -import { getVc } from "./ViewerContext"; -import { nodes as userConnectionNodesResolver, users as queryUsersResolver } from "./models/UserConnection"; -import { Viewer as queryViewerResolver } from "./models/Viewer"; -import { createLike as mutationCreateLikeResolver } from "./models/Like"; -import { createPost as mutationCreatePostResolver } from "./models/Post"; -import { createUser as mutationCreateUserResolver } from "./models/User"; +import { id as likeIdResolver, id as userIdResolver, id as postIdResolver, node as queryNodeResolver, nodes as queryNodesResolver } from "./graphql/Node.js"; +import { nodes as postConnectionNodesResolver, posts as queryPostsResolver } from "./models/PostConnection.js"; +import { nodes as likeConnectionNodesResolver, likes as queryLikesResolver, postLikes as subscriptionPostLikesResolver } from "./models/LikeConnection.js"; +import { getVc } from "./ViewerContext.js"; +import { nodes as userConnectionNodesResolver, users as queryUsersResolver } from "./models/UserConnection.js"; +import { Viewer as queryViewerResolver } from "./models/Viewer.js"; +import { createLike as mutationCreateLikeResolver } from "./models/Like.js"; +import { createPost as mutationCreatePostResolver } from "./models/Post.js"; +import { createUser as mutationCreateUserResolver } from "./models/User.js"; export type SchemaConfig = { scalars: { Date: GqlScalar; diff --git a/examples/production-app/server.ts b/examples/production-app/server.ts index aae01e51..39e3ecb8 100644 --- a/examples/production-app/server.ts +++ b/examples/production-app/server.ts @@ -1,10 +1,10 @@ import { createServer } from "node:http"; import { createYoga } from "graphql-yoga"; -import { getSchema } from "./schema"; -import { VC } from "./ViewerContext"; -import { scalarConfig } from "./graphql/CustomScalars"; +import { getSchema } from "./schema.js"; +import { VC } from "./ViewerContext.js"; +import { scalarConfig } from "./graphql/CustomScalars.js"; import { useDeferStream } from "@graphql-yoga/plugin-defer-stream"; -import { applyCreditLimit } from "./graphql/directives"; +import { applyCreditLimit } from "./graphql/directives.js"; let schema = getSchema({ scalars: scalarConfig }); schema = applyCreditLimit(schema); diff --git a/examples/production-app/tsconfig.json b/examples/production-app/tsconfig.json index 5f7c2e7d..79dc2a64 100644 --- a/examples/production-app/tsconfig.json +++ b/examples/production-app/tsconfig.json @@ -1,5 +1,7 @@ { - "grats": {}, + "grats": { + "importModuleSpecifierEnding": ".js" + }, "compilerOptions": { "outDir": "dist", "module": "NodeNext", diff --git a/examples/strict-semantic-nullability/interfaces/IPerson.ts b/examples/strict-semantic-nullability/interfaces/IPerson.ts index 21cbc43c..1be795f1 100644 --- a/examples/strict-semantic-nullability/interfaces/IPerson.ts +++ b/examples/strict-semantic-nullability/interfaces/IPerson.ts @@ -1,4 +1,4 @@ -import User from "../models/User"; +import User from "../models/User.js"; /** @gqlInterface */ export default interface IPerson { diff --git a/examples/strict-semantic-nullability/models/Group.ts b/examples/strict-semantic-nullability/models/Group.ts index 9e672ad3..083ed7a9 100644 --- a/examples/strict-semantic-nullability/models/Group.ts +++ b/examples/strict-semantic-nullability/models/Group.ts @@ -1,4 +1,4 @@ -import User from "./User"; +import User from "./User.js"; /** @gqlType */ export default class Group { diff --git a/examples/strict-semantic-nullability/models/User.ts b/examples/strict-semantic-nullability/models/User.ts index 034a09a3..1dde3ed8 100644 --- a/examples/strict-semantic-nullability/models/User.ts +++ b/examples/strict-semantic-nullability/models/User.ts @@ -1,5 +1,5 @@ -import IPerson from "../interfaces/IPerson"; -import Group from "./Group"; +import IPerson from "../interfaces/IPerson.js"; +import Group from "./Group.js"; /** @gqlType User */ export default class User implements IPerson { diff --git a/examples/strict-semantic-nullability/package.json b/examples/strict-semantic-nullability/package.json index 5842fe43..25f4320b 100644 --- a/examples/strict-semantic-nullability/package.json +++ b/examples/strict-semantic-nullability/package.json @@ -2,6 +2,7 @@ "name": "grats-example-strict-sematic-nullability", "version": "0.0.0", "description": "Example server showcasing Grats' experimental support for strict semantic nullability", + "type": "module", "main": "index.js", "scripts": { "start": "tsc && node dist/server.js", diff --git a/examples/strict-semantic-nullability/schema.ts b/examples/strict-semantic-nullability/schema.ts index 6fb799b2..e5948402 100644 --- a/examples/strict-semantic-nullability/schema.ts +++ b/examples/strict-semantic-nullability/schema.ts @@ -3,12 +3,12 @@ * Do not manually edit. Regenerate by running `npx grats`. */ -import UserClass from "./models/User"; -import queryAllUsersResolver from "./models/User"; -import queryMeResolver from "./models/User"; +import UserClass from "./models/User.js"; +import queryAllUsersResolver from "./models/User.js"; +import queryMeResolver from "./models/User.js"; import { GraphQLSchema, GraphQLDirective, DirectiveLocation, GraphQLList, GraphQLInt, specifiedDirectives, GraphQLObjectType, GraphQLNonNull, GraphQLString, defaultFieldResolver, GraphQLInterfaceType } from "graphql"; -import { person as queryPersonResolver } from "./interfaces/IPerson"; -import { countdown as subscriptionCountdownResolver, nullItems as subscriptionNullItemsResolver, nullIterable as subscriptionNullIterableResolver } from "./Subscription"; +import { person as queryPersonResolver } from "./interfaces/IPerson.js"; +import { countdown as subscriptionCountdownResolver, nullItems as subscriptionNullItemsResolver, nullIterable as subscriptionNullIterableResolver } from "./Subscription.js"; async function assertNonNull(value: T | Promise): Promise { const awaited = await value; if (awaited == null) diff --git a/examples/strict-semantic-nullability/server.ts b/examples/strict-semantic-nullability/server.ts index 3ffa1c21..7a03bd50 100644 --- a/examples/strict-semantic-nullability/server.ts +++ b/examples/strict-semantic-nullability/server.ts @@ -1,6 +1,6 @@ import { createServer } from "node:http"; import { createYoga } from "graphql-yoga"; -import { getSchema } from "./schema"; +import { getSchema } from "./schema.js"; const yoga = createYoga({ schema: getSchema(), diff --git a/examples/strict-semantic-nullability/tsconfig.json b/examples/strict-semantic-nullability/tsconfig.json index 609f9758..6cd133aa 100644 --- a/examples/strict-semantic-nullability/tsconfig.json +++ b/examples/strict-semantic-nullability/tsconfig.json @@ -1,7 +1,8 @@ { "grats": { "nullableByDefault": true, - "strictSemanticNullability": true + "strictSemanticNullability": true, + "importModuleSpecifierEnding": ".js" }, "compilerOptions": { "outDir": "dist", diff --git a/examples/yoga/interfaces/IPerson.ts b/examples/yoga/interfaces/IPerson.ts index 21cbc43c..1be795f1 100644 --- a/examples/yoga/interfaces/IPerson.ts +++ b/examples/yoga/interfaces/IPerson.ts @@ -1,4 +1,4 @@ -import User from "../models/User"; +import User from "../models/User.js"; /** @gqlInterface */ export default interface IPerson { diff --git a/examples/yoga/models/Group.ts b/examples/yoga/models/Group.ts index 9e672ad3..083ed7a9 100644 --- a/examples/yoga/models/Group.ts +++ b/examples/yoga/models/Group.ts @@ -1,4 +1,4 @@ -import User from "./User"; +import User from "./User.js"; /** @gqlType */ export default class Group { diff --git a/examples/yoga/models/User.ts b/examples/yoga/models/User.ts index 6b1d0fa8..6c563b3d 100644 --- a/examples/yoga/models/User.ts +++ b/examples/yoga/models/User.ts @@ -1,5 +1,5 @@ -import IPerson from "../interfaces/IPerson"; -import Group from "./Group"; +import IPerson from "../interfaces/IPerson.js"; +import Group from "./Group.js"; /** @gqlType User */ export default class User implements IPerson { diff --git a/examples/yoga/package.json b/examples/yoga/package.json index 5ca95223..866a5940 100644 --- a/examples/yoga/package.json +++ b/examples/yoga/package.json @@ -2,6 +2,7 @@ "name": "grats-example-yoga", "version": "0.0.0", "description": "Example server showcasing Grats used with Yoga", + "type": "module", "main": "index.js", "scripts": { "start": "tsc && node dist/server.js", diff --git a/examples/yoga/schema.ts b/examples/yoga/schema.ts index 2d8515bd..ede983c3 100644 --- a/examples/yoga/schema.ts +++ b/examples/yoga/schema.ts @@ -3,12 +3,12 @@ * Do not manually edit. Regenerate by running `npx grats`. */ -import UserClass from "./models/User"; -import queryAllUsersResolver from "./models/User"; -import queryMeResolver from "./models/User"; +import UserClass from "./models/User.js"; +import queryAllUsersResolver from "./models/User.js"; +import queryMeResolver from "./models/User.js"; import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLString, GraphQLInterfaceType, GraphQLInt } from "graphql"; -import { person as queryPersonResolver } from "./interfaces/IPerson"; -import { countdown as subscriptionCountdownResolver } from "./Subscription"; +import { person as queryPersonResolver } from "./interfaces/IPerson.js"; +import { countdown as subscriptionCountdownResolver } from "./Subscription.js"; export function getSchema(): GraphQLSchema { const GroupType: GraphQLObjectType = new GraphQLObjectType({ name: "Group", diff --git a/examples/yoga/server.ts b/examples/yoga/server.ts index 3ffa1c21..7a03bd50 100644 --- a/examples/yoga/server.ts +++ b/examples/yoga/server.ts @@ -1,6 +1,6 @@ import { createServer } from "node:http"; import { createYoga } from "graphql-yoga"; -import { getSchema } from "./schema"; +import { getSchema } from "./schema.js"; const yoga = createYoga({ schema: getSchema(), diff --git a/examples/yoga/tsconfig.json b/examples/yoga/tsconfig.json index 7869c561..7e1447a3 100644 --- a/examples/yoga/tsconfig.json +++ b/examples/yoga/tsconfig.json @@ -1,6 +1,7 @@ { "grats": { - "nullableByDefault": false + "nullableByDefault": false, + "importModuleSpecifierEnding": ".js" }, "compilerOptions": { "outDir": "dist", diff --git a/package.json b/package.json index b2a71830..5f639e60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "grats", "version": "0.0.35", + "type": "module", "main": "dist/src/index.js", "bin": "dist/src/cli.js", "types": "dist/src/index.d.ts", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76a30ff3..ab4196b0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -350,9 +350,9 @@ importers: monaco-editor-webpack-plugin: specifier: ^7.1.0 version: 7.1.0(monaco-editor@0.52.2)(webpack@5.78.0) - ts-node: - specifier: ^10.9.2 - version: 10.9.2(@types/node@18.15.0)(typescript@5.9.2) + tsx: + specifier: ^4.19.2 + version: 4.21.0 typescript: specifier: 5.9.2 version: 5.9.2 @@ -1725,10 +1725,6 @@ packages: resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==} engines: {node: '>=0.1.90'} - '@cspotcode/source-map-support@0.8.1': - resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} - engines: {node: '>=12'} - '@csstools/cascade-layer-name-parser@2.0.4': resolution: {integrity: sha512-7DFHlPuIxviKYZrOiwVU/PiHLm3lLUR23OMuEEtfEOQTOp9hzQ2JjdY6X5H18RVuUPJqSCI+qNnD5iOLMVE0bA==} engines: {node: '>=18'} @@ -2571,9 +2567,6 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} - '@jridgewell/trace-mapping@0.3.9': - resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} - '@leichtgewicht/ip-codec@2.0.4': resolution: {integrity: sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==} @@ -2836,18 +2829,6 @@ packages: resolution: {integrity: sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==} engines: {node: '>=10.13.0'} - '@tsconfig/node10@1.0.9': - resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} - - '@tsconfig/node12@1.0.11': - resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} - - '@tsconfig/node14@1.0.3': - resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} - - '@tsconfig/node16@1.0.3': - resolution: {integrity: sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==} - '@types/acorn@4.0.6': resolution: {integrity: sha512-veQTnWP+1D/xbxVrPC3zHnCZRjSrKfhbMUlEA43iMZLu7EsnTtkJklIuwrCPbOi8YkvDQAiW05VQQFvvz9oieQ==} @@ -3388,9 +3369,6 @@ packages: resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==} engines: {node: '>= 8'} - arg@4.1.3: - resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} - arg@5.0.2: resolution: {integrity: sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==} @@ -3840,9 +3818,6 @@ packages: typescript: optional: true - create-require@1.1.1: - resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} - cross-inspect@1.0.1: resolution: {integrity: sha512-Pcw1JTvZLSJH83iiGWt6fRcT+BjZlCDRVwYLbUcHzv/CRpB7r0MlSrGbIyQvVSNyGnbt7G4AXuyCiDR3POvZ1A==} engines: {node: '>=16.0.0'} @@ -4226,10 +4201,6 @@ packages: devlop@1.1.0: resolution: {integrity: sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==} - diff@4.0.2: - resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} - engines: {node: '>=0.3.1'} - diff@5.2.0: resolution: {integrity: sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==} engines: {node: '>=0.3.1'} @@ -5446,9 +5417,6 @@ packages: resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==} hasBin: true - make-error@1.3.6: - resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} - markdown-extensions@2.0.0: resolution: {integrity: sha512-o5vL7aDWatOTX8LzaS1WMoaoxIiLRQJuIKKe2wAw6IeULDHaqbiqiggmx+pKvZDb1Sj+pE46Sn1T7lCqfFtg1Q==} engines: {node: '>=16'} @@ -7292,20 +7260,6 @@ packages: resolution: {integrity: sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==} engines: {node: '>=6.10'} - ts-node@10.9.2: - resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} - hasBin: true - peerDependencies: - '@swc/core': '>=1.2.50' - '@swc/wasm': '>=1.2.50' - '@types/node': '*' - typescript: '>=2.7' - peerDependenciesMeta: - '@swc/core': - optional: true - '@swc/wasm': - optional: true - tslib@2.5.0: resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==} @@ -7507,9 +7461,6 @@ packages: engines: {node: '>=8'} hasBin: true - v8-compile-cache-lib@3.0.1: - resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} - value-equal@1.0.1: resolution: {integrity: sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==} @@ -7713,10 +7664,6 @@ packages: resolution: {integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==} engines: {node: '>= 6'} - yn@3.1.1: - resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} - engines: {node: '>=6'} - yocto-queue@0.1.0: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} @@ -9502,10 +9449,6 @@ snapshots: '@colors/colors@1.5.0': optional: true - '@cspotcode/source-map-support@0.8.1': - dependencies: - '@jridgewell/trace-mapping': 0.3.9 - '@csstools/cascade-layer-name-parser@2.0.4(@csstools/css-parser-algorithms@3.0.4(@csstools/css-tokenizer@3.0.3))(@csstools/css-tokenizer@3.0.3)': dependencies: '@csstools/css-parser-algorithms': 3.0.4(@csstools/css-tokenizer@3.0.3) @@ -10930,11 +10873,6 @@ snapshots: '@jridgewell/resolve-uri': 3.1.0 '@jridgewell/sourcemap-codec': 1.4.14 - '@jridgewell/trace-mapping@0.3.9': - dependencies: - '@jridgewell/resolve-uri': 3.1.0 - '@jridgewell/sourcemap-codec': 1.4.14 - '@leichtgewicht/ip-codec@2.0.4': {} '@mdx-js/mdx@3.0.1': @@ -11195,14 +11133,6 @@ snapshots: '@trysound/sax@0.2.0': {} - '@tsconfig/node10@1.0.9': {} - - '@tsconfig/node12@1.0.11': {} - - '@tsconfig/node14@1.0.3': {} - - '@tsconfig/node16@1.0.3': {} - '@types/acorn@4.0.6': dependencies: '@types/estree': 1.0.6 @@ -11897,8 +11827,6 @@ snapshots: normalize-path: 3.0.0 picomatch: 2.3.1 - arg@4.1.3: {} - arg@5.0.2: {} argparse@1.0.10: @@ -12411,8 +12339,6 @@ snapshots: optionalDependencies: typescript: 5.9.2 - create-require@1.1.1: {} - cross-inspect@1.0.1: dependencies: tslib: 2.8.1 @@ -12830,8 +12756,6 @@ snapshots: dependencies: dequal: 2.0.3 - diff@4.0.2: {} - diff@5.2.0: {} dir-glob@3.0.1: @@ -14163,8 +14087,6 @@ snapshots: lz-string@1.5.0: {} - make-error@1.3.6: {} - markdown-extensions@2.0.0: {} markdown-table@2.0.0: @@ -16510,24 +16432,6 @@ snapshots: ts-dedent@2.2.0: {} - ts-node@10.9.2(@types/node@18.15.0)(typescript@5.9.2): - dependencies: - '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.9 - '@tsconfig/node12': 1.0.11 - '@tsconfig/node14': 1.0.3 - '@tsconfig/node16': 1.0.3 - '@types/node': 18.15.0 - acorn: 8.15.0 - acorn-walk: 8.2.0 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - typescript: 5.9.2 - v8-compile-cache-lib: 3.0.1 - yn: 3.1.1 - tslib@2.5.0: {} tslib@2.6.2: {} @@ -16726,8 +16630,6 @@ snapshots: kleur: 4.1.5 sade: 1.8.1 - v8-compile-cache-lib@3.0.1: {} - value-equal@1.0.1: {} value-or-promise@1.0.12: {} @@ -17020,8 +16922,6 @@ snapshots: yaml@1.10.2: {} - yn@3.1.1: {} - yocto-queue@0.1.0: {} yocto-queue@1.0.0: {} diff --git a/scripts/buildConfigTypes.ts b/scripts/buildConfigTypes.ts index 40e6c925..38695f41 100644 --- a/scripts/buildConfigTypes.ts +++ b/scripts/buildConfigTypes.ts @@ -1,8 +1,12 @@ import * as fs from "fs"; import * as path from "path"; +import { fileURLToPath } from "url"; import { makeTypeScriptType } from "../src/gratsConfig.js"; import { GratsConfigSpec } from "../src/configSpec.js"; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + export function writeTypeScriptTypeToDisk(): void { const doc = `/** * This file is generated by src/gratsConfigBeta.ts. Do not edit directly. diff --git a/src/cli.ts b/src/cli.ts index 8ea67b4a..6da10b2b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -12,9 +12,9 @@ import { extractSchemaAndDoc, } from "./lib.js"; import { Command } from "commander"; -import { writeFileSync } from "fs"; +import { writeFileSync, readFileSync } from "fs"; import { resolve, dirname } from "path"; -import { version } from "../package.json"; +import { fileURLToPath } from "url"; import { locate } from "./Locate.js"; import { printGratsSDL, @@ -35,6 +35,27 @@ import { withFixesFixed, FixOptions, applyFixes } from "./fixFixable.js"; type BuildOptions = FixOptions; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const version = readPackageVersion(); + +function readPackageVersion(): string { + // Works from both source (src/cli.ts → ../package.json) + // and compiled output (dist/src/cli.js → ../../package.json) + for (const relPath of ["../package.json", "../../package.json"]) { + try { + const pkg = JSON.parse(readFileSync(resolve(__dirname, relPath), "utf8")); + if (pkg.name === "grats") return pkg.version; + } catch { + // Ignore missing/unreadable package.json files + } + } + console.error( + "Grats: Could not determine package version. Please report this issue at https://github.com/captbaritone/grats/issues", + ); + return "unknown"; +} + const program = new Command(); program diff --git a/src/configSpec.ts b/src/configSpec.ts index b91bb6d4..25ca04f8 100644 --- a/src/configSpec.ts +++ b/src/configSpec.ts @@ -1,5 +1,5 @@ -import * as _GratsConfigSpec from "./configSpecRaw.json"; import { ConfigSpec } from "./gratsConfig.js"; +import _GratsConfigSpec from "./configSpecRaw.json" with { type: "json" }; // TypeScript does not preserve string literal types when importing JSON. export const GratsConfigSpec: ConfigSpec = _GratsConfigSpec as any; diff --git a/src/gratsRoot.ts b/src/gratsRoot.ts index 3e5b00db..92d6dc2c 100644 --- a/src/gratsRoot.ts +++ b/src/gratsRoot.ts @@ -1,4 +1,5 @@ -import { relative, resolve, join } from "path"; +import { relative, resolve, join, dirname } from "path"; +import { fileURLToPath } from "url"; // Grats parses TypeScript files and finds resolvers. If the field resolver is a // named export, Grats needs to be able to import that file during execution. @@ -7,7 +8,15 @@ import { relative, resolve, join } from "path"; // the path to the module that contains the resolver. In order to allow those // paths to be relative, they must be relative to something that both the build // step and the runtime can agree on. This path is that thing. -const gratsRoot = join(__dirname, "../.."); + +// This file lives at src/gratsRoot.ts (source) or dist/src/gratsRoot.js +// (compiled). In both cases, going up two levels reaches the project root. +// In the browser (webpack playground), fileURLToPath may not be available +// since the `url` module is stubbed out via webpack fallback. +const gratsRoot = + typeof fileURLToPath === "function" + ? join(dirname(fileURLToPath(import.meta.url)), "../..") + : "."; export function relativePath(absolute: string): string { return relative(gratsRoot, absolute); diff --git a/src/tests/test.ts b/src/tests/test.ts index b72927a8..491540f3 100644 --- a/src/tests/test.ts +++ b/src/tests/test.ts @@ -1,4 +1,5 @@ import * as path from "path"; +import { fileURLToPath } from "url"; import TestRunner, { Transformer, TransformerResult } from "./TestRunner.js"; import { buildSchemaAndDocResult, @@ -76,6 +77,9 @@ program } }); +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + const gratsDir = path.join(__dirname, "../.."); const fixturesDir = path.join(__dirname, "fixtures"); const configFixturesDir = path.join(__dirname, "configParserFixtures"); diff --git a/src/tsPlugin/initTsPlugin.ts b/src/tsPlugin/initTsPlugin.ts index 3bfedab5..a1dc2de5 100644 --- a/src/tsPlugin/initTsPlugin.ts +++ b/src/tsPlugin/initTsPlugin.ts @@ -1,5 +1,5 @@ import { version as gratsTsVersion } from "typescript"; -import type * as TS from "typescript/lib/tsserverlibrary"; +import type * as TS from "typescript"; import { extract } from "../Extractor.js"; import { FAKE_ERROR_CODE } from "../utils/DiagnosticError.js"; import { nullThrows } from "../utils/helpers.js"; diff --git a/website/babel.config.js b/website/babel.config.js index bfd75dbd..38576b7f 100644 --- a/website/babel.config.js +++ b/website/babel.config.js @@ -1,3 +1,9 @@ module.exports = { presets: [require.resolve("@docusaurus/core/lib/babel/preset")], + plugins: [ + [ + require.resolve("@babel/plugin-syntax-import-attributes"), + { deprecatedAssertSyntax: true }, + ], + ], }; diff --git a/website/package.json b/website/package.json index 04869f86..4a813f71 100644 --- a/website/package.json +++ b/website/package.json @@ -12,7 +12,7 @@ "write-translations": "docusaurus write-translations", "write-heading-ids": "docusaurus write-heading-ids", "typecheck": "tsc", - "grats": "ts-node ./scripts/gratsCode.ts", + "grats": "tsx ./scripts/gratsCode.ts", "word-count": "find . -type f \\( -name \\*.md -o -name \\*.mdx \\) -exec wc -w {} + | awk '{total += $1} END {print total}'" }, "dependencies": { @@ -53,7 +53,7 @@ "cheerio": "^1.2.0", "graphql-relay": "^0.10.0", "monaco-editor-webpack-plugin": "^7.1.0", - "ts-node": "^10.9.2", + "tsx": "^4.19.2", "typescript": "5.9.2" }, "browserslist": { diff --git a/website/plugins/webpack.js b/website/plugins/webpack.js index e3f4c6a5..b14f2f62 100644 --- a/website/plugins/webpack.js +++ b/website/plugins/webpack.js @@ -8,6 +8,8 @@ module.exports = function (_context, _options) { resolve: { fallback: { path: require.resolve("path-browserify"), + url: false, + fs: false, }, // Map .js extensions to .ts for ESM-style imports in TypeScript source extensionAlias: {