Skip to content

Commit

Permalink
chore(deps): update dependency bob-the-bundler to v4 (#1103)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency bob-the-bundler to v4

* v4 ready

* use jest resolver :)

* pretty shit

* feat: add missing deps + modernize env

* fix: workaround esm/cjs madness :)

* add changeset

* chore(dependencies): updated changesets for modified dependencies

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 26, 2022
1 parent a1845a4 commit 2c568f1
Show file tree
Hide file tree
Showing 23 changed files with 1,329 additions and 266 deletions.
7 changes: 7 additions & 0 deletions .changeset/graphql-config-1103-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"graphql-config": patch
---

dependencies updates:

- Added dependency [`tslib@^2.4.0` ↗︎](https://www.npmjs.com/package/tslib/v/null) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/serious-turkeys-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-config': patch
---

Proper ESM/CJS support on Node.js
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
- name: Build
run: yarn build

- name: Integrity check
run: yarn bob check

lint:
name: Lint
uses: the-guild-org/shared-config/.github/workflows/lint.yml@main
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ out.txt
package-lock.json
.next/
*.log
.bob
6 changes: 6 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: process.versions.node.split('.')[0] } }],
'@babel/preset-typescript',
],
};
16 changes: 12 additions & 4 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const { pathsToModuleNameMapper } = require('ts-jest');
const { resolve } = require('path');

const ROOT_DIR = __dirname;
const TSCONFIG = resolve(ROOT_DIR, 'tsconfig.json');
const tsconfig = require(TSCONFIG);

// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
// Automatically clear mock calls and instances between every test
clearMocks: true,
Expand All @@ -17,6 +23,8 @@ module.exports = {

// An array of file extensions your modules use
moduleFileExtensions: ['ts', 'js'],
modulePathIgnorePatterns: ['dist', '.bob'],
moduleNameMapper: pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { prefix: `${ROOT_DIR}/` }),

// The test environment that will be used for testing
testEnvironment: 'node',
Expand All @@ -25,9 +33,9 @@ module.exports = {
testMatch: ['**/test/**/*.spec.ts'],

// A map from regular expressions to paths to transformers
transform: {
'^.+\\.ts$': 'ts-jest',
},
transform: { '^.+\\.tsx?$': 'babel-jest' },

errorOnDeprecated: true,

resolver: 'bob-the-bundler/jest-resolver.js',
};
59 changes: 36 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,40 @@
"version": "4.3.3",
"description": "The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)",
"sideEffects": false,
"main": "dist/index.js",
"module": "dist/index.mjs",
"typings": "dist/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs"
"require": {
"types": "./dist/typings/index.d.cts",
"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/*.mjs"
}
"./package.json": "./package.json"
},
"typings": "dist/typings/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
"definition": "dist/typings/index.d.ts"
},
"publishConfig": {
"directory": "dist",
"access": "public"
},
"type": "module",
"scripts": {
"prepublishOnly": "yarn build",
"clean": "rimraf dist",
"postinstall": "patch-package",
"prebuild": "yarn clean && yarn json-schema",
"build": "bob build --single",
"prepack": "bob prepack",
"build": "bob build",
"prettier": "prettier --ignore-path .gitignore --write --list-different .",
"prettier:check": "prettier --ignore-path .gitignore --check .",
"lint": "eslint --ignore-path .gitignore .",
Expand All @@ -50,16 +61,21 @@
"cosmiconfig-typescript-loader": "^3.1.0",
"minimatch": "4.2.1",
"ts-node": "^10.8.1",
"string-env-interpolation": "1.0.1"
"string-env-interpolation": "1.0.1",
"tslib": "^2.4.0"
},
"devDependencies": {
"@babel/core": "7.18.13",
"@babel/preset-env": "7.18.10",
"@babel/preset-typescript": "7.18.6",
"@changesets/cli": "2.24.3",
"@changesets/changelog-github": "0.4.6",
"@types/jest": "28.1.7",
"@types/node": "16.11.54",
"@typescript-eslint/eslint-plugin": "5.34.0",
"@typescript-eslint/parser": "5.34.0",
"bob-the-bundler": "1.7.3",
"babel-jest": "28.1.3",
"bob-the-bundler": "4.0.0",
"del": "6.1.1",
"eslint": "8.22.0",
"eslint-config-prettier": "8.5.0",
Expand All @@ -73,7 +89,6 @@
"prettier": "2.7.1",
"rimraf": "3.0.2",
"ts-jest": "28.0.8",
"tslib": "2.4.0",
"typescript": "4.7.4",
"typescript-json-schema": "0.54.0"
},
Expand All @@ -94,10 +109,12 @@
"url": "https://github.com/kamilkisiela"
},
"license": "MIT",
"buildOptions": {
"copy": [
"config-schema.json"
]
"bob": {
"build": {
"copy": [
"config-schema.json"
]
}
},
"lint-staged": {
"{src,test}/**/*": [
Expand All @@ -109,10 +126,6 @@
"pre-commit": "lint-staged"
}
},
"publishConfig": {
"directory": "dist",
"access": "public"
},
"engines": {
"node": ">= 10.0.0"
}
Expand Down
14 changes: 7 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname } from 'path';
import type { IGraphQLConfig, GraphQLConfigResult } from './types';
import { GraphQLProjectConfig } from './project-config';
import type { IGraphQLConfig, GraphQLConfigResult } from './types.js';
import { GraphQLProjectConfig } from './project-config.js';
import {
isMultipleProjectConfig,
isSingleProjectConfig,
Expand All @@ -9,11 +9,11 @@ import {
getConfigSync,
findConfigSync,
isLegacyProjectConfig,
} from './helpers';
import { ProjectNotFoundError, ConfigNotFoundError, ConfigEmptyError } from './errors';
import { GraphQLExtensionDeclaration, GraphQLExtensionsRegistry } from './extension';
import { EndpointsExtension } from './extensions/endpoints';
import { isLegacyConfig } from './helpers/cosmiconfig';
} from './helpers/index.js';
import { ProjectNotFoundError, ConfigNotFoundError, ConfigEmptyError } from './errors.js';
import { GraphQLExtensionDeclaration, GraphQLExtensionsRegistry } from './extension.js';
import { EndpointsExtension } from './extensions/endpoints.js';
import { isLegacyConfig } from './helpers/cosmiconfig.js';

