Skip to content

Commit 0cd6a2e

Browse files
jawadsh123Lenz Weber
andauthored
fix: point sourceMappingURL to correct sourcemaps in build artifacts (#1459)
* pass fileName to transpileModule * fix sourcemaps Co-authored-by: Lenz Weber <lenz.weber@mayflower.de>
1 parent 487e0aa commit 0cd6a2e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

packages/toolkit/scripts/build.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ import rollup from 'rollup'
66
import path from 'path'
77
import fs from 'fs-extra'
88
import ts from 'typescript'
9-
import { RawSourceMap, SourceMapConsumer } from 'source-map'
9+
import type { RawSourceMap } from 'source-map'
1010
import merge from 'merge-source-map'
11-
import {
12-
Extractor,
13-
ExtractorConfig,
14-
ExtractorResult,
15-
} from '@microsoft/api-extractor'
11+
import type { ExtractorResult } from '@microsoft/api-extractor'
12+
import { Extractor, ExtractorConfig } from '@microsoft/api-extractor'
1613
import yargs from 'yargs/yargs'
1714

1815
import { extractInlineSourcemap, removeInlineSourceMap } from './sourcemap'
@@ -201,12 +198,14 @@ async function bundle(options: BuildOptions & EntryPointOptions) {
201198
const origin = chunk.text
202199
const sourcemap = extractInlineSourcemap(origin)
203200
const result = ts.transpileModule(removeInlineSourceMap(origin), {
201+
fileName: chunk.path.replace(/.js$/, '.ts'),
204202
compilerOptions: {
205203
sourceMap: true,
206204
module:
207205
format !== 'cjs' ? ts.ModuleKind.ES2015 : ts.ModuleKind.CommonJS,
208206
target: esVersion,
209207
},
208+
fileName: chunk.path
210209
})
211210

212211
const mergedSourcemap = merge(sourcemap, result.sourceMapText)
@@ -217,7 +216,11 @@ async function bundle(options: BuildOptions & EntryPointOptions) {
217216
const transformResult = await terser.minify(
218217
appendInlineSourceMap(code, mapping),
219218
{
220-
sourceMap: { content: 'inline', asObject: true } as any,
219+
sourceMap: {
220+
content: 'inline',
221+
asObject: true,
222+
url: path.basename(chunk.path) + '.map',
223+
} as any,
221224
output: {
222225
comments: false,
223226
},

0 commit comments

Comments
 (0)