diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 68525600..54a6b12c 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -75,16 +75,16 @@ function isDirFileExists(path: string, type: 'DIR' | 'FILE'): Promise { } -// create directories recursively -export async function createDir(path: string): Promise { +/** create directories recursively */ +export async function createDir(path: string): Promise { if (! path) { throw new Error('value of path param invalid') } else { - path = normalize(path) // ! required for '.../.myca' under win32 + const target = normalize(path) // ! required for '.../.myca' under win32 /* istanbul ignore else */ - if (!await isDirExists(path)) { - await path.split(sep).reduce( + if (!await isDirExists(target)) { + await target.split(sep).reduce( async (parentDir: Promise, childDir: string) => { const curDir = pathResolve(await parentDir, childDir) @@ -94,6 +94,8 @@ export async function createDir(path: string): Promise { Promise.resolve(sep), ) } + + return target } } diff --git a/test/10_shared_utils.test.ts b/test/10_shared_utils.test.ts index 42a8b6ff..9e26bba2 100644 --- a/test/10_shared_utils.test.ts +++ b/test/10_shared_utils.test.ts @@ -73,7 +73,8 @@ describe(filename, () => { const randomPath = `${tmpDir}/${pathPrefix}-${random}` try { - await createDir(randomPath) + const path = await createDir(randomPath) + assert(path === normalize(randomPath)) } catch (ex) { return assert(false, ex) @@ -91,7 +92,8 @@ describe(filename, () => { const randomPath = `${tmpDir}/${pathPrefix}-${random}/.test/0ab` try { - await createDir(randomPath) + const path = await createDir(randomPath) + assert(path === normalize(randomPath)) } catch (ex) { return assert(false, ex)