diff --git a/package-lock.json b/package-lock.json index eddff3d..3bad7af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -360,6 +360,17 @@ "node": ">=v14" } }, + "node_modules/@commitlint/config-conventional/node_modules/conventional-changelog-conventionalcommits": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-6.1.0.tgz", + "integrity": "sha512-3cS3GEtR78zTfMzk0AizXKKIdN4OvSh7ibNz6/DPbhWWQu7LqE/8+/GqSodV+sywUR2gpJAdP/1JFf4XtN7Zpw==", + "dependencies": { + "compare-func": "^2.0.0" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/@commitlint/config-validator": { "version": "17.6.7", "resolved": "https://registry.npmjs.org/@commitlint/config-validator/-/config-validator-17.6.7.tgz", @@ -4460,14 +4471,14 @@ } }, "node_modules/conventional-changelog-conventionalcommits": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-6.1.0.tgz", - "integrity": "sha512-3cS3GEtR78zTfMzk0AizXKKIdN4OvSh7ibNz6/DPbhWWQu7LqE/8+/GqSodV+sywUR2gpJAdP/1JFf4XtN7Zpw==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-7.0.2.tgz", + "integrity": "sha512-NKXYmMR/Hr1DevQegFB4MwfM5Vv0m4UIxKZTTYuD98lpTknaZlSRrDOG4X7wIXpGkfsYxZTghUN+Qq+T0YQI7w==", "dependencies": { "compare-func": "^2.0.0" }, "engines": { - "node": ">=14" + "node": ">=16" } }, "node_modules/conventional-changelog-core": { @@ -4904,18 +4915,6 @@ "node": ">=16" } }, - "node_modules/conventional-changelog/node_modules/conventional-changelog-conventionalcommits": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-7.0.2.tgz", - "integrity": "sha512-NKXYmMR/Hr1DevQegFB4MwfM5Vv0m4UIxKZTTYuD98lpTknaZlSRrDOG4X7wIXpGkfsYxZTghUN+Qq+T0YQI7w==", - "peer": true, - "dependencies": { - "compare-func": "^2.0.0" - }, - "engines": { - "node": ">=16" - } - }, "node_modules/conventional-commits-filter": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/conventional-commits-filter/-/conventional-commits-filter-4.0.0.tgz", @@ -5135,9 +5134,9 @@ "integrity": "sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==" }, "node_modules/daisyui": { - "version": "3.9.2", - "resolved": "https://registry.npmjs.org/daisyui/-/daisyui-3.9.2.tgz", - "integrity": "sha512-yJZ1QjHUaL+r9BkquTdzNHb7KIgAJVFh0zbOXql2Wu0r7zx5qZNLxclhjN0WLoIpY+o2h/8lqXg7ijj8oTigOw==", + "version": "3.9.3", + "resolved": "https://registry.npmjs.org/daisyui/-/daisyui-3.9.3.tgz", + "integrity": "sha512-8li177QCu6dqlEOzE3h/dAV1y9Movbjx5bzJIO/hNqMNZtJkbHM0trjTzbDejV7N57eNGdjBvAGtxZYKzS4jow==", "dev": true, "dependencies": { "colord": "^2.9", @@ -5449,9 +5448,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.556", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.556.tgz", - "integrity": "sha512-6RPN0hHfzDU8D56E72YkDvnLw5Cj2NMXZGg3UkgyoHxjVhG99KZpsKgBWMmTy0Ei89xwan+rbRsVB9yzATmYzQ==", + "version": "1.4.557", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.557.tgz", + "integrity": "sha512-6x0zsxyMXpnMJnHrondrD3SuAeKcwij9S+83j2qHAQPXbGTDDfgImzzwgGlzrIcXbHQ42tkG4qA6U860cImNhw==", "dev": true }, "node_modules/emoji-regex": { @@ -9100,9 +9099,9 @@ "integrity": "sha512-EZSPZB70jiVsivaBLYDCyntd5eH8NTSMOn3rB+HxwdmKThGELLdYv8qVIMWvZEFy9w8ZZpW9h9OB32l1rGtj7g==" }, "node_modules/node-abi": { - "version": "3.50.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.50.0.tgz", - "integrity": "sha512-2Gxu7Eq7vnBIRfYSmqPruEllMM14FjOQFJSoqdGWthVn+tmwEXzmdPpya6cvvwf0uZA3F5N1fMFr9mijZBplFA==", + "version": "3.51.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.51.0.tgz", + "integrity": "sha512-SQkEP4hmNWjlniS5zdnfIXTk1x7Ome85RDzHlTbBtzE97Gfwz/Ipw4v/Ryk20DWIy3yCNVLVlGKApCnmvYoJbA==", "dependencies": { "semver": "^7.3.5" }, @@ -16407,16 +16406,18 @@ }, "packages/conventional-changelog": { "name": "@deopea.os/conventional-changelog", - "version": "1.0.0", + "version": "2.0.0-alpha.1", "license": "MIT", "devDependencies": { "@types/conventional-changelog": "^3.1.3", "@types/conventional-changelog-config-spec": "^2.1.3", "@types/node": "^20.8.4", + "conventional-changelog-conventionalcommits": "*", "typescript": "*" }, "peerDependencies": { "conventional-changelog": "^5.1.0", + "conventional-changelog-conventionalcommits": "^7.0.0", "typescript": "^5.0.0" } }, diff --git a/packages/conventional-changelog/index.ts b/packages/conventional-changelog/index.ts index 9330027..b45b83e 100644 --- a/packages/conventional-changelog/index.ts +++ b/packages/conventional-changelog/index.ts @@ -19,9 +19,11 @@ const config: Config = { ], }; -const options: conventionalConfig.ResolvedConfig & { config: typeof config } = { +const options = (): conventionalConfig.ResolvedConfig & { + config: typeof config; +} => ({ ...conventionalConfig(config), config, -}; +}); export = options; diff --git a/packages/conventional-changelog/package.json b/packages/conventional-changelog/package.json index 26c80bc..685ddb8 100644 --- a/packages/conventional-changelog/package.json +++ b/packages/conventional-changelog/package.json @@ -17,12 +17,14 @@ }, "peerDependencies": { "conventional-changelog": "^5.1.0", + "conventional-changelog-conventionalcommits": "^7.0.0", "typescript": "^5.0.0" }, "devDependencies": { "@types/conventional-changelog": "^3.1.3", "@types/conventional-changelog-config-spec": "^2.1.3", "@types/node": "^20.8.4", + "conventional-changelog-conventionalcommits": "*", "typescript": "*" }, "keywords": [ diff --git a/packages/semantic-release-config/src/release-workspaces.cts b/packages/semantic-release-config/src/release-workspaces.cts index afaa760..323d3fb 100644 --- a/packages/semantic-release-config/src/release-workspaces.cts +++ b/packages/semantic-release-config/src/release-workspaces.cts @@ -4,44 +4,43 @@ import type { Commit, GenerateNotesContext, GlobalConfig, + Options, } from "semantic-release"; import path = require("path"); import pkgUp = require("read-pkg-up"); import simpleGit = require("simple-git"); +import utils = require("./utils.cjs"); const pkg: NormalizedReadResult | undefined = pkgUp.sync(); const pkgDir = pkg && path.dirname(pkg.path); const git = simpleGit.simpleGit(); -const verifyConditions = () => { - if (!pkg) throw new Error("package.json unavailable"); -}; +let _commitsCache: Record> = {}; +const getPackageCommits = async (commits: readonly Commit[]) => + (_commitsCache[pkg!.packageJson.name] ??= await Promise.all( + commits.map(async (cmt) => { + const res = await git.show(["--stat", cmt.hash, pkgDir!]); + return { + ...cmt, + include: Boolean(res), + }; + }), + ).then((cs) => cs.filter((c) => c.include))); -let commitsToInclude: Array | null = null; const wrapLifecycle = - (lifecycle: string) => + (lifecycle: "analyzeCommits" | "generateNotes") => async ( - config: GlobalConfig, + config: Options, { logger, - commits, + commits: allCommits, ...ctx }: (AnalyzeCommitsContext | GenerateNotesContext) & { options: GlobalConfig; }, ) => { - commitsToInclude ??= await Promise.all( - commits.map(async (cmt) => { - const res = await git.show(["--stat", cmt.hash, pkgDir!]); - logger.debug("Include commit:", cmt.hash, Boolean(res)); - - return { - ...cmt, - include: Boolean(res), - }; - }), - ).then((cs) => cs.filter((c) => c.include)); + const commitsToInclude = await getPackageCommits(allCommits); if (!commitsToInclude?.length) { logger.log("Release does not include changes for package"); @@ -52,16 +51,24 @@ const wrapLifecycle = let res: unknown; for (const plugin of ctx.options.plugins) { const pluginName = typeof plugin === "string" ? plugin : plugin[0]; + // const pluginOptions = + // typeof plugin === "string" + // ? {} + // : (plugin[1] as Record); - const module = await new Function(`return import("${pluginName}");`)(); + const module = await utils.dynamicImport(pluginName); if (!module[lifecycle]) continue; logger.success("Release workspaces", "loaded plugin", pluginName); - res = await module[lifecycle]?.(config, { - ...ctx, - logger, - commits, - }); + res = await module[lifecycle]?.( + // TODO: add in plugin options + config, + { + ...ctx, + logger, + commits: commitsToInclude, + }, + ); logger.success( "Release workspaces", "completed step", @@ -71,14 +78,15 @@ const wrapLifecycle = ); } - if (lifecycle === "generateNotes") { - logger.log(res); - } return res; }; +const verifyConditions = () => { + if (!pkg) throw new Error("package.json unavailable"); +}; + const onComplete = () => { - commitsToInclude = null; + _commitsCache = {}; }; export = { diff --git a/packages/semantic-release-config/src/utils.cts b/packages/semantic-release-config/src/utils.cts new file mode 100644 index 0000000..e154b65 --- /dev/null +++ b/packages/semantic-release-config/src/utils.cts @@ -0,0 +1,22 @@ +import type { + AnalyzeCommitsContext, + GenerateNotesContext, + Options, +} from "semantic-release"; + +// eslint-disable-next-line @typescript-eslint/no-implied-eval +const dynamicImport = new Function("moduleId", `return import(moduleId);`) as ( + moduleId: string, +) => Promise< + Record< + string, + ( + options: Options, + context: AnalyzeCommitsContext | GenerateNotesContext, + ) => Promise + > +>; + +export = { + dynamicImport, +};