Skip to content

Commit 9bb5e2a

Browse files
committed
refactor: rename relativePath to rootDir like in typescript manner
BREAKING CHANGE: in `directoryToAst(module, opts)` was renamed option `relativePath` to `rootDir`
1 parent b06e895 commit 9bb5e2a

9 files changed

+478
-388
lines changed

Diff for: jest.config.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
module.exports = {
22
preset: 'ts-jest',
3+
testEnvironment: 'node',
34
globals: {
45
'ts-jest': {
56
tsconfig: '<rootDir>/tsconfig.json',
67
isolatedModules: true,
78
diagnostics: false,
89
},
910
},
10-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
11+
moduleFileExtensions: ['ts', 'js'],
1112
transform: {
12-
'^.+\\.ts$': 'ts-jest',
13+
'^.+\\.(ts|js)$': 'ts-jest',
1314
},
1415
roots: ['<rootDir>/src'],
1516
testPathIgnorePatterns: ['/node_modules/', '/lib/'],
1617
testMatch: ['**/__tests__/**/*-test.(ts|js)'],
18+
reporters: [
19+
'default',
20+
[
21+
'jest-junit',
22+
{
23+
outputDirectory: 'coverage/junit/',
24+
outputName: 'jest-junit.xml',
25+
classNameTemplate: '{classname} › {title}',
26+
titleTemplate: '{classname} › {title}',
27+
suiteName: '{filepath}',
28+
addFileAttribute: 'true',
29+
ancestorSeparator: ' › ',
30+
usePathForSuiteName: 'true',
31+
},
32+
],
33+
],
1734
};

