Skip to content

Commit e70736d

Browse files
feat(core): Address resolveSourceMap PR comments
1. Added better debug logging around the `resolveSourceMap` hook invocation 2. Expanded the `resolveSourceMap` doc comment to include more detail and an example use case 3. Added `resolveSourceMap` documentation to `generate-documentation-table.ts` 4. Removed the feature-specific playground test previously added
1 parent b55feb0 commit e70736d

File tree

5 files changed

+42
-51
lines changed

5 files changed

+42
-51
lines changed

packages/bundler-plugin-core/src/debug-id-upload.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ export async function determineSourceMapPathFromBundle(
125125
const searchLocations: string[] = [];
126126

127127
if (resolveSourceMapHook) {
128+
logger.debug(`Calling sourcemaps.resolveSourceMap(${JSON.stringify(bundlePath)}, ${JSON.stringify(sourceMappingUrl)})`);
128129
const customPath = await resolveSourceMapHook(bundlePath, sourceMappingUrl);
130+
logger.debug(`resolveSourceMap hook returned: ${JSON.stringify(customPath)}`);
131+
129132
if (customPath) {
130133
searchLocations.push(customPath);
131134
}
@@ -166,7 +169,8 @@ export async function determineSourceMapPathFromBundle(
166169

167170
// This is just a debug message because it can be quite spammy for some frameworks
168171
logger.debug(
169-
`Could not determine source map path for bundle: \`${bundlePath}\`` +
172+
`Could not determine source map path for bundle \`${bundlePath}\`` +
173+
` with sourceMappingURL=${sourceMappingUrl === undefined ? "undefined" : `\`${sourceMappingUrl}\``}` +
170174
` - Did you turn on source map generation in your bundler?` +
171175
` (Attempted paths: ${searchLocations.map(e => `\`${e}\``).join(", ")})`
172176
);

packages/bundler-plugin-core/src/types.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,20 @@ export interface Options {
130130
* Hook to customize source map file resolution.
131131
*
132132
* The hook is called with the absolute path of the build artifact and the value of the `//# sourceMappingURL=`
133-
* comment, if present. The hook should then return an absolute path indicating where to find the artifact's
134-
* corresponding `.map` file. If no path is returned or the returned path doesn't exist, the standard source map
135-
* resolution process will be used.
133+
* comment, if present. The hook should then return an absolute path (or a promise that resolves to one) indicating
134+
* where to find the artifact's corresponding source map file. If no path is returned or the returned path doesn't
135+
* exist, the standard source map resolution process will be used.
136+
*
137+
* The standard process first tries to resolve based on the `//# sourceMappingURL=` value (it supports `file://`
138+
* urls and absolute/relative paths). If that path doesn't exist, it then looks for a file named
139+
* `${artifactName}.map` in the same directory as the artifact.
140+
*
141+
* Note: This is mostly helpful for complex builds with custom source map generation. For example, if you put source
142+
* maps into a separate directory and rewrite the `//# sourceMappingURL=` comment to something other than a relative
143+
* directory, sentry will be unable to locate the source maps for a given build artifact. This hook allows you to
144+
* implement the resolution process yourself.
145+
*
146+
* Use the `debug` option to print information about source map resolution.
136147
*/
137148
resolveSourceMap?: ResolveSourceMapHook;
138149

packages/dev-utils/src/generate-documentation-table.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ errorHandler: (err) => {
9696
fullDescription:
9797
"Hook to rewrite the `sources` field inside the source map before being uploaded to Sentry. Does not modify the actual source map. Effectively, this modifies how files inside the stacktrace will show up in Sentry.\n\nDefaults to making all sources relative to `process.cwd()` while building.",
9898
},
99+
{
100+
name: "resolveSourceMap",
101+
type: "(artifactPath: string, sourceMappingUrl: string | undefined) => string | undefined | Promise<string | undefined>",
102+
fullDescription: `Hook to customize source map file resolution.
103+
104+
The hook is called with the absolute path of the build artifact and the value of the \`//# sourceMappingURL=\`
105+
comment, if present. The hook should then return an absolute path (or a promise that resolves to one) indicating
106+
where to find the artifact's corresponding source map file. If no path is returned or the returned path doesn't
107+
exist, the standard source map resolution process will be used.
108+
109+
The standard process first tries to resolve based on the \`//# sourceMappingURL=\` value (it supports \`file://\`
110+
urls and absolute/relative paths). If that path doesn't exist, it then looks for a file named
111+
\`\${artifactName}.map\` in the same directory as the artifact.
112+
113+
Note: This is mostly helpful for complex builds with custom source map generation. For example, if you put source
114+
maps into a separate directory and rewrite the \`//# sourceMappingURL=\` comment to something other than a relative
115+
directory, sentry will be unable to locate the source maps for a given build artifact. This hook allows you to
116+
implement the resolution process yourself.
117+
118+
Use the \`debug\` option to print information about source map resolution.
119+
`,
120+
},
99121
{
100122
name: "filesToDeleteAfterUpload",
101123
type: "string | string[] | Promise<string | string[]>",

packages/playground/build-webpack-resolveSourceMap.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

packages/playground/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
"license": "MIT",
55
"private": true,
66
"scripts": {
7-
"build:playground": "run-p build:rollup build:vite build:webpack4 build:webpack5 build:webpackResolveSourceMap build:esbuild",
7+
"build:playground": "run-p build:rollup build:vite build:webpack4 build:webpack5 build:esbuild",
88
"build:rollup": "rollup --config rollup.config.mjs",
99
"build:vite": "vite build --config vite.config.js",
1010
"build:webpack4": "node build-webpack4.js",
1111
"build:webpack5": "node build-webpack5.js",
12-
"build:webpackResolveSourceMap": "node build-webpack-resolveSourceMap.js",
1312
"build:esbuild": "node build-esbuild.js",
1413
"build:smallNodeApp": "vite build --config vite.config.smallNodeApp.js",
1514
"clean": "run-s clean:build",

0 commit comments

Comments
 (0)