Skip to content

Commit

Permalink
Factor out fileMatchesConfigGlob
Browse files Browse the repository at this point in the history
  • Loading branch information
smikula committed Oct 11, 2017
1 parent 5dc81a4 commit fe82695
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/fileMatchesConfigGlob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as path from 'path';

export default function fileMatchesConfigGlob(importFile: string, configPath: string, key: string) {
// Remove the file extension before matching
importFile = importFile.substr(0, importFile.length - path.extname(importFile).length);
return path.resolve(configPath, key) == importFile;
}
9 changes: 2 additions & 7 deletions src/validateImportIsAccessible.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path';
import Config from './types/Config';
import getConfigsForFile from './getConfigsForFile';
import fileMatchesConfigGlob from './fileMatchesConfigGlob';
import fileMatchesTag from './fileMatchesTag';
import reportError from './reportError';

Expand Down Expand Up @@ -41,7 +42,7 @@ function hasMatchingExport(config: Config, sourceFile: string, importFile: strin
let tags = config.exports[key];

if (
keyMatchesImportFile(config.path, key, importFile) &&
fileMatchesConfigGlob(importFile, config.path, key) &&
fileMatchesTag(sourceFile, tags)
) {
isExported = true;
Expand All @@ -50,9 +51,3 @@ function hasMatchingExport(config: Config, sourceFile: string, importFile: strin

return isExported;
}

function keyMatchesImportFile(configPath: string, key: string, importFile: string) {
// Remove the file extension before matching
importFile = importFile.substr(0, importFile.length - path.extname(importFile).length);
return path.resolve(configPath, key) == importFile;
}

0 comments on commit fe82695

Please sign in to comment.