Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Node16 resolution #186

Merged
merged 21 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"corepack",
"printables",
"arethetypeswrong",
"oneof",
"typesafe"
],
"ignorePaths": ["**/*.svg", "**/*.ai", "**/pnpm-lock.yaml", "*.excalidraw"]
Expand Down
2 changes: 1 addition & 1 deletion jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
},
workerThreads: true, // Enabled so jest would stop complaining about serializing BigInt. See https://github.com/jestjs/jest/issues/11617#issuecomment-1458155552 for details
transform: {
"^.+\\.(ts|tsx)$": [
"^.+\\.(ts|tsx|js)$": [
"ts-jest",
{
isolatedModules: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"scripts": {
"clean": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm && npm run build:proxy",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --moduleResolution node --verbatimModuleSyntax false --outDir ./dist/cjs --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
paul-sachs marked this conversation as resolved.
Show resolved Hide resolved
"build:esm": "tsc --project tsconfig.build.json",
"build:proxy": "node ../../scripts/gen-esm-proxy.mjs .",
"generate": "buf generate --path eliza.proto",
"test": "jest",
Expand Down
14 changes: 7 additions & 7 deletions packages/connect-query/src/call-unary-method.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import type { QueryFunctionContext } from "@tanstack/react-query";
import { useQueries } from "@tanstack/react-query";
import { renderHook, waitFor } from "@testing-library/react";

import { callUnaryMethod } from "./call-unary-method";
import type { ConnectQueryKey } from "./connect-query-key";
import { createConnectQueryKey } from "./connect-query-key";
import { defaultOptions } from "./default-options";
import { ElizaService } from "./gen/eliza_connect";
import type { SayRequest } from "./gen/eliza_pb";
import { mockEliza, wrapper } from "./jest/test-utils";
import { callUnaryMethod } from "./call-unary-method.js";
import type { ConnectQueryKey } from "./connect-query-key.js";
import { createConnectQueryKey } from "./connect-query-key.js";
import { defaultOptions } from "./default-options.js";
import { ElizaService } from "./gen/eliza_connect.js";
import type { SayRequest } from "./gen/eliza_pb.js";
import { mockEliza, wrapper } from "./jest/test-utils.js";

const sayMethodDescriptor = {
...ElizaService.methods.say,
Expand Down
6 changes: 3 additions & 3 deletions packages/connect-query/src/connect-query-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import { describe, expect, it } from "@jest/globals";

import { createConnectQueryKey } from "./connect-query-key";
import { SayRequest } from "./gen/eliza_pb";
import { disableQuery } from "./utils";
import { createConnectQueryKey } from "./connect-query-key.js";
import { SayRequest } from "./gen/eliza_pb.js";
import { disableQuery } from "./utils.js";

describe("makeQueryKey", () => {
const methodDescriptor = {
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-query/src/default-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { describe, expect, it } from "@jest/globals";

import { defaultOptions } from "./default-options";
import { defaultOptions } from "./default-options.js";

describe("defaultOptions", () => {
const {
Expand Down
3 changes: 2 additions & 1 deletion packages/connect-query/src/default-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
// limitations under the License.

import type { DefaultOptions } from "@tanstack/react-query";
import stableHash from "stable-hash";

import stableHash from "./stable-hash.js";

/**
* These default options are required for proper query key hashing.
Expand Down
12 changes: 8 additions & 4 deletions packages/connect-query/src/jest/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ import {
BigIntService,
ElizaService,
PaginatedService,
} from "../gen/eliza_connect";
import type { CountRequest, ListResponse, SayRequest } from "../gen/eliza_pb";
import { CountResponse, SayResponse } from "../gen/eliza_pb";
import { TransportProvider } from "../use-transport";
} from "../gen/eliza_connect.js";
import type {
CountRequest,
ListResponse,
SayRequest,
} from "../gen/eliza_pb.js";
import { CountResponse, SayResponse } from "../gen/eliza_pb.js";
import { TransportProvider } from "../use-transport.js";

/**
* A utils wrapper that supplies Tanstack Query's `QueryClientProvider` as well as Connect-Query's `TransportProvider`.
Expand Down
26 changes: 26 additions & 0 deletions packages/connect-query/src/stable-hash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021-2023 The Connect Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import stableHash from "stable-hash";

/**
* Convert stable-hash to a typed API. This is a necessary workaround because
* stable-hash does not export a type for its default export that is compatible
* with Node16 resolution.
paul-sachs marked this conversation as resolved.
Show resolved Hide resolved
*
* @type {(value: unknown) => string}
*/
const defaultStableHash = stableHash;

export default defaultStableHash;
12 changes: 6 additions & 6 deletions packages/connect-query/src/use-infinite-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
import { describe, expect, it } from "@jest/globals";
import { renderHook, waitFor } from "@testing-library/react";

import { createConnectQueryKey } from "./connect-query-key";
import { defaultOptions } from "./default-options";
import { PaginatedService } from "./gen/eliza_connect";
import { mockPaginatedTransport, wrapper } from "./jest/test-utils";
import { createConnectQueryKey } from "./connect-query-key.js";
import { defaultOptions } from "./default-options.js";
import { PaginatedService } from "./gen/eliza_connect.js";
import { mockPaginatedTransport, wrapper } from "./jest/test-utils.js";
import {
useInfiniteQuery,
useSuspenseInfiniteQuery,
} from "./use-infinite-query";
import { disableQuery } from "./utils";
} from "./use-infinite-query.js";
import { disableQuery } from "./utils.js";

// TODO: maybe create a helper to take a service and method and generate this.
const methodDescriptor = {
Expand Down
8 changes: 4 additions & 4 deletions packages/connect-query/src/use-mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import { describe, expect, it, jest } from "@jest/globals";
import { renderHook, waitFor } from "@testing-library/react";

import { defaultOptions } from "./default-options";
import { PaginatedService } from "./gen/eliza_connect";
import { mockPaginatedTransport, wrapper } from "./jest/test-utils";
import { useMutation } from "./use-mutation";
import { defaultOptions } from "./default-options.js";
import { PaginatedService } from "./gen/eliza_connect.js";
import { mockPaginatedTransport, wrapper } from "./jest/test-utils.js";
import { useMutation } from "./use-mutation.js";

// TODO: maybe create a helper to take a service and method and generate this.
const methodDescriptor = {
Expand Down
8 changes: 4 additions & 4 deletions packages/connect-query/src/use-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import { describe, expect, it } from "@jest/globals";
import { renderHook, waitFor } from "@testing-library/react";

import { ElizaService } from "./gen/eliza_connect";
import { mockEliza, wrapper } from "./jest/test-utils";
import { useQuery, useSuspenseQuery } from "./use-query";
import { disableQuery } from "./utils";
import { ElizaService } from "./gen/eliza_connect.js";
import { mockEliza, wrapper } from "./jest/test-utils.js";
import { useQuery, useSuspenseQuery } from "./use-query.js";
import { disableQuery } from "./utils.js";

// TODO: maybe create a helper to take a service and method and generate this.
const sayMethodDescriptor = {
Expand Down
8 changes: 4 additions & 4 deletions packages/connect-query/src/use-transport.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import { ConnectError } from "@connectrpc/connect";
import { describe, expect, it } from "@jest/globals";
import { renderHook, waitFor } from "@testing-library/react";

import { ElizaService } from "./gen/eliza_connect";
import { mockBigInt, wrapper } from "./jest/test-utils";
import { useQuery } from "./use-query";
import { ElizaService } from "./gen/eliza_connect.js";
import { mockBigInt, wrapper } from "./jest/test-utils.js";
import { useQuery } from "./use-query.js";
import {
fallbackTransport,
TransportProvider,
useTransport,
} from "./use-transport";
} from "./use-transport.js";

const sayMethodDescriptor = {
...ElizaService.methods.say,
Expand Down
12 changes: 8 additions & 4 deletions packages/connect-query/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
import type { PartialMessage } from "@bufbuild/protobuf";
import { describe, expect, it, jest } from "@jest/globals";

import { BigIntService } from "./gen/eliza_connect";
import type { CountResponse } from "./gen/eliza_pb";
import type { Equal, Expect } from "./jest/test-utils";
import { assert, createProtobufSafeUpdater, isAbortController } from "./utils";
import { BigIntService } from "./gen/eliza_connect.js";
import type { CountResponse } from "./gen/eliza_pb.js";
import type { Equal, Expect } from "./jest/test-utils.js";
import {
assert,
createProtobufSafeUpdater,
isAbortController,
} from "./utils.js";

describe("assert", () => {
const message = "assertion message";
Expand Down
6 changes: 5 additions & 1 deletion packages/connect-query/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"skipLibCheck": true
"skipLibCheck": true,
"verbatimModuleSyntax": true,
paul-sachs marked this conversation as resolved.
Show resolved Hide resolved
"declaration": true,
"declarationDir": "./dist/esm",
"outDir": "./dist/esm"
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["**/*.test.ts", "**/*.test.tsx", "src/jest/**"]
Expand Down
4 changes: 3 additions & 1 deletion packages/connect-query/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"compilerOptions": {
"rootDir": ".",
"noUnusedLocals": false, // necessary for TypeScript type tests, but since this is not enabled for build, unused variables have no risk of leaking into the build output
"lib": ["DOM", "ESNext"]
"lib": ["DOM", "ESNext"],
"noEmit": true,
"verbatimModuleSyntax": false
},
"exclude": ["coverage", "dist"],
"include": ["src", "./*.config.ts"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import { createEcmaScriptPlugin } from "@bufbuild/protoplugin";

import { version } from "../package.json";
import { generateDts } from "./generateDts";
import { generateTs } from "./generateTs";
import { generateDts } from "./generateDts.js";
import { generateTs } from "./generateTs.js";

export const protocGenConnectQuery = createEcmaScriptPlugin({
name: "protoc-gen-connect-query",
Expand Down
3 changes: 2 additions & 1 deletion packages/protoc-gen-connect-query/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"files": ["src/protoc-gen-connect-query-plugin.ts"],
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"moduleResolution": "Node16",
"module": "Node16",
"outDir": "dist/cjs",
"module": "CommonJS",
"resolveJsonModule": true
}
}
4 changes: 3 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"compilerOptions": {
"allowJs": true,
"target": "ESNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx",
"resolveJsonModule": true,
"module": "Node16",

"strict": true,
"exactOptionalPropertyTypes": true,
Expand All @@ -14,7 +16,7 @@
"noImplicitOverride": true,

// We need node's module resolution, so we do not have to skip lib checks
"moduleResolution": "Node",
"moduleResolution": "Node16",
paul-sachs marked this conversation as resolved.
Show resolved Hide resolved
"skipLibCheck": false,
"declaration": true,
"declarationMap": true,
Expand Down