From 85ecc7af871fd1d46a27a863a64b6be89b47de22 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 24 May 2024 12:20:28 +0200 Subject: [PATCH 01/13] annotate files with known used exports --- src/execution/execute.ts | 11 +++++++++++ src/execution/values.ts | 6 ++++++ src/jsutils/Maybe.ts | 4 ++++ src/jsutils/ObjMap.ts | 6 ++++++ src/jsutils/PromiseOrValue.ts | 4 ++++ src/language/ast.ts | 7 +++++++ src/language/lexer.ts | 7 +++++++ src/language/parser.ts | 7 +++++++ src/type/schema.ts | 7 +++++++ src/validation/ValidationContext.ts | 10 ++++++++++ src/validation/specifiedRules.ts | 7 +++++++ src/validation/validate.ts | 9 +++++++++ 12 files changed, 85 insertions(+) diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 55c22ea9de..7e16b9c900 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -1,3 +1,14 @@ +/** + * Quoted as "used by external libraries". + * Missing exports from `graphql`: + * * ExecutionContext + * * assertValidExecutionArguments @internal + * * buildExecutionContext @internal + * * buildResolveInfo @internal + * * getFieldDef @internal + * Should we still expose this file? + */ + import { devAssert } from '../jsutils/devAssert'; import { inspect } from '../jsutils/inspect'; import { invariant } from '../jsutils/invariant'; diff --git a/src/execution/values.ts b/src/execution/values.ts index d65ea9cf20..c883707007 100644 --- a/src/execution/values.ts +++ b/src/execution/values.ts @@ -1,3 +1,9 @@ +/** + * Quoted as "used by external libraries". + * Missing exports from `graphql`: none + * Should we still expose this file? + */ + import { inspect } from '../jsutils/inspect'; import { keyMap } from '../jsutils/keyMap'; import type { Maybe } from '../jsutils/Maybe'; diff --git a/src/jsutils/Maybe.ts b/src/jsutils/Maybe.ts index 0ba64a4b64..48b7fd9657 100644 --- a/src/jsutils/Maybe.ts +++ b/src/jsutils/Maybe.ts @@ -1,2 +1,6 @@ +/** + * Quoted as "used by external libraries". + * Should we still expose these? + */ /** Conveniently represents flow's "Maybe" type https://flow.org/en/docs/types/maybe/ */ export type Maybe = null | undefined | T; diff --git a/src/jsutils/ObjMap.ts b/src/jsutils/ObjMap.ts index 2c20282187..34c3023657 100644 --- a/src/jsutils/ObjMap.ts +++ b/src/jsutils/ObjMap.ts @@ -1,3 +1,9 @@ +/** + * Quoted as "used by external libraries". + * All of these could be replaced by Record or Readonly> + * Should we still expose these? + */ + export interface ObjMap { [key: string]: T; } diff --git a/src/jsutils/PromiseOrValue.ts b/src/jsutils/PromiseOrValue.ts index 6b2517ee62..edf86834da 100644 --- a/src/jsutils/PromiseOrValue.ts +++ b/src/jsutils/PromiseOrValue.ts @@ -1 +1,5 @@ +/** + * Quoted as "used by external libraries". + * Should we still expose these? + */ export type PromiseOrValue = Promise | T; diff --git a/src/language/ast.ts b/src/language/ast.ts index 29029342a1..0081ecb9d8 100644 --- a/src/language/ast.ts +++ b/src/language/ast.ts @@ -1,3 +1,10 @@ +/** + * Quoted as "used by external libraries". + * Missing exports from `graphql`: + * * isNode @internal + * * QueryDocumentKeys @internal + * Should we still expose this file? + */ import type { Kind } from './kinds'; import type { Source } from './source'; import type { TokenKind } from './tokenKind'; diff --git a/src/language/lexer.ts b/src/language/lexer.ts index 818f81b286..c77ddd6ee0 100644 --- a/src/language/lexer.ts +++ b/src/language/lexer.ts @@ -1,3 +1,10 @@ +/** + * Quoted as "used by external libraries". + * Missing exports from `graphql`: + * * isPunctuatorTokenKind @internal + * Should we still expose this file? + */ + import { syntaxError } from '../error/syntaxError'; import { Token } from './ast'; diff --git a/src/language/parser.ts b/src/language/parser.ts index eb54a0376b..288512bedd 100644 --- a/src/language/parser.ts +++ b/src/language/parser.ts @@ -1,3 +1,10 @@ +/** + * Quoted as "used by external libraries". + * Missing exports from `graphql`: + * * Parser @internal + * Should we still expose this file? + */ + import type { Maybe } from '../jsutils/Maybe'; import type { GraphQLError } from '../error/GraphQLError'; diff --git a/src/type/schema.ts b/src/type/schema.ts index 97c2782145..2aede3953b 100644 --- a/src/type/schema.ts +++ b/src/type/schema.ts @@ -1,3 +1,10 @@ +/** + * Quoted as "used by external libraries". + * Missing exports from `graphql`: + * * GraphQLSchemaNormalizedConfig @internal + * * GraphQLSchemaValidationOptions + * Should we still expose this file? + */ import { devAssert } from '../jsutils/devAssert'; import { inspect } from '../jsutils/inspect'; import { instanceOf } from '../jsutils/instanceOf'; diff --git a/src/validation/ValidationContext.ts b/src/validation/ValidationContext.ts index f6944a6ebd..f5fa8f7bd0 100644 --- a/src/validation/ValidationContext.ts +++ b/src/validation/ValidationContext.ts @@ -1,3 +1,13 @@ +/** + * Quoted as "used by external libraries". + * Missing exports from `graphql`: + * * ASTValidationContext + * * ASTValidationRule + * * SDLValidationContext + * * SDLValidationRule + * Should we still expose this file? + */ + import type { Maybe } from '../jsutils/Maybe'; import type { ObjMap } from '../jsutils/ObjMap'; diff --git a/src/validation/specifiedRules.ts b/src/validation/specifiedRules.ts index 16e555db8a..b46b93b837 100644 --- a/src/validation/specifiedRules.ts +++ b/src/validation/specifiedRules.ts @@ -1,3 +1,10 @@ +/** + * Quoted as "used by external libraries". + * Missing exports from `graphql`: + * * specifiedSDLRules @internal + * Should we still expose this file? + */ + // Spec Section: "Executable Definitions" import { ExecutableDefinitionsRule } from './rules/ExecutableDefinitionsRule'; // Spec Section: "Field Selections on Objects, Interfaces, and Unions Types" diff --git a/src/validation/validate.ts b/src/validation/validate.ts index 7259874240..7d27b40866 100644 --- a/src/validation/validate.ts +++ b/src/validation/validate.ts @@ -1,3 +1,12 @@ +/** + * Quoted as "used by external libraries". + * Missing exports from `graphql`: + * * assertValidSDL @internal + * * assertValidSDLExtension @internal + * * validateSDL @internal + * Should we still expose this file? + */ + import { devAssert } from '../jsutils/devAssert'; import type { Maybe } from '../jsutils/Maybe'; From 9646d84a804bdf7ad6c54dd08990ff926f8fb471 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 24 May 2024 15:53:40 +0200 Subject: [PATCH 02/13] generate `.js.mjs` and `.js.d.mts` files --- resources/build-npm.js | 145 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/resources/build-npm.js b/resources/build-npm.js index 7ff0cf079c..e124ea35ed 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -13,6 +13,14 @@ const { showDirStats, } = require('./utils.js'); +const entryPoints = [ + 'index.ts', + 'execution/execute.ts', + 'jsutils/instanceOf.ts', + 'language/parser.ts', + 'language/ast.ts', +]; + if (require.main === module) { fs.rmSync('./npmDist', { recursive: true, force: true }); fs.mkdirSync('./npmDist'); @@ -57,11 +65,21 @@ if (require.main === module) { const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost); const tsResult = tsProgram.emit(); + assert( !tsResult.emitSkipped, 'Fail to generate `*.d.ts` files, please run `npm run check`', ); + for (const [filename, contents] of Object.entries( + buildCjsEsmWrapper( + entryPoints.map((e) => './src/' + e), + tsProgram, + ), + )) { + writeGeneratedFile(filename, contents); + } + assert(packageJSON.types === undefined, 'Unexpected "types" in package.json'); const supportedTSVersions = Object.keys(packageJSON.typesVersions); assert( @@ -137,3 +155,130 @@ function buildPackageJSON() { return packageJSON; } + +/** + * + * @param {string[]} files + * @param {ts.Program} tsProgram + * @returns + */ +function buildCjsEsmWrapper(files, tsProgram) { + /** + * @type {Record} inputFiles + */ + const inputFiles = {}; + for (const file of files) { + const sourceFile = tsProgram.getSourceFile(file); + assert(sourceFile, `No source file found for ${file}`); + + const generatedFileName = path.relative( + path.dirname(tsProgram.getRootFileNames()[0]), + file.replace(/\.ts$/, '.js.mts'), + ); + const exportFrom = ts.factory.createStringLiteral( + './' + path.basename(file, '.ts') + '.js', + ); + + /** + * @type {ts.Statement[]} + */ + const statements = []; + + /** @type {string[]} */ + const exports = []; + + /** @type {string[]} */ + const typeExports = []; + + sourceFile.forEachChild((node) => { + if (ts.isExportDeclaration(node)) { + if (node.exportClause && ts.isNamedExports(node.exportClause)) { + for (const element of node.exportClause.elements) { + if (node.isTypeOnly || element.isTypeOnly) { + typeExports.push(element.name.text); + } else { + exports.push(element.name.text); + } + } + } + } else if ( + node.modifiers?.some( + (modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword, + ) + ) { + if (ts.isVariableStatement(node)) { + for (const declaration of node.declarationList.declarations) { + if (declaration.name && ts.isIdentifier(declaration.name)) { + exports.push(declaration.name.text); + } + } + } else if ( + ts.isFunctionDeclaration(node) || + ts.isClassDeclaration(node) + ) { + exports.push(node.name.text); + } else if (ts.isTypeAliasDeclaration(node)) { + typeExports.push(node.name.text); + } + } + }); + if (exports.length > 0) { + statements.push( + ts.factory.createExportDeclaration( + undefined, + undefined, + false, + ts.factory.createNamedExports( + exports.map((name) => + ts.factory.createExportSpecifier(false, undefined, name), + ), + ), + exportFrom, + ), + ); + } + if (typeExports.length > 0) { + statements.push( + ts.factory.createExportDeclaration( + undefined, + undefined, + true, + ts.factory.createNamedExports( + typeExports.map((name) => + ts.factory.createExportSpecifier(false, undefined, name), + ), + ), + exportFrom, + ), + ); + } + const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); + inputFiles[generatedFileName] = printer.printFile( + ts.factory.createSourceFile( + statements, + ts.factory.createToken(ts.SyntaxKind.EndOfFileToken), + ts.NodeFlags.None, + ), + ); + } + /** + * @type {ts.CompilerOptions} options + */ + const options = { + ...tsProgram.getCompilerOptions(), + declaration: true, + emitDeclarationOnly: false, + isolatedModules: true, + module: ts.ModuleKind.ESNext, + }; + options.outDir = options.declarationDir; + const results = {}; + const host = ts.createCompilerHost(options); + host.writeFile = (fileName, contents) => (results[fileName] = contents); + host.readFile = (fileName) => inputFiles[fileName]; + + const program = ts.createProgram(Object.keys(inputFiles), options, host); + program.emit(); + + return results; +} From 16fa5d5b00cb2b444241d0f2d5b0ce8687662232 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Fri, 24 May 2024 16:08:05 +0200 Subject: [PATCH 03/13] adjust `package.json` --- package.json | 49 +++++++++++++++++++++++++++++++++++++++++- resources/build-npm.js | 2 ++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f3466e2735..13088ad7d7 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,55 @@ "description": "A Query Language and Runtime which can target any service.", "license": "MIT", "private": true, - "main": "index", + "main": "index.js", "module": "index.mjs", + "exports": { + ".": { + "types": { + "import": "./index.js.d.mts", + "default": "./index.d.ts" + }, + "module": "./index.mjs", + "import": "./index.js.mjs", + "default": "./index.js" + }, + "./execution/execute.js": { + "types": { + "import": "./execution/execute.js.d.mts", + "default": "./execution/execute.d.ts" + }, + "module": "./execution/execute.mjs", + "import": "./execution/execute.js.mjs", + "default": "./execution/execute.js" + }, + "./jsutils/instanceOf.js": { + "types": { + "import": "./jsutils/instanceOf.js.d.mts", + "default": "./jsutils/instanceOf.d.ts" + }, + "module": "./jsutils/instanceOf.mjs", + "import": "./jsutils/instanceOf.js.mjs", + "default": "./jsutils/instanceOf.js" + }, + "./language/parser.js": { + "types": { + "import": "./language/parser.js.d.mts", + "default": "./language/parser.d.ts" + }, + "module": "./language/parser.mjs", + "import": "./language/parser.js.mjs", + "default": "./language/parser.js" + }, + "./language/ast.js": { + "types": { + "import": "./language/ast.js.d.mts", + "default": "./language/ast.d.ts" + }, + "module": "./language/ast.mjs", + "import": "./language/ast.js.mjs", + "default": "./language/ast.js" + } + }, "typesVersions": { ">=4.1.0": { "*": [ diff --git a/resources/build-npm.js b/resources/build-npm.js index e124ea35ed..d97c12a664 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -125,6 +125,8 @@ function buildPackageJSON() { delete packageJSON.scripts; delete packageJSON.devDependencies; + packageJSON.type = 'commonjs'; + // TODO: move to integration tests const publishTag = packageJSON.publishConfig?.tag; assert(publishTag != null, 'Should have packageJSON.publishConfig defined!'); From 2fa37dc76021c6871382a4377b905c6e81db6fc9 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 27 May 2024 14:59:47 +0200 Subject: [PATCH 04/13] add entry point for each folder, generate exports --- package.json | 9 --------- resources/build-npm.js | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 13088ad7d7..bdcf847f72 100644 --- a/package.json +++ b/package.json @@ -7,15 +7,6 @@ "main": "index.js", "module": "index.mjs", "exports": { - ".": { - "types": { - "import": "./index.js.d.mts", - "default": "./index.d.ts" - }, - "module": "./index.mjs", - "import": "./index.js.mjs", - "default": "./index.js" - }, "./execution/execute.js": { "types": { "import": "./execution/execute.js.d.mts", diff --git a/resources/build-npm.js b/resources/build-npm.js index d97c12a664..6bf175a565 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -13,13 +13,17 @@ const { showDirStats, } = require('./utils.js'); -const entryPoints = [ - 'index.ts', - 'execution/execute.ts', - 'jsutils/instanceOf.ts', - 'language/parser.ts', - 'language/ast.ts', -]; +const entryPoints = fs + .readdirSync('./src', { recursive: true }) + .filter((f) => f.endsWith('index.ts')) + .map((f) => f.replace(/^src/, '')) + .reverse() + .concat([ + 'execution/execute.ts', + 'jsutils/instanceOf.ts', + 'language/parser.ts', + 'language/ast.ts', + ]); if (require.main === module) { fs.rmSync('./npmDist', { recursive: true, force: true }); @@ -127,6 +131,27 @@ function buildPackageJSON() { packageJSON.type = 'commonjs'; + for (const entryPoint of entryPoints) { + if (!entryPoint.endsWith('index.ts')) { + continue; + } + const base = ('./' + path.dirname(entryPoint)).replace(/\/.?$/, ''); + const generated = {}; + generated[base] = { + types: { + import: base + '/index.js.d.mts', + default: base + '/index.d.ts', + }, + module: base + '/index.mjs', + import: base + '/index.js.mjs', + default: base + '/index.js', + }; + packageJSON.exports = { + ...generated, + ...packageJSON.exports, + }; + } + // TODO: move to integration tests const publishTag = packageJSON.publishConfig?.tag; assert(publishTag != null, 'Should have packageJSON.publishConfig defined!'); From 881b1bfd0655cf70d801c89c718e4a2e6af4a454 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 27 May 2024 15:29:45 +0200 Subject: [PATCH 05/13] flip order of module/import --- package.json | 8 ++++---- resources/build-npm.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index bdcf847f72..7c449223cf 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "import": "./execution/execute.js.d.mts", "default": "./execution/execute.d.ts" }, - "module": "./execution/execute.mjs", "import": "./execution/execute.js.mjs", + "module": "./execution/execute.mjs", "default": "./execution/execute.js" }, "./jsutils/instanceOf.js": { @@ -21,8 +21,8 @@ "import": "./jsutils/instanceOf.js.d.mts", "default": "./jsutils/instanceOf.d.ts" }, - "module": "./jsutils/instanceOf.mjs", "import": "./jsutils/instanceOf.js.mjs", + "module": "./jsutils/instanceOf.mjs", "default": "./jsutils/instanceOf.js" }, "./language/parser.js": { @@ -30,8 +30,8 @@ "import": "./language/parser.js.d.mts", "default": "./language/parser.d.ts" }, - "module": "./language/parser.mjs", "import": "./language/parser.js.mjs", + "module": "./language/parser.mjs", "default": "./language/parser.js" }, "./language/ast.js": { @@ -39,8 +39,8 @@ "import": "./language/ast.js.d.mts", "default": "./language/ast.d.ts" }, - "module": "./language/ast.mjs", "import": "./language/ast.js.mjs", + "module": "./language/ast.mjs", "default": "./language/ast.js" } }, diff --git a/resources/build-npm.js b/resources/build-npm.js index 6bf175a565..a6427811aa 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -142,8 +142,8 @@ function buildPackageJSON() { import: base + '/index.js.d.mts', default: base + '/index.d.ts', }, - module: base + '/index.mjs', import: base + '/index.js.mjs', + module: base + '/index.mjs', default: base + '/index.js', }; packageJSON.exports = { From 864015c4b389720113dad4324371a2688acbc550 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 27 May 2024 16:04:36 +0200 Subject: [PATCH 06/13] roll back, add vitest condition --- package.json | 24 ++++++++++++++++++++---- resources/build-npm.js | 17 ++++++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7c449223cf..f3af9af392 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,12 @@ "import": "./execution/execute.js.d.mts", "default": "./execution/execute.d.ts" }, - "import": "./execution/execute.js.mjs", + "vitest": { + "import": "./execution/execute.js.mjs", + "default": "./execution/execute.js" + }, "module": "./execution/execute.mjs", + "import": "./execution/execute.js.mjs", "default": "./execution/execute.js" }, "./jsutils/instanceOf.js": { @@ -21,8 +25,12 @@ "import": "./jsutils/instanceOf.js.d.mts", "default": "./jsutils/instanceOf.d.ts" }, - "import": "./jsutils/instanceOf.js.mjs", + "vitest": { + "import": "./jsutils/instanceOf.js.mjs", + "default": "./jsutils/instanceOf.js" + }, "module": "./jsutils/instanceOf.mjs", + "import": "./jsutils/instanceOf.js.mjs", "default": "./jsutils/instanceOf.js" }, "./language/parser.js": { @@ -30,8 +38,12 @@ "import": "./language/parser.js.d.mts", "default": "./language/parser.d.ts" }, - "import": "./language/parser.js.mjs", + "vitest": { + "import": "./language/parser.js.mjs", + "default": "./language/parser.js" + }, "module": "./language/parser.mjs", + "import": "./language/parser.js.mjs", "default": "./language/parser.js" }, "./language/ast.js": { @@ -39,8 +51,12 @@ "import": "./language/ast.js.d.mts", "default": "./language/ast.d.ts" }, - "import": "./language/ast.js.mjs", + "vitest": { + "import": "./language/ast.js.mjs", + "default": "./language/ast.js" + }, "module": "./language/ast.mjs", + "import": "./language/ast.js.mjs", "default": "./language/ast.js" } }, diff --git a/resources/build-npm.js b/resources/build-npm.js index a6427811aa..102c90e7be 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -142,8 +142,23 @@ function buildPackageJSON() { import: base + '/index.js.d.mts', default: base + '/index.d.ts', }, - import: base + '/index.js.mjs', + /* + this is not automatically picked up by vitest, but we can instruct users to add it to their vitest config: + ```js title="vite.config.ts" + import { defineConfig } from 'vite'; + export default defineConfig(async ({ mode }) => { + return { + resolve: mode === 'test' ? { conditions: ['vitest'] } : undefined, + }; + }); + ``` + */ + vitest: { + import: base + '/index.js.mjs', + default: base + '/index.js', + }, module: base + '/index.mjs', + import: base + '/index.js.mjs', default: base + '/index.js', }; packageJSON.exports = { From f93c7bf6979b14fd33fa6cced6d4f62ffec3d85b Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 28 May 2024 14:07:55 +0200 Subject: [PATCH 07/13] add package.json to exports field --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index f3af9af392..7a5b4452b8 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "main": "index.js", "module": "index.mjs", "exports": { + "./package.json": "./package.json", "./execution/execute.js": { "types": { "import": "./execution/execute.js.d.mts", From 011ce2c5b67e7ea9f9f5d7c0c2f3d1c8e4e4d21c Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 28 May 2024 14:18:53 +0200 Subject: [PATCH 08/13] bump integration test ts versions --- integrationTests/ts/package.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/integrationTests/ts/package.json b/integrationTests/ts/package.json index 413e1aec05..2322c18ce5 100644 --- a/integrationTests/ts/package.json +++ b/integrationTests/ts/package.json @@ -6,11 +6,18 @@ }, "dependencies": { "graphql": "file:../graphql.tgz", - "typescript-4.1": "npm:typescript@4.1.x", "typescript-4.2": "npm:typescript@4.2.x", "typescript-4.3": "npm:typescript@4.3.x", "typescript-4.4": "npm:typescript@4.4.x", "typescript-4.5": "npm:typescript@4.5.x", - "typescript-4.6": "npm:typescript@4.6.x" + "typescript-4.6": "npm:typescript@4.6.x", + "typescript-4.7": "npm:typescript@4.7.x", + "typescript-4.8": "npm:typescript@4.8.x", + "typescript-4.9": "npm:typescript@4.9.x", + "typescript-5.0": "npm:typescript@5.0.x", + "typescript-5.1": "npm:typescript@5.1.x", + "typescript-5.2": "npm:typescript@5.2.x", + "typescript-5.3": "npm:typescript@5.3.x", + "typescript-5.4": "npm:typescript@5.4.x" } } From f86e6d0dab1cf32ad9f49820dec0e19b5106e721 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 28 May 2024 14:52:29 +0200 Subject: [PATCH 09/13] adjust linter warnings --- src/jsutils/ObjMap.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jsutils/ObjMap.ts b/src/jsutils/ObjMap.ts index 34c3023657..8413127dd8 100644 --- a/src/jsutils/ObjMap.ts +++ b/src/jsutils/ObjMap.ts @@ -1,6 +1,6 @@ /** * Quoted as "used by external libraries". - * All of these could be replaced by Record or Readonly> + * All of these could be replaced by Record\ or Readonly\\> * Should we still expose these? */ From 73adce64a4038748fc05e42d94de1c6f0892882b Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 29 Jul 2024 15:32:15 +0200 Subject: [PATCH 10/13] rename `vitest` condition to `'dual-module-hazard-workaround'` --- resources/build-npm.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/build-npm.js b/resources/build-npm.js index 102c90e7be..7efe39402e 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -148,12 +148,12 @@ function buildPackageJSON() { import { defineConfig } from 'vite'; export default defineConfig(async ({ mode }) => { return { - resolve: mode === 'test' ? { conditions: ['vitest'] } : undefined, + resolve: mode === 'test' ? { conditions: ['dual-module-hazard-workaround'] } : undefined, }; }); ``` */ - vitest: { + 'dual-module-hazard-workaround': { import: base + '/index.js.mjs', default: base + '/index.js', }, From 44516d2e6762a6eccbd57af6596c68c9758efbb6 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 29 Jul 2024 15:32:45 +0200 Subject: [PATCH 11/13] apply definitelyTyped TS support --- integrationTests/ts/package.json | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/integrationTests/ts/package.json b/integrationTests/ts/package.json index 2322c18ce5..f66128edd3 100644 --- a/integrationTests/ts/package.json +++ b/integrationTests/ts/package.json @@ -6,18 +6,13 @@ }, "dependencies": { "graphql": "file:../graphql.tgz", - "typescript-4.2": "npm:typescript@4.2.x", - "typescript-4.3": "npm:typescript@4.3.x", - "typescript-4.4": "npm:typescript@4.4.x", - "typescript-4.5": "npm:typescript@4.5.x", - "typescript-4.6": "npm:typescript@4.6.x", - "typescript-4.7": "npm:typescript@4.7.x", "typescript-4.8": "npm:typescript@4.8.x", "typescript-4.9": "npm:typescript@4.9.x", "typescript-5.0": "npm:typescript@5.0.x", "typescript-5.1": "npm:typescript@5.1.x", "typescript-5.2": "npm:typescript@5.2.x", "typescript-5.3": "npm:typescript@5.3.x", - "typescript-5.4": "npm:typescript@5.4.x" + "typescript-5.4": "npm:typescript@5.4.x", + "typescript-5.5": "npm:typescript@5.5.x" } } From bea8025b387395815b72eb2c5011b132149e9ffd Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 29 Jul 2024 16:01:31 +0200 Subject: [PATCH 12/13] vitest is a valid word, so is vite --- cspell.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cspell.yml b/cspell.yml index 8770a4d781..e4656139c1 100644 --- a/cspell.yml +++ b/cspell.yml @@ -29,6 +29,8 @@ words: - graphiql - sublinks - instanceof + - vitest + - vite # Different names used inside tests - Skywalker From 3f74ec5c9a555ff7d6bb996512d3a20c67d30917 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 29 Jul 2024 16:03:43 +0200 Subject: [PATCH 13/13] generate all entrypoints --- package.json | 54 +----------------------------------------- resources/build-npm.js | 20 +++++++--------- 2 files changed, 10 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index 7a5b4452b8..a41a3f0f07 100644 --- a/package.json +++ b/package.json @@ -7,59 +7,7 @@ "main": "index.js", "module": "index.mjs", "exports": { - "./package.json": "./package.json", - "./execution/execute.js": { - "types": { - "import": "./execution/execute.js.d.mts", - "default": "./execution/execute.d.ts" - }, - "vitest": { - "import": "./execution/execute.js.mjs", - "default": "./execution/execute.js" - }, - "module": "./execution/execute.mjs", - "import": "./execution/execute.js.mjs", - "default": "./execution/execute.js" - }, - "./jsutils/instanceOf.js": { - "types": { - "import": "./jsutils/instanceOf.js.d.mts", - "default": "./jsutils/instanceOf.d.ts" - }, - "vitest": { - "import": "./jsutils/instanceOf.js.mjs", - "default": "./jsutils/instanceOf.js" - }, - "module": "./jsutils/instanceOf.mjs", - "import": "./jsutils/instanceOf.js.mjs", - "default": "./jsutils/instanceOf.js" - }, - "./language/parser.js": { - "types": { - "import": "./language/parser.js.d.mts", - "default": "./language/parser.d.ts" - }, - "vitest": { - "import": "./language/parser.js.mjs", - "default": "./language/parser.js" - }, - "module": "./language/parser.mjs", - "import": "./language/parser.js.mjs", - "default": "./language/parser.js" - }, - "./language/ast.js": { - "types": { - "import": "./language/ast.js.d.mts", - "default": "./language/ast.d.ts" - }, - "vitest": { - "import": "./language/ast.js.mjs", - "default": "./language/ast.js" - }, - "module": "./language/ast.mjs", - "import": "./language/ast.js.mjs", - "default": "./language/ast.js" - } + "./package.json": "./package.json" }, "typesVersions": { ">=4.1.0": { diff --git a/resources/build-npm.js b/resources/build-npm.js index 7efe39402e..9081bda5ee 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -132,15 +132,13 @@ function buildPackageJSON() { packageJSON.type = 'commonjs'; for (const entryPoint of entryPoints) { - if (!entryPoint.endsWith('index.ts')) { - continue; - } const base = ('./' + path.dirname(entryPoint)).replace(/\/.?$/, ''); + const filename = path.basename(entryPoint, '.ts'); const generated = {}; - generated[base] = { + generated[filename === 'index' ? base : `${base}/${filename}.js`] = { types: { - import: base + '/index.js.d.mts', - default: base + '/index.d.ts', + import: `${base}/${filename}.js.d.mts`, + default: `${base}/${filename}.d.ts`, }, /* this is not automatically picked up by vitest, but we can instruct users to add it to their vitest config: @@ -154,12 +152,12 @@ function buildPackageJSON() { ``` */ 'dual-module-hazard-workaround': { - import: base + '/index.js.mjs', - default: base + '/index.js', + import: `${base}/${filename}.js.mjs`, + default: `${base}/${filename}.js`, }, - module: base + '/index.mjs', - import: base + '/index.js.mjs', - default: base + '/index.js', + module: `${base}/${filename}.mjs`, + import: `${base}/${filename}.js.mjs`, + default: `${base}/${filename}.js`, }; packageJSON.exports = { ...generated,