This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fix-maps.js
44 lines (40 loc) · 1.54 KB
/
fix-maps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// https://github.com/apollographql/apollo-client/issues/3699#issuecomment-676570540
/* eslint-disable */
const fs = require('fs');
const path = require('path');
async function* walk(dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) yield* walk(entry);
else if (d.isFile()) yield entry;
}
}
async function main() {
let counter = 0;
for await (const p of walk(path.resolve(path.join(__dirname, './node_modules/@apollo/client')))) {
counter++;
if (p.indexOf('.js.map') !== -1) {
const mappath = p;
const jspath = p.replace('.map', '');
// @TODO: Make these async for more perf.
const js = fs.readFileSync(jspath, {encoding:'utf8', flag:'r'});
const map = JSON.parse(fs.readFileSync(mappath, {encoding:'utf8', flag:'r'}));
// Add missing source content to the .map files.
map.sourcesContent = js;
fs.writeFileSync(mappath, JSON.stringify(map));
}
}
for await (const p of walk(path.resolve(path.join(__dirname, './node_modules/react-responsive/dist')))) {
counter++;
if (p.indexOf('.js.map') !== -1) {
const mappath = p;
// @TODO: Make these async for more perf.
let map = fs.readFileSync(mappath, {encoding:'utf8', flag:'r'});
// Fix inavlid import path.
map = map.replace('webpack:///dist/', './')
fs.writeFileSync(mappath, map);
}
}
console.log(`Updated ${parseInt(counter)} files`);
}
main();