@sentry/bundler-plugins 11.12.0 → 11.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
- package/build/cjs/_virtual/_rolldown/runtime.js +22 -0
- package/build/cjs/babel-plugin/component-annotation.js +14 -32
- package/build/cjs/babel-plugin/component-annotation.js.map +1 -1
- package/build/cjs/babel-plugin/constants.js +140 -122
- package/build/cjs/babel-plugin/constants.js.map +1 -1
- package/build/cjs/babel-plugin/experimental.js +204 -307
- package/build/cjs/babel-plugin/experimental.js.map +1 -1
- package/build/cjs/babel-plugin/index.js +315 -437
- package/build/cjs/babel-plugin/index.js.map +1 -1
- package/build/cjs/bun/index.js +81 -117
- package/build/cjs/bun/index.js.map +1 -1
- package/build/cjs/core/build-plugin-manager.js +626 -702
- package/build/cjs/core/build-plugin-manager.js.map +1 -1
- package/build/cjs/core/cli.js +134 -129
- package/build/cjs/core/cli.js.map +1 -1
- package/build/cjs/core/component-annotate-hooks.js +16 -27
- package/build/cjs/core/component-annotate-hooks.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-ast.js +10 -21
- package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-fragments.js +45 -74
- package/build/cjs/core/component-annotation-oxc-fragments.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-jsx.js +116 -156
- package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-walk.js +62 -123
- package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc.js +68 -103
- package/build/cjs/core/component-annotation-oxc.js.map +1 -1
- package/build/cjs/core/debug-id-upload.js +223 -234
- package/build/cjs/core/debug-id-upload.js.map +1 -1
- package/build/cjs/core/get-code-injection-position.js +59 -74
- package/build/cjs/core/get-code-injection-position.js.map +1 -1
- package/build/cjs/core/glob.js +9 -7
- package/build/cjs/core/glob.js.map +1 -1
- package/build/cjs/core/index.js +77 -61
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/logger.js +17 -26
- package/build/cjs/core/logger.js.map +1 -1
- package/build/cjs/core/options-mapping.js +95 -117
- package/build/cjs/core/options-mapping.js.map +1 -1
- package/build/cjs/core/sentry/telemetry.js +90 -105
- package/build/cjs/core/sentry/telemetry.js.map +1 -1
- package/build/cjs/core/sentry/transports.js +92 -99
- package/build/cjs/core/sentry/transports.js.map +1 -1
- package/build/cjs/core/sourcemap-settings.js +98 -61
- package/build/cjs/core/sourcemap-settings.js.map +1 -1
- package/build/cjs/core/upload-filter.js +41 -46
- package/build/cjs/core/upload-filter.js.map +1 -1
- package/build/cjs/core/utils.js +228 -219
- package/build/cjs/core/utils.js.map +1 -1
- package/build/cjs/core/version.js +4 -5
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/esbuild/index.js +180 -211
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/cjs/loader-utils/index.js +5 -10
- package/build/cjs/rollup/debug-id-injection.js +22 -38
- package/build/cjs/rollup/debug-id-injection.js.map +1 -1
- package/build/cjs/rollup/debug-id-stamping.js +14 -24
- package/build/cjs/rollup/debug-id-stamping.js.map +1 -1
- package/build/cjs/rollup/index.js +192 -246
- package/build/cjs/rollup/index.js.map +1 -1
- package/build/cjs/rollup/source-map-handling.js +151 -175
- package/build/cjs/rollup/source-map-handling.js.map +1 -1
- package/build/cjs/vite/index.js +19 -21
- package/build/cjs/vite/index.js.map +1 -1
- package/build/cjs/vite/source-map-hooks.js +112 -89
- package/build/cjs/vite/source-map-hooks.js.map +1 -1
- package/build/cjs/webpack/component-annotation-transform.js +20 -26
- package/build/cjs/webpack/component-annotation-transform.js.map +1 -1
- package/build/cjs/webpack/index.js +271 -340
- package/build/cjs/webpack/index.js.map +1 -1
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
- package/build/esm/_virtual/_rolldown/runtime.js +2 -0
- package/build/esm/babel-plugin/component-annotation.js +13 -29
- package/build/esm/babel-plugin/component-annotation.js.map +1 -1
- package/build/esm/babel-plugin/constants.js +140 -120
- package/build/esm/babel-plugin/constants.js.map +1 -1
- package/build/esm/babel-plugin/experimental.js +204 -305
- package/build/esm/babel-plugin/experimental.js.map +1 -1
- package/build/esm/babel-plugin/index.js +311 -434
- package/build/esm/babel-plugin/index.js.map +1 -1
- package/build/esm/bun/index.js +76 -101
- package/build/esm/bun/index.js.map +1 -1
- package/build/esm/core/build-plugin-manager.js +621 -683
- package/build/esm/core/build-plugin-manager.js.map +1 -1
- package/build/esm/core/cli.js +134 -127
- package/build/esm/core/cli.js.map +1 -1
- package/build/esm/core/component-annotate-hooks.js +16 -25
- package/build/esm/core/component-annotate-hooks.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-ast.js +9 -19
- package/build/esm/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-fragments.js +44 -72
- package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-jsx.js +115 -154
- package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-walk.js +61 -121
- package/build/esm/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/esm/core/component-annotation-oxc.js +65 -96
- package/build/esm/core/component-annotation-oxc.js.map +1 -1
- package/build/esm/core/debug-id-upload.js +218 -213
- package/build/esm/core/debug-id-upload.js.map +1 -1
- package/build/esm/core/get-code-injection-position.js +59 -72
- package/build/esm/core/get-code-injection-position.js.map +1 -1
- package/build/esm/core/glob.js +9 -5
- package/build/esm/core/glob.js.map +1 -1
- package/build/esm/core/index.js +62 -47
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/logger.js +17 -24
- package/build/esm/core/logger.js.map +1 -1
- package/build/esm/core/options-mapping.js +95 -115
- package/build/esm/core/options-mapping.js.map +1 -1
- package/build/esm/core/sentry/telemetry.js +89 -102
- package/build/esm/core/sentry/telemetry.js.map +1 -1
- package/build/esm/core/sentry/transports.js +90 -83
- package/build/esm/core/sentry/transports.js.map +1 -1
- package/build/esm/core/sourcemap-settings.js +96 -59
- package/build/esm/core/sourcemap-settings.js.map +1 -1
- package/build/esm/core/upload-filter.js +39 -30
- package/build/esm/core/upload-filter.js.map +1 -1
- package/build/esm/core/utils.js +221 -209
- package/build/esm/core/utils.js.map +1 -1
- package/build/esm/core/version.js +4 -3
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/esbuild/index.js +176 -195
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/loader-utils/index.js +4 -3
- package/build/esm/package.json +1 -1
- package/build/esm/rollup/debug-id-injection.js +22 -36
- package/build/esm/rollup/debug-id-injection.js.map +1 -1
- package/build/esm/rollup/debug-id-stamping.js +14 -22
- package/build/esm/rollup/debug-id-stamping.js.map +1 -1
- package/build/esm/rollup/index.js +189 -226
- package/build/esm/rollup/index.js.map +1 -1
- package/build/esm/rollup/source-map-handling.js +149 -159
- package/build/esm/rollup/source-map-handling.js.map +1 -1
- package/build/esm/vite/index.js +19 -18
- package/build/esm/vite/index.js.map +1 -1
- package/build/esm/vite/source-map-hooks.js +109 -72
- package/build/esm/vite/source-map-hooks.js.map +1 -1
- package/build/esm/webpack/component-annotation-transform.js +17 -24
- package/build/esm/webpack/component-annotation-transform.js.map +1 -1
- package/build/esm/webpack/index.js +268 -322
- package/build/esm/webpack/index.js.map +1 -1
- package/build/types/core/build-plugin-manager.d.ts +16 -5
- package/build/types/core/build-plugin-manager.d.ts.map +1 -1
- package/build/types/core/cli.d.ts +6 -1
- package/build/types/core/cli.d.ts.map +1 -1
- package/build/types/core/debug-id-upload.d.ts +7 -4
- package/build/types/core/debug-id-upload.d.ts.map +1 -1
- package/build/types/core/index.d.ts +3 -3
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/options-mapping.d.ts +4 -3
- package/build/types/core/options-mapping.d.ts.map +1 -1
- package/build/types/core/sentry/telemetry.d.ts.map +1 -1
- package/build/types/core/sourcemap-settings.d.ts +10 -1
- package/build/types/core/sourcemap-settings.d.ts.map +1 -1
- package/build/types/core/types.d.ts +25 -1
- package/build/types/core/types.d.ts.map +1 -1
- package/build/types/core/utils.d.ts +4 -0
- package/build/types/core/utils.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/esbuild/index.d.ts +2 -2
- package/build/types/esbuild/index.d.ts.map +1 -1
- package/build/types/rollup/index.d.ts +2 -2
- package/build/types/rollup/index.d.ts.map +1 -1
- package/build/types/rollup/source-map-handling.d.ts.map +1 -1
- package/build/types/vite/index.d.ts +3 -3
- package/build/types/vite/index.d.ts.map +1 -1
- package/build/types/vite/source-map-hooks.d.ts.map +1 -1
- package/build/types/webpack/index.d.ts +7 -3
- package/build/types/webpack/index.d.ts.map +1 -1
- package/package.json +8 -15
- package/build/cjs/loader-utils/index.js.map +0 -1
- package/build/esm/loader-utils/index.js.map +0 -1
|
@@ -1,244 +1,249 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as
|
|
5
|
-
import
|
|
6
|
-
|
|
1
|
+
import { stripQueryAndHashFromPath } from "./utils.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import * as url from "url";
|
|
5
|
+
import * as util from "util";
|
|
6
|
+
// src/core/debug-id-upload.ts
|
|
7
7
|
function createDebugIdUploadFunction({ sentryBuildPluginManager }) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
return async (buildArtifactPaths, opts) => {
|
|
9
|
+
const cleanedPaths = buildArtifactPaths.map(stripQueryAndHashFromPath);
|
|
10
|
+
return sentryBuildPluginManager.uploadSourcemaps(cleanedPaths, opts);
|
|
11
|
+
};
|
|
12
12
|
}
|
|
13
|
+
/** Resolves to `undefined` when the bundle was skipped. */
|
|
13
14
|
async function prepareBundleForDebugIdUpload(bundleFilePath, uploadFolder, chunkIndex, logger, rewriteSourcesHook, resolveSourceMapHook) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
rewriteSourcesHook
|
|
47
|
-
});
|
|
48
|
-
if (!result.ok) {
|
|
49
|
-
if (result.reason === "invalid-source-map") {
|
|
50
|
-
logger.error(`Failed to parse source map for debug ID upload: ${sourceMapPath}`);
|
|
51
|
-
} else {
|
|
52
|
-
logger.debug(`Not uploading bundle without a source map: ${bundleFilePath}`);
|
|
53
|
-
}
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
await writePreparedArtifact(uploadFolder, `${result.artifact.debugId}-${chunkIndex}`, result.artifact);
|
|
15
|
+
let bundleContent;
|
|
16
|
+
try {
|
|
17
|
+
bundleContent = await fs.promises.readFile(bundleFilePath, "utf8");
|
|
18
|
+
} catch (e) {
|
|
19
|
+
logger.error(`Could not read bundle to determine debug ID and source map: ${bundleFilePath}`, e);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (determineDebugIdFromBundleSource(bundleContent) === void 0) {
|
|
23
|
+
logger.debug(`Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: ${bundleFilePath}`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const sourceMapPath = await determineSourceMapPathFromBundle(bundleFilePath, bundleContent, logger, resolveSourceMapHook);
|
|
27
|
+
let sourceMapSource;
|
|
28
|
+
if (sourceMapPath) try {
|
|
29
|
+
sourceMapSource = await fs.promises.readFile(sourceMapPath, "utf8");
|
|
30
|
+
} catch (e) {
|
|
31
|
+
logger.error(`Failed to read source map for debug ID upload: ${sourceMapPath}`, e);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const result = prepareArtifactForUpload({
|
|
35
|
+
code: bundleContent,
|
|
36
|
+
mapSource: sourceMapSource,
|
|
37
|
+
mapDir: path.dirname(sourceMapPath ?? bundleFilePath),
|
|
38
|
+
rewriteSourcesHook
|
|
39
|
+
});
|
|
40
|
+
if (!result.ok) {
|
|
41
|
+
if (result.reason === "invalid-source-map") logger.error(`Failed to parse source map for debug ID upload: ${sourceMapPath}`);
|
|
42
|
+
else logger.debug(`Not uploading bundle without a source map: ${bundleFilePath}`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
await writePreparedArtifact(uploadFolder, `${result.artifact.debugId}-${chunkIndex}`, result.artifact);
|
|
46
|
+
return { sourceMapPath };
|
|
57
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Prepares a bundle and its source map for the debug ID upload: stamps the debug ID into both
|
|
50
|
+
* and runs the `rewriteSources` hook over the map's `sources`.
|
|
51
|
+
*
|
|
52
|
+
* Pass `mapSource: undefined` when the bundle has no separate source map. A bundle with an
|
|
53
|
+
* inlined map is still prepared; a bundle without any map is skipped because it cannot be
|
|
54
|
+
* symbolicated.
|
|
55
|
+
*/
|
|
58
56
|
function prepareArtifactForUpload(input) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
57
|
+
const debugId = determineDebugIdFromBundleSource(input.code);
|
|
58
|
+
if (debugId === void 0) return {
|
|
59
|
+
ok: false,
|
|
60
|
+
reason: "no-debug-id"
|
|
61
|
+
};
|
|
62
|
+
const bundleSource = addDebugIdToBundleSource(input.code, debugId);
|
|
63
|
+
if (input.mapSource === void 0) {
|
|
64
|
+
if (!bundleHasInlineSourceMap(input.code)) return {
|
|
65
|
+
ok: false,
|
|
66
|
+
reason: "no-source-map"
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
artifact: {
|
|
71
|
+
debugId,
|
|
72
|
+
bundleSource,
|
|
73
|
+
sourceMapSource: void 0
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const map = parseSourceMap(input.mapSource);
|
|
78
|
+
if (!map) return {
|
|
79
|
+
ok: false,
|
|
80
|
+
reason: "invalid-source-map"
|
|
81
|
+
};
|
|
82
|
+
setDebugIdOnSourceMap(map, debugId);
|
|
83
|
+
if (Array.isArray(map["sources"])) map["sources"] = map["sources"].map((source) => input.rewriteSourcesHook(source, map, { mapDir: input.mapDir }));
|
|
84
|
+
return {
|
|
85
|
+
ok: true,
|
|
86
|
+
artifact: {
|
|
87
|
+
debugId,
|
|
88
|
+
bundleSource,
|
|
89
|
+
sourceMapSource: JSON.stringify(map)
|
|
90
|
+
}
|
|
91
|
+
};
|
|
81
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Writes a prepared artifact as `<uniqueUploadName>.js` (and `.js.map`) into the upload folder.
|
|
95
|
+
*/
|
|
82
96
|
async function writePreparedArtifact(uploadFolder, uniqueUploadName, artifact) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (artifact.sourceMapSource !== void 0) {
|
|
87
|
-
writes.push(
|
|
88
|
-
fs__default.promises.writeFile(path__default.join(uploadFolder, `${uniqueUploadName}.js.map`), artifact.sourceMapSource, "utf-8")
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
await Promise.all(writes);
|
|
97
|
+
const writes = [fs.promises.writeFile(path.join(uploadFolder, `${uniqueUploadName}.js`), artifact.bundleSource, "utf-8")];
|
|
98
|
+
if (artifact.sourceMapSource !== void 0) writes.push(fs.promises.writeFile(path.join(uploadFolder, `${uniqueUploadName}.js.map`), artifact.sourceMapSource, "utf-8"));
|
|
99
|
+
await Promise.all(writes);
|
|
92
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle
|
|
103
|
+
* source and extracts the bundle's debug ID from it.
|
|
104
|
+
*
|
|
105
|
+
* The string pattern is injected via the debug ID injection snipped.
|
|
106
|
+
*/
|
|
93
107
|
function determineDebugIdFromBundleSource(code) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (match) {
|
|
98
|
-
return match[1];
|
|
99
|
-
} else {
|
|
100
|
-
return void 0;
|
|
101
|
-
}
|
|
108
|
+
const match = code.match(/sentry-dbid-([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/);
|
|
109
|
+
if (match) return match[1];
|
|
110
|
+
else return;
|
|
102
111
|
}
|
|
103
112
|
const SPEC_LAST_DEBUG_ID_REGEX = /\/\/# debugId=([a-fA-F0-9-]+)(?![\s\S]*\/\/# debugId=)/m;
|
|
104
113
|
function hasSpecCompliantDebugId(bundleSource) {
|
|
105
|
-
|
|
114
|
+
return SPEC_LAST_DEBUG_ID_REGEX.test(bundleSource);
|
|
106
115
|
}
|
|
107
116
|
function addDebugIdToBundleSource(bundleSource, debugId) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
} else {
|
|
111
|
-
return `${bundleSource}
|
|
112
|
-
//# debugId=${debugId}`;
|
|
113
|
-
}
|
|
117
|
+
if (hasSpecCompliantDebugId(bundleSource)) return bundleSource.replace(SPEC_LAST_DEBUG_ID_REGEX, `//# debugId=${debugId}`);
|
|
118
|
+
else return `${bundleSource}\n//# debugId=${debugId}`;
|
|
114
119
|
}
|
|
115
120
|
function setDebugIdOnSourceMap(map, debugId) {
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
map["debug_id"] = debugId;
|
|
122
|
+
map["debugId"] = debugId;
|
|
118
123
|
}
|
|
119
124
|
function parseSourceMap(sourceMapSource) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
let map;
|
|
126
|
+
try {
|
|
127
|
+
map = JSON.parse(sourceMapSource);
|
|
128
|
+
} catch {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
return map && typeof map === "object" ? map : void 0;
|
|
127
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Stamps the debug ID injected into `bundleSource` into the bundle (as `//# debugId=` comment) and its
|
|
135
|
+
* source map (as `debug_id`/`debugId` fields).
|
|
136
|
+
*
|
|
137
|
+
* This exists for `sourcemaps.disable: "disable-upload"`: the regular upload path only stamps
|
|
138
|
+
* temporary copies of the artifacts (see `prepareBundleForDebugIdUpload`), so without this the
|
|
139
|
+
* emitted artifacts would carry no debug ID and a later manual upload could not match them.
|
|
140
|
+
* Callers must apply the result inside the bundler's asset pipeline (or, for bundlers without one,
|
|
141
|
+
* before the build resolves) so that integrity hashes computed by later build steps include it.
|
|
142
|
+
*
|
|
143
|
+
* Pass `sourceMapSource: undefined` when the bundle has no separate source map. A bundle with an
|
|
144
|
+
* inlined map still gets the comment, which is all the CLI and Symbolicator read the debug ID from.
|
|
145
|
+
*
|
|
146
|
+
* @returns the stamped artifacts, or `undefined` for bundles without a debug ID, without any source
|
|
147
|
+
* map, or with an unparseable map.
|
|
148
|
+
*/
|
|
128
149
|
function stampDebugId(bundleSource, sourceMapSource) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
bundleSource: addDebugIdToBundleSource(bundleSource, debugId),
|
|
146
|
-
sourceMapSource: JSON.stringify(map)
|
|
147
|
-
};
|
|
150
|
+
const debugId = determineDebugIdFromBundleSource(bundleSource);
|
|
151
|
+
if (debugId === void 0) return;
|
|
152
|
+
if (sourceMapSource === void 0) {
|
|
153
|
+
if (!bundleHasInlineSourceMap(bundleSource)) return;
|
|
154
|
+
return {
|
|
155
|
+
bundleSource: addDebugIdToBundleSource(bundleSource, debugId),
|
|
156
|
+
sourceMapSource: void 0
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const map = parseSourceMap(sourceMapSource);
|
|
160
|
+
if (!map) return;
|
|
161
|
+
setDebugIdOnSourceMap(map, debugId);
|
|
162
|
+
return {
|
|
163
|
+
bundleSource: addDebugIdToBundleSource(bundleSource, debugId),
|
|
164
|
+
sourceMapSource: JSON.stringify(map)
|
|
165
|
+
};
|
|
148
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Stamps the debug ID of an emitted bundle into the bundle and its source map on disk.
|
|
169
|
+
*
|
|
170
|
+
* Used by bundlers that offer no hook to modify assets before they are written (esbuild).
|
|
171
|
+
*/
|
|
149
172
|
async function addDebugIdToEmittedArtifacts(bundleFilePath, logger, resolveSourceMapHook) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const writes = [fs__default.promises.writeFile(bundleFilePath, stamped.bundleSource, "utf8")];
|
|
180
|
-
if (sourceMapPath && stamped.sourceMapSource !== void 0) {
|
|
181
|
-
writes.push(fs__default.promises.writeFile(sourceMapPath, stamped.sourceMapSource, "utf8"));
|
|
182
|
-
}
|
|
183
|
-
try {
|
|
184
|
-
await Promise.all(writes);
|
|
185
|
-
} catch (e) {
|
|
186
|
-
logger.error(`Could not write debug ID into build artifacts: ${bundleFilePath}`, e);
|
|
187
|
-
}
|
|
173
|
+
let bundleSource;
|
|
174
|
+
try {
|
|
175
|
+
bundleSource = await fs.promises.readFile(bundleFilePath, "utf8");
|
|
176
|
+
} catch (e) {
|
|
177
|
+
logger.error(`Could not read bundle to stamp debug ID: ${bundleFilePath}`, e);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const sourceMapPath = await determineSourceMapPathFromBundle(bundleFilePath, bundleSource, logger, resolveSourceMapHook);
|
|
181
|
+
let sourceMapSource;
|
|
182
|
+
if (sourceMapPath) try {
|
|
183
|
+
sourceMapSource = await fs.promises.readFile(sourceMapPath, "utf8");
|
|
184
|
+
} catch (e) {
|
|
185
|
+
logger.error(`Could not read source map to stamp debug ID: ${sourceMapPath}`, e);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const stamped = stampDebugId(bundleSource, sourceMapSource);
|
|
189
|
+
if (!stamped) {
|
|
190
|
+
logger.debug(`Could not stamp debug ID (no debug ID in bundle, no source map, or invalid source map): ${bundleFilePath}`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const writes = [fs.promises.writeFile(bundleFilePath, stamped.bundleSource, "utf8")];
|
|
194
|
+
if (sourceMapPath && stamped.sourceMapSource !== void 0) writes.push(fs.promises.writeFile(sourceMapPath, stamped.sourceMapSource, "utf8"));
|
|
195
|
+
try {
|
|
196
|
+
await Promise.all(writes);
|
|
197
|
+
} catch (e) {
|
|
198
|
+
logger.error(`Could not write debug ID into build artifacts: ${bundleFilePath}`, e);
|
|
199
|
+
}
|
|
188
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Whether the bundle carries its source map inlined as `sourceMappingURL=data:`
|
|
203
|
+
* URI, rather than referencing a separate `.map` file. Such bundles must still
|
|
204
|
+
* be uploaded even when no `.map` file is found, because the source file itself
|
|
205
|
+
* contains the map.
|
|
206
|
+
*/
|
|
189
207
|
function bundleHasInlineSourceMap(bundleSource) {
|
|
190
|
-
|
|
208
|
+
return /^\s*\/\/# sourceMappingURL=data:/m.test(bundleSource);
|
|
191
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Applies a set of heuristics to find the source map for a particular bundle.
|
|
212
|
+
*
|
|
213
|
+
* @returns the path to the bundle's source map or `undefined` if none could be found.
|
|
214
|
+
*/
|
|
192
215
|
async function determineSourceMapPathFromBundle(bundlePath, bundleSource, logger, resolveSourceMapHook) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
searchLocations.push(`${bundlePath}.map`);
|
|
221
|
-
for (const searchLocation of searchLocations) {
|
|
222
|
-
try {
|
|
223
|
-
await util.promisify(fs__default.access)(searchLocation);
|
|
224
|
-
logger.debug(`Source map found for bundle \`${bundlePath}\`: \`${searchLocation}\``);
|
|
225
|
-
return searchLocation;
|
|
226
|
-
} catch {
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
logger.debug(
|
|
230
|
-
`Could not determine source map path for bundle \`${bundlePath}\` with sourceMappingURL=${sourceMappingUrl === void 0 ? "undefined" : `\`${sourceMappingUrl}\``} - Did you turn on source map generation in your bundler? (Attempted paths: ${searchLocations.map((e) => `\`${e}\``).join(", ")})`
|
|
231
|
-
);
|
|
232
|
-
return void 0;
|
|
216
|
+
const sourceMappingUrlMatch = bundleSource.match(/^\s*\/\/# sourceMappingURL=(.*)$/m);
|
|
217
|
+
const sourceMappingUrl = sourceMappingUrlMatch ? sourceMappingUrlMatch[1] : void 0;
|
|
218
|
+
const searchLocations = [];
|
|
219
|
+
if (resolveSourceMapHook) {
|
|
220
|
+
logger.debug(`Calling sourcemaps.resolveSourceMap(${JSON.stringify(bundlePath)}, ${JSON.stringify(sourceMappingUrl)})`);
|
|
221
|
+
const customPath = await resolveSourceMapHook(bundlePath, sourceMappingUrl);
|
|
222
|
+
logger.debug(`resolveSourceMap hook returned: ${JSON.stringify(customPath)}`);
|
|
223
|
+
if (customPath) searchLocations.push(customPath);
|
|
224
|
+
}
|
|
225
|
+
if (sourceMappingUrl) {
|
|
226
|
+
let parsedUrl;
|
|
227
|
+
try {
|
|
228
|
+
parsedUrl = new URL(sourceMappingUrl);
|
|
229
|
+
} catch {}
|
|
230
|
+
if (parsedUrl?.protocol === "file:") searchLocations.push(url.fileURLToPath(sourceMappingUrl));
|
|
231
|
+
else if (parsedUrl) {} else if (path.isAbsolute(sourceMappingUrl)) searchLocations.push(path.normalize(sourceMappingUrl));
|
|
232
|
+
else searchLocations.push(path.normalize(path.join(path.dirname(bundlePath), sourceMappingUrl)));
|
|
233
|
+
}
|
|
234
|
+
searchLocations.push(`${bundlePath}.map`);
|
|
235
|
+
for (const searchLocation of searchLocations) try {
|
|
236
|
+
await util.promisify(fs.access)(searchLocation);
|
|
237
|
+
logger.debug(`Source map found for bundle \`${bundlePath}\`: \`${searchLocation}\``);
|
|
238
|
+
return searchLocation;
|
|
239
|
+
} catch {}
|
|
240
|
+
logger.debug(`Could not determine source map path for bundle \`${bundlePath}\` with sourceMappingURL=${sourceMappingUrl === void 0 ? "undefined" : `\`${sourceMappingUrl}\``} - Did you turn on source map generation in your bundler? (Attempted paths: ${searchLocations.map((e) => `\`${e}\``).join(", ")})`);
|
|
233
241
|
}
|
|
234
242
|
const PROTOCOL_REGEX = /^[a-zA-Z][a-zA-Z0-9+\-.]*:\/\//;
|
|
235
243
|
function defaultRewriteSourcesHook(source) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
} else {
|
|
239
|
-
return path__default.relative(process.cwd(), path__default.normalize(source));
|
|
240
|
-
}
|
|
244
|
+
if (source.match(PROTOCOL_REGEX)) return source.replace(PROTOCOL_REGEX, "");
|
|
245
|
+
else return path.relative(process.cwd(), path.normalize(source));
|
|
241
246
|
}
|
|
242
|
-
|
|
243
247
|
export { addDebugIdToEmittedArtifacts, createDebugIdUploadFunction, defaultRewriteSourcesHook, determineSourceMapPathFromBundle, prepareArtifactForUpload, prepareBundleForDebugIdUpload, stampDebugId, writePreparedArtifact };
|
|
244
|
-
|
|
248
|
+
|
|
249
|
+
//# sourceMappingURL=debug-id-upload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug-id-upload.js","sources":["../../../src/core/debug-id-upload.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport * as url from 'url';\nimport * as util from 'util';\nimport type { SentryBuildPluginManager, UploadStaging } from './build-plugin-manager';\nimport type { Logger } from './logger';\nimport type { ResolveSourceMapHook, RewriteSourcesHook } from './types';\nimport { stripQueryAndHashFromPath } from './utils';\n\ninterface DebugIdUploadPluginOptions {\n sentryBuildPluginManager: SentryBuildPluginManager;\n}\n\nexport function createDebugIdUploadFunction({ sentryBuildPluginManager }: DebugIdUploadPluginOptions) {\n return async (buildArtifactPaths: string[], opts?: { staging?: UploadStaging }) => {\n // Webpack and perhaps other bundlers allow you to append query strings to\n // filenames for cache busting purposes. We should strip these before upload.\n const cleanedPaths = buildArtifactPaths.map(stripQueryAndHashFromPath);\n return sentryBuildPluginManager.uploadSourcemaps(cleanedPaths, opts);\n };\n}\n\nexport async function prepareBundleForDebugIdUpload(\n bundleFilePath: string,\n uploadFolder: string,\n chunkIndex: number,\n logger: Logger,\n rewriteSourcesHook: RewriteSourcesHook,\n resolveSourceMapHook: ResolveSourceMapHook | undefined,\n): Promise<void> {\n let bundleContent: string;\n try {\n bundleContent = await fs.promises.readFile(bundleFilePath, 'utf8');\n } catch (e) {\n logger.error(`Could not read bundle to determine debug ID and source map: ${bundleFilePath}`, e);\n return;\n }\n\n if (determineDebugIdFromBundleSource(bundleContent) === undefined) {\n logger.debug(\n `Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: ${bundleFilePath}`,\n );\n return;\n }\n\n const sourceMapPath = await determineSourceMapPathFromBundle(\n bundleFilePath,\n bundleContent,\n logger,\n resolveSourceMapHook,\n );\n\n let sourceMapSource: string | undefined;\n if (sourceMapPath) {\n try {\n sourceMapSource = await fs.promises.readFile(sourceMapPath, 'utf8');\n } catch (e) {\n logger.error(`Failed to read source map for debug ID upload: ${sourceMapPath}`, e);\n return;\n }\n }\n\n const result = prepareArtifactForUpload({\n code: bundleContent,\n mapSource: sourceMapSource,\n mapDir: path.dirname(sourceMapPath ?? bundleFilePath),\n rewriteSourcesHook,\n });\n\n if (!result.ok) {\n if (result.reason === 'invalid-source-map') {\n logger.error(`Failed to parse source map for debug ID upload: ${sourceMapPath}`);\n } else {\n // A chunk with a debug ID but no resolvable source map\n // (e.g. framework-generated stub chunks that never emit one) can't be\n // symbolicated, so uploading its minified source alone accomplishes\n // nothing and only makes the uploader warn about a missing source map ref.\n logger.debug(`Not uploading bundle without a source map: ${bundleFilePath}`);\n }\n return;\n }\n\n await writePreparedArtifact(uploadFolder, `${result.artifact.debugId}-${chunkIndex}`, result.artifact);\n}\n\nexport type PreparedUploadArtifact = {\n debugId: string;\n bundleSource: string;\n /** `undefined` when the bundle has no separate source map (i.e. the map is inlined). */\n sourceMapSource: string | undefined;\n};\n\nexport type PrepareArtifactResult =\n | { ok: true; artifact: PreparedUploadArtifact }\n | { ok: false; reason: 'no-debug-id' | 'no-source-map' | 'invalid-source-map' };\n\n/**\n * Prepares a bundle and its source map for the debug ID upload: stamps the debug ID into both\n * and runs the `rewriteSources` hook over the map's `sources`.\n *\n * Pass `mapSource: undefined` when the bundle has no separate source map. A bundle with an\n * inlined map is still prepared; a bundle without any map is skipped because it cannot be\n * symbolicated.\n */\nexport function prepareArtifactForUpload(input: {\n code: string;\n mapSource: string | undefined;\n /** Directory the source map lives in, passed to the `rewriteSources` hook. */\n mapDir: string;\n rewriteSourcesHook: RewriteSourcesHook;\n}): PrepareArtifactResult {\n const debugId = determineDebugIdFromBundleSource(input.code);\n if (debugId === undefined) {\n return { ok: false, reason: 'no-debug-id' };\n }\n\n const bundleSource = addDebugIdToBundleSource(input.code, debugId);\n\n if (input.mapSource === undefined) {\n if (!bundleHasInlineSourceMap(input.code)) {\n return { ok: false, reason: 'no-source-map' };\n }\n return { ok: true, artifact: { debugId, bundleSource, sourceMapSource: undefined } };\n }\n\n const map = parseSourceMap(input.mapSource);\n if (!map) {\n return { ok: false, reason: 'invalid-source-map' };\n }\n\n setDebugIdOnSourceMap(map, debugId);\n\n if (Array.isArray(map['sources'])) {\n map['sources'] = map['sources'].map((source: string) =>\n input.rewriteSourcesHook(source, map, { mapDir: input.mapDir }),\n );\n }\n\n return { ok: true, artifact: { debugId, bundleSource, sourceMapSource: JSON.stringify(map) } };\n}\n\n/**\n * Writes a prepared artifact as `<uniqueUploadName>.js` (and `.js.map`) into the upload folder.\n */\nexport async function writePreparedArtifact(\n uploadFolder: string,\n uniqueUploadName: string,\n artifact: PreparedUploadArtifact,\n): Promise<void> {\n const writes = [\n fs.promises.writeFile(path.join(uploadFolder, `${uniqueUploadName}.js`), artifact.bundleSource, 'utf-8'),\n ];\n\n if (artifact.sourceMapSource !== undefined) {\n writes.push(\n fs.promises.writeFile(path.join(uploadFolder, `${uniqueUploadName}.js.map`), artifact.sourceMapSource, 'utf-8'),\n );\n }\n\n await Promise.all(writes);\n}\n\n/**\n * Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle\n * source and extracts the bundle's debug ID from it.\n *\n * The string pattern is injected via the debug ID injection snipped.\n */\nfunction determineDebugIdFromBundleSource(code: string): string | undefined {\n const match = code.match(\n /sentry-dbid-([0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12})/,\n );\n\n if (match) {\n return match[1];\n } else {\n return undefined;\n }\n}\n\nconst SPEC_LAST_DEBUG_ID_REGEX = /\\/\\/# debugId=([a-fA-F0-9-]+)(?![\\s\\S]*\\/\\/# debugId=)/m;\n\nfunction hasSpecCompliantDebugId(bundleSource: string): boolean {\n return SPEC_LAST_DEBUG_ID_REGEX.test(bundleSource);\n}\n\nfunction addDebugIdToBundleSource(bundleSource: string, debugId: string): string {\n if (hasSpecCompliantDebugId(bundleSource)) {\n return bundleSource.replace(SPEC_LAST_DEBUG_ID_REGEX, `//# debugId=${debugId}`);\n } else {\n return `${bundleSource}\\n//# debugId=${debugId}`;\n }\n}\n\nfunction setDebugIdOnSourceMap(map: Record<string, unknown>, debugId: string): void {\n // For now we write both fields until we know what will become the standard - if ever.\n map['debug_id'] = debugId;\n map['debugId'] = debugId;\n}\n\nexport type StampedArtifacts = {\n bundleSource: string;\n /** `undefined` when the bundle has no separate source map (i.e. the map is inlined). */\n sourceMapSource: string | undefined;\n};\n\nfunction parseSourceMap(sourceMapSource: string): Record<string, unknown> | undefined {\n let map: unknown;\n try {\n map = JSON.parse(sourceMapSource);\n } catch {\n return undefined;\n }\n\n return map && typeof map === 'object' ? (map as Record<string, unknown>) : undefined;\n}\n\n/**\n * Stamps the debug ID injected into `bundleSource` into the bundle (as `//# debugId=` comment) and its\n * source map (as `debug_id`/`debugId` fields).\n *\n * This exists for `sourcemaps.disable: \"disable-upload\"`: the regular upload path only stamps\n * temporary copies of the artifacts (see `prepareBundleForDebugIdUpload`), so without this the\n * emitted artifacts would carry no debug ID and a later manual upload could not match them.\n * Callers must apply the result inside the bundler's asset pipeline (or, for bundlers without one,\n * before the build resolves) so that integrity hashes computed by later build steps include it.\n *\n * Pass `sourceMapSource: undefined` when the bundle has no separate source map. A bundle with an\n * inlined map still gets the comment, which is all the CLI and Symbolicator read the debug ID from.\n *\n * @returns the stamped artifacts, or `undefined` for bundles without a debug ID, without any source\n * map, or with an unparseable map.\n */\nexport function stampDebugId(bundleSource: string, sourceMapSource: string | undefined): StampedArtifacts | undefined {\n const debugId = determineDebugIdFromBundleSource(bundleSource);\n if (debugId === undefined) {\n return undefined;\n }\n\n if (sourceMapSource === undefined) {\n if (!bundleHasInlineSourceMap(bundleSource)) {\n return undefined;\n }\n\n return { bundleSource: addDebugIdToBundleSource(bundleSource, debugId), sourceMapSource: undefined };\n }\n\n const map = parseSourceMap(sourceMapSource);\n if (!map) {\n return undefined;\n }\n\n setDebugIdOnSourceMap(map, debugId);\n\n return {\n bundleSource: addDebugIdToBundleSource(bundleSource, debugId),\n sourceMapSource: JSON.stringify(map),\n };\n}\n\n/**\n * Stamps the debug ID of an emitted bundle into the bundle and its source map on disk.\n *\n * Used by bundlers that offer no hook to modify assets before they are written (esbuild).\n */\nexport async function addDebugIdToEmittedArtifacts(\n bundleFilePath: string,\n logger: Logger,\n resolveSourceMapHook: ResolveSourceMapHook | undefined,\n): Promise<void> {\n let bundleSource: string;\n try {\n bundleSource = await fs.promises.readFile(bundleFilePath, 'utf8');\n } catch (e) {\n logger.error(`Could not read bundle to stamp debug ID: ${bundleFilePath}`, e);\n return;\n }\n\n const sourceMapPath = await determineSourceMapPathFromBundle(\n bundleFilePath,\n bundleSource,\n logger,\n resolveSourceMapHook,\n );\n\n let sourceMapSource: string | undefined;\n if (sourceMapPath) {\n try {\n sourceMapSource = await fs.promises.readFile(sourceMapPath, 'utf8');\n } catch (e) {\n logger.error(`Could not read source map to stamp debug ID: ${sourceMapPath}`, e);\n return;\n }\n }\n\n const stamped = stampDebugId(bundleSource, sourceMapSource);\n if (!stamped) {\n logger.debug(\n `Could not stamp debug ID (no debug ID in bundle, no source map, or invalid source map): ${bundleFilePath}`,\n );\n return;\n }\n\n const writes = [fs.promises.writeFile(bundleFilePath, stamped.bundleSource, 'utf8')];\n if (sourceMapPath && stamped.sourceMapSource !== undefined) {\n writes.push(fs.promises.writeFile(sourceMapPath, stamped.sourceMapSource, 'utf8'));\n }\n\n try {\n await Promise.all(writes);\n } catch (e) {\n logger.error(`Could not write debug ID into build artifacts: ${bundleFilePath}`, e);\n }\n}\n\n/**\n * Whether the bundle carries its source map inlined as `sourceMappingURL=data:`\n * URI, rather than referencing a separate `.map` file. Such bundles must still\n * be uploaded even when no `.map` file is found, because the source file itself\n * contains the map.\n */\nfunction bundleHasInlineSourceMap(bundleSource: string): boolean {\n return /^\\s*\\/\\/# sourceMappingURL=data:/m.test(bundleSource);\n}\n\n/**\n * Applies a set of heuristics to find the source map for a particular bundle.\n *\n * @returns the path to the bundle's source map or `undefined` if none could be found.\n */\nexport async function determineSourceMapPathFromBundle(\n bundlePath: string,\n bundleSource: string,\n logger: Logger,\n resolveSourceMapHook: ResolveSourceMapHook | undefined,\n): Promise<string | undefined> {\n const sourceMappingUrlMatch = bundleSource.match(/^\\s*\\/\\/# sourceMappingURL=(.*)$/m);\n const sourceMappingUrl = sourceMappingUrlMatch ? (sourceMappingUrlMatch[1] as string) : undefined;\n\n const searchLocations: string[] = [];\n\n if (resolveSourceMapHook) {\n logger.debug(\n `Calling sourcemaps.resolveSourceMap(${JSON.stringify(bundlePath)}, ${JSON.stringify(sourceMappingUrl)})`,\n );\n const customPath = await resolveSourceMapHook(bundlePath, sourceMappingUrl);\n logger.debug(`resolveSourceMap hook returned: ${JSON.stringify(customPath)}`);\n\n if (customPath) {\n searchLocations.push(customPath);\n }\n }\n\n // 1. try to find source map at `sourceMappingURL` location\n if (sourceMappingUrl) {\n let parsedUrl: URL | undefined;\n try {\n parsedUrl = new URL(sourceMappingUrl);\n } catch {\n // noop\n }\n\n if (parsedUrl?.protocol === 'file:') {\n searchLocations.push(url.fileURLToPath(sourceMappingUrl));\n } else if (parsedUrl) {\n // noop, non-file urls don't translate to a local sourcemap file\n } else if (path.isAbsolute(sourceMappingUrl)) {\n searchLocations.push(path.normalize(sourceMappingUrl));\n } else {\n searchLocations.push(path.normalize(path.join(path.dirname(bundlePath), sourceMappingUrl)));\n }\n }\n\n // 2. try to find source map at path adjacent to chunk source, but with `.map` appended\n searchLocations.push(`${bundlePath}.map`);\n\n for (const searchLocation of searchLocations) {\n try {\n await util.promisify(fs.access)(searchLocation);\n logger.debug(`Source map found for bundle \\`${bundlePath}\\`: \\`${searchLocation}\\``);\n return searchLocation;\n } catch {\n // noop\n }\n }\n\n // This is just a debug message because it can be quite spammy for some frameworks\n logger.debug(\n `Could not determine source map path for bundle \\`${bundlePath}\\`` +\n ` with sourceMappingURL=${sourceMappingUrl === undefined ? 'undefined' : `\\`${sourceMappingUrl}\\``}` +\n ` - Did you turn on source map generation in your bundler?` +\n ` (Attempted paths: ${searchLocations.map(e => `\\`${e}\\``).join(', ')})`,\n );\n return undefined;\n}\n\nconst PROTOCOL_REGEX = /^[a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\//;\nexport function defaultRewriteSourcesHook(source: string): string {\n if (source.match(PROTOCOL_REGEX)) {\n return source.replace(PROTOCOL_REGEX, '');\n } else {\n return path.relative(process.cwd(), path.normalize(source));\n }\n}\n"],"names":["fs","path"],"mappings":";;;;;;AAaO,SAAS,2BAAA,CAA4B,EAAE,wBAAA,EAAyB,EAA+B;AACpG,EAAA,OAAO,OAAO,oBAA8B,IAAA,KAAuC;AAGjF,IAAA,MAAM,YAAA,GAAe,kBAAA,CAAmB,GAAA,CAAI,yBAAyB,CAAA;AACrE,IAAA,OAAO,wBAAA,CAAyB,gBAAA,CAAiB,YAAA,EAAc,IAAI,CAAA;AAAA,EACrE,CAAA;AACF;AAEA,eAAsB,8BACpB,cAAA,EACA,YAAA,EACA,UAAA,EACA,MAAA,EACA,oBACA,oBAAA,EACe;AACf,EAAA,IAAI,aAAA;AACJ,EAAA,IAAI;AACF,IAAA,aAAA,GAAgB,MAAMA,WAAA,CAAG,QAAA,CAAS,QAAA,CAAS,gBAAgB,MAAM,CAAA;AAAA,EACnE,SAAS,CAAA,EAAG;AACV,IAAA,MAAA,CAAO,KAAA,CAAM,CAAA,4DAAA,EAA+D,cAAc,CAAA,CAAA,EAAI,CAAC,CAAA;AAC/F,IAAA;AAAA,EACF;AAEA,EAAA,IAAI,gCAAA,CAAiC,aAAa,CAAA,KAAM,MAAA,EAAW;AACjE,IAAA,MAAA,CAAO,KAAA;AAAA,MACL,0KAA0K,cAAc,CAAA;AAAA,KAC1L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AS,0BAA0B,MAAA,EAAwB;AAChE,EAAA,IAAI,MAAA,CAAO,KAAA,CAAM,cAAc,CAAA,EAAG;AAChC,IAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,cAAA,EAAgB,EAAE,CAAA;AAAA,EAC1C,CAAA,MAAO;AACL,IAAA,OAAOC,aAAA,CAAK,SAAS,OAAA,CAAQ,GAAA,IAAOA,aAAA,CAAK,SAAA,CAAU,MAAM,CAAC,CAAA;AAAA,EAC5D;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"debug-id-upload.js","names":[],"sources":["../../../src/core/debug-id-upload.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport * as url from 'url';\nimport * as util from 'util';\nimport type { SentryBuildPluginManager, UploadStaging } from './build-plugin-manager';\nimport type { Logger } from './logger';\nimport type { ResolveSourceMapHook, RewriteSourcesHook } from './types';\nimport { stripQueryAndHashFromPath } from './utils';\n\ninterface DebugIdUploadPluginOptions {\n sentryBuildPluginManager: SentryBuildPluginManager;\n}\n\nexport function createDebugIdUploadFunction({ sentryBuildPluginManager }: DebugIdUploadPluginOptions) {\n return async (buildArtifactPaths: string[], opts?: { staging?: UploadStaging }) => {\n // Webpack and perhaps other bundlers allow you to append query strings to\n // filenames for cache busting purposes. We should strip these before upload.\n const cleanedPaths = buildArtifactPaths.map(stripQueryAndHashFromPath);\n return sentryBuildPluginManager.uploadSourcemaps(cleanedPaths, opts);\n };\n}\n\n/** The source map of a prepared bundle. `sourceMapPath` is `undefined` for an inline map. */\nexport type PreparedBundle = { sourceMapPath: string | undefined };\n\n/** Resolves to `undefined` when the bundle was skipped. */\nexport async function prepareBundleForDebugIdUpload(\n bundleFilePath: string,\n uploadFolder: string,\n chunkIndex: number,\n logger: Logger,\n rewriteSourcesHook: RewriteSourcesHook,\n resolveSourceMapHook: ResolveSourceMapHook | undefined,\n): Promise<PreparedBundle | undefined> {\n let bundleContent: string;\n try {\n bundleContent = await fs.promises.readFile(bundleFilePath, 'utf8');\n } catch (e) {\n logger.error(`Could not read bundle to determine debug ID and source map: ${bundleFilePath}`, e);\n return;\n }\n\n if (determineDebugIdFromBundleSource(bundleContent) === undefined) {\n logger.debug(\n `Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: ${bundleFilePath}`,\n );\n return;\n }\n\n const sourceMapPath = await determineSourceMapPathFromBundle(\n bundleFilePath,\n bundleContent,\n logger,\n resolveSourceMapHook,\n );\n\n let sourceMapSource: string | undefined;\n if (sourceMapPath) {\n try {\n sourceMapSource = await fs.promises.readFile(sourceMapPath, 'utf8');\n } catch (e) {\n logger.error(`Failed to read source map for debug ID upload: ${sourceMapPath}`, e);\n return;\n }\n }\n\n const result = prepareArtifactForUpload({\n code: bundleContent,\n mapSource: sourceMapSource,\n mapDir: path.dirname(sourceMapPath ?? bundleFilePath),\n rewriteSourcesHook,\n });\n\n if (!result.ok) {\n if (result.reason === 'invalid-source-map') {\n logger.error(`Failed to parse source map for debug ID upload: ${sourceMapPath}`);\n } else {\n // A chunk with a debug ID but no resolvable source map\n // (e.g. framework-generated stub chunks that never emit one) can't be\n // symbolicated, so uploading its minified source alone accomplishes\n // nothing and only makes the uploader warn about a missing source map ref.\n logger.debug(`Not uploading bundle without a source map: ${bundleFilePath}`);\n }\n return;\n }\n\n await writePreparedArtifact(uploadFolder, `${result.artifact.debugId}-${chunkIndex}`, result.artifact);\n return { sourceMapPath };\n}\n\nexport type PreparedUploadArtifact = {\n debugId: string;\n bundleSource: string;\n /** `undefined` when the bundle has no separate source map (i.e. the map is inlined). */\n sourceMapSource: string | undefined;\n};\n\nexport type PrepareArtifactResult =\n | { ok: true; artifact: PreparedUploadArtifact }\n | { ok: false; reason: 'no-debug-id' | 'no-source-map' | 'invalid-source-map' };\n\n/**\n * Prepares a bundle and its source map for the debug ID upload: stamps the debug ID into both\n * and runs the `rewriteSources` hook over the map's `sources`.\n *\n * Pass `mapSource: undefined` when the bundle has no separate source map. A bundle with an\n * inlined map is still prepared; a bundle without any map is skipped because it cannot be\n * symbolicated.\n */\nexport function prepareArtifactForUpload(input: {\n code: string;\n mapSource: string | undefined;\n /** Directory the source map lives in, passed to the `rewriteSources` hook. */\n mapDir: string;\n rewriteSourcesHook: RewriteSourcesHook;\n}): PrepareArtifactResult {\n const debugId = determineDebugIdFromBundleSource(input.code);\n if (debugId === undefined) {\n return { ok: false, reason: 'no-debug-id' };\n }\n\n const bundleSource = addDebugIdToBundleSource(input.code, debugId);\n\n if (input.mapSource === undefined) {\n if (!bundleHasInlineSourceMap(input.code)) {\n return { ok: false, reason: 'no-source-map' };\n }\n return { ok: true, artifact: { debugId, bundleSource, sourceMapSource: undefined } };\n }\n\n const map = parseSourceMap(input.mapSource);\n if (!map) {\n return { ok: false, reason: 'invalid-source-map' };\n }\n\n setDebugIdOnSourceMap(map, debugId);\n\n if (Array.isArray(map['sources'])) {\n map['sources'] = map['sources'].map((source: string) =>\n input.rewriteSourcesHook(source, map, { mapDir: input.mapDir }),\n );\n }\n\n return { ok: true, artifact: { debugId, bundleSource, sourceMapSource: JSON.stringify(map) } };\n}\n\n/**\n * Writes a prepared artifact as `<uniqueUploadName>.js` (and `.js.map`) into the upload folder.\n */\nexport async function writePreparedArtifact(\n uploadFolder: string,\n uniqueUploadName: string,\n artifact: PreparedUploadArtifact,\n): Promise<void> {\n const writes = [\n fs.promises.writeFile(path.join(uploadFolder, `${uniqueUploadName}.js`), artifact.bundleSource, 'utf-8'),\n ];\n\n if (artifact.sourceMapSource !== undefined) {\n writes.push(\n fs.promises.writeFile(path.join(uploadFolder, `${uniqueUploadName}.js.map`), artifact.sourceMapSource, 'utf-8'),\n );\n }\n\n await Promise.all(writes);\n}\n\n/**\n * Looks for a particular string pattern (`sdbid-[debug ID]`) in the bundle\n * source and extracts the bundle's debug ID from it.\n *\n * The string pattern is injected via the debug ID injection snipped.\n */\nfunction determineDebugIdFromBundleSource(code: string): string | undefined {\n const match = code.match(\n /sentry-dbid-([0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12})/,\n );\n\n if (match) {\n return match[1];\n } else {\n return undefined;\n }\n}\n\nconst SPEC_LAST_DEBUG_ID_REGEX = /\\/\\/# debugId=([a-fA-F0-9-]+)(?![\\s\\S]*\\/\\/# debugId=)/m;\n\nfunction hasSpecCompliantDebugId(bundleSource: string): boolean {\n return SPEC_LAST_DEBUG_ID_REGEX.test(bundleSource);\n}\n\nfunction addDebugIdToBundleSource(bundleSource: string, debugId: string): string {\n if (hasSpecCompliantDebugId(bundleSource)) {\n return bundleSource.replace(SPEC_LAST_DEBUG_ID_REGEX, `//# debugId=${debugId}`);\n } else {\n return `${bundleSource}\\n//# debugId=${debugId}`;\n }\n}\n\nfunction setDebugIdOnSourceMap(map: Record<string, unknown>, debugId: string): void {\n // For now we write both fields until we know what will become the standard - if ever.\n map['debug_id'] = debugId;\n map['debugId'] = debugId;\n}\n\nexport type StampedArtifacts = {\n bundleSource: string;\n /** `undefined` when the bundle has no separate source map (i.e. the map is inlined). */\n sourceMapSource: string | undefined;\n};\n\nfunction parseSourceMap(sourceMapSource: string): Record<string, unknown> | undefined {\n let map: unknown;\n try {\n map = JSON.parse(sourceMapSource);\n } catch {\n return undefined;\n }\n\n return map && typeof map === 'object' ? (map as Record<string, unknown>) : undefined;\n}\n\n/**\n * Stamps the debug ID injected into `bundleSource` into the bundle (as `//# debugId=` comment) and its\n * source map (as `debug_id`/`debugId` fields).\n *\n * This exists for `sourcemaps.disable: \"disable-upload\"`: the regular upload path only stamps\n * temporary copies of the artifacts (see `prepareBundleForDebugIdUpload`), so without this the\n * emitted artifacts would carry no debug ID and a later manual upload could not match them.\n * Callers must apply the result inside the bundler's asset pipeline (or, for bundlers without one,\n * before the build resolves) so that integrity hashes computed by later build steps include it.\n *\n * Pass `sourceMapSource: undefined` when the bundle has no separate source map. A bundle with an\n * inlined map still gets the comment, which is all the CLI and Symbolicator read the debug ID from.\n *\n * @returns the stamped artifacts, or `undefined` for bundles without a debug ID, without any source\n * map, or with an unparseable map.\n */\nexport function stampDebugId(bundleSource: string, sourceMapSource: string | undefined): StampedArtifacts | undefined {\n const debugId = determineDebugIdFromBundleSource(bundleSource);\n if (debugId === undefined) {\n return undefined;\n }\n\n if (sourceMapSource === undefined) {\n if (!bundleHasInlineSourceMap(bundleSource)) {\n return undefined;\n }\n\n return { bundleSource: addDebugIdToBundleSource(bundleSource, debugId), sourceMapSource: undefined };\n }\n\n const map = parseSourceMap(sourceMapSource);\n if (!map) {\n return undefined;\n }\n\n setDebugIdOnSourceMap(map, debugId);\n\n return {\n bundleSource: addDebugIdToBundleSource(bundleSource, debugId),\n sourceMapSource: JSON.stringify(map),\n };\n}\n\n/**\n * Stamps the debug ID of an emitted bundle into the bundle and its source map on disk.\n *\n * Used by bundlers that offer no hook to modify assets before they are written (esbuild).\n */\nexport async function addDebugIdToEmittedArtifacts(\n bundleFilePath: string,\n logger: Logger,\n resolveSourceMapHook: ResolveSourceMapHook | undefined,\n): Promise<void> {\n let bundleSource: string;\n try {\n bundleSource = await fs.promises.readFile(bundleFilePath, 'utf8');\n } catch (e) {\n logger.error(`Could not read bundle to stamp debug ID: ${bundleFilePath}`, e);\n return;\n }\n\n const sourceMapPath = await determineSourceMapPathFromBundle(\n bundleFilePath,\n bundleSource,\n logger,\n resolveSourceMapHook,\n );\n\n let sourceMapSource: string | undefined;\n if (sourceMapPath) {\n try {\n sourceMapSource = await fs.promises.readFile(sourceMapPath, 'utf8');\n } catch (e) {\n logger.error(`Could not read source map to stamp debug ID: ${sourceMapPath}`, e);\n return;\n }\n }\n\n const stamped = stampDebugId(bundleSource, sourceMapSource);\n if (!stamped) {\n logger.debug(\n `Could not stamp debug ID (no debug ID in bundle, no source map, or invalid source map): ${bundleFilePath}`,\n );\n return;\n }\n\n const writes = [fs.promises.writeFile(bundleFilePath, stamped.bundleSource, 'utf8')];\n if (sourceMapPath && stamped.sourceMapSource !== undefined) {\n writes.push(fs.promises.writeFile(sourceMapPath, stamped.sourceMapSource, 'utf8'));\n }\n\n try {\n await Promise.all(writes);\n } catch (e) {\n logger.error(`Could not write debug ID into build artifacts: ${bundleFilePath}`, e);\n }\n}\n\n/**\n * Whether the bundle carries its source map inlined as `sourceMappingURL=data:`\n * URI, rather than referencing a separate `.map` file. Such bundles must still\n * be uploaded even when no `.map` file is found, because the source file itself\n * contains the map.\n */\nfunction bundleHasInlineSourceMap(bundleSource: string): boolean {\n return /^\\s*\\/\\/# sourceMappingURL=data:/m.test(bundleSource);\n}\n\n/**\n * Applies a set of heuristics to find the source map for a particular bundle.\n *\n * @returns the path to the bundle's source map or `undefined` if none could be found.\n */\nexport async function determineSourceMapPathFromBundle(\n bundlePath: string,\n bundleSource: string,\n logger: Logger,\n resolveSourceMapHook: ResolveSourceMapHook | undefined,\n): Promise<string | undefined> {\n const sourceMappingUrlMatch = bundleSource.match(/^\\s*\\/\\/# sourceMappingURL=(.*)$/m);\n const sourceMappingUrl = sourceMappingUrlMatch ? (sourceMappingUrlMatch[1] as string) : undefined;\n\n const searchLocations: string[] = [];\n\n if (resolveSourceMapHook) {\n logger.debug(\n `Calling sourcemaps.resolveSourceMap(${JSON.stringify(bundlePath)}, ${JSON.stringify(sourceMappingUrl)})`,\n );\n const customPath = await resolveSourceMapHook(bundlePath, sourceMappingUrl);\n logger.debug(`resolveSourceMap hook returned: ${JSON.stringify(customPath)}`);\n\n if (customPath) {\n searchLocations.push(customPath);\n }\n }\n\n // 1. try to find source map at `sourceMappingURL` location\n if (sourceMappingUrl) {\n let parsedUrl: URL | undefined;\n try {\n parsedUrl = new URL(sourceMappingUrl);\n } catch {\n // noop\n }\n\n if (parsedUrl?.protocol === 'file:') {\n searchLocations.push(url.fileURLToPath(sourceMappingUrl));\n } else if (parsedUrl) {\n // noop, non-file urls don't translate to a local sourcemap file\n } else if (path.isAbsolute(sourceMappingUrl)) {\n searchLocations.push(path.normalize(sourceMappingUrl));\n } else {\n searchLocations.push(path.normalize(path.join(path.dirname(bundlePath), sourceMappingUrl)));\n }\n }\n\n // 2. try to find source map at path adjacent to chunk source, but with `.map` appended\n searchLocations.push(`${bundlePath}.map`);\n\n for (const searchLocation of searchLocations) {\n try {\n await util.promisify(fs.access)(searchLocation);\n logger.debug(`Source map found for bundle \\`${bundlePath}\\`: \\`${searchLocation}\\``);\n return searchLocation;\n } catch {\n // noop\n }\n }\n\n // This is just a debug message because it can be quite spammy for some frameworks\n logger.debug(\n `Could not determine source map path for bundle \\`${bundlePath}\\`` +\n ` with sourceMappingURL=${sourceMappingUrl === undefined ? 'undefined' : `\\`${sourceMappingUrl}\\``}` +\n ` - Did you turn on source map generation in your bundler?` +\n ` (Attempted paths: ${searchLocations.map(e => `\\`${e}\\``).join(', ')})`,\n );\n return undefined;\n}\n\nconst PROTOCOL_REGEX = /^[a-zA-Z][a-zA-Z0-9+\\-.]*:\\/\\//;\nexport function defaultRewriteSourcesHook(source: string): string {\n if (source.match(PROTOCOL_REGEX)) {\n return source.replace(PROTOCOL_REGEX, '');\n } else {\n return path.relative(process.cwd(), path.normalize(source));\n }\n}\n"],"mappings":";;;;;;AAaA,SAAgB,4BAA4B,EAAE,4BAAwD;CACpG,OAAO,OAAO,oBAA8B,SAAuC;EAGjF,MAAM,eAAe,mBAAmB,IAAI,yBAAyB;EACrE,OAAO,yBAAyB,iBAAiB,cAAc,IAAI;CACrE;AACF;;AAMA,eAAsB,8BACpB,gBACA,cACA,YACA,QACA,oBACA,sBACqC;CACrC,IAAI;CACJ,IAAI;EACF,gBAAgB,MAAM,GAAG,SAAS,SAAS,gBAAgB,MAAM;CACnE,SAAS,GAAG;EACV,OAAO,MAAM,+DAA+D,kBAAkB,CAAC;EAC/F;CACF;CAEA,IAAI,iCAAiC,aAAa,MAAM,KAAA,GAAW;EACjE,OAAO,MACL,0KAA0K,gBAC5K;EACA;CACF;CAEA,MAAM,gBAAgB,MAAM,iCAC1B,gBACA,eACA,QACA,oBACF;CAEA,I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