Skip to content

Commit a598de4

Browse files
author
Divyendu Singh
committed
feat: find config in subdir - remove dep on fs-finder
1 parent e4a38c6 commit a598de4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"typescript": "2.7.2"
5050
},
5151
"dependencies": {
52-
"fs-finder": "^1.8.1",
5352
"graphql-import": "^0.4.4",
5453
"graphql-request": "^1.5.0",
5554
"js-yaml": "^3.10.0",

src/findGraphQLConfigFile.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { resolve, join as joinPaths, dirname, basename } from 'path'
2-
import { existsSync } from 'fs'
3-
import * as Finder from 'fs-finder'
1+
import { resolve, join as joinPaths, dirname, basename, join } from 'path'
2+
import { existsSync, readdirSync, lstatSync } from 'fs'
43

54
import {
65
ConfigNotFoundError
@@ -41,12 +40,20 @@ export function findGraphQLConfigFile(filePath: string): string {
4140
}
4241

4342
// Try to find GraphQL config in first level of sub-directories.
44-
const subDirectories = Finder.in(filePath).showSystemFiles().findDirectories()
43+
const subDirectories = readdirSync(filePath).map(dir => joinPaths(filePath, dir)).filter(dir => {
44+
return (lstatSync(dir).isDirectory())
45+
})
4546
const subDirectoriesWithGraphQLConfig = subDirectories.map(subDirectory => {
46-
const subDirectoryFiles = Finder.in(subDirectory).showSystemFiles().findFiles().map(file => basename(file))
47+
const subDirectoryFiles = readdirSync(subDirectory)
48+
.filter(file => {
49+
return !(lstatSync(joinPaths(subDirectory, file)).isDirectory())
50+
})
51+
.map(file => {
52+
return basename(joinPaths(subDirectory, file))
53+
})
4754
if (subDirectoryFiles.includes(GRAPHQL_CONFIG_NAME)) {
4855
return `${subDirectory}/${GRAPHQL_CONFIG_NAME}`
49-
}
56+
}
5057
if (subDirectoryFiles.includes(`${GRAPHQL_CONFIG_NAME}.yml`)) {
5158
return `${subDirectory}/${GRAPHQL_CONFIG_NAME}.yml`
5259
}
@@ -55,7 +62,7 @@ export function findGraphQLConfigFile(filePath: string): string {
5562
}
5663
})
5764
if (subDirectoriesWithGraphQLConfig.length > 0) {
58-
return subDirectoriesWithGraphQLConfig[0]
65+
return subDirectoriesWithGraphQLConfig[0] as string
5966
}
6067

6168
throw new ConfigNotFoundError(

0 commit comments

Comments
 (0)