Skip to content

Commit

Permalink
Fix ESM/CJS (#668)
Browse files Browse the repository at this point in the history
Co-authored-by: enisdenjo <badurinadenis@gmail.com>
  • Loading branch information
kamilkisiela and enisdenjo committed Nov 22, 2022
1 parent 2745d5d commit e116841
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 81 deletions.
6 changes: 6 additions & 0 deletions .changeset/breezy-carrots-beam.md
@@ -0,0 +1,6 @@
---
'@graphql-hive/client': patch
'@graphql-hive/core': patch
---

Fix ESM/CJS issue
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Expand Up @@ -213,6 +213,9 @@ jobs:
- name: Build
run: pnpm build

- name: Test ESM & CJS exports integrity
run: pnpm turbo check:build

- name: Archive @hive/app
run: zip -r packages/web/app/dist.zip packages/web/app/dist

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/docker-compose.yml
Expand Up @@ -183,7 +183,7 @@ services:
ports:
- 3012:3012
volumes:
- '../packages/libraries/external-composition/dist/example.mjs:/example.mjs'
- '../packages/libraries/external-composition/dist/example.js:/example.mjs'
- './run-external-composition.sh:/run-external-composition.sh'
environment:
NODE_ENV: production
Expand Down
28 changes: 9 additions & 19 deletions packages/libraries/client/package.json
Expand Up @@ -14,12 +14,10 @@
},
"homepage": "https://graphql-hive.com",
"license": "MIT",
"sideEffects": false,
"type": "module",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/typings/index.d.ts"
},
"exports": {
".": {
"require": {
Expand All @@ -35,23 +33,15 @@
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": {
"types": "./dist/typings/*.d.cts",
"default": "./dist/cjs/*.js"
},
"import": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
},
"default": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
}
}
"./package.json": "./package.json"
},
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/typings/index.d.ts"
},
"scripts": {
"build": "node scripts/update-version.mjs && bob build"
"build": "node scripts/update-version.mjs && bob build",
"check:build": "bob check"
},
"peerDependencies": {
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/libraries/client/src/apollo.ts
@@ -1,11 +1,11 @@
import type { ApolloServerPlugin } from 'apollo-server-plugin-base';
import type { DocumentNode } from 'graphql';
import type { HiveClient, HivePluginOptions, SupergraphSDLFetcherOptions } from './internal/types';
import type { HiveClient, HivePluginOptions, SupergraphSDLFetcherOptions } from './internal/types.js';
import { createHash } from 'crypto';
import axios from 'axios';
import { createHive } from './client';
import { isHiveClient } from './internal/utils';
import { version } from './version';
import { createHive } from './client.js';
import { isHiveClient } from './internal/utils.js';
import { version } from './version.js';

export function createSupergraphSDLFetcher({ endpoint, key }: SupergraphSDLFetcherOptions) {
let cacheETag: string | null = null;
Expand Down
12 changes: 6 additions & 6 deletions packages/libraries/client/src/client.ts
@@ -1,11 +1,11 @@
import { GraphQLSchema, ExecutionArgs, ExecutionResult } from 'graphql';
import axios from 'axios';
import type { HivePluginOptions, HiveClient } from './internal/types';
import { createUsage } from './internal/usage';
import { createReporting } from './internal/reporting';
import { createOperationsStore } from './internal/operations-store';
import { logIf } from './internal/utils';
import { version } from './version';
import type { HivePluginOptions, HiveClient } from './internal/types.js';
import { createUsage } from './internal/usage.js';
import { createReporting } from './internal/reporting.js';
import { createOperationsStore } from './internal/operations-store.js';
import { logIf } from './internal/utils.js';
import { version } from './version.js';

export function createHive(options: HivePluginOptions): HiveClient {
const logger = options?.agent?.logger ?? console;
Expand Down
6 changes: 3 additions & 3 deletions packages/libraries/client/src/envelop.ts
@@ -1,7 +1,7 @@
import type { Plugin } from '@envelop/types';
import type { HiveClient, HivePluginOptions } from './internal/types';
import { createHive } from './client';
import { isHiveClient } from './internal/utils';
import type { HiveClient, HivePluginOptions } from './internal/types.js';
import { createHive } from './client.js';
import { isHiveClient } from './internal/utils.js';

export function useHive(clientOrOptions: HiveClient): Plugin;
export function useHive(clientOrOptions: HivePluginOptions): Plugin;
Expand Down
4 changes: 2 additions & 2 deletions packages/libraries/client/src/gateways.ts
@@ -1,7 +1,7 @@
import axios from 'axios';
import { createHash } from 'crypto';
import type { SchemaFetcherOptions, ServicesFetcherOptions } from './internal/types';
import { version } from './version';
import type { SchemaFetcherOptions, ServicesFetcherOptions } from './internal/types.js';
import { version } from './version.js';

interface Schema {
sdl: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/libraries/client/src/index.ts
@@ -1,5 +1,5 @@
export type { HivePluginOptions, HiveClient } from './internal/types';
export { useHive } from './envelop';
export { hiveApollo, createSupergraphSDLFetcher, createSupergraphManager } from './apollo';
export { createSchemaFetcher, createServicesFetcher } from './gateways';
export { createHive } from './client';
export type { HivePluginOptions, HiveClient } from './internal/types.js';
export { useHive } from './envelop.js';
export { hiveApollo, createSupergraphSDLFetcher, createSupergraphManager } from './apollo.js';
export { createSchemaFetcher, createServicesFetcher } from './gateways.js';
export { createHive } from './client.js';
4 changes: 2 additions & 2 deletions packages/libraries/client/src/internal/agent.ts
@@ -1,7 +1,7 @@
import retry from 'async-retry';
import axios from 'axios';
import { version } from '../version';
import type { Logger } from './types';
import { version } from '../version.js';
import type { Logger } from './types.js';

export interface AgentOptions {
enabled?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/libraries/client/src/internal/operations-store.ts
@@ -1,7 +1,7 @@
import type { DocumentNode } from 'graphql';
import { stripIgnoredCharacters, parse } from 'graphql';
import axios from 'axios';
import type { HivePluginOptions } from './types';
import type { HivePluginOptions } from './types.js';

export interface OperationsStore {
canHandle(key: string): boolean;
Expand Down
10 changes: 5 additions & 5 deletions packages/libraries/client/src/internal/reporting.ts
@@ -1,10 +1,10 @@
import { GraphQLSchema, stripIgnoredCharacters, print, Kind, ExecutionResult } from 'graphql';
import { getDocumentNodeFromSchema } from '@graphql-tools/utils';
import { createAgent } from './agent';
import { version } from '../version';
import type { HivePluginOptions } from './types';
import type { SchemaPublishMutation } from '../__generated__/types';
import { logIf } from './utils';
import { createAgent } from './agent.js';
import { version } from '../version.js';
import type { HivePluginOptions } from './types.js';
import type { SchemaPublishMutation } from '../__generated__/types.js';
import { logIf } from './utils.js';

export interface SchemaReporter {
report(args: { schema: GraphQLSchema }): void;
Expand Down
6 changes: 3 additions & 3 deletions packages/libraries/client/src/internal/types.ts
@@ -1,7 +1,7 @@
import type { ExecutionArgs } from 'graphql';
import type { AgentOptions } from './agent';
import type { SchemaReporter } from './reporting';
import type { OperationsStore } from './operations-store';
import type { AgentOptions } from './agent.js';
import type { SchemaReporter } from './reporting.js';
import type { OperationsStore } from './operations-store.js';

export interface HiveClient {
info(): Promise<void>;
Expand Down
10 changes: 5 additions & 5 deletions packages/libraries/client/src/internal/usage.ts
Expand Up @@ -25,11 +25,11 @@ import {
} from 'graphql';
import LRU from 'tiny-lru';
import { normalizeOperation } from '@graphql-hive/core';
import { createAgent } from './agent';
import { randomSampling } from './sampling';
import { version } from '../version';
import { cache, cacheDocumentKey, measureDuration, memo, isAsyncIterableIterator, logIf } from './utils';
import type { HivePluginOptions, HiveUsagePluginOptions, CollectUsageCallback, ClientInfo } from './types';
import { createAgent } from './agent.js';
import { randomSampling } from './sampling.js';
import { version } from '../version.js';
import { cache, cacheDocumentKey, measureDuration, memo, isAsyncIterableIterator, logIf } from './utils.js';
import type { HivePluginOptions, HiveUsagePluginOptions, CollectUsageCallback, ClientInfo } from './types.js';

interface UsageCollector {
collect(args: ExecutionArgs): CollectUsageCallback;
Expand Down
2 changes: 1 addition & 1 deletion packages/libraries/client/src/internal/utils.ts
@@ -1,5 +1,5 @@
import { createHash } from 'crypto';
import type { HiveClient, HivePluginOptions, AsyncIterableIteratorOrValue } from './types';
import type { HiveClient, HivePluginOptions, AsyncIterableIteratorOrValue } from './types.js';

export function isAsyncIterableIterator<T>(value: AsyncIterableIteratorOrValue<T>): value is AsyncIterableIterator<T> {
return typeof (value as any)?.[Symbol.asyncIterator] === 'function';
Expand Down
2 changes: 1 addition & 1 deletion packages/libraries/client/src/version.ts
@@ -1 +1 @@
export const version = '0.21.1';
export const version = '0.21.2';
28 changes: 9 additions & 19 deletions packages/libraries/core/package.json
Expand Up @@ -13,12 +13,10 @@
},
"homepage": "https://graphql-hive.com",
"license": "MIT",
"type": "module",
"sideEffects": false,
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/typings/index.d.ts"
},
"exports": {
".": {
"require": {
Expand All @@ -34,28 +32,20 @@
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": {
"types": "./dist/typings/*.d.cts",
"default": "./dist/cjs/*.js"
},
"import": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
},
"default": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
}
}
"./package.json": "./package.json"
},
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/typings/index.d.ts"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public",
"directory": "dist"
},
"scripts": {
"build": "bob build"
"build": "bob build",
"check:build": "bob check"
},
"peerDependencies": {
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/libraries/core/src/index.ts
@@ -1,2 +1,2 @@
export * from './normalize/operation';
export * from './hash';
export * from './normalize/operation.js';
export * from './hash.js';
3 changes: 2 additions & 1 deletion packages/libraries/external-composition/build-example.mjs
Expand Up @@ -8,13 +8,14 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
const pkg = JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf8'));

await tsup({
entryPoints: [join(__dirname, 'example.mjs')],
entry: [join(__dirname, 'example.mjs')],
outDir: join(__dirname, 'dist'),
target: 'node16',
format: ['esm'],
splitting: false,
sourcemap: true,
clean: true,
shims: false,
skipNodeModulesBundle: false,
noExternal: Object.keys(pkg.peerDependencies).concat(Object.keys(pkg.devDependencies)),
banner: {
Expand Down
5 changes: 4 additions & 1 deletion packages/libraries/external-composition/package.json
Expand Up @@ -14,6 +14,8 @@
},
"homepage": "https://graphql-hive.com",
"license": "MIT",
"type": "module",
"sideEffects": false,
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"typings": "dist/typings/index.d.ts",
Expand Down Expand Up @@ -52,7 +54,8 @@
},
"scripts": {
"build": "bob build",
"build-local": "pnpm build && node build-example.mjs"
"build-local": "pnpm build && node build-example.mjs",
"check:build": "bob check"
},
"peerDependencies": {
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
Expand Down
3 changes: 3 additions & 0 deletions turbo.json
Expand Up @@ -50,6 +50,9 @@
},
"typecheck": {
"outputs": [""]
},
"check:build": {
"outputs": [""]
}
}
}

0 comments on commit e116841

Please sign in to comment.