diff options
Diffstat (limited to 'nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js')
-rwxr-xr-x | nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js b/nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js new file mode 100755 index 000000000000..86e92f852087 --- /dev/null +++ b/nixpkgs/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js @@ -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, + ) + } + }) + }) |