Skip to content

Commit cc72b89

Browse files
authored
chore: fix smoke tests to account for new release versions within a workspace (#8143)
A reworking of the smoke tests to accommodate a recent PR where the check to see if the version has already been published conflicted with the smoke tests. A fix was implemented to add prerelease tags to address this issue. However, when the version bumps are legitimate and a prerelease tag is added, the workspace dependencies still have the version prior to the prerelease tag. This PR adds the prerelease tag and bumps all versions used in the workspace.
1 parent 8461186 commit cc72b89

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

scripts/publish.js

+52-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const { log } = require('proc-log')
33
const pacote = require('pacote')
44
const { read } = require('read')
55
const Table = require('cli-table3')
6-
const { run, git, npm, pkg: cli, spawn } = require('./util.js')
6+
const { run, git, npm, pkgPath: cliPath, pkg: cli, spawn } = require('./util.js')
7+
const fs = require('fs').promises
78

89
const resetdeps = () => npm('run', 'resetdeps')
910

@@ -49,22 +50,40 @@ const versionNotExists = async ({ name, version }) => {
4950
const getPublishes = async ({ force }) => {
5051
const publishPackages = []
5152

52-
for (const { pkg } of await cli.mapWorkspaces({ public: true })) {
53+
for (const { pkg, pkgPath } of await cli.mapWorkspaces({ public: true })) {
54+
const updatePkg = async (cb) => {
55+
const data = JSON.parse(await fs.readFile(pkgPath, 'utf8'))
56+
const result = cb(data)
57+
await fs.writeFile(pkgPath, JSON.stringify(result, null, 2))
58+
return result
59+
}
60+
5361
if (force || await versionNotExists(pkg)) {
5462
publishPackages.push({
55-
workspace: true,
63+
workspace: `--workspace=${pkg.name}`,
5664
name: pkg.name,
5765
version: pkg.version,
66+
dependencies: pkg.dependencies,
67+
devDependencies: pkg.devDependencies,
5868
tag: await getWorkspaceTag(pkg),
69+
updatePkg,
5970
})
6071
}
6172
}
6273

6374
if (force || await versionNotExists(cli)) {
6475
publishPackages.push({
76+
workspace: '',
6577
name: cli.name,
6678
version: cli.version,
6779
tag: `next-${semver.major(cli.version)}`,
80+
dependencies: cli.dependencies,
81+
devDependencies: cli.devDependencies,
82+
updatePkg: async (cb) => {
83+
const result = cb(cli)
84+
await fs.writeFile(cliPath, JSON.stringify(result, null, 2))
85+
return result
86+
},
6887
})
6988
}
7089

@@ -128,6 +147,36 @@ const main = async (opts) => {
128147
}
129148

130149
let count = -1
150+
151+
if (smokePublish) {
152+
// when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run
153+
// this is the equivlent of running `npm version prerelease`, but ensureing all internally used workflows are bumped
154+
for (const publish of publishes) {
155+
const { version } = await publish.updatePkg((pkg) => ({ ...pkg, version: `${pkg.version}-smoke.0` }))
156+
for (const ipublish of publishes) {
157+
if (ipublish.dependencies?.[publish.name]) {
158+
await ipublish.updatePkg((pkg) => ({
159+
...pkg,
160+
dependencies: {
161+
...pkg.dependencies,
162+
[publish.name]: version,
163+
},
164+
}))
165+
}
166+
if (ipublish.devDependencies?.[publish.name]) {
167+
await ipublish.updatePkg((pkg) => ({
168+
...pkg,
169+
devDependencies: {
170+
...pkg.devDependencies,
171+
[publish.name]: version,
172+
},
173+
}))
174+
}
175+
}
176+
}
177+
await npm('install')
178+
}
179+
131180
for (const publish of publishes) {
132181
log.info(`Publishing ${publish.name}@${publish.version} to ${publish.tag} ${count++}/${publishes.length}`)
133182
const workspace = publish.workspace && `--workspace=${publish.name}`
@@ -142,8 +191,6 @@ const main = async (opts) => {
142191
}
143192

144193
if (smokePublish) {
145-
// when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run
146-
await npm('version', 'prerelease', workspace, '--preid=smoke', '--ignore-scripts', '--no-git-tag-version')
147194
await publishPkg('--dry-run', '--ignore-scripts')
148195
} else {
149196
await publishPkg(

scripts/util.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ const mapWorkspaces = require('@npmcli/map-workspaces')
1212
const EOL = '\n'
1313
const CWD = resolve(__dirname, '..')
1414

15+
const rootPkgPath = join(CWD, 'package.json')
1516
const pkg = require(join(CWD, 'package.json'))
1617
pkg.mapWorkspaces = async ({ public = false } = {}) => {
1718
const ws = []
1819
for (const [name, path] of await mapWorkspaces({ pkg })) {
19-
const pkgJson = require(join(path, 'package.json'))
20+
const pkgPath = join(path, 'package.json')
21+
const pkgJson = require(pkgPath)
2022

2123
if (public && pkgJson.private) {
2224
continue
2325
}
2426

25-
ws.push({ name, path, pkg: pkgJson })
27+
ws.push({ name, path, pkgPath, pkg: pkgJson })
2628
}
2729
return ws
2830
}
@@ -205,6 +207,7 @@ const run = async (main, { redact } = {}) => {
205207
module.exports = {
206208
CWD,
207209
pkg,
210+
pkgPath: rootPkgPath,
208211
run,
209212
fs,
210213
spawn,

0 commit comments

Comments
 (0)