Skip to content

Commit

Permalink
refactor: rename relativePath to rootDir like in typescript manner
Browse files Browse the repository at this point in the history
BREAKING CHANGE: in `directoryToAst(module, opts)` was renamed option `relativePath` to `rootDir`
  • Loading branch information
nodkz committed Oct 13, 2021
1 parent b06e895 commit 9bb5e2a
Show file tree
Hide file tree
Showing 9 changed files with 478 additions and 388 deletions.
21 changes: 19 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.json',
isolatedModules: true,
diagnostics: false,
},
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
moduleFileExtensions: ['ts', 'js'],
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.(ts|js)$': 'ts-jest',
},
roots: ['<rootDir>/src'],
testPathIgnorePatterns: ['/node_modules/', '/lib/'],
testMatch: ['**/__tests__/**/*-test.(ts|js)'],
reporters: [
'default',
[
'jest-junit',
{
outputDirectory: 'coverage/junit/',
outputName: 'jest-junit.xml',
classNameTemplate: '{classname} › {title}',
titleTemplate: '{classname} › {title}',
suiteName: '{filepath}',
addFileAttribute: 'true',
ancestorSeparator: ' › ',
usePathForSuiteName: 'true',
},
],
],
};
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
"@types/glob": "7.1.4",
"@types/jest": "27.0.2",
"@types/lodash.sortby": "^4.7.6",
"@types/node": "16.10.2",
"@typescript-eslint/eslint-plugin": "4.32.0",
"@typescript-eslint/parser": "4.32.0",
"@types/node": "16.10.8",
"@typescript-eslint/eslint-plugin": "5.0.0",
"@typescript-eslint/parser": "5.0.0",
"apollo-server": "2.25.0",
"eslint": "7.32.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "4.0.0",
"graphql": "15.6.0",
"graphql-compose": "9.0.3",
"jest": "27.2.4",
"jest": "27.2.5",
"jest-junit": "^13.0.0",
"lodash.sortby": "^4.7.0",
"prettier": "2.4.1",
"rimraf": "3.0.2",
"semantic-release": "17.4.7",
"ts-jest": "27.0.5",
"ts-node": "10.2.1",
"ts-node": "10.3.0",
"ts-node-dev": "1.1.8",
"typescript": "4.4.3"
"typescript": "4.4.4"
},
"scripts": {
"watch": "jest --watch",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/astMerge-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ describe('astMerge', () => {
let ast2: AstRootNode;

beforeEach(() => {
ast1 = directoryToAst(module, { relativePath: './__fixtures__/merge/schema1' });
ast2 = directoryToAst(module, { relativePath: './__fixtures__/merge/schema2' });
ast1 = directoryToAst(module, { rootDir: './__fixtures__/merge/schema1' });
ast2 = directoryToAst(module, { rootDir: './__fixtures__/merge/schema2' });
});

it('should merge two schemas', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/astToSchema-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dedent from 'dedent';

describe('astToSchema()', () => {
describe('Schema ./__testSchema__', () => {
const ast = directoryToAst(module, { relativePath: './__testSchema__' });
const ast = directoryToAst(module, { rootDir: './__testSchema__' });
const sc = astToSchema(ast);

it('should return schema composer', () => {
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('astToSchema()', () => {

it('should properly set name for nested fields with dot notation', () => {
const ast = directoryToAst(module, {
relativePath: './__testSchema__',
rootDir: './__testSchema__',
include: /query\.auth$|query\.auth\/nested/,
});
const sc = astToSchema(ast);
Expand All @@ -123,7 +123,7 @@ describe('astToSchema()', () => {
describe('astToSchema()', () => {
it('should properly add prefix for created TypeNames', () => {
const ast = directoryToAst(module, {
relativePath: './__testSchema__',
rootDir: './__testSchema__',
include: /query\.auth$|query\.auth\/nested/,
});
const sc = astToSchema(ast, { prefix: 'Corp', suffix: 'Old' });
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/astVisitor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('astVisitor', () => {
const schemaComposer = new SchemaComposer();

beforeEach(() => {
ast = directoryToAst(module, { relativePath: './__testSchema__' });
ast = directoryToAst(module, { rootDir: './__testSchema__' });
schemaComposer.clear();
});

Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/directoryToAst-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { directoryToAst } from '../directoryToAst';

describe('directoryToAst()', () => {
describe('Schema ./__testSchema__', () => {
const ast = directoryToAst(module, { relativePath: './__testSchema__' });

it('should return root types', () => {
const ast = directoryToAst(module, { rootDir: './__testSchema__' });
expect(Object.keys(ast.children)).toEqual(expect.arrayContaining(['query', 'mutation']));
});

it('query has proper values', () => {
const ast = directoryToAst(module, { rootDir: './__testSchema__' });
expect(ast.children.query).toMatchSnapshot({
name: 'query',
kind: 'rootType',
Expand Down Expand Up @@ -55,6 +55,7 @@ describe('directoryToAst()', () => {
});

it('mutation has proper values', () => {
const ast = directoryToAst(module, { rootDir: './__testSchema__' });
expect(ast.children.mutation).toMatchSnapshot({
name: 'mutation',
kind: 'rootType',
Expand Down
13 changes: 10 additions & 3 deletions src/directoryToAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const defaultOptions: DirectoryToAstOptions = {

export interface DirectoryToAstOptions {
/** Scan relative directory to `module` which was provided as a first arg to directoryToAst method. By default `.` */
relativePath?: string;
rootDir?: string;
/** Which file extensions should be loaded. By default: .js, .ts */
extensions?: string[];
/** Regexp or custom function which determines should be loaded file/dir or not */
Expand All @@ -65,10 +65,17 @@ export function directoryToAst(
m: NodeModule,
options: DirectoryToAstOptions = defaultOptions
): AstRootNode {
// @ts-ignore
if (options?.relativePath) {
throw new Error(
'graphql-compose-modules: `relativePath` option is deprecated use `rootDir` instead'
);
}

// if no path was passed in, assume the equivalent of __dirname from caller
// otherwise, resolve path relative to the equivalent of __dirname
const schemaPath = options?.relativePath
? resolve(dirname(m.filename), options.relativePath)
const schemaPath = options?.rootDir
? resolve(dirname(m.filename), options.rootDir)
: dirname(m.filename);

// setup default options
Expand Down
17 changes: 11 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
{
"compilerOptions": {
"noEmit": true,
"target": "es5",
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"rootDir": "./",
"lib": ["es2017"],
"skipLibCheck": true,
"moduleResolution": "Node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "./",
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"noFallthroughCasesInSwitch": true,
"types": ["node", "jest"],
"paths": {
"graphql-compose-modules": ["./", "./src"]
}
},
},
"include": ["src/**/*", "examples/**/*"]
"include": ["src/**/*", "examples/**/*"],
"exclude": ["./node_modules"]
}
Loading

0 comments on commit 9bb5e2a

Please sign in to comment.