Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return {filePath: builtins[filename]};
}
let parts = this.getModuleParts(filename);
let root = path.parse(dir).root;
while (dir !== root) {
// Skip node_modules directories
if (path.basename(dir) === 'node_modules') {
dir = path.dirname(dir);
}
try {
// First, check if the module directory exists. This prevents a lot of unnecessary checks later.
let moduleDir = path.join(dir, 'node_modules', parts[0]);
let stats = await fs.stat(moduleDir);
if (stats.isDirectory()) {
return {
moduleName: parts[0],
subPath: parts[1],
moduleDir: moduleDir,
filePath: path.join(dir, 'node_modules', filename)
};
}
} catch (err) {
// ignore
}
// Move up a directory
dir = path.dirname(dir);
}
}
async read(filename) {
if (this.invalidated.has(filename)) {
return null;
}
let cacheFile = this.getCacheFile(filename);
try {
let stats = await fs.stat(filename);
let cacheStats = await fs.stat(cacheFile);
if (stats.mtime > cacheStats.mtime) {
return null;
}
let json = await fs.readFile(cacheFile);
let data = JSON.parse(json);
if (!(await this.checkDepMtimes(data))) {
return null;
}
return data;
} catch (err) {
return null;
}
async getLastModified(filename) {
if (isGlob(filename)) {
let files = await glob(filename, {
onlyFiles: true,
});
return (
await Promise.all(
files.map(file => fs.stat(file).then(({mtime}) => mtime.getTime())),
)
).reduce((a, b) => Math.max(a, b), 0);
}
return (await fs.stat(filename)).mtime.getTime();
}
async read(filename) {
if (this.invalidated.has(filename)) {
return null;
}
let cacheFile = this.getCacheFile(filename);
try {
let stats = await fs.stat(filename);
let cacheStats = await fs.stat(cacheFile);
if (stats.mtime > cacheStats.mtime) {
return null;
}
let json = await fs.readFile(cacheFile);
let data = JSON.parse(json);
if (!(await this.checkDepMtimes(data))) {
return null;
}
return data;
} catch (err) {
return null;
}
}
files.map(file => fs.stat(file).then(({mtime}) => mtime.getTime())),
)
files.map(file => fs.stat(file).then(({mtime}) => mtime.getTime()))
)).reduce((a, b) => Math.max(a, b), 0);
async getLastModified(filename) {
if (isGlob(filename)) {
let files = await glob(filename, {
onlyFiles: true
});
return (await Promise.all(
files.map(file => fs.stat(file).then(({mtime}) => mtime.getTime()))
)).reduce((a, b) => Math.max(a, b), 0);
}
return (await fs.stat(filename)).mtime.getTime();
}
async read(filename) {
if (this.invalidated.has(filename)) {
return null;
}
let cacheFile = this.getCacheFile(filename);
try {
let stats = await fs.stat(filename);
let cacheStats = await fs.stat(cacheFile);
if (stats.mtime > cacheStats.mtime) {
return null;
}
let json = await fs.readFile(cacheFile);
let data = JSON.parse(json);
if (!(await this.checkDepMtimes(data))) {
return null;
}
return data;
} catch (err) {
return null;
}
}