Skip to content

Commit

Permalink
Merge branch 'lerna:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
SherfeyInv authored Sep 10, 2024
2 parents 4780298 + 28c8ef2 commit eede69e
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 34 deletions.
3 changes: 2 additions & 1 deletion libs/commands/publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ Useful in [Continuous integration (CI)](https://en.wikipedia.org/wiki/Continuous
lerna publish --canary --yes --summary-file
# Will create a summary file in the provided directory, i.e. `./some/other/dir/lerna-publish-summary.json`
lerna publish --canary --yes --summary-file ./some/other/dir

# Will create a summary file with the provided name, i.e. `./some/other/dir/my-summary.json`
lerna publish --canary --yes --summary-file ./some/other/dir/my-summary.json
```

When run with this flag, a json summary report will be generated after all packages have been successfully published (see below for an example).
Expand Down
29 changes: 25 additions & 4 deletions libs/commands/publish/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,15 @@ class PublishCommand extends Command {
output("Successfully published:");

if (this.options.summaryFile !== undefined) {
// create a json object and output it to a file location.
const filePath = this.options.summaryFile
? `${this.options.summaryFile}/lerna-publish-summary.json`
: "./lerna-publish-summary.json";
const filePath = this.getSummaryFilePath();

const jsonObject = publishedPackagesSorted.map((pkg) => {
return {
packageName: pkg.name,
version: pkg.version,
};
});

output(jsonObject);
try {
fs.writeFileSync(filePath, JSON.stringify(jsonObject));
Expand Down Expand Up @@ -1220,6 +1219,28 @@ class PublishCommand extends Command {
}
}
}

private getSummaryFilePath(): string {
if (this.options.summaryFile === undefined) {
throw new Error("summaryFile options is not defined. Unable to get path.");
}

if (this.options.summaryFile === "") {
return path.join(process.cwd(), "./lerna-publish-summary.json");
}

const normalizedPath = path.normalize(this.options.summaryFile);

if (normalizedPath === "") {
throw new Error("summaryFile is not a valid path.");
}

if (normalizedPath.endsWith(".json")) {
return path.join(process.cwd(), normalizedPath);
}

return path.join(process.cwd(), normalizedPath, "lerna-publish-summary.json");
}
}

module.exports.PublishCommand = PublishCommand;
23 changes: 21 additions & 2 deletions libs/commands/publish/src/lib/publish-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Map {
];
expect(fsSpy).toHaveBeenCalled();
expect(fsSpy).toHaveBeenCalledWith(
"./outputs/lerna-publish-summary.json",
path.join(process.cwd(), "outputs/lerna-publish-summary.json"),
JSON.stringify(expectedJsonResponse)
);
});
Expand All @@ -392,6 +392,25 @@ Map {
const fsSpy = jest.spyOn(fsmain, "writeFileSync");
await lernaPublish(cwd)("--summary-file");

const expectedJsonResponse = [
{ packageName: "package-1", version: "1.0.1" },
{ packageName: "package-2", version: "1.0.1" },
{ packageName: "package-3", version: "1.0.1" },
{ packageName: "package-4", version: "1.0.1" },
];

expect(fsSpy).toHaveBeenCalled();
expect(fsSpy).toHaveBeenCalledWith(
path.join(process.cwd(), "./lerna-publish-summary.json"),
JSON.stringify(expectedJsonResponse)
);
});

it("creates the summary file in the provided file path", async () => {
const cwd = await initFixture("normal");
const fsSpy = jest.spyOn(fsmain, "writeFileSync");
await lernaPublish(cwd)("--summary-file", "./outputs/lerna-publish-summary.json");

const expectedJsonResponse = [
{ packageName: "package-1", version: "1.0.1" },
{ packageName: "package-2", version: "1.0.1" },
Expand All @@ -400,7 +419,7 @@ Map {
];
expect(fsSpy).toHaveBeenCalled();
expect(fsSpy).toHaveBeenCalledWith(
"./lerna-publish-summary.json",
path.join(process.cwd(), "outputs/lerna-publish-summary.json"),
JSON.stringify(expectedJsonResponse)
);
});
Expand Down
4 changes: 4 additions & 0 deletions libs/commands/version/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class VersionCommand extends Command {
signoffGitCommit?: boolean;
signGitTag?: boolean;
forceGitTag?: boolean;
overrideMessage?: boolean;
};
savePrefix?: string;
currentBranch?: string;
Expand Down Expand Up @@ -175,12 +176,14 @@ class VersionCommand extends Command {
forceGitTag,
tagVersionPrefix = "v",
premajorVersionBump = "default",
message,
} = this.options;

this.gitRemote = gitRemote;
this.tagPrefix = tagVersionPrefix;
this.commitAndTag = gitTagVersion;
this.pushToRemote = gitTagVersion && amend !== true && push;
const overrideMessage: boolean = amend && !!message;
this.premajorVersionBump = premajorVersionBump;
// never automatically push to remote when amending a commit

Expand All @@ -204,6 +207,7 @@ class VersionCommand extends Command {
signoffGitCommit,
signGitTag,
forceGitTag,
overrideMessage,
};

// https://docs.npmjs.com/misc/config#save-prefix
Expand Down
20 changes: 14 additions & 6 deletions libs/commands/version/src/lib/git-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ const childProcess = require("@lerna/child-process");

export interface GitCommitOptions {
amend?: boolean;
overrideMessage?: boolean;
commitHooks?: boolean;
signGitCommit?: boolean;
signoffGitCommit?: boolean;
}

export function gitCommit(
message: string,
{ amend, commitHooks, signGitCommit, signoffGitCommit }: GitCommitOptions,
{ amend, commitHooks, signGitCommit, signoffGitCommit, overrideMessage }: GitCommitOptions,
opts: ExecOptions
) {
log.silly("gitCommit", message);
Expand All @@ -32,13 +33,20 @@ export function gitCommit(
args.push("--signoff");
}

const shouldChangeMessage = amend ? amend && overrideMessage : true;
if (amend) {
args.push("--amend", "--no-edit");
} else if (message.indexOf(EOL) > -1) {
// Use tempfile to allow multi\nline strings.
args.push("-F", tempWrite.sync(message, "lerna-commit.txt"));
args.push("--amend");
}

if (shouldChangeMessage) {
if (message.indexOf(EOL) > -1) {
// Use tempfile to allow multi\nline strings.
args.push("-F", tempWrite.sync(message, "lerna-commit.txt"));
} else {
args.push("-m", message);
}
} else {
args.push("-m", message);
args.push("--no-edit");
}

// TODO: refactor to address type issues
Expand Down
7 changes: 4 additions & 3 deletions libs/commands/version/src/lib/version-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,13 @@ Changes:
expect(checkWorkingTree).not.toHaveBeenCalled();
});

it("ignores custom messages", async () => {
it("considers custom messages", async () => {
const testDir = await initFixture("normal", "preserved");
await lernaVersion(testDir)("-m", "ignored", "--amend");
await lernaVersion(testDir)("-m", "custom", "--amend");

const message = await getCommitMessage(testDir);
expect(message).toBe("preserved");

expect(message).toBe("custom");
});
});

Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/legacy-package-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"console-control-strings": "^1.1.0",
"conventional-changelog-core": "5.0.1",
"conventional-recommended-bump": "7.0.1",
"cosmiconfig": "^8.2.0",
"cosmiconfig": "9.0.0",
"dedent": "1.5.3",
"execa": "5.0.0",
"file-url": "3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy-structure/commands/create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"console-control-strings": "^1.1.0",
"conventional-changelog-core": "5.0.1",
"conventional-recommended-bump": "7.0.1",
"cosmiconfig": "^8.2.0",
"cosmiconfig": "9.0.0",
"dedent": "1.5.3",
"execa": "5.0.0",
"fs-extra": "^11.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/lerna/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"conventional-changelog-angular": "7.0.0",
"conventional-changelog-core": "5.0.1",
"conventional-recommended-bump": "7.0.1",
"cosmiconfig": "^8.2.0",
"cosmiconfig": "9.0.0",
"dedent": "1.5.3",
"envinfo": "7.13.0",
"execa": "5.0.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/lerna/schemas/lerna-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"type": "string",
"description": "The JSON schema version used to validate this configuration file"
},
"extends": {
"type": "string",
"description": "A shareable configuration preset that will be used as the base for this configuration"
},
"version": {
"type": "string",
"description": "The version of the repository, or \"independent\" for a repository with independently versioned packages.",
Expand Down

0 comments on commit eede69e

Please sign in to comment.