@npmcli/template-oss 3.8.0 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,13 +6,9 @@
6
6
  "postlint": "template-oss-check",
7
7
  "template-oss-apply": "template-oss-apply --force",
8
8
  "lintfix": "{{npmBin}} run lint -- --fix",
9
- "preversion": "{{npmBin}} test",
10
- {{#if pkgPrivate}}
11
- "postversion": "git push origin --follow-tags",
12
- {{else}}
13
- "postversion": "{{npmBin}} publish",
14
- "prepublishOnly": "git push origin --follow-tags",
15
- {{/if}}
9
+ "preversion": {{{del}}},
10
+ "postversion": {{{del}}},
11
+ "prepublishOnly": {{{del}}},
16
12
  "snap": "tap",
17
13
  "test": "tap",
18
14
  "posttest": "{{npmBin}} run lint",
@@ -37,7 +37,7 @@ jobs:
37
37
  - name: Output ref
38
38
  id: ref
39
39
  run: echo "::set-output name=branch::$\{{ fromJSON(needs.release-please.outputs.pr).headBranchName }}"
40
- {{> setupGit with=(obj ref="${{ steps.ref.outputs.branch }}")}}
40
+ {{> setupGit with=(obj ref="${{ steps.ref.outputs.branch }}" fetch-depth=0)}}
41
41
  {{> setupNode}}
42
42
  {{> setupDeps}}
43
43
  - name: Post pull request actions
@@ -3,11 +3,15 @@ const logger = require('./logger.js')
3
3
  const ChangelogNotes = require('./changelog.js')
4
4
  const Version = require('./version.js')
5
5
  const WorkspaceDeps = require('./workspace-deps.js')
6
+ const NodeWorkspace = require('./node-workspace.js')
6
7
 
7
8
  RP.setLogger(logger)
8
9
  RP.registerChangelogNotes('default', (options) => new ChangelogNotes(options))
9
10
  RP.registerVersioningStrategy('default', (options) => new Version(options))
10
- RP.registerPlugin('workspace-deps', (options) => new WorkspaceDeps(options))
11
+ RP.registerPlugin('workspace-deps', (o) =>
12
+ new WorkspaceDeps(o.github, o.targetBranch, o.repositoryConfig))
13
+ RP.registerPlugin('node-workspace', (o) =>
14
+ new NodeWorkspace(o.github, o.targetBranch, o.repositoryConfig))
11
15
 
12
16
  const main = async ({ repo: fullRepo, token, dryRun, branch }) => {
13
17
  if (!token) {
@@ -0,0 +1,11 @@
1
+ const Version = require('./version.js')
2
+ const RP = require('release-please/build/src/plugins/node-workspace')
3
+
4
+ module.exports = class NodeWorkspace extends RP.NodeWorkspace {
5
+ bumpVersion (pkg) {
6
+ // The default release please node-workspace plugin forces a patch
7
+ // bump for the root if it only includes workspace dep updates.
8
+ // This does the same thing except it respects the prerelease config.
9
+ return new Version(pkg).bump(pkg.version, [{ type: 'fix' }])
10
+ }
11
+ }
@@ -1,4 +1,6 @@
1
1
  const { ManifestPlugin } = require('release-please/build/src/plugin')
2
+ const { Changelog } = require('release-please/build/src/updaters/changelog.js')
3
+ const { PackageJson } = require('release-please/build/src/updaters/node/package-json.js')
2
4
 
3
5
  const matchLine = (line, re) => {
4
6
  const trimmed = line.trim().replace(/^[*\s]+/, '')
@@ -10,61 +12,86 @@ const matchLine = (line, re) => {
10
12
 
11
13
  module.exports = class WorkspaceDeps extends ManifestPlugin {
12
14
  run (pullRequests) {
13
- for (const { pullRequest } of pullRequests) {
14
- const depLinks = pullRequest.body.releaseData.reduce((acc, release) => {
15
- if (release.component) {
16
- const url = matchLine(release.notes.split('\n')[0], /\[[^\]]+\]\((.*?)\)/)
17
- if (url) {
18
- acc[release.component] = url[1]
15
+ try {
16
+ for (const { pullRequest } of pullRequests) {
17
+ const getChangelog = (release) => pullRequest.updates.find((u) => {
18
+ const isChangelog = u.updater instanceof Changelog
19
+ const isComponent = release.component && u.path.startsWith(release.component)
20
+ const isRoot = !release.component && !u.path.includes('/')
21
+ return isChangelog && (isComponent || isRoot)
22
+ })
23
+
24
+ const getComponent = (pkgName) => pullRequest.updates.find((u) => {
25
+ const isPkg = u.updater instanceof PackageJson
26
+ return isPkg && JSON.parse(u.updater.rawContent).name === pkgName
27
+ }).path.replace(/\/package\.json$/, '')
28
+
29
+ const depLinksByComponent = pullRequest.body.releaseData.reduce((acc, release) => {
30
+ if (release.component) {
31
+ const path = [
32
+ this.github.repository.owner,
33
+ this.github.repository.repo,
34
+ 'releases',
35
+ 'tag',
36
+ release.tag.toString(),
37
+ ]
38
+ acc[release.component] = `https://github.com/${path.join('/')}`
19
39
  }
20
- }
21
- return acc
22
- }, {})
40
+ return acc
41
+ }, {})
23
42
 
24
- for (const release of pullRequest.body.releaseData) {
25
- const lines = release.notes.split('\n')
26
- const newLines = []
43
+ for (const release of pullRequest.body.releaseData) {
44
+ const lines = release.notes.split('\n')
45
+ const newLines = []
27
46
 
28
- let inWorkspaceDeps = false
29
- let collectWorkspaceDeps = false
47
+ let inWorkspaceDeps = false
48
+ let collectWorkspaceDeps = false
30
49
 
31
- for (const line of lines) {
32
- if (matchLine(line, 'The following workspace dependencies were updated')) {
50
+ for (const line of lines) {
51
+ if (matchLine(line, 'The following workspace dependencies were updated')) {
33
52
  // We are in the section with our workspace deps
34
53
  // Set the flag and discard this line since we dont want it in the final output
35
- inWorkspaceDeps = true
36
- } else if (inWorkspaceDeps) {
37
- if (collectWorkspaceDeps) {
38
- const depMatch = matchLine(line, /^(\S+) bumped from \S+ to (\S+)$/)
39
- if (depMatch) {
54
+ inWorkspaceDeps = true
55
+ } else if (inWorkspaceDeps) {
56
+ if (collectWorkspaceDeps) {
57
+ const depMatch = matchLine(line, /^(\S+) bumped from \S+ to (\S+)$/)
58
+ if (depMatch) {
40
59
  // If we have a line that is a workspace dep update, then reformat
41
60
  // it and save it to the new lines
42
- const [, depName, newVersion] = depMatch
43
- const depSpec = `\`${depName}@${newVersion}\``
44
- const url = depLinks[depName]
45
- newLines.push(` * ${url ? `[${depSpec}](${url})` : depSpec}`)
46
- } else {
61
+ const [, depName, newVersion] = depMatch
62
+ const depSpec = `\`${depName}@${newVersion}\``
63
+ const url = depLinksByComponent[getComponent(depName)]
64
+ newLines.push(` * deps: [${depSpec}](${url})`)
65
+ } else {
47
66
  // Anything else means we are done with dependencies so ignore
48
67
  // this line and dont look for any more
49
- collectWorkspaceDeps = false
50
- }
51
- } else if (matchLine(line, 'dependencies')) {
68
+ collectWorkspaceDeps = false
69
+ }
70
+ } else if (matchLine(line, 'dependencies')) {
52
71
  // Only collect dependencies discard dev deps and everything else
53
- collectWorkspaceDeps = true
54
- } else if (matchLine(line, '') || matchLine(line, /^#/)) {
55
- inWorkspaceDeps = false
72
+ collectWorkspaceDeps = true
73
+ } else if (matchLine(line, '') || matchLine(line, /^#/)) {
74
+ inWorkspaceDeps = false
75
+ newLines.push(line)
76
+ }
77
+ } else {
56
78
  newLines.push(line)
57
79
  }
58
- } else {
59
- newLines.push(line)
60
80
  }
61
- }
62
81
 
63
- const newNotes = newLines.join('\n').trim()
64
- const emptyDeps = newNotes.match(/### Dependencies[\n]+(### .*)/m)
82
+ let newNotes = newLines.join('\n').trim()
83
+ const emptyDeps = newNotes.match(/### Dependencies[\n]+(### .*)/m)
84
+ if (emptyDeps) {
85
+ newNotes = newNotes.replace(emptyDeps[0], emptyDeps[1])
86
+ }
65
87
 
66
- release.notes = emptyDeps ? newNotes.replace(emptyDeps[0], emptyDeps[1]) : newNotes
88
+ release.notes = newNotes
89
+ getChangelog(release).updater.changelogEntry = newNotes
90
+ }
67
91
  }
92
+ } catch {
93
+ // Always return pull requests even if we failed so
94
+ // we dont fail the release
68
95
  }
69
96
 
70
97
  return pullRequests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npmcli/template-oss",
3
- "version": "3.8.0",
3
+ "version": "3.8.1",
4
4
  "description": "templated files used in npm CLI team oss projects",
5
5
  "main": "lib/content/index.js",
6
6
  "bin": {
@@ -12,9 +12,6 @@
12
12
  "lint": "eslint \"**/*.js\"",
13
13
  "lintfix": "npm run lint -- --fix",
14
14
  "posttest": "npm run lint",
15
- "postversion": "npm publish",
16
- "prepublishOnly": "git push origin --follow-tags",
17
- "preversion": "npm test",
18
15
  "snap": "tap",
19
16
  "test": "tap",
20
17
  "template-oss-apply": "template-oss-apply --force",