Skip to content

Commit 600b5c1

Browse files
authored
internal: satisfy stricter deno type/package checks (#4623)
as performed by `deno publish --dry-run` enable tsconfig `isolatedDeclarations`, add a local `check:deno` step, and add a CI step for multiple versions to achieve conformity.
1 parent 53db0c3 commit 600b5c1

30 files changed

+470
-397
lines changed

.c8rc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"src/jsutils/Maybe.ts",
88
"src/jsutils/ObjMap.ts",
99
"src/jsutils/PromiseOrValue.ts",
10+
"src/language/KindTypeMap.ts",
1011
"src/utilities/typedQueryDocumentNode.ts",
1112
"src/**/__tests__/**/*.ts"
1213
],

.github/workflows/ci.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: npm run lint
2727

2828
- name: Check Types
29-
run: npm run check
29+
run: npm run check:ts
3030

3131
- name: Lint Prettier
3232
run: npm run prettier:check
@@ -244,7 +244,7 @@ jobs:
244244
name: denoDist
245245
path: ./denoDist
246246

247-
type-check-deno-dist:
247+
check-deno-dist:
248248
name: Type check denoDist on Deno v${{ matrix.deno_version_to_setup }}
249249
needs: build-deno-dist
250250
runs-on: ubuntu-latest
@@ -268,5 +268,12 @@ jobs:
268268
with:
269269
deno-version: ${{ matrix.deno_version_to_setup }}
270270

271-
- name: Check denoDist package
272-
run: deno check ./denoDist/index.ts
271+
- name: Run denoDist package publish dry-run checks
272+
# `deno publish --dry-run` performs a number of checks including:
273+
# (a) type-checking package modules/public API,
274+
# (b) validating exports and module-graph resolution,
275+
# (c) validating the publish file set (gitignore + publish.exclude/include),
276+
# (d) validating package metadata/config, and
277+
# (e) enforcing JSR slow-types checks.
278+
working-directory: ./denoDist
279+
run: deno publish --dry-run

.github/workflows/release.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,9 @@ jobs:
134134
runs-on: ubuntu-latest
135135
environment: release
136136
permissions:
137-
contents: read # for actions/checkout
137+
contents: read # for actions/download-artifact
138138
id-token: write # for JSR trusted publishing via OIDC
139139
steps:
140-
- name: Checkout repo
141-
uses: actions/checkout@v4
142-
with:
143-
persist-credentials: false
144-
145140
- name: Download denoDist package
146141
uses: actions/download-artifact@v4
147142
with:

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"benchmark": "node --import ./resources/register-ts-node.js resources/benchmark.ts",
3737
"test": "npm run lint && npm run check && npm run testonly:cover && npm run prettier:check && npm run check:spelling && npm run check:integrations",
3838
"lint": "eslint --cache --max-warnings 0 .",
39-
"check": "tsc --pretty",
39+
"check": "npm run check:ts && npm run check:deno",
40+
"check:ts": "tsc --pretty",
41+
"check:deno": "npm run build:deno && deno publish --dry-run --allow-dirty --config denoDist/jsr.json",
4042
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.ts",
4143
"testonly:cover": "c8 npm run testonly",
4244
"testonly:watch": "npm run testonly -- --watch",

resources/build-deno.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ interface JSRConfig {
9090
name: string;
9191
version: string;
9292
exports: { [entrypoint: string]: string };
93+
publish: {
94+
exclude: ReadonlyArray<string>;
95+
};
9396
}
9497

