| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c984158 commit 7a8a2d5
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,7 @@ const kLeadingProtocol = /^\w+:\/\//; | |||
| 39 | 39 | const kSourceMappingURLMagicComment = /\/[*/]#\s+sourceMappingURL=(?<sourceMappingURL>[^\s]+)/g; | |
| 40 | 40 | const kSourceURLMagicComment = /\/[*/]#\s+sourceURL=(?<sourceURL>[^\s]+)/g; | |
| 41 | 41 | ||
| 42 | + const { isAbsolute } = require('path'); | ||
| 42 | 43 | const { fileURLToPath, pathToFileURL, URL } = require('internal/url'); | |
| 43 | 44 | ||
| 44 | 45 | let SourceMap; | |
@@ -263,9 +264,13 @@ function sourceMapFromDataUrl(sourceURL, url) { | |||
| 263 | 264 | // If the sources are not absolute URLs after prepending of the "sourceRoot", | |
| 264 | 265 | // the sources are resolved relative to the SourceMap (like resolving script | |
| 265 | 266 | // src in a html document). | |
| 267 | + // If the sources are absolute paths, the sources are converted to absolute file URLs. | ||
| 266 | 268 | function sourcesToAbsolute(baseURL, data) { | |
| 267 | 269 | data.sources = data.sources.map((source) => { | |
| 268 | 270 | source = (data.sourceRoot || '') + source; | |
| 271 | + if (isAbsolute(source)) { | ||
| 272 | + return pathToFileURL(source).href; | ||
| 273 | + } | ||
| 269 | 274 | return new URL(source, baseURL).href; | |
| 270 | 275 | }); | |
| 271 | 276 | // The sources array is now resolved to absolute URLs, sourceRoot should | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + function foo(str: string) { | ||
| 2 | + return str; | ||
| 3 | + } | ||
| 4 | + | ||
| 5 | + foo('noop'); | ||
| 6 | + | ||
| 7 | + // To recreate (Windows only): | ||
| 8 | + // | ||
| 9 | + // const filePath = require.resolve('./test/fixtures/source-map/ts-node.ts'); | ||
| 10 | + // const compiled = require('ts-node').create({ transpileOnly: true }).compile(fs.readFileSync(filePath, 'utf8'), filePath); | ||
| 11 | + // fs.writeFileSync('test/fixtures/source-map/ts-node-win32.js', compiled); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -289,6 +289,30 @@ function nextdir() { | |||
| 289 | 289 | assert.match(output.stderr.toString(), /at functionC.*10:3/); | |
| 290 | 290 | } | |
| 291 | 291 | ||
| 292 | + // Properly converts Windows absolute paths to absolute URLs. | ||
| 293 | + // Refs: https://github.com/nodejs/node/issues/50523 | ||
| 294 | + // Refs: https://github.com/TypeStrong/ts-node/issues/1769 | ||
| 295 | + { | ||
| 296 | + const coverageDirectory = nextdir(); | ||
| 297 | + const output = spawnSync(process.execPath, [ | ||
| 298 | + require.resolve('../fixtures/source-map/ts-node-win32.js'), | ||
| 299 | + ], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } }); | ||
| 300 | + assert.strictEqual(output.status, 0); | ||
| 301 | + assert.strictEqual(output.stderr.toString(), ''); | ||
| 302 | + const sourceMap = getSourceMapFromCache( | ||
| 303 | + 'ts-node-win32.js', | ||
| 304 | + coverageDirectory | ||
| 305 | + ); | ||
| 306 | + // base64 JSON should have been decoded, the D: in the sources field should | ||
| 307 | + // have been taken as the drive letter on Windows, the scheme on POSIX. | ||
| 308 | + assert.strictEqual( | ||
| 309 | + sourceMap.data.sources[0], | ||
| 310 | + common.isWindows ? | ||
| 311 | + 'file:///D:/workspaces/node/test/fixtures/source-map/ts-node.ts' : | ||
| 312 | + 'd:/workspaces/node/test/fixtures/source-map/ts-node.ts' | ||
| 313 | + ); | ||
| 314 | + } | ||
| 315 | + | ||
| 292 | 316 | // Stores and applies source map associated with file that throws while | |
| 293 | 317 | // being required. | |
| 294 | 318 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments