From b01f20e7fc4a97d574c1538e884555f67e62aa01 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 10 May 2024 00:40:04 +0900 Subject: [PATCH] feat(symlink): support type --- src/index.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index ce2a09b..dc8c0c3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,20 +9,35 @@ import { export type { FsFixture }; +type SymlinkType = 'file' | 'dir' | 'junction'; + class Symlink { target: string; + type?: SymlinkType; + path?: string; - constructor(target: string) { + constructor( + target: string, + type?: SymlinkType, + ) { this.target = target; + this.type = type; } } type ApiBase = { fixturePath: string; getPath(...subpaths: string[]): string; - symlink(targetPath: string): Symlink; + symlink( + targetPath: string, + + /** + * Symlink type for Windows. Defaults to auto-detect by Node. + */ + type?: SymlinkType, + ): Symlink; }; type Api = ApiBase & { @@ -108,13 +123,13 @@ export const createFixture = async ( const api: ApiBase = { fixturePath, getPath: (...subpaths) => path.join(fixturePath, ...subpaths), - symlink: targetPath => new Symlink(targetPath), + symlink: (targetPath, type) => new Symlink(targetPath, type), }; await Promise.all( flattenFileTree(source, fixturePath, api).map(async (file) => { await fs.mkdir(path.dirname(file.path!), { recursive: true }); if (file instanceof Symlink) { - await fs.symlink(file.target, file.path!); + await fs.symlink(file.target, file.path!, file.type); } else { await fs.writeFile(file.path, file.content); }