@file-services/memory
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -113,6 +113,6 @@ "use strict"; | ||
if (!fileNode) { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.NO_FILE, 'ENOENT'); | ||
} | ||
else if (fileNode.type === 'dir') { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -126,3 +126,3 @@ return fileNode.contents; | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -150,3 +150,3 @@ const fileName = posixPath.basename(resolvedPath); | ||
else { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -159,3 +159,3 @@ } | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.NO_FILE, 'ENOENT'); | ||
} | ||
@@ -166,6 +166,6 @@ const fileName = posixPath.basename(resolvedPath); | ||
if (!fileNode) { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.NO_FILE, 'ENOENT'); | ||
} | ||
else if (fileNode.type === 'dir') { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -179,6 +179,6 @@ parentNode.contents.delete(lowerCaseFileName); | ||
if (!directoryNode) { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.NO_DIRECTORY, 'ENOENT'); | ||
} | ||
else if (directoryNode.type === 'file') { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_IS_FILE}`, 'ENOTDIR'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.PATH_IS_FILE, 'ENOTDIR'); | ||
} | ||
@@ -190,11 +190,26 @@ const childNodes = Array.from(directoryNode.contents.values()); | ||
} | ||
function mkdirSync(directoryPath) { | ||
function mkdirSync(directoryPath, options) { | ||
const resolvedPath = resolvePath(directoryPath); | ||
const parentPath = posixPath.dirname(resolvedPath); | ||
const parentNode = getNode(parentPath); | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
let parentNode = getNode(parentPath); | ||
const recursive = options === null || options === void 0 ? void 0 : options.recursive; | ||
if (!parentNode) { | ||
if (recursive) { | ||
mkdirSync(parentPath, options); | ||
parentNode = getNode(parentPath); | ||
} | ||
else { | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
} | ||
else if (parentNode.type !== 'dir') { | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.PATH_IS_FILE, 'ENOTDIR'); | ||
} | ||
else if (parentPath === resolvedPath) { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
if (recursive) { | ||
return; | ||
} | ||
else { | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
} | ||
@@ -205,3 +220,6 @@ const directoryName = posixPath.basename(resolvedPath); | ||
if (currentNode) { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
if (recursive && currentNode.type === 'dir') { | ||
return; | ||
} | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
@@ -217,3 +235,3 @@ const newDirNode = createMemDirectory(directoryName); | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.NO_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -224,6 +242,6 @@ const directoryName = posixPath.basename(resolvedPath); | ||
if (!directoryNode || directoryNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.NO_DIRECTORY, 'ENOENT'); | ||
} | ||
else if (directoryNode.contents.size > 0) { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.DIRECTORY_NOT_EMPTY, 'ENOTEMPTY'); | ||
} | ||
@@ -240,3 +258,3 @@ parentNode.contents.delete(lowerCaseDirectoryName); | ||
if (!node) { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -253,3 +271,3 @@ const { birthtime, mtime } = node; | ||
if (!node) { | ||
throw createFsError(`${resolvedPath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -264,3 +282,3 @@ return resolvedPath; | ||
if (!sourceParentNode || sourceParentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedSourcePath, error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -271,3 +289,3 @@ const sourceName = posixPath.basename(resolvedSourcePath); | ||
if (!sourceNode) { | ||
throw createFsError(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedSourcePath, error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -277,3 +295,3 @@ const destinationParentPath = posixPath.dirname(resolvedDestinationPath); | ||
if (!destinationParentNode || destinationParentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedDestinationPath, error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -286,7 +304,7 @@ const destinationName = posixPath.basename(resolvedDestinationPath); | ||
if (destinationNode.contents.size > 0) { | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
throw createFsError(resolvedDestinationPath, error_codes_1.FsErrorCodes.DIRECTORY_NOT_EMPTY, 'ENOTEMPTY'); | ||
} | ||
} | ||
else { | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
throw createFsError(resolvedDestinationPath, error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
@@ -306,6 +324,6 @@ } | ||
if (!sourceFileNode) { | ||
throw createFsError(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedSourcePath, error_codes_1.FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
if (sourceFileNode.type !== 'file') { | ||
throw createFsError(`${resolvedSourcePath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedSourcePath, error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -315,3 +333,3 @@ const destParentPath = posixPath.dirname(resolvedDestinationPath); | ||
if (!destParentNode || destParentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedDestinationPath, error_codes_1.FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -324,6 +342,6 @@ const targetName = posixPath.basename(resolvedDestinationPath); | ||
if (!shouldOverride) { | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
throw createFsError(resolvedDestinationPath, error_codes_1.FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
if (destinationFileNode.type !== 'file') { | ||
throw createFsError(`${resolvedDestinationPath} ${error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedDestinationPath, error_codes_1.FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -377,4 +395,5 @@ } | ||
} | ||
function createFsError(message, code) { | ||
const error = new Error(message); | ||
function createFsError(path, message, code) { | ||
const error = new Error(`${path} ${message}`); | ||
error.path = path; | ||
error.code = code; | ||
@@ -381,0 +400,0 @@ throw error; |
@@ -105,6 +105,6 @@ import { createFileSystem, syncToAsyncFs, SetMultiMap } from '@file-services/utils'; | ||
if (!fileNode) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE, 'ENOENT'); | ||
} | ||
else if (fileNode.type === 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -118,3 +118,3 @@ return fileNode.contents; | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -142,3 +142,3 @@ const fileName = posixPath.basename(resolvedPath); | ||
else { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -151,3 +151,3 @@ } | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE, 'ENOENT'); | ||
} | ||
@@ -158,6 +158,6 @@ const fileName = posixPath.basename(resolvedPath); | ||
if (!fileNode) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE, 'ENOENT'); | ||
} | ||
else if (fileNode.type === 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -171,6 +171,6 @@ parentNode.contents.delete(lowerCaseFileName); | ||
if (!directoryNode) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_DIRECTORY, 'ENOENT'); | ||
} | ||
else if (directoryNode.type === 'file') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_FILE}`, 'ENOTDIR'); | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_FILE, 'ENOTDIR'); | ||
} | ||
@@ -182,11 +182,26 @@ const childNodes = Array.from(directoryNode.contents.values()); | ||
} | ||
function mkdirSync(directoryPath) { | ||
function mkdirSync(directoryPath, options) { | ||
const resolvedPath = resolvePath(directoryPath); | ||
const parentPath = posixPath.dirname(resolvedPath); | ||
const parentNode = getNode(parentPath); | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
let parentNode = getNode(parentPath); | ||
const recursive = options === null || options === void 0 ? void 0 : options.recursive; | ||
if (!parentNode) { | ||
if (recursive) { | ||
mkdirSync(parentPath, options); | ||
parentNode = getNode(parentPath); | ||
} | ||
else { | ||
throw createFsError(resolvedPath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
} | ||
else if (parentNode.type !== 'dir') { | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_FILE, 'ENOTDIR'); | ||
} | ||
else if (parentPath === resolvedPath) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
if (recursive) { | ||
return; | ||
} | ||
else { | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
} | ||
@@ -197,3 +212,6 @@ const directoryName = posixPath.basename(resolvedPath); | ||
if (currentNode) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
if (recursive && currentNode.type === 'dir') { | ||
return; | ||
} | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
@@ -209,3 +227,3 @@ const newDirNode = createMemDirectory(directoryName); | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -216,6 +234,6 @@ const directoryName = posixPath.basename(resolvedPath); | ||
if (!directoryNode || directoryNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_DIRECTORY, 'ENOENT'); | ||
} | ||
else if (directoryNode.contents.size > 0) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
throw createFsError(resolvedPath, FsErrorCodes.DIRECTORY_NOT_EMPTY, 'ENOTEMPTY'); | ||
} | ||
@@ -232,3 +250,3 @@ parentNode.contents.delete(lowerCaseDirectoryName); | ||
if (!node) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -245,3 +263,3 @@ const { birthtime, mtime } = node; | ||
if (!node) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -256,3 +274,3 @@ return resolvedPath; | ||
if (!sourceParentNode || sourceParentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedSourcePath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -263,3 +281,3 @@ const sourceName = posixPath.basename(resolvedSourcePath); | ||
if (!sourceNode) { | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedSourcePath, FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -269,3 +287,3 @@ const destinationParentPath = posixPath.dirname(resolvedDestinationPath); | ||
if (!destinationParentNode || destinationParentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -278,7 +296,7 @@ const destinationName = posixPath.basename(resolvedDestinationPath); | ||
if (destinationNode.contents.size > 0) { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.DIRECTORY_NOT_EMPTY, 'ENOTEMPTY'); | ||
} | ||
} | ||
else { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
@@ -298,6 +316,6 @@ } | ||
if (!sourceFileNode) { | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedSourcePath, FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
if (sourceFileNode.type !== 'file') { | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedSourcePath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -307,3 +325,3 @@ const destParentPath = posixPath.dirname(resolvedDestinationPath); | ||
if (!destParentNode || destParentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -316,6 +334,6 @@ const targetName = posixPath.basename(resolvedDestinationPath); | ||
if (!shouldOverride) { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
if (destinationFileNode.type !== 'file') { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -368,4 +386,5 @@ } | ||
} | ||
function createFsError(message, code) { | ||
const error = new Error(message); | ||
function createFsError(path, message, code) { | ||
const error = new Error(`${path} ${message}`); | ||
error.path = path; | ||
error.code = code; | ||
@@ -372,0 +391,0 @@ throw error; |
{ | ||
"name": "@file-services/memory", | ||
"description": "An in-memory, sync/async, file system implementation.", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"main": "cjs/index.js", | ||
@@ -17,5 +17,5 @@ "module": "esm/index.js", | ||
"dependencies": { | ||
"@file-services/path": "^3.0.0", | ||
"@file-services/types": "^3.0.0", | ||
"@file-services/utils": "^3.0.0" | ||
"@file-services/path": "^3.1.0", | ||
"@file-services/types": "^3.1.0", | ||
"@file-services/utils": "^3.1.0" | ||
}, | ||
@@ -22,0 +22,0 @@ "files": [ |
@@ -132,5 +132,5 @@ import { createFileSystem, syncToAsyncFs, SetMultiMap } from '@file-services/utils'; | ||
if (!fileNode) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE, 'ENOENT'); | ||
} else if (fileNode.type === 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -147,3 +147,3 @@ | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -171,3 +171,3 @@ | ||
} else { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -182,3 +182,3 @@ } | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE, 'ENOENT'); | ||
} | ||
@@ -191,5 +191,5 @@ | ||
if (!fileNode) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE, 'ENOENT'); | ||
} else if (fileNode.type === 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -217,5 +217,5 @@ | ||
if (!directoryNode) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_DIRECTORY, 'ENOENT'); | ||
} else if (directoryNode.type === 'file') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_IS_FILE}`, 'ENOTDIR'); | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_FILE, 'ENOTDIR'); | ||
} | ||
@@ -229,11 +229,23 @@ const childNodes = Array.from(directoryNode.contents.values()); | ||
function mkdirSync(directoryPath: string): void { | ||
function mkdirSync(directoryPath: string, options?: { recursive?: boolean }): void { | ||
const resolvedPath = resolvePath(directoryPath); | ||
const parentPath = posixPath.dirname(resolvedPath); | ||
const parentNode = getNode(parentPath); | ||
let parentNode = getNode(parentPath); | ||
const recursive = options?.recursive; | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
if (!parentNode) { | ||
if (recursive) { | ||
mkdirSync(parentPath, options); | ||
parentNode = getNode(parentPath) as IFsMemDirectoryNode; | ||
} else { | ||
throw createFsError(resolvedPath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
} else if (parentNode.type !== 'dir') { | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_IS_FILE, 'ENOTDIR'); | ||
} else if (parentPath === resolvedPath) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
if (recursive) { | ||
return; | ||
} else { | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
} | ||
@@ -246,3 +258,6 @@ | ||
if (currentNode) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
if (recursive && currentNode.type === 'dir') { | ||
return; | ||
} | ||
throw createFsError(resolvedPath, FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
@@ -262,3 +277,3 @@ | ||
if (!parentNode || parentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -271,5 +286,5 @@ | ||
if (!directoryNode || directoryNode.type !== 'dir') { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_DIRECTORY, 'ENOENT'); | ||
} else if (directoryNode.contents.size > 0) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
throw createFsError(resolvedPath, FsErrorCodes.DIRECTORY_NOT_EMPTY, 'ENOTEMPTY'); | ||
} | ||
@@ -289,3 +304,3 @@ | ||
if (!node) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -304,3 +319,3 @@ const { birthtime, mtime } = node; | ||
if (!node) { | ||
throw createFsError(`${resolvedPath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedPath, FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -317,3 +332,3 @@ return resolvedPath; | ||
if (!sourceParentNode || sourceParentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedSourcePath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -326,3 +341,3 @@ | ||
if (!sourceNode) { | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedSourcePath, FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
@@ -334,3 +349,3 @@ | ||
if (!destinationParentNode || destinationParentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -345,6 +360,6 @@ | ||
if (destinationNode.contents.size > 0) { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.DIRECTORY_NOT_EMPTY}`, 'ENOTEMPTY'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.DIRECTORY_NOT_EMPTY, 'ENOTEMPTY'); | ||
} | ||
} else { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
@@ -368,7 +383,7 @@ } | ||
if (!sourceFileNode) { | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.NO_FILE_OR_DIRECTORY}`, 'ENOENT'); | ||
throw createFsError(resolvedSourcePath, FsErrorCodes.NO_FILE_OR_DIRECTORY, 'ENOENT'); | ||
} | ||
if (sourceFileNode.type !== 'file') { | ||
throw createFsError(`${resolvedSourcePath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedSourcePath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -380,3 +395,3 @@ | ||
if (!destParentNode || destParentNode.type !== 'dir') { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.CONTAINING_NOT_EXISTS}`, 'ENOENT'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.CONTAINING_NOT_EXISTS, 'ENOENT'); | ||
} | ||
@@ -392,7 +407,7 @@ | ||
if (!shouldOverride) { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_ALREADY_EXISTS}`, 'EEXIST'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.PATH_ALREADY_EXISTS, 'EEXIST'); | ||
} | ||
if (destinationFileNode.type !== 'file') { | ||
throw createFsError(`${resolvedDestinationPath} ${FsErrorCodes.PATH_IS_DIRECTORY}`, 'EISDIR'); | ||
throw createFsError(resolvedDestinationPath, FsErrorCodes.PATH_IS_DIRECTORY, 'EISDIR'); | ||
} | ||
@@ -454,6 +469,11 @@ } | ||
function createFsError(message: string, code: 'ENOENT' | 'EEXIST' | 'EISDIR' | 'ENOTDIR' | 'ENOTEMPTY'): Error { | ||
const error = new Error(message); | ||
function createFsError( | ||
path: string, | ||
message: FsErrorCodes, | ||
code: 'ENOENT' | 'EEXIST' | 'EISDIR' | 'ENOTDIR' | 'ENOTEMPTY' | ||
): Error { | ||
const error = new Error(`${path} ${message}`); | ||
(error as Error & { path: string }).path = path; | ||
(error as Error & { code: string }).code = code; | ||
throw error; | ||
} |
@@ -1,2 +0,7 @@ | ||
import type { IBaseFileSystemSync, IBaseFileSystemAsync, IFileSystemAsync, IFileSystemSync } from '@file-services/types'; | ||
import type { | ||
IBaseFileSystemSync, | ||
IBaseFileSystemAsync, | ||
IFileSystemAsync, | ||
IFileSystemSync, | ||
} from '@file-services/types'; | ||
@@ -3,0 +8,0 @@ export interface IMemFileSystem extends IFileSystemSync, IFileSystemAsync { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
90260
1343
Updated@file-services/path@^3.1.0
Updated@file-services/types@^3.1.0
Updated@file-services/utils@^3.1.0