Skip to content

Commit

Permalink
fix(sandbox): make directory if not exists before symlinking node_mod…
Browse files Browse the repository at this point in the history
…ules (#2856)

First, create the directory if doesn't exist _before_ creating the symlink to `node_modules` inside the sandbox directory.
  • Loading branch information
nicojs authored Apr 27, 2021
1 parent 36c687f commit 40f9a1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core/src/utils/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export function moveDirectoryRecursiveSync(from: string, to: string): void {
* @param to The thing you want to point to
* @param from The thing you want to point from
*/
export function symlinkJunction(to: string, from: string): Promise<void> {
export async function symlinkJunction(to: string, from: string): Promise<void> {
await fs.promises.mkdir(path.dirname(from), { recursive: true });
return fs.promises.symlink(to, from, 'junction');
}

Expand Down
5 changes: 5 additions & 0 deletions packages/core/test/unit/utils/file-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('fileUtils', () => {
beforeEach(() => {
sinon.stub(fs.promises, 'writeFile');
sinon.stub(fs.promises, 'symlink');
sinon.stub(fs.promises, 'mkdir');
readdirStub = sinon.stub(fs.promises, 'readdir');
});

Expand All @@ -29,6 +30,10 @@ describe('fileUtils', () => {
await fileUtils.symlinkJunction('a', 'b');
expect(fs.promises.symlink).calledWith('a', 'b', 'junction');
});
it("should create the dir if it doesn't exist", async () => {
await fileUtils.symlinkJunction('a', path.resolve('b', 'c'));
expect(fs.promises.mkdir).calledWith(path.resolve('b'), { recursive: true });
});
});

describe('findNodeModulesList', () => {
Expand Down

0 comments on commit 40f9a1d

Please sign in to comment.