@sentry/bundler-plugins 11.13.0 → 11.14.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/core/build-plugin-manager.js +1 -1
- package/build/cjs/core/sentry/transports.js +1 -1
- package/build/cjs/core/utils.js +4 -6
- package/build/cjs/core/utils.js.map +1 -1
- package/build/cjs/core/version.js +1 -1
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/esbuild/index.js +3 -2
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/esm/core/build-plugin-manager.js +1 -1
- package/build/esm/core/sentry/transports.js +1 -1
- package/build/esm/core/utils.js +1 -3
- package/build/esm/core/utils.js.map +1 -1
- package/build/esm/core/version.js +1 -1
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/esbuild/index.js +3 -2
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- 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.map +1 -1
- package/package.json +4 -4
|
@@ -15,8 +15,8 @@ let fs = require("fs");
|
|
|
15
15
|
fs = require_runtime.__toESM(fs);
|
|
16
16
|
let os = require("os");
|
|
17
17
|
os = require_runtime.__toESM(os);
|
|
18
|
-
let glob = require("glob");
|
|
19
18
|
let _sentry_core = require("@sentry/core");
|
|
19
|
+
let glob = require("glob");
|
|
20
20
|
let dotenv = require("dotenv");
|
|
21
21
|
dotenv = require_runtime.__toESM(dotenv);
|
|
22
22
|
// src/core/build-plugin-manager.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
2
|
-
let node_path = require("node:path");
|
|
3
2
|
let _sentry_core = require("@sentry/core");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
4
|
let node_https = require("node:https");
|
|
5
5
|
node_https = require_runtime.__toESM(node_https);
|
|
6
6
|
let node_stream = require("node:stream");
|
package/build/cjs/core/utils.js
CHANGED
|
@@ -12,6 +12,7 @@ child_process = require_runtime.__toESM(child_process);
|
|
|
12
12
|
let magic_string = require("magic-string");
|
|
13
13
|
magic_string = require_runtime.__toESM(magic_string);
|
|
14
14
|
let _sentry_core_server = require("@sentry/core/server");
|
|
15
|
+
let _sentry_core = require("@sentry/core");
|
|
15
16
|
// src/core/utils.ts
|
|
16
17
|
/**
|
|
17
18
|
* Checks whether the given input is already an array, and if it isn't, wraps it in one.
|
|
@@ -171,23 +172,20 @@ function warnAboutPlaceholderCommitEnvVar(name) {
|
|
|
171
172
|
function readCommitEnvVar(name) {
|
|
172
173
|
return (0, _sentry_core_server._INTERNAL_readCommitEnvVar)(name, warnAboutPlaceholderCommitEnvVar);
|
|
173
174
|
}
|
|
174
|
-
function stringifyForCodeInjection(value) {
|
|
175
|
-
return JSON.stringify(value)?.replace(/</g, "\\u003c");
|
|
176
|
-
}
|
|
177
175
|
/**
|
|
178
176
|
* Generates code for the global injector which is responsible for setting the global
|
|
179
177
|
* `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.
|
|
180
178
|
*/
|
|
181
179
|
function generateReleaseInjectorCode({ release, injectBuildInformation }) {
|
|
182
|
-
let code = `e.SENTRY_RELEASE={id:${stringifyForCodeInjection(release)}};`;
|
|
180
|
+
let code = `e.SENTRY_RELEASE={id:${(0, _sentry_core.stringifyForCodeInjection)(release)}};`;
|
|
183
181
|
if (injectBuildInformation) {
|
|
184
182
|
const buildInfo = getBuildInformation();
|
|
185
|
-
code += `e.SENTRY_BUILD_INFO=${stringifyForCodeInjection(buildInfo)};`;
|
|
183
|
+
code += `e.SENTRY_BUILD_INFO=${(0, _sentry_core.stringifyForCodeInjection)(buildInfo)};`;
|
|
186
184
|
}
|
|
187
185
|
return new CodeInjection(code);
|
|
188
186
|
}
|
|
189
187
|
function generateModuleMetadataInjectorCode(metadata) {
|
|
190
|
-
return new CodeInjection(`e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${stringifyForCodeInjection(metadata)});`);
|
|
188
|
+
return new CodeInjection(`e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${(0, _sentry_core.stringifyForCodeInjection)(metadata)});`);
|
|
191
189
|
}
|
|
192
190
|
function getBuildInformation() {
|
|
193
191
|
const packageJson = getPackageJson();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["path","os","fs","crypto","childProcess","getReleaseFromCommitEnv","readCoreCommitEnvVar","MagicString"],"sources":["../../../src/core/utils.ts"],"sourcesContent":["/* oxlint-disable max-lines */\nimport path from 'path';\nimport fs from 'fs';\nimport os from 'os';\nimport crypto from 'crypto';\nimport childProcess from 'child_process';\nimport type { SourceMap } from 'magic-string';\nimport MagicString from 'magic-string';\nimport {\n _INTERNAL_getReleaseFromCommitEnv as getReleaseFromCommitEnv,\n _INTERNAL_readCommitEnvVar as readCoreCommitEnvVar,\n} from '@sentry/core/server';\n\n/**\n * Checks whether the given input is already an array, and if it isn't, wraps it in one.\n *\n * @param maybeArray Input to turn into an array, if necessary\n * @returns The input, if already an array, or an array with the input as the only element, if not\n */\nexport function arrayify<T = unknown>(maybeArray: T | T[]): T[] {\n return Array.isArray(maybeArray) ? maybeArray : [maybeArray];\n}\n\ntype PackageJson = Record<string, unknown>;\n\n/**\n * Get the closes package.json from a given starting point upwards.\n * This handles a few edge cases:\n * * Check if a given file package.json appears to be an actual NPM package.json file\n * * Stop at the home dir, to avoid looking too deeply\n */\nexport function getPackageJson({ cwd, stopAt }: { cwd?: string; stopAt?: string } = {}): PackageJson | undefined {\n return lookupPackageJson(cwd ?? process.cwd(), path.normalize(stopAt ?? os.homedir()));\n}\n\nexport function parseMajorVersion(ver: string): number | undefined {\n let version = ver;\n // if it has a `v` prefix, remove it\n if (version.startsWith('v')) {\n version = version.slice(1);\n }\n\n // First, try simple lookup of exact, ~ and ^ versions\n const regex = /^[\\^~]?(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n\n const match = version.match(regex);\n if (match) {\n return parseInt(match[1] as string, 10);\n }\n\n // Try to parse e.g. 1.x\n const coerced = parseInt(version, 10);\n if (!Number.isNaN(coerced)) {\n return coerced;\n }\n\n // Match <= and >= ranges.\n const gteLteRegex = /^[<>]=\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const gteLteMatch = version.match(gteLteRegex);\n if (gteLteMatch) {\n return parseInt(gteLteMatch[1] as string, 10);\n }\n\n // match < ranges\n const ltRegex = /^<\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const ltMatch = version.match(ltRegex);\n if (ltMatch) {\n // Two scenarios:\n // a) < 2.0.0 --> return 1\n // b) < 2.1.0 --> return 2\n\n const major = parseInt(ltMatch[1] as string, 10);\n\n if (\n // minor version > 0\n (typeof ltMatch[2] === 'string' && parseInt(ltMatch[2].slice(1), 10) > 0) ||\n // patch version > 0\n (typeof ltMatch[3] === 'string' && parseInt(ltMatch[3].slice(1), 10) > 0)\n ) {\n return major;\n }\n\n return major - 1;\n }\n\n // match > ranges\n const gtRegex = /^>\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const gtMatch = version.match(gtRegex);\n if (gtMatch) {\n // We always return the version here, even though it _may_ be incorrect\n // E.g. if given > 2.0.0, it should be 2 if there exists any 2.x.x version, else 3\n // Since there is no way for us to know this, we're going to assume any kind of patch/feature release probably exists\n return parseInt(gtMatch[1] as string, 10);\n }\n return undefined;\n}\n\n// This is an explicit list of packages where we want to include the (major) version number.\nconst PACKAGES_TO_INCLUDE_VERSION = [\n 'react',\n '@angular/core',\n 'vue',\n 'ember-source',\n 'svelte',\n '@sveltejs/kit',\n 'webpack',\n 'vite',\n 'gatsby',\n 'next',\n 'remix',\n 'rollup',\n 'esbuild',\n];\n\nexport function getDependencies(packageJson: PackageJson): {\n deps: string[];\n depsVersions: Record<string, number>;\n} {\n const dependencies: Record<string, string> = Object.assign(\n {},\n packageJson['devDependencies'] ?? {},\n packageJson['dependencies'] ?? {},\n );\n\n const deps = Object.keys(dependencies).sort();\n\n const depsVersions: Record<string, number> = deps.reduce(\n (depsVersions, depName) => {\n if (PACKAGES_TO_INCLUDE_VERSION.includes(depName)) {\n const version = dependencies[depName] as string;\n const majorVersion = parseMajorVersion(version);\n if (majorVersion) {\n depsVersions[depName] = majorVersion;\n }\n }\n return depsVersions;\n },\n {} as Record<string, number>,\n );\n\n return { deps, depsVersions };\n}\n\nfunction findPackageJson(cwd: string, stopAt: string): string | undefined {\n let dirName = path.resolve(cwd);\n\n for (;;) {\n // Stop if we reach this dir\n if (path.normalize(dirName) === stopAt) {\n return undefined;\n }\n\n const jsonPath = path.join(dirName, 'package.json');\n if (fs.existsSync(jsonPath)) {\n return jsonPath;\n }\n\n const parentDirName = path.dirname(dirName);\n // We reached the file system root\n if (parentDirName === dirName) {\n return undefined;\n }\n\n dirName = parentDirName;\n }\n}\n\nfunction lookupPackageJson(cwd: string, stopAt: string): PackageJson | undefined {\n const jsonPath = findPackageJson(cwd, stopAt);\n\n if (!jsonPath) {\n return undefined;\n }\n\n try {\n const jsonStr = fs.readFileSync(jsonPath, 'utf8');\n const json = JSON.parse(jsonStr) as PackageJson;\n\n // Ensure it is an actual package.json\n // This is very much not bulletproof, but should be good enough\n if ('name' in json || 'private' in json) {\n return json;\n }\n } catch {\n // Ignore and walk up\n }\n\n // Continue up the tree, if we find a fitting package.json\n const newCwd = path.dirname(path.resolve(`${jsonPath}/..`));\n return lookupPackageJson(newCwd, stopAt);\n}\n\n/**\n * Deterministically hashes a string and turns the hash into a uuid.\n */\nexport function stringToUUID(str: string): string {\n const sha256Hash = crypto.createHash('sha256').update(str).digest('hex');\n\n // Position 16 is fixed to either 8, 9, a, or b in the uuid v4 spec (10xx in binary)\n // RFC 4122 section 4.4\n const v4variant = ['8', '9', 'a', 'b'][sha256Hash.substring(16, 17).charCodeAt(0) % 4] as string;\n\n return `${sha256Hash.substring(0, 8)}-${sha256Hash.substring(8, 12)}-4${sha256Hash.substring(13, 16)}-${v4variant}${sha256Hash.substring(17, 20)}-${sha256Hash.substring(20, 32)}`.toLowerCase();\n}\n\nfunction gitRevision(): string | undefined {\n let gitRevision: string | undefined;\n try {\n gitRevision = childProcess\n .execSync('git rev-parse HEAD', { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true })\n .toString()\n .trim();\n } catch {\n // noop\n }\n return gitRevision;\n}\n\n// Mirrors the CLI's `set-commits --auto` fallback for builds without an `origin` remote. Vercel is left out\n// because the CLI only reads `VERCEL_GIT_*` on production builds.\nconst CI_REPOSITORY_ENV_VARS = [\n 'GITHUB_REPOSITORY',\n 'CI_PROJECT_PATH',\n 'BITBUCKET_REPO_FULL_NAME',\n 'RENDER_GIT_REPO_SLUG',\n 'RAILWAY_GIT_REPO_NAME',\n 'CIRCLE_PROJECT_REPONAME',\n 'BUILDKITE_REPO',\n 'BUILD_REPOSITORY_URI',\n] as const;\n\n/**\n * Whether `set-commits --auto` can find the repository: from the `origin` git remote, or from CI variables.\n */\nexport function canAutoDetectRepository(): boolean {\n if (\n CI_REPOSITORY_ENV_VARS.some(name => process.env[name]) ||\n (process.env['NETLIFY'] && process.env['REPOSITORY_URL'])\n ) {\n return true;\n }\n try {\n childProcess.execSync('git remote get-url origin', { stdio: 'ignore', windowsHide: true });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Tries to guess a release name based on environmental data.\n */\nexport function determineReleaseName(): string | undefined {\n return getReleaseFromCommitEnv(warnAboutPlaceholderCommitEnvVar) || gitRevision();\n}\n\n// Release detection and commit association can read the same variable in one build.\nconst warnedPlaceholderEnvVars = new Set<string>();\n\nfunction warnAboutPlaceholderCommitEnvVar(name: string): void {\n if (warnedPlaceholderEnvVars.has(name)) {\n return;\n }\n warnedPlaceholderEnvVars.add(name);\n // This runs before the plugin logger exists, so `silent: true` does not suppress it. That is\n // deliberate: a warning that is easy to miss is how this misconfiguration went unnoticed.\n // eslint-disable-next-line no-console\n console.warn(\n `[@sentry/bundler-plugins] Ignoring the ${name} environment variable as a release name, because its value is its own name. Set the release explicitly, or fix the variable in your build environment.`,\n );\n}\n\n/**\n * Reads an environment variable that should hold a commit SHA, ignoring a value that is the\n * variable's own name. See `_INTERNAL_readCommitEnvVar` in `@sentry/core/server`.\n */\nexport function readCommitEnvVar(name: string): string | undefined {\n return readCoreCommitEnvVar(name, warnAboutPlaceholderCommitEnvVar);\n}\n\nfunction stringifyForCodeInjection(value: unknown): string | undefined {\n // Bundles may be inlined in HTML, where JSON quoting does not escape script tags or HTML comments.\n return JSON.stringify(value)?.replace(/</g, '\\\\u003c');\n}\n\n/**\n * Generates code for the global injector which is responsible for setting the global\n * `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.\n */\nexport function generateReleaseInjectorCode({\n release,\n injectBuildInformation,\n}: {\n release: string;\n injectBuildInformation: boolean;\n}): CodeInjection {\n let code = `e.SENTRY_RELEASE={id:${stringifyForCodeInjection(release)}};`;\n\n if (injectBuildInformation) {\n const buildInfo = getBuildInformation();\n\n code += `e.SENTRY_BUILD_INFO=${stringifyForCodeInjection(buildInfo)};`;\n }\n\n return new CodeInjection(code);\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function generateModuleMetadataInjectorCode(metadata: any): CodeInjection {\n // We are merging the metadata objects in case modules are bundled twice with the plugin\n // Use try-catch to avoid issues when bundlers rename global variables like 'window' to 'k'\n return new CodeInjection(\n `e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${stringifyForCodeInjection(\n metadata,\n )});`,\n );\n}\n\nexport function getBuildInformation(): {\n deps: string[];\n depsVersions: Record<string, number>;\n nodeVersion: number | undefined;\n} {\n const packageJson = getPackageJson();\n\n const { deps, depsVersions } = packageJson ? getDependencies(packageJson) : { deps: [], depsVersions: {} };\n\n return {\n deps,\n depsVersions,\n nodeVersion: parseMajorVersion(process.version),\n };\n}\n\nexport function stripQueryAndHashFromPath(path: string): string {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return path.split('?')[0]!.split('#')[0]!;\n}\n\nexport function replaceBooleanFlagsInCode(\n code: string,\n replacementValues: Record<string, boolean | undefined>,\n): { code: string; map: SourceMap } | null {\n const ms = new MagicString(code);\n\n Object.keys(replacementValues).forEach(key => {\n const value = replacementValues[key];\n\n if (typeof value === 'boolean') {\n ms.replaceAll(key, JSON.stringify(value));\n }\n });\n\n if (ms.hasChanged()) {\n return {\n code: ms.toString(),\n map: ms.generateMap({ hires: 'boundary' }),\n };\n }\n\n return null;\n}\n\n// https://turbo.build/repo/docs/reference/system-environment-variables#environment-variables-in-tasks\nexport function getTurborepoEnvPassthroughWarning(envVarName: string): string {\n return process.env['TURBO_HASH']\n ? `\\nYou seem to be using Turborepo, did you forget to put ${envVarName} in \\`passThroughEnv\\`? https://turbo.build/repo/docs/reference/configuration#passthroughenv`\n : '';\n}\n\n/**\n * Gets the projects from the project option. This might be a single project or an array of projects.\n */\nexport function getProjects(project: string | string[] | undefined): string[] | undefined {\n if (Array.isArray(project)) {\n return project;\n }\n\n if (project) {\n return [project];\n }\n\n return undefined;\n}\n\n/**\n * Checks if a chunk contains only import/export statements and no substantial code.\n *\n * In Vite MPA (multi-page application) mode, HTML entry points create \"facade\" chunks\n * that only contain import statements to load shared modules. These should not have\n * Sentry code injected. However, in SPA mode, the main bundle also has an HTML facade\n * but contains substantial application code that SHOULD have debug IDs injected.\n *\n * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/839\n */\nexport function containsOnlyImports(code: string): boolean {\n const codeWithoutImports = code\n // Remove side effect imports: import '/path'; or import \"./path\";\n // Using explicit negated character classes to avoid polynomial backtracking\n .replace(/^\\s*import\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove named/default imports: import x from '/path'; import { x } from '/path';\n .replace(/^\\s*import\\b[^'\"`\\n]*\\bfrom\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove re-exports: export * from '/path'; export { x } from '/path';\n .replace(/^\\s*export\\b[^'\"`\\n]*\\bfrom\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove block comments\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n // Remove line comments\n .replace(/\\/\\/.*$/gm, '')\n // Remove \"use strict\" directives\n .replace(/[\"']use strict[\"']\\s*;?/g, '')\n .trim();\n\n return codeWithoutImports.length === 0;\n}\n\nexport class CodeInjection {\n // The code below is mostly ternary operators because it saves bundle size.\n // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)\n private readonly header: string;\n private readonly footer: string;\n\n constructor(private body: string = '') {\n // `globalThis` is checked first so the other identifiers are never evaluated\n // where it exists. A downstream bundler that runs over an already-injected\n // chunk can turn a free `global` into a `const` it declares further down the\n // file (Nitro's node compat does this). Reading that binding from the top of\n // the file hits the temporal dead zone, and `typeof` throws there instead of\n // returning \"undefined\", so the whole injection was silently swallowed by the\n // `catch` below and the chunk registered no debug ID.\n this.header = `!function(){try{var e=\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof self?self:{};`;\n this.footer = '}catch(e){}}();';\n }\n\n public code(): string {\n if (this.isEmpty()) {\n return '';\n }\n\n return this.header + this.body + this.footer;\n }\n\n public isEmpty(): boolean {\n return this.body.length === 0;\n }\n\n public append(code: CodeInjection | string): void {\n if (code instanceof CodeInjection) {\n this.body += code.body;\n } else {\n this.body += code;\n }\n }\n\n public clear(): void {\n this.body = '';\n }\n\n public clone(): CodeInjection {\n return new CodeInjection(this.body);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,SAAsB,YAA0B;CAC9D,OAAO,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,UAAU;AAC7D;;;;;;;AAUA,SAAgB,eAAe,EAAE,KAAK,WAA8C,CAAC,GAA4B;CAC/G,OAAO,kBAAkB,OAAO,QAAQ,IAAI,GAAGA,KAAAA,QAAK,UAAU,UAAUC,GAAAA,QAAG,QAAQ,CAAC,CAAC;AACvF;AAEA,SAAgB,kBAAkB,KAAiC;CACjE,IAAI,UAAU;CAEd,IAAI,QAAQ,WAAW,GAAG,GACxB,UAAU,QAAQ,MAAM,CAAC;CAM3B,MAAM,QAAQ,QAAQ,MAAM,oCAAK;CACjC,IAAI,OACF,OAAO,SAAS,MAAM,IAAc,EAAE;CAIxC,MAAM,UAAU,SAAS,SAAS,EAAE;CACpC,IAAI,CAAC,OAAO,MAAM,OAAO,GACvB,OAAO;CAKT,MAAM,cAAc,QAAQ,MAAM,sCAAW;CAC7C,IAAI,aACF,OAAO,SAAS,YAAY,IAAc,EAAE;CAK9C,MAAM,UAAU,QAAQ,MAAM,kCAAO;CACrC,IAAI,SAAS;EAKX,MAAM,QAAQ,SAAS,QAAQ,IAAc,EAAE;EAE/C,IAEG,OAAO,QAAQ,OAAO,YAAY,SAAS,QAAQ,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,KAEtE,OAAO,QAAQ,OAAO,YAAY,SAAS,QAAQ,EAAE,CAAC,MAAM,CAAC,GAAG,EA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IAAI,GAAG,WAAW,GAChB,OAAO;EACL,MAAM,GAAG,SAAS;EAClB,KAAK,GAAG,YAAY,EAAE,OAAO,WAAW,CAAC;CAC3C;CAGF,OAAO;AACT;AAGA,SAAgB,kCAAkC,YAA4B;CAC5E,OAAO,QAAQ,IAAI,gBACf,2DAA2D,WAAW,gGACtE;AACN;;;;AAKA,SAAgB,YAAY,SAA8D;CACxF,IAAI,MAAM,QAAQ,OAAO,GACvB,OAAO;CAGT,IAAI,SACF,OAAO,CAAC,OAAO;AAInB;;;;;;;;;;;;AAaA,SAAgB,oBAAoB,MAAuB;CAiBzD,OAhB2B,KAGxB,QAAQ,2DAA2D,EAAE,CAAC,CAEtE,QAAQ,4EAA4E,EAAE,CAAC,CAEvF,QAAQ,4EAA4E,EAAE,CAAC,CAEvF,QAAQ,qBAAqB,EAAE,CAAC,CAEhC,QAAQ,aAAa,EAAE,CAAC,CAExB,QAAQ,4BAA4B,EAAE,CAAC,CACvC,KAEqB,CAAC,CAAC,WAAW;AACvC;AAEA,IAAa,gBAAb,MAAa,cAAc;CAMzB,YAAoB,OAAe,IAAI;EAAnB,KAAA,OAAA;EAQlB,KAAK,SAAS;EACd,KAAK,SAAS;CAChB;CAEO,OAAe;EACpB,IAAI,KAAK,QAAQ,GACf,OAAO;EAGT,OAAO,KAAK,SAAS,KAAK,OAAO,KAAK;CACxC;CAEO,UAAmB;EACxB,OAAO,KAAK,KAAK,WAAW;CAC9B;CAEO,OAAO,MAAoC;EAChD,IAAI,gBAAgB,eAClB,KAAK,QAAQ,KAAK;OAElB,KAAK,QAAQ;CAEjB;CAEO,QAAc;EACnB,KAAK,OAAO;CACd;CAEO,QAAuB;EAC5B,OAAO,IAAI,cAAc,KAAK,IAAI;CACpC;AACF"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":["path","os","fs","crypto","childProcess","getReleaseFromCommitEnv","readCoreCommitEnvVar","stringifyForCodeInjection","MagicString"],"sources":["../../../src/core/utils.ts"],"sourcesContent":["/* oxlint-disable max-lines */\nimport path from 'path';\nimport fs from 'fs';\nimport os from 'os';\nimport crypto from 'crypto';\nimport childProcess from 'child_process';\nimport type { SourceMap } from 'magic-string';\nimport MagicString from 'magic-string';\nimport {\n _INTERNAL_getReleaseFromCommitEnv as getReleaseFromCommitEnv,\n _INTERNAL_readCommitEnvVar as readCoreCommitEnvVar,\n} from '@sentry/core/server';\nimport { stringifyForCodeInjection } from '@sentry/core';\n\n/**\n * Checks whether the given input is already an array, and if it isn't, wraps it in one.\n *\n * @param maybeArray Input to turn into an array, if necessary\n * @returns The input, if already an array, or an array with the input as the only element, if not\n */\nexport function arrayify<T = unknown>(maybeArray: T | T[]): T[] {\n return Array.isArray(maybeArray) ? maybeArray : [maybeArray];\n}\n\ntype PackageJson = Record<string, unknown>;\n\n/**\n * Get the closes package.json from a given starting point upwards.\n * This handles a few edge cases:\n * * Check if a given file package.json appears to be an actual NPM package.json file\n * * Stop at the home dir, to avoid looking too deeply\n */\nexport function getPackageJson({ cwd, stopAt }: { cwd?: string; stopAt?: string } = {}): PackageJson | undefined {\n return lookupPackageJson(cwd ?? process.cwd(), path.normalize(stopAt ?? os.homedir()));\n}\n\nexport function parseMajorVersion(ver: string): number | undefined {\n let version = ver;\n // if it has a `v` prefix, remove it\n if (version.startsWith('v')) {\n version = version.slice(1);\n }\n\n // First, try simple lookup of exact, ~ and ^ versions\n const regex = /^[\\^~]?(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n\n const match = version.match(regex);\n if (match) {\n return parseInt(match[1] as string, 10);\n }\n\n // Try to parse e.g. 1.x\n const coerced = parseInt(version, 10);\n if (!Number.isNaN(coerced)) {\n return coerced;\n }\n\n // Match <= and >= ranges.\n const gteLteRegex = /^[<>]=\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const gteLteMatch = version.match(gteLteRegex);\n if (gteLteMatch) {\n return parseInt(gteLteMatch[1] as string, 10);\n }\n\n // match < ranges\n const ltRegex = /^<\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const ltMatch = version.match(ltRegex);\n if (ltMatch) {\n // Two scenarios:\n // a) < 2.0.0 --> return 1\n // b) < 2.1.0 --> return 2\n\n const major = parseInt(ltMatch[1] as string, 10);\n\n if (\n // minor version > 0\n (typeof ltMatch[2] === 'string' && parseInt(ltMatch[2].slice(1), 10) > 0) ||\n // patch version > 0\n (typeof ltMatch[3] === 'string' && parseInt(ltMatch[3].slice(1), 10) > 0)\n ) {\n return major;\n }\n\n return major - 1;\n }\n\n // match > ranges\n const gtRegex = /^>\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const gtMatch = version.match(gtRegex);\n if (gtMatch) {\n // We always return the version here, even though it _may_ be incorrect\n // E.g. if given > 2.0.0, it should be 2 if there exists any 2.x.x version, else 3\n // Since there is no way for us to know this, we're going to assume any kind of patch/feature release probably exists\n return parseInt(gtMatch[1] as string, 10);\n }\n return undefined;\n}\n\n// This is an explicit list of packages where we want to include the (major) version number.\nconst PACKAGES_TO_INCLUDE_VERSION = [\n 'react',\n '@angular/core',\n 'vue',\n 'ember-source',\n 'svelte',\n '@sveltejs/kit',\n 'webpack',\n 'vite',\n 'gatsby',\n 'next',\n 'remix',\n 'rollup',\n 'esbuild',\n];\n\nexport function getDependencies(packageJson: PackageJson): {\n deps: string[];\n depsVersions: Record<string, number>;\n} {\n const dependencies: Record<string, string> = Object.assign(\n {},\n packageJson['devDependencies'] ?? {},\n packageJson['dependencies'] ?? {},\n );\n\n const deps = Object.keys(dependencies).sort();\n\n const depsVersions: Record<string, number> = deps.reduce(\n (depsVersions, depName) => {\n if (PACKAGES_TO_INCLUDE_VERSION.includes(depName)) {\n const version = dependencies[depName] as string;\n const majorVersion = parseMajorVersion(version);\n if (majorVersion) {\n depsVersions[depName] = majorVersion;\n }\n }\n return depsVersions;\n },\n {} as Record<string, number>,\n );\n\n return { deps, depsVersions };\n}\n\nfunction findPackageJson(cwd: string, stopAt: string): string | undefined {\n let dirName = path.resolve(cwd);\n\n for (;;) {\n // Stop if we reach this dir\n if (path.normalize(dirName) === stopAt) {\n return undefined;\n }\n\n const jsonPath = path.join(dirName, 'package.json');\n if (fs.existsSync(jsonPath)) {\n return jsonPath;\n }\n\n const parentDirName = path.dirname(dirName);\n // We reached the file system root\n if (parentDirName === dirName) {\n return undefined;\n }\n\n dirName = parentDirName;\n }\n}\n\nfunction lookupPackageJson(cwd: string, stopAt: string): PackageJson | undefined {\n const jsonPath = findPackageJson(cwd, stopAt);\n\n if (!jsonPath) {\n return undefined;\n }\n\n try {\n const jsonStr = fs.readFileSync(jsonPath, 'utf8');\n const json = JSON.parse(jsonStr) as PackageJson;\n\n // Ensure it is an actual package.json\n // This is very much not bulletproof, but should be good enough\n if ('name' in json || 'private' in json) {\n return json;\n }\n } catch {\n // Ignore and walk up\n }\n\n // Continue up the tree, if we find a fitting package.json\n const newCwd = path.dirname(path.resolve(`${jsonPath}/..`));\n return lookupPackageJson(newCwd, stopAt);\n}\n\n/**\n * Deterministically hashes a string and turns the hash into a uuid.\n */\nexport function stringToUUID(str: string): string {\n const sha256Hash = crypto.createHash('sha256').update(str).digest('hex');\n\n // Position 16 is fixed to either 8, 9, a, or b in the uuid v4 spec (10xx in binary)\n // RFC 4122 section 4.4\n const v4variant = ['8', '9', 'a', 'b'][sha256Hash.substring(16, 17).charCodeAt(0) % 4] as string;\n\n return `${sha256Hash.substring(0, 8)}-${sha256Hash.substring(8, 12)}-4${sha256Hash.substring(13, 16)}-${v4variant}${sha256Hash.substring(17, 20)}-${sha256Hash.substring(20, 32)}`.toLowerCase();\n}\n\nfunction gitRevision(): string | undefined {\n let gitRevision: string | undefined;\n try {\n gitRevision = childProcess\n .execSync('git rev-parse HEAD', { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true })\n .toString()\n .trim();\n } catch {\n // noop\n }\n return gitRevision;\n}\n\n// Mirrors the CLI's `set-commits --auto` fallback for builds without an `origin` remote. Vercel is left out\n// because the CLI only reads `VERCEL_GIT_*` on production builds.\nconst CI_REPOSITORY_ENV_VARS = [\n 'GITHUB_REPOSITORY',\n 'CI_PROJECT_PATH',\n 'BITBUCKET_REPO_FULL_NAME',\n 'RENDER_GIT_REPO_SLUG',\n 'RAILWAY_GIT_REPO_NAME',\n 'CIRCLE_PROJECT_REPONAME',\n 'BUILDKITE_REPO',\n 'BUILD_REPOSITORY_URI',\n] as const;\n\n/**\n * Whether `set-commits --auto` can find the repository: from the `origin` git remote, or from CI variables.\n */\nexport function canAutoDetectRepository(): boolean {\n if (\n CI_REPOSITORY_ENV_VARS.some(name => process.env[name]) ||\n (process.env['NETLIFY'] && process.env['REPOSITORY_URL'])\n ) {\n return true;\n }\n try {\n childProcess.execSync('git remote get-url origin', { stdio: 'ignore', windowsHide: true });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Tries to guess a release name based on environmental data.\n */\nexport function determineReleaseName(): string | undefined {\n return getReleaseFromCommitEnv(warnAboutPlaceholderCommitEnvVar) || gitRevision();\n}\n\n// Release detection and commit association can read the same variable in one build.\nconst warnedPlaceholderEnvVars = new Set<string>();\n\nfunction warnAboutPlaceholderCommitEnvVar(name: string): void {\n if (warnedPlaceholderEnvVars.has(name)) {\n return;\n }\n warnedPlaceholderEnvVars.add(name);\n // This runs before the plugin logger exists, so `silent: true` does not suppress it. That is\n // deliberate: a warning that is easy to miss is how this misconfiguration went unnoticed.\n // eslint-disable-next-line no-console\n console.warn(\n `[@sentry/bundler-plugins] Ignoring the ${name} environment variable as a release name, because its value is its own name. Set the release explicitly, or fix the variable in your build environment.`,\n );\n}\n\n/**\n * Reads an environment variable that should hold a commit SHA, ignoring a value that is the\n * variable's own name. See `_INTERNAL_readCommitEnvVar` in `@sentry/core/server`.\n */\nexport function readCommitEnvVar(name: string): string | undefined {\n return readCoreCommitEnvVar(name, warnAboutPlaceholderCommitEnvVar);\n}\n\n/**\n * Generates code for the global injector which is responsible for setting the global\n * `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.\n */\nexport function generateReleaseInjectorCode({\n release,\n injectBuildInformation,\n}: {\n release: string;\n injectBuildInformation: boolean;\n}): CodeInjection {\n let code = `e.SENTRY_RELEASE={id:${stringifyForCodeInjection(release)}};`;\n\n if (injectBuildInformation) {\n const buildInfo = getBuildInformation();\n\n code += `e.SENTRY_BUILD_INFO=${stringifyForCodeInjection(buildInfo)};`;\n }\n\n return new CodeInjection(code);\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function generateModuleMetadataInjectorCode(metadata: any): CodeInjection {\n // We are merging the metadata objects in case modules are bundled twice with the plugin\n // Use try-catch to avoid issues when bundlers rename global variables like 'window' to 'k'\n return new CodeInjection(\n `e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${stringifyForCodeInjection(\n metadata,\n )});`,\n );\n}\n\nexport function getBuildInformation(): {\n deps: string[];\n depsVersions: Record<string, number>;\n nodeVersion: number | undefined;\n} {\n const packageJson = getPackageJson();\n\n const { deps, depsVersions } = packageJson ? getDependencies(packageJson) : { deps: [], depsVersions: {} };\n\n return {\n deps,\n depsVersions,\n nodeVersion: parseMajorVersion(process.version),\n };\n}\n\nexport function stripQueryAndHashFromPath(path: string): string {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return path.split('?')[0]!.split('#')[0]!;\n}\n\nexport function replaceBooleanFlagsInCode(\n code: string,\n replacementValues: Record<string, boolean | undefined>,\n): { code: string; map: SourceMap } | null {\n const ms = new MagicString(code);\n\n Object.keys(replacementValues).forEach(key => {\n const value = replacementValues[key];\n\n if (typeof value === 'boolean') {\n ms.replaceAll(key, JSON.stringify(value));\n }\n });\n\n if (ms.hasChanged()) {\n return {\n code: ms.toString(),\n map: ms.generateMap({ hires: 'boundary' }),\n };\n }\n\n return null;\n}\n\n// https://turbo.build/repo/docs/reference/system-environment-variables#environment-variables-in-tasks\nexport function getTurborepoEnvPassthroughWarning(envVarName: string): string {\n return process.env['TURBO_HASH']\n ? `\\nYou seem to be using Turborepo, did you forget to put ${envVarName} in \\`passThroughEnv\\`? https://turbo.build/repo/docs/reference/configuration#passthroughenv`\n : '';\n}\n\n/**\n * Gets the projects from the project option. This might be a single project or an array of projects.\n */\nexport function getProjects(project: string | string[] | undefined): string[] | undefined {\n if (Array.isArray(project)) {\n return project;\n }\n\n if (project) {\n return [project];\n }\n\n return undefined;\n}\n\n/**\n * Checks if a chunk contains only import/export statements and no substantial code.\n *\n * In Vite MPA (multi-page application) mode, HTML entry points create \"facade\" chunks\n * that only contain import statements to load shared modules. These should not have\n * Sentry code injected. However, in SPA mode, the main bundle also has an HTML facade\n * but contains substantial application code that SHOULD have debug IDs injected.\n *\n * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/839\n */\nexport function containsOnlyImports(code: string): boolean {\n const codeWithoutImports = code\n // Remove side effect imports: import '/path'; or import \"./path\";\n // Using explicit negated character classes to avoid polynomial backtracking\n .replace(/^\\s*import\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove named/default imports: import x from '/path'; import { x } from '/path';\n .replace(/^\\s*import\\b[^'\"`\\n]*\\bfrom\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove re-exports: export * from '/path'; export { x } from '/path';\n .replace(/^\\s*export\\b[^'\"`\\n]*\\bfrom\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove block comments\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n // Remove line comments\n .replace(/\\/\\/.*$/gm, '')\n // Remove \"use strict\" directives\n .replace(/[\"']use strict[\"']\\s*;?/g, '')\n .trim();\n\n return codeWithoutImports.length === 0;\n}\n\nexport class CodeInjection {\n // The code below is mostly ternary operators because it saves bundle size.\n // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)\n private readonly header: string;\n private readonly footer: string;\n\n constructor(private body: string = '') {\n // `globalThis` is checked first so the other identifiers are never evaluated\n // where it exists. A downstream bundler that runs over an already-injected\n // chunk can turn a free `global` into a `const` it declares further down the\n // file (Nitro's node compat does this). Reading that binding from the top of\n // the file hits the temporal dead zone, and `typeof` throws there instead of\n // returning \"undefined\", so the whole injection was silently swallowed by the\n // `catch` below and the chunk registered no debug ID.\n this.header = `!function(){try{var e=\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof self?self:{};`;\n this.footer = '}catch(e){}}();';\n }\n\n public code(): string {\n if (this.isEmpty()) {\n return '';\n }\n\n return this.header + this.body + this.footer;\n }\n\n public isEmpty(): boolean {\n return this.body.length === 0;\n }\n\n public append(code: CodeInjection | string): void {\n if (code instanceof CodeInjection) {\n this.body += code.body;\n } else {\n this.body += code;\n }\n }\n\n public clear(): void {\n this.body = '';\n }\n\n public clone(): CodeInjection {\n return new CodeInjection(this.body);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,SAAsB,YAA0B;CAC9D,OAAO,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,UAAU;AAC7D;;;;;;;AAUA,SAAgB,eAAe,EAAE,KAAK,WAA8C,CAAC,GAA4B;CAC/G,OAAO,kBAAkB,OAAO,QAAQ,IAAI,GAAGA,KAAAA,QAAK,UAAU,UAAUC,GAAAA,QAAG,QAAQ,CAAC,CAAC;AACvF;AAEA,SAAgB,kBAAkB,KAAiC;CACjE,IAAI,UAAU;CAEd,IAAI,QAAQ,WAAW,GAAG,GACxB,UAAU,QAAQ,MAAM,CAAC;CAM3B,MAAM,QAAQ,QAAQ,M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Ae;EACpB,IAAI,KAAK,QAAQ,GACf,OAAO;EAGT,OAAO,KAAK,SAAS,KAAK,OAAO,KAAK;CACxC;CAEO,UAAmB;EACxB,OAAO,KAAK,KAAK,WAAW;CAC9B;CAEO,OAAO,MAAoC;EAChD,IAAI,gBAAgB,eAClB,KAAK,QAAQ,KAAK;OAElB,KAAK,QAAQ;CAEjB;CAEO,QAAc;EACnB,KAAK,OAAO;CACd;CAEO,QAAuB;EAC5B,OAAO,IAAI,cAAc,KAAK,IAAI;CACpC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.14.0\";\n"],"mappings":";AAAA,MAAa,cAAc"}
|
|
@@ -7,6 +7,7 @@ const require_utils = require("../core/utils.js");
|
|
|
7
7
|
const require_debug_id_upload = require("../core/debug-id-upload.js");
|
|
8
8
|
const require_build_plugin_manager = require("../core/build-plugin-manager.js");
|
|
9
9
|
const require_index = require("../core/index.js");
|
|
10
|
+
let _sentry_core = require("@sentry/core");
|
|
10
11
|
let node_path = require("node:path");
|
|
11
12
|
node_path = require_runtime.__toESM(node_path);
|
|
12
13
|
let node_module = require("node:module");
|
|
@@ -119,9 +120,9 @@ function sentryEsbuildPlugin(userOptions = {}) {
|
|
|
119
120
|
pluginName,
|
|
120
121
|
contents: `
|
|
121
122
|
import "_sentry-debug-id-injection-stub";
|
|
122
|
-
import * as OriginalModule from ${
|
|
123
|
+
import * as OriginalModule from ${(0, _sentry_core.stringifyForCodeInjection)(originalPath)};
|
|
123
124
|
export default OriginalModule.default;
|
|
124
|
-
export * from ${
|
|
125
|
+
export * from ${(0, _sentry_core.stringifyForCodeInjection)(originalPath)};`,
|
|
125
126
|
resolveDir: originalResolveDir
|
|
126
127
|
};
|
|
127
128
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["createRequire","createSentryBuildPluginManager","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","path","randomUUID","getDebugIdSnippet","createDebugIdUploadFunction","isJsFile","addDebugIdToEmittedArtifacts"],"sources":["../../../src/esbuild/index.ts"],"sourcesContent":["import type { InternalOptions, SourceMapDecision, SourceMapKind } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n CodeInjection,\n addDebugIdToEmittedArtifacts,\n isJsFile,\n} from '../core';\nimport * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\n\ninterface EsbuildOnResolveArgs {\n path: string;\n kind: string;\n importer?: string;\n resolveDir: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnResolveResult {\n path: string;\n sideEffects?: boolean;\n pluginName?: string;\n namespace?: string;\n suffix?: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadArgs {\n path: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadResult {\n loader: string;\n pluginName: string;\n contents: string;\n resolveDir?: string;\n}\n\ninterface EsbuildOnEndArgs {\n metafile?: {\n outputs: Record<string, unknown>;\n };\n}\n\ntype EsbuildSourceMapSetting = boolean | 'inline' | 'external' | 'linked' | 'both' | undefined;\n\ninterface EsbuildInitialOptions {\n bundle?: boolean;\n inject?: string[];\n metafile?: boolean;\n define?: Record<string, string>;\n write?: boolean;\n absWorkingDir?: string;\n logOverride?: Record<string, string>;\n sourcemap?: EsbuildSourceMapSetting;\n}\n\n/** Maps esbuild's `sourcemap` setting onto the plugin's source map kinds. */\nfunction sourceMapKindFromEsbuildSetting(setting: EsbuildSourceMapSetting): SourceMapKind {\n switch (setting) {\n case undefined:\n return 'unset';\n case false:\n return 'off';\n case 'external':\n return 'hidden';\n case 'inline':\n case 'both':\n return 'inline';\n default:\n return 'visible';\n }\n}\n\ninterface EsbuildPluginBuild {\n initialOptions: EsbuildInitialOptions;\n onLoad: (\n options: { filter: RegExp; namespace?: string },\n callback: (args: EsbuildOnLoadArgs) => EsbuildOnLoadResult | null,\n ) => void;\n onResolve: (\n options: { filter: RegExp },\n callback: (args: EsbuildOnResolveArgs) => EsbuildOnResolveResult | undefined,\n ) => void;\n onStart: (callback: () => void) => void;\n onEnd: (callback: (result: EsbuildOnEndArgs) => void | Promise<void>) => void;\n}\n\nfunction getEsbuildMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - esbuild transpiles this for us\n const req = createRequire(import.meta.url);\n const esbuild = req('esbuild') as { version?: string };\n // esbuild hasn't released a v1 yet, so we'll return the minor version as the major version\n return esbuild.version?.split('.')[1];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nconst pluginName = 'sentry-esbuild-plugin';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function sentryEsbuildPlugin(userOptions: InternalOptions = {}): any {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,\n buildTool: 'esbuild',\n buildToolMajorVersion: getEsbuildMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n name: 'sentry-esbuild-noop-plugin',\n setup() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n // Component annotation warning\n if (options.reactComponentAnnotation?.enabled) {\n logger.warn(\n 'Component name annotation is not supported in esbuild. Please use a separate transform step or consider using a different bundler.',\n );\n }\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n // Track entry points wrapped for debug ID injection\n const debugIdWrappedPaths = new Set<string>();\n\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n return {\n name: pluginName,\n setup({ initialOptions, onLoad, onResolve, onStart, onEnd }: EsbuildPluginBuild) {\n // Release and/or metadata injection\n if (!staticInjectionCode.isEmpty()) {\n const virtualInjectionFilePath = path.resolve('_sentry-injection-stub');\n initialOptions.inject = initialOptions.inject || [];\n // esbuild emits injected files after an entry's directive prologue. A banner would precede\n // \"use strict\" and turn it into an ordinary string expression.\n initialOptions.inject.push(virtualInjectionFilePath);\n\n onResolve({ filter: /_sentry-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n };\n });\n\n onLoad({ filter: /_sentry-injection-stub/ }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: staticInjectionCode.code(),\n };\n });\n }\n\n // Bundle size optimizations\n if (transformReplace) {\n const replacementStringValues: Record<string, string> = {};\n Object.entries(replacementValues).forEach(([key, value]) => {\n replacementStringValues[key] = JSON.stringify(value);\n });\n\n initialOptions.define = { ...initialOptions.define, ...replacementStringValues };\n }\n\n // Debug ID injection - requires per-entry-point unique IDs\n if (sourcemapsEnabled) {\n // `setup` runs once per context, `onStart` once per build, so a\n // rebuild wraps the entry points again.\n onStart(() => debugIdWrappedPaths.clear());\n\n // The proxy module re-exports `OriginalModule.default` statically so downstream bundlers can tree-shake it,\n // but esbuild warns about that access when the entry point has no default export.\n initialOptions.logOverride = { 'import-is-undefined': 'silent', ...initialOptions.logOverride };\n\n if (!initialOptions.bundle) {\n logger.warn(\n 'The Sentry esbuild plugin only supports esbuild with `bundle: true` being set in the esbuild build options. Esbuild will probably crash now. Sorry about that. If you need to upload sourcemaps without `bundle: true`, it is recommended to use Sentry CLI instead: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/',\n );\n }\n\n // Wrap entry points to inject debug IDs\n onResolve({ filter: /.*/ }, args => {\n if (args.kind !== 'entry-point') {\n return;\n }\n\n // Skip injecting debug IDs into modules specified in the esbuild `inject` option\n // since they're already part of the entry points\n if (initialOptions.inject?.includes(args.path)) {\n return;\n }\n\n const resolvedPath = path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path);\n\n // Skip injecting debug IDs into paths that have already been wrapped\n if (debugIdWrappedPaths.has(resolvedPath)) {\n return;\n }\n debugIdWrappedPaths.add(resolvedPath);\n\n return {\n pluginName,\n path: resolvedPath,\n pluginData: {\n isDebugIdProxy: true,\n originalPath: args.path,\n originalResolveDir: args.resolveDir,\n },\n // We need to add a suffix here, otherwise esbuild will mark the entrypoint as resolved and won't traverse\n // the module tree any further down past the proxy module because we're essentially creating a dependency\n // loop back to the proxy module.\n // By setting a suffix we're telling esbuild that the entrypoint and proxy module are two different things,\n // making it re-resolve the entrypoint when it is imported from the proxy module.\n // Super confusing? Yes. Works? Apparently... Let's see.\n suffix: '?sentryDebugIdProxy=true',\n };\n });\n\n onLoad({ filter: /.*/ }, args => {\n if (!(args.pluginData as { isDebugIdProxy?: boolean })?.isDebugIdProxy) {\n return null;\n }\n\n const originalPath = (args.pluginData as { originalPath: string }).originalPath;\n const originalResolveDir = (args.pluginData as { originalResolveDir: string }).originalResolveDir;\n\n return {\n loader: 'js',\n pluginName,\n contents: `\n import \"_sentry-debug-id-injection-stub\";\n import * as OriginalModule from ${JSON.stringify(originalPath)};\n export default OriginalModule.default;\n export * from ${JSON.stringify(originalPath)};`,\n resolveDir: originalResolveDir,\n };\n });\n\n onResolve({ filter: /_sentry-debug-id-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n namespace: 'sentry-debug-id-stub',\n suffix: `?sentry-module-id=${randomUUID()}`,\n };\n });\n\n onLoad({ filter: /_sentry-debug-id-injection-stub/, namespace: 'sentry-debug-id-stub' }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: getDebugIdSnippet(randomUUID()).code(),\n };\n });\n }\n\n // With `write: false` nothing reaches the disk, so nothing can be uploaded or deleted.\n const sourceMapKind = sourceMapKindFromEsbuildSetting(initialOptions.sourcemap);\n const sourceMapDecision: SourceMapDecision =\n initialOptions.write === false\n ? { enableHidden: false, deleteAfterUpload: false }\n : sentryBuildPluginManager.sourceMaps.decide(sourceMapKind);\n if (sourceMapDecision.enableHidden) {\n initialOptions.sourcemap = 'external';\n }\n\n // Create release and optionally upload\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n initialOptions.metafile = true;\n onEnd(async result => {\n try {\n await sentryBuildPluginManager.createRelease();\n\n // The metafile lists outputs relative to `absWorkingDir`, not to the process.\n const outputDir = initialOptions.absWorkingDir ?? process.cwd();\n const buildArtifacts = result.metafile\n ? Object.keys(result.metafile.outputs).map(output => path.resolve(outputDir, output))\n : [];\n\n const { sourceMaps } = sentryBuildPluginManager;\n const allMaps = buildArtifacts.filter(artifact => artifact.endsWith('.map'));\n const deleteWithoutUpload = sourceMapDecision.deleteAfterUpload && !sourceMaps.uploadPossible;\n if (sourcemapsEnabled && options.sourcemaps?.disable === 'disable-upload') {\n if (initialOptions.write === false) {\n logger.debug('Build output is not written to disk. Skipping debug ID injection into build artifacts.');\n } else {\n // The upload routine (which stamps debug IDs into temp copies of the artifacts) is\n // skipped with `disable-upload`. esbuild has no hook to modify outputs before they are\n // written, so the emitted artifacts get stamped on disk instead.\n await Promise.all(\n buildArtifacts\n .filter(isJsFile)\n .map(bundle => addDebugIdToEmittedArtifacts(bundle, logger, options.sourcemaps?.resolveSourceMap)),\n );\n }\n } else if (sourcemapsEnabled) {\n // The upload globs the paths, and glob reads backslashes as escapes.\n // When no upload can run, this logs why.\n const { uploaded, uploadedSourceMapPaths } = await upload(\n buildArtifacts.map(artifact => artifact.split(path.sep).join('/')),\n );\n\n // esbuild writes before `onEnd` runs, so the maps are deleted from disk\n // afterwards instead of being dropped from the output like in other bundlers.\n // A map the plugin turned on never stays in the output. A map the user\n // enabled is only deleted once it was uploaded.\n if (sourceMapDecision.deleteAfterUpload && !deleteWithoutUpload) {\n const mapsToDelete = sourceMapDecision.removeAllSourceMaps ? allMaps : uploadedSourceMapPaths;\n\n if (uploaded) {\n await sourceMaps.deleteFromOutput(mapsToDelete);\n } else if (mapsToDelete.length > 0) {\n logger.error('The source maps were not uploaded, so they stay in the build output.');\n }\n }\n }\n\n if (deleteWithoutUpload) {\n const bundleOf = (map: string): string => map.slice(0, -'.map'.length);\n const isUploaded = (map: string): boolean =>\n isJsFile(bundleOf(map)) && sourceMaps.shouldUpload(bundleOf(map));\n await sourceMaps.deleteFromOutput(\n sourceMapDecision.removeAllSourceMaps ? allMaps : allMaps.filter(isUploaded),\n );\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n });\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default sentryEsbuildPlugin;\nexport type { Options as SentryEsbuildPluginOptions } from '../core';\n"],"mappings":";;;;;;;;;;;;;;;AAgEA,SAAS,gCAAgC,SAAiD;CACxF,QAAQ,SAAR;EACE,KAAK,KAAA,GACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK;EACL,KAAK,QACH,OAAO;EACT,SACE,OAAO;CACX;AACF;A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Ae;KACvB,MAAM,UAAU,eAAe,QAAO,aAAY,SAAS,SAAS,MAAM,CAAC;KAC3E,MAAM,sBAAsB,kBAAkB,qBAAqB,CAAC,WAAW;KAC/E,IAAI,qBAAqB,QAAQ,YAAY,YAAY,kBAAkB;MACzE,IAAI,eAAe,UAAU,OAC3B,OAAO,MAAM,wFAAwF;WAKrG,MAAM,QAAQ,IACZ,eACG,OAAOI,cAAAA,QAAQ,CAAC,CAChB,KAAI,WAAUC,wBAAAA,6BAA6B,QAAQ,QAAQ,QAAQ,YAAY,gBAAgB,CAAC,CACrG;KAEJ,OAAO,IAAI,mBAAmB;MAG5B,MAAM,EAAE,UAAU,2BAA2B,MAAM,OACjD,eAAe,KAAI,aAAY,SAAS,MAAML,UAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CACnE;MAMA,IAAI,kBAAkB,qBAAqB,CAAC,qBAAqB;OAC/D,MAAM,eAAe,kBAAkB,sBAAsB,UAAU;OAEvE,IAAI,UACF,MAAM,WAAW,iBAAiB,YAAY;YACzC,IAAI,aAAa,SAAS,GAC/B,OAAO,MAAM,sEAAsE;MAEvF;KACF;KAEA,IAAI,qBAAqB;MACvB,MAAM,YAAY,QAAwB,IAAI,MAAM,GAAG,EAAc;MACrE,MAAM,cAAc,QAClBI,cAAAA,SAAS,SAAS,GAAG,CAAC,KAAK,WAAW,aAAa,SAAS,GAAG,CAAC;MAClE,MAAM,WAAW,iBACf,kBAAkB,sBAAsB,UAAU,QAAQ,OAAO,UAAU,CAC7E;KACF;IACF,UAAU;KACR,qCAAqC;KACrC,MAAM,yBAAyB,gBAAgB;IACjD;GACF,CAAC;EACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["createRequire","createSentryBuildPluginManager","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","path","stringifyForCodeInjection","randomUUID","getDebugIdSnippet","createDebugIdUploadFunction","isJsFile","addDebugIdToEmittedArtifacts"],"sources":["../../../src/esbuild/index.ts"],"sourcesContent":["/* oxlint-disable max-lines */\nimport type { InternalOptions, SourceMapDecision, SourceMapKind } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n CodeInjection,\n addDebugIdToEmittedArtifacts,\n isJsFile,\n} from '../core';\nimport * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\nimport { stringifyForCodeInjection } from '@sentry/core';\n\ninterface EsbuildOnResolveArgs {\n path: string;\n kind: string;\n importer?: string;\n resolveDir: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnResolveResult {\n path: string;\n sideEffects?: boolean;\n pluginName?: string;\n namespace?: string;\n suffix?: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadArgs {\n path: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadResult {\n loader: string;\n pluginName: string;\n contents: string;\n resolveDir?: string;\n}\n\ninterface EsbuildOnEndArgs {\n metafile?: {\n outputs: Record<string, unknown>;\n };\n}\n\ntype EsbuildSourceMapSetting = boolean | 'inline' | 'external' | 'linked' | 'both' | undefined;\n\ninterface EsbuildInitialOptions {\n bundle?: boolean;\n inject?: string[];\n metafile?: boolean;\n define?: Record<string, string>;\n write?: boolean;\n absWorkingDir?: string;\n logOverride?: Record<string, string>;\n sourcemap?: EsbuildSourceMapSetting;\n}\n\n/** Maps esbuild's `sourcemap` setting onto the plugin's source map kinds. */\nfunction sourceMapKindFromEsbuildSetting(setting: EsbuildSourceMapSetting): SourceMapKind {\n switch (setting) {\n case undefined:\n return 'unset';\n case false:\n return 'off';\n case 'external':\n return 'hidden';\n case 'inline':\n case 'both':\n return 'inline';\n default:\n return 'visible';\n }\n}\n\ninterface EsbuildPluginBuild {\n initialOptions: EsbuildInitialOptions;\n onLoad: (\n options: { filter: RegExp; namespace?: string },\n callback: (args: EsbuildOnLoadArgs) => EsbuildOnLoadResult | null,\n ) => void;\n onResolve: (\n options: { filter: RegExp },\n callback: (args: EsbuildOnResolveArgs) => EsbuildOnResolveResult | undefined,\n ) => void;\n onStart: (callback: () => void) => void;\n onEnd: (callback: (result: EsbuildOnEndArgs) => void | Promise<void>) => void;\n}\n\nfunction getEsbuildMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - esbuild transpiles this for us\n const req = createRequire(import.meta.url);\n const esbuild = req('esbuild') as { version?: string };\n // esbuild hasn't released a v1 yet, so we'll return the minor version as the major version\n return esbuild.version?.split('.')[1];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nconst pluginName = 'sentry-esbuild-plugin';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function sentryEsbuildPlugin(userOptions: InternalOptions = {}): any {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,\n buildTool: 'esbuild',\n buildToolMajorVersion: getEsbuildMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n name: 'sentry-esbuild-noop-plugin',\n setup() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n // Component annotation warning\n if (options.reactComponentAnnotation?.enabled) {\n logger.warn(\n 'Component name annotation is not supported in esbuild. Please use a separate transform step or consider using a different bundler.',\n );\n }\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n // Track entry points wrapped for debug ID injection\n const debugIdWrappedPaths = new Set<string>();\n\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n return {\n name: pluginName,\n setup({ initialOptions, onLoad, onResolve, onStart, onEnd }: EsbuildPluginBuild) {\n // Release and/or metadata injection\n if (!staticInjectionCode.isEmpty()) {\n const virtualInjectionFilePath = path.resolve('_sentry-injection-stub');\n initialOptions.inject = initialOptions.inject || [];\n // esbuild emits injected files after an entry's directive prologue. A banner would precede\n // \"use strict\" and turn it into an ordinary string expression.\n initialOptions.inject.push(virtualInjectionFilePath);\n\n onResolve({ filter: /_sentry-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n };\n });\n\n onLoad({ filter: /_sentry-injection-stub/ }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: staticInjectionCode.code(),\n };\n });\n }\n\n // Bundle size optimizations\n if (transformReplace) {\n const replacementStringValues: Record<string, string> = {};\n Object.entries(replacementValues).forEach(([key, value]) => {\n replacementStringValues[key] = JSON.stringify(value);\n });\n\n initialOptions.define = { ...initialOptions.define, ...replacementStringValues };\n }\n\n // Debug ID injection - requires per-entry-point unique IDs\n if (sourcemapsEnabled) {\n // `setup` runs once per context, `onStart` once per build, so a\n // rebuild wraps the entry points again.\n onStart(() => debugIdWrappedPaths.clear());\n\n // The proxy module re-exports `OriginalModule.default` statically so downstream bundlers can tree-shake it,\n // but esbuild warns about that access when the entry point has no default export.\n initialOptions.logOverride = { 'import-is-undefined': 'silent', ...initialOptions.logOverride };\n\n if (!initialOptions.bundle) {\n logger.warn(\n 'The Sentry esbuild plugin only supports esbuild with `bundle: true` being set in the esbuild build options. Esbuild will probably crash now. Sorry about that. If you need to upload sourcemaps without `bundle: true`, it is recommended to use Sentry CLI instead: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/',\n );\n }\n\n // Wrap entry points to inject debug IDs\n onResolve({ filter: /.*/ }, args => {\n if (args.kind !== 'entry-point') {\n return;\n }\n\n // Skip injecting debug IDs into modules specified in the esbuild `inject` option\n // since they're already part of the entry points\n if (initialOptions.inject?.includes(args.path)) {\n return;\n }\n\n const resolvedPath = path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path);\n\n // Skip injecting debug IDs into paths that have already been wrapped\n if (debugIdWrappedPaths.has(resolvedPath)) {\n return;\n }\n debugIdWrappedPaths.add(resolvedPath);\n\n return {\n pluginName,\n path: resolvedPath,\n pluginData: {\n isDebugIdProxy: true,\n originalPath: args.path,\n originalResolveDir: args.resolveDir,\n },\n // We need to add a suffix here, otherwise esbuild will mark the entrypoint as resolved and won't traverse\n // the module tree any further down past the proxy module because we're essentially creating a dependency\n // loop back to the proxy module.\n // By setting a suffix we're telling esbuild that the entrypoint and proxy module are two different things,\n // making it re-resolve the entrypoint when it is imported from the proxy module.\n // Super confusing? Yes. Works? Apparently... Let's see.\n suffix: '?sentryDebugIdProxy=true',\n };\n });\n\n onLoad({ filter: /.*/ }, args => {\n if (!(args.pluginData as { isDebugIdProxy?: boolean })?.isDebugIdProxy) {\n return null;\n }\n\n const originalPath = (args.pluginData as { originalPath: string }).originalPath;\n const originalResolveDir = (args.pluginData as { originalResolveDir: string }).originalResolveDir;\n\n return {\n loader: 'js',\n pluginName,\n contents: `\n import \"_sentry-debug-id-injection-stub\";\n import * as OriginalModule from ${stringifyForCodeInjection(originalPath)};\n export default OriginalModule.default;\n export * from ${stringifyForCodeInjection(originalPath)};`,\n resolveDir: originalResolveDir,\n };\n });\n\n onResolve({ filter: /_sentry-debug-id-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n namespace: 'sentry-debug-id-stub',\n suffix: `?sentry-module-id=${randomUUID()}`,\n };\n });\n\n onLoad({ filter: /_sentry-debug-id-injection-stub/, namespace: 'sentry-debug-id-stub' }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: getDebugIdSnippet(randomUUID()).code(),\n };\n });\n }\n\n // With `write: false` nothing reaches the disk, so nothing can be uploaded or deleted.\n const sourceMapKind = sourceMapKindFromEsbuildSetting(initialOptions.sourcemap);\n const sourceMapDecision: SourceMapDecision =\n initialOptions.write === false\n ? { enableHidden: false, deleteAfterUpload: false }\n : sentryBuildPluginManager.sourceMaps.decide(sourceMapKind);\n if (sourceMapDecision.enableHidden) {\n initialOptions.sourcemap = 'external';\n }\n\n // Create release and optionally upload\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n initialOptions.metafile = true;\n onEnd(async result => {\n try {\n await sentryBuildPluginManager.createRelease();\n\n // The metafile lists outputs relative to `absWorkingDir`, not to the process.\n const outputDir = initialOptions.absWorkingDir ?? process.cwd();\n const buildArtifacts = result.metafile\n ? Object.keys(result.metafile.outputs).map(output => path.resolve(outputDir, output))\n : [];\n\n const { sourceMaps } = sentryBuildPluginManager;\n const allMaps = buildArtifacts.filter(artifact => artifact.endsWith('.map'));\n const deleteWithoutUpload = sourceMapDecision.deleteAfterUpload && !sourceMaps.uploadPossible;\n if (sourcemapsEnabled && options.sourcemaps?.disable === 'disable-upload') {\n if (initialOptions.write === false) {\n logger.debug('Build output is not written to disk. Skipping debug ID injection into build artifacts.');\n } else {\n // The upload routine (which stamps debug IDs into temp copies of the artifacts) is\n // skipped with `disable-upload`. esbuild has no hook to modify outputs before they are\n // written, so the emitted artifacts get stamped on disk instead.\n await Promise.all(\n buildArtifacts\n .filter(isJsFile)\n .map(bundle => addDebugIdToEmittedArtifacts(bundle, logger, options.sourcemaps?.resolveSourceMap)),\n );\n }\n } else if (sourcemapsEnabled) {\n // The upload globs the paths, and glob reads backslashes as escapes.\n // When no upload can run, this logs why.\n const { uploaded, uploadedSourceMapPaths } = await upload(\n buildArtifacts.map(artifact => artifact.split(path.sep).join('/')),\n );\n\n // esbuild writes before `onEnd` runs, so the maps are deleted from disk\n // afterwards instead of being dropped from the output like in other bundlers.\n // A map the plugin turned on never stays in the output. A map the user\n // enabled is only deleted once it was uploaded.\n if (sourceMapDecision.deleteAfterUpload && !deleteWithoutUpload) {\n const mapsToDelete = sourceMapDecision.removeAllSourceMaps ? allMaps : uploadedSourceMapPaths;\n\n if (uploaded) {\n await sourceMaps.deleteFromOutput(mapsToDelete);\n } else if (mapsToDelete.length > 0) {\n logger.error('The source maps were not uploaded, so they stay in the build output.');\n }\n }\n }\n\n if (deleteWithoutUpload) {\n const bundleOf = (map: string): string => map.slice(0, -'.map'.length);\n const isUploaded = (map: string): boolean =>\n isJsFile(bundleOf(map)) && sourceMaps.shouldUpload(bundleOf(map));\n await sourceMaps.deleteFromOutput(\n sourceMapDecision.removeAllSourceMaps ? allMaps : allMaps.filter(isUploaded),\n );\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n });\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default sentryEsbuildPlugin;\nexport type { Options as SentryEsbuildPluginOptions } from '../core';\n"],"mappings":";;;;;;;;;;;;;;;;AAkEA,SAAS,gCAAgC,SAAiD;CACxF,QAAQ,SAAR;EACE,KAAK,KAAA,GACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK;EACL,KAAK,QACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAgBA,SAAS,yBAA6C;CACpD,IAAI;EAMF,QAAA,GAHYA,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IACM,CAAC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,CAAC,WAAW;KAC/E,IAAI,qBAAqB,QAAQ,YAAY,YAAY,kBAAkB;MACzE,IAAI,eAAe,UAAU,OAC3B,OAAO,MAAM,wFAAwF;WAKrG,MAAM,QAAQ,IACZ,eACG,OAAOK,cAAAA,QAAQ,CAAC,CAChB,KAAI,WAAUC,wBAAAA,6BAA6B,QAAQ,QAAQ,QAAQ,YAAY,gBAAgB,CAAC,CACrG;KAEJ,OAAO,IAAI,mBAAmB;MAG5B,MAAM,EAAE,UAAU,2BAA2B,MAAM,OACjD,eAAe,KAAI,aAAY,SAAS,MAAMN,UAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CACnE;MAMA,IAAI,kBAAkB,qBAAqB,CAAC,qBAAqB;OAC/D,MAAM,eAAe,kBAAkB,sBAAsB,UAAU;OAEvE,IAAI,UACF,MAAM,WAAW,iBAAiB,YAAY;YACzC,IAAI,aAAa,SAAS,GAC/B,OAAO,MAAM,sEAAsE;MAEvF;KACF;KAEA,IAAI,qBAAqB;MACvB,MAAM,YAAY,QAAwB,IAAI,MAAM,GAAG,EAAc;MACrE,MAAM,cAAc,QAClBK,cAAAA,SAAS,SAAS,GAAG,CAAC,KAAK,WAAW,aAAa,SAAS,GAAG,CAAC;MAClE,MAAM,WAAW,iBACf,kBAAkB,sBAAsB,UAAU,QAAQ,OAAO,UAAU,CAC7E;KACF;IACF,UAAU;KACR,qCAAqC;KACrC,MAAM,yBAAyB,gBAAgB;IACjD;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -11,8 +11,8 @@ import { LIB_VERSION } from "./version.js";
|
|
|
11
11
|
import * as path from "path";
|
|
12
12
|
import * as fs from "fs";
|
|
13
13
|
import * as os from "os";
|
|
14
|
-
import { escape } from "glob";
|
|
15
14
|
import { DEFAULT_ENVIRONMENT, closeSession, makeSession, setMeasurement, startSpan } from "@sentry/core";
|
|
15
|
+
import { escape } from "glob";
|
|
16
16
|
import * as dotenv from "dotenv";
|
|
17
17
|
// src/core/build-plugin-manager.ts
|
|
18
18
|
const _deployedReleases = /* @__PURE__ */ new Set();
|
package/build/esm/core/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ import crypto from "crypto";
|
|
|
5
5
|
import childProcess from "child_process";
|
|
6
6
|
import MagicString from "magic-string";
|
|
7
7
|
import { _INTERNAL_getReleaseFromCommitEnv, _INTERNAL_readCommitEnvVar } from "@sentry/core/server";
|
|
8
|
+
import { stringifyForCodeInjection } from "@sentry/core";
|
|
8
9
|
// src/core/utils.ts
|
|
9
10
|
/**
|
|
10
11
|
* Checks whether the given input is already an array, and if it isn't, wraps it in one.
|
|
@@ -164,9 +165,6 @@ function warnAboutPlaceholderCommitEnvVar(name) {
|
|
|
164
165
|
function readCommitEnvVar(name) {
|
|
165
166
|
return _INTERNAL_readCommitEnvVar(name, warnAboutPlaceholderCommitEnvVar);
|
|
166
167
|
}
|
|
167
|
-
function stringifyForCodeInjection(value) {
|
|
168
|
-
return JSON.stringify(value)?.replace(/</g, "\\u003c");
|
|
169
|
-
}
|
|
170
168
|
/**
|
|
171
169
|
* Generates code for the global injector which is responsible for setting the global
|
|
172
170
|
* `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["getReleaseFromCommitEnv","readCoreCommitEnvVar"],"sources":["../../../src/core/utils.ts"],"sourcesContent":["/* oxlint-disable max-lines */\nimport path from 'path';\nimport fs from 'fs';\nimport os from 'os';\nimport crypto from 'crypto';\nimport childProcess from 'child_process';\nimport type { SourceMap } from 'magic-string';\nimport MagicString from 'magic-string';\nimport {\n _INTERNAL_getReleaseFromCommitEnv as getReleaseFromCommitEnv,\n _INTERNAL_readCommitEnvVar as readCoreCommitEnvVar,\n} from '@sentry/core/server';\n\n/**\n * Checks whether the given input is already an array, and if it isn't, wraps it in one.\n *\n * @param maybeArray Input to turn into an array, if necessary\n * @returns The input, if already an array, or an array with the input as the only element, if not\n */\nexport function arrayify<T = unknown>(maybeArray: T | T[]): T[] {\n return Array.isArray(maybeArray) ? maybeArray : [maybeArray];\n}\n\ntype PackageJson = Record<string, unknown>;\n\n/**\n * Get the closes package.json from a given starting point upwards.\n * This handles a few edge cases:\n * * Check if a given file package.json appears to be an actual NPM package.json file\n * * Stop at the home dir, to avoid looking too deeply\n */\nexport function getPackageJson({ cwd, stopAt }: { cwd?: string; stopAt?: string } = {}): PackageJson | undefined {\n return lookupPackageJson(cwd ?? process.cwd(), path.normalize(stopAt ?? os.homedir()));\n}\n\nexport function parseMajorVersion(ver: string): number | undefined {\n let version = ver;\n // if it has a `v` prefix, remove it\n if (version.startsWith('v')) {\n version = version.slice(1);\n }\n\n // First, try simple lookup of exact, ~ and ^ versions\n const regex = /^[\\^~]?(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n\n const match = version.match(regex);\n if (match) {\n return parseInt(match[1] as string, 10);\n }\n\n // Try to parse e.g. 1.x\n const coerced = parseInt(version, 10);\n if (!Number.isNaN(coerced)) {\n return coerced;\n }\n\n // Match <= and >= ranges.\n const gteLteRegex = /^[<>]=\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const gteLteMatch = version.match(gteLteRegex);\n if (gteLteMatch) {\n return parseInt(gteLteMatch[1] as string, 10);\n }\n\n // match < ranges\n const ltRegex = /^<\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const ltMatch = version.match(ltRegex);\n if (ltMatch) {\n // Two scenarios:\n // a) < 2.0.0 --> return 1\n // b) < 2.1.0 --> return 2\n\n const major = parseInt(ltMatch[1] as string, 10);\n\n if (\n // minor version > 0\n (typeof ltMatch[2] === 'string' && parseInt(ltMatch[2].slice(1), 10) > 0) ||\n // patch version > 0\n (typeof ltMatch[3] === 'string' && parseInt(ltMatch[3].slice(1), 10) > 0)\n ) {\n return major;\n }\n\n return major - 1;\n }\n\n // match > ranges\n const gtRegex = /^>\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const gtMatch = version.match(gtRegex);\n if (gtMatch) {\n // We always return the version here, even though it _may_ be incorrect\n // E.g. if given > 2.0.0, it should be 2 if there exists any 2.x.x version, else 3\n // Since there is no way for us to know this, we're going to assume any kind of patch/feature release probably exists\n return parseInt(gtMatch[1] as string, 10);\n }\n return undefined;\n}\n\n// This is an explicit list of packages where we want to include the (major) version number.\nconst PACKAGES_TO_INCLUDE_VERSION = [\n 'react',\n '@angular/core',\n 'vue',\n 'ember-source',\n 'svelte',\n '@sveltejs/kit',\n 'webpack',\n 'vite',\n 'gatsby',\n 'next',\n 'remix',\n 'rollup',\n 'esbuild',\n];\n\nexport function getDependencies(packageJson: PackageJson): {\n deps: string[];\n depsVersions: Record<string, number>;\n} {\n const dependencies: Record<string, string> = Object.assign(\n {},\n packageJson['devDependencies'] ?? {},\n packageJson['dependencies'] ?? {},\n );\n\n const deps = Object.keys(dependencies).sort();\n\n const depsVersions: Record<string, number> = deps.reduce(\n (depsVersions, depName) => {\n if (PACKAGES_TO_INCLUDE_VERSION.includes(depName)) {\n const version = dependencies[depName] as string;\n const majorVersion = parseMajorVersion(version);\n if (majorVersion) {\n depsVersions[depName] = majorVersion;\n }\n }\n return depsVersions;\n },\n {} as Record<string, number>,\n );\n\n return { deps, depsVersions };\n}\n\nfunction findPackageJson(cwd: string, stopAt: string): string | undefined {\n let dirName = path.resolve(cwd);\n\n for (;;) {\n // Stop if we reach this dir\n if (path.normalize(dirName) === stopAt) {\n return undefined;\n }\n\n const jsonPath = path.join(dirName, 'package.json');\n if (fs.existsSync(jsonPath)) {\n return jsonPath;\n }\n\n const parentDirName = path.dirname(dirName);\n // We reached the file system root\n if (parentDirName === dirName) {\n return undefined;\n }\n\n dirName = parentDirName;\n }\n}\n\nfunction lookupPackageJson(cwd: string, stopAt: string): PackageJson | undefined {\n const jsonPath = findPackageJson(cwd, stopAt);\n\n if (!jsonPath) {\n return undefined;\n }\n\n try {\n const jsonStr = fs.readFileSync(jsonPath, 'utf8');\n const json = JSON.parse(jsonStr) as PackageJson;\n\n // Ensure it is an actual package.json\n // This is very much not bulletproof, but should be good enough\n if ('name' in json || 'private' in json) {\n return json;\n }\n } catch {\n // Ignore and walk up\n }\n\n // Continue up the tree, if we find a fitting package.json\n const newCwd = path.dirname(path.resolve(`${jsonPath}/..`));\n return lookupPackageJson(newCwd, stopAt);\n}\n\n/**\n * Deterministically hashes a string and turns the hash into a uuid.\n */\nexport function stringToUUID(str: string): string {\n const sha256Hash = crypto.createHash('sha256').update(str).digest('hex');\n\n // Position 16 is fixed to either 8, 9, a, or b in the uuid v4 spec (10xx in binary)\n // RFC 4122 section 4.4\n const v4variant = ['8', '9', 'a', 'b'][sha256Hash.substring(16, 17).charCodeAt(0) % 4] as string;\n\n return `${sha256Hash.substring(0, 8)}-${sha256Hash.substring(8, 12)}-4${sha256Hash.substring(13, 16)}-${v4variant}${sha256Hash.substring(17, 20)}-${sha256Hash.substring(20, 32)}`.toLowerCase();\n}\n\nfunction gitRevision(): string | undefined {\n let gitRevision: string | undefined;\n try {\n gitRevision = childProcess\n .execSync('git rev-parse HEAD', { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true })\n .toString()\n .trim();\n } catch {\n // noop\n }\n return gitRevision;\n}\n\n// Mirrors the CLI's `set-commits --auto` fallback for builds without an `origin` remote. Vercel is left out\n// because the CLI only reads `VERCEL_GIT_*` on production builds.\nconst CI_REPOSITORY_ENV_VARS = [\n 'GITHUB_REPOSITORY',\n 'CI_PROJECT_PATH',\n 'BITBUCKET_REPO_FULL_NAME',\n 'RENDER_GIT_REPO_SLUG',\n 'RAILWAY_GIT_REPO_NAME',\n 'CIRCLE_PROJECT_REPONAME',\n 'BUILDKITE_REPO',\n 'BUILD_REPOSITORY_URI',\n] as const;\n\n/**\n * Whether `set-commits --auto` can find the repository: from the `origin` git remote, or from CI variables.\n */\nexport function canAutoDetectRepository(): boolean {\n if (\n CI_REPOSITORY_ENV_VARS.some(name => process.env[name]) ||\n (process.env['NETLIFY'] && process.env['REPOSITORY_URL'])\n ) {\n return true;\n }\n try {\n childProcess.execSync('git remote get-url origin', { stdio: 'ignore', windowsHide: true });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Tries to guess a release name based on environmental data.\n */\nexport function determineReleaseName(): string | undefined {\n return getReleaseFromCommitEnv(warnAboutPlaceholderCommitEnvVar) || gitRevision();\n}\n\n// Release detection and commit association can read the same variable in one build.\nconst warnedPlaceholderEnvVars = new Set<string>();\n\nfunction warnAboutPlaceholderCommitEnvVar(name: string): void {\n if (warnedPlaceholderEnvVars.has(name)) {\n return;\n }\n warnedPlaceholderEnvVars.add(name);\n // This runs before the plugin logger exists, so `silent: true` does not suppress it. That is\n // deliberate: a warning that is easy to miss is how this misconfiguration went unnoticed.\n // eslint-disable-next-line no-console\n console.warn(\n `[@sentry/bundler-plugins] Ignoring the ${name} environment variable as a release name, because its value is its own name. Set the release explicitly, or fix the variable in your build environment.`,\n );\n}\n\n/**\n * Reads an environment variable that should hold a commit SHA, ignoring a value that is the\n * variable's own name. See `_INTERNAL_readCommitEnvVar` in `@sentry/core/server`.\n */\nexport function readCommitEnvVar(name: string): string | undefined {\n return readCoreCommitEnvVar(name, warnAboutPlaceholderCommitEnvVar);\n}\n\nfunction stringifyForCodeInjection(value: unknown): string | undefined {\n // Bundles may be inlined in HTML, where JSON quoting does not escape script tags or HTML comments.\n return JSON.stringify(value)?.replace(/</g, '\\\\u003c');\n}\n\n/**\n * Generates code for the global injector which is responsible for setting the global\n * `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.\n */\nexport function generateReleaseInjectorCode({\n release,\n injectBuildInformation,\n}: {\n release: string;\n injectBuildInformation: boolean;\n}): CodeInjection {\n let code = `e.SENTRY_RELEASE={id:${stringifyForCodeInjection(release)}};`;\n\n if (injectBuildInformation) {\n const buildInfo = getBuildInformation();\n\n code += `e.SENTRY_BUILD_INFO=${stringifyForCodeInjection(buildInfo)};`;\n }\n\n return new CodeInjection(code);\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function generateModuleMetadataInjectorCode(metadata: any): CodeInjection {\n // We are merging the metadata objects in case modules are bundled twice with the plugin\n // Use try-catch to avoid issues when bundlers rename global variables like 'window' to 'k'\n return new CodeInjection(\n `e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${stringifyForCodeInjection(\n metadata,\n )});`,\n );\n}\n\nexport function getBuildInformation(): {\n deps: string[];\n depsVersions: Record<string, number>;\n nodeVersion: number | undefined;\n} {\n const packageJson = getPackageJson();\n\n const { deps, depsVersions } = packageJson ? getDependencies(packageJson) : { deps: [], depsVersions: {} };\n\n return {\n deps,\n depsVersions,\n nodeVersion: parseMajorVersion(process.version),\n };\n}\n\nexport function stripQueryAndHashFromPath(path: string): string {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return path.split('?')[0]!.split('#')[0]!;\n}\n\nexport function replaceBooleanFlagsInCode(\n code: string,\n replacementValues: Record<string, boolean | undefined>,\n): { code: string; map: SourceMap } | null {\n const ms = new MagicString(code);\n\n Object.keys(replacementValues).forEach(key => {\n const value = replacementValues[key];\n\n if (typeof value === 'boolean') {\n ms.replaceAll(key, JSON.stringify(value));\n }\n });\n\n if (ms.hasChanged()) {\n return {\n code: ms.toString(),\n map: ms.generateMap({ hires: 'boundary' }),\n };\n }\n\n return null;\n}\n\n// https://turbo.build/repo/docs/reference/system-environment-variables#environment-variables-in-tasks\nexport function getTurborepoEnvPassthroughWarning(envVarName: string): string {\n return process.env['TURBO_HASH']\n ? `\\nYou seem to be using Turborepo, did you forget to put ${envVarName} in \\`passThroughEnv\\`? https://turbo.build/repo/docs/reference/configuration#passthroughenv`\n : '';\n}\n\n/**\n * Gets the projects from the project option. This might be a single project or an array of projects.\n */\nexport function getProjects(project: string | string[] | undefined): string[] | undefined {\n if (Array.isArray(project)) {\n return project;\n }\n\n if (project) {\n return [project];\n }\n\n return undefined;\n}\n\n/**\n * Checks if a chunk contains only import/export statements and no substantial code.\n *\n * In Vite MPA (multi-page application) mode, HTML entry points create \"facade\" chunks\n * that only contain import statements to load shared modules. These should not have\n * Sentry code injected. However, in SPA mode, the main bundle also has an HTML facade\n * but contains substantial application code that SHOULD have debug IDs injected.\n *\n * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/839\n */\nexport function containsOnlyImports(code: string): boolean {\n const codeWithoutImports = code\n // Remove side effect imports: import '/path'; or import \"./path\";\n // Using explicit negated character classes to avoid polynomial backtracking\n .replace(/^\\s*import\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove named/default imports: import x from '/path'; import { x } from '/path';\n .replace(/^\\s*import\\b[^'\"`\\n]*\\bfrom\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove re-exports: export * from '/path'; export { x } from '/path';\n .replace(/^\\s*export\\b[^'\"`\\n]*\\bfrom\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove block comments\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n // Remove line comments\n .replace(/\\/\\/.*$/gm, '')\n // Remove \"use strict\" directives\n .replace(/[\"']use strict[\"']\\s*;?/g, '')\n .trim();\n\n return codeWithoutImports.length === 0;\n}\n\nexport class CodeInjection {\n // The code below is mostly ternary operators because it saves bundle size.\n // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)\n private readonly header: string;\n private readonly footer: string;\n\n constructor(private body: string = '') {\n // `globalThis` is checked first so the other identifiers are never evaluated\n // where it exists. A downstream bundler that runs over an already-injected\n // chunk can turn a free `global` into a `const` it declares further down the\n // file (Nitro's node compat does this). Reading that binding from the top of\n // the file hits the temporal dead zone, and `typeof` throws there instead of\n // returning \"undefined\", so the whole injection was silently swallowed by the\n // `catch` below and the chunk registered no debug ID.\n this.header = `!function(){try{var e=\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof self?self:{};`;\n this.footer = '}catch(e){}}();';\n }\n\n public code(): string {\n if (this.isEmpty()) {\n return '';\n }\n\n return this.header + this.body + this.footer;\n }\n\n public isEmpty(): boolean {\n return this.body.length === 0;\n }\n\n public append(code: CodeInjection | string): void {\n if (code instanceof CodeInjection) {\n this.body += code.body;\n } else {\n this.body += code;\n }\n }\n\n public clear(): void {\n this.body = '';\n }\n\n public clone(): CodeInjection {\n return new CodeInjection(this.body);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,SAAgB,SAAsB,YAA0B;CAC9D,OAAO,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,UAAU;AAC7D;;;;;;;AAUA,SAAgB,eAAe,EAAE,KAAK,WAA8C,CAAC,GAA4B;CAC/G,OAAO,kBAAkB,OAAO,QAAQ,IAAI,GAAG,KAAK,UAAU,UAAU,GAAG,QAAQ,CAAC,CAAC;AACvF;AAEA,SAAgB,kBAAkB,KAAiC;CACjE,IAAI,UAAU;CAEd,IAAI,QAAQ,WAAW,GAAG,GACxB,UAAU,QAAQ,MAAM,CAAC;CAM3B,MAAM,QAAQ,QAAQ,MAAM,oCAAK;CACjC,IAAI,OACF,OAAO,SAAS,MAAM,IAAc,EAAE;CAIxC,MAAM,UAAU,SAAS,SAAS,EAAE;CACpC,IAAI,CAAC,OAAO,MAAM,OAAO,GACvB,OAAO;CAKT,MAAM,cAAc,QAAQ,MAAM,sCAAW;CAC7C,IAAI,aACF,OAAO,SAAS,YAAY,IAAc,EAAE;CAK9C,MAAM,UAAU,QAAQ,MAAM,kCAAO;CACrC,IAAI,SAAS;EAKX,MAAM,Q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ts"],"sourcesContent":["/* oxlint-disable max-lines */\nimport path from 'path';\nimport fs from 'fs';\nimport os from 'os';\nimport crypto from 'crypto';\nimport childProcess from 'child_process';\nimport type { SourceMap } from 'magic-string';\nimport MagicString from 'magic-string';\nimport {\n _INTERNAL_getReleaseFromCommitEnv as getReleaseFromCommitEnv,\n _INTERNAL_readCommitEnvVar as readCoreCommitEnvVar,\n} from '@sentry/core/server';\nimport { stringifyForCodeInjection } from '@sentry/core';\n\n/**\n * Checks whether the given input is already an array, and if it isn't, wraps it in one.\n *\n * @param maybeArray Input to turn into an array, if necessary\n * @returns The input, if already an array, or an array with the input as the only element, if not\n */\nexport function arrayify<T = unknown>(maybeArray: T | T[]): T[] {\n return Array.isArray(maybeArray) ? maybeArray : [maybeArray];\n}\n\ntype PackageJson = Record<string, unknown>;\n\n/**\n * Get the closes package.json from a given starting point upwards.\n * This handles a few edge cases:\n * * Check if a given file package.json appears to be an actual NPM package.json file\n * * Stop at the home dir, to avoid looking too deeply\n */\nexport function getPackageJson({ cwd, stopAt }: { cwd?: string; stopAt?: string } = {}): PackageJson | undefined {\n return lookupPackageJson(cwd ?? process.cwd(), path.normalize(stopAt ?? os.homedir()));\n}\n\nexport function parseMajorVersion(ver: string): number | undefined {\n let version = ver;\n // if it has a `v` prefix, remove it\n if (version.startsWith('v')) {\n version = version.slice(1);\n }\n\n // First, try simple lookup of exact, ~ and ^ versions\n const regex = /^[\\^~]?(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n\n const match = version.match(regex);\n if (match) {\n return parseInt(match[1] as string, 10);\n }\n\n // Try to parse e.g. 1.x\n const coerced = parseInt(version, 10);\n if (!Number.isNaN(coerced)) {\n return coerced;\n }\n\n // Match <= and >= ranges.\n const gteLteRegex = /^[<>]=\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const gteLteMatch = version.match(gteLteRegex);\n if (gteLteMatch) {\n return parseInt(gteLteMatch[1] as string, 10);\n }\n\n // match < ranges\n const ltRegex = /^<\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const ltMatch = version.match(ltRegex);\n if (ltMatch) {\n // Two scenarios:\n // a) < 2.0.0 --> return 1\n // b) < 2.1.0 --> return 2\n\n const major = parseInt(ltMatch[1] as string, 10);\n\n if (\n // minor version > 0\n (typeof ltMatch[2] === 'string' && parseInt(ltMatch[2].slice(1), 10) > 0) ||\n // patch version > 0\n (typeof ltMatch[3] === 'string' && parseInt(ltMatch[3].slice(1), 10) > 0)\n ) {\n return major;\n }\n\n return major - 1;\n }\n\n // match > ranges\n const gtRegex = /^>\\s*(\\d+)(\\.\\d+)?(\\.\\d+)?(-.+)?/;\n const gtMatch = version.match(gtRegex);\n if (gtMatch) {\n // We always return the version here, even though it _may_ be incorrect\n // E.g. if given > 2.0.0, it should be 2 if there exists any 2.x.x version, else 3\n // Since there is no way for us to know this, we're going to assume any kind of patch/feature release probably exists\n return parseInt(gtMatch[1] as string, 10);\n }\n return undefined;\n}\n\n// This is an explicit list of packages where we want to include the (major) version number.\nconst PACKAGES_TO_INCLUDE_VERSION = [\n 'react',\n '@angular/core',\n 'vue',\n 'ember-source',\n 'svelte',\n '@sveltejs/kit',\n 'webpack',\n 'vite',\n 'gatsby',\n 'next',\n 'remix',\n 'rollup',\n 'esbuild',\n];\n\nexport function getDependencies(packageJson: PackageJson): {\n deps: string[];\n depsVersions: Record<string, number>;\n} {\n const dependencies: Record<string, string> = Object.assign(\n {},\n packageJson['devDependencies'] ?? {},\n packageJson['dependencies'] ?? {},\n );\n\n const deps = Object.keys(dependencies).sort();\n\n const depsVersions: Record<string, number> = deps.reduce(\n (depsVersions, depName) => {\n if (PACKAGES_TO_INCLUDE_VERSION.includes(depName)) {\n const version = dependencies[depName] as string;\n const majorVersion = parseMajorVersion(version);\n if (majorVersion) {\n depsVersions[depName] = majorVersion;\n }\n }\n return depsVersions;\n },\n {} as Record<string, number>,\n );\n\n return { deps, depsVersions };\n}\n\nfunction findPackageJson(cwd: string, stopAt: string): string | undefined {\n let dirName = path.resolve(cwd);\n\n for (;;) {\n // Stop if we reach this dir\n if (path.normalize(dirName) === stopAt) {\n return undefined;\n }\n\n const jsonPath = path.join(dirName, 'package.json');\n if (fs.existsSync(jsonPath)) {\n return jsonPath;\n }\n\n const parentDirName = path.dirname(dirName);\n // We reached the file system root\n if (parentDirName === dirName) {\n return undefined;\n }\n\n dirName = parentDirName;\n }\n}\n\nfunction lookupPackageJson(cwd: string, stopAt: string): PackageJson | undefined {\n const jsonPath = findPackageJson(cwd, stopAt);\n\n if (!jsonPath) {\n return undefined;\n }\n\n try {\n const jsonStr = fs.readFileSync(jsonPath, 'utf8');\n const json = JSON.parse(jsonStr) as PackageJson;\n\n // Ensure it is an actual package.json\n // This is very much not bulletproof, but should be good enough\n if ('name' in json || 'private' in json) {\n return json;\n }\n } catch {\n // Ignore and walk up\n }\n\n // Continue up the tree, if we find a fitting package.json\n const newCwd = path.dirname(path.resolve(`${jsonPath}/..`));\n return lookupPackageJson(newCwd, stopAt);\n}\n\n/**\n * Deterministically hashes a string and turns the hash into a uuid.\n */\nexport function stringToUUID(str: string): string {\n const sha256Hash = crypto.createHash('sha256').update(str).digest('hex');\n\n // Position 16 is fixed to either 8, 9, a, or b in the uuid v4 spec (10xx in binary)\n // RFC 4122 section 4.4\n const v4variant = ['8', '9', 'a', 'b'][sha256Hash.substring(16, 17).charCodeAt(0) % 4] as string;\n\n return `${sha256Hash.substring(0, 8)}-${sha256Hash.substring(8, 12)}-4${sha256Hash.substring(13, 16)}-${v4variant}${sha256Hash.substring(17, 20)}-${sha256Hash.substring(20, 32)}`.toLowerCase();\n}\n\nfunction gitRevision(): string | undefined {\n let gitRevision: string | undefined;\n try {\n gitRevision = childProcess\n .execSync('git rev-parse HEAD', { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true })\n .toString()\n .trim();\n } catch {\n // noop\n }\n return gitRevision;\n}\n\n// Mirrors the CLI's `set-commits --auto` fallback for builds without an `origin` remote. Vercel is left out\n// because the CLI only reads `VERCEL_GIT_*` on production builds.\nconst CI_REPOSITORY_ENV_VARS = [\n 'GITHUB_REPOSITORY',\n 'CI_PROJECT_PATH',\n 'BITBUCKET_REPO_FULL_NAME',\n 'RENDER_GIT_REPO_SLUG',\n 'RAILWAY_GIT_REPO_NAME',\n 'CIRCLE_PROJECT_REPONAME',\n 'BUILDKITE_REPO',\n 'BUILD_REPOSITORY_URI',\n] as const;\n\n/**\n * Whether `set-commits --auto` can find the repository: from the `origin` git remote, or from CI variables.\n */\nexport function canAutoDetectRepository(): boolean {\n if (\n CI_REPOSITORY_ENV_VARS.some(name => process.env[name]) ||\n (process.env['NETLIFY'] && process.env['REPOSITORY_URL'])\n ) {\n return true;\n }\n try {\n childProcess.execSync('git remote get-url origin', { stdio: 'ignore', windowsHide: true });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Tries to guess a release name based on environmental data.\n */\nexport function determineReleaseName(): string | undefined {\n return getReleaseFromCommitEnv(warnAboutPlaceholderCommitEnvVar) || gitRevision();\n}\n\n// Release detection and commit association can read the same variable in one build.\nconst warnedPlaceholderEnvVars = new Set<string>();\n\nfunction warnAboutPlaceholderCommitEnvVar(name: string): void {\n if (warnedPlaceholderEnvVars.has(name)) {\n return;\n }\n warnedPlaceholderEnvVars.add(name);\n // This runs before the plugin logger exists, so `silent: true` does not suppress it. That is\n // deliberate: a warning that is easy to miss is how this misconfiguration went unnoticed.\n // eslint-disable-next-line no-console\n console.warn(\n `[@sentry/bundler-plugins] Ignoring the ${name} environment variable as a release name, because its value is its own name. Set the release explicitly, or fix the variable in your build environment.`,\n );\n}\n\n/**\n * Reads an environment variable that should hold a commit SHA, ignoring a value that is the\n * variable's own name. See `_INTERNAL_readCommitEnvVar` in `@sentry/core/server`.\n */\nexport function readCommitEnvVar(name: string): string | undefined {\n return readCoreCommitEnvVar(name, warnAboutPlaceholderCommitEnvVar);\n}\n\n/**\n * Generates code for the global injector which is responsible for setting the global\n * `SENTRY_RELEASE` & `SENTRY_BUILD_INFO` variables.\n */\nexport function generateReleaseInjectorCode({\n release,\n injectBuildInformation,\n}: {\n release: string;\n injectBuildInformation: boolean;\n}): CodeInjection {\n let code = `e.SENTRY_RELEASE={id:${stringifyForCodeInjection(release)}};`;\n\n if (injectBuildInformation) {\n const buildInfo = getBuildInformation();\n\n code += `e.SENTRY_BUILD_INFO=${stringifyForCodeInjection(buildInfo)};`;\n }\n\n return new CodeInjection(code);\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function generateModuleMetadataInjectorCode(metadata: any): CodeInjection {\n // We are merging the metadata objects in case modules are bundled twice with the plugin\n // Use try-catch to avoid issues when bundlers rename global variables like 'window' to 'k'\n return new CodeInjection(\n `e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${stringifyForCodeInjection(\n metadata,\n )});`,\n );\n}\n\nexport function getBuildInformation(): {\n deps: string[];\n depsVersions: Record<string, number>;\n nodeVersion: number | undefined;\n} {\n const packageJson = getPackageJson();\n\n const { deps, depsVersions } = packageJson ? getDependencies(packageJson) : { deps: [], depsVersions: {} };\n\n return {\n deps,\n depsVersions,\n nodeVersion: parseMajorVersion(process.version),\n };\n}\n\nexport function stripQueryAndHashFromPath(path: string): string {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return path.split('?')[0]!.split('#')[0]!;\n}\n\nexport function replaceBooleanFlagsInCode(\n code: string,\n replacementValues: Record<string, boolean | undefined>,\n): { code: string; map: SourceMap } | null {\n const ms = new MagicString(code);\n\n Object.keys(replacementValues).forEach(key => {\n const value = replacementValues[key];\n\n if (typeof value === 'boolean') {\n ms.replaceAll(key, JSON.stringify(value));\n }\n });\n\n if (ms.hasChanged()) {\n return {\n code: ms.toString(),\n map: ms.generateMap({ hires: 'boundary' }),\n };\n }\n\n return null;\n}\n\n// https://turbo.build/repo/docs/reference/system-environment-variables#environment-variables-in-tasks\nexport function getTurborepoEnvPassthroughWarning(envVarName: string): string {\n return process.env['TURBO_HASH']\n ? `\\nYou seem to be using Turborepo, did you forget to put ${envVarName} in \\`passThroughEnv\\`? https://turbo.build/repo/docs/reference/configuration#passthroughenv`\n : '';\n}\n\n/**\n * Gets the projects from the project option. This might be a single project or an array of projects.\n */\nexport function getProjects(project: string | string[] | undefined): string[] | undefined {\n if (Array.isArray(project)) {\n return project;\n }\n\n if (project) {\n return [project];\n }\n\n return undefined;\n}\n\n/**\n * Checks if a chunk contains only import/export statements and no substantial code.\n *\n * In Vite MPA (multi-page application) mode, HTML entry points create \"facade\" chunks\n * that only contain import statements to load shared modules. These should not have\n * Sentry code injected. However, in SPA mode, the main bundle also has an HTML facade\n * but contains substantial application code that SHOULD have debug IDs injected.\n *\n * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/829\n * @ref https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/839\n */\nexport function containsOnlyImports(code: string): boolean {\n const codeWithoutImports = code\n // Remove side effect imports: import '/path'; or import \"./path\";\n // Using explicit negated character classes to avoid polynomial backtracking\n .replace(/^\\s*import\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove named/default imports: import x from '/path'; import { x } from '/path';\n .replace(/^\\s*import\\b[^'\"`\\n]*\\bfrom\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove re-exports: export * from '/path'; export { x } from '/path';\n .replace(/^\\s*export\\b[^'\"`\\n]*\\bfrom\\s+(?:'[^'\\n]*'|\"[^\"\\n]*\"|`[^`\\n]*`)[\\s;]*$/gm, '')\n // Remove block comments\n .replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n // Remove line comments\n .replace(/\\/\\/.*$/gm, '')\n // Remove \"use strict\" directives\n .replace(/[\"']use strict[\"']\\s*;?/g, '')\n .trim();\n\n return codeWithoutImports.length === 0;\n}\n\nexport class CodeInjection {\n // The code below is mostly ternary operators because it saves bundle size.\n // The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)\n private readonly header: string;\n private readonly footer: string;\n\n constructor(private body: string = '') {\n // `globalThis` is checked first so the other identifiers are never evaluated\n // where it exists. A downstream bundler that runs over an already-injected\n // chunk can turn a free `global` into a `const` it declares further down the\n // file (Nitro's node compat does this). Reading that binding from the top of\n // the file hits the temporal dead zone, and `typeof` throws there instead of\n // returning \"undefined\", so the whole injection was silently swallowed by the\n // `catch` below and the chunk registered no debug ID.\n this.header = `!function(){try{var e=\"undefined\"!=typeof globalThis?globalThis:\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof self?self:{};`;\n this.footer = '}catch(e){}}();';\n }\n\n public code(): string {\n if (this.isEmpty()) {\n return '';\n }\n\n return this.header + this.body + this.footer;\n }\n\n public isEmpty(): boolean {\n return this.body.length === 0;\n }\n\n public append(code: CodeInjection | string): void {\n if (code instanceof CodeInjection) {\n this.body += code.body;\n } else {\n this.body += code;\n }\n }\n\n public clear(): void {\n this.body = '';\n }\n\n public clone(): CodeInjection {\n return new CodeInjection(this.body);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,SAAgB,SAAsB,YAA0B;CAC9D,OAAO,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,UAAU;AAC7D;;;;;;;AAUA,SAAgB,eAAe,EAAE,KAAK,WAA8C,CAAC,GAA4B;CAC/G,OAAO,kBAAkB,OAAO,QAAQ,IAAI,GAAG,KAAK,UAAU,UAAU,GAAG,QAAQ,CAAC,CAAC;AACvF;AAEA,SAAgB,kBAAkB,KAAiC;CACjE,IAAI,UAAU;CAEd,IAAI,QAAQ,WAAW,GAAG,GACxB,UAAU,QAAQ,MAAM,CAAC;CAM3B,MAAM,QAAQ,QAAQ,MAAM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AAK,QAAQ;CAEjB;CAEO,QAAc;EACnB,KAAK,OAAO;CACd;CAEO,QAAuB;EAC5B,OAAO,IAAI,cAAc,KAAK,IAAI;CACpC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../../src/core/version.ts"],"sourcesContent":["export const LIB_VERSION = \"11.14.0\";\n"],"mappings":";AAAA,MAAa,cAAc"}
|
|
@@ -4,6 +4,7 @@ import { addDebugIdToEmittedArtifacts, createDebugIdUploadFunction } from "../co
|
|
|
4
4
|
import { createSentryBuildPluginManager } from "../core/build-plugin-manager.js";
|
|
5
5
|
import { getDebugIdSnippet, isJsFile } from "../core/index.js";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
|
+
import { stringifyForCodeInjection } from "@sentry/core";
|
|
7
8
|
import * as path from "node:path";
|
|
8
9
|
import { randomUUID } from "node:crypto";
|
|
9
10
|
// src/esbuild/index.ts
|
|
@@ -114,9 +115,9 @@ function sentryEsbuildPlugin(userOptions = {}) {
|
|
|
114
115
|
pluginName,
|
|
115
116
|
contents: `
|
|
116
117
|
import "_sentry-debug-id-injection-stub";
|
|
117
|
-
import * as OriginalModule from ${
|
|
118
|
+
import * as OriginalModule from ${stringifyForCodeInjection(originalPath)};
|
|
118
119
|
export default OriginalModule.default;
|
|
119
|
-
export * from ${
|
|
120
|
+
export * from ${stringifyForCodeInjection(originalPath)};`,
|
|
120
121
|
resolveDir: originalResolveDir
|
|
121
122
|
};
|
|
122
123
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/esbuild/index.ts"],"sourcesContent":["import type { InternalOptions, SourceMapDecision, SourceMapKind } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n CodeInjection,\n addDebugIdToEmittedArtifacts,\n isJsFile,\n} from '../core';\nimport * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\n\ninterface EsbuildOnResolveArgs {\n path: string;\n kind: string;\n importer?: string;\n resolveDir: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnResolveResult {\n path: string;\n sideEffects?: boolean;\n pluginName?: string;\n namespace?: string;\n suffix?: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadArgs {\n path: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadResult {\n loader: string;\n pluginName: string;\n contents: string;\n resolveDir?: string;\n}\n\ninterface EsbuildOnEndArgs {\n metafile?: {\n outputs: Record<string, unknown>;\n };\n}\n\ntype EsbuildSourceMapSetting = boolean | 'inline' | 'external' | 'linked' | 'both' | undefined;\n\ninterface EsbuildInitialOptions {\n bundle?: boolean;\n inject?: string[];\n metafile?: boolean;\n define?: Record<string, string>;\n write?: boolean;\n absWorkingDir?: string;\n logOverride?: Record<string, string>;\n sourcemap?: EsbuildSourceMapSetting;\n}\n\n/** Maps esbuild's `sourcemap` setting onto the plugin's source map kinds. */\nfunction sourceMapKindFromEsbuildSetting(setting: EsbuildSourceMapSetting): SourceMapKind {\n switch (setting) {\n case undefined:\n return 'unset';\n case false:\n return 'off';\n case 'external':\n return 'hidden';\n case 'inline':\n case 'both':\n return 'inline';\n default:\n return 'visible';\n }\n}\n\ninterface EsbuildPluginBuild {\n initialOptions: EsbuildInitialOptions;\n onLoad: (\n options: { filter: RegExp; namespace?: string },\n callback: (args: EsbuildOnLoadArgs) => EsbuildOnLoadResult | null,\n ) => void;\n onResolve: (\n options: { filter: RegExp },\n callback: (args: EsbuildOnResolveArgs) => EsbuildOnResolveResult | undefined,\n ) => void;\n onStart: (callback: () => void) => void;\n onEnd: (callback: (result: EsbuildOnEndArgs) => void | Promise<void>) => void;\n}\n\nfunction getEsbuildMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - esbuild transpiles this for us\n const req = createRequire(import.meta.url);\n const esbuild = req('esbuild') as { version?: string };\n // esbuild hasn't released a v1 yet, so we'll return the minor version as the major version\n return esbuild.version?.split('.')[1];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nconst pluginName = 'sentry-esbuild-plugin';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function sentryEsbuildPlugin(userOptions: InternalOptions = {}): any {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,\n buildTool: 'esbuild',\n buildToolMajorVersion: getEsbuildMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n name: 'sentry-esbuild-noop-plugin',\n setup() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n // Component annotation warning\n if (options.reactComponentAnnotation?.enabled) {\n logger.warn(\n 'Component name annotation is not supported in esbuild. Please use a separate transform step or consider using a different bundler.',\n );\n }\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n // Track entry points wrapped for debug ID injection\n const debugIdWrappedPaths = new Set<string>();\n\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n return {\n name: pluginName,\n setup({ initialOptions, onLoad, onResolve, onStart, onEnd }: EsbuildPluginBuild) {\n // Release and/or metadata injection\n if (!staticInjectionCode.isEmpty()) {\n const virtualInjectionFilePath = path.resolve('_sentry-injection-stub');\n initialOptions.inject = initialOptions.inject || [];\n // esbuild emits injected files after an entry's directive prologue. A banner would precede\n // \"use strict\" and turn it into an ordinary string expression.\n initialOptions.inject.push(virtualInjectionFilePath);\n\n onResolve({ filter: /_sentry-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n };\n });\n\n onLoad({ filter: /_sentry-injection-stub/ }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: staticInjectionCode.code(),\n };\n });\n }\n\n // Bundle size optimizations\n if (transformReplace) {\n const replacementStringValues: Record<string, string> = {};\n Object.entries(replacementValues).forEach(([key, value]) => {\n replacementStringValues[key] = JSON.stringify(value);\n });\n\n initialOptions.define = { ...initialOptions.define, ...replacementStringValues };\n }\n\n // Debug ID injection - requires per-entry-point unique IDs\n if (sourcemapsEnabled) {\n // `setup` runs once per context, `onStart` once per build, so a\n // rebuild wraps the entry points again.\n onStart(() => debugIdWrappedPaths.clear());\n\n // The proxy module re-exports `OriginalModule.default` statically so downstream bundlers can tree-shake it,\n // but esbuild warns about that access when the entry point has no default export.\n initialOptions.logOverride = { 'import-is-undefined': 'silent', ...initialOptions.logOverride };\n\n if (!initialOptions.bundle) {\n logger.warn(\n 'The Sentry esbuild plugin only supports esbuild with `bundle: true` being set in the esbuild build options. Esbuild will probably crash now. Sorry about that. If you need to upload sourcemaps without `bundle: true`, it is recommended to use Sentry CLI instead: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/',\n );\n }\n\n // Wrap entry points to inject debug IDs\n onResolve({ filter: /.*/ }, args => {\n if (args.kind !== 'entry-point') {\n return;\n }\n\n // Skip injecting debug IDs into modules specified in the esbuild `inject` option\n // since they're already part of the entry points\n if (initialOptions.inject?.includes(args.path)) {\n return;\n }\n\n const resolvedPath = path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path);\n\n // Skip injecting debug IDs into paths that have already been wrapped\n if (debugIdWrappedPaths.has(resolvedPath)) {\n return;\n }\n debugIdWrappedPaths.add(resolvedPath);\n\n return {\n pluginName,\n path: resolvedPath,\n pluginData: {\n isDebugIdProxy: true,\n originalPath: args.path,\n originalResolveDir: args.resolveDir,\n },\n // We need to add a suffix here, otherwise esbuild will mark the entrypoint as resolved and won't traverse\n // the module tree any further down past the proxy module because we're essentially creating a dependency\n // loop back to the proxy module.\n // By setting a suffix we're telling esbuild that the entrypoint and proxy module are two different things,\n // making it re-resolve the entrypoint when it is imported from the proxy module.\n // Super confusing? Yes. Works? Apparently... Let's see.\n suffix: '?sentryDebugIdProxy=true',\n };\n });\n\n onLoad({ filter: /.*/ }, args => {\n if (!(args.pluginData as { isDebugIdProxy?: boolean })?.isDebugIdProxy) {\n return null;\n }\n\n const originalPath = (args.pluginData as { originalPath: string }).originalPath;\n const originalResolveDir = (args.pluginData as { originalResolveDir: string }).originalResolveDir;\n\n return {\n loader: 'js',\n pluginName,\n contents: `\n import \"_sentry-debug-id-injection-stub\";\n import * as OriginalModule from ${JSON.stringify(originalPath)};\n export default OriginalModule.default;\n export * from ${JSON.stringify(originalPath)};`,\n resolveDir: originalResolveDir,\n };\n });\n\n onResolve({ filter: /_sentry-debug-id-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n namespace: 'sentry-debug-id-stub',\n suffix: `?sentry-module-id=${randomUUID()}`,\n };\n });\n\n onLoad({ filter: /_sentry-debug-id-injection-stub/, namespace: 'sentry-debug-id-stub' }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: getDebugIdSnippet(randomUUID()).code(),\n };\n });\n }\n\n // With `write: false` nothing reaches the disk, so nothing can be uploaded or deleted.\n const sourceMapKind = sourceMapKindFromEsbuildSetting(initialOptions.sourcemap);\n const sourceMapDecision: SourceMapDecision =\n initialOptions.write === false\n ? { enableHidden: false, deleteAfterUpload: false }\n : sentryBuildPluginManager.sourceMaps.decide(sourceMapKind);\n if (sourceMapDecision.enableHidden) {\n initialOptions.sourcemap = 'external';\n }\n\n // Create release and optionally upload\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n initialOptions.metafile = true;\n onEnd(async result => {\n try {\n await sentryBuildPluginManager.createRelease();\n\n // The metafile lists outputs relative to `absWorkingDir`, not to the process.\n const outputDir = initialOptions.absWorkingDir ?? process.cwd();\n const buildArtifacts = result.metafile\n ? Object.keys(result.metafile.outputs).map(output => path.resolve(outputDir, output))\n : [];\n\n const { sourceMaps } = sentryBuildPluginManager;\n const allMaps = buildArtifacts.filter(artifact => artifact.endsWith('.map'));\n const deleteWithoutUpload = sourceMapDecision.deleteAfterUpload && !sourceMaps.uploadPossible;\n if (sourcemapsEnabled && options.sourcemaps?.disable === 'disable-upload') {\n if (initialOptions.write === false) {\n logger.debug('Build output is not written to disk. Skipping debug ID injection into build artifacts.');\n } else {\n // The upload routine (which stamps debug IDs into temp copies of the artifacts) is\n // skipped with `disable-upload`. esbuild has no hook to modify outputs before they are\n // written, so the emitted artifacts get stamped on disk instead.\n await Promise.all(\n buildArtifacts\n .filter(isJsFile)\n .map(bundle => addDebugIdToEmittedArtifacts(bundle, logger, options.sourcemaps?.resolveSourceMap)),\n );\n }\n } else if (sourcemapsEnabled) {\n // The upload globs the paths, and glob reads backslashes as escapes.\n // When no upload can run, this logs why.\n const { uploaded, uploadedSourceMapPaths } = await upload(\n buildArtifacts.map(artifact => artifact.split(path.sep).join('/')),\n );\n\n // esbuild writes before `onEnd` runs, so the maps are deleted from disk\n // afterwards instead of being dropped from the output like in other bundlers.\n // A map the plugin turned on never stays in the output. A map the user\n // enabled is only deleted once it was uploaded.\n if (sourceMapDecision.deleteAfterUpload && !deleteWithoutUpload) {\n const mapsToDelete = sourceMapDecision.removeAllSourceMaps ? allMaps : uploadedSourceMapPaths;\n\n if (uploaded) {\n await sourceMaps.deleteFromOutput(mapsToDelete);\n } else if (mapsToDelete.length > 0) {\n logger.error('The source maps were not uploaded, so they stay in the build output.');\n }\n }\n }\n\n if (deleteWithoutUpload) {\n const bundleOf = (map: string): string => map.slice(0, -'.map'.length);\n const isUploaded = (map: string): boolean =>\n isJsFile(bundleOf(map)) && sourceMaps.shouldUpload(bundleOf(map));\n await sourceMaps.deleteFromOutput(\n sourceMapDecision.removeAllSourceMaps ? allMaps : allMaps.filter(isUploaded),\n );\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n });\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default sentryEsbuildPlugin;\nexport type { Options as SentryEsbuildPluginOptions } from '../core';\n"],"mappings":";;;;;;;;;;AAgEA,SAAS,gCAAgC,SAAiD;CACxF,QAAQ,SAAR;EACE,KAAK,KAAA,GACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK;EACL,KAAK,QACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAgBA,SAAS,yBAA6C;CACpD,IAAI;EAMF,OAHY,cAAc,YAAY,GACpB,CAAC,CAAC,SAEP,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC;CACrC,QAAQ,CAER;AAGF;AAEA,MAAM,aAAa;AAGnB,SAAgB,oBAAoB,cAA+B,CAAC,GAAQ;CAC1E,MAAM,2BAA2B,+BAA+B,aAAa;EAC3E,cAAc,YAAY,cAAc,wBAAwB,IAAI,WAAW;EAC/E,WAAW;EACX,uBAAuB,uBAAuB;CAChD,CAAC;CAED,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AqB,CAAC,qBAAqB;OAC/D,MAAM,eAAe,kBAAkB,sBAAsB,UAAU;OAEvE,IAAI,UACF,MAAM,WAAW,iBAAiB,YAAY;YACzC,IAAI,aAAa,SAAS,GAC/B,OAAO,MAAM,sEAAsE;MAEvF;KACF;KAEA,IAAI,qBAAqB;MACvB,MAAM,YAAY,QAAwB,IAAI,MAAM,GAAG,EAAc;MACrE,MAAM,cAAc,QAClB,SAAS,SAAS,GAAG,CAAC,KAAK,WAAW,aAAa,SAAS,GAAG,CAAC;MAClE,MAAM,WAAW,iBACf,kBAAkB,sBAAsB,UAAU,QAAQ,OAAO,UAAU,CAC7E;KACF;IACF,UAAU;KACR,qCAAqC;KACrC,MAAM,yBAAyB,gBAAgB;IACjD;GACF,CAAC;EACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/esbuild/index.ts"],"sourcesContent":["/* oxlint-disable max-lines */\nimport type { InternalOptions, SourceMapDecision, SourceMapKind } from '../core';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n CodeInjection,\n addDebugIdToEmittedArtifacts,\n isJsFile,\n} from '../core';\nimport * as path from 'node:path';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\nimport { stringifyForCodeInjection } from '@sentry/core';\n\ninterface EsbuildOnResolveArgs {\n path: string;\n kind: string;\n importer?: string;\n resolveDir: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnResolveResult {\n path: string;\n sideEffects?: boolean;\n pluginName?: string;\n namespace?: string;\n suffix?: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadArgs {\n path: string;\n pluginData?: unknown;\n}\n\ninterface EsbuildOnLoadResult {\n loader: string;\n pluginName: string;\n contents: string;\n resolveDir?: string;\n}\n\ninterface EsbuildOnEndArgs {\n metafile?: {\n outputs: Record<string, unknown>;\n };\n}\n\ntype EsbuildSourceMapSetting = boolean | 'inline' | 'external' | 'linked' | 'both' | undefined;\n\ninterface EsbuildInitialOptions {\n bundle?: boolean;\n inject?: string[];\n metafile?: boolean;\n define?: Record<string, string>;\n write?: boolean;\n absWorkingDir?: string;\n logOverride?: Record<string, string>;\n sourcemap?: EsbuildSourceMapSetting;\n}\n\n/** Maps esbuild's `sourcemap` setting onto the plugin's source map kinds. */\nfunction sourceMapKindFromEsbuildSetting(setting: EsbuildSourceMapSetting): SourceMapKind {\n switch (setting) {\n case undefined:\n return 'unset';\n case false:\n return 'off';\n case 'external':\n return 'hidden';\n case 'inline':\n case 'both':\n return 'inline';\n default:\n return 'visible';\n }\n}\n\ninterface EsbuildPluginBuild {\n initialOptions: EsbuildInitialOptions;\n onLoad: (\n options: { filter: RegExp; namespace?: string },\n callback: (args: EsbuildOnLoadArgs) => EsbuildOnLoadResult | null,\n ) => void;\n onResolve: (\n options: { filter: RegExp },\n callback: (args: EsbuildOnResolveArgs) => EsbuildOnResolveResult | undefined,\n ) => void;\n onStart: (callback: () => void) => void;\n onEnd: (callback: (result: EsbuildOnEndArgs) => void | Promise<void>) => void;\n}\n\nfunction getEsbuildMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - esbuild transpiles this for us\n const req = createRequire(import.meta.url);\n const esbuild = req('esbuild') as { version?: string };\n // esbuild hasn't released a v1 yet, so we'll return the minor version as the major version\n return esbuild.version?.split('.')[1];\n } catch {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\nconst pluginName = 'sentry-esbuild-plugin';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function sentryEsbuildPlugin(userOptions: InternalOptions = {}): any {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[${pluginName}]`,\n buildTool: 'esbuild',\n buildToolMajorVersion: getEsbuildMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n name: 'sentry-esbuild-noop-plugin',\n setup() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n // Component annotation warning\n if (options.reactComponentAnnotation?.enabled) {\n logger.warn(\n 'Component name annotation is not supported in esbuild. Please use a separate transform step or consider using a different bundler.',\n );\n }\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n // Track entry points wrapped for debug ID injection\n const debugIdWrappedPaths = new Set<string>();\n\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n return {\n name: pluginName,\n setup({ initialOptions, onLoad, onResolve, onStart, onEnd }: EsbuildPluginBuild) {\n // Release and/or metadata injection\n if (!staticInjectionCode.isEmpty()) {\n const virtualInjectionFilePath = path.resolve('_sentry-injection-stub');\n initialOptions.inject = initialOptions.inject || [];\n // esbuild emits injected files after an entry's directive prologue. A banner would precede\n // \"use strict\" and turn it into an ordinary string expression.\n initialOptions.inject.push(virtualInjectionFilePath);\n\n onResolve({ filter: /_sentry-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n };\n });\n\n onLoad({ filter: /_sentry-injection-stub/ }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: staticInjectionCode.code(),\n };\n });\n }\n\n // Bundle size optimizations\n if (transformReplace) {\n const replacementStringValues: Record<string, string> = {};\n Object.entries(replacementValues).forEach(([key, value]) => {\n replacementStringValues[key] = JSON.stringify(value);\n });\n\n initialOptions.define = { ...initialOptions.define, ...replacementStringValues };\n }\n\n // Debug ID injection - requires per-entry-point unique IDs\n if (sourcemapsEnabled) {\n // `setup` runs once per context, `onStart` once per build, so a\n // rebuild wraps the entry points again.\n onStart(() => debugIdWrappedPaths.clear());\n\n // The proxy module re-exports `OriginalModule.default` statically so downstream bundlers can tree-shake it,\n // but esbuild warns about that access when the entry point has no default export.\n initialOptions.logOverride = { 'import-is-undefined': 'silent', ...initialOptions.logOverride };\n\n if (!initialOptions.bundle) {\n logger.warn(\n 'The Sentry esbuild plugin only supports esbuild with `bundle: true` being set in the esbuild build options. Esbuild will probably crash now. Sorry about that. If you need to upload sourcemaps without `bundle: true`, it is recommended to use Sentry CLI instead: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/',\n );\n }\n\n // Wrap entry points to inject debug IDs\n onResolve({ filter: /.*/ }, args => {\n if (args.kind !== 'entry-point') {\n return;\n }\n\n // Skip injecting debug IDs into modules specified in the esbuild `inject` option\n // since they're already part of the entry points\n if (initialOptions.inject?.includes(args.path)) {\n return;\n }\n\n const resolvedPath = path.isAbsolute(args.path) ? args.path : path.join(args.resolveDir, args.path);\n\n // Skip injecting debug IDs into paths that have already been wrapped\n if (debugIdWrappedPaths.has(resolvedPath)) {\n return;\n }\n debugIdWrappedPaths.add(resolvedPath);\n\n return {\n pluginName,\n path: resolvedPath,\n pluginData: {\n isDebugIdProxy: true,\n originalPath: args.path,\n originalResolveDir: args.resolveDir,\n },\n // We need to add a suffix here, otherwise esbuild will mark the entrypoint as resolved and won't traverse\n // the module tree any further down past the proxy module because we're essentially creating a dependency\n // loop back to the proxy module.\n // By setting a suffix we're telling esbuild that the entrypoint and proxy module are two different things,\n // making it re-resolve the entrypoint when it is imported from the proxy module.\n // Super confusing? Yes. Works? Apparently... Let's see.\n suffix: '?sentryDebugIdProxy=true',\n };\n });\n\n onLoad({ filter: /.*/ }, args => {\n if (!(args.pluginData as { isDebugIdProxy?: boolean })?.isDebugIdProxy) {\n return null;\n }\n\n const originalPath = (args.pluginData as { originalPath: string }).originalPath;\n const originalResolveDir = (args.pluginData as { originalResolveDir: string }).originalResolveDir;\n\n return {\n loader: 'js',\n pluginName,\n contents: `\n import \"_sentry-debug-id-injection-stub\";\n import * as OriginalModule from ${stringifyForCodeInjection(originalPath)};\n export default OriginalModule.default;\n export * from ${stringifyForCodeInjection(originalPath)};`,\n resolveDir: originalResolveDir,\n };\n });\n\n onResolve({ filter: /_sentry-debug-id-injection-stub/ }, args => {\n return {\n path: args.path,\n sideEffects: true,\n pluginName,\n namespace: 'sentry-debug-id-stub',\n suffix: `?sentry-module-id=${randomUUID()}`,\n };\n });\n\n onLoad({ filter: /_sentry-debug-id-injection-stub/, namespace: 'sentry-debug-id-stub' }, () => {\n return {\n loader: 'js',\n pluginName,\n contents: getDebugIdSnippet(randomUUID()).code(),\n };\n });\n }\n\n // With `write: false` nothing reaches the disk, so nothing can be uploaded or deleted.\n const sourceMapKind = sourceMapKindFromEsbuildSetting(initialOptions.sourcemap);\n const sourceMapDecision: SourceMapDecision =\n initialOptions.write === false\n ? { enableHidden: false, deleteAfterUpload: false }\n : sentryBuildPluginManager.sourceMaps.decide(sourceMapKind);\n if (sourceMapDecision.enableHidden) {\n initialOptions.sourcemap = 'external';\n }\n\n // Create release and optionally upload\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n initialOptions.metafile = true;\n onEnd(async result => {\n try {\n await sentryBuildPluginManager.createRelease();\n\n // The metafile lists outputs relative to `absWorkingDir`, not to the process.\n const outputDir = initialOptions.absWorkingDir ?? process.cwd();\n const buildArtifacts = result.metafile\n ? Object.keys(result.metafile.outputs).map(output => path.resolve(outputDir, output))\n : [];\n\n const { sourceMaps } = sentryBuildPluginManager;\n const allMaps = buildArtifacts.filter(artifact => artifact.endsWith('.map'));\n const deleteWithoutUpload = sourceMapDecision.deleteAfterUpload && !sourceMaps.uploadPossible;\n if (sourcemapsEnabled && options.sourcemaps?.disable === 'disable-upload') {\n if (initialOptions.write === false) {\n logger.debug('Build output is not written to disk. Skipping debug ID injection into build artifacts.');\n } else {\n // The upload routine (which stamps debug IDs into temp copies of the artifacts) is\n // skipped with `disable-upload`. esbuild has no hook to modify outputs before they are\n // written, so the emitted artifacts get stamped on disk instead.\n await Promise.all(\n buildArtifacts\n .filter(isJsFile)\n .map(bundle => addDebugIdToEmittedArtifacts(bundle, logger, options.sourcemaps?.resolveSourceMap)),\n );\n }\n } else if (sourcemapsEnabled) {\n // The upload globs the paths, and glob reads backslashes as escapes.\n // When no upload can run, this logs why.\n const { uploaded, uploadedSourceMapPaths } = await upload(\n buildArtifacts.map(artifact => artifact.split(path.sep).join('/')),\n );\n\n // esbuild writes before `onEnd` runs, so the maps are deleted from disk\n // afterwards instead of being dropped from the output like in other bundlers.\n // A map the plugin turned on never stays in the output. A map the user\n // enabled is only deleted once it was uploaded.\n if (sourceMapDecision.deleteAfterUpload && !deleteWithoutUpload) {\n const mapsToDelete = sourceMapDecision.removeAllSourceMaps ? allMaps : uploadedSourceMapPaths;\n\n if (uploaded) {\n await sourceMaps.deleteFromOutput(mapsToDelete);\n } else if (mapsToDelete.length > 0) {\n logger.error('The source maps were not uploaded, so they stay in the build output.');\n }\n }\n }\n\n if (deleteWithoutUpload) {\n const bundleOf = (map: string): string => map.slice(0, -'.map'.length);\n const isUploaded = (map: string): boolean =>\n isJsFile(bundleOf(map)) && sourceMaps.shouldUpload(bundleOf(map));\n await sourceMaps.deleteFromOutput(\n sourceMapDecision.removeAllSourceMaps ? allMaps : allMaps.filter(isUploaded),\n );\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n });\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default sentryEsbuildPlugin;\nexport type { Options as SentryEsbuildPluginOptions } from '../core';\n"],"mappings":";;;;;;;;;;;AAkEA,SAAS,gCAAgC,SAAiD;CACxF,QAAQ,SAAR;EACE,KAAK,KAAA,GACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK;EACL,KAAK,QACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAgBA,SAAS,yBAA6C;CACpD,IAAI;EAMF,OAHY,cAAc,YAAY,GACpB,CAAC,CAAC,SAEP,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,CAAC;CACrC,QAAQ,CAER;AAGF;AAEA,MAAM,aAAa;AAGnB,SAAgB,oBAAoB,cAA+B,CAAC,GAAQ;CAC1E,MAAM,2BAA2B,+BAA+B,aAAa;EAC3E,cAAc,YAAY,cAAc,wBAAwB,IAAI,WAAW;EAC/E,WAAW;EACX,uBAAuB,uBAAuB;CAChD,CAAC;CAED,MAAM,EACJ,QACA,mBAAmB,SACnB,yCAAyC,mBACzC,gBACA,qCACE;CAEJ,IAAI,QAAQ,SACV,OAAO;EACL,MAAM;EACN,QAAQ,CAER;CACF;CAGF,IAAI,QAAQ,IAAI,CAAC,CAAC,MAAM,mCAAmC,GACzD,OAAO,KAAK,wFAAwF;CAGtG,MAAM,oBAAoB,QAAQ,YAAY,YAAY;CAC1D,MAAM,sBAAsB,IAAI,cAAc;CAE9C,IAAI,CAAC,QAAQ,QAAQ,QACnB,OAAO,MAAM,kFAAkF;MAC1F,IAAI,CAAC,QAAQ,QAAQ,MAC1B,OAAO,MACL,mHACF;MAEA,oBAAoB,OAClB,4BAA4B;EAC1B,SAAS,QAAQ,QAAQ;EACzB,wBAAwB,QAAQ,aAAa,0BAA0B;CACzE,C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.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"11.
|
|
1
|
+
{"type":"module","version":"11.14.0","sideEffects":["./sentry-release-injection-file.js","./sentry-esbuild-debugid-injection-file.js"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/core/utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/core/utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQ9C;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAE9D;AAED,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,WAAW,GAAG,SAAS,CAE/G;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA4DjE;AAmBD,wBAAgB,eAAe,CAAC,WAAW,EAAE,WAAW,GAAG;IACzD,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAwBA;AAmDD;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQhD;AA4BD;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAajD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM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AAW,EAUpC;IAEM,IAAI,IAAI,MAAM,CAMpB;IAEM,OAAO,IAAI,OAAO,CAExB;IAEM,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAMhD;IAEM,KAAK,IAAI,IAAI,CAEnB;IAEM,KAAK,IAAI,aAAa,CAE5B;CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "11.
|
|
1
|
+
export declare const LIB_VERSION = "11.14.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/esbuild/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/esbuild/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAoC,MAAM,SAAS,CAAC;AAiHjF,wBAAgB,mBAAmB,CAAC,WAAW,GAAE,eAAoB,GAAG,GAAG,CAmR1E;eAGc,mBAAmB;AAClC,YAAY,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/bundler-plugins",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.14.0",
|
|
4
4
|
"description": "Sentry Bundler Plugins",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"@sentry/core": "11.
|
|
94
|
+
"@sentry/core": "11.14.0",
|
|
95
95
|
"dotenv": "^17.4.2",
|
|
96
96
|
"glob": "^14.0.3",
|
|
97
97
|
"magic-string": "~0.30.8 || ^1.0.0",
|
|
@@ -114,8 +114,8 @@
|
|
|
114
114
|
"@babel/core": "^7.18.5",
|
|
115
115
|
"@babel/parser": "^8.0.10",
|
|
116
116
|
"@babel/preset-react": "^7.23.3",
|
|
117
|
-
"@sentry-internal/rollup-utils": "11.
|
|
118
|
-
"@sentry-internal/test-utils": "11.
|
|
117
|
+
"@sentry-internal/rollup-utils": "11.14.0",
|
|
118
|
+
"@sentry-internal/test-utils": "11.14.0",
|
|
119
119
|
"@types/babel__core": "^7.20.5",
|
|
120
120
|
"@types/node": "^20.19.0",
|
|
121
121
|
"rolldown": "^1.0.0",
|