Skip to content

Commit

Permalink
detect symbolic link packages
Browse files Browse the repository at this point in the history
* detect symbolic link packages
  • Loading branch information
aminya authored and sadick254 committed Sep 8, 2020
1 parent 9b7614b commit 6d6f204
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/fixtures/packages/folder/package-symlinked/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "package-symlinked",
"version": "0.1.0"
}
22 changes: 22 additions & 0 deletions spec/package-manager-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1890,4 +1890,26 @@ describe('PackageManager', () => {
});
});
});

describe('::getAvailablePackageNames', () => {
it('detects a symlinked package', () => {
const packageSymLinkedSource = path.join(
__dirname,
'fixtures',
'packages',
'folder',
'package-symlinked'
);
const destination = path.join(
atom.packages.getPackageDirPaths()[0],
'package-symlinked'
);
if (!fs.isDirectorySync(destination)) {
fs.symlinkSync(packageSymLinkedSource, destination, 'junction');
}
const availablePackages = atom.packages.getAvailablePackageNames();
expect(availablePackages.includes('package-symlinked')).toBe(true);
fs.removeSync(destination);
});
});
});
9 changes: 8 additions & 1 deletion src/package-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,16 @@ module.exports = class PackageManager {

for (const packageDirPath of this.packageDirPaths) {
if (fs.isDirectorySync(packageDirPath)) {
// checks for directories.
// dirent is faster, but for checking symbolic link we need stat.
const packageNames = fs
.readdirSync(packageDirPath, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.filter(
dirent =>
dirent.isDirectory() ||
(dirent.isSymbolicLink() &&
fs.isDirectorySync(path.join(packageDirPath, dirent.name)))
)
.map(dirent => dirent.name);

for (const packageName of packageNames) {
Expand Down

0 comments on commit 6d6f204

Please sign in to comment.