Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"license": "Apache-2.0",
"dependencies": {
"node-gyp-build": "<4.0",
"p-limit": "^3.1.0",
"pprof-format": "^2.2.1",
"source-map": "^0.7.4"
},
Expand Down
23 changes: 21 additions & 2 deletions ts/src/sourcemapper/sourcemapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,30 @@ import * as fs from 'fs';
import * as path from 'path';
import * as sourceMap from 'source-map';
import {logger} from '../logger';
import pLimit from 'p-limit';

const readFile = fs.promises.readFile;

const CONCURRENCY = 10;

function createLimiter(concurrency: number) {
let active = 0;
const queue: Array<() => void> = [];
return function limit<T>(fn: () => Promise<T>): Promise<T> {
return new Promise<T>((resolve, reject) => {
const run = () => {
active++;
fn()
.then(resolve, reject)
.finally(() => {
active--;
if (queue.length > 0) queue.shift()!();
});
};
if (active < concurrency) run();
else queue.push(run);
});
};
}
const MAP_EXT = '.map';

function error(msg: string) {
Expand Down Expand Up @@ -306,7 +325,7 @@ async function createFromMapFiles(
mapFiles: string[],
debug: boolean,
): Promise<SourceMapper> {
const limit = pLimit(CONCURRENCY);
const limit = createLimiter(CONCURRENCY);
const mapper = new SourceMapper(debug);
const promises: Array<Promise<void>> = mapFiles.map(mapPath =>
limit(() => processSourceMap(mapper.infoMap, mapPath, debug)),
Expand Down