Skip to content

Commit

Permalink
Merge pull request #137 from zowe-actions/fix/lerna-default-config
Browse files Browse the repository at this point in the history
Make the default lerna config smarter
  • Loading branch information
t1m0thyj committed Mar 4, 2024
2 parents 61cfdfa + 85ec01f commit 611d26f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
19 changes: 15 additions & 4 deletions dist/lerna.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions packages/lerna/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ export default async function (context: IContext, config: IPluginConfig): Promis
}
if (config[IS_LERNA_JSON_TEMP]) {
context.version.new = packageJson.version;
fs.writeFileSync("lerna.json", JSON.stringify({
version: packageJson.version,
useWorkspaces: true
}, null, 2));
const lernaConfig: Record<string, any> = { version: packageJson.version };
if (fs.existsSync("pnpm-workspaces.yaml")) {
lernaConfig.npmClient = "pnpm";
}
if ((await utils.getLernaMajorVersion() || 0) < 7) {
lernaConfig.useWorkspaces = true;
}
fs.writeFileSync("lerna.json", JSON.stringify(lernaConfig, null, 2));
}
} catch {
throw new Error(`Missing or invalid package.json in branch ${context.branch.name}`);
Expand Down
6 changes: 6 additions & 0 deletions packages/lerna/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ async function npxCmd(): Promise<string> {
return usePnpm ? "pnpm exec" : "npx";
}

export async function getLernaMajorVersion(): Promise<number> {
// If using lerna lite, the version is "unknown" so this function will return NaN
const cmdOutput = await exec.getExecOutput(await npxCmd(), ["lerna", "--version"]);
return parseInt(cmdOutput.stdout.split(".", 1)[0]);
}

export async function lernaList(onlyChanged?: boolean): Promise<Record<string, any>[]> {
const cmdArgs = ["lerna"];
if (onlyChanged) {
Expand Down

0 comments on commit 611d26f

Please sign in to comment.