Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("returns false when filePath is not a shimmed executable", () => {
const filePath = path.resolve("./packages/package-1/node_modules/.bin/package-2");
fs.lstatSync.mockImplementation(() => ({
isSymbolicLink: () => false,
isFile: () => true,
}));
readCmdShim.sync.mockImplementation(() => {
throw new Error("ENOTASHIM");
});
expect(FileSystemUtilities.isSymlink(filePath)).toBe(false);
});
it("returns resolved path of a shimmed executable", () => {
const original = path.resolve("./packages/package-2/cli.js");
const filePath = path.resolve("./packages/package-1/node_modules/.bin/package-2.cmd");
fs.lstatSync.mockImplementation(() => ({
isSymbolicLink: () => false,
isFile: () => true,
}));
readCmdShim.sync.mockImplementation(() => linkRelative(original, filePath));
expect(FileSystemUtilities.isSymlink(filePath)).toBe(original);
});
});
function resolveWindowsSymlink(filePath) {
const { resolvedPath, lstat } = resolveSymbolicLink(filePath);
if (lstat.isFile() && !resolvedPath) {
try {
return path.resolve(path.dirname(filePath), readCmdShim.sync(filePath));
} catch (e) {
return false;
}
}
return resolvedPath && path.resolve(resolvedPath);
}
function resolveWindowsSymlink(filePath) {
const { resolvedPath, lstat } = resolveSymbolicLink(filePath);
if (lstat.isFile() && !resolvedPath) {
try {
return path.resolve(path.dirname(filePath), readCmdShim.sync(filePath));
} catch (e) {
return false;
}
}
return resolvedPath && path.resolve(resolvedPath);
}
return promisify(cb => _readCmdShim(filePath, cb));
}