Skip to content

Commit

Permalink
fix: Do not bundle as esm but just to be bundled
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed May 29, 2024
1 parent 65f9560 commit 4da863c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 35 deletions.
5 changes: 0 additions & 5 deletions esm-postbuild.sh

This file was deleted.

17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
"name": "apollo-proxy-cache",
"version": "9.0.3",
"description": "Provides an apollo-link and express (proxy) middleware setup to support a local `@cache` directive",
"main": "build/cjs/index.js",
"typings": "build/mjs/index.d.ts",
"module": "build/mjs/index.js",
"main": "build/module/index.js",
"typings": "build/module/index.d.ts",
"module": "build/module/index.js",
"repository": "[email protected]:BowlingX/apollo-proxy-cache.git",
"author": "David Heidrich <[email protected]>",
"license": "MIT",
"files": [
"build/"
],
"type": "module",
"devDependencies": {
"@apollo/client": "^3.10.4",
"@semantic-release/changelog": "^6.0.3",
Expand Down Expand Up @@ -42,7 +41,7 @@
},
"scripts": {
"prepack": "yarn build",
"build": "yarn run build:main && yarn run build:cjs && sh ./esm-postbuild.sh",
"build": "yarn run build:main",
"build:main": "tsc -p tsconfig.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:types": "tsc --project tsconfig.types.json",
Expand All @@ -52,12 +51,8 @@
"exports": {
".": {
"import": {
"types": "./build/mjs/index.d.ts",
"default": "./build/mjs/index.js"
},
"require": {
"types": "./build/cjs/index.d.ts",
"default": "./build/cjs/index.js"
"types": "./build/module/index.d.ts",
"default": "./build/module/index.js"
}
}
},
Expand Down
4 changes: 1 addition & 3 deletions src/createProxyCacheMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hasDirectives } from 'apollo-utilities'
import bp from 'body-parser'
import { json } from 'body-parser'
import type { Request, Response, NextFunction, RequestHandler } from 'express'
import { DocumentNode, parse, print } from 'graphql'
import {
Expand All @@ -21,8 +21,6 @@ const CACHE_HEADER = 'X-Proxy-Cached'

type RequestWithCache = Request & { _hasCache: { id: string; timeout: number } }

const { json } = bp

const middlewareToPromise =
(middleware: RequestHandler) =>
(req: Parameters<RequestHandler>[0], res: Parameters<RequestHandler>[1]) => {
Expand Down
10 changes: 5 additions & 5 deletions src/proxyCacheLink.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as apollo from '@apollo/client'
import { ApolloLink, Observable, FetchResult } from '@apollo/client'
import { hasDirectives } from 'apollo-utilities'
import type { Subscription } from 'zen-observable-ts'
import type { Cache } from './caches/types.js'
Expand All @@ -15,7 +15,7 @@ export const proxyCacheLink = <K extends string, V, T extends Cache<K, V>>(
queryCache: T,
cacheKeyModifier?: CacheKeyModifier,
) => {
return new apollo.ApolloLink((operation, forward) => {
return new ApolloLink((operation, forward) => {
const directives = 'directive @cache on QUERY'
operation.setContext(({ schemas = [] }) => ({
// @ts-expect-error schemas is never
Expand Down Expand Up @@ -48,7 +48,7 @@ export const proxyCacheLink = <K extends string, V, T extends Cache<K, V>>(
return forward(operation)
}
let subscriber: Subscription
return new apollo.Observable((observer) => {
return new Observable((observer) => {
queryCache
.get(id)
.then((data) => {
Expand All @@ -57,9 +57,9 @@ export const proxyCacheLink = <K extends string, V, T extends Cache<K, V>>(
observer.complete()
return data
}
const obs: apollo.Observable<apollo.FetchResult> = server
const obs: Observable<FetchResult> = server
? forward(operation)
: apollo.Observable.of({
: Observable.of({
data: {},
})
subscriber = obs.subscribe({
Expand Down
8 changes: 0 additions & 8 deletions tsconfig.cjs.json

This file was deleted.

6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"compilerOptions": {
"target": "ES2022",
"outDir": "build/mjs",
"module": "Node16",
"outDir": "build/module",
"module": "ES2022",
"rootDir": "src",
"moduleResolution": "node16",
"moduleResolution": "bundler",
"skipLibCheck": true,
"declaration": true,
"inlineSourceMap": false,
Expand Down

0 comments on commit 4da863c

Please sign in to comment.