Skip to content

Commit a3b6b91

Browse files
committed
Avoid using source-map-support/register
This was highly unperformant.
1 parent 06b3f6e commit a3b6b91

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

lib/assertions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function fail(message: string) {
99
}
1010

1111
export function assert(value: unknown, message: string): asserts value {
12-
if (value) {
12+
if (value != null) {
1313
return;
1414
}
1515

lib/diagnostics/diagnose.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import "source-map-support/register";
21
import fs from "fs/promises";
32
import path from "path";
43
import util from "util";
@@ -14,6 +13,7 @@ import {
1413
import { generateMessages } from "@cucumber/gherkin";
1514
import { IdGenerator, SourceMediaType } from "@cucumber/messages";
1615
import * as esbuild from "esbuild";
16+
import sourceMap from "source-map";
1717
import { assert, assertAndReturn } from "../assertions";
1818
import { createAstIdMap } from "../ast-helpers";
1919
import { ensureIsRelative } from "../helpers/paths";
@@ -138,7 +138,7 @@ export async function diagnose(configuration: {
138138
const esbuildResult = await esbuild.build({
139139
entryPoints: [inputFileName],
140140
bundle: true,
141-
sourcemap: true,
141+
sourcemap: "external",
142142
outfile: outputFileName,
143143
});
144144

@@ -167,12 +167,40 @@ export async function diagnose(configuration: {
167167
});
168168

169169
registry.finalize();
170+
171+
const consumer = await new sourceMap.SourceMapConsumer(
172+
(await fs.readFile(outputFileName + ".map")).toString()
173+
);
174+
175+
for (const stepDefinition of registry.stepDefinitions) {
176+
const originalPosition = position(stepDefinition);
177+
178+
const newPosition = consumer.originalPositionFor(originalPosition);
179+
180+
stepDefinition.position = {
181+
line: assertAndReturn(
182+
newPosition.line,
183+
"Expected to find a line number"
184+
),
185+
column: assertAndReturn(
186+
newPosition.column,
187+
"Expected to find a column number"
188+
),
189+
source: assertAndReturn(
190+
newPosition.source,
191+
"Expected to find a source"
192+
),
193+
};
194+
}
195+
196+
consumer.destroy();
170197
} finally {
171198
/**
172199
* Delete without regard for errors.
173200
*/
174201
await fs.rm(inputFileName).catch(() => true);
175202
await fs.rm(outputFileName).catch(() => true);
203+
await fs.rm(outputFileName + ".map").catch(() => true);
176204
}
177205

178206
const options = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"module-alias": "^2.2.2",
6767
"node-hook": "^1.0.0",
6868
"resolve-pkg": "^2.0.0",
69-
"source-map-support": "^0.5.21",
69+
"source-map": "^0.7.4",
7070
"uuid": "^8.3.2"
7171
},
7272
"devDependencies": {

0 commit comments

Comments
 (0)