Skip to content

Commit

Permalink
feat: add new @changesets/write package to separate writing changesets (
Browse files Browse the repository at this point in the history
#292)

* feat: add new @changesets/write package to separate writing changesets

* chore: add changesets

* Update README.md

* Update README.md

* Add @babel/runtime

* Changeset nits

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>
  • Loading branch information
acheronfail and emmatown committed Mar 11, 2020
1 parent 2363366 commit 41e2e3d
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-bikes-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/types": minor
---

Add new `Changeset` type
5 changes: 5 additions & 0 deletions .changeset/hot-rocks-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

Use `@changesets/write` for writing changesets internally
5 changes: 5 additions & 0 deletions .changeset/stale-cobras-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/parse": patch
---

Fix `repository` field in package.json
5 changes: 5 additions & 0 deletions .changeset/thick-foxes-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/write": minor
---

Initial release
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@changesets/pre": "^0.2.0",
"@changesets/read": "^0.4.1",
"@changesets/types": "^0.4.0",
"@changesets/write": "^0.0.0",
"@types/semver": "^6.0.0",
"boxen": "^1.3.0",
"chalk": "^2.1.0",
Expand All @@ -46,7 +47,6 @@
"meow": "^5.0.0",
"outdent": "^0.5.0",
"p-limit": "^2.2.0",
"prettier": "^1.18.2",
"semver": "^5.4.1",
"spawndamnit": "^2.0.0",
"term-size": "^2.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/add/__tests__/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import stripAnsi from "strip-ansi";
import * as git from "@changesets/git";
import { defaultConfig } from "@changesets/config";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import writeChangeset from "@changesets/write";

import {
askCheckboxPlus,
Expand All @@ -11,11 +12,10 @@ import {
askList
} from "../../../utils/cli-utilities";
import addChangeset from "..";
import writeChangeset from "../writeChangeset";

jest.mock("../../../utils/cli-utilities");
jest.mock("@changesets/git");
jest.mock("../writeChangeset");
jest.mock("@changesets/write");
// @ts-ignore
writeChangeset.mockImplementation(() => Promise.resolve("abcdefg"));
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as cli from "../../utils/cli-utilities";
import * as git from "@changesets/git";
import { info, log, warn } from "@changesets/logger";
import { Config } from "@changesets/types";
import writeChangeset from "@changesets/write";

import writeChangeset from "./writeChangeset";
import createChangeset from "./createChangeset";
import printConfirmationMessage from "./messages";
import getWorkspaces from "../../utils/getWorkspaces";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/status/__tests__/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import fs from "fs-extra";
import path from "path";
import { defaultConfig } from "@changesets/config";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import writeChangeset from "@changesets/write";

import writeChangeset from "../../add/writeChangeset";
import status from "..";

import humanId from "human-id";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/version/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import versionCommand from "./index";
import * as git from "@changesets/git";
import { warn } from "@changesets/logger";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import writeChangeset from "../add/writeChangeset";
import writeChangeset from "@changesets/write";
import { NewChangeset, Config } from "@changesets/types";
import { defaultConfig } from "@changesets/config";
import pre from "../pre";
Expand Down
2 changes: 1 addition & 1 deletion packages/parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "dist/parse.cjs.js",
"module": "dist/parse.esm.js",
"license": "MIT",
"repository": "https://github.com/changesets/changesets/tree/master/packages/read",
"repository": "https://github.com/changesets/changesets/tree/master/packages/parse",
"dependencies": {
"@changesets/types": "^0.4.0",
"js-yaml": "^3.13.1"
Expand Down
7 changes: 5 additions & 2 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ export type ComprehensiveRelease = {
changesets: string[];
};

export type NewChangeset = {
id: string;
export type Changeset = {
summary: string;
releases: Array<Release>;
};

export type NewChangeset = Changeset & {
id: string;
};

export type ReleasePlan = {
changesets: NewChangeset[];
releases: ComprehensiveRelease[];
Expand Down
43 changes: 43 additions & 0 deletions packages/write/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# @changesets/write

Writes a changeset to a file.

```js
import write from "@changesets/write";

const changeset = {
"summary": "A description of a minor change",
"releases": [
{ "name": "@changesets/something", "type": "minor" },
{ "name": "@changesets/something-else", "type": "patch" }
]
};

const uniqueId = await write(changeset, cwd);
console.log(uniqueId); // orange-foxes-waggle
```

For example, it can convert:

```json
{
"summary": "A description of a minor change",
"releases": [
{ "name": "@changesets/something", "type": "minor" },
{ "name": "@changesets/something-else", "type": "patch" }
]
}
```

to

```markdown
---
"@changesets/something": minor
"@changesets/something-else": patch
---

A description of a minor change
```

This package will take care of generating a unique id for the changeset.
20 changes: 20 additions & 0 deletions packages/write/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@changesets/write",
"version": "0.0.0",
"description": "Writes a changeset to a file",
"main": "dist/write.cjs.js",
"module": "dist/write.esm.js",
"license": "MIT",
"repository": "https://github.com/changesets/changesets/tree/master/packages/write",
"dependencies": {
"@babel/runtime": "^7.4.4",
"@changesets/types": "^0.4.0",
"fs-extra": "^7.0.1",
"human-id": "^1.0.2",
"prettier": "^1.18.2"
},
"devDependencies": {
"@changesets/parse": "*",
"jest-fixtures": "^0.5.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from "fs-extra";
import path from "path";
import parse from "@changesets/parse";
import { Release } from "@changesets/types";
import writeChangeset from "../writeChangeset";
import writeChangeset from "./";

import humanId from "human-id";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import fs from "fs-extra";
import path from "path";
import prettier from "prettier";
import humanId from "human-id";
import { Release } from "@changesets/types";
import { Changeset } from "@changesets/types";

async function writeChangeset(
changeset: { summary: string; releases: Array<Release> },
changeset: Changeset,
cwd: string
) {
): Promise<string> {
const { summary, releases } = changeset;

const changesetBase = path.resolve(cwd, ".changeset");
Expand Down

0 comments on commit 41e2e3d

Please sign in to comment.