@file-services/utils
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -45,2 +45,3 @@ "use strict"; | ||
function ensureDirectorySync(directoryPath) { | ||
var _a, _b; | ||
try { | ||
@@ -50,5 +51,17 @@ mkdirSync(directoryPath); | ||
catch (e) { | ||
if (e && (e.code === 'EEXIST' || e.code === 'EISDIR')) { | ||
const code = (_a = e) === null || _a === void 0 ? void 0 : _a.code; | ||
if (code === 'EISDIR') { | ||
return; | ||
} | ||
else if (code === 'EEXIST') { | ||
if (directoryExistsSync(directoryPath)) { | ||
return; | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
else if (code === 'ENOTDIR' || !code) { | ||
throw e; | ||
} | ||
const parentPath = dirname(directoryPath); | ||
@@ -63,3 +76,5 @@ if (parentPath === directoryPath) { | ||
catch (e) { | ||
if (!e || (e.code !== 'EEXIST' && e.code !== 'EISDIR')) { | ||
const code = (_b = e) === null || _b === void 0 ? void 0 : _b.code; | ||
const isDirectoryExistsError = code === 'EISDIR' || (code === 'EEXIST' && directoryExistsSync(directoryPath)); | ||
if (!isDirectoryExistsError) { | ||
throw e; | ||
@@ -213,2 +228,3 @@ } | ||
async function ensureDirectory(directoryPath) { | ||
var _a, _b; | ||
try { | ||
@@ -218,5 +234,17 @@ await mkdir(directoryPath); | ||
catch (e) { | ||
if (e && (e.code === 'EEXIST' || e.code === 'EISDIR')) { | ||
const code = (_a = e) === null || _a === void 0 ? void 0 : _a.code; | ||
if (code === 'EISDIR') { | ||
return; | ||
} | ||
else if (code === 'EEXIST') { | ||
if (await directoryExists(directoryPath)) { | ||
return; | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
else if (code === 'ENOTDIR' || !code) { | ||
throw e; | ||
} | ||
const parentPath = dirname(directoryPath); | ||
@@ -231,3 +259,5 @@ if (parentPath === directoryPath) { | ||
catch (e) { | ||
if (!e || (e.code !== 'EEXIST' && e.code !== 'EISDIR')) { | ||
const code = (_b = e) === null || _b === void 0 ? void 0 : _b.code; | ||
const isDirectoryExistsError = code === 'EISDIR' || (code === 'EEXIST' && (await directoryExists(directoryPath))); | ||
if (!isDirectoryExistsError) { | ||
throw e; | ||
@@ -234,0 +264,0 @@ } |
@@ -23,4 +23,4 @@ "use strict"; | ||
}, | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
async mkdir(directoryPath, ...args) { | ||
return syncFs.mkdirSync(directoryPath, ...args); | ||
}, | ||
@@ -27,0 +27,0 @@ async rmdir(directoryPath) { |
@@ -40,2 +40,3 @@ const returnsTrue = () => true; | ||
function ensureDirectorySync(directoryPath) { | ||
var _a, _b; | ||
try { | ||
@@ -45,5 +46,17 @@ mkdirSync(directoryPath); | ||
catch (e) { | ||
if (e && (e.code === 'EEXIST' || e.code === 'EISDIR')) { | ||
const code = (_a = e) === null || _a === void 0 ? void 0 : _a.code; | ||
if (code === 'EISDIR') { | ||
return; | ||
} | ||
else if (code === 'EEXIST') { | ||
if (directoryExistsSync(directoryPath)) { | ||
return; | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
else if (code === 'ENOTDIR' || !code) { | ||
throw e; | ||
} | ||
const parentPath = dirname(directoryPath); | ||
@@ -58,3 +71,5 @@ if (parentPath === directoryPath) { | ||
catch (e) { | ||
if (!e || (e.code !== 'EEXIST' && e.code !== 'EISDIR')) { | ||
const code = (_b = e) === null || _b === void 0 ? void 0 : _b.code; | ||
const isDirectoryExistsError = code === 'EISDIR' || (code === 'EEXIST' && directoryExistsSync(directoryPath)); | ||
if (!isDirectoryExistsError) { | ||
throw e; | ||
@@ -206,2 +221,3 @@ } | ||
async function ensureDirectory(directoryPath) { | ||
var _a, _b; | ||
try { | ||
@@ -211,5 +227,17 @@ await mkdir(directoryPath); | ||
catch (e) { | ||
if (e && (e.code === 'EEXIST' || e.code === 'EISDIR')) { | ||
const code = (_a = e) === null || _a === void 0 ? void 0 : _a.code; | ||
if (code === 'EISDIR') { | ||
return; | ||
} | ||
else if (code === 'EEXIST') { | ||
if (await directoryExists(directoryPath)) { | ||
return; | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
else if (code === 'ENOTDIR' || !code) { | ||
throw e; | ||
} | ||
const parentPath = dirname(directoryPath); | ||
@@ -224,3 +252,5 @@ if (parentPath === directoryPath) { | ||
catch (e) { | ||
if (!e || (e.code !== 'EEXIST' && e.code !== 'EISDIR')) { | ||
const code = (_b = e) === null || _b === void 0 ? void 0 : _b.code; | ||
const isDirectoryExistsError = code === 'EISDIR' || (code === 'EEXIST' && (await directoryExists(directoryPath))); | ||
if (!isDirectoryExistsError) { | ||
throw e; | ||
@@ -227,0 +257,0 @@ } |
@@ -20,4 +20,4 @@ import { callbackify } from './callbackify'; | ||
}, | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
async mkdir(directoryPath, ...args) { | ||
return syncFs.mkdirSync(directoryPath, ...args); | ||
}, | ||
@@ -24,0 +24,0 @@ async rmdir(directoryPath) { |
{ | ||
"name": "@file-services/utils", | ||
"description": "Common file system utility functions.", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"main": "cjs/index.js", | ||
@@ -14,3 +14,3 @@ "module": "esm/index.js", | ||
"dependencies": { | ||
"@file-services/types": "^3.0.0" | ||
"@file-services/types": "^3.1.0" | ||
}, | ||
@@ -17,0 +17,0 @@ "files": [ |
@@ -76,5 +76,15 @@ import type { | ||
} catch (e) { | ||
if (e && ((e as NodeJS.ErrnoException).code === 'EEXIST' || (e as NodeJS.ErrnoException).code === 'EISDIR')) { | ||
const code = (e as NodeJS.ErrnoException)?.code; | ||
if (code === 'EISDIR') { | ||
return; | ||
} else if (code === 'EEXIST') { | ||
if (directoryExistsSync(directoryPath)) { | ||
return; | ||
} else { | ||
throw e; | ||
} | ||
} else if (code === 'ENOTDIR' || !code) { | ||
throw e; | ||
} | ||
const parentPath = dirname(directoryPath); | ||
@@ -84,2 +94,3 @@ if (parentPath === directoryPath) { | ||
} | ||
ensureDirectorySync(parentPath); | ||
@@ -89,3 +100,5 @@ try { | ||
} catch (e) { | ||
if (!e || ((e as NodeJS.ErrnoException).code !== 'EEXIST' && (e as NodeJS.ErrnoException).code !== 'EISDIR')) { | ||
const code = (e as NodeJS.ErrnoException)?.code; | ||
const isDirectoryExistsError = code === 'EISDIR' || (code === 'EEXIST' && directoryExistsSync(directoryPath)); | ||
if (!isDirectoryExistsError) { | ||
throw e; | ||
@@ -262,5 +275,15 @@ } | ||
} catch (e) { | ||
if (e && ((e as NodeJS.ErrnoException).code === 'EEXIST' || (e as NodeJS.ErrnoException).code === 'EISDIR')) { | ||
const code = (e as NodeJS.ErrnoException)?.code; | ||
if (code === 'EISDIR') { | ||
return; | ||
} else if (code === 'EEXIST') { | ||
if (await directoryExists(directoryPath)) { | ||
return; | ||
} else { | ||
throw e; | ||
} | ||
} else if (code === 'ENOTDIR' || !code) { | ||
throw e; | ||
} | ||
const parentPath = dirname(directoryPath); | ||
@@ -270,2 +293,3 @@ if (parentPath === directoryPath) { | ||
} | ||
await ensureDirectory(parentPath); | ||
@@ -275,3 +299,6 @@ try { | ||
} catch (e) { | ||
if (!e || ((e as NodeJS.ErrnoException).code !== 'EEXIST' && (e as NodeJS.ErrnoException).code !== 'EISDIR')) { | ||
const code = (e as NodeJS.ErrnoException)?.code; | ||
const isDirectoryExistsError = | ||
code === 'EISDIR' || (code === 'EEXIST' && (await directoryExists(directoryPath))); | ||
if (!isDirectoryExistsError) { | ||
throw e; | ||
@@ -278,0 +305,0 @@ } |
@@ -27,4 +27,4 @@ import type { IBaseFileSystemSync, IBaseFileSystemAsync, IBaseFileSystemPromiseActions } from '@file-services/types'; | ||
async mkdir(directoryPath) { | ||
return syncFs.mkdirSync(directoryPath); | ||
async mkdir(directoryPath, ...args) { | ||
return syncFs.mkdirSync(directoryPath, ...args); | ||
}, | ||
@@ -72,3 +72,3 @@ | ||
readdir: callbackify(syncFs.readdirSync) as IBaseFileSystemAsync['readdir'], | ||
mkdir: callbackify(syncFs.mkdirSync), | ||
mkdir: callbackify(syncFs.mkdirSync) as IBaseFileSystemAsync['mkdir'], | ||
rmdir: callbackify(syncFs.rmdirSync), | ||
@@ -75,0 +75,0 @@ stat: callbackify(syncFs.statSync), |
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
105609
1677
Updated@file-services/types@^3.1.0