1
- import "source-map-support/register" ;
2
1
import fs from "fs/promises" ;
3
2
import path from "path" ;
4
3
import util from "util" ;
@@ -14,6 +13,7 @@ import {
14
13
import { generateMessages } from "@cucumber/gherkin" ;
15
14
import { IdGenerator , SourceMediaType } from "@cucumber/messages" ;
16
15
import * as esbuild from "esbuild" ;
16
+ import sourceMap from "source-map" ;
17
17
import { assert , assertAndReturn } from "../assertions" ;
18
18
import { createAstIdMap } from "../ast-helpers" ;
19
19
import { ensureIsRelative } from "../helpers/paths" ;
@@ -138,7 +138,7 @@ export async function diagnose(configuration: {
138
138
const esbuildResult = await esbuild . build ( {
139
139
entryPoints : [ inputFileName ] ,
140
140
bundle : true ,
141
- sourcemap : true ,
141
+ sourcemap : "external" ,
142
142
outfile : outputFileName ,
143
143
} ) ;
144
144
@@ -167,12 +167,40 @@ export async function diagnose(configuration: {
167
167
} ) ;
168
168
169
169
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 ( ) ;
170
197
} finally {
171
198
/**
172
199
* Delete without regard for errors.
173
200
*/
174
201
await fs . rm ( inputFileName ) . catch ( ( ) => true ) ;
175
202
await fs . rm ( outputFileName ) . catch ( ( ) => true ) ;
203
+ await fs . rm ( outputFileName + ".map" ) . catch ( ( ) => true ) ;
176
204
}
177
205
178
206
const options = {
0 commit comments