nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 53 lines 1.6 kB view raw
1#!/usr/bin/env node 2 3/* Usage: 4 * node fixup_bin.js <bin_dir> <modules_dir> [<bin_pkg_1>, <bin_pkg_2> ... ] 5 */ 6 7const fs = require("fs"); 8const path = require("path"); 9 10const derivationBinPath = process.argv[2]; 11const nodeModules = process.argv[3]; 12const packagesToPublishBin = process.argv.slice(4); 13 14function processPackage(name) { 15 console.log("fixup_bin: Processing ", name); 16 17 const packagePath = `${nodeModules}/${name}`; 18 const packageJsonPath = `${packagePath}/package.json`; 19 const packageJson = JSON.parse(fs.readFileSync(packageJsonPath)); 20 21 if (!packageJson.bin) { 22 console.log("fixup_bin: No binaries provided"); 23 return; 24 } 25 26 // There are two alternative syntaxes for `bin` 27 // a) just a plain string, in which case the name of the package is the name of the binary. 28 // b) an object, where key is the name of the eventual binary, and the value the path to that binary. 29 if (typeof packageJson.bin === "string") { 30 const binName = packageJson.bin; 31 packageJson.bin = {}; 32 packageJson.bin[packageJson.name] = binName; 33 } 34 35 // eslint-disable-next-line no-restricted-syntax, guard-for-in 36 for (const binName in packageJson.bin) { 37 const binPath = packageJson.bin[binName]; 38 const normalizedBinName = binName.replace("@", "").replace("/", "-"); 39 40 const targetPath = path.normalize(`${packagePath}/${binPath}`); 41 const createdPath = `${derivationBinPath}/${normalizedBinName}`; 42 43 console.log( 44 `fixup_bin: creating link ${createdPath} that points to ${targetPath}` 45 ); 46 47 fs.symlinkSync(targetPath, createdPath); 48 } 49} 50 51packagesToPublishBin.forEach(pkg => { 52 processPackage(pkg); 53});