diff --git a/package.json b/package.json index 019ff69..59122bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "symlink-dir", - "version": "5.0.0", + "version": "5.0.1", "description": "Cross-platform directory symlinking", "main": "dist/index.js", "files": [ diff --git a/src/index.ts b/src/index.ts index 7de58cd..9a1f6d2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,7 +49,7 @@ async function forceSymlink (src: string, dest: string): Promise<{ reused: Boole `Details: ${mkdirError}` throw mkdirError } - await fs.symlink(src, dest, symlinkType) + await forceSymlink(src, dest) return { reused: false } case 'EEXIST': case 'EISDIR': diff --git a/test/index.ts b/test/index.ts index dab9855..ab5daa4 100644 --- a/test/index.ts +++ b/test/index.ts @@ -69,3 +69,20 @@ test('create parent directory of symlink', async (t) => { t.end() }) + +test('concurrently creating the same symlink twice', async (t) => { + const temp = tempy.directory() + t.comment(`testing in ${temp}`) + process.chdir(temp) + + await writeJsonFile('src/file.json', { ok: true }) + + await Promise.all([ + symlink('src', 'dest/subdir'), + symlink('src', 'dest/subdir'), + ]) + + t.deepEqual(await import(path.resolve('dest/subdir/file.json')), { ok: true }) + + t.end() +})