@monoweave/changelog 2.7.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/changelog.js CHANGED
@@ -2,8 +2,8 @@ import { Readable } from 'stream';
2
2
  import { parseRepositoryProperty } from '@monoweave/git';
3
3
  import { readStream, readStreamString } from '@monoweave/io';
4
4
  import { structUtils } from '@yarnpkg/core';
5
- import conventionalChangelogWriter from 'conventional-changelog-writer';
6
- import conventionalCommitsParser from 'conventional-commits-parser';
5
+ import { writeChangelogStream } from 'conventional-changelog-writer';
6
+ import { parseCommitsStream } from 'conventional-commits-parser';
7
7
  import { defaultChangelogWriter } from './defaultChangelogWriter.js';
8
8
  import resolveConventionalConfig from './resolveConventionalConfig.js';
9
9
  export const generateChangelogEntry = async ({ config, context, packageName, previousVersion, newVersion, commits, }) => {
@@ -31,9 +31,9 @@ export const generateChangelogEntry = async ({ config, context, packageName, pre
31
31
  });
32
32
  }
33
33
  const conventionalConfig = await resolveConventionalConfig({ config });
34
- const commitsStream = Readable.from(commits.map((commit) => `${commit.body}\n-hash-\n${commit.sha}`)).pipe(conventionalCommitsParser(conventionalConfig.parserOpts));
34
+ const commitsStream = Readable.from(commits.map((commit) => `${commit.body}\n-hash-\n${commit.sha}`)).pipe(parseCommitsStream(conventionalConfig.parserOpts));
35
35
  const conventionalCommits = await readStream(commitsStream);
36
- const changelogWriter = conventionalChangelogWriter(templateContext, conventionalConfig.writerOpts);
36
+ const changelogWriter = writeChangelogStream(templateContext, conventionalConfig.writerOpts);
37
37
  async function* transformedCommits() {
38
38
  for (const commit of conventionalCommits) {
39
39
  // NOTE: This mutates the commit.
@@ -1,6 +1,6 @@
1
1
  import type { MonoweaveConfiguration } from '@monoweave/types';
2
2
  import type { Options as ConventionalCommitsWriterOptions } from 'conventional-changelog-writer';
3
- import type { Commit, Options as ConventionalCommitsParserOptions } from 'conventional-commits-parser';
3
+ import type { Commit, ParserOptions as ConventionalCommitsParserOptions } from 'conventional-commits-parser';
4
4
  interface ConventionalStrategy {
5
5
  level?: number | null;
6
6
  }
@@ -8,7 +8,7 @@ interface ConventionalChangelogConfig {
8
8
  parserOpts: ConventionalCommitsParserOptions;
9
9
  writerOpts: ConventionalCommitsWriterOptions;
10
10
  recommendedBumpOpts: {
11
- whatBump: (commits: Commit[]) => ConventionalStrategy;
11
+ whatBump: (commits: Commit[]) => ConventionalStrategy | Promise<ConventionalStrategy>;
12
12
  };
13
13
  }
14
14
  declare const resolveConventionalConfig: ({ config, }: {
@@ -1,4 +1,4 @@
1
- import { createRequire } from 'node:module';
1
+ import { pathToFileURL } from 'node:url';
2
2
  import { npath } from '@yarnpkg/fslib';
3
3
  const coerceConventionalConfig = (config) => {
4
4
  if (typeof config === 'string') {
@@ -8,6 +8,34 @@ const coerceConventionalConfig = (config) => {
8
8
  }
9
9
  return config;
10
10
  };
11
+ const normalizeConventionalConfig = (config) => {
12
+ const whatBump = config.recommendedBumpOpts?.whatBump ?? config.whatBump;
13
+ if (!whatBump) {
14
+ throw new Error('Conventional changelog config is missing whatBump');
15
+ }
16
+ return {
17
+ parserOpts: config.parserOpts ?? config.parser ?? {},
18
+ writerOpts: config.writerOpts ?? config.writer ?? {},
19
+ recommendedBumpOpts: { whatBump },
20
+ };
21
+ };
22
+ const unwrapModule = (mod) => {
23
+ if (mod && typeof mod === 'object' && 'default' in mod) {
24
+ const exported = mod.default;
25
+ if (typeof exported === 'function' || (exported && typeof exported === 'object')) {
26
+ return exported;
27
+ }
28
+ }
29
+ return mod;
30
+ };
31
+ const loadConventionalConfigModule = async (name, cwdPackageJson) => {
32
+ const parentURL = pathToFileURL(cwdPackageJson).href;
33
+ const resolvedURL = npath.isAbsolute(name)
34
+ ? pathToFileURL(name).href
35
+ : import.meta.resolve(name, parentURL);
36
+ const imported = await import(resolvedURL);
37
+ return unwrapModule(imported);
38
+ };
11
39
  const resolveConventionalConfig = async ({ config, }) => {
12
40
  const conventionalChangelogConfig = config.conventionalChangelogConfig;
13
41
  if (!conventionalChangelogConfig) {
@@ -15,9 +43,10 @@ const resolveConventionalConfig = async ({ config, }) => {
15
43
  }
16
44
  const conventionalConfig = coerceConventionalConfig(conventionalChangelogConfig);
17
45
  const nCwd = npath.join(npath.fromPortablePath(config.cwd), 'package.json');
18
- const conventionalConfigModule = createRequire(nCwd)(conventionalConfig.name);
19
- return await (typeof conventionalConfigModule === 'function'
46
+ const conventionalConfigModule = await loadConventionalConfigModule(conventionalConfig.name, nCwd);
47
+ const resolvedConfig = await (typeof conventionalConfigModule === 'function'
20
48
  ? conventionalConfigModule(conventionalConfig)
21
49
  : conventionalConfigModule);
50
+ return normalizeConventionalConfig(resolvedConfig);
22
51
  };
23
52
  export default resolveConventionalConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoweave/changelog",
3
- "version": "2.7.0",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,32 +31,31 @@
31
31
  "prepack": "run workspace:build \"$(pwd)\""
32
32
  },
33
33
  "peerDependencies": {
34
- "@monoweave/git": "^2.7.0",
35
- "@monoweave/io": "^2.7.0",
36
- "@monoweave/logging": "^2.7.0",
37
- "@monoweave/types": "^2.7.0",
38
- "@yarnpkg/core": "^4.9.0",
34
+ "@monoweave/git": "^3.0.0",
35
+ "@monoweave/io": "^3.0.0",
36
+ "@monoweave/logging": "^3.0.0",
37
+ "@monoweave/types": "^3.0.0",
38
+ "@yarnpkg/core": "^4.9.1",
39
39
  "@yarnpkg/fslib": "^3.1.5",
40
40
  "@yarnpkg/shell": "^4.1.3"
41
41
  },
42
42
  "dependencies": {
43
- "conventional-changelog-writer": "^7.0.1",
44
- "conventional-commits-parser": "^5.0.0",
45
- "p-limit": "^7.3.0"
43
+ "conventional-changelog-writer": "^9.2.1",
44
+ "conventional-commits-parser": "^7.1.2",
45
+ "p-limit": "^7.3.3"
46
46
  },
47
47
  "devDependencies": {
48
- "@monoweave/git": "2.7.0",
49
- "@monoweave/io": "2.7.0",
50
- "@monoweave/logging": "2.7.0",
48
+ "@monoweave/git": "3.0.0",
49
+ "@monoweave/io": "3.0.0",
50
+ "@monoweave/logging": "3.0.0",
51
51
  "@monoweave/test-utils": "0.0.0",
52
- "@monoweave/types": "2.7.0",
53
- "@types/conventional-changelog-writer": "^4.0.11",
54
- "@types/conventional-commits-parser": "^5.0.2",
55
- "@types/node": "^22.19.15",
56
- "@yarnpkg/core": "^4.9.0",
52
+ "@monoweave/types": "3.0.0",
53
+ "@types/node": "^26.6.3",
54
+ "@yarnpkg/core": "^4.9.1",
57
55
  "@yarnpkg/fslib": "^3.1.5",
58
56
  "@yarnpkg/shell": "^4.1.3",
59
- "vitest": "^4.1.9"
57
+ "vite": "^8.3.4",
58
+ "vitest": "^5.0.5"
60
59
  },
61
60
  "types": "./lib/index.d.ts"
62
61
  }