const cwd = typeof process !== 'undefined' ? process.cwd() : undefined;
const defaultConfigName = 'graphql';
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { UrlLoader } from '@graphql-tools/url-loader';
import { JsonFileLoader } from '@graphql-tools/json-file-loader';
import { LoadersRegistry } from './loaders';
import { LoadersRegistry } from './loaders.js';

export type GraphQLExtensionDeclaration = (api: ExtensionAPI) => GraphQLConfigExtension;

Expand Down
4 changes: 2 additions & 2 deletions src/extensions/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GraphQLExtensionDeclaration } from '../extension';
import type { WithList } from '../types';
import type { GraphQLExtensionDeclaration } from '../extension.js';
import type { WithList } from '../types.js';

export interface Endpoint {
url: string;
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/cosmiconfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { cosmiconfig, cosmiconfigSync, Loader, defaultLoaders } from 'cosmiconfig';
import loadTs from 'cosmiconfig-typescript-loader';
import unsecure_loadTs from 'cosmiconfig-typescript-loader';
import { loadToml } from 'cosmiconfig-toml-loader';
import { env } from 'string-env-interpolation';

/** The underlying module gives us { default: } on ESM but no default on CJS :) */
const loadTs: typeof unsecure_loadTs = (unsecure_loadTs as any)?.default ?? unsecure_loadTs;
export interface ConfigSearchResult {
config: any;
filepath: string;
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/find-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigNotFoundError, ConfigEmptyError, composeMessage } from '../errors';
import { GraphQLConfigResult } from '../types';
import { createCosmiConfig, createCosmiConfigSync, ConfigSearchResult } from './cosmiconfig';
import { ConfigNotFoundError, ConfigEmptyError, composeMessage } from '../errors.js';
import { GraphQLConfigResult } from '../types.js';
import { createCosmiConfig, createCosmiConfigSync, ConfigSearchResult } from './cosmiconfig.js';

const cwd = typeof process !== 'undefined' ? process.cwd() : undefined;

Expand Down
6 changes: 3 additions & 3 deletions src/helpers/get-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigNotFoundError, ConfigEmptyError, composeMessage } from '../errors';
import { GraphQLConfigResult } from '../types';
import { ConfigSearchResult, createCosmiConfigSync, createCosmiConfig } from './cosmiconfig';
import { ConfigNotFoundError, ConfigEmptyError, composeMessage } from '../errors.js';
import { GraphQLConfigResult } from '../types.js';
import { ConfigSearchResult, createCosmiConfigSync, createCosmiConfig } from './cosmiconfig.js';