Diff for: package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,25 @@
2121
"@types/glob": "7.1.4",
2222
"@types/jest": "27.0.2",
2323
"@types/lodash.sortby": "^4.7.6",
24-
"@types/node": "16.10.2",
25-
"@typescript-eslint/eslint-plugin": "4.32.0",
26-
"@typescript-eslint/parser": "4.32.0",
24+
"@types/node": "16.10.8",
25+
"@typescript-eslint/eslint-plugin": "5.0.0",
26+
"@typescript-eslint/parser": "5.0.0",
2727
"apollo-server": "2.25.0",
2828
"eslint": "7.32.0",
2929
"eslint-config-prettier": "8.3.0",
3030
"eslint-plugin-prettier": "4.0.0",
3131
"graphql": "15.6.0",
3232
"graphql-compose": "9.0.3",
33-
"jest": "27.2.4",
33+
"jest": "27.2.5",
34+
"jest-junit": "^13.0.0",
3435
"lodash.sortby": "^4.7.0",
3536
"prettier": "2.4.1",
3637
"rimraf": "3.0.2",
3738
"semantic-release": "17.4.7",
3839
"ts-jest": "27.0.5",
39-
"ts-node": "10.2.1",
40+
"ts-node": "10.3.0",
4041
"ts-node-dev": "1.1.8",
41-
"typescript": "4.4.3"
42+
"typescript": "4.4.4"
4243
},
4344
"scripts": {
4445
"watch": "jest --watch",

Diff for: src/__tests__/astMerge-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe('astMerge', () => {
77
let ast2: AstRootNode;
88

99
beforeEach(() => {
10-
ast1 = directoryToAst(module, { relativePath: './__fixtures__/merge/schema1' });
11-
ast2 = directoryToAst(module, { relativePath: './__fixtures__/merge/schema2' });
10+
ast1 = directoryToAst(module, { rootDir: './__fixtures__/merge/schema1' });
11+
ast2 = directoryToAst(module, { rootDir: './__fixtures__/merge/schema2' });
1212
});
1313

1414
it('should merge two schemas', () => {

Diff for: src/__tests__/astToSchema-test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dedent from 'dedent';
77

88
describe('astToSchema()', () => {
99
describe('Schema ./__testSchema__', () => {
10-
const ast = directoryToAst(module, { relativePath: './__testSchema__' });
10+
const ast = directoryToAst(module, { rootDir: './__testSchema__' });
1111
const sc = astToSchema(ast);
1212

1313
it('should return schema composer', () => {
@@ -97,7 +97,7 @@ describe('astToSchema()', () => {
9797

9898
it('should properly set name for nested fields with dot notation', () => {
9999
const ast = directoryToAst(module, {
100-
relativePath: './__testSchema__',
100+
rootDir: './__testSchema__',
101101
include: /query\.auth$|query\.auth\/nested/,
102102
});
103103
const sc = astToSchema(ast);
@@ -123,7 +123,7 @@ describe('astToSchema()', () => {
123123
describe('astToSchema()', () => {
124124
it('should properly add prefix for created TypeNames', () => {
125125
const ast = directoryToAst(module, {
126-
relativePath: './__testSchema__',
126+
rootDir: './__testSchema__',
127127
include: /query\.auth$|query\.auth\/nested/,
128128
});
129129
const sc = astToSchema(ast, { prefix: 'Corp', suffix: 'Old' });

Diff for: src/__tests__/astVisitor-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('astVisitor', () => {
1010
const schemaComposer = new SchemaComposer();
1111

1212
beforeEach(() => {
13-
ast = directoryToAst(module, { relativePath: './__testSchema__' });
13+
ast = directoryToAst(module, { rootDir: './__testSchema__' });
1414
schemaComposer.clear();
1515
});
1616

Diff for: src/__tests__/directoryToAst-test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { directoryToAst } from '../directoryToAst';
22

33
describe('directoryToAst()', () => {
44
describe('Schema ./__testSchema__', () => {
5-
const ast = directoryToAst(module, { relativePath: './__testSchema__' });
6-
75
it('should return root types', () => {
6+
const ast = directoryToAst(module, { rootDir: './__testSchema__' });
87
expect(Object.keys(ast.children)).toEqual(expect.arrayContaining(['query', 'mutation']));
98
});
109

1110
it('query has proper values', () => {
11+
const ast = directoryToAst(module, { rootDir: './__testSchema__' });
1212
expect(ast.children.query).toMatchSnapshot({
1313
name: 'query',
1414
kind: 'rootType',
@@ -55,6 +55,7 @@ describe('directoryToAst()', () => {
5555
});
5656

5757
it('mutation has proper values', () => {
58+
const ast = directoryToAst(module, { rootDir: './__testSchema__' });
5859
expect(ast.children.mutation).toMatchSnapshot({
5960
name: 'mutation',
6061
kind: 'rootType',

Diff for: src/directoryToAst.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const defaultOptions: DirectoryToAstOptions = {
4646

4747
export interface DirectoryToAstOptions {
4848
/** Scan relative directory to `module` which was provided as a first arg to directoryToAst method. By default `.` */
49-
relativePath?: string;
49+
rootDir?: string;
5050
/** Which file extensions should be loaded. By default: .js, .ts */
5151
extensions?: string[];
5252
/** Regexp or custom function which determines should be loaded file/dir or not */
@@ -65,10 +65,17 @@ export function directoryToAst(
6565
m: NodeModule,
6666
options: DirectoryToAstOptions = defaultOptions
6767
): AstRootNode {
68+
// @ts-ignore
69+
if (options?.relativePath) {
70+
throw new Error(
71+
'graphql-compose-modules: `relativePath` option is deprecated use `rootDir` instead'
72+
);
73+
}
74+
6875
// if no path was passed in, assume the equivalent of __dirname from caller
6976
// otherwise, resolve path relative to the equivalent of __dirname
70-
const schemaPath = options?.relativePath
71-
? resolve(dirname(m.filename), options.relativePath)
77+
const schemaPath = options?.rootDir
78+
? resolve(dirname(m.filename), options.rootDir)
7279
: dirname(m.filename);
7380

7481
// setup default options

Diff for: tsconfig.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
{
22
"compilerOptions": {
3-
"noEmit": true,
4-
"target": "es5",
3+
"target": "es2016",
54
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
67
"strict": true,
78
"rootDir": "./",
89
"lib": ["es2017"],
910
"skipLibCheck": true,
10-
"moduleResolution": "Node",
11-
"esModuleInterop": true,
1211
"forceConsistentCasingInFileNames": true,
1312
"baseUrl": "./",
13+
"sourceMap": true,
14+
"declaration": true,
15+
"declarationMap": true,
16+
"noFallthroughCasesInSwitch": true,
17+
"types": ["node", "jest"],
1418
"paths": {
1519
"graphql-compose-modules": ["./", "./src"]
16-
}
20+
},
1721
},
18-
"include": ["src/**/*", "examples/**/*"]
22+
"include": ["src/**/*", "examples/**/*"],
23+
"exclude": ["./node_modules"]
1924
}

0 commit comments

Comments
 (0)