Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
No longer care if node_modules/@<scope> doesn’t exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomek Wiszniewski committed May 31, 2016
1 parent e4f85cb commit 91a0296
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
7 changes: 5 additions & 2 deletions debootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ module.exports = (params) => {
if (!symlink.isSymbolicLink()) throw symlinkError(scopeSymlinkPath);
} catch (error) {
if (error.code !== 'ENOENT') throw error;
mkdirp.sync(nodeModulesPath);
}

// Check if package dep symlinks are safe to remove
Expand All @@ -57,7 +56,11 @@ module.exports = (params) => {
});

// Remove scope symlink
fs.unlinkSync(scopeSymlinkPath);
try {
fs.unlinkSync(scopeSymlinkPath);
} catch (error) {
if (error.code !== 'ENOENT') throw error;
}

// Remove package deps symlinks
packageDepsSymlinkPaths.forEach(symlinkPath => fs.unlinkSync(symlinkPath));
Expand Down
39 changes: 31 additions & 8 deletions test/debootstrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ const projectNodeModulesPath = `${path}/node_modules`;
const mockSymlink = mockFs.symlink({ path: 'whatever' });
const packagePath =
name => `${path}/packages/${name}`;
const treeWithPackages = { [path]: {
'packages': asObject(packages.map(name => ({
key: name,
value: {
'node_modules': mockSymlink,
},
}))),
} };

test('Removes the `node_modules/@<scope>` symlink', (is) => {
is.plan(1);
Expand Down Expand Up @@ -70,15 +78,30 @@ test((
is.end();
});

test((
'Doesn’t care if `node_modules/@<scope>` doesn’t exist'
), (is) => {
is.plan(1);
mockFs(treeWithPackages);

try {
debootstrap({ path, scope });
is.ok(
!includes(fs.readdirSync(packagePath(packages[0])), 'node_modules'),
'does its job'
);
} catch (error) {
is.fail(
'doesn’t throw an error'
);
}

mockFs.restore();
is.end();
});

test('Removes `packages/*/node_modules` symlinks', (is) => {
mockFs({ [path]: {
'packages': asObject(packages.map(name => ({
key: name,
value: {
'node_modules': mockSymlink,
},
}))),
} });
mockFs(treeWithPackages);

debootstrap({ path });

Expand Down

0 comments on commit 91a0296

Please sign in to comment.