9598
async function writeJSRConfig(
@@ -122,6 +125,10 @@ async function writeJSRConfig(
122125
name: '@graphql/graphql-js',
123126
version,
124127
exports: jsrExports,
128+
publish: {
129+
// The package root is `denoDist/`, so unignore relative to that root.
130+
exclude: ['!.'],
131+
},
125132
};
126133

127134
const prettified = await prettify(jsrConfigPath, JSON.stringify(jsrConfig));

resources/change-extension-in-import-paths.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ import ts from 'typescript';
2121
* ```
2222
*
2323
*/
24-
export function changeExtensionInImportPaths(config: { extension: string }) {
24+
export function changeExtensionInImportPaths(config: {
25+
extension: string;
26+
}): ts.TransformerFactory<ts.SourceFile> {
2527
const { extension } = config;
26-
return (context: ts.TransformationContext) => {
28+
return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {
2729
const { factory } = context;
2830

2931
return visitSourceFile;
3032

31-
function visitSourceFile(sourceFile: ts.SourceFile) {
33+
function visitSourceFile(sourceFile: ts.SourceFile): ts.SourceFile {
3234
return ts.visitNode(sourceFile, visitNode, ts.isSourceFile);
3335
}
3436

resources/gen-version.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export const version = '${version}' as string;
2020
/**
2121
* An object containing the components of the GraphQL.js version string
2222
*/
23-
export const versionInfo = Object.freeze({
23+
export const versionInfo: Readonly<{
24+
major: number;
25+
minor: number;
26+
patch: number;
27+
preReleaseTag: string | null;
28+
}> = Object.freeze({
2429
major: ${major} as number,
2530
minor: ${minor} as number,
2631
patch: ${patch} as number,

resources/inline-invariant.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import ts from 'typescript';
1111
*
1212
* if (!(<cond>)) invariant(false, ...)
1313
*/
14-
export function inlineInvariant(context: ts.TransformationContext) {
14+
export function inlineInvariant(
15+
context: ts.TransformationContext,
16+
): ts.Transformer<ts.SourceFile> {
1517
const { factory } = context;
1618

1719
return visitSourceFile;
1820

19-
function visitSourceFile(sourceFile: ts.SourceFile) {
21+
function visitSourceFile(sourceFile: ts.SourceFile): ts.SourceFile {
2022
return ts.visitNode(sourceFile, visitNode, ts.isSourceFile);
2123
}
2224

src/__testUtils__/expectJSON.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,33 @@ function toJSONDeep(value: unknown): unknown {
2323
return mapValue(value, toJSONDeep);
2424
}
2525

26-
export function expectJSON(actual: unknown) {
26+
export function expectJSON(actual: unknown): {
27+
toDeepEqual: (expected: unknown) => ReturnType<typeof expect>;
28+
toDeepNestedProperty: (
29+
path: string,
30+
expected: unknown,
31+
) => ReturnType<typeof expect>;
32+
} {
2733
const actualJSON = toJSONDeep(actual);
2834

2935
return {
30-
toDeepEqual(expected: unknown) {
36+
toDeepEqual(expected: unknown): ReturnType<typeof expect> {
3137
const expectedJSON = toJSONDeep(expected);
32-
expect(actualJSON).to.deep.equal(expectedJSON);
38+
return expect(actualJSON).to.deep.equal(expectedJSON);
3339
},
34-
toDeepNestedProperty(path: string, expected: unknown) {
40+
toDeepNestedProperty(
41+
path: string,
42+
expected: unknown,
43+
): ReturnType<typeof expect> {
3544
const expectedJSON = toJSONDeep(expected);
36-
expect(actualJSON).to.deep.nested.property(path, expectedJSON);
45+
return expect(actualJSON).to.deep.nested.property(path, expectedJSON);
3746
},
3847
};
3948
}
4049

41-
export function expectToThrowJSON(fn: () => unknown) {
50+
export function expectToThrowJSON(
51+
fn: () => unknown,
52+
): ReturnType<typeof expect> {
4253
function mapException(): unknown {
4354
try {
4455
return fn();

src/__testUtils__/expectPromise.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ import { assert, expect } from 'chai';
33
import { inspect } from '../jsutils/inspect.js';
44
import { isPromise } from '../jsutils/isPromise.js';
55

6-
export function expectPromise(maybePromise: unknown) {
6+
interface PromiseExpectation {
7+
toResolve: () => Promise<unknown>;
8+
toRejectWith: (message: string) => Promise<void>;
9+
}
10+
11+
export function expectPromise(maybePromise: unknown): PromiseExpectation {
712
assert(
813
isPromise(maybePromise),
914
`Expected a promise, received '${inspect(maybePromise)}'`,
1015
);
1116

1217
return {
13-
toResolve() {
18+
toResolve(): Promise<unknown> {
1419
return maybePromise;
1520
},
16-
async toRejectWith(message: string) {
21+
async toRejectWith(message: string): Promise<void> {
1722
let caughtError: unknown;
1823
let resolved;
1924
let rejected = false;

0 commit comments

Comments
 (0)