|
| 1 | +const process = require('process'); |
| 2 | +const fs = require('fs'); |
| 3 | + |
| 4 | +console.log('Copy `debugId` from packager source map to Hermes source map...'); |
| 5 | + |
| 6 | +const packagerSourceMapPath = process.argv[2]; |
| 7 | +const hermesSourceMapPath = process.argv[3]; |
| 8 | + |
| 9 | +if (!packagerSourceMapPath) { |
| 10 | + console.log('Please provide packager source map path (A path to copy `debugId` from).'); |
| 11 | + process.exit(0); |
| 12 | +} |
| 13 | +if (!hermesSourceMapPath) { |
| 14 | + console.log('Please provide Hermes source map path. ((A path to copy `debugId` to))'); |
| 15 | + process.exit(0); |
| 16 | +} |
| 17 | +if (!fs.existsSync(packagerSourceMapPath)) { |
| 18 | + console.log('Packager source map path (A path to copy `debugId` from).'); |
| 19 | + process.exit(0); |
| 20 | +} |
| 21 | +if (!fs.existsSync(hermesSourceMapPath)) { |
| 22 | + console.log('Hermes source map not found. ((A path to copy `debugId` to))'); |
| 23 | + process.exit(0); |
| 24 | +} |
| 25 | + |
| 26 | +const from = fs.readFileSync(process.argv[2], 'utf8'); |
| 27 | +const to = fs.readFileSync(process.argv[3], 'utf8'); |
| 28 | + |
| 29 | +const fromParsed = JSON.parse(from); |
| 30 | +const toParsed = JSON.parse(to); |
| 31 | + |
| 32 | +if (!fromParsed.debugId && !fromParsed.debug_id) { |
| 33 | + console.log('Packager source map does not have `debugId`.'); |
| 34 | + process.exit(0); |
| 35 | +} |
| 36 | + |
| 37 | +if (toParsed.debugId || toParsed.debug_id) { |
| 38 | + console.log('Hermes combined source map already has `debugId`.'); |
| 39 | + process.exit(0); |
| 40 | +} |
| 41 | + |
| 42 | +if (fromParsed.debugId) { |
| 43 | + toParsed.debugId = fromParsed.debugId; |
| 44 | + toParsed.debug_id = fromParsed.debugId; |
| 45 | +} else if (fromParsed.debug_id) { |
| 46 | + toParsed.debugId = fromParsed.debug_id; |
| 47 | + toParsed.debug_id = fromParsed.debug_id; |
| 48 | +} |
| 49 | + |
| 50 | +fs.writeFileSync(process.argv[3], JSON.stringify(toParsed)); |
| 51 | + |
| 52 | +console.log('Done.'); |
0 commit comments