Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Commit 7b11c5b

Browse files
committed
refactor: uses -ws flag to version and publish packages to simplify
steps
1 parent 3c917d7 commit 7b11c5b

File tree

14 files changed

+73
-170
lines changed

14 files changed

+73
-170
lines changed

.release-workspaces.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"metadata": {
3-
"version": "0.7.12"
3+
"version": "0.7.14"
44
}
55
}

bin/__tests__/increment.spec.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ describe("runIncrement()", () => {
5858

5959
it("versions an entry", async () => {
6060
// Given
61-
const command = getVersionCommand(entryOne.name, config.releaseVersion)
61+
const command = getVersionCommand(config.releaseVersion)
6262
// When
63-
await runIncrement(config, entryOne)
63+
await runIncrement(config)
6464
// Then
6565
expect(cmd).toBeCalledWith(command, expect.objectContaining(config), true)
6666
})
@@ -74,7 +74,7 @@ describe("runIncrement()", () => {
7474
2
7575
)
7676
// When
77-
await runIncrement(config, entryOne)
77+
await runIncrement(config)
7878
// Then
7979
expect(fs.writeFileSync).toBeCalledWith(
8080
`${entryOne.dir}/package.json`,
@@ -87,16 +87,16 @@ describe("runIncrement()", () => {
8787
// Given
8888
const dryConfig = { ...config, dryRun: true }
8989
// When
90-
await runIncrement(dryConfig, entryOne)
90+
await runIncrement(dryConfig)
9191
// Then
9292
expect(fs.writeFileSync).not.toBeCalled()
9393
})
9494

95-
it("does not write to file if there are no matching dependencies", async () => {
95+
it("does not write dependency versions when package has no matches", async () => {
9696
// When
97-
await runIncrement(config, entryTwo)
97+
await runIncrement(config)
9898
// Then
99-
expect(fs.writeFileSync).not.toBeCalled()
99+
expect(fs.writeFileSync).toBeCalledTimes(1)
100100
})
101101
})
102102

@@ -113,7 +113,7 @@ describe("runIncrement()", () => {
113113

114114
it("exits if write to file fails", async () => {
115115
// When
116-
await runIncrement(config, entryOne)
116+
await runIncrement(config)
117117
// Then
118118
expect(exitWithError).toBeCalled()
119119
})
@@ -132,7 +132,7 @@ describe("runIncrement()", () => {
132132
// Given
133133
const dryConfig = { ...config, verbose: true, dryRun: true }
134134
// When
135-
await runIncrement(dryConfig, entryOne)
135+
await runIncrement(dryConfig)
136136
// Then
137137
expect(report).toBeCalledWith(
138138
expect.objectContaining({
@@ -146,7 +146,7 @@ describe("runIncrement()", () => {
146146
// Given
147147
const verbConfig = { ...config, verbose: true }
148148
// When
149-
await runIncrement(verbConfig, entryOne)
149+
await runIncrement(verbConfig)
150150
// Then
151151
expect(report).toBeCalledWith(
152152
expect.objectContaining({
@@ -158,24 +158,24 @@ describe("runIncrement()", () => {
158158

159159
it("reports start", async () => {
160160
// When
161-
await runIncrement(config, entryTwo)
161+
await runIncrement(config)
162162
// Then
163163
expect(report).toBeCalledWith(
164164
expect.objectContaining({
165-
m: `${entryTwo.name} | ${config.prevVersion} -> ${config.releaseVersion}`,
165+
m: `Incrementing version: ${config.prevVersion} -> ${config.releaseVersion}`,
166166
type: "start",
167167
})
168168
)
169169
})
170170

171171
it("reports success", async () => {
172172
// When
173-
await runIncrement(config, entryTwo)
173+
await runIncrement(config)
174174
// Then
175175
expect(report).toBeCalledWith(
176176
expect.objectContaining({
177177
m: {
178-
text: `${entryTwo.name} | ${config.prevVersion} -> ${config.releaseVersion}`,
178+
text: `Incrementing version: ${config.prevVersion} -> ${config.releaseVersion}`,
179179
symbol: "📦",
180180
},
181181
type: "stopAndPersist",

bin/__tests__/npm.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ const config = {
5757
}
5858

5959
describe("runNpm()", () => {
60-
it("increments each package", async () => {
60+
it("increments packages", async () => {
6161
// When
6262
await runNpm(config)
6363
// Then
64-
expect(runIncrement).toBeCalledTimes(config.packages.length)
64+
expect(runIncrement).toBeCalled()
6565
})
6666

67-
it("publishes each package", async () => {
67+
it("publishes packages", async () => {
6868
// When
6969
await runNpm(config)
7070
// Then
71-
expect(runPublish).toBeCalledTimes(config.packages.length)
71+
expect(runPublish).toBeCalled()
7272
})
7373

7474
it("sets root version", async () => {

bin/__tests__/publish.spec.js

Lines changed: 14 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { getPublishCommand } from "../helpers/commands.js"
44
import { cmd } from "../helpers/cmd.js"
55
import { report } from "../helpers/reporter.js"
66
import { runPublish } from "../modules/publish.js"
7-
import { setRollback } from "../helpers/rollback.js"
87

98
jest.mock("../helpers/cmd.js", () => ({
109
cmd: jest.fn(),
@@ -42,25 +41,15 @@ const privateEntry = {
4241
const baseConfig = {
4342
npmTag: "",
4443
preid: "",
44+
packages: [entry, privateEntry],
4545
}
4646

4747
describe("runPublish()", () => {
4848
it("publishes package", async () => {
4949
// When
50-
await runPublish(baseConfig, entry)
50+
await runPublish(baseConfig)
5151
// Then
52-
expect(cmd).toBeCalledWith(
53-
getPublishCommand(entry.name, "latest"),
54-
baseConfig,
55-
true
56-
)
57-
})
58-
59-
it("does not publish private package", async () => {
60-
// When
61-
await runPublish(baseConfig, privateEntry)
62-
// Then
63-
expect(cmd).not.toBeCalled()
52+
expect(cmd).toBeCalledWith(getPublishCommand("latest"), baseConfig, true)
6453
})
6554

6655
it("publishes with npm tag if given", async () => {
@@ -70,29 +59,18 @@ describe("runPublish()", () => {
7059
npmTag: "next",
7160
}
7261
// When
73-
await runPublish(config, entry)
62+
await runPublish(config)
7463
// Then
75-
expect(cmd).toBeCalledWith(
76-
getPublishCommand(entry.name, "next"),
77-
config,
78-
true
79-
)
64+
expect(cmd).toBeCalledWith(getPublishCommand("next"), config, true)
8065
})
8166

8267
it("publishes with preid if given", async () => {
8368
// Given
84-
const config = {
85-
...baseConfig,
86-
preid: "alpha",
87-
}
69+
const config = { ...baseConfig, preid: "alpha" }
8870
// When
89-
await runPublish(config, entry)
71+
await runPublish(config)
9072
// Then
91-
expect(cmd).toBeCalledWith(
92-
getPublishCommand(entry.name, "alpha"),
93-
config,
94-
true
95-
)
73+
expect(cmd).toBeCalledWith(getPublishCommand("alpha"), config, true)
9674
})
9775

9876
it("publishes with parsed preid if it exists", async () => {
@@ -102,67 +80,28 @@ describe("runPublish()", () => {
10280
releaseVersion: "0.0.1-beta.0",
10381
}
10482
// When
105-
await runPublish(config, entry)
106-
// Then
107-
expect(cmd).toBeCalledWith(
108-
getPublishCommand(entry.name, "beta"),
109-
config,
110-
true
111-
)
112-
})
113-
114-
it("adds publish action if public", async () => {
115-
// When
116-
await runPublish(baseConfig, entry)
83+
await runPublish(config)
11784
// Then
118-
// eslint-disable-next-line no-unused-vars
119-
expect(setRollback).toBeCalledWith(
120-
expect.objectContaining(baseConfig),
121-
expect.objectContaining({
122-
type: "publish",
123-
callback: expect.any(Function),
124-
})
125-
)
85+
expect(cmd).toBeCalledWith(getPublishCommand("beta"), config, true)
12686
})
12787

12888
describe("report", () => {
12989
it("reports start", async () => {
13090
// When
131-
await runPublish(baseConfig, entry)
91+
await runPublish(baseConfig)
13292
// Then
13393
expect(report).toBeCalledWith(
134-
expect.objectContaining({
135-
m: `Publishing ${entry.name}...`,
136-
type: "start",
137-
})
138-
)
139-
})
140-
141-
it("reports private publish skipped", async () => {
142-
// When
143-
await runPublish(baseConfig, privateEntry)
144-
// Then
145-
expect(report).toBeCalledWith(
146-
expect.objectContaining({
147-
m: {
148-
text: `Publish skipped (private): ${privateEntry.name}`,
149-
symbol: "☕",
150-
},
151-
type: "stopAndPersist",
152-
})
94+
expect.objectContaining({ m: `Publishing...`, type: "start" })
15395
)
15496
})
15597

15698
it("reports publish success", async () => {
15799
// When
158-
await runPublish(baseConfig, entry)
100+
await runPublish(baseConfig)
159101
// Then
160102
expect(report).toBeCalledWith(
161103
expect.objectContaining({
162-
m: {
163-
text: `Published ${entry.name}`,
164-
symbol: "🚀",
165-
},
104+
m: { text: `Published`, symbol: "🚀" },
166105
type: "stopAndPersist",
167106
})
168107
)

bin/helpers/commands.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export function getAddCommand() {
1414
return "git add . -u"
1515
}
1616

17-
export function getPublishCommand(name, tag) {
18-
return `npm publish -w ${name} --tag ${tag}`
17+
export function getPublishCommand(tag) {
18+
return `npm publish -ws --tag ${tag}`
1919
}
2020

21-
export function getVersionCommand(name, version) {
22-
return `npm version -w ${name} ${version} --no-git-tag-version`
21+
export function getVersionCommand(version) {
22+
return `npm version -ws ${version} --no-git-tag-version`
2323
}

bin/modules/increment.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,16 @@ function setDependencies(config, entry) {
8686
}
8787
}
8888

89-
export async function runIncrement(config, entry) {
90-
const message = `${entry.name} | ${config.prevVersion} -> ${config.releaseVersion}`
89+
export async function runIncrement(config) {
90+
const message = `Incrementing version: ${config.prevVersion} -> ${config.releaseVersion}`
9191

92-
report({
93-
m: message,
94-
type: "start",
95-
})
92+
report({ m: message, type: "start" })
9693

97-
await cmd(getVersionCommand(entry.name, config.releaseVersion), config, true)
98-
setDependencies(config, entry)
94+
await cmd(getVersionCommand(config.releaseVersion), config, true)
9995

100-
report({
101-
m: {
102-
text: message,
103-
symbol: "📦",
104-
},
105-
type: "stopAndPersist",
106-
})
96+
for (const entry of config.packages) {
97+
setDependencies(config, entry)
98+
}
99+
100+
report({ m: { text: message, symbol: "📦" }, type: "stopAndPersist" })
107101
}

bin/modules/npm.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import { setRootVersion } from "../helpers/set-root-version.js"
1111

1212
export async function runNpm(config) {
1313
const {
14-
packages,
1514
hooks: { preincrement, postincrement, prepublish, postpublish },
1615
npm: { increment, publish },
1716
} = config
18-
const length = packages.length
1917

2018
setRollback(config, {
2119
type: "increment",
@@ -32,9 +30,7 @@ export async function runNpm(config) {
3230
})
3331
}
3432

35-
for (let i = 0; i < length; i++) {
36-
await runIncrement(config, packages[i])
37-
}
33+
await runIncrement(config)
3834

3935
// Set root version to config/package.json, then stage changes
4036
await setRootVersion(config)
@@ -53,9 +49,7 @@ export async function runNpm(config) {
5349
await reportCmd(prepublish, { ...config, step: ReportSteps.PREPUBLISH })
5450
}
5551

56-
for (let i = 0; i < length; i++) {
57-
await runPublish(config, packages[i])
58-
}
52+
await runPublish(config)
5953

6054
if (postpublish) {
6155
await reportCmd(postpublish, { ...config, step: ReportSteps.POSTPUBLISH })

0 commit comments

Comments
 (0)