Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3776553
commit 82625aa
Showing
6 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"coffee", | ||
"es6", | ||
"es7", | ||
"graphql", | ||
"jsx", | ||
"sass", | ||
"typescript", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { readFileSync } = require('fs'); | ||
const requirePackageName = require('require-package-name'); | ||
const JSON5 = require('json5'); | ||
|
||
export default function graphqlParser(filePath) { | ||
const foundDeps = []; | ||
const content = readFileSync(filePath, { encoding: 'utf8' }); | ||
const lines = content.split(/\r\n|\r|\n/); | ||
lines.some((line) => { | ||
if (line[0] === '#' && line.slice(1).split(' ')[0] === 'import') { | ||
const importFileExpr = line.slice(1).split(' ')[1]; | ||
if (importFileExpr) { | ||
// Need to support single and double quotes, so use JSON5 | ||
const importFile = JSON5.parse(importFileExpr); | ||
if (importFile && typeof importFile === 'string') { | ||
foundDeps.push(importFile); | ||
} | ||
} | ||
} | ||
return line.length !== 0 && line[0] !== '#'; | ||
}); | ||
return foundDeps.map((p) => requirePackageName(p)).filter(Boolean); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "graphql-depcheck-test", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"unused": "*", | ||
"@scope/ok": "*", | ||
"ok": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import "./foo.graphql" | ||
#import "ok/test.graphql" | ||
#import "@scope/ok/test.graphql" | ||
#import "@scope/missing/missing.graphql" | ||
#import "missing/missing.graphql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters