Skip to content

Commit

Permalink
fix: patch/replace @changesets/assemble-release-plan to disable major…
Browse files Browse the repository at this point in the history
… on peer dep change (#3184)
  • Loading branch information
ScriptedAlchemy authored Nov 6, 2024
1 parent 550e33f commit c2a63a6
Show file tree
Hide file tree
Showing 24 changed files with 4,808 additions and 1,416 deletions.
3 changes: 2 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"host-v5",
"host-vue3",
"3008-runtime-remote",
"modernjs-ssr-*"
"modernjs-ssr-*",
"@changesets/assemble-release-plan"
]
}
1 change: 1 addition & 0 deletions .nxignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.md
./assemble-release-plan
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pnpm-lock.yaml
apps/website-new/docs

/.nx/workspace-data
/.nx/cache
/.nx/cache
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@
"build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:type:pkg'",
"changegen": "./changeset-gen.js --path ./packages/enhanced --staged &&./changeset-gen.js --path ./packages/node --staged && ./changeset-gen.js --path ./packages/runtime --staged && ./changeset-gen.js --path ./packages/data-prefetch --staged && ./changeset-gen.js --path ./packages/nextjs-mf --staged",
"commitgen:staged": "./commit-gen.js --path ./packages --staged",
"commitgen:main": "./commit-gen.js --path ./packages"
"commitgen:main": "./commit-gen.js --path ./packages",
"changeset:status": "changeset status"
},
"pnpm": {
"packageExtensions": {
"@changesets/cli": {
"dependencies": {
"@changesets/assemble-release-plan": "workspace:*"
}
}
},
"overrides": {
"@changesets/assemble-release-plan": "workspace:*"
}
},
"dependencies": {
"@storybook/addon-interactions": "^8.2.8",
Expand Down
1 change: 1 addition & 0 deletions packages/assemble-release-plan/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./dist
410 changes: 410 additions & 0 deletions packages/assemble-release-plan/CHANGELOG.md

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions packages/assemble-release-plan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Assemble Release Plan

[![View changelog](https://img.shields.io/badge/changelogs.xyz-Explore%20Changelog-brightgreen)](https://changelogs.xyz/@changesets/assemble-release-plan)

Assemble a release plan for changesets from data about a repository.

Usage

```ts
import assembleReleasePlan from "@changesets/assemble-release-plan";
import readChangesets from "@changesets/read";
import { read } from "@changesets/config";
import { getPackages } from "@manypkg/get-packages";
import { readPreState } from "@changesets/pre";

const packages = await getPackages(cwd);
const preState = await readPreState(cwd);
const config = await read(cwd, packages);
const changesets = await readChangesets(cwd, sinceRef);

const releasePlan = assembleReleasePlan(changesets, packages, config, preState);
```

Signature

```ts
import { NewChangeset, Config, ReleasePlan } from "@changesets/types";
import { Packages } from "@manypkg/get-packages";

assembleReleasePlan = (
changesets: NewChangeset[],
packages: Packages,
config: Config
) => ReleasePlan;
```

This package exists so assembling a release plan can be done without reading from disc.
This is useful primarily for testing within the changesets project, and when you cannot
run commands within the repository you want a release plan for (some CI cases).

For most cases, you should use `@changesets/get-release-plan` which will read local changeset
files, config, and workspaces, to assemble the release plan from.
11 changes: 11 additions & 0 deletions packages/assemble-release-plan/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: { node: 8 },
},
],
],
overrides: [{ test: '**/*.ts', presets: ['@babel/preset-typescript'] }],
};
59 changes: 59 additions & 0 deletions packages/assemble-release-plan/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@changesets/assemble-release-plan",
"version": "6.0.4",
"private": true,
"description": "Reads changesets and adds information on dependents that need bumping",
"main": "dist/changesets-assemble-release-plan.cjs.js",
"module": "dist/changesets-assemble-release-plan.esm.js",
"exports": {
".": {
"types": {
"import": "./dist/changesets-assemble-release-plan.cjs.mjs",
"default": "./dist/changesets-assemble-release-plan.cjs.js"
},
"module": "./dist/changesets-assemble-release-plan.esm.js",
"import": "./dist/changesets-assemble-release-plan.cjs.mjs",
"default": "./dist/changesets-assemble-release-plan.cjs.js"
},
"./package.json": "./package.json"
},
"scripts": {
"test": "jest",
"build": "preconstruct build",
"watch": "preconstruct watch",
"postinstall": "preconstruct dev",
"lint": "yarn eslint . --ext .ts,.tsx,.js",
"types:check": "tsc",
"changeset": "packages/cli/bin.js",
"check-all": "yarn test && yarn types:check && yarn lint && yarn format",
"version-packages": "changeset version && yarn format:fix",
"release": "yarn build && changeset publish"
},
"license": "MIT",
"repository": "https://github.com/changesets/changesets/tree/main/packages/assemble-release-plan",
"dependencies": {
"@changesets/errors": "^0.2.0",
"@changesets/get-dependents-graph": "^2.1.2",
"@changesets/should-skip-package": "^0.1.1",
"@changesets/types": "^6.0.0",
"@manypkg/get-packages": "^1.1.3",
"semver": "^7.5.3"
},
"devDependencies": {
"@changesets/config": "*",
"@preconstruct/cli": "^2.8.1",
"@babel/preset-typescript": "^7.26.0",
"@babel/preset-env": "^7.26.0"
},
"preconstruct": {
"packages": [
"."
],
"exports": {
"importConditionDefaultExport": "default"
},
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
"importsConditions": true
}
}
}
4 changes: 4 additions & 0 deletions packages/assemble-release-plan/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Get Release Info

This package does the end-to-end work of reading in the current set of changesets, and generating a release plan
based on them.
57 changes: 57 additions & 0 deletions packages/assemble-release-plan/src/apply-links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Linked } from '@changesets/types';
import { Package } from '@manypkg/get-packages';
import { InternalRelease } from './types';
import { getCurrentHighestVersion, getHighestReleaseType } from './utils';

/*
WARNING:
Important note for understanding how this package works:
We are doing some kind of wacky things with manipulating the objects within the
releases array, despite the fact that this was passed to us as an argument. We are
aware that this is generally bad practice, but have decided to to this here as
we control the entire flow of releases.
We could solve this by inlining this function, or by returning a deep-cloned then
modified array, but we decided both of those are worse than this solution.
*/
export default function applyLinks(
releases: Map<string, InternalRelease>,
packagesByName: Map<string, Package>,
linked: Linked,
): boolean {
let updated = false;

// We do this for each set of linked packages
for (let linkedPackages of linked) {
// First we filter down to all the relevant releases for one set of linked packages
let releasingLinkedPackages = [...releases.values()].filter(
(release) =>
linkedPackages.includes(release.name) && release.type !== 'none',
);

// If we proceed any further we do extra work with calculating highestVersion for things that might
// not need one, as they only have workspace based packages
if (releasingLinkedPackages.length === 0) continue;

let highestReleaseType = getHighestReleaseType(releasingLinkedPackages);
let highestVersion = getCurrentHighestVersion(
linkedPackages,
packagesByName,
);

// Finally, we update the packages so all of them are on the highest version
for (let linkedPackage of releasingLinkedPackages) {
if (linkedPackage.type !== highestReleaseType) {
updated = true;
linkedPackage.type = highestReleaseType;
}
if (linkedPackage.oldVersion !== highestVersion) {
updated = true;
linkedPackage.oldVersion = highestVersion;
}
}
}

return updated;
}
Loading

0 comments on commit c2a63a6

Please sign in to comment.