@notifiles/sdk 1.4.0 → 1.5.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/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Runs `worker` over `items` with at most `concurrency` in flight at once.
|
|
2
|
+
// Every item runs to completion regardless of sibling failures; if any
|
|
3
|
+
// worker throws, a single aggregate error (with an `.errors` array) is
|
|
4
|
+
// thrown after all items have settled, so a failure never abandons work
|
|
5
|
+
// that was already in progress.
|
|
6
|
+
export default async function runWithConcurrency(items, concurrency, worker) {
|
|
7
|
+
const queue = [...items]
|
|
8
|
+
const errors = []
|
|
9
|
+
|
|
10
|
+
const lanes = Array.from(
|
|
11
|
+
{ length: Math.max(1, Math.min(concurrency, queue.length)) },
|
|
12
|
+
async () => {
|
|
13
|
+
while (queue.length) {
|
|
14
|
+
const item = queue.shift()
|
|
15
|
+
try {
|
|
16
|
+
await worker(item)
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.error(e)
|
|
19
|
+
errors.push(e)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
await Promise.all(lanes)
|
|
26
|
+
|
|
27
|
+
if (errors.length) {
|
|
28
|
+
const error = new Error(`[notifiles] ${errors.length} of ${items.length} item(s) failed`)
|
|
29
|
+
error.errors = errors
|
|
30
|
+
throw error
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -12,6 +12,9 @@ import {
|
|
|
12
12
|
getCachedTemplateHash,
|
|
13
13
|
updateTemplateHashCache
|
|
14
14
|
} from './lib/cache.js'
|
|
15
|
+
import runWithConcurrency from '../../lib/async/runWithConcurrency.js'
|
|
16
|
+
|
|
17
|
+
const DEFAULT_CONCURRENCY = 4
|
|
15
18
|
|
|
16
19
|
export default async ({
|
|
17
20
|
path,
|
|
@@ -28,13 +31,14 @@ export default async ({
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
const forceUpdate = force || settings.forceUpdate
|
|
34
|
+
const concurrency = settings.concurrency || DEFAULT_CONCURRENCY
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
let entry =
|
|
36
|
+
await runWithConcurrency(entries, concurrency, async (initialEntry) => {
|
|
37
|
+
let entry = initialEntry
|
|
34
38
|
|
|
35
39
|
switch (entry.manifest.status) {
|
|
36
40
|
case 'pause': {
|
|
37
|
-
|
|
41
|
+
return
|
|
38
42
|
}
|
|
39
43
|
default: break
|
|
40
44
|
}
|
|
@@ -43,7 +47,7 @@ export default async ({
|
|
|
43
47
|
const currentHash = await computeTemplateHash({ path: entry.path })
|
|
44
48
|
if (!forceUpdate && cachedHash && currentHash && cachedHash === currentHash) {
|
|
45
49
|
console.log(`[notifiles] Skip ${entry.slug || entry.name || entry.path}: no changes detected`)
|
|
46
|
-
|
|
50
|
+
return
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
entry = (await format({ entry, settings })).entry
|
|
@@ -53,7 +57,7 @@ export default async ({
|
|
|
53
57
|
entry = (await cloudify({ entry, settings })).entry
|
|
54
58
|
entry = (await attach({ entry, settings })).entry
|
|
55
59
|
if (settings.dryRun) {
|
|
56
|
-
|
|
60
|
+
return
|
|
57
61
|
}
|
|
58
62
|
entry = (await sync({ entry, settings })).entry
|
|
59
63
|
|
|
@@ -61,7 +65,7 @@ export default async ({
|
|
|
61
65
|
if (newHash) {
|
|
62
66
|
await updateTemplateHashCache({ path: entry.path, hash: newHash })
|
|
63
67
|
}
|
|
64
|
-
}
|
|
68
|
+
})
|
|
65
69
|
|
|
66
70
|
return true
|
|
67
71
|
}
|