@scaleway/changesets-renovate 2.2.2 → 2.2.3

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/dist/cli.js ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import { env } from "node:process";
3
+ import { simpleGit } from "simple-git";
4
+ import { handleCatalogChanges } from "./handle-catalog.js";
5
+ import { handlePackageChanges } from "./handle-packages.js";
6
+ async function run() {
7
+ const branch = await simpleGit().branch();
8
+ const branchPrefix = env["BRANCH_PREFIX"] ?? "renovate/";
9
+ console.log("Detected branch:", branch);
10
+ if (!(branch.current.startsWith(branchPrefix) || env["SKIP_BRANCH_CHECK"])) {
11
+ console.log("Not a renovate branch, skipping");
12
+ return;
13
+ }
14
+ const diffOutput = await simpleGit().diffSummary(["--name-only", "HEAD~1"]);
15
+ const diffFiles = diffOutput.files.map((file) => file.file);
16
+ console.log("Found changed files:", diffFiles);
17
+ if (diffFiles.find((f) => f.startsWith(".changeset"))) {
18
+ console.log("Changeset already exists, skipping");
19
+ return;
20
+ }
21
+ const hasPackageChanges = diffFiles.some(
22
+ (file) => file.includes("package.json")
23
+ );
24
+ const hasWorkspaceChanges = diffFiles.some(
25
+ (file) => file.includes("pnpm-workspace.yaml")
26
+ );
27
+ if (!(hasPackageChanges || hasWorkspaceChanges)) {
28
+ console.log("No relevant changes detected, skipping");
29
+ return;
30
+ }
31
+ if (hasWorkspaceChanges) {
32
+ console.log("📚 Processing pnpm workspace catalog changes...");
33
+ await handleCatalogChanges(diffFiles);
34
+ }
35
+ if (hasPackageChanges) {
36
+ console.log("📦 Processing package.json changes...");
37
+ await handlePackageChanges(diffFiles);
38
+ }
39
+ }
40
+ run().catch(console.error);
41
+ export {
42
+ run
43
+ };
@@ -0,0 +1 @@
1
+ export declare function createChangeset(fileName: string, packageBumps: Map<string, string>, packages: string[]): Promise<void>;
@@ -0,0 +1,24 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { env } from "node:process";
3
+ async function createChangeset(fileName, packageBumps, packages) {
4
+ const messageLines = [];
5
+ for (const [pkg, bump] of packageBumps) {
6
+ messageLines.push(`Updated dependency \`${pkg}\` to \`${bump}\`.`);
7
+ }
8
+ if (env["SORT_CHANGESETS"]) {
9
+ packages.sort();
10
+ messageLines.sort();
11
+ }
12
+ const message = messageLines.join("\n");
13
+ const pkgs = packages.map((pkg) => `'${pkg}': patch`).join("\n");
14
+ const body = `---
15
+ ${pkgs}
16
+ ---
17
+
18
+ ${message.trim()}
19
+ `;
20
+ await writeFile(fileName, body);
21
+ }
22
+ export {
23
+ createChangeset
24
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Load catalog from pnpm workspace file at specific git revision
3
+ * @param revision Git revision to load file from (default: HEAD)
4
+ * @param filePath Path to the pnpm workspace file (default: pnpm-workspace.yaml)
5
+ * @returns Catalog object or empty object if not found
6
+ */
7
+ export declare function loadCatalogFromGit(revision?: string, filePath?: string): Promise<Record<string, string>>;
8
+ /**
9
+ * Find changed dependencies between two git revisions of pnpm workspace
10
+ * @param oldRevision The previous git revision
11
+ * @param newRevision The current git revision (default: HEAD)
12
+ * @param filePath Path to the pnpm workspace file (default: pnpm-workspace.yaml)
13
+ * @returns Array of package names that have changed
14
+ */
15
+ export declare function findChangedDependenciesFromGit(oldRevision: string, newRevision?: string, filePath?: string): Promise<Map<string, string>>;
16
+ export declare function getBumpsFromGit(files: string[]): Promise<Map<string, string>>;
17
+ /**
18
+ * Find packages affected by dependency changes
19
+ * @param changedDeps Array of changed dependency names
20
+ * @param packageJsonGlob Glob pattern to find package.json files
21
+ * @returns Set of package names that are affected by the changes
22
+ */
23
+ export declare function findAffectedPackages(changedDeps: string[], packageJsonGlob?: string): Promise<Set<string>>;
24
+ export declare function handleChangesetFile(fileName: string): Promise<void>;
@@ -0,0 +1,86 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { env } from "node:process";
3
+ import fg from "fast-glob";
4
+ import { load } from "js-yaml";
5
+ import { simpleGit } from "simple-git";
6
+ const { globSync } = fg;
7
+ async function loadCatalogFromGit(revision = "HEAD", filePath = "pnpm-workspace.yaml") {
8
+ try {
9
+ if (!revision) {
10
+ return {};
11
+ }
12
+ const git = simpleGit();
13
+ const content = await git.show([`${revision}:${filePath}`]);
14
+ const parsed = load(content);
15
+ return parsed?.catalog ?? {};
16
+ } catch {
17
+ return {};
18
+ }
19
+ }
20
+ async function findChangedDependenciesFromGit(oldRevision, newRevision = "HEAD", filePath = "pnpm-workspace.yaml") {
21
+ const oldCatalog = await loadCatalogFromGit(oldRevision, filePath);
22
+ const newCatalog = await loadCatalogFromGit(newRevision, filePath);
23
+ const bumps = /* @__PURE__ */ new Map();
24
+ const filtedPackage = Object.entries(newCatalog).filter(
25
+ ([pkg, newVersion]) => oldCatalog[pkg] && oldCatalog[pkg] !== newVersion
26
+ );
27
+ for (const [pkg, newVersion] of filtedPackage) {
28
+ bumps.set(pkg, newVersion);
29
+ }
30
+ return bumps;
31
+ }
32
+ async function getBumpsFromGit(files) {
33
+ const bumps = /* @__PURE__ */ new Map();
34
+ const promises = files.map(async (file) => {
35
+ const changes = await simpleGit().show([file]);
36
+ for (const change of changes.split("\n")) {
37
+ if (change.startsWith("+ ")) {
38
+ const match = change.match(/"(.*?)"/g);
39
+ if (match?.[0] && match[1]) {
40
+ bumps.set(match[0].replace(/"/g, ""), match[1].replace(/"/g, ""));
41
+ }
42
+ }
43
+ }
44
+ });
45
+ await Promise.all(promises);
46
+ return bumps;
47
+ }
48
+ async function findAffectedPackages(changedDeps, packageJsonGlob = "packages/*/package.json") {
49
+ if (changedDeps.length === 0) {
50
+ return /* @__PURE__ */ new Set();
51
+ }
52
+ const packageJsonPaths = globSync(packageJsonGlob);
53
+ const affectedPackages = /* @__PURE__ */ new Set();
54
+ for (const pkgJsonPath of packageJsonPaths) {
55
+ try {
56
+ const json = JSON.parse(await readFile(pkgJsonPath, "utf8"));
57
+ const deps = {
58
+ ...json.dependencies,
59
+ ...json.devDependencies,
60
+ ...json.peerDependencies
61
+ };
62
+ for (const dep of changedDeps) {
63
+ if (deps[dep]) {
64
+ affectedPackages.add(json.name);
65
+ break;
66
+ }
67
+ }
68
+ } catch {
69
+ }
70
+ }
71
+ return affectedPackages;
72
+ }
73
+ async function handleChangesetFile(fileName) {
74
+ if (!env["SKIP_COMMIT"]) {
75
+ await simpleGit().add(fileName);
76
+ await simpleGit().commit(`chore: add ${fileName}`);
77
+ await simpleGit().push();
78
+ }
79
+ }
80
+ export {
81
+ findAffectedPackages,
82
+ findChangedDependenciesFromGit,
83
+ getBumpsFromGit,
84
+ handleChangesetFile,
85
+ loadCatalogFromGit
86
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Handle pnpm workspace catalog changes
3
+ */
4
+ export declare function handleCatalogChanges(diffFiles: string[]): Promise<void>;
@@ -0,0 +1,48 @@
1
+ import { simpleGit } from "simple-git";
2
+ import { createChangeset } from "./createChangeset.js";
3
+ const {
4
+ findChangedDependenciesFromGit,
5
+ findAffectedPackages,
6
+ handleChangesetFile
7
+ } = await import("./git-utils.js");
8
+ async function handleCatalogChanges(diffFiles) {
9
+ const workspaceFiles = diffFiles.filter(
10
+ (file) => file.includes("pnpm-workspace.yaml")
11
+ );
12
+ if (workspaceFiles.length === 0) {
13
+ return;
14
+ }
15
+ console.log(
16
+ "🔍 Detected pnpm workspace changes, checking for catalog updates..."
17
+ );
18
+ console.log("🔍 Comparing catalogs: HEAD~1 -> HEAD");
19
+ const changedDeps = await findChangedDependenciesFromGit(
20
+ "HEAD~1",
21
+ "HEAD",
22
+ "pnpm-workspace.yaml"
23
+ );
24
+ if (changedDeps.size === 0) {
25
+ console.log("✅ No catalog dependency changes.", { changedDeps });
26
+ return;
27
+ }
28
+ console.log("📦 Changed dependencies:", changedDeps);
29
+ const affectedPackages = await findAffectedPackages([...changedDeps.keys()]);
30
+ if (affectedPackages.size === 0) {
31
+ console.log("📦 No packages affected by catalog changes.");
32
+ return;
33
+ }
34
+ console.log("\n📝 Affected packages:");
35
+ for (const pkg of affectedPackages) {
36
+ console.log(` - ${pkg}`);
37
+ }
38
+ console.log("\n✏️ Creating changesets...");
39
+ const packageNames = [...affectedPackages.keys()];
40
+ const shortHash = (await simpleGit().revparse(["--short", "HEAD"])).trim();
41
+ const fileName = `.changeset/renovate-${shortHash}.md`;
42
+ await createChangeset(fileName, changedDeps, packageNames);
43
+ await handleChangesetFile(fileName);
44
+ console.log("\n✅ Done creating changesets.");
45
+ }
46
+ export {
47
+ handleCatalogChanges
48
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Handle package.json changes (original Renovate flow)
3
+ */
4
+ export declare function handlePackageChanges(diffFiles: string[]): Promise<void>;
@@ -0,0 +1,24 @@
1
+ import { simpleGit } from "simple-git";
2
+ import { createChangeset } from "./createChangeset.js";
3
+ import { getBumpsFromGit, handleChangesetFile } from "./git-utils.js";
4
+ import { getPackagesNames } from "./utils.js";
5
+ async function handlePackageChanges(diffFiles) {
6
+ const files = diffFiles.filter((file) => file.includes("package.json"));
7
+ if (files.length === 0) {
8
+ console.log("No package.json changes to published packages, skipping");
9
+ return;
10
+ }
11
+ const packageNames = await getPackagesNames(files);
12
+ if (packageNames.length === 0) {
13
+ console.log("No packages modified, skipping");
14
+ return;
15
+ }
16
+ const shortHash = (await simpleGit().revparse(["--short", "HEAD"])).trim();
17
+ const fileName = `.changeset/renovate-${shortHash}.md`;
18
+ const packageBumps = await getBumpsFromGit(files);
19
+ await createChangeset(fileName, packageBumps, packageNames);
20
+ await handleChangesetFile(fileName);
21
+ }
22
+ export {
23
+ handlePackageChanges
24
+ };
@@ -0,0 +1,29 @@
1
+ export declare function shouldIgnorePackage(packageName: string, ignoredPackages: string[]): boolean;
2
+ export declare function getChangesetIgnoredPackages(): Promise<string[]>;
3
+ export declare function getPackagesNames(files: string[]): Promise<string[]>;
4
+ /**
5
+ * Load catalog from a YAML file
6
+ * @param filePath Path to the YAML file containing the catalog
7
+ * @returns Catalog object or empty object if not found
8
+ */
9
+ export declare function loadCatalogFromFile(filePath: string): Promise<Record<string, string>>;
10
+ /**
11
+ * Load catalog from pnpm workspace YAML content
12
+ * @param content Content of the pnpm-workspace.yaml file
13
+ * @returns Catalog object or empty object if not found
14
+ */
15
+ export declare function loadCatalogFromWorkspaceContent(content: string): Record<string, string>;
16
+ /**
17
+ * Find changed dependencies between two catalogs
18
+ * @param oldCatalog The previous catalog
19
+ * @param newCatalog The current catalog
20
+ * @returns Array of package names that have changed
21
+ */
22
+ export declare function findChangedDependencies(oldCatalog: Record<string, string>, newCatalog: Record<string, string>): string[];
23
+ /**
24
+ * Find packages affected by dependency changes
25
+ * @param changedDeps Array of changed dependency names
26
+ * @param packageJsonGlob Glob pattern to find package.json files
27
+ * @returns Set of package names that are affected by the changes
28
+ */
29
+ export declare function findAffectedPackages(changedDeps: string[], packageJsonGlob?: string): Promise<Set<string>>;
package/dist/utils.js ADDED
@@ -0,0 +1,38 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import fg from "fast-glob";
3
+ import "js-yaml";
4
+ const { globSync } = fg;
5
+ function shouldIgnorePackage(packageName, ignoredPackages) {
6
+ return ignoredPackages.some((ignoredPackage) => {
7
+ if (ignoredPackage.endsWith("*")) {
8
+ return packageName.startsWith(ignoredPackage.slice(0, -1));
9
+ }
10
+ return packageName === ignoredPackage;
11
+ });
12
+ }
13
+ async function getChangesetIgnoredPackages() {
14
+ const changesetConfig = JSON.parse(
15
+ await readFile(".changeset/config.json", "utf8")
16
+ );
17
+ return changesetConfig.ignore ?? [];
18
+ }
19
+ async function getPackagesNames(files) {
20
+ const ignoredPackages = await getChangesetIgnoredPackages();
21
+ const packages = [];
22
+ const promises = files.map(async (file) => {
23
+ const data = JSON.parse(await readFile(file, "utf8"));
24
+ if (shouldIgnorePackage(data.name, ignoredPackages)) {
25
+ return;
26
+ }
27
+ if (!data.workspaces && data.version) {
28
+ packages.push(data.name);
29
+ }
30
+ });
31
+ await Promise.all(promises);
32
+ return packages;
33
+ }
34
+ export {
35
+ getChangesetIgnoredPackages,
36
+ getPackagesNames,
37
+ shouldIgnorePackage
38
+ };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@scaleway/changesets-renovate",
3
- "version": "2.2.2",
4
- "description": "Automatically create changesets for Renovate",
3
+ "version": "2.2.3",
4
+ "description": "Automatically create changesets for Renovate and pnpm catalogs",
5
5
  "type": "module",
6
- "module": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
6
+ "module": "./dist/cli.js",
7
+ "types": "./dist/cli.d.ts",
8
8
  "sideEffects": false,
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "default": "./dist/index.js"
11
+ "types": "./dist/cli.d.ts",
12
+ "default": "./dist/cli.js"
13
13
  }
14
14
  },
15
15
  "files": [
@@ -19,7 +19,7 @@
19
19
  "node": ">=20.x"
20
20
  },
21
21
  "bin": {
22
- "changesets-renovate": "dist/index.js"
22
+ "changesets-renovate": "dist/cli.js"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"
@@ -33,15 +33,22 @@
33
33
  "keywords": [
34
34
  "changesets",
35
35
  "renovate",
36
+ "pnpm",
37
+ "catalogs",
36
38
  "sync"
37
39
  ],
38
40
  "dependencies": {
41
+ "@types/js-yaml": "4.0.9",
42
+ "fast-glob": "3.3.3",
43
+ "js-yaml": "4.1.1",
39
44
  "simple-git": "3.30.0"
40
45
  },
41
46
  "scripts": {
42
47
  "prebuild": "shx rm -rf dist",
43
48
  "typecheck": "tsc --noEmit",
49
+ "typecheck:go": "tsgo --noEmit",
44
50
  "type:generate": "tsc --declaration -p tsconfig.build.json",
51
+ "type:generate:go": "tsgo --declaration -p tsconfig.build.json",
45
52
  "build": "vite build --config vite.config.ts && pnpm run type:generate",
46
53
  "build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
47
54
  "lint": "eslint --report-unused-disable-directives --cache --cache-strategy content --ext ts,tsx .",
package/dist/index.js DELETED
@@ -1,107 +0,0 @@
1
- #!/usr/bin/env node
2
- import fs from "node:fs/promises";
3
- import { simpleGit } from "simple-git";
4
- console.debug("simpleGit", simpleGit);
5
- async function getChangesetIgnoredPackages() {
6
- const changesetConfig = JSON.parse(
7
- await fs.readFile(".changeset/config.json", "utf8")
8
- );
9
- return changesetConfig.ignore ?? [];
10
- }
11
- function shouldIgnorePackage(packageName, ignoredPackages) {
12
- return ignoredPackages.some((ignoredPackage) => {
13
- if (ignoredPackage.endsWith("*")) {
14
- return packageName.startsWith(ignoredPackage.slice(0, -1));
15
- }
16
- return packageName === ignoredPackage;
17
- });
18
- }
19
- async function getPackagesNames(files) {
20
- const ignoredPackages = await getChangesetIgnoredPackages();
21
- const packages = [];
22
- const promises = files.map(async (file) => {
23
- const data = JSON.parse(await fs.readFile(file, "utf8"));
24
- if (shouldIgnorePackage(data.name, ignoredPackages)) {
25
- return;
26
- }
27
- if (!data.workspaces && data.version) {
28
- packages.push(data.name);
29
- }
30
- });
31
- await Promise.all(promises);
32
- return packages;
33
- }
34
- async function createChangeset(fileName, packageBumps, packages) {
35
- const messageLines = [];
36
- for (const [pkg, bump] of packageBumps) {
37
- messageLines.push(`Updated dependency \`${pkg}\` to \`${bump}\`.`);
38
- }
39
- if (process.env["SORT_CHANGESETS"]) {
40
- packages.sort();
41
- messageLines.sort();
42
- }
43
- const message = messageLines.join("\n");
44
- const pkgs = packages.map((pkg) => `'${pkg}': patch`).join("\n");
45
- const body = `---
46
- ${pkgs}
47
- ---
48
-
49
- ${message.trim()}
50
- `;
51
- await fs.writeFile(fileName, body);
52
- }
53
- async function getBumps(files) {
54
- const bumps = /* @__PURE__ */ new Map();
55
- const promises = files.map(async (file) => {
56
- const changes = await simpleGit().show([file]);
57
- for (const change of changes.split("\n")) {
58
- if (change.startsWith("+ ")) {
59
- const match = change.match(/"(.*?)"/g);
60
- if (match?.[0] && match[1]) {
61
- bumps.set(match[0].replace(/"/g, ""), match[1].replace(/"/g, ""));
62
- }
63
- }
64
- }
65
- });
66
- await Promise.all(promises);
67
- return bumps;
68
- }
69
- async function run() {
70
- const branch = await simpleGit().branch();
71
- const branchPrefix = process.env["BRANCH_PREFIX"] ?? "renovate/";
72
- console.log("Detected branch:", branch);
73
- if (!branch.current.startsWith(branchPrefix) && !process.env["SKIP_BRANCH_CHECK"]) {
74
- console.log("Not a renovate branch, skipping");
75
- return;
76
- }
77
- const diffOutput = await simpleGit().diffSummary(["--name-only", "HEAD~1"]);
78
- const diffFiles = diffOutput.files.map((file) => file.file);
79
- console.log("Found changed files:", diffFiles);
80
- if (diffFiles.find((f) => f.startsWith(".changeset"))) {
81
- console.log("Changeset already exists, skipping");
82
- return;
83
- }
84
- const files = diffFiles.filter((file) => file.includes("package.json"));
85
- if (!files.length) {
86
- console.log("No package.json changes to published packages, skipping");
87
- return;
88
- }
89
- const packageNames = await getPackagesNames(files);
90
- if (packageNames.length === 0) {
91
- console.log("No packages modified, skipping");
92
- return;
93
- }
94
- const shortHash = (await simpleGit().revparse(["--short", "HEAD"])).trim();
95
- const fileName = `.changeset/renovate-${shortHash}.md`;
96
- const packageBumps = await getBumps(files);
97
- await createChangeset(fileName, packageBumps, packageNames);
98
- if (!process.env["SKIP_COMMIT"]) {
99
- await simpleGit().add(fileName);
100
- await simpleGit().commit(`chore: add changeset renovate-${shortHash}`);
101
- await simpleGit().push();
102
- }
103
- }
104
- run().catch(console.error);
105
- export {
106
- run
107
- };
File without changes