nix: temporarily vendor yarn2nix

This commit is contained in:
Yureka
2021-09-15 21:03:56 +02:00
parent 049377ae8b
commit 5ab48849f7
15 changed files with 9183 additions and 5 deletions

View File

@ -0,0 +1,53 @@
#!/usr/bin/env node
/* Usage:
* node fixup_bin.js <bin_dir> <modules_dir> [<bin_pkg_1>, <bin_pkg_2> ... ]
*/
const fs = require('fs')
const path = require('path')
const derivationBinPath = process.argv[2]
const nodeModules = process.argv[3]
const packagesToPublishBin = process.argv.slice(4)
function processPackage(name) {
console.log('fixup_bin: Processing ', name)
const packagePath = `${nodeModules}/${name}`
const packageJsonPath = `${packagePath}/package.json`
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
if (!packageJson.bin) {
console.log('fixup_bin: No binaries provided')
return
}
// There are two alternative syntaxes for `bin`
// a) just a plain string, in which case the name of the package is the name of the binary.
// b) an object, where key is the name of the eventual binary, and the value the path to that binary.
if (typeof packageJson.bin === 'string') {
const binName = packageJson.bin
packageJson.bin = {}
packageJson.bin[packageJson.name] = binName
}
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const binName in packageJson.bin) {
const binPath = packageJson.bin[binName]
const normalizedBinName = binName.replace('@', '').replace('/', '-')
const targetPath = path.normalize(`${packagePath}/${binPath}`)
const createdPath = `${derivationBinPath}/${normalizedBinName}`
console.log(
`fixup_bin: creating link ${createdPath} that points to ${targetPath}`,
)
fs.symlinkSync(targetPath, createdPath)
}
}
packagesToPublishBin.forEach(pkg => {
processPackage(pkg)
})

View File

@ -0,0 +1,49 @@
#!/usr/bin/env node
/* Usage:
* node fixup_yarn_lock.js yarn.lock
*/
const fs = require('fs')
const readline = require('readline')
const urlToName = require('../lib/urlToName')
const yarnLockPath = process.argv[2]
const readFile = readline.createInterface({
input: fs.createReadStream(yarnLockPath, { encoding: 'utf8' }),
// Note: we use the crlfDelay option to recognize all instances of CR LF
// ('\r\n') in input.txt as a single line break.
crlfDelay: Infinity,
terminal: false, // input and output should be treated like a TTY
})
const result = []
readFile
.on('line', line => {
const arr = line.match(/^ {2}resolved "([^#]+)#([^"]+)"$/)
if (arr !== null) {
const [_, url, shaOrRev] = arr
const fileName = urlToName(url)
result.push(` resolved "${fileName}#${shaOrRev}"`)
} else {
result.push(line)
}
})
.on('close', () => {
fs.writeFile(yarnLockPath, result.join('\n'), 'utf8', err => {
if (err) {
console.error(
'fixup_yarn_lock: fatal error when trying to write to yarn.lock',
err,
)
}
})
})