Skip to content

Commit

Permalink
Fix and improve directory handling in packages registry (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x80 authored Apr 1, 2024
1 parent 077eb51 commit b7c83c6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/lib/registry/create-packages-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ export async function createPackagesRegistry(
workspaceRootDir
);

const cwd = process.cwd();
process.chdir(workspaceRootDir);

const registry: PackagesRegistry = (
await Promise.all(
allPackages.map(async (rootRelativeDir) => {
const manifestPath = path.join(rootRelativeDir, "package.json");
const absoluteDir = path.join(workspaceRootDir, rootRelativeDir);
const manifestPath = path.join(absoluteDir, "package.json");

if (!fs.existsSync(manifestPath)) {
log.warn(
Expand All @@ -45,13 +43,13 @@ export async function createPackagesRegistry(
log.debug(`Registering package ./${rootRelativeDir}`);

const manifest = await readTypedJson<PackageManifest>(
path.join(rootRelativeDir, "package.json")
path.join(absoluteDir, "package.json")
);

return {
manifest,
rootRelativeDir,
absoluteDir: path.join(workspaceRootDir, rootRelativeDir),
absoluteDir,
};
}
})
Expand All @@ -63,8 +61,6 @@ export async function createPackagesRegistry(
return acc;
}, {});

process.chdir(cwd);

return registry;
}

Expand All @@ -83,6 +79,9 @@ function listWorkspacePackages(

return rushConfig.projects.map(({ projectFolder }) => projectFolder);
} else {
const currentDir = process.cwd();
process.chdir(workspaceRootDir);

const packagesGlobs =
workspacePackagesOverride ?? findPackagesGlobs(workspaceRootDir);

Expand All @@ -91,6 +90,7 @@ function listWorkspacePackages(
/** Make sure to filter any loose files that might hang around. */
.filter((dir) => fs.lstatSync(dir).isDirectory());

process.chdir(currentDir);
return allPackages;
}
}

0 comments on commit b7c83c6

Please sign in to comment.