-
Notifications
You must be signed in to change notification settings - Fork 27.8k
/
Copy pathpull-turbo-cache.js
66 lines (56 loc) · 1.5 KB
/
pull-turbo-cache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
// @ts-check
const { spawn } = require('child_process')
;(async function () {
const target = process.argv[process.argv.length - 1]
let turboResult = ''
await new Promise((resolve, reject) => {
const child = spawn(
'/bin/bash',
['-c', `pnpm turbo run cache-build-native --dry=json -- ${target}`],
{
stdio: 'pipe',
}
)
child.stdout.on('data', (data) => {
turboResult += data.toString()
})
child.on('exit', (code, signal) => {
if (code || signal) {
return reject(
new Error(`invalid exit code ${code} or signal ${signal}`)
)
}
resolve(0)
})
})
const turboData = JSON.parse(turboResult)
const task = turboData.tasks.find((t) => t.command !== '<NONEXISTENT>')
if (!task) {
console.warn(`Failed to find related turbo task`, turboResult)
return
}
// pull cache if it was available
if (task.cache.local || task.cache.remote) {
await new Promise((resolve, reject) => {
const child = spawn(
'/bin/bash',
['-c', `pnpm turbo run cache-build-native -- ${target}`],
{
stdio: 'inherit',
}
)
child.on('exit', (code, signal) => {
if (code || signal) {
return reject(
new Error(`invalid exit code ${code} or signal ${signal}`)
)
}
resolve(0)
})
})
} else {
console.warn(`No turbo cache was available, continuing...`)
console.warn(task)
}
})()