Skip to content

Commit

Permalink
Adopt package manger definition from root manifest (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x80 authored Apr 20, 2024
1 parent bce55fa commit 33015af
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/isolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export async function isolate(

const log = useLogger();

const thisPackageManifest = await readTypedJson<PackageManifest>(
const { version: libraryVersion } = await readTypedJson<PackageManifest>(
path.join(path.join(__dirname, "..", "package.json"))
);

log.debug("Using isolate-package version", thisPackageManifest.version);
log.debug("Using isolate-package version", libraryVersion);

/**
* If a targetPackagePath is set, we assume the configuration lives in the
Expand Down
2 changes: 2 additions & 0 deletions src/lib/manifest/adapt-target-package-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export async function adaptTargetPackageManifest({

return {
...adaptedManifest,
/** Adopt the package manager definition from the root manifest if available. */
packageManager: packageManager.packageManagerString,
/**
* Scripts are removed by default if not explicitly picked or omitted via
* config.
Expand Down
18 changes: 12 additions & 6 deletions src/lib/package-manager/helpers/infer-from-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import { getLockfileFileName, supportedPackageManagerNames } from "../names";
export function inferFromManifest(workspaceRoot: string) {
const log = useLogger();

const rootManifest = readTypedJsonSync<PackageManifest>(
path.join(workspaceRoot, "package.json")
);
const { packageManager: packageManagerString } =
readTypedJsonSync<PackageManifest>(
path.join(workspaceRoot, "package.json")
);

if (!rootManifest.packageManager) {
if (!packageManagerString) {
log.debug("No packageManager field found in root manifest");
return;
}

const [name, version = "*"] = rootManifest.packageManager.split("@") as [
const [name, version = "*"] = packageManagerString.split("@") as [
PackageManagerName,
string,
];
Expand All @@ -37,5 +38,10 @@ export function inferFromManifest(workspaceRoot: string) {
`Manifest declares ${name} to be the packageManager, but failed to find ${lockfileName} in workspace root`
);

return { name, version, majorVersion: getMajorVersion(version) };
return {
name,
version,
majorVersion: getMajorVersion(version),
packageManagerString,
};
}
1 change: 1 addition & 0 deletions src/lib/package-manager/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type PackageManager = {
name: PackageManagerName;
version: string;
majorVersion: number;
packageManagerString?: string;
};

export function getLockfileFileName(name: PackageManagerName) {
Expand Down

0 comments on commit 33015af

Please sign in to comment.