Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the changelog from the monorepo root in each package #147

Merged
merged 6 commits into from
Jan 6, 2024

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Jan 4, 2024

release-plan uses a single changelog for all packages in the monorepo.

This PR copies that single changelog to the workspace directory during build (and consequently, during prepack) so there is a changelog distributed with package changes.

This provides context to each change, so when folks review the changes in a PR, they'll see what other packages changed, and which other packages may also be a good idea to update at the same time.

Lastly, because the changelog is copied from the root, all package-based changelogs are gitignored.

script used to apply these changes
import path from "node:path";
import { project, packageJson } from "ember-apply";
import fse from "fs-extra";

await project.gitIgnore("**/CHANGELOG.md");

for (let workspace of await project.getWorkspaces()) {
  let manifest = await packageJson.read(workspace);

  if (manifest.private || !manifest.name) continue;

  try {
    await workOn(workspace);
  } catch (e) {
    console.error(workspace);
    console.error(e);
  }
}

async function workOn(workspace) {
  let rollupPath = path.join(workspace, "rollup.config.mjs");
  let hasRollup = await fse.pathExists(rollupPath);

  if (!hasRollup) {
    return;
  }

  await fse.remove(path.join(workspace, "CHANGELOG.md"));

  await packageJson.addDevDependencies(
    { "rollup-plugin-copy": "^3.5.0" },
    workspace,
  );

  await fse.writeFile(
    rollupPath,
    `
import path from 'node:path';
import { execSync } from 'node:child_process';
import { compile } from "@starbeam-dev/compile";
import copy from 'rollup-plugin-copy'

const config = compile(import.meta);

const monorepoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim();

const rootChangelog = path.join(monorepoRoot, 'CHANGELOG.md');

// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
const includeChangelog = copy({ 
  targets: [
    {
      src: rootChangelog,
      dest: 'CHANGELOG.md',
    }
  ],
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
config[0].plugins.push(includeChangelog);

export default config;
`,
  );
}

Copy link

stackblitz bot commented Jan 4, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review January 4, 2024 19:34
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@starbeam-dev/compile 1.0.2 environment +2550 15.8 GB wycats

@NullVoxPopuli NullVoxPopuli merged commit d342d90 into main Jan 6, 2024
6 checks passed
@NullVoxPopuli NullVoxPopuli deleted the copy-root-changelog-to-package branch January 6, 2024 15:52
@github-actions github-actions bot mentioned this pull request Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant