-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pnpmfile.cjs
69 lines (58 loc) · 2.04 KB
/
.pnpmfile.cjs
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
67
68
69
// @ts-check
const fs = require('node:fs')
const path = require('node:path')
const process = require('node:process')
const active = require('./scripts/utils/getActive')
const logger = require('./scripts/utils/logger')
if (!active.includes('all')) {
const lockfileDir = path.resolve(__dirname, '.jiek-locks')
if (!fs.existsSync(lockfileDir)) fs.mkdirSync(lockfileDir)
const tempDir = path.resolve(lockfileDir, '.tmp')
if (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir)
const lockfile = active.length === 0
? path.resolve(lockfileDir, 'pnpm-lock.base.yaml')
: path.resolve(lockfileDir, `pnpm-lock.${active.join(',')}.yaml`)
const defaultLockFile = path.resolve(__dirname, 'pnpm-lock.yaml')
const defaultLockFileTemp = path.resolve(
tempDir,
`pnpm-lock.${Math.random().toString(36).substring(7)}.tmp.yaml`
)
fs.copyFileSync(defaultLockFile, defaultLockFileTemp)
// cache default lockfile
if (fs.existsSync(lockfile)) {
logger.log('Using lockfile:', lockfile)
fs.copyFileSync(lockfile, defaultLockFile)
}
process.on('exit', code => {
if (code === 0) {
// save lockfile to cache
logger.log('Saving lockfile:', lockfile)
fs.copyFileSync(defaultLockFile, lockfile)
}
// restore default lockfile
fs.copyFileSync(defaultLockFileTemp, defaultLockFile)
fs.unlinkSync(defaultLockFileTemp)
if (fs.readdirSync(tempDir).length === 0) {
fs.rmdirSync(tempDir)
}
})
process.on('SIGINT', () => {
process.exit(1)
})
}
module.exports = /** @type {import('./scripts/pnpmfile').Pnpmfile} */ ({
hooks: {
async readPackage(packageJson) {
if (active.includes('all')) return packageJson
let pkgActive = packageJson['.jiek']?.active ?? packageJson['.jiek.active']
if (!pkgActive) return packageJson
if (typeof pkgActive === 'string') pkgActive = [pkgActive]
const isActive = active.some(x => pkgActive.includes(x))
if (isActive) return packageJson
return {}
},
async afterAllResolved(resolveContext) {
return resolveContext
}
}
})