Skip to content

Commit a9cf8d9

Browse files
authored
Merge pull request #20 from ioj4/master
fix packages path search
2 parents 900e53a + bb0d6ea commit a9cf8d9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/core/packageLoader/getPackagesPath.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,26 @@ switch (processLocation()) {
1616
function getPackagesPath(): string {
1717
switch (processLocation()) {
1818
case "MAIN":
19+
// Directory in which kernel.asar is in
1920
const kernelPath = path.join(__dirname, "..", "..", "..");
20-
const packagesPath = path.resolve(kernelPath, "packages");
21+
const rootPath = path.parse(__dirname).root;
22+
let currentPath = kernelPath;
2123

22-
if (!fs.existsSync(packagesPath)) {
23-
console.log(
24-
`No package directory found. Creating one at "${packagesPath}"`
25-
);
24+
while (true) {
25+
if (fs.existsSync(path.join(currentPath, "packages"))) break;
26+
if (currentPath !== rootPath) {
27+
// Traverse further up
28+
currentPath = path.parse(currentPath).dir;
29+
continue;
30+
};
31+
32+
const packagesPath = path.join(kernelPath, "packages");
33+
console.log(`No package directory found. Creating one at "${packagesPath}"`);
2634
fs.mkdirSync(packagesPath);
35+
return packagesPath;
2736
}
2837

29-
return packagesPath;
38+
return path.join(currentPath, "packages");
3039

3140
case "PRELOAD":
3241
return ipcRenderer.sendSync("KERNEL_getPackagesPath");

0 commit comments

Comments
 (0)