zx-bulk-release 2.2.4 → 2.2.6

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [2.2.6](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.5...v2.2.6) (2023-03-24)
2
+
3
+ ### Fixes & improvements
4
+ * refactor: apply memoize to git utils ([ff8ff78](https://github.com/semrel-extra/zx-bulk-release/commit/ff8ff7840eb65171b7d69d45cafed944627bfd20))
5
+
6
+ ## [2.2.5](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.4...v2.2.5) (2023-03-24)
7
+
8
+ ### Fixes & improvements
9
+ * perf: print err.stack on process failure ([5f3271f](https://github.com/semrel-extra/zx-bulk-release/commit/5f3271fa4e85d6d8f0b23ad240c9d566fddf69be))
10
+
1
11
  ## [2.2.4](https://github.com/semrel-extra/zx-bulk-release/compare/v2.2.3...v2.2.4) (2023-03-24)
2
12
 
3
13
  ### Fixes & improvements
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zx-bulk-release",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "description": "zx-based alternative for multi-semantic-release",
5
5
  "type": "module",
6
6
  "exports": {
@@ -34,8 +34,6 @@ export const normalizePkgConfig = (config, env) => ({
34
34
  npmFetch: config.npmFetch || config.fetch || config.fetchPkg,
35
35
  buildCmd: config.buildCmd || config.cmd,
36
36
  get ghBasicAuth() {
37
- console.log('this.ghToken', !!this.ghToken)
38
- console.log('this.ghUser', !!this.ghUser)
39
37
  return this.ghUser && this.ghToken ? `${this.ghUser}:${this.ghToken}` : false
40
38
  }
41
39
  })
@@ -1,14 +1,8 @@
1
1
  import {$, ctx, fs, path, tempy, copy} from 'zx-extra'
2
2
  import {log} from './log.js'
3
- import {keyByValue} from './util.js'
4
-
5
- const branches = {}
6
- export const fetchRepo = async ({cwd: _cwd, branch, origin: _origin, basicAuth}) => ctx(async ($) => {
7
- const root = await getRoot(_cwd)
8
- const id = `${root}:${branch}`
9
-
10
- if (branches[id]) return branches[id]
3
+ import {keyByValue, memoizeBy} from './util.js'
11
4
 
5
+ export const fetchRepo = memoizeBy(async ({cwd: _cwd, branch, origin: _origin, basicAuth}) => ctx(async ($) => {
12
6
  const origin = _origin || (await getRepo(_cwd, {basicAuth})).repoAuthedUrl
13
7
  const cwd = tempy.temporaryDirectory()
14
8
  $.cwd = cwd
@@ -19,10 +13,9 @@ export const fetchRepo = async ({cwd: _cwd, branch, origin: _origin, basicAuth})
19
13
  await $`git init .`
20
14
  await $`git remote add origin ${origin}`
21
15
  }
22
- branches[id] = cwd
23
16
 
24
- return branches[id]
25
- })
17
+ return cwd
18
+ }), async ({cwd, branch}) => `${await getRoot(cwd)}:${branch}`)
26
19
 
27
20
  export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFiles, files = [], basicAuth, gitCommitterEmail, gitCommitterName}) => ctx(async ($) => {
28
21
  let retries = 3
@@ -54,7 +47,6 @@ export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFile
54
47
  } catch (e) {
55
48
  retries -= 1
56
49
  log({level: 'error'})('git push failed', 'branch', branch, 'retries left', retries, e)
57
- branches[keyByValue(branches, _cwd)] = null
58
50
 
59
51
  if (retries === 0) {
60
52
  throw e
@@ -63,14 +55,11 @@ export const pushCommit = async ({cwd, from, to, branch, origin, msg, ignoreFile
63
55
  }
64
56
  })
65
57
 
66
- const repos = {}
67
- export const getRepo = async (_cwd, {basicAuth} = {}) => {
68
- const cwd = await getRoot(_cwd)
69
- if (repos[cwd]) return repos[cwd]
58
+ export const getRoot = async (cwd) => (await $.o({cwd})`git rev-parse --show-toplevel`).toString().trim()
70
59
 
71
- const e = new Error()
72
- console.log('!!! has basic auth', !!basicAuth, e.stack)
60
+ export const getSha = async (cwd) => (await $.o({cwd})`git rev-parse HEAD`).toString().trim()
73
61
 
62
+ export const getRepo = memoizeBy(async (cwd, {basicAuth} = {}) => {
74
63
  const originUrl = await getOrigin(cwd)
75
64
  const [, , repoHost, repoName] = originUrl.replace(':', '/').replace(/\.git/, '').match(/.+(@|\/\/)([^/]+)\/(.+)$/) || []
76
65
  const repoPublicUrl = `https://${repoHost}/${repoName}`
@@ -78,29 +67,18 @@ export const getRepo = async (_cwd, {basicAuth} = {}) => {
78
67
  ? `https://${basicAuth}@${repoHost}/${repoName}.git`
79
68
  : originUrl
80
69
 
81
- repos[cwd] = {
70
+ return {
82
71
  repoName,
83
72
  repoHost,
84
73
  repoPublicUrl,
85
74
  repoAuthedUrl,
86
75
  originUrl,
87
76
  }
77
+ }, getRoot)
88
78
 
89
- return repos[cwd]
90
- }
91
-
92
- const origins = {}
93
- export const getOrigin = async (cwd) => {
94
- if (!origins[cwd]) {
95
- origins[cwd] = (await $.o({cwd})`git config --get remote.origin.url`).toString().trim()
96
- }
97
-
98
- return origins[cwd]
99
- }
100
-
101
- export const getRoot = async (cwd) => (await $.o({cwd})`git rev-parse --show-toplevel`).toString().trim()
102
-
103
- export const getSha = async (cwd) => (await $.o({cwd})`git rev-parse HEAD`).toString().trim()
79
+ export const getOrigin = memoizeBy(async (cwd) =>
80
+ $.o({cwd})`git config --get remote.origin.url`.then(r => r.toString().trim())
81
+ )
104
82
 
105
83
  export const getCommits = async (cwd, from, to = 'HEAD') => ctx(async ($) => {
106
84
  const ref = from ? `${from}..${to}` : to
@@ -45,9 +45,9 @@ export const pushMeta = async (pkg) => {
45
45
  }
46
46
 
47
47
  export const getLatest = async (pkg) => {
48
- const {absPath: cwd, name} = pkg
48
+ const {absPath: cwd, name, config: {ghBasicAuth: basicAuth}} = pkg
49
49
  const tag = await getLatestTag(cwd, name)
50
- const meta = await getLatestMeta(cwd, tag?.ref) || await fetchManifest(pkg, {nothrow: true})
50
+ const meta = await getLatestMeta(cwd, tag?.ref, basicAuth) || await fetchManifest(pkg, {nothrow: true})
51
51
 
52
52
  return {
53
53
  tag,
@@ -155,11 +155,11 @@ export const parseDateTag = (date) => new Date(date.replaceAll('.', '-')+'Z')
155
155
 
156
156
  export const getArtifactPath = (tag) => tag.toLowerCase().replace(/[^a-z0-9-]/g, '-')
157
157
 
158
- export const getLatestMeta = async (cwd, tag) => {
158
+ export const getLatestMeta = async (cwd, tag, basicAuth) => {
159
159
  if (!tag) return null
160
160
 
161
161
  try {
162
- const _cwd = await fetchRepo({cwd, branch: 'meta'})
162
+ const _cwd = await fetchRepo({cwd, branch: 'meta', basicAuth})
163
163
  return await Promise.any([
164
164
  fs.readJson(path.resolve(_cwd, `${getArtifactPath(tag)}.json`)),
165
165
  fs.readJson(path.resolve(_cwd, getArtifactPath(tag), 'meta.json'))
@@ -63,7 +63,7 @@ export const run = async ({cwd = process.cwd(), env, flags = {}} = {}) => within
63
63
  }})
64
64
  } catch (e) {
65
65
  report
66
- .log({level: 'error'})(e)
66
+ .log({level: 'error'})(e, e.stack)
67
67
  .set('error', e)
68
68
  .setStatus('failure')
69
69
  throw e
@@ -45,8 +45,8 @@ export const getPromise = () => {
45
45
 
46
46
  export const keyByValue = (obj, value) => Object.keys(obj).find((key) => obj[key] === value)
47
47
 
48
- export const memoizeBy = (fn, memo = new Map(), getKey = v => v) => (...args) => {
49
- const key = getKey(...args)
48
+ export const memoizeBy = (fn, getKey = v => v, memo = new Map()) => async (...args) => {
49
+ const key = await getKey(...args)
50
50
  if (memo.has(key)) {
51
51
  return memo.get(key)
52
52
  }