Skip to content

Commit f585fb3

Browse files
authored
feat: typescript esm export map support (#930)
* feat: support TypeScript node module resolution * chore: add changeset * chore: use Node 16 in tests
1 parent 93239dc commit f585fb3

File tree

77 files changed

+1283
-568
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1283
-568
lines changed

.changeset/warm-moles-remember.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@n1ru4l/graphql-live-query": minor
3+
"@n1ru4l/graphql-live-query-patch": minor
4+
"@n1ru4l/graphql-live-query-patch-jsondiffpatch": minor
5+
"@n1ru4l/graphql-live-query-patch-json-patch": minor
6+
"@n1ru4l/in-memory-live-query-store": minor
7+
"@n1ru4l/json-patch-plus": minor
8+
"@n1ru4l/socket-io-graphql-client": minor
9+
"@n1ru4l/socket-io-graphql-server": minor
10+
---
11+
12+
Support TypeScript ESM module resolution. More information on https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js

.github/workflows/ci-todo-example.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ jobs:
1515
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
1616
fetch-depth: 0
1717

18-
- name: Setup Node.js 14.x
18+
- name: Setup Node.js 16.x
1919
uses: actions/setup-node@master
2020
with:
21-
node-version: 14.x
21+
node-version: 16.x
2222

2323
- name: Install Dependencies
24-
run: yarn
24+
run: yarn install
2525

2626
- name: Build Packages
2727
run: yarn build

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
1616
fetch-depth: 0
1717

18-
- name: Setup Node.js 14.x
18+
- name: Setup Node.js 16.x
1919
uses: actions/setup-node@master
2020
with:
21-
node-version: 14.x
21+
node-version: 16.x
2222

2323
- name: Install Dependencies
2424
run: yarn
@@ -29,5 +29,5 @@ jobs:
2929
- name: "Test Packages"
3030
run: yarn test
3131

32-
- name: "Test ESM Support"
33-
run: node scripts/test-esm.mjs
32+
- name: "Test ESM & CJS integrity"
33+
run: yarn bob check

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
1717
fetch-depth: 0
1818

19-
- name: Setup Node.js 14.x
19+
- name: Setup Node.js 16.x
2020
uses: actions/setup-node@master
2121
with:
22-
node-version: 14.x
22+
node-version: 16.x
2323

2424
- name: Install Dependencies
2525
run: yarn

jest.config.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ module.exports = {
1111
rootDir: ROOT_DIR,
1212
restoreMocks: true,
1313
reporters: ["default"],
14-
modulePathIgnorePatterns: ["dist", "test-assets", "test-files", "fixtures"],
14+
modulePathIgnorePatterns: [
15+
"dist",
16+
"test-assets",
17+
"test-files",
18+
"fixtures",
19+
".bob",
20+
],
1521
testPathIgnorePatterns: ["packages/todo-example/end2end-tests"],
1622
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
1723
prefix: `${ROOT_DIR}/`,
1824
}),
1925
collectCoverage: false,
2026
cacheDirectory: resolve(ROOT_DIR, `${CI ? "" : "node_modules/"}.cache/jest`),
27+
resolver: "bob-the-bundler/jest-resolver.js",
2128
};

jest.end2end.config.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ module.exports = {
1111
rootDir: ROOT_DIR,
1212
restoreMocks: true,
1313
reporters: ["default"],
14-
modulePathIgnorePatterns: ["dist", "test-assets", "test-files", "fixtures"],
14+
modulePathIgnorePatterns: [
15+
"dist",
16+
"test-assets",
17+
"test-files",
18+
"fixtures",
19+
".bob",
20+
],
1521
testMatch: ["**/packages/todo-example/end2end-tests/**/*.spec.ts"],
1622
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
1723
prefix: `${ROOT_DIR}/`,
@@ -21,4 +27,5 @@ module.exports = {
2127
ROOT_DIR,
2228
`${CI ? "" : "node_modules/"}.cache/jest-end2end`
2329
),
30+
resolver: "bob-the-bundler/jest-resolver.js",
2431
};

jest.project.js

-38
This file was deleted.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@changesets/cli": "2.21.1",
1717
"@types/jest": "27.5.1",
1818
"babel-jest": "27.5.1",
19-
"bob-the-bundler": "1.5.1",
19+
"bob-the-bundler": "2.0.0",
2020
"chalk": "4.1.2",
2121
"globby": "12.2.0",
2222
"husky": "7.0.4",
@@ -33,11 +33,10 @@
3333
"graphql": "16.0.0-experimental-stream-defer.5"
3434
},
3535
"scripts": {
36-
"build": "yarn ts:transpile && bob build",
37-
"watch-build": "tsc-watch --project tsconfig.build.json --onSuccess \"bob build\"",
36+
"build": "bob build",
37+
"watch-build": "tsc-watch --onSuccess \"bob build\"",
3838
"test": "jest --no-watchman",
3939
"test:end2end": "jest --no-watchman --config jest.end2end.config.js",
40-
"ts:transpile": "tsc --project tsconfig.build.json",
4140
"prerelease": "yarn build",
4241
"release": "changeset publish",
4342
"postinstall": "patch-package",

packages/graphql-live-query-patch-json-diff/package.json

+18-10
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,28 @@
3030
"peerDependencies": {
3131
"graphql": "^15.4.0 || ^16.0.0"
3232
},
33-
"main": "dist/index.js",
33+
"main": "dist/cjs/index.js",
3434
"module": "dist/esm/index.js",
3535
"exports": {
3636
".": {
37-
"require": "./dist/index.js",
38-
"import": "./dist/esm/index.js"
37+
"require": {
38+
"types": "./dist/typings/index.d.ts",
39+
"default": "./dist/cjs/index.js"
40+
},
41+
"import": {
42+
"types": "./dist/typings/index.d.ts",
43+
"default": "./dist/esm/index.js"
44+
},
45+
"default": {
46+
"types": "./dist/typings/index.d.ts",
47+
"default": "./dist/esm/index.js"
48+
}
3949
},
40-
"./*": {
41-
"require": "./dist/*.js",
42-
"import": "./dist/esm/*.js"
43-
}
50+
"./package.json": "./package.json"
4451
},
45-
"typings": "dist/index.d.ts",
52+
"typings": "dist/typings/index.d.ts",
4653
"typescript": {
47-
"definition": "dist/index.d.ts"
54+
"definition": "dist/typings/index.d.ts"
4855
},
4956
"scripts": {
5057
"test": "jest",
@@ -56,5 +63,6 @@
5663
"publishConfig": {
5764
"directory": "dist",
5865
"access": "public"
59-
}
66+
},
67+
"type": "module"
6068
}

packages/graphql-live-query-patch-json-diff/src/applyLiveQueryJSONDiffPatch.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ExecutionResult } from "graphql";
22
import { LiveExecutionResult } from "@n1ru4l/graphql-live-query";
3-
import { applyLiveQueryJSONDiffPatch } from "./applyLiveQueryJSONDiffPatch";
3+
import { applyLiveQueryJSONDiffPatch } from "./applyLiveQueryJSONDiffPatch.js";
44

55
test("pass through non live query patch result", async () => {
66
async function* source() {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createApplyLiveQueryPatch } from "@n1ru4l/graphql-live-query-patch";
2-
import { applyJSONDiffPatch } from "./applyJSONDiffPatch";
2+
import { applyJSONDiffPatch } from "./applyJSONDiffPatch.js";
33

44
export const applyLiveQueryJSONDiffPatch =
55
createApplyLiveQueryPatch(applyJSONDiffPatch);

packages/graphql-live-query-patch-json-diff/src/applyLiveQueryJSONDiffPatchGenerator.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ExecutionResult } from "graphql";
22
import { LiveExecutionResult } from "packages/graphql-live-query/src";
3-
import { liveQueryJSONDiffPatchGenerator } from "./liveQueryJSONDiffPatchGenerator";
3+
import { liveQueryJSONDiffPatchGenerator } from "./liveQueryJSONDiffPatchGenerator.js";
44

55
it("passes through non live query values", async () => {
66
async function* source() {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createApplyLiveQueryPatchGenerator } from "@n1ru4l/graphql-live-query-patch";
2-
import { generateJSONDiffPatch } from "./generateJSONDiffPatch";
2+
import { generateJSONDiffPatch } from "./generateJSONDiffPatch.js";
33

44
export const applyLiveQueryJSONDiffPatchGenerator =
55
createApplyLiveQueryPatchGenerator(generateJSONDiffPatch);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from "./applyJSONDiffPatch";
2-
export * from "./applyLiveQueryJSONDiffPatch";
3-
export * from "./applyLiveQueryJSONDiffPatchGenerator";
4-
export * from "./generateJSONDiffPatch";
5-
export * from "./liveQueryJSONDiffPatchGenerator";
1+
export * from "./applyJSONDiffPatch.js";
2+
export * from "./applyLiveQueryJSONDiffPatch.js";
3+
export * from "./applyLiveQueryJSONDiffPatchGenerator.js";
4+
export * from "./generateJSONDiffPatch.js";
5+
export * from "./liveQueryJSONDiffPatchGenerator.js";

packages/graphql-live-query-patch-json-diff/src/liveQueryJSONDiffPatchGenerator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createLiveQueryPatchGenerator } from "@n1ru4l/graphql-live-query-patch";
2-
import { generateJSONDiffPatch } from "./generateJSONDiffPatch";
2+
import { generateJSONDiffPatch } from "./generateJSONDiffPatch.js";
33

44
export const liveQueryJSONDiffPatchGenerator = createLiveQueryPatchGenerator(
55
generateJSONDiffPatch

packages/graphql-live-query-patch-json-patch/package.json

+18-10
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,28 @@
3030
"peerDependencies": {
3131
"graphql": "^15.4.0 || ^16.0.0"
3232
},
33-
"main": "dist/index.js",
33+
"main": "dist/cjs/index.js",
3434
"module": "dist/esm/index.js",
3535
"exports": {
3636
".": {
37-
"require": "./dist/index.js",
38-
"import": "./dist/esm/index.js"
37+
"require": {
38+
"types": "./dist/typings/index.d.ts",
39+
"default": "./dist/cjs/index.js"
40+
},
41+
"import": {
42+
"types": "./dist/typings/index.d.ts",
43+
"default": "./dist/esm/index.js"
44+
},
45+
"default": {
46+
"types": "./dist/typings/index.d.ts",
47+
"default": "./dist/esm/index.js"
48+
}
3949
},
40-
"./*": {
41-
"require": "./dist/*.js",
42-
"import": "./dist/esm/*.js"
43-
}
50+
"./package.json": "./package.json"
4451
},
45-
"typings": "dist/index.d.ts",
52+
"typings": "dist/typings/index.d.ts",
4653
"typescript": {
47-
"definition": "dist/index.d.ts"
54+
"definition": "dist/typings/index.d.ts"
4855
},
4956
"scripts": {
5057
"test": "jest",
@@ -56,5 +63,6 @@
5663
"publishConfig": {
5764
"directory": "dist",
5865
"access": "public"
59-
}
66+
},
67+
"type": "module"
6068
}

packages/graphql-live-query-patch-json-patch/src/applyLiveQueryJSONPatch.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ExecutionResult } from "graphql";
22
import { LiveExecutionResult } from "@n1ru4l/graphql-live-query";
3-
import { applyLiveQueryJSONPatch } from "./applyLiveQueryJSONPatch";
3+
import { applyLiveQueryJSONPatch } from "./applyLiveQueryJSONPatch.js";
44

55
test("pass through non live query patch result", async () => {
66
async function* source() {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createApplyLiveQueryPatch } from "@n1ru4l/graphql-live-query-patch";
2-
import { applyJSONPatch } from "./applyJSONPatch";
2+
import { applyJSONPatch } from "./applyJSONPatch.js";
33

44
export const applyLiveQueryJSONPatch =
55
createApplyLiveQueryPatch(applyJSONPatch);

packages/graphql-live-query-patch-json-patch/src/applyLiveQueryJSONPatchGenerator.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ExecutionResult } from "graphql";
22
import { LiveExecutionResult } from "packages/graphql-live-query/src";
3-
import { liveQueryJSONPatchGenerator } from "./liveQueryJSONPatchGenerator";
3+
import { liveQueryJSONPatchGenerator } from "./liveQueryJSONPatchGenerator.js";
44

55
it("passes through non live query values", async () => {
66
async function* source() {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createApplyLiveQueryPatchGenerator } from "@n1ru4l/graphql-live-query-patch";
2-
import { generateJSONPatch } from "./generateJSONPatch";
2+
import { generateJSONPatch } from "./generateJSONPatch.js";
33

44
export const applyLiveQueryJSONPatchGenerator =
55
createApplyLiveQueryPatchGenerator(generateJSONPatch);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from "./applyJSONPatch";
2-
export * from "./applyLiveQueryJSONPatch";
3-
export * from "./applyLiveQueryJSONPatchGenerator";
4-
export * from "./generateJSONPatch";
5-
export * from "./liveQueryJSONPatchGenerator";
1+
export * from "./applyJSONPatch.js";
2+
export * from "./applyLiveQueryJSONPatch.js";
3+
export * from "./applyLiveQueryJSONPatchGenerator.js";
4+
export * from "./generateJSONPatch.js";
5+
export * from "./liveQueryJSONPatchGenerator.js";
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createLiveQueryPatchGenerator } from "@n1ru4l/graphql-live-query-patch";
2-
import { generateJSONPatch } from "./generateJSONPatch";
2+
import { generateJSONPatch } from "./generateJSONPatch.js";
33

44
export const liveQueryJSONPatchGenerator =
55
createLiveQueryPatchGenerator(generateJSONPatch);

0 commit comments

Comments
 (0)