Skip to content

Commit 2c568f1

Browse files
renovate[bot]n1ru4lgithub-actions[bot]
authored
chore(deps): update dependency bob-the-bundler to v4 (#1103)
* 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>
1 parent a1845a4 commit 2c568f1

23 files changed

+1329
-266
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"graphql-config": patch
3+
---
4+
5+
dependencies updates:
6+
7+
- Added dependency [`tslib@^2.4.0` ↗︎](https://www.npmjs.com/package/tslib/v/null) (to `dependencies`)

.changeset/serious-turkeys-impress.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-config': patch
3+
---
4+
5+
Proper ESM/CJS support on Node.js

.github/workflows/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
- name: Build
3131
run: yarn build
3232

33+
- name: Integrity check
34+
run: yarn bob check
35+
3336
lint:
3437
name: Lint
3538
uses: the-guild-org/shared-config/.github/workflows/lint.yml@main

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ out.txt
77
package-lock.json
88
.next/
99
*.log
10+
.bob

babel.config.cjs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', { targets: { node: process.versions.node.split('.')[0] } }],
4+
'@babel/preset-typescript',
5+
],
6+
};

jest.config.cjs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
const { pathsToModuleNameMapper } = require('ts-jest');
2+
const { resolve } = require('path');
3+
4+
const ROOT_DIR = __dirname;
5+
const TSCONFIG = resolve(ROOT_DIR, 'tsconfig.json');
6+
const tsconfig = require(TSCONFIG);
7+
18
// For a detailed explanation regarding each configuration property, visit:
29
// https://jestjs.io/docs/en/configuration.html
3-
410
module.exports = {
511
// Automatically clear mock calls and instances between every test
612
clearMocks: true,
@@ -17,6 +23,8 @@ module.exports = {
1723

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

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

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

3238
errorOnDeprecated: true,
39+
40+
resolver: 'bob-the-bundler/jest-resolver.js',
3341
};

package.json

+36-23
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,40 @@
33
"version": "4.3.3",
44
"description": "The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)",
55
"sideEffects": false,
6-
"main": "dist/index.js",
7-
"module": "dist/index.mjs",
8-
"typings": "dist/index.d.ts",
6+
"main": "dist/cjs/index.js",
7+
"module": "dist/esm/index.js",
98
"exports": {
109
".": {
11-
"require": "./dist/index.js",
12-
"import": "./dist/index.mjs"
10+
"require": {
11+
"types": "./dist/typings/index.d.cts",
12+
"default": "./dist/cjs/index.js"
13+
},
14+
"import": {
15+
"types": "./dist/typings/index.d.ts",
16+
"default": "./dist/esm/index.js"
17+
},
18+
"default": {
19+
"types": "./dist/typings/index.d.ts",
20+
"default": "./dist/esm/index.js"
21+
}
1322
},
14-
"./*": {
15-
"require": "./dist/*.js",
16-
"import": "./dist/*.mjs"
17-
}
23+
"./package.json": "./package.json"
1824
},
25+
"typings": "dist/typings/index.d.ts",
1926
"typescript": {
20-
"definition": "dist/index.d.ts"
27+
"definition": "dist/typings/index.d.ts"
28+
},
29+
"publishConfig": {
30+
"directory": "dist",
31+
"access": "public"
2132
},
33+
"type": "module",
2234
"scripts": {
2335
"prepublishOnly": "yarn build",
2436
"clean": "rimraf dist",
2537
"postinstall": "patch-package",
2638
"prebuild": "yarn clean && yarn json-schema",
27-
"build": "bob build --single",
28-
"prepack": "bob prepack",
39+
"build": "bob build",
2940
"prettier": "prettier --ignore-path .gitignore --write --list-different .",
3041
"prettier:check": "prettier --ignore-path .gitignore --check .",
3142
"lint": "eslint --ignore-path .gitignore .",
@@ -50,16 +61,21 @@
5061
"cosmiconfig-typescript-loader": "^3.1.0",
5162
"minimatch": "4.2.1",
5263
"ts-node": "^10.8.1",
53-
"string-env-interpolation": "1.0.1"
64+
"string-env-interpolation": "1.0.1",
65+
"tslib": "^2.4.0"
5466
},
5567
"devDependencies": {
68+
"@babel/core": "7.18.13",
69+
"@babel/preset-env": "7.18.10",
70+
"@babel/preset-typescript": "7.18.6",
5671
"@changesets/cli": "2.24.3",
5772
"@changesets/changelog-github": "0.4.6",
5873
"@types/jest": "28.1.7",
5974
"@types/node": "16.11.54",
6075
"@typescript-eslint/eslint-plugin": "5.34.0",
6176
"@typescript-eslint/parser": "5.34.0",
62-
"bob-the-bundler": "1.7.3",
77+
"babel-jest": "28.1.3",
78+
"bob-the-bundler": "4.0.0",
6379
"del": "6.1.1",
6480
"eslint": "8.22.0",
6581
"eslint-config-prettier": "8.5.0",
@@ -73,7 +89,6 @@
7389
"prettier": "2.7.1",
7490
"rimraf": "3.0.2",
7591
"ts-jest": "28.0.8",
76-
"tslib": "2.4.0",
7792
"typescript": "4.7.4",
7893
"typescript-json-schema": "0.54.0"
7994
},
@@ -94,10 +109,12 @@
94109
"url": "https://github.com/kamilkisiela"
95110
},
96111
"license": "MIT",
97-
"buildOptions": {
98-
"copy": [
99-
"config-schema.json"
100-
]
112+
"bob": {
113+
"build": {
114+
"copy": [
115+
"config-schema.json"
116+
]
117+
}
101118
},
102119
"lint-staged": {
103120
"{src,test}/**/*": [
@@ -109,10 +126,6 @@
109126
"pre-commit": "lint-staged"
110127
}
111128
},
112-
"publishConfig": {
113-
"directory": "dist",
114-
"access": "public"
115-
},
116129
"engines": {
117130
"node": ">= 10.0.0"
118131
}

src/config.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { dirname } from 'path';
2-
import type { IGraphQLConfig, GraphQLConfigResult } from './types';
3-
import { GraphQLProjectConfig } from './project-config';
2+
import type { IGraphQLConfig, GraphQLConfigResult } from './types.js';
3+
import { GraphQLProjectConfig } from './project-config.js';
44
import {
55
isMultipleProjectConfig,
66
isSingleProjectConfig,
@@ -9,11 +9,11 @@ import {
99
getConfigSync,
1010
findConfigSync,
1111
isLegacyProjectConfig,
12-
} from './helpers';
13-
import { ProjectNotFoundError, ConfigNotFoundError, ConfigEmptyError } from './errors';
14-
import { GraphQLExtensionDeclaration, GraphQLExtensionsRegistry } from './extension';
15-
import { EndpointsExtension } from './extensions/endpoints';
16-
import { isLegacyConfig } from './helpers/cosmiconfig';
12+
} from './helpers/index.js';
13+
import { ProjectNotFoundError, ConfigNotFoundError, ConfigEmptyError } from './errors.js';
14+
import { GraphQLExtensionDeclaration, GraphQLExtensionsRegistry } from './extension.js';
15+
import { EndpointsExtension } from './extensions/endpoints.js';
16+
import { isLegacyConfig } from './helpers/cosmiconfig.js';
1717

1818
const cwd = typeof process !== 'undefined' ? process.cwd() : undefined;
1919
const defaultConfigName = 'graphql';

src/extension.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
22
import { UrlLoader } from '@graphql-tools/url-loader';
33
import { JsonFileLoader } from '@graphql-tools/json-file-loader';
4-
import { LoadersRegistry } from './loaders';
4+
import { LoadersRegistry } from './loaders.js';
55

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

src/extensions/endpoints.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { GraphQLExtensionDeclaration } from '../extension';
2-
import type { WithList } from '../types';
1+
import type { GraphQLExtensionDeclaration } from '../extension.js';
2+
import type { WithList } from '../types.js';
33

44
export interface Endpoint {
55
url: string;

src/helpers/cosmiconfig.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { cosmiconfig, cosmiconfigSync, Loader, defaultLoaders } from 'cosmiconfig';
2-
import loadTs from 'cosmiconfig-typescript-loader';
2+
import unsecure_loadTs from 'cosmiconfig-typescript-loader';
33
import { loadToml } from 'cosmiconfig-toml-loader';
44
import { env } from 'string-env-interpolation';
55

6+
/** The underlying module gives us { default: } on ESM but no default on CJS :) */
7+
const loadTs: typeof unsecure_loadTs = (unsecure_loadTs as any)?.default ?? unsecure_loadTs;
68
export interface ConfigSearchResult {
79
config: any;
810
filepath: string;

src/helpers/find-config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ConfigNotFoundError, ConfigEmptyError, composeMessage } from '../errors';
2-
import { GraphQLConfigResult } from '../types';
3-
import { createCosmiConfig, createCosmiConfigSync, ConfigSearchResult } from './cosmiconfig';
1+
import { ConfigNotFoundError, ConfigEmptyError, composeMessage } from '../errors.js';
2+
import { GraphQLConfigResult } from '../types.js';
3+
import { createCosmiConfig, createCosmiConfigSync, ConfigSearchResult } from './cosmiconfig.js';
44

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

src/helpers/get-config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ConfigNotFoundError, ConfigEmptyError, composeMessage } from '../errors';
2-
import { GraphQLConfigResult } from '../types';
3-
import { ConfigSearchResult, createCosmiConfigSync, createCosmiConfig } from './cosmiconfig';
1+
import { ConfigNotFoundError, ConfigEmptyError, composeMessage } from '../errors.js';
2+
import { GraphQLConfigResult } from '../types.js';
3+
import { ConfigSearchResult, createCosmiConfigSync, createCosmiConfig } from './cosmiconfig.js';
44

55
export async function getConfig({
66
filepath,

src/helpers/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './find-config';
2-
export * from './get-config';
3-
export * from './utils';
1+
export * from './find-config.js';
2+
export * from './get-config.js';
3+
export * from './utils.js';

src/helpers/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IGraphQLConfig, IGraphQLProject, IGraphQLProjects, IGraphQLProjectLegacy } from '../types';
1+
import type { IGraphQLConfig, IGraphQLProject, IGraphQLProjects, IGraphQLProjectLegacy } from '../types.js';
22

33
export function isMultipleProjectConfig(config: IGraphQLConfig): config is IGraphQLProjects {
44
return typeof (config as IGraphQLProjects).projects === 'object';

src/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
export { GraphQLConfig, loadConfig, loadConfigSync } from './config';
2-
export { GraphQLProjectConfig } from './project-config';
3-
export { GraphQLExtensionDeclaration } from './extension';
1+
export { GraphQLConfig, loadConfig, loadConfigSync } from './config.js';
2+
export { GraphQLProjectConfig } from './project-config.js';
3+
export { GraphQLExtensionDeclaration } from './extension.js';
44
export { Source, Loader } from '@graphql-tools/utils';
5-
export * from './types';
6-
export * from './errors';
5+
export * from './types.js';
6+
export * from './errors.js';
7+
export { LoadersRegistry } from "./loaders.js"

src/loaders.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '@graphql-tools/load';
1414
import { mergeTypeDefs } from '@graphql-tools/merge';
1515
import { GraphQLSchema, DocumentNode, buildASTSchema, print } from 'graphql';
16-
import { MiddlewareFn, useMiddleware } from './helpers';
16+
import { MiddlewareFn, useMiddleware } from './helpers/index.js';
1717

1818
type Pointer = UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[];
1919
type LoadTypedefsOptions = Partial<ToolsLoadTypedefsOptions>;

src/project-config.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {
77
LoadTypedefsOptions as ToolsLoadTypedefsOptions,
88
UnnormalizedTypeDefPointer,
99
} from '@graphql-tools/load';
10-
import { ExtensionMissingError } from './errors';
11-
import type { GraphQLExtensionsRegistry } from './extension';
12-
import type { IExtensions, IGraphQLProject, IGraphQLProjectLegacy, WithList } from './types';
13-
import { isLegacyProjectConfig } from './helpers';
14-
import type { SchemaOutput } from './loaders';
10+
import { ExtensionMissingError } from './errors.js';
11+
import type { GraphQLExtensionsRegistry } from './extension.js';
12+
import type { IExtensions, IGraphQLProject, IGraphQLProjectLegacy, WithList } from './types.js';
13+
import { isLegacyProjectConfig } from './helpers/index.js';
14+
import type { SchemaOutput } from './loaders.js';
1515

1616
type Pointer = UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[];
1717
type LoadTypedefsOptions = Partial<ToolsLoadTypedefsOptions>;

test/config.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { buildSchema, buildASTSchema } from 'graphql';
22
import { resolve, basename } from 'path';
33
import { TempDir } from './utils/temp-dir';
44
import { runTests } from './utils/runner';
5-
import { loadConfig, loadConfigSync, ConfigNotFoundError } from '../src';
5+
import { loadConfig, loadConfigSync, ConfigNotFoundError } from 'graphql-config';
6+
import { beforeEach, beforeAll, test, describe, expect } from '@jest/globals';
67

78
const temp = new TempDir();
89

test/loaders.spec.ts

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import { parse, DirectiveDefinitionNode, buildSchema, GraphQLSchema, Kind } from 'graphql';
1+
import { DirectiveDefinitionNode, buildSchema, GraphQLSchema, Kind } from 'graphql';
22
import { Loader, Source } from '@graphql-tools/utils';
3+
import { beforeAll, test, describe, expect } from '@jest/globals';
4+
import { LoadersRegistry } from 'graphql-config';
35
import { loadTypedefsSync, loadSchemaSync, loadSchema, LoadSchemaOptions } from '@graphql-tools/load';
46

5-
const schema = buildSchema(/* GraphQL */ `
6-
type Query {
7-
foo: String
8-
}
9-
`);
7+
jest.mock('@graphql-tools/load', () => {
8+
const { parse, buildSchema } = require('graphql');
9+
const document = parse(/* GraphQL */ `
10+
type Query {
11+
foo: String @cache
12+
}
13+
`);
1014

11-
const document = parse(/* GraphQL */ `
12-
type Query {
13-
foo: String @cache
14-
}
15-
`);
15+
const schema = buildSchema(/* GraphQL */ `
16+
type Query {
17+
foo: String
18+
}
19+
`);
20+
21+
schema.isTheOne = true
1622

17-
jest.mock('@graphql-tools/load', () => {
1823
return {
1924
loadTypedefs: jest.fn(() => {
2025
return [{ document }];
@@ -31,7 +36,8 @@ jest.mock('@graphql-tools/load', () => {
3136
};
3237
});
3338

34-
import { LoadersRegistry } from '../src/loaders';
39+
40+
3541

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

73-
expect(received).toBe(schema);
74-
expect(receivedAsync).toBe(schema);
79+
expect(received.isTheOne).toEqual(true);
80+
expect(receivedAsync.isTheOne).toEqual(true);
81+
7582
});
7683
});
7784

85+
86+
7887
class CustomLoader implements Loader {
7988
private schema: GraphQLSchema;
8089

test/utils/runner.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe } from '@jest/globals';
2+
13
type PromiseOf<T extends (...args: any[]) => any> = T extends (...args: any[]) => Promise<infer R> ? R : ReturnType<T>;
24

35
export function runTests<

0 commit comments

Comments
 (0)