Skip to content

Commit

Permalink
feat: typescript esm export map support (#930)
Browse files Browse the repository at this point in the history
* feat: support TypeScript node module resolution

* chore: add changeset

* chore: use Node 16 in tests
  • Loading branch information
n1ru4l authored Jun 27, 2022
1 parent 93239dc commit f585fb3
Show file tree
Hide file tree
Showing 77 changed files with 1,283 additions and 568 deletions.
12 changes: 12 additions & 0 deletions .changeset/warm-moles-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@n1ru4l/graphql-live-query": minor
"@n1ru4l/graphql-live-query-patch": minor
"@n1ru4l/graphql-live-query-patch-jsondiffpatch": minor
"@n1ru4l/graphql-live-query-patch-json-patch": minor
"@n1ru4l/in-memory-live-query-store": minor
"@n1ru4l/json-patch-plus": minor
"@n1ru4l/socket-io-graphql-client": minor
"@n1ru4l/socket-io-graphql-server": minor
---

Support TypeScript ESM module resolution. More information on https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js
6 changes: 3 additions & 3 deletions .github/workflows/ci-todo-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 14.x
- name: Setup Node.js 16.x
uses: actions/setup-node@master
with:
node-version: 14.x
node-version: 16.x

- name: Install Dependencies
run: yarn
run: yarn install

- name: Build Packages
run: yarn build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 14.x
- name: Setup Node.js 16.x
uses: actions/setup-node@master
with:
node-version: 14.x
node-version: 16.x

- name: Install Dependencies
run: yarn
Expand All @@ -29,5 +29,5 @@ jobs:
- name: "Test Packages"
run: yarn test

- name: "Test ESM Support"
run: node scripts/test-esm.mjs
- name: "Test ESM & CJS integrity"
run: yarn bob check
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 14.x
- name: Setup Node.js 16.x
uses: actions/setup-node@master
with:
node-version: 14.x
node-version: 16.x

- name: Install Dependencies
run: yarn
Expand Down
9 changes: 8 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ module.exports = {
rootDir: ROOT_DIR,
restoreMocks: true,
reporters: ["default"],
modulePathIgnorePatterns: ["dist", "test-assets", "test-files", "fixtures"],
modulePathIgnorePatterns: [
"dist",
"test-assets",
"test-files",
"fixtures",
".bob",
],
testPathIgnorePatterns: ["packages/todo-example/end2end-tests"],
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
prefix: `${ROOT_DIR}/`,
}),
collectCoverage: false,
cacheDirectory: resolve(ROOT_DIR, `${CI ? "" : "node_modules/"}.cache/jest`),
resolver: "bob-the-bundler/jest-resolver.js",
};
9 changes: 8 additions & 1 deletion jest.end2end.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ module.exports = {
rootDir: ROOT_DIR,
restoreMocks: true,
reporters: ["default"],
modulePathIgnorePatterns: ["dist", "test-assets", "test-files", "fixtures"],
modulePathIgnorePatterns: [
"dist",
"test-assets",
"test-files",
"fixtures",
".bob",
],
testMatch: ["**/packages/todo-example/end2end-tests/**/*.spec.ts"],
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
prefix: `${ROOT_DIR}/`,
Expand All @@ -21,4 +27,5 @@ module.exports = {
ROOT_DIR,
`${CI ? "" : "node_modules/"}.cache/jest-end2end`
),
resolver: "bob-the-bundler/jest-resolver.js",
};
38 changes: 0 additions & 38 deletions jest.project.js

