diff --git a/dist/changelog.js b/dist/changelog.js index 63d7b41..89a7c63 100644 --- a/dist/changelog.js +++ b/dist/changelog.js @@ -4209,9 +4209,12 @@ function getPackageChangelog(context, changelogFile, headerLine) { } function updatePackageChangelog(context, changelogFile, headerLine) { var _a; - if (context.version.new !== context.version.old && fs.existsSync(changelogFile)) { + if (fs.existsSync(changelogFile)) { const oldContents = fs.readFileSync(changelogFile, "utf-8"); const newVersion = ((_a = context.version.overrides[path.dirname(changelogFile)]) == null ? void 0 : _a.new) || context.version.new; + if (oldContents.includes(`## \`${newVersion}\``)) { + return false; + } const newContents = oldContents.replace(headerLine, `## \`${newVersion}\``); if (newContents !== oldContents) { fs.writeFileSync(changelogFile, newContents); diff --git a/dist/lerna.js b/dist/lerna.js index 1ed3026..18ea589 100644 --- a/dist/lerna.js +++ b/dist/lerna.js @@ -5526,6 +5526,7 @@ var require_glob = __commonJS({ // src/index.ts var src_exports = {}; __export(src_exports, { + IS_LERNA_JSON_TEMP: () => IS_LERNA_JSON_TEMP, init: () => init_default, publish: () => publish_default, success: () => success_default, @@ -5539,6 +5540,9 @@ var fs2 = __toESM(require("fs")); var path = __toESM(require("path")); var import_npm = require("./npm"); +// src/config.ts +var IS_LERNA_JSON_TEMP = Symbol(); + // src/utils.ts var utils_exports = {}; __export(utils_exports, { @@ -5602,12 +5606,15 @@ function init_default(context, config) { return __async(this, null, function* () { var _a; let publishConfig; - try { - const lernaJson = JSON.parse(fs2.readFileSync("lerna.json", "utf-8")); - context.version.new = lernaJson.version; - publishConfig = (_a = lernaJson.command) == null ? void 0 : _a.publish; - } catch (e) { - throw new Error(`Missing or invalid lerna.json in branch ${context.branch.name}`); + config[IS_LERNA_JSON_TEMP] = !fs2.existsSync("lerna.json"); + if (!config[IS_LERNA_JSON_TEMP]) { + try { + const lernaJson = JSON.parse(fs2.readFileSync("lerna.json", "utf-8")); + context.version.new = lernaJson.version; + publishConfig = (_a = lernaJson.command) == null ? void 0 : _a.publish; + } catch (e) { + throw new Error(`Missing or invalid lerna.json in branch ${context.branch.name}`); + } } try { const packageJson = JSON.parse(fs2.readFileSync("package.json", "utf-8")); @@ -5615,6 +5622,13 @@ function init_default(context, config) { if (publishConfig == null) { publishConfig = packageJson.publishConfig; } + if (config[IS_LERNA_JSON_TEMP]) { + context.version.new = packageJson.version; + fs2.writeFileSync("lerna.json", JSON.stringify({ + version: packageJson.version, + useWorkspaces: true + }, null, 2)); + } } catch (e) { throw new Error(`Missing or invalid package.json in branch ${context.branch.name}`); } @@ -5688,7 +5702,10 @@ function version_default2(context, config) { } } yield lernaPostVersion(); - context.changedFiles.push("lerna.json", "package.json"); + context.changedFiles.push("package.json"); + if (!config[IS_LERNA_JSON_TEMP]) { + context.changedFiles.push("lerna.json"); + } const lockfilePath = yield (0, import_find_up.default)(["pnpm-lock.yaml", "yarn.lock", "npm-shrinkwrap.json", "package-lock.json"]); if (lockfilePath != null) { context.changedFiles.push(path2.relative(context.rootDir, lockfilePath)); @@ -5727,6 +5744,7 @@ function updateIndependentVersion(context, pkgInfo, newVersion) { } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { + IS_LERNA_JSON_TEMP, init, publish, success, diff --git a/packages/changelog/src/version.ts b/packages/changelog/src/version.ts index 5843387..d4054ea 100644 --- a/packages/changelog/src/version.ts +++ b/packages/changelog/src/version.ts @@ -88,11 +88,14 @@ function getPackageChangelog(context: IContext, changelogFile: string, headerLin } function updatePackageChangelog(context: IContext, changelogFile: string, headerLine: string): boolean { - if (context.version.new !== context.version.old && fs.existsSync(changelogFile)) { + if (fs.existsSync(changelogFile)) { const oldContents = fs.readFileSync(changelogFile, "utf-8"); const newVersion = context.version.overrides[path.dirname(changelogFile)]?.new || context.version.new; - const newContents = oldContents.replace(headerLine, `## \`${newVersion}\``); + if (oldContents.includes(`## \`${newVersion}\``)) { + return false; + } + const newContents = oldContents.replace(headerLine, `## \`${newVersion}\``); if (newContents !== oldContents) { fs.writeFileSync(changelogFile, newContents); context.logger.info(`Updated version header in ${changelogFile}`) diff --git a/packages/lerna/src/config.ts b/packages/lerna/src/config.ts index df363e9..0e60edc 100644 --- a/packages/lerna/src/config.ts +++ b/packages/lerna/src/config.ts @@ -16,7 +16,10 @@ import { IPluginConfig as NpmPluginConfig } from "@octorelease/npm"; +export const IS_LERNA_JSON_TEMP = Symbol(); + export type IPluginConfig = NpmPluginConfig & { pruneShrinkwrap?: boolean | string[]; versionIndependent?: string[]; + [IS_LERNA_JSON_TEMP]?: boolean; }; diff --git a/packages/lerna/src/init.ts b/packages/lerna/src/init.ts index da13b55..1ebce28 100644 --- a/packages/lerna/src/init.ts +++ b/packages/lerna/src/init.ts @@ -18,17 +18,20 @@ import * as fs from "fs"; import * as path from "path"; import { IContext } from "@octorelease/core"; import { DEFAULT_NPM_REGISTRY, utils as npmUtils } from "@octorelease/npm"; -import { IPluginConfig } from "./config"; +import { IPluginConfig, IS_LERNA_JSON_TEMP } from "./config"; import * as utils from "./utils"; export default async function (context: IContext, config: IPluginConfig): Promise { let publishConfig; - try { - const lernaJson = JSON.parse(fs.readFileSync("lerna.json", "utf-8")); - context.version.new = lernaJson.version; - publishConfig = lernaJson.command?.publish; - } catch { - throw new Error(`Missing or invalid lerna.json in branch ${context.branch.name}`); + config[IS_LERNA_JSON_TEMP] = !fs.existsSync("lerna.json"); + if (!config[IS_LERNA_JSON_TEMP]) { + try { + const lernaJson = JSON.parse(fs.readFileSync("lerna.json", "utf-8")); + context.version.new = lernaJson.version; + publishConfig = lernaJson.command?.publish; + } catch { + throw new Error(`Missing or invalid lerna.json in branch ${context.branch.name}`); + } } try { @@ -37,6 +40,13 @@ export default async function (context: IContext, config: IPluginConfig): Promis if (publishConfig == null) { publishConfig = packageJson.publishConfig; } + if (config[IS_LERNA_JSON_TEMP]) { + context.version.new = packageJson.version; + fs.writeFileSync("lerna.json", JSON.stringify({ + version: packageJson.version, + useWorkspaces: true + }, null, 2)); + } } catch { throw new Error(`Missing or invalid package.json in branch ${context.branch.name}`); } diff --git a/packages/lerna/src/version.ts b/packages/lerna/src/version.ts index 5a992c9..b8eaf9e 100644 --- a/packages/lerna/src/version.ts +++ b/packages/lerna/src/version.ts @@ -20,7 +20,7 @@ import findUp from "find-up"; import * as glob from "@actions/glob"; import { IContext } from "@octorelease/core"; import { utils as npmUtils } from "@octorelease/npm"; -import { IPluginConfig } from "./config"; +import { IPluginConfig, IS_LERNA_JSON_TEMP } from "./config"; import * as utils from "./utils"; export default async function (context: IContext, config: IPluginConfig): Promise { @@ -47,7 +47,10 @@ export default async function (context: IContext, config: IPluginConfig): Promis } await utils.lernaPostVersion(); // Update lockfile because lerna doesn't - context.changedFiles.push("lerna.json", "package.json"); + context.changedFiles.push("package.json"); + if (!config[IS_LERNA_JSON_TEMP]) { + context.changedFiles.push("lerna.json"); + } const lockfilePath = await findUp(["pnpm-lock.yaml", "yarn.lock", "npm-shrinkwrap.json", "package-lock.json"]); if (lockfilePath != null) { context.changedFiles.push(path.relative(context.rootDir, lockfilePath));