Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: npm/template-oss
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.1.1
Choose a base ref
...
head repository: npm/template-oss
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.1.2
Choose a head ref
  • 2 commits
  • 7 files changed
  • 2 contributors

Commits on Sep 14, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6bc355a View commit details
  2. chore: release 4.1.2 (#193)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    github-actions[bot] authored Sep 14, 2022
    Copy the full SHA
    ca5c14e View commit details
Showing with 229 additions and 27 deletions.
  1. +1 −1 .release-please-manifest.json
  2. +6 −0 CHANGELOG.md
  3. +7 −0 bin/release-please.js
  4. +27 −23 lib/release-please/github.js
  5. +8 −2 lib/release-please/node-workspace.js
  6. +2 −1 package.json
  7. +178 −0 test/release-please/node-workspace.js
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "4.1.1"
".": "4.1.2"
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [4.1.2](https://github.com/npm/template-oss/compare/v4.1.1...v4.1.2) (2022-09-14)

### Bug Fixes

* [`6bc355a`](https://github.com/npm/template-oss/commit/6bc355a2b313bdde0fd6fe7cdf0c290ebf747af9) [#192](https://github.com/npm/template-oss/pull/192) set package.json version from release please (#192) (@lukekarrys)

## [4.1.1](https://github.com/npm/template-oss/compare/v4.1.0...v4.1.1) (2022-09-13)

### Bug Fixes
7 changes: 7 additions & 0 deletions bin/release-please.js
Original file line number Diff line number Diff line change
@@ -20,6 +20,13 @@ const setOutput = (key, val) => {
console.log(update.updater.changelogEntry)
console.log('-'.repeat(40))
}
for (const update of val.updates.filter(u => u.updater.rawContent)) {
console.log('package:', update.path)
console.log('-'.repeat(40))
console.log(JSON.parse(update.updater.rawContent).name)
console.log(JSON.parse(update.updater.rawContent).version)
console.log('-'.repeat(40))
}
}
} else {
core.setOutput(key, JSON.stringify(val))
50 changes: 27 additions & 23 deletions lib/release-please/github.js
Original file line number Diff line number Diff line change
@@ -10,35 +10,39 @@ module.exports = (gh) => {
return response
}

const { repository } = await gh.graphql(
`fragment CommitAuthors on GitObject {
... on Commit {
authors (first:10) {
nodes {
user { login }
name
try {
const { repository } = await gh.graphql(
`fragment CommitAuthors on GitObject {
... on Commit {
authors (first:10) {
nodes {
user { login }
name
}
}
}
}
}
query {
repository (owner:"${owner}", name:"${repo}") {
${shas.map((s) => {
return `_${s}: object (expression: "${s}") { ...CommitAuthors }`
})}
query {
repository (owner:"${owner}", name:"${repo}") {
${shas.map((s) => {
return `_${s}: object (expression: "${s}") { ...CommitAuthors }`
})}
}
}`
)

for (const [key, commit] of Object.entries(repository)) {
if (commit) {
response[key.slice(1)] = commit.authors.nodes
.map((a) => a.user && a.user.login ? `@${a.user.login}` : a.name)
.filter(Boolean)
}
}`
)

for (const [key, commit] of Object.entries(repository)) {
if (commit) {
response[key.slice(1)] = commit.authors.nodes
.map((a) => a.user && a.user.login ? `@${a.user.login}` : a.name)
.filter(Boolean)
}
}

return response
return response
} catch {
return response
}
}

const url = (...p) => `https://github.com/${owner}/${repo}/${p.join('/')}`
10 changes: 8 additions & 2 deletions lib/release-please/node-workspace.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const localeCompare = require('@isaacs/string-locale-compare')('en')
const { NodeWorkspace } = require('release-please/build/src/plugins/node-workspace.js')
const { RawContent } = require('release-please/build/src/updaters/raw-content.js')
const { jsonStringify } = require('release-please/build/src/util/json-stringify.js')
@@ -105,9 +106,11 @@ module.exports = class extends NodeWorkspace {
// except it only updates the package.json instead of appending
// anything to changelogs since we've already done that in preconfigure.
updateCandidate (candidate, pkg, updatedVersions) {
const newVersion = updatedVersions.get(pkg.name)
const graphPackage = this.packageGraph.get(pkg.name)
const updatedPackage = pkg.clone()

const updatedPackage = pkg.clone()
updatedPackage.version = newVersion.toString()
for (const [depName, resolved] of graphPackage.localDependencies) {
const depVersion = updatedVersions.get(depName)
if (depVersion && resolved.type !== 'directory') {
@@ -160,10 +163,13 @@ module.exports = class extends NodeWorkspace {
if (aPath === ROOT_PROJECT_PATH) {
return -1
}
// release please pre sorts based on graph order so
// this is never called in normal circumstances
/* istanbul ignore next */
if (bPath === ROOT_PROJECT_PATH) {
return 1
}
return 0
return localeCompare(aPath, bPath)
})
}

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@npmcli/template-oss",
"version": "4.1.1",
"version": "4.1.2",
"description": "templated files used in npm CLI team oss projects",
"main": "lib/content/index.js",
"bin": {
@@ -32,6 +32,7 @@
"@actions/core": "^1.9.1",
"@commitlint/cli": "^17.1.1",
"@commitlint/config-conventional": "^17.1.0",
"@isaacs/string-locale-compare": "^1.1.0",
"@npmcli/fs": "^2.0.1",
"@npmcli/git": "^3.0.0",
"@npmcli/map-workspaces": "^2.0.2",
178 changes: 178 additions & 0 deletions test/release-please/node-workspace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
const t = require('tap')
const { setLogger } = require('release-please') // this avoids a release-please cycle when testing
const { Node } = require('release-please/build/src/strategies/node')
const { Version } = require('release-please/build/src/version')
const { TagName } = require('release-please/build/src/util/tag-name')
const NodeWorkspace = require('../../lib/release-please/node-workspace')
const Changelog = require('../../lib/release-please/changelog')

setLogger({ error () {}, warn () {}, info () {}, debug () {}, trace () {} })

const mockNodeWorkspace = async (workspaceNames = ['a']) => {
const names = { '.': 'npm' }
const versions = { '.': new Version(1, 1, 1) }

for (const ws of workspaceNames) {
names[`workspaces/${ws}`] = `@npmcli/${ws}`
versions[`workspaces/${ws}`] = new Version(2, 2, 2)
}

const paths = Object.keys(names)

const github = {
repository: { owner: 'npm', repo: 'cli' },
getFileContentsOnBranch: (file) => {
const path = file.replace(/\/?package.json$/, '') || '.'
const dependencies = path === '.' ? paths.filter(p => p !== '.').reduce((acc, ws) => {
acc[names[ws]] = `^${versions[ws]}`
return acc
}, {}) : {}
return {
parsedContent: JSON.stringify({
name: names[path],
version: versions[path].toString(),
dependencies,
}),
}
},
}

const workspaces = (fn) => paths.reduce((acc, p) => {
acc[p] = fn(p)
return acc
}, {})

return {
workspaces,
github,
versions,
paths,
plugin: new NodeWorkspace(github, 'latest', workspaces(() => ({ releaseType: 'node' }))),
}
}

const mockPullRequests = async (workspace, updates = workspace.paths) => {
const { workspaces, plugin, github, versions } = workspace

const strategiesByPath = workspaces((path) => new Node({
github,
path,
changelogSections: [
{ type: 'deps', section: 'Dependencies' },
{ type: 'fix', section: 'Fixes' },
],
changelogNotes: new Changelog({ github }),
}))

const commitsByPath = workspaces((path) => updates.includes(path) ? [{
sha: '123',
message: 'fix: stuff',
files: ['package.json'],
}] : [])

const releaseByPath = workspaces((p) => ({
sha: '',
notes: '',
tag: new TagName(versions[p], '', '-', true),
}))

await plugin.preconfigure(strategiesByPath, commitsByPath, releaseByPath)

const candidatePullRequests = []
for (const [path, strategy] of Object.entries(strategiesByPath)) {
const pullRequest = await strategy.buildReleasePullRequest(
commitsByPath[path],
releaseByPath[path]
)
if (pullRequest?.version) {
candidatePullRequests.push({
path,
pullRequest,
config: {
releaseType: 'node',
},
})
}
}

const result = await plugin.run(candidatePullRequests)
return result[0].pullRequest
}

t.test('root and ws fixes', async t => {
const workspace = await mockNodeWorkspace()
const pullRequest = await mockPullRequests(workspace)
const pkgs = pullRequest.updates
.filter(u => u.updater.rawContent)
.map(u => JSON.parse(u.updater.rawContent))

t.strictSame(pkgs, [
{
name: '@npmcli/a',
version: '2.2.3',
dependencies: {},
},
{
name: 'npm',
version: '1.1.2',
dependencies: { '@npmcli/a': '^2.2.3' },
},
])
})

t.test('root only', async t => {
const workspace = await mockNodeWorkspace()
const pullRequest = await mockPullRequests(workspace, ['.'])
const pkgs = pullRequest.updates
.filter(u => u.updater.rawContent)
.map(u => JSON.parse(u.updater.rawContent))

t.strictSame(pkgs, [
{
name: 'npm',
version: '1.1.2',
dependencies: { '@npmcli/a': '^2.2.2' },
},
])
})

t.test('ws only', async t => {
const workspace = await mockNodeWorkspace()
const pullRequest = await mockPullRequests(workspace, ['workspaces/a'])
const pkgs = pullRequest.updates
.filter(u => u.updater.rawContent)
.map(u => JSON.parse(u.updater.rawContent))

t.strictSame(pkgs, [
{
name: '@npmcli/a',
version: '2.2.3',
dependencies: {},
},
{
name: 'npm',
version: '1.1.2',
dependencies: { '@npmcli/a': '^2.2.3' },
},
])
})

t.test('orders root to top', async t => {
const ws1 = await mockNodeWorkspace(['a', 'b', 'c', 'd', 'e', 'f'])
const [rootWs1] = ws1.paths.splice(0, 1)
ws1.paths.push(rootWs1)
const pr1 = await mockPullRequests(ws1)
t.equal(pr1.body.releaseData[0].component, 'npm')

const ws2 = await mockNodeWorkspace(['a', '123', 'bb', 'bbb', 'bbbe', 'aaaa'])
const [rootWs2] = ws2.paths.splice(0, 1)
ws2.paths.splice(4, 0, rootWs2)
const pr2 = await mockPullRequests(ws2)
t.equal(pr2.body.releaseData[0].component, 'npm')
})

t.test('stubbed errors', async t => {
const { plugin } = await mockNodeWorkspace()
t.throws(() => plugin.newCandidate())
t.throws(() => plugin.bumpVersion())
})