Skip to content

Commit

Permalink
fix: symlink to overwrite directories
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Apr 22, 2022
1 parent fe6b793 commit 99ad461
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -26,12 +26,14 @@
},
"devDependencies": {
"@pvtnbr/eslint-config": "^0.19.1",
"@types/fs-extra": "^9.0.13",
"@types/node": "^17.0.25",
"cleye": "^1.1.0",
"cmd-shim": "^5.0.0",
"eslint": "^8.13.0",
"esno": "^0.14.1",
"execa": "^6.1.0",
"fs-extra": "^10.1.0",
"get-node": "^12.1.0",
"kolorist": "^1.5.1",
"manten": "^0.0.3",
Expand Down
32 changes: 32 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/utils/symlink.ts
@@ -1,5 +1,6 @@
import fs from 'fs';
import { fsExists } from './fs-exists';
import { remove } from 'fs-extra/lib/remove';

export async function symlink(
targetPath: string,
Expand All @@ -13,7 +14,7 @@ export async function symlink(
return;
}

await fs.promises.unlink(symlinkPath);
await remove(symlinkPath);
}

await fs.promises.symlink(
Expand Down
20 changes: 20 additions & 0 deletions tests/specs/cli.ts
@@ -1,3 +1,4 @@
import fs from 'fs';
import path from 'path';
import { testSuite, expect } from 'manten';
import { execa, execaNode } from 'execa';
Expand Down Expand Up @@ -190,5 +191,24 @@ export default testSuite(({ describe }, nodePath: string) => {

await fixture.rm();
});

test('overwrites directory in place of symlink', async () => {
const fixture = await createFixture('./tests/fixtures/');
const entryPackagePath = path.join(fixture.path, 'package-entry');

await fs.promises.mkdir(
path.join(entryPackagePath, 'node_modules/package-binary'),
{ recursive: true },
);

const linkBinary = await link(['../package-binary'], {
cwd: entryPackagePath,
nodePath,
});

expect(linkBinary.exitCode).toBe(0);

await fixture.rm();
});
});
});

0 comments on commit 99ad461

Please sign in to comment.