From 9ac3837f673cc45b279cd592ab3a765ab2b89ccb Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Sat, 15 Jun 2019 00:30:49 +0200 Subject: [PATCH] I don't know why this is needed but it fixes an npm issue if install fails node scripts/fix-package-lock.js might help --- scripts/fix-package-lock.js | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/fix-package-lock.js diff --git a/scripts/fix-package-lock.js b/scripts/fix-package-lock.js new file mode 100644 index 0000000..aa9d57c --- /dev/null +++ b/scripts/fix-package-lock.js @@ -0,0 +1,45 @@ +#!/usr/bin/env node + +// whatever npm does?! and for whatever this is needed.. +// https://github.com/aragon/aragon-cli/blob/master/packages/aragon-cli/scripts/fix-lockfile +// https://github.com/aragon/aragon-cli/blob/master/docs-internal/Dependencies.md#regenerate-the-lockfiles + +const fs = require('fs') + +function replaceAll(string, mapObject) { + const regex = new RegExp(Object.keys(mapObject).join('|'), 'gi') + let occurrences = 0 + const result = string.replace(regex, matched => { + occurrences++ + return mapObject[matched] + }) + console.log(`[fix-lockfile] Replaced ${occurrences} occurrences.`) + return result +} +async function fixLockfile(path, replacementMap) { + const originalJson = require(path) + const originalText = JSON.stringify(originalJson, null, 2) + const fixedText = replaceAll(originalText, replacementMap) + const fixedJson = JSON.parse(fixedText) + await fs.writeFileSync(path, JSON.stringify(fixedJson, null, 2)) +} +// + +const LOCKFILE_PATH = '../package-lock.json' + +const replacementMap = { + // + '"version": "github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c"': + '"version": "0.2.3"', + // + '"from": "github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c"': + '"resolved": "github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c"', + // + '"from": "async-eventemitter@github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c"': + '"resolved": "github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c"', + // + '"async-eventemitter": "async-eventemitter@github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c"': + '"async-eventemitter": "github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c"', +} + +fixLockfile(LOCKFILE_PATH, replacementMap)