UNPKG

snyk-docker-plugin

Version:
65 lines 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getApplicationFiles = exports.getAppFilesRootDir = void 0; const path = require("path"); function getAppFilesRootDir(filePaths) { const appFiles = []; const splitPaths = []; if (!filePaths.length) { return [path.sep, appFiles]; } for (const filePath of filePaths) { appFiles.push({ path: filePath }); splitPaths.push(filePath.split("/").filter(Boolean)); } // Find the shortest path length to prevent out-of-bounds access const minLength = Math.min(...splitPaths.map((path) => path.length)); // Find the common parts of the paths const commonParts = []; for (let i = 0; i < minLength - 1; i++) { const currentPart = splitPaths[0][i]; if (splitPaths.every((path) => path[i] === currentPart)) { commonParts.push(currentPart); } else { break; } } // Join the common parts to form the common directory const rootDir = "/" + commonParts.join("/"); // Remove the common path prefix from each appFile appFiles.forEach((file) => { const prefix = rootDir === path.sep ? rootDir : `${rootDir}${path.sep}`; if (file.path.startsWith(prefix)) { file.path = file.path.substring(prefix.length); // Remove rootDir from path } }); return [rootDir || path.sep, appFiles]; } exports.getAppFilesRootDir = getAppFilesRootDir; function getApplicationFiles(filePathToContent, language, identityType) { const scanResults = []; const [appFilesRootDir, appFiles] = getAppFilesRootDir(Object.keys(filePathToContent)); if (appFiles.length) { scanResults.push({ facts: [ { type: "applicationFiles", data: [ { language, fileHierarchy: appFiles, }, ], }, ], identity: { type: identityType, targetFile: appFilesRootDir, }, }); } return scanResults; } exports.getApplicationFiles = getApplicationFiles; //# sourceMappingURL=runtime-common.js.map