@file-services/overlay
Advanced tools
Comparing version 7.0.0 to 7.0.1
@@ -5,2 +5,3 @@ "use strict"; | ||
const utils_1 = require("@file-services/utils"); | ||
const getEntryName = (item) => item.name; | ||
function createOverlayFs(lowerFs, upperFs, baseDirectoryPath = lowerFs.cwd()) { | ||
@@ -34,3 +35,3 @@ const { promises: lowerPromises } = lowerFs; | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
const { stackTraceLimit } = Error; | ||
@@ -52,3 +53,3 @@ try { | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -68,3 +69,3 @@ const stats = upperFs.statSync(resolvedUpperPath, ...args); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -84,3 +85,3 @@ const stats = upperFs.lstatSync(resolvedUpperPath, ...args); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
const { stackTraceLimit } = Error; | ||
@@ -102,3 +103,3 @@ try { | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
const { stackTraceLimit } = Error; | ||
@@ -118,11 +119,16 @@ try { | ||
}, | ||
readdirSync: ((path, ...args) => { | ||
readdirSync: ((path, options) => { | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
const { stackTraceLimit } = Error; | ||
try { | ||
Error.stackTraceLimit = 0; | ||
const resInUpper = upperFs.readdirSync(resolvedUpperPath, ...args); | ||
const resInUpper = upperFs.readdirSync(resolvedUpperPath, options); | ||
try { | ||
return [...lowerFs.readdirSync(resolvedLowerPath, ...args), ...resInUpper]; | ||
const resInLower = lowerFs.readdirSync(resolvedLowerPath, options); | ||
if (options !== null && typeof options === 'object' && options.withFileTypes) { | ||
const namesInUpper = new Set(resInUpper.map(getEntryName)); | ||
return [...resInLower.filter((item) => !namesInUpper.has(item.name)), ...resInUpper]; | ||
} | ||
return Array.from(new Set([...resInLower, ...resInUpper])); | ||
} | ||
@@ -140,3 +146,3 @@ catch { | ||
} | ||
return lowerFs.readdirSync(resolvedLowerPath, ...args); | ||
return lowerFs.readdirSync(resolvedLowerPath, options); | ||
}), | ||
@@ -156,3 +162,3 @@ }; | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -169,3 +175,3 @@ return await upperPromises.readFile(resolvedUpperPath, ...args); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -182,3 +188,3 @@ return await upperPromises.stat(resolvedUpperPath); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -195,3 +201,3 @@ return await upperPromises.lstat(resolvedUpperPath); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -208,3 +214,3 @@ return lowerFs.join(baseDirectoryPath, await upperPromises.realpath(resolvedUpperPath)); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -219,9 +225,14 @@ return await upperPromises.readlink(resolvedUpperPath); | ||
}, | ||
readdir: async function readdir(path, ...args) { | ||
readdir: async function readdir(path, options) { | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
const resInUpper = await upperPromises.readdir(resolvedUpperPath, ...args); | ||
const resInUpper = await upperPromises.readdir(resolvedUpperPath, options); | ||
try { | ||
return [...(await lowerPromises.readdir(resolvedLowerPath, ...args)), ...resInUpper]; | ||
const resInLower = await lowerPromises.readdir(resolvedLowerPath, options); | ||
if (options !== null && typeof options === 'object' && options.withFileTypes) { | ||
const namesInUpper = new Set(resInUpper.map(getEntryName)); | ||
return [...resInLower.filter((item) => !namesInUpper.has(item.name)), ...resInUpper]; | ||
} | ||
return Array.from(new Set([...resInLower, ...resInUpper])); | ||
} | ||
@@ -237,3 +248,3 @@ catch { | ||
} | ||
return lowerPromises.readdir(resolvedLowerPath, ...args); | ||
return lowerPromises.readdir(resolvedLowerPath, options); | ||
}, | ||
@@ -355,3 +366,3 @@ }; | ||
if (resolvedUpperPath !== undefined) { | ||
upperFs.readdir(resolvedUpperPath, options, (upperError, upperItems) => { | ||
upperFs.readdir(resolvedUpperPath, options, (upperError, resInUpper) => { | ||
if (upperError) { | ||
@@ -361,8 +372,16 @@ lowerFs.readdir(resolvedLowerPath, options, callback); | ||
else { | ||
lowerFs.readdir(resolvedLowerPath, options, (lowerError, lowerItems) => { | ||
lowerFs.readdir(resolvedLowerPath, options, (lowerError, resInLower) => { | ||
if (lowerError) { | ||
callback(upperError, upperItems); | ||
callback(upperError, resInUpper); | ||
} | ||
else { | ||
callback(upperError, [...lowerItems, ...upperItems]); | ||
if (options !== null && typeof options === 'object' && options.withFileTypes) { | ||
const namesInUpper = new Set(resInUpper.map(getEntryName)); | ||
const combined = [...resInLower.filter((item) => !namesInUpper.has(item.name)), ...resInUpper]; | ||
callback(upperError, combined); | ||
} | ||
else { | ||
const combined = Array.from(new Set([...resInLower, ...resInUpper])); | ||
callback(upperError, combined); | ||
} | ||
} | ||
@@ -369,0 +388,0 @@ }); |
{ | ||
"name": "@file-services/overlay", | ||
"description": "Overlay files and directories from one file system on top of another.", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"main": "dist/index.js", | ||
@@ -12,4 +12,4 @@ "scripts": { | ||
"dependencies": { | ||
"@file-services/types": "^7.0.0", | ||
"@file-services/utils": "^7.0.0" | ||
"@file-services/types": "^7.0.1", | ||
"@file-services/utils": "^7.0.1" | ||
}, | ||
@@ -16,0 +16,0 @@ "files": [ |
@@ -13,2 +13,4 @@ import type { | ||
const getEntryName = (item: IDirectoryEntry) => item.name; | ||
export function createOverlayFs( | ||
@@ -46,5 +48,5 @@ lowerFs: IFileSystem, | ||
}, | ||
readFileSync: function readFileSync(path: string, ...args: [ReadFileOptions]): string | Buffer { | ||
readFileSync: function readFileSync(path, ...args) { | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
const { stackTraceLimit } = Error; | ||
@@ -64,3 +66,3 @@ try { | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -79,3 +81,3 @@ const stats = upperFs.statSync(resolvedUpperPath, ...args); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -94,3 +96,3 @@ const stats = upperFs.lstatSync(resolvedUpperPath, ...args); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
const { stackTraceLimit } = Error; | ||
@@ -110,3 +112,3 @@ try { | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
const { stackTraceLimit } = Error; | ||
@@ -124,11 +126,16 @@ try { | ||
}, | ||
readdirSync: ((path: string, ...args: [{ withFileTypes: true }]) => { | ||
readdirSync: ((path, options: { withFileTypes: true }) => { | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
const { stackTraceLimit } = Error; | ||
try { | ||
Error.stackTraceLimit = 0; | ||
const resInUpper = upperFs.readdirSync(resolvedUpperPath, ...args); | ||
const resInUpper = upperFs.readdirSync(resolvedUpperPath, options); | ||
try { | ||
return [...lowerFs.readdirSync(resolvedLowerPath, ...args), ...resInUpper]; | ||
const resInLower = lowerFs.readdirSync(resolvedLowerPath, options); | ||
if (options !== null && typeof options === 'object' && options.withFileTypes) { | ||
const namesInUpper = new Set<string>(resInUpper.map(getEntryName)); | ||
return [...resInLower.filter((item) => !namesInUpper.has(item.name)), ...resInUpper]; | ||
} | ||
return Array.from(new Set([...resInLower, ...resInUpper])); | ||
} catch { | ||
@@ -143,3 +150,3 @@ return resInUpper; | ||
} | ||
return lowerFs.readdirSync(resolvedLowerPath, ...args); | ||
return lowerFs.readdirSync(resolvedLowerPath, options); | ||
}) as IBaseFileSystemSyncActions['readdirSync'], | ||
@@ -159,3 +166,3 @@ }; | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -171,3 +178,3 @@ return await upperPromises.readFile(resolvedUpperPath, ...args); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -183,3 +190,3 @@ return await upperPromises.stat(resolvedUpperPath); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -195,3 +202,3 @@ return await upperPromises.lstat(resolvedUpperPath); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -207,3 +214,3 @@ return lowerFs.join(baseDirectoryPath, await upperPromises.realpath(resolvedUpperPath)); | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
@@ -217,9 +224,14 @@ return await upperPromises.readlink(resolvedUpperPath); | ||
}, | ||
readdir: async function readdir(path: string, ...args: [{ withFileTypes: false }]) { | ||
readdir: async function readdir(path: string, options: { withFileTypes: true }) { | ||
const { resolvedLowerPath, resolvedUpperPath } = resolvePaths(path); | ||
if (resolvedUpperPath !== undefined) { | ||
if (resolvedUpperPath !== undefined && upperFs.existsSync(resolvedUpperPath)) { | ||
try { | ||
const resInUpper = await upperPromises.readdir(resolvedUpperPath, ...args); | ||
const resInUpper = await upperPromises.readdir(resolvedUpperPath, options); | ||
try { | ||
return [...(await lowerPromises.readdir(resolvedLowerPath, ...args)), ...resInUpper]; | ||
const resInLower = await lowerPromises.readdir(resolvedLowerPath, options); | ||
if (options !== null && typeof options === 'object' && options.withFileTypes) { | ||
const namesInUpper = new Set<string>(resInUpper.map(getEntryName)); | ||
return [...resInLower.filter((item) => !namesInUpper.has(item.name)), ...resInUpper]; | ||
} | ||
return Array.from(new Set([...resInLower, ...resInUpper])); | ||
} catch { | ||
@@ -233,3 +245,3 @@ /**/ | ||
} | ||
return lowerPromises.readdir(resolvedLowerPath, ...args); | ||
return lowerPromises.readdir(resolvedLowerPath, options); | ||
} as IBaseFileSystemPromiseActions['readdir'], | ||
@@ -346,3 +358,3 @@ }; | ||
if (resolvedUpperPath !== undefined) { | ||
upperFs.readdir(resolvedUpperPath, options as { withFileTypes: true }, (upperError, upperItems) => { | ||
upperFs.readdir(resolvedUpperPath, options as { withFileTypes: true }, (upperError, resInUpper) => { | ||
if (upperError) { | ||
@@ -355,7 +367,14 @@ lowerFs.readdir( | ||
} else { | ||
lowerFs.readdir(resolvedLowerPath, options as { withFileTypes: true }, (lowerError, lowerItems) => { | ||
lowerFs.readdir(resolvedLowerPath, options as { withFileTypes: true }, (lowerError, resInLower) => { | ||
if (lowerError) { | ||
(callback as CallbackFn<IDirectoryEntry[]>)(upperError, upperItems); | ||
(callback as CallbackFn<IDirectoryEntry[]>)(upperError, resInUpper); | ||
} else { | ||
(callback as CallbackFn<IDirectoryEntry[]>)(upperError, [...lowerItems, ...upperItems]); | ||
if (options !== null && typeof options === 'object' && options.withFileTypes) { | ||
const namesInUpper = new Set<string>(resInUpper.map(getEntryName)); | ||
const combined = [...resInLower.filter((item) => !namesInUpper.has(item.name)), ...resInUpper]; | ||
(callback as CallbackFn<IDirectoryEntry[]>)(upperError, combined); | ||
} else { | ||
const combined = Array.from(new Set([...resInLower, ...resInUpper])); | ||
(callback as CallbackFn<IDirectoryEntry[]>)(upperError, combined); | ||
} | ||
} | ||
@@ -362,0 +381,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47929
787
Updated@file-services/types@^7.0.1
Updated@file-services/utils@^7.0.1