Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
filterDefinitions: ({ repo, filePath, fileContent, results }) => {
const currentFileImportedPaths = fileContent
.split(/\r?\n/)
.map(line => {
// Matches the import at index 3
const match = /^(import |\t)(\w+ |\. )?"(.*)"$/.exec(
line
)
return match ? match[3] : undefined
})
.filter((x): x is string => Boolean(x))
const currentFileImportPath =
repo + '/' + path.dirname(filePath)
const filteredResults = results.filter(result => {
const resultImportPath =
result.repo + '/' + path.dirname(result.file)
return [
...currentFileImportedPaths,
currentFileImportPath,
].some(i => resultImportPath === i)
})
return filteredResults.length === 0 ? results : filteredResults
},
},
async function gitPkgUp(gitInfo, filePath) {
// Return true if a list of file paths contains a package.json file
const filesContainPkgJson = files =>
files.some(file => path.basename(file.path) === 'package.json');
let curPath = path.dirname(filePath);
let filesInDir = await getBitbucketDir(gitInfo, curPath);
while (!filesContainPkgJson(filesInDir) && curPath !== '.') {
curPath = path.dirname(curPath);
filesInDir = await getBitbucketDir(gitInfo, curPath);
}
if (!filesContainPkgJson(filesInDir)) {
throw new Error('Unable to find a package.json');
}
return path.join(curPath, 'package.json').replace('./', '');
}
async function gitPkgUp(gitInfo, filePath) {
// Return true if a list of file paths contains a package.json file
const filesContainPkgJson = files =>
files.some(file => path.basename(file.path) === 'package.json');
let curPath = path.dirname(filePath);
let filesInDir = await getBitbucketDir(gitInfo, curPath);
while (!filesContainPkgJson(filesInDir) && curPath !== '.') {
curPath = path.dirname(curPath);
filesInDir = await getBitbucketDir(gitInfo, curPath);
}
if (!filesContainPkgJson(filesInDir)) {
throw new Error('Unable to find a package.json');
}
return path.join(curPath, 'package.json').replace('./', '');
}
function supportRelativeURL(file, url) {
if (!file) return url;
var dir = path.dirname(file);
var match = /^\w+:\/\/[^\/]*/.exec(dir);
var protocol = match ? match[0] : '';
return protocol + path.resolve(dir.slice(protocol.length), url);
}
const filteredResults = results.filter(result => {
const resultImportPath =
result.repo + '/' + path.dirname(result.file)
return [
...currentFileImportedPaths,
currentFileImportPath,
].some(i => resultImportPath === i)
})
return [...currentFileImports, currentPackage].some(i =>
path
.dirname(result.file)
.replace(/\//g, '.')
.endsWith(i)
)