export async function getConfig({
filepath,
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './find-config';
export * from './get-config';
export * from './utils';
export * from './find-config.js';
export * from './get-config.js';
export * from './utils.js';
2 changes: 1 addition & 1 deletion src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IGraphQLConfig, IGraphQLProject, IGraphQLProjects, IGraphQLProjectLegacy } from '../types';
import type { IGraphQLConfig, IGraphQLProject, IGraphQLProjects, IGraphQLProjectLegacy } from '../types.js';

export function isMultipleProjectConfig(config: IGraphQLConfig): config is IGraphQLProjects {
return typeof (config as IGraphQLProjects).projects === 'object';
Expand Down
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { GraphQLConfig, loadConfig, loadConfigSync } from './config';
export { GraphQLProjectConfig } from './project-config';
export { GraphQLExtensionDeclaration } from './extension';
export { GraphQLConfig, loadConfig, loadConfigSync } from './config.js';
export { GraphQLProjectConfig } from './project-config.js';
export { GraphQLExtensionDeclaration } from './extension.js';
export { Source, Loader } from '@graphql-tools/utils';
export * from './types';
export * from './errors';
export * from './types.js';
export * from './errors.js';
export { LoadersRegistry } from "./loaders.js"
2 changes: 1 addition & 1 deletion src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@graphql-tools/load';
import { mergeTypeDefs } from '@graphql-tools/merge';
import { GraphQLSchema, DocumentNode, buildASTSchema, print } from 'graphql';
import { MiddlewareFn, useMiddleware } from './helpers';
import { MiddlewareFn, useMiddleware } from './helpers/index.js';

type Pointer = UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[];
type LoadTypedefsOptions = Partial<ToolsLoadTypedefsOptions>;
Expand Down
10 changes: 5 additions & 5 deletions src/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
LoadTypedefsOptions as ToolsLoadTypedefsOptions,
UnnormalizedTypeDefPointer,
} from '@graphql-tools/load';
import { ExtensionMissingError } from './errors';
import type { GraphQLExtensionsRegistry } from './extension';
import type { IExtensions, IGraphQLProject, IGraphQLProjectLegacy, WithList } from './types';
import { isLegacyProjectConfig } from './helpers';
import type { SchemaOutput } from './loaders';
import { ExtensionMissingError } from './errors.js';
import type { GraphQLExtensionsRegistry } from './extension.js';
import type { IExtensions, IGraphQLProject, IGraphQLProjectLegacy, WithList } from './types.js';
import { isLegacyProjectConfig } from './helpers/index.js';
import type { SchemaOutput } from './loaders.js';

type Pointer = UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[];
type LoadTypedefsOptions = Partial<ToolsLoadTypedefsOptions>;
Expand Down
3 changes: 2 additions & 1 deletion test/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { buildSchema, buildASTSchema } from 'graphql';
import { resolve, basename } from 'path';
import { TempDir } from './utils/temp-dir';
import { runTests } from './utils/runner';
import { loadConfig, loadConfigSync, ConfigNotFoundError } from '../src';
import { loadConfig, loadConfigSync, ConfigNotFoundError } from 'graphql-config';
import { beforeEach, beforeAll, test, describe, expect } from '@jest/globals';

const temp = new TempDir();

Expand Down
39 changes: 24 additions & 15 deletions test/loaders.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { parse, DirectiveDefinitionNode, buildSchema, GraphQLSchema, Kind } from 'graphql';
import { DirectiveDefinitionNode, buildSchema, GraphQLSchema, Kind } from 'graphql';
import { Loader, Source } from '@graphql-tools/utils';
import { beforeAll, test, describe, expect } from '@jest/globals';
import { LoadersRegistry } from 'graphql-config';
import { loadTypedefsSync, loadSchemaSync, loadSchema, LoadSchemaOptions } from '@graphql-tools/load';

const schema = buildSchema(/* GraphQL */ `
type Query {
foo: String
}
`);
jest.mock('@graphql-tools/load', () => {
const { parse, buildSchema } = require('graphql');
const document = parse(/* GraphQL */ `
type Query {
foo: String @cache
}
`);

const document = parse(/* GraphQL */ `
type Query {
foo: String @cache
}
`);
const schema = buildSchema(/* GraphQL */ `
type Query {
foo: String
}
`);

schema.isTheOne = true

jest.mock('@graphql-tools/load', () => {
return {
loadTypedefs: jest.fn(() => {
return [{ document }];
Expand All @@ -31,7 +36,8 @@ jest.mock('@graphql-tools/load', () => {
};
});

import { LoadersRegistry } from '../src/loaders';



describe('middlewares', () => {
test('loads Sources instead of GraphQLSchema when middlewares are defined', () => {
Expand Down Expand Up @@ -70,11 +76,14 @@ describe('middlewares', () => {
const received = registry.loadSchemaSync('anything');
const receivedAsync = await registry.loadSchema('anything');

expect(received).toBe(schema);
expect(receivedAsync).toBe(schema);
expect(received.isTheOne).toEqual(true);
expect(receivedAsync.isTheOne).toEqual(true);

});
});



class CustomLoader implements Loader {
private schema: GraphQLSchema;

Expand Down
2 changes: 2 additions & 0 deletions test/utils/runner.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe } from '@jest/globals';

type PromiseOf<T extends (...args: any[]) => any> = T extends (...args: any[]) => Promise<infer R> ? R : ReturnType<T>;

export function runTests<
Expand Down

1 comment on commit 2c568f1

@vercel
Copy link

@vercel vercel bot commented on 2c568f1 Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.