zx-bulk-release 2.0.0 → 2.1.0
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 +10 -0
- package/package.json +1 -1
- package/src/main/js/build.js +2 -2
- package/src/main/js/deps.js +28 -0
- package/src/main/js/npm.js +6 -7
- package/src/main/js/processor.js +43 -16
- package/src/main/js/util.js +11 -0
- package/src/main/js/contextify.js +0 -18
- package/src/main/js/topo.js +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [2.1.0](https://github.com/semrel-extra/zx-bulk-release/compare/v2.0.1...v2.1.0) (2023-03-22)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
* feat: add memoize to avoid redundant builds ([151ea71](https://github.com/semrel-extra/zx-bulk-release/commit/151ea7118af3907aad73f395ac3fb2420e25b2c8))
|
|
5
|
+
|
|
6
|
+
## [2.0.1](https://github.com/semrel-extra/zx-bulk-release/compare/v2.0.0...v2.0.1) (2023-03-22)
|
|
7
|
+
|
|
8
|
+
### Fixes & improvements
|
|
9
|
+
* perf: optimize pkg fetch ([749ea0b](https://github.com/semrel-extra/zx-bulk-release/commit/749ea0b29f854e57a447f4cdefe06ab32acba497))
|
|
10
|
+
|
|
1
11
|
## [2.0.0](https://github.com/semrel-extra/zx-bulk-release/compare/v1.26.2...v2.0.0) (2023-03-21)
|
|
2
12
|
|
|
3
13
|
### Features
|
package/package.json
CHANGED
package/src/main/js/build.js
CHANGED
|
@@ -2,10 +2,10 @@ import {traverseDeps} from './deps.js'
|
|
|
2
2
|
import {fetchPkg} from './npm.js'
|
|
3
3
|
import {runCmd} from './processor.js'
|
|
4
4
|
|
|
5
|
-
export const build = async (pkg, packages, run = runCmd) => {
|
|
5
|
+
export const build = async (pkg, packages, run = runCmd, self = build) => {
|
|
6
6
|
if (pkg.built) return true
|
|
7
7
|
|
|
8
|
-
await traverseDeps(pkg, packages, async (_, {pkg}) =>
|
|
8
|
+
await traverseDeps(pkg, packages, async (_, {pkg}) => self(pkg, packages))
|
|
9
9
|
|
|
10
10
|
const {config} = pkg
|
|
11
11
|
|
package/src/main/js/deps.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {semver} from 'zx-extra'
|
|
2
|
+
import {topo as _topo} from '@semrel-extra/topo'
|
|
2
3
|
|
|
3
4
|
export const depScopes = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
|
|
4
5
|
|
|
@@ -63,3 +64,30 @@ export const subsWorkspace = (decl, actual) => {
|
|
|
63
64
|
|
|
64
65
|
return decl
|
|
65
66
|
}
|
|
67
|
+
|
|
68
|
+
export const topo = async ({flags = {}, cwd} = {}) => {
|
|
69
|
+
const ignore = typeof flags.ignore === 'string'
|
|
70
|
+
? flags.ignore.split(/\s*,\s*/)
|
|
71
|
+
: Array.isArray(flags.ignore)
|
|
72
|
+
? flags.ignore
|
|
73
|
+
: []
|
|
74
|
+
|
|
75
|
+
const filter = flags.includePrivate
|
|
76
|
+
? () => true
|
|
77
|
+
: ({manifest: {private: _private, name}}) =>
|
|
78
|
+
flags.includePrivate ? true : !_private &&
|
|
79
|
+
!ignore.includes(name)
|
|
80
|
+
|
|
81
|
+
return _topo({cwd, filter})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const traverseQueue = async ({queue, prev, cb}) => {
|
|
85
|
+
const acc = {}
|
|
86
|
+
|
|
87
|
+
return Promise.all(queue.map((name) =>
|
|
88
|
+
(acc[name] = (async () => {
|
|
89
|
+
await Promise.all((prev.get(name) || []).map((p) => acc[p]))
|
|
90
|
+
await cb(name)
|
|
91
|
+
})()))
|
|
92
|
+
)
|
|
93
|
+
}
|
package/src/main/js/npm.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import {parseEnv} from './config.js'
|
|
2
2
|
import {log} from './log.js'
|
|
3
|
-
import {$, ctx, fs, path,
|
|
3
|
+
import {$, ctx, fs, path, INI, fetch} from 'zx-extra'
|
|
4
4
|
|
|
5
5
|
export const fetchPkg = async (pkg, {env = $.env} = {}) => {
|
|
6
|
+
const id = `${pkg.name}@${pkg.version}`
|
|
7
|
+
|
|
6
8
|
try {
|
|
9
|
+
log({pkg})(`fetching '${id}'`)
|
|
7
10
|
const cwd = pkg.absPath
|
|
8
11
|
const {npmRegistry, npmToken, npmConfig} = parseEnv(env)
|
|
9
|
-
const temp = tempy.temporaryDirectory()
|
|
10
12
|
const bearerToken = getBearerToken(npmRegistry, npmToken, npmConfig)
|
|
11
13
|
const tarball = getTarballUrl(npmRegistry, pkg.name, pkg.version)
|
|
12
|
-
|
|
13
|
-
await $.raw`wget --header='Authorization: ${bearerToken}' -qO- ${tarball} | tar xvz -C ${temp}`
|
|
14
|
-
await copy({from: ['**/*', '!package.json'], to: cwd, baseFrom: `${temp}/package`})
|
|
14
|
+
await $.raw`wget --header='Authorization: ${bearerToken}' -qO- ${tarball} | tar xvz -C ${cwd} --strip-components=1 --exclude='package.json'`
|
|
15
15
|
|
|
16
16
|
pkg.fetched = true
|
|
17
|
-
log({pkg})(`fetched '${pkg.name}@${pkg.version}'`)
|
|
18
17
|
} catch (e) {
|
|
19
|
-
log({pkg})(`fetching '${
|
|
18
|
+
log({pkg})(`fetching '${id} failed`, e)
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
|
package/src/main/js/processor.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import os from 'node:os'
|
|
2
|
-
import {$,
|
|
2
|
+
import {$, within} from 'zx-extra'
|
|
3
3
|
import {log} from './log.js'
|
|
4
|
-
import {topo,
|
|
5
|
-
import {contextify} from './contextify.js'
|
|
4
|
+
import {topo, traverseQueue} from './deps.js'
|
|
6
5
|
import {analyze} from './analyze.js'
|
|
7
6
|
import {build} from './build.js'
|
|
8
|
-
import {publish} from './publish.js'
|
|
7
|
+
import {getLatest, publish} from './publish.js'
|
|
9
8
|
import {createState} from './state.js'
|
|
10
|
-
import {tpl} from './util.js'
|
|
9
|
+
import {memoizeBy, tpl} from './util.js'
|
|
11
10
|
import {queuefy} from 'queuefy'
|
|
11
|
+
import {getConfig} from "./config.js";
|
|
12
12
|
|
|
13
|
-
export const run = async ({cwd = process.cwd(), env, flags = {}
|
|
14
|
-
const state =
|
|
15
|
-
const _runCmd = queuefy(runCmd, concurrency)
|
|
16
|
-
|
|
17
|
-
$.state = state
|
|
18
|
-
$.env = {...process.env, ...env}
|
|
19
|
-
$.verbose = !!(flags.debug || $.env.DEBUG ) || $.verbose
|
|
13
|
+
export const run = async ({cwd = process.cwd(), env, flags = {}} = {}) => within(async () => {
|
|
14
|
+
const {state, build, publish} = createContext(flags, env)
|
|
20
15
|
|
|
21
16
|
log()('zx-bulk-release')
|
|
22
17
|
|
|
@@ -26,7 +21,7 @@ export const run = async ({cwd = process.cwd(), env, flags = {}, concurrency = o
|
|
|
26
21
|
|
|
27
22
|
state.setQueue(queue, packages)
|
|
28
23
|
|
|
29
|
-
await
|
|
24
|
+
await traverseQueue({queue, prev, async cb(name) {
|
|
30
25
|
state.setStatus('analyzing', name)
|
|
31
26
|
const pkg = packages[name]
|
|
32
27
|
await contextify(pkg, packages, root)
|
|
@@ -40,7 +35,7 @@ export const run = async ({cwd = process.cwd(), env, flags = {}, concurrency = o
|
|
|
40
35
|
|
|
41
36
|
state.setStatus('pending')
|
|
42
37
|
|
|
43
|
-
await
|
|
38
|
+
await traverseQueue({queue, prev, async cb(name) {
|
|
44
39
|
const pkg = packages[name]
|
|
45
40
|
|
|
46
41
|
if (!pkg.releaseType) {
|
|
@@ -49,7 +44,7 @@ export const run = async ({cwd = process.cwd(), env, flags = {}, concurrency = o
|
|
|
49
44
|
}
|
|
50
45
|
|
|
51
46
|
state.setStatus('building', name)
|
|
52
|
-
await build(pkg, packages
|
|
47
|
+
await build(pkg, packages)
|
|
53
48
|
|
|
54
49
|
if (flags.dryRun) {
|
|
55
50
|
state.setStatus('success', name)
|
|
@@ -57,7 +52,7 @@ export const run = async ({cwd = process.cwd(), env, flags = {}, concurrency = o
|
|
|
57
52
|
}
|
|
58
53
|
|
|
59
54
|
state.setStatus('publishing', name)
|
|
60
|
-
await publish(pkg
|
|
55
|
+
await publish(pkg)
|
|
61
56
|
|
|
62
57
|
state.setStatus('success', name)
|
|
63
58
|
}})
|
|
@@ -79,3 +74,35 @@ export const runCmd = async (pkg, name) => {
|
|
|
79
74
|
await $.o({cwd: pkg.absPath, quote: v => v, preferLocal: true})`${cmd}`
|
|
80
75
|
}
|
|
81
76
|
}
|
|
77
|
+
|
|
78
|
+
const createContext = (flags, env) => {
|
|
79
|
+
const state = createState({file: flags.report})
|
|
80
|
+
const _runCmd = queuefy(runCmd, flags.concurrency || os.cpus().length)
|
|
81
|
+
const _build = memoizeBy((pkg, packages) => build(pkg, packages, _runCmd, _build))
|
|
82
|
+
const _publish = memoizeBy((pkg) => publish(pkg, _runCmd))
|
|
83
|
+
|
|
84
|
+
$.state = state
|
|
85
|
+
$.env = {...process.env, ...env}
|
|
86
|
+
$.verbose = !!(flags.debug || $.env.DEBUG ) || $.verbose
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
state,
|
|
90
|
+
runCmd: _runCmd,
|
|
91
|
+
build: _build,
|
|
92
|
+
publish: _publish
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Inspired by https://docs.github.com/en/actions/learn-github-actions/contexts
|
|
97
|
+
export const contextify = async (pkg, packages, root) => {
|
|
98
|
+
pkg.config = await getConfig(pkg.absPath, root.absPath)
|
|
99
|
+
pkg.latest = await getLatest(pkg)
|
|
100
|
+
pkg.context = {
|
|
101
|
+
git: {
|
|
102
|
+
sha: (await $`git rev-parse HEAD`).toString().trim(),
|
|
103
|
+
root: (await $`git rev-parse --show-toplevel`).toString().trim(),
|
|
104
|
+
},
|
|
105
|
+
env: $.env,
|
|
106
|
+
packages
|
|
107
|
+
}
|
|
108
|
+
}
|
package/src/main/js/util.js
CHANGED
|
@@ -44,3 +44,14 @@ export const getPromise = () => {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export const keyByValue = (obj, value) => Object.keys(obj).find((key) => obj[key] === value)
|
|
47
|
+
|
|
48
|
+
export const memoizeBy = (fn, memo = new Map(), getKey = v => v) => (...args) => {
|
|
49
|
+
const key = getKey(...args)
|
|
50
|
+
if (memo.has(key)) {
|
|
51
|
+
return memo.get(key)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const value = fn(...args)
|
|
55
|
+
memo.set(key, value)
|
|
56
|
+
return value
|
|
57
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Inspired by https://docs.github.com/en/actions/learn-github-actions/contexts
|
|
2
|
-
|
|
3
|
-
import {getConfig} from './config.js'
|
|
4
|
-
import {getLatest} from './publish.js'
|
|
5
|
-
import {$} from 'zx-extra'
|
|
6
|
-
|
|
7
|
-
export const contextify = async (pkg, packages, root) => {
|
|
8
|
-
pkg.config = await getConfig(pkg.absPath, root.absPath)
|
|
9
|
-
pkg.latest = await getLatest(pkg)
|
|
10
|
-
pkg.context = {
|
|
11
|
-
git: {
|
|
12
|
-
sha: (await $`git rev-parse HEAD`).toString().trim(),
|
|
13
|
-
root: (await $`git rev-parse --show-toplevel`).toString().trim(),
|
|
14
|
-
},
|
|
15
|
-
env: $.env,
|
|
16
|
-
packages
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/main/js/topo.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {topo as _topo} from '@semrel-extra/topo'
|
|
2
|
-
import {getPromise} from './util.js'
|
|
3
|
-
|
|
4
|
-
export const topo = async ({flags = {}, cwd} = {}) => {
|
|
5
|
-
const ignore = typeof flags.ignore === 'string'
|
|
6
|
-
? flags.ignore.split(/\s*,\s*/)
|
|
7
|
-
: Array.isArray(flags.ignore)
|
|
8
|
-
? flags.ignore
|
|
9
|
-
: []
|
|
10
|
-
|
|
11
|
-
const filter = flags.includePrivate
|
|
12
|
-
? () => true
|
|
13
|
-
: ({manifest: {private: _private, name}}) =>
|
|
14
|
-
flags.includePrivate ? true : !_private &&
|
|
15
|
-
!ignore.includes(name)
|
|
16
|
-
|
|
17
|
-
return _topo({cwd, filter})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const traverse = async ({nodes, prev, cb}) => {
|
|
21
|
-
const waitings = nodes.reduce((acc, node) => {
|
|
22
|
-
acc[node] = getPromise()
|
|
23
|
-
return acc
|
|
24
|
-
}, {})
|
|
25
|
-
|
|
26
|
-
await Promise.all(nodes.map(async (name) => {
|
|
27
|
-
await Promise.all((prev.get(name) || []).map((p) => waitings[p].promise))
|
|
28
|
-
await cb(name)
|
|
29
|
-
waitings[name].resolve(true)
|
|
30
|
-
}))
|
|
31
|
-
}
|