This file was deleted.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@changesets/cli": "2.21.1",
"@types/jest": "27.5.1",
"babel-jest": "27.5.1",
"bob-the-bundler": "1.5.1",
"bob-the-bundler": "2.0.0",
"chalk": "4.1.2",
"globby": "12.2.0",
"husky": "7.0.4",
Expand All @@ -33,11 +33,10 @@
"graphql": "16.0.0-experimental-stream-defer.5"
},
"scripts": {
"build": "yarn ts:transpile && bob build",
"watch-build": "tsc-watch --project tsconfig.build.json --onSuccess \"bob build\"",
"build": "bob build",
"watch-build": "tsc-watch --onSuccess \"bob build\"",
"test": "jest --no-watchman",
"test:end2end": "jest --no-watchman --config jest.end2end.config.js",
"ts:transpile": "tsc --project tsconfig.build.json",
"prerelease": "yarn build",
"release": "changeset publish",
"postinstall": "patch-package",
Expand Down
28 changes: 18 additions & 10 deletions packages/graphql-live-query-patch-json-diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,28 @@
"peerDependencies": {
"graphql": "^15.4.0 || ^16.0.0"
},
"main": "dist/index.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/esm/index.js"
"require": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/esm/*.js"
}
"./package.json": "./package.json"
},
"typings": "dist/index.d.ts",
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
"definition": "dist/typings/index.d.ts"
},
"scripts": {
"test": "jest",
Expand All @@ -56,5 +63,6 @@
"publishConfig": {
"directory": "dist",
"access": "public"
}
},
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExecutionResult } from "graphql";
import { LiveExecutionResult } from "@n1ru4l/graphql-live-query";
import { applyLiveQueryJSONDiffPatch } from "./applyLiveQueryJSONDiffPatch";
import { applyLiveQueryJSONDiffPatch } from "./applyLiveQueryJSONDiffPatch.js";

test("pass through non live query patch result", async () => {
async function* source() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApplyLiveQueryPatch } from "@n1ru4l/graphql-live-query-patch";
import { applyJSONDiffPatch } from "./applyJSONDiffPatch";
import { applyJSONDiffPatch } from "./applyJSONDiffPatch.js";

export const applyLiveQueryJSONDiffPatch =
createApplyLiveQueryPatch(applyJSONDiffPatch);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExecutionResult } from "graphql";
import { LiveExecutionResult } from "packages/graphql-live-query/src";
import { liveQueryJSONDiffPatchGenerator } from "./liveQueryJSONDiffPatchGenerator";
import { liveQueryJSONDiffPatchGenerator } from "./liveQueryJSONDiffPatchGenerator.js";

it("passes through non live query values", async () => {
async function* source() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApplyLiveQueryPatchGenerator } from "@n1ru4l/graphql-live-query-patch";
import { generateJSONDiffPatch } from "./generateJSONDiffPatch";
import { generateJSONDiffPatch } from "./generateJSONDiffPatch.js";

export const applyLiveQueryJSONDiffPatchGenerator =
createApplyLiveQueryPatchGenerator(generateJSONDiffPatch);
10 changes: 5 additions & 5 deletions packages/graphql-live-query-patch-json-diff/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./applyJSONDiffPatch";
export * from "./applyLiveQueryJSONDiffPatch";
export * from "./applyLiveQueryJSONDiffPatchGenerator";
export * from "./generateJSONDiffPatch";
export * from "./liveQueryJSONDiffPatchGenerator";
export * from "./applyJSONDiffPatch.js";
export * from "./applyLiveQueryJSONDiffPatch.js";
export * from "./applyLiveQueryJSONDiffPatchGenerator.js";
export * from "./generateJSONDiffPatch.js";
export * from "./liveQueryJSONDiffPatchGenerator.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createLiveQueryPatchGenerator } from "@n1ru4l/graphql-live-query-patch";
import { generateJSONDiffPatch } from "./generateJSONDiffPatch";
import { generateJSONDiffPatch } from "./generateJSONDiffPatch.js";

export const liveQueryJSONDiffPatchGenerator = createLiveQueryPatchGenerator(
generateJSONDiffPatch
Expand Down
28 changes: 18 additions & 10 deletions packages/graphql-live-query-patch-json-patch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,28 @@
"peerDependencies": {
"graphql": "^15.4.0 || ^16.0.0"
},
"main": "dist/index.js",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/esm/index.js"
"require": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": "./dist/*.js",
"import": "./dist/esm/*.js"
}
"./package.json": "./package.json"
},
"typings": "dist/index.d.ts",
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
"definition": "dist/typings/index.d.ts"
},
"scripts": {
"test": "jest",
Expand All @@ -56,5 +63,6 @@
"publishConfig": {
"directory": "dist",
"access": "public"
}
},
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExecutionResult } from "graphql";
import { LiveExecutionResult } from "@n1ru4l/graphql-live-query";
import { applyLiveQueryJSONPatch } from "./applyLiveQueryJSONPatch";
import { applyLiveQueryJSONPatch } from "./applyLiveQueryJSONPatch.js";

test("pass through non live query patch result", async () => {
async function* source() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApplyLiveQueryPatch } from "@n1ru4l/graphql-live-query-patch";
import { applyJSONPatch } from "./applyJSONPatch";
import { applyJSONPatch } from "./applyJSONPatch.js";

export const applyLiveQueryJSONPatch =
createApplyLiveQueryPatch(applyJSONPatch);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExecutionResult } from "graphql";
import { LiveExecutionResult } from "packages/graphql-live-query/src";
import { liveQueryJSONPatchGenerator } from "./liveQueryJSONPatchGenerator";
import { liveQueryJSONPatchGenerator } from "./liveQueryJSONPatchGenerator.js";

it("passes through non live query values", async () => {
async function* source() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApplyLiveQueryPatchGenerator } from "@n1ru4l/graphql-live-query-patch";
import { generateJSONPatch } from "./generateJSONPatch";
import { generateJSONPatch } from "./generateJSONPatch.js";

export const applyLiveQueryJSONPatchGenerator =
createApplyLiveQueryPatchGenerator(generateJSONPatch);
10 changes: 5 additions & 5 deletions packages/graphql-live-query-patch-json-patch/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./applyJSONPatch";
export * from "./applyLiveQueryJSONPatch";
export * from "./applyLiveQueryJSONPatchGenerator";
export * from "./generateJSONPatch";
export * from "./liveQueryJSONPatchGenerator";
export * from "./applyJSONPatch.js";
export * from "./applyLiveQueryJSONPatch.js";
export * from "./applyLiveQueryJSONPatchGenerator.js";
export * from "./generateJSONPatch.js";
export * from "./liveQueryJSONPatchGenerator.js";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createLiveQueryPatchGenerator } from "@n1ru4l/graphql-live-query-patch";
import { generateJSONPatch } from "./generateJSONPatch";
import { generateJSONPatch } from "./generateJSONPatch.js";

export const liveQueryJSONPatchGenerator =
createLiveQueryPatchGenerator(generateJSONPatch);
Loading

0 comments on commit f585fb3

Please sign in to comment.