Skip to content

Commit

Permalink
feat(symlink): support type
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed May 9, 2024
1 parent 2fd3622 commit b01f20e
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b01f20e

Please sign in to comment.