1- import { relative , dirname } from "path" ;
1+ import { relative } from "path" ;
22import minimatch = require( "minimatch" ) ;
33import * as glob from "glob" ;
44import { invariant } from "@apollographql/apollo-tools" ;
55import URI from "vscode-uri" ;
66
77export class FileSet {
8- private configDirURI ?: URI ;
98 private rootURI : URI ;
109 private includes : string [ ] ;
1110 private excludes : string [ ] ;
1211
1312 constructor ( {
14- configURI,
1513 rootURI,
1614 includes,
1715 excludes
1816 } : {
19- configURI ?: URI ;
2017 rootURI : URI ;
2118 includes : string [ ] ;
2219 excludes : string [ ] ;
@@ -25,24 +22,14 @@ export class FileSet {
2522 invariant ( includes , `Must provide "includes".` ) ;
2623 invariant ( excludes , `Must provide "excludes".` ) ;
2724
28- // the URI of the folder _containing_ the apollo.config.js
29- this . configDirURI =
30- configURI && configURI . fsPath . includes ( ".js" )
31- ? URI . parse ( dirname ( configURI . fsPath ) )
32- : configURI ;
3325 this . rootURI = rootURI ;
3426 this . includes = includes ;
3527 this . excludes = excludes ;
3628 }
3729
38- includesFile ( filePath : string , configDirURI ?: URI ) : boolean {
39- // if we're given a path to the config file, we should match the
40- // "includes" glob relative to that dir. This allows us to run this command
41- // from a "root" dir above the root of the project, like when at the root of a monorepo
42- filePath = relative (
43- configDirURI ? configDirURI . path : this . rootURI . fsPath ,
44- filePath
45- ) ;
30+ includesFile ( filePath : string ) : boolean {
31+ filePath = relative ( this . rootURI . fsPath , filePath ) ;
32+
4633 return (
4734 this . includes . some ( include => minimatch ( filePath , include ) ) &&
4835 ! this . excludes . some ( exclude => minimatch ( filePath , exclude ) )
@@ -52,25 +39,12 @@ export class FileSet {
5239 allFiles ( ) : string [ ] {
5340 return this . includes
5441 . flatMap ( include =>
55- glob . sync ( include , {
56- cwd : this . configDirURI
57- ? this . configDirURI . fsPath
58- : this . rootURI . fsPath ,
59- absolute : true
60- } )
42+ glob . sync ( include , { cwd : this . rootURI . fsPath , absolute : true } )
6143 )
6244 . filter (
6345 filePath =>
6446 ! this . excludes . some ( exclude =>
65- minimatch (
66- relative (
67- this . configDirURI
68- ? this . configDirURI . fsPath
69- : this . rootURI . fsPath ,
70- filePath
71- ) ,
72- exclude
73- )
47+ minimatch ( relative ( this . rootURI . fsPath , filePath ) , exclude )
7448 )
7549 ) ;
7650 }
0 commit comments