Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"apps/docs": "0.1.85",
"packages/core": "0.2.0",
"packages/react": "0.2.0",
"packages/vue": "0.2.0"
Expand Down
4 changes: 4 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"include-component-in-tag": false,
"separate-pull-requests": false,
"packages": {
"apps/docs": {
"release-type": "node"
},
"packages/core": {
"release-type": "node"
},
Expand All @@ -27,6 +30,7 @@
"type": "linked-versions",
"groupName": "cindor workspace",
"components": [
"cindor-ui-docs",
"cindor-ui-core",
"cindor-ui-react",
"cindor-ui-vue"
Expand Down
82 changes: 82 additions & 0 deletions scripts/release-please-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { readFileSync, readdirSync } from "node:fs";
import { join, resolve } from "node:path";

import { describe, expect, it } from "vitest";

type PackageManifest = {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
optionalDependencies?: Record<string, string>;
name: string;
private?: boolean;
version?: string;
};

type ReleasePleaseConfig = {
packages: Record<string, { "release-type": string }>;
plugins?: Array<{
components?: string[];
groupName?: string;
type: string;
}>;
};

const repoRoot = resolve(import.meta.dirname, "..");
const packageJsonSections = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"] as const;
const exactVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;

describe("release-please config", () => {
it("manages every workspace consumer with exact internal dependency pins", () => {
const manifests = getWorkspaceManifests();
const releasePleaseConfig = readJson<ReleasePleaseConfig>("release-please-config.json");
const managedPackagePaths = new Set(Object.keys(releasePleaseConfig.packages));
const linkedVersionComponents = new Set(
releasePleaseConfig.plugins
?.filter((plugin) => plugin.type === "linked-versions")
.flatMap((plugin) => plugin.components ?? []) ?? []
);
const workspacePackageNames = new Set(manifests.map(({ manifest }) => manifest.name));

const exactInternalConsumers = manifests.filter(({ manifest }) =>
packageJsonSections.some((section) =>
Object.entries(manifest[section] ?? {}).some(
([dependencyName, dependencyVersion]) =>
workspacePackageNames.has(dependencyName) && exactVersionPattern.test(dependencyVersion)
)
)
);

expect(exactInternalConsumers.map(({ packagePath }) => packagePath).sort()).toEqual([
"apps/docs/package.json",
"packages/react/package.json",
"packages/vue/package.json"
]);

for (const { packagePath } of exactInternalConsumers) {
const workspacePath = packagePath.replace(/\/package\.json$/, "");
expect(managedPackagePaths.has(workspacePath), `${workspacePath} must be managed by release-please`).toBe(true);
}

for (const { manifest, packagePath } of exactInternalConsumers) {
expect(linkedVersionComponents.has(manifest.name), `${packagePath} must participate in linked versions`).toBe(true);
}
});
});

function getWorkspaceManifests() {
const packagePaths = ["apps", "packages"].flatMap((workspaceRoot) =>
readdirSync(resolve(repoRoot, workspaceRoot), { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => `${workspaceRoot}/${entry.name}/package.json`)
);

return packagePaths.map((packagePath) => ({
packagePath,
manifest: readJson<PackageManifest>(packagePath)
}));
}

function readJson<T>(relativePath: string): T {
return JSON.parse(readFileSync(join(repoRoot, relativePath), "utf8")) as T;
}
Loading