@file-services/memory
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -18,3 +18,3 @@ "use strict"; | ||
const baseFs = createBaseMemoryFs(); | ||
const fs = Object.assign({}, utils_1.createFileSystem(baseFs), { root: baseFs.root }); | ||
const fs = Object.assign(Object.assign({}, utils_1.createFileSystem(baseFs)), { root: baseFs.root }); | ||
if (rootContents) { | ||
@@ -32,3 +32,3 @@ fs.populateDirectorySync(posix_path_1.default.POSIX_ROOT, rootContents); | ||
const syncMemFs = createBaseMemoryFsSync(); | ||
return Object.assign({}, syncMemFs, utils_1.syncToAsyncFs(syncMemFs)); | ||
return Object.assign(Object.assign({}, syncMemFs), utils_1.syncToAsyncFs(syncMemFs)); | ||
} | ||
@@ -45,3 +45,3 @@ exports.createBaseMemoryFs = createBaseMemoryFs; | ||
let workingDirectoryPath = posix_path_1.default.POSIX_ROOT; | ||
return Object.assign({ root }, posix_path_1.default, { resolve: resolvePath, watchService: { | ||
return Object.assign(Object.assign({ root }, posix_path_1.default), { resolve: resolvePath, watchService: { | ||
async watchPath(path, listener) { | ||
@@ -99,6 +99,6 @@ const resolvedPath = resolvePath(path); | ||
if (!fileNode) { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
} | ||
else if (fileNode.type === 'dir') { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -112,3 +112,3 @@ return fileNode.contents; | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -136,3 +136,3 @@ const fileName = posix_path_1.default.basename(resolvedPath); | ||
else { | ||
throw new Error(`${resolvedPath} EISDIR ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -145,3 +145,3 @@ } | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
} | ||
@@ -152,6 +152,6 @@ const fileName = posix_path_1.default.basename(resolvedPath); | ||
if (!fileNode) { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
} | ||
else if (fileNode.type === 'dir') { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -165,6 +165,6 @@ parentNode.contents.delete(lowerCaseFileName); | ||
if (!directoryNode) { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
} | ||
else if (directoryNode.type === 'file') { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_FILE}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_FILE}`, 'ENOTDIR'); | ||
} | ||
@@ -181,3 +181,3 @@ const childNodes = Array.from(directoryNode.contents.values()); | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -188,3 +188,3 @@ const directoryName = posix_path_1.default.basename(resolvedPath); | ||
if (currentNode) { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
} | ||
@@ -200,3 +200,3 @@ const newDirNode = createMemDirectory(directoryName); | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -207,6 +207,6 @@ const directoryName = posix_path_1.default.basename(resolvedPath); | ||
if (!directoryNode || directoryNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
} | ||
else if (directoryNode.contents.size > 0) { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.DIRECTORY_NOT_EMPTY}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
} | ||
@@ -223,3 +223,3 @@ parentNode.contents.delete(lowerCaseDirectoryName); | ||
if (!node) { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -236,3 +236,3 @@ const { birthtime, mtime } = node; | ||
if (!node) { | ||
throw new Error(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -247,3 +247,3 @@ return resolvedPath; | ||
if (!sourceParentNode || sourceParentNode.type !== 'dir') { | ||
throw new Error(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -254,3 +254,3 @@ const sourceName = posix_path_1.default.basename(resolvedSourcePath); | ||
if (!sourceNode) { | ||
throw new Error(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -260,3 +260,3 @@ const destinationParentPath = posix_path_1.default.dirname(resolvedDestinationPath); | ||
if (!destinationParentNode || destinationParentNode.type !== 'dir') { | ||
throw new Error(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -269,7 +269,7 @@ const destinationName = posix_path_1.default.basename(resolvedDestinationPath); | ||
if (destinationNode.contents.size > 0) { | ||
throw new Error(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.DIRECTORY_NOT_EMPTY}`); | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
} | ||
} | ||
else { | ||
throw new Error(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
} | ||
@@ -289,6 +289,6 @@ } | ||
if (!sourceFileNode) { | ||
throw new Error(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
if (sourceFileNode.type !== 'file') { | ||
throw new Error(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -298,3 +298,3 @@ const destParentPath = posix_path_1.default.dirname(resolvedDestinationPath); | ||
if (!destParentNode || destParentNode.type !== 'dir') { | ||
throw new Error(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -305,11 +305,11 @@ const targetName = posix_path_1.default.basename(resolvedDestinationPath); | ||
if (destinationFileNode) { | ||
const shouldOverride = !(flags & types_1.FileSystemConstants.COPYFILE_EXCL); // tslint:disable-line no-bitwise | ||
const shouldOverride = !(flags & types_1.FileSystemConstants.COPYFILE_EXCL); | ||
if (!shouldOverride) { | ||
throw new Error(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
} | ||
if (destinationFileNode.type !== 'file') { | ||
throw new Error(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
} | ||
const newFileNode = Object.assign({}, sourceFileNode, { name: targetName, mtime: new Date() }); | ||
const newFileNode = Object.assign(Object.assign({}, sourceFileNode), { name: targetName, mtime: new Date() }); | ||
destParentNode.contents.set(lowerCaseTargetName, newFileNode); | ||
@@ -360,2 +360,7 @@ emitWatchEvent({ path: resolvedDestinationPath, stats: createStatsFromNode(newFileNode) }); | ||
} | ||
function createFsError(message, code) { | ||
const error = new Error(message); | ||
error.code = code; | ||
throw error; | ||
} | ||
//# sourceMappingURL=memory-fs.js.map |
@@ -13,3 +13,3 @@ import { createFileSystem, syncToAsyncFs, SetMultiMap } from '@file-services/utils'; | ||
const baseFs = createBaseMemoryFs(); | ||
const fs = Object.assign({}, createFileSystem(baseFs), { root: baseFs.root }); | ||
const fs = Object.assign(Object.assign({}, createFileSystem(baseFs)), { root: baseFs.root }); | ||
if (rootContents) { | ||
@@ -26,3 +26,3 @@ fs.populateDirectorySync(posixPath.POSIX_ROOT, rootContents); | ||
const syncMemFs = createBaseMemoryFsSync(); | ||
return Object.assign({}, syncMemFs, syncToAsyncFs(syncMemFs)); | ||
return Object.assign(Object.assign({}, syncMemFs), syncToAsyncFs(syncMemFs)); | ||
} | ||
@@ -38,3 +38,3 @@ /** | ||
let workingDirectoryPath = posixPath.POSIX_ROOT; | ||
return Object.assign({ root }, posixPath, { resolve: resolvePath, watchService: { | ||
return Object.assign(Object.assign({ root }, posixPath), { resolve: resolvePath, watchService: { | ||
async watchPath(path, listener) { | ||
@@ -92,6 +92,6 @@ const resolvedPath = resolvePath(path); | ||
if (!fileNode) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
} | ||
else if (fileNode.type === 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -105,3 +105,3 @@ return fileNode.contents; | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -129,3 +129,3 @@ const fileName = posixPath.basename(resolvedPath); | ||
else { | ||
throw new Error(`${resolvedPath} EISDIR ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -138,3 +138,3 @@ } | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
} | ||
@@ -145,6 +145,6 @@ const fileName = posixPath.basename(resolvedPath); | ||
if (!fileNode) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
} | ||
else if (fileNode.type === 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -158,6 +158,6 @@ parentNode.contents.delete(lowerCaseFileName); | ||
if (!directoryNode) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
} | ||
else if (directoryNode.type === 'file') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.PATH_IS_FILE}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_FILE}`, 'ENOTDIR'); | ||
} | ||
@@ -174,3 +174,3 @@ const childNodes = Array.from(directoryNode.contents.values()); | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -181,3 +181,3 @@ const directoryName = posixPath.basename(resolvedPath); | ||
if (currentNode) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
} | ||
@@ -193,3 +193,3 @@ const newDirNode = createMemDirectory(directoryName); | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -200,6 +200,6 @@ const directoryName = posixPath.basename(resolvedPath); | ||
if (!directoryNode || directoryNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
} | ||
else if (directoryNode.contents.size > 0) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
} | ||
@@ -216,3 +216,3 @@ parentNode.contents.delete(lowerCaseDirectoryName); | ||
if (!node) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -229,3 +229,3 @@ const { birthtime, mtime } = node; | ||
if (!node) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -240,3 +240,3 @@ return resolvedPath; | ||
if (!sourceParentNode || sourceParentNode.type !== 'dir') { | ||
throw new Error(`${resolvedSourcePath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -247,3 +247,3 @@ const sourceName = posixPath.basename(resolvedSourcePath); | ||
if (!sourceNode) { | ||
throw new Error(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -253,3 +253,3 @@ const destinationParentPath = posixPath.dirname(resolvedDestinationPath); | ||
if (!destinationParentNode || destinationParentNode.type !== 'dir') { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -262,7 +262,7 @@ const destinationName = posixPath.basename(resolvedDestinationPath); | ||
if (destinationNode.contents.size > 0) { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
} | ||
} | ||
else { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
} | ||
@@ -282,6 +282,6 @@ } | ||
if (!sourceFileNode) { | ||
throw new Error(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
if (sourceFileNode.type !== 'file') { | ||
throw new Error(`${resolvedSourcePath} ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -291,3 +291,3 @@ const destParentPath = posixPath.dirname(resolvedDestinationPath); | ||
if (!destParentNode || destParentNode.type !== 'dir') { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -298,11 +298,11 @@ const targetName = posixPath.basename(resolvedDestinationPath); | ||
if (destinationFileNode) { | ||
const shouldOverride = !(flags & FileSystemConstants.COPYFILE_EXCL); // tslint:disable-line no-bitwise | ||
const shouldOverride = !(flags & FileSystemConstants.COPYFILE_EXCL); | ||
if (!shouldOverride) { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
} | ||
if (destinationFileNode.type !== 'file') { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
} | ||
const newFileNode = Object.assign({}, sourceFileNode, { name: targetName, mtime: new Date() }); | ||
const newFileNode = Object.assign(Object.assign({}, sourceFileNode), { name: targetName, mtime: new Date() }); | ||
destParentNode.contents.set(lowerCaseTargetName, newFileNode); | ||
@@ -352,2 +352,7 @@ emitWatchEvent({ path: resolvedDestinationPath, stats: createStatsFromNode(newFileNode) }); | ||
} | ||
function createFsError(message, code) { | ||
const error = new Error(message); | ||
error.code = code; | ||
throw error; | ||
} | ||
//# sourceMappingURL=memory-fs.js.map |
{ | ||
"name": "@file-services/memory", | ||
"description": "An in-memory, sync/async, file system implementation.", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"main": "cjs/index.js", | ||
@@ -17,5 +17,5 @@ "module": "esm/index.js", | ||
"dependencies": { | ||
"@file-services/posix-path": "^1.0.3", | ||
"@file-services/types": "^2.0.1", | ||
"@file-services/utils": "^2.0.1" | ||
"@file-services/posix-path": "^2.1.0", | ||
"@file-services/types": "^2.1.0", | ||
"@file-services/utils": "^2.1.0" | ||
}, | ||
@@ -25,4 +25,3 @@ "files": [ | ||
"esm", | ||
"src", | ||
"!src/tsconfig.json" | ||
"src" | ||
], | ||
@@ -36,3 +35,3 @@ "license": "MIT", | ||
"sideEffects": false, | ||
"gitHead": "fc4bf2d1f67151dfd6357fcda60bc0c43f6a10d6" | ||
"gitHead": "d0f4daec4165377749c39bb159c24b6e0808fae4" | ||
} |
@@ -130,5 +130,5 @@ import { createFileSystem, syncToAsyncFs, SetMultiMap } from '@file-services/utils'; | ||
if (!fileNode) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
} else if (fileNode.type === 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -145,3 +145,3 @@ | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -169,3 +169,3 @@ | ||
} else { | ||
throw new Error(`${resolvedPath} EISDIR ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -180,3 +180,3 @@ } | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
} | ||
@@ -189,5 +189,5 @@ | ||
if (!fileNode) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
} else if (fileNode.type === 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -215,5 +215,5 @@ | ||
if (!directoryNode) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
} else if (directoryNode.type === 'file') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.PATH_IS_FILE}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_FILE}`, 'ENOTDIR'); | ||
} | ||
@@ -233,3 +233,3 @@ const childNodes = Array.from(directoryNode.contents.values()); | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -242,3 +242,3 @@ | ||
if (currentNode) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
} | ||
@@ -258,3 +258,3 @@ | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -267,5 +267,5 @@ | ||
if (!directoryNode || directoryNode.type !== 'dir') { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
} else if (directoryNode.contents.size > 0) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
} | ||
@@ -285,3 +285,3 @@ | ||
if (!node) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -300,3 +300,3 @@ const { birthtime, mtime } = node; | ||
if (!node) { | ||
throw new Error(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -313,3 +313,3 @@ return resolvedPath; | ||
if (!sourceParentNode || sourceParentNode.type !== 'dir') { | ||
throw new Error(`${resolvedSourcePath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -322,3 +322,3 @@ | ||
if (!sourceNode) { | ||
throw new Error(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
@@ -330,3 +330,3 @@ | ||
if (!destinationParentNode || destinationParentNode.type !== 'dir') { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -341,6 +341,6 @@ | ||
if (destinationNode.contents.size > 0) { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
} | ||
} else { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
} | ||
@@ -358,3 +358,3 @@ } | ||
function copyFileSync(sourcePath: string, destinationPath: string, flags: number = 0): void { | ||
function copyFileSync(sourcePath: string, destinationPath: string, flags = 0): void { | ||
const resolvedSourcePath = resolvePath(sourcePath); | ||
@@ -365,7 +365,7 @@ const resolvedDestinationPath = resolvePath(destinationPath); | ||
if (!sourceFileNode) { | ||
throw new Error(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`); | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
} | ||
if (sourceFileNode.type !== 'file') { | ||
throw new Error(`${resolvedSourcePath} ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -377,3 +377,3 @@ | ||
if (!destParentNode || destParentNode.type !== 'dir') { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
} | ||
@@ -386,10 +386,10 @@ | ||
if (destinationFileNode) { | ||
const shouldOverride = !(flags & FileSystemConstants.COPYFILE_EXCL); // tslint:disable-line no-bitwise | ||
const shouldOverride = !(flags & FileSystemConstants.COPYFILE_EXCL); | ||
if (!shouldOverride) { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
} | ||
if (destinationFileNode.type !== 'file') { | ||
throw new Error(`${resolvedDestinationPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`); | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
} | ||
@@ -450,1 +450,7 @@ } | ||
} | ||
function createFsError(message: string, code: 'ENOENT' | 'EEXIST' | 'EISDIR' | 'ENOTDIR' | 'ENOTEMPTY'): Error { | ||
const error = new Error(message); | ||
(error as Error & { code: string }).code = code; | ||
throw error; | ||
} |
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
88731
1228
+ Added@file-services/posix-path@2.1.0(transitive)
- Removed@file-services/posix-path@1.0.3(transitive)
Updated@file-services/types@^2.1.0
Updated@file-services/utils@^2.1.0