From 7b7793f285d020723608ddd6a71befdb9f2463c3 Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 10:24:35 +0200 Subject: [PATCH 01/11] initial migration --- dev-packages/rollup-utils/bundleHelpers.mjs | 8 +- dev-packages/rollup-utils/npmHelpers.mjs | 8 +- .../rollup-utils/plugins/npmPlugins.mjs | 90 +++++++------ .../plugins/vendor/sucrase-plugin.mjs | 79 ----------- dev-packages/rollup-utils/utils.mjs | 9 +- package.json | 6 +- yarn.lock | 124 ++++-------------- 7 files changed, 90 insertions(+), 234 deletions(-) delete mode 100644 dev-packages/rollup-utils/plugins/vendor/sucrase-plugin.mjs diff --git a/dev-packages/rollup-utils/bundleHelpers.mjs b/dev-packages/rollup-utils/bundleHelpers.mjs index 8dd2ebd21999..96d84d660027 100644 --- a/dev-packages/rollup-utils/bundleHelpers.mjs +++ b/dev-packages/rollup-utils/bundleHelpers.mjs @@ -8,14 +8,13 @@ import deepMerge from 'deepmerge'; import { makeBrowserBuildPlugin, - makeCleanupPlugin, makeCommonJSPlugin, + makeEsbuildPlugin, makeIsDebugBuildPlugin, makeLicensePlugin, makeNodeResolvePlugin, makeRrwebBuildPlugin, makeSetSDKSourcePlugin, - makeSucrasePlugin, makeTerserPlugin, } from './plugins/index.mjs'; import { mergePlugins } from './utils.mjs'; @@ -27,8 +26,7 @@ export function makeBaseBundleConfig(options) { const { bundleType, entrypoints, licenseTitle, outputFileBase, packageSpecificConfig, sucrase } = options; const nodeResolvePlugin = makeNodeResolvePlugin(); - const sucrasePlugin = makeSucrasePlugin({}, sucrase); - const cleanupPlugin = makeCleanupPlugin(); + const transpilePlugin = makeEsbuildPlugin({}, sucrase); const markAsBrowserBuildPlugin = makeBrowserBuildPlugin(true); const licensePlugin = makeLicensePlugin(licenseTitle); const rrwebBuildPlugin = makeRrwebBuildPlugin({ @@ -118,7 +116,7 @@ export function makeBaseBundleConfig(options) { strict: false, esModule: false, }, - plugins: [productionReplacePlugin, sucrasePlugin, nodeResolvePlugin, cleanupPlugin], + plugins: [productionReplacePlugin, transpilePlugin, nodeResolvePlugin], treeshake: 'smallest', }; diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index e361b00ef2b8..0ac125755a58 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -13,12 +13,11 @@ import deepMerge from 'deepmerge'; import { defineConfig } from 'rollup'; import { - makeCleanupPlugin, makeDebugBuildStatementReplacePlugin, + makeEsbuildPlugin, makeNodeResolvePlugin, makeProductionReplacePlugin, makeRrwebBuildPlugin, - makeSucrasePlugin, } from './plugins/index.mjs'; import { makePackageNodeEsm } from './plugins/make-esm-plugin.mjs'; import { mergeExternals, mergePlugins } from './utils.mjs'; @@ -39,9 +38,8 @@ export function makeBaseNPMConfig(options = {}) { } = options; const nodeResolvePlugin = makeNodeResolvePlugin(); - const sucrasePlugin = makeSucrasePlugin({}, sucrase); + const transpilePlugin = makeEsbuildPlugin({}, sucrase); const debugBuildStatementReplacePlugin = makeDebugBuildStatementReplacePlugin(); - const cleanupPlugin = makeCleanupPlugin(); const rrwebBuildPlugin = makeRrwebBuildPlugin({ excludeShadowDom: undefined, excludeIframe: undefined, @@ -104,7 +102,7 @@ export function makeBaseNPMConfig(options = {}) { }, }, - plugins: [nodeResolvePlugin, sucrasePlugin, debugBuildStatementReplacePlugin, rrwebBuildPlugin, cleanupPlugin], + plugins: [nodeResolvePlugin, transpilePlugin, debugBuildStatementReplacePlugin, rrwebBuildPlugin], // don't include imported modules from outside the package in the final output // also treat subpath exports (e.g. `@sentry/core/browser`) as external diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index 221a4a34f8c4..1af62f253a9c 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -2,37 +2,68 @@ * Rollup plugin hooks docs: https://rollupjs.org/guide/en/#build-hooks and * https://rollupjs.org/guide/en/#output-generation-hooks * - * Cleanup plugin docs: https://github.com/aMarCruz/rollup-plugin-cleanup + * esbuild plugin docs: https://github.com/egoist/rollup-plugin-esbuild * Replace plugin docs: https://github.com/rollup/plugins/tree/master/packages/replace - * Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase */ import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; -import cleanup from 'rollup-plugin-cleanup'; -import sucrase from './vendor/sucrase-plugin.mjs'; +import esbuild from 'rollup-plugin-esbuild'; /** - * Create a plugin to transpile TS syntax using `sucrase`. + * Create a plugin to transpile TS/JSX syntax using `esbuild`. * - * @returns An instance of the `@rollup/plugin-sucrase` plugin + * `target: 'es2020'` keeps ES2020-native syntax (`?.`, `??`, optional catch binding) and + * downlevels everything newer (logical assignment, numeric separators, class private + * fields, static class blocks, ...) — replacing the policy the legacy `getsentry/sucrase` + * fork used to enforce. + * + * The second argument keeps the legacy `sucrase: { jsxRuntime, jsxPragma, ... }` option + * shape so per-package `rollup.*.config.mjs` files keep working unchanged; we just + * translate the JSX-related keys to their esbuild equivalents. */ -export function makeSucrasePlugin(options = {}, sucraseOptions = {}) { - return sucrase( - { - // Required for bundling OTEL code properly - exclude: ['**/*.json'], - ...options, - }, - { - transforms: ['typescript', 'jsx'], - // We use a custom forked version of sucrase, - // where there is a new option `disableES2019Transforms` - disableESTransforms: false, - disableES2019Transforms: true, - ...sucraseOptions, +export function makeEsbuildPlugin(options = {}, transpileOptions = {}) { + const { jsxRuntime, jsxPragma, jsxFragmentPragma, production, transforms: _transforms, ...rest } = transpileOptions; + + const jsxOptions = {}; + if (jsxRuntime === 'automatic') { + jsxOptions.jsx = 'automatic'; + if (typeof production === 'boolean') jsxOptions.jsxDev = !production; + } else if (jsxRuntime === 'preserve') { + jsxOptions.jsx = 'preserve'; + } else { + // legacy default and 'classic' both map to esbuild's 'transform' + jsxOptions.jsx = 'transform'; + } + if (jsxPragma) jsxOptions.jsxFactory = jsxPragma; + if (jsxFragmentPragma) jsxOptions.jsxFragment = jsxFragmentPragma; + + const plugin = esbuild({ + // `.json` is handled by the JSON plugin further down the pipeline. + exclude: ['**/*.json'], + ...options, + // ES2020 is our floor — keeps `?.`/`??` native, downlevels everything newer. + target: 'es2020', + // Don't read per-package tsconfig (they vary and can pull in unrelated settings). + // Pin only the compilerOptions that affect codegen. + tsconfig: false, + tsconfigRaw: { + compilerOptions: { + // Match the project tsconfig's effective behavior at target=es2020: class + // field initializers compile to `this.x = v` (set semantics), not via the + // `Object.defineProperty`-based `__publicField` helper esbuild emits by + // default. This is what sucrase/tsc output too. + useDefineForClassFields: false, + }, }, - ); + sourceMap: true, + ...jsxOptions, + ...rest, + }); + + // Force a stable plugin name so the plugin sort order in utils.mjs can target it. + plugin.name = 'esbuild'; + return plugin; } export function makeJsonPlugin() { @@ -89,23 +120,6 @@ export function makeDebuggerPlugin(hookName) { }; } -/** - * Create a plugin to clean up output files by: - * - Converting line endings unix line endings - * - Removing consecutive empty lines - * - * @returns A `rollup-plugin-cleanup` instance. - */ -export function makeCleanupPlugin() { - return cleanup({ - // line endings are unix-ized by default - comments: 'all', // comments to keep - compactComments: 'false', // don't remove blank lines in multi-line comments - maxEmptyLines: 1, - extensions: ['js', 'jsx', 'ts', 'tsx'], - }); -} - /** * Creates a plugin to replace all instances of "__DEBUG_BUILD__" with a safe statement that * a) evaluates to `true` diff --git a/dev-packages/rollup-utils/plugins/vendor/sucrase-plugin.mjs b/dev-packages/rollup-utils/plugins/vendor/sucrase-plugin.mjs deleted file mode 100644 index 63465e768bc9..000000000000 --- a/dev-packages/rollup-utils/plugins/vendor/sucrase-plugin.mjs +++ /dev/null @@ -1,79 +0,0 @@ -// Vendored from https://github.com/rollup/plugins/blob/0090e728f52828d39b071ab5c7925b9b575cd568/packages/sucrase/src/index.js and modified - -/* - -The MIT License (MIT) - -Copyright (c) 2019 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -*/ - -import fs from 'fs'; -import path from 'path'; - -import { createFilter } from '@rollup/pluginutils'; -import { transform } from 'sucrase'; - -export default function sucrase(opts = {}, sucraseOpts = {}) { - const filter = createFilter(opts.include, opts.exclude); - - return { - name: 'sucrase', - - // eslint-disable-next-line consistent-return - resolveId(importee, importer) { - if (importer && /^[./]/.test(importee)) { - const resolved = path.resolve(importer ? path.dirname(importer) : process.cwd(), importee); - // resolve in the same order that TypeScript resolves modules - const resolvedFilenames = [ - `${resolved}.ts`, - `${resolved}.tsx`, - `${resolved}/index.ts`, - `${resolved}/index.tsx`, - ]; - if (resolved.endsWith('.js')) { - resolvedFilenames.splice(2, 0, `${resolved.slice(0, -3)}.ts`, `${resolved.slice(0, -3)}.tsx`); - } - const resolvedFilename = resolvedFilenames.find(filename => fs.existsSync(filename)); - - if (resolvedFilename) { - return resolvedFilename; - } - } - }, - - transform(code, id) { - if (!filter(id)) return null; - const result = transform(code, { - transforms: sucraseOpts.transforms, - filePath: id, - sourceMapOptions: { - compiledFilename: id, - }, - ...sucraseOpts, - }); - return { - code: result.code, - map: result.sourceMap, - }; - }, - }; -} diff --git a/dev-packages/rollup-utils/utils.mjs b/dev-packages/rollup-utils/utils.mjs index dd64e1e38c10..fbcc5cc7cc64 100644 --- a/dev-packages/rollup-utils/utils.mjs +++ b/dev-packages/rollup-utils/utils.mjs @@ -35,16 +35,13 @@ export function mergeExternals(base, specific) { export function mergePlugins(pluginsA, pluginsB) { const plugins = [...pluginsA, ...pluginsB]; plugins.sort((a, b) => { - // Hacky way to make sure the ones we care about end up where they belong in the order. Really the TS and sucrase - // plugins are tied - both should come first - but they're mutually exclusive, so they can come in arbitrary order - // here. - // Additionally, the excludeReplay plugin must run before TS/Sucrase so that we can eliminate the replay code + // Hacky way to make sure the ones we care about end up where they belong in the order. + // Additionally, the excludeReplay plugin must run before TS/esbuild so that we can eliminate the replay code // before anything is type-checked (TS-only) and transpiled. const order = [ 'remove-dev-mode-blocks', 'excludeReplay', - 'typescript', - 'sucrase', + 'esbuild', '...', 'terser', 'license', diff --git a/package.json b/package.json index bca64a9f863f..07aa2877bc8a 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,6 @@ "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-replace": "^5.0.5", - "@rollup/plugin-sucrase": "^5.0.2", "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^11.1.6", "@rollup/pluginutils": "^5.1.0", @@ -130,6 +129,7 @@ "deepmerge": "^4.2.2", "downlevel-dts": "~0.11.0", "es-check": "^7.2.1", + "esbuild": "^0.28.0", "jsdom": "^21.1.2", "madge": "8.0.0", "nodemon": "^3.1.10", @@ -140,10 +140,9 @@ "oxlint-tsgolint": "^0.16.0", "rimraf": "^5.0.10", "rollup": "^4.60.3", - "rollup-plugin-cleanup": "^3.2.1", + "rollup-plugin-esbuild": "^6.2.1", "rollup-plugin-license": "^3.7.1", "size-limit": "~12.1.0", - "sucrase": "^3.35.0", "ts-node": "10.9.2", "typescript": "~5.8.0", "vitest": "^3.2.4", @@ -161,7 +160,6 @@ "gauge/strip-ansi": "6.0.1", "wide-align/string-width": "4.2.3", "cliui/wrap-ansi": "7.0.0", - "sucrase": "getsentry/sucrase#es2020-polyfills", "**/express/path-to-regexp": "0.1.12", "**/@verdaccio/local-storage-legacy/lodash": "4.17.23", "**/@verdaccio/core/minimatch": "~7.4.9" diff --git a/yarn.lock b/yarn.lock index 06a319881032..9da6ebb512f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7492,14 +7492,6 @@ "@rollup/pluginutils" "^5.0.1" magic-string "^0.30.3" -"@rollup/plugin-sucrase@^5.0.2": - version "5.0.2" - resolved "https://registry.yarnpkg.com/@rollup/plugin-sucrase/-/plugin-sucrase-5.0.2.tgz#f8b8b54ad789a47fa882b968a76cede0194eea6e" - integrity sha512-4MhIVH9Dy2Hwose1/x5QMs0XF7yn9jDd/yozHqzdIrMWIolgFpGnrnVhQkqTaK1RALY/fpyrEKmwH/04vr1THA== - dependencies: - "@rollup/pluginutils" "^5.0.1" - sucrase "^3.27.0" - "@rollup/plugin-terser@^0.4.4": version "0.4.4" resolved "https://registry.yarnpkg.com/@rollup/plugin-terser/-/plugin-terser-0.4.4.tgz#15dffdb3f73f121aa4fbb37e7ca6be9aeea91962" @@ -11225,7 +11217,7 @@ ansis@^4.1.0: resolved "https://registry.yarnpkg.com/ansis/-/ansis-4.2.0.tgz#2e6e61c46b11726ac67f78785385618b9e658780" integrity sha512-HqZ5rWlFjGiV0tDm3UxxgNRqsOTniqoKZu0pIAfh7TZQMGuZK+hH0drySty0si0QXj1ieop4+SkSfPZBPPkHig== -any-promise@^1.0.0, any-promise@^1.1.0: +any-promise@^1.1.0: version "1.3.0" resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f" integrity sha1-q8av7tzqUugJzcA3au0845Y10X8= @@ -13662,7 +13654,7 @@ commander@^2.20.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^4.0.0, commander@^4.1.1: +commander@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068" integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA== @@ -15907,7 +15899,7 @@ es-module-lexer@^0.9.0: resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-0.9.3.tgz#6f13db00cc38417137daf74366f535c8eb438f19" integrity sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ== -es-module-lexer@^1.3.0, es-module-lexer@^1.3.1, es-module-lexer@^1.7.0: +es-module-lexer@^1.3.0, es-module-lexer@^1.3.1, es-module-lexer@^1.6.0, es-module-lexer@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.7.0.tgz#9159601561880a85f2734560a9099b2c31e5372a" integrity sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA== @@ -16849,11 +16841,6 @@ estree-walker@2.0.2, estree-walker@^2.0.2: resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac" integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w== -estree-walker@^0.6.1: - version "0.6.1" - resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362" - integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w== - estree-walker@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" @@ -18102,6 +18089,13 @@ get-symbol-description@^1.1.0: es-errors "^1.3.0" get-intrinsic "^1.2.6" +get-tsconfig@^4.10.0: + version "4.14.0" + resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.14.0.tgz#985d85c52a9903864280ccc2448d413fbf1efed8" + integrity sha512-yTb+8DXzDREzgvYmh6s9vHsSVCHeC0G3PI5bEXNBHtmshPnO+S5O7qgLEOn0I5QvMy6kpZN8K1NKGyilLb93wA== + dependencies: + resolve-pkg-maps "^1.0.0" + get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" @@ -18179,7 +18173,7 @@ glob@8.0.3: minimatch "^5.0.1" once "^1.3.0" -glob@^10.0.0, glob@^10.3.10, glob@^10.3.7, glob@^10.4.1: +glob@^10.0.0, glob@^10.3.7, glob@^10.4.1: version "10.5.0" resolved "https://registry.yarnpkg.com/glob/-/glob-10.5.0.tgz#8ec0355919cd3338c28428a23d4f24ecc5fe738c" integrity sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg== @@ -20194,15 +20188,6 @@ jiti@^2.1.2, jiti@^2.4.2, jiti@^2.6.1: resolved "https://registry.yarnpkg.com/jiti/-/jiti-2.6.1.tgz#178ef2fc9a1a594248c20627cd820187a4d78d92" integrity sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ== -js-cleanup@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/js-cleanup/-/js-cleanup-1.2.0.tgz#8dbc65954b1d38b255f1e8cf02cd17b3f7a053f9" - integrity sha512-JeDD0yiiSt80fXzAVa/crrS0JDPQljyBG/RpOtaSbyDq03VHa9szJWMaWOYU/bcTn412uMN2MxApXq8v79cUiQ== - dependencies: - magic-string "^0.25.7" - perf-regexes "^1.0.1" - skip-regex "^1.0.2" - js-md4@^0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/js-md4/-/js-md4-0.3.2.tgz#cd3b3dc045b0c404556c81ddb5756c23e59d7cf5" @@ -22564,15 +22549,6 @@ mysql@^2.18.1: safe-buffer "5.1.2" sqlstring "2.3.1" -mz@^2.7.0: - version "2.7.0" - resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32" - integrity sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q== - dependencies: - any-promise "^1.0.0" - object-assign "^4.0.1" - thenify-all "^1.0.0" - named-placeholders@^1.1.6: version "1.1.6" resolved "https://registry.yarnpkg.com/named-placeholders/-/named-placeholders-1.1.6.tgz#c50c6920b43f258f59c16add1e56654f5cc02bb5" @@ -23419,7 +23395,7 @@ nypm@^0.6.0, nypm@^0.6.2, nypm@^0.6.5: pathe "^2.0.3" tinyexec "^1.0.2" -object-assign@4.1.1, object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1: +object-assign@4.1.1, object-assign@^4, object-assign@^4.1.0, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= @@ -24337,11 +24313,6 @@ pend@~1.2.0: resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50" integrity sha1-elfrVQpng/kRUzH89GY9XI4AelA= -perf-regexes@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/perf-regexes/-/perf-regexes-1.0.1.tgz#6da1d62f5a94bf9353a0451bccacf69068b75d0b" - integrity sha512-L7MXxUDtqr4PUaLFCDCXBfGV/6KLIuSEccizDI7JxT+c9x1G1v04BQ4+4oag84SHaCdrBgQAIs/Cqn+flwFPng== - perfect-debounce@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/perfect-debounce/-/perfect-debounce-1.0.0.tgz#9c2e8bc30b169cc984a58b7d5b28049839591d2a" @@ -24523,11 +24494,6 @@ pino@9.10.0: sonic-boom "^4.0.1" thread-stream "^3.0.0" -pirates@^4.0.1: - version "4.0.6" - resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.6.tgz#3018ae32ecfcff6c29ba2267cbf21166ac1f36b9" - integrity sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg== - piscina@3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/piscina/-/piscina-3.2.0.tgz#f5a1dde0c05567775690cccefe59d9223924d154" @@ -26494,6 +26460,11 @@ resolve-pathname@^3.0.0: resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-3.0.0.tgz#99d02224d3cf263689becbb393bc560313025dcd" integrity sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng== +resolve-pkg-maps@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f" + integrity sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw== + resolve-url-loader@5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/resolve-url-loader/-/resolve-url-loader-5.0.0.tgz#ee3142fb1f1e0d9db9524d539cfa166e9314f795" @@ -26709,14 +26680,6 @@ rolldown@^1.0.0-rc.15, rolldown@^1.0.0-rc.8: "@rolldown/binding-win32-arm64-msvc" "1.0.0-rc.15" "@rolldown/binding-win32-x64-msvc" "1.0.0-rc.15" -rollup-plugin-cleanup@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/rollup-plugin-cleanup/-/rollup-plugin-cleanup-3.2.1.tgz#8cbc92ecf58babd7c210051929797f137bbf777c" - integrity sha512-zuv8EhoO3TpnrU8MX8W7YxSbO4gmOR0ny06Lm3nkFfq0IVKdBUtHwhVzY1OAJyNCIAdLiyPnOrU0KnO0Fri1GQ== - dependencies: - js-cleanup "^1.2.0" - rollup-pluginutils "^2.8.2" - rollup-plugin-dts@^6.0.0: version "6.1.1" resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-6.1.1.tgz#46b33f4d1d7f4e66f1171ced9b282ac11a15a254" @@ -26726,6 +26689,16 @@ rollup-plugin-dts@^6.0.0: optionalDependencies: "@babel/code-frame" "^7.24.2" +rollup-plugin-esbuild@^6.2.1: + version "6.2.1" + resolved "https://registry.yarnpkg.com/rollup-plugin-esbuild/-/rollup-plugin-esbuild-6.2.1.tgz#c556195465bf452965686e0f21adfe306b90c219" + integrity sha512-jTNOMGoMRhs0JuueJrJqbW8tOwxumaWYq+V5i+PD+8ecSCVkuX27tGW7BXqDgoULQ55rO7IdNxPcnsWtshz3AA== + dependencies: + debug "^4.4.0" + es-module-lexer "^1.6.0" + get-tsconfig "^4.10.0" + unplugin-utils "^0.2.4" + rollup-plugin-license@^3.7.1: version "3.7.1" resolved "https://registry.yarnpkg.com/rollup-plugin-license/-/rollup-plugin-license-3.7.1.tgz#b99329f1c840142559789e3d6cb9f69e9e5b36ef" @@ -26758,13 +26731,6 @@ rollup-plugin-visualizer@^6.0.3, rollup-plugin-visualizer@^6.0.5: source-map "^0.7.4" yargs "^17.5.1" -rollup-pluginutils@^2.8.2: - version "2.8.2" - resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e" - integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ== - dependencies: - estree-walker "^0.6.1" - rollup@^2.70.0: version "2.80.0" resolved "https://registry.npmjs.org/rollup/-/rollup-2.80.0.tgz" @@ -27586,11 +27552,6 @@ size-limit@~12.1.0: picocolors "^1.1.1" tinyglobby "^0.2.16" -skip-regex@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/skip-regex/-/skip-regex-1.0.2.tgz#ac655d77e7c771ac2b9f37585fea37bff56ad65b" - integrity sha512-pEjMUbwJ5Pl/6Vn6FsamXHXItJXSRftcibixDmNCWbWhic0hzHrwkMZo0IZ7fMRH9KxcWDFSkzhccB4285PutA== - slash@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" @@ -28484,18 +28445,6 @@ stylus@0.59.0, stylus@^0.59.0: sax "~1.2.4" source-map "^0.7.3" -sucrase@^3.27.0, sucrase@^3.35.0, sucrase@getsentry/sucrase#es2020-polyfills: - version "3.36.0" - resolved "https://codeload.github.com/getsentry/sucrase/tar.gz/fd682f6129e507c00bb4e6319cc5d6b767e36061" - dependencies: - "@jridgewell/gen-mapping" "^0.3.2" - commander "^4.0.0" - glob "^10.3.10" - lines-and-columns "^1.1.6" - mz "^2.7.0" - pirates "^4.0.1" - ts-interface-checker "^0.1.9" - sum-up@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/sum-up/-/sum-up-1.0.3.tgz#1c661f667057f63bcb7875aa1438bc162525156e" @@ -28885,20 +28834,6 @@ text-table@0.2.0, text-table@^0.2.0: resolved "https://registry.yarnpkg.com/textextensions/-/textextensions-2.6.0.tgz#d7e4ab13fe54e32e08873be40d51b74229b00fc4" integrity sha512-49WtAWS+tcsy93dRt6P0P3AMD2m5PvXRhuEA0kaXos5ZLlujtYmpmFsB+QvWUSxE1ZsstmYXfQ7L40+EcQgpAQ== -thenify-all@^1.0.0: - version "1.6.0" - resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726" - integrity sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA== - dependencies: - thenify ">= 3.1.0 < 4" - -"thenify@>= 3.1.0 < 4": - version "3.3.1" - resolved "https://registry.yarnpkg.com/thenify/-/thenify-3.3.1.tgz#8932e686a4066038a016dd9e2ca46add9838a95f" - integrity sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw== - dependencies: - any-promise "^1.0.0" - thread-stream@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/thread-stream/-/thread-stream-3.1.0.tgz#4b2ef252a7c215064507d4ef70c05a5e2d34c4f1" @@ -29226,11 +29161,6 @@ ts-graphviz@^2.1.2: "@ts-graphviz/common" "^2.1.5" "@ts-graphviz/core" "^2.0.7" -ts-interface-checker@^0.1.9: - version "0.1.13" - resolved "https://registry.yarnpkg.com/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz#784fd3d679722bc103b1b4b8030bcddb5db2a699" - integrity sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA== - ts-node@10.9.2: version "10.9.2" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.2.tgz#70f021c9e185bccdca820e26dc413805c101c71f" From 98a7a9af245c0d2e36566e6233c0c2ba85158dbc Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 10:32:10 +0200 Subject: [PATCH 02/11] improve comments & cleanup --- .../rollup-utils/plugins/npmPlugins.mjs | 3 +-- dev-packages/rollup-utils/utils.mjs | 27 +++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index 1af62f253a9c..db945268b3ba 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -15,8 +15,7 @@ import esbuild from 'rollup-plugin-esbuild'; * * `target: 'es2020'` keeps ES2020-native syntax (`?.`, `??`, optional catch binding) and * downlevels everything newer (logical assignment, numeric separators, class private - * fields, static class blocks, ...) — replacing the policy the legacy `getsentry/sucrase` - * fork used to enforce. + * fields, static class blocks, ...) * * The second argument keeps the legacy `sucrase: { jsxRuntime, jsxPragma, ... }` option * shape so per-package `rollup.*.config.mjs` files keep working unchanged; we just diff --git a/dev-packages/rollup-utils/utils.mjs b/dev-packages/rollup-utils/utils.mjs index fbcc5cc7cc64..29543684ac04 100644 --- a/dev-packages/rollup-utils/utils.mjs +++ b/dev-packages/rollup-utils/utils.mjs @@ -31,27 +31,26 @@ export function mergeExternals(base, specific) { /** * Merge two arrays of plugins, making sure they're sorted in the correct order. + * + * Each entry below has a real reason to be pinned; `...` is where every other plugin lands: + * - `remove-dev-mode-blocks` (transform) — must run before `esbuild` because esbuild + * strips the `/* rollup-include-development-only *\/` marker comments during transpile. + * - `esbuild` (transform) — produces JS that the rest of the transform plugins + * (replace, etc.) operate on. + * - `terser` (renderChunk) — minifies and strips comments. Anything that contributes + * code to a chunk must run before this. + * - `license` (renderChunk) — prepends the license banner, which is a comment. Must run + * after `terser` or terser would strip it (we minify with `comments: false`). + * - `output-base64-worker-script` (renderChunk) — captures the final chunk text as + * base64, so it must run last. */ export function mergePlugins(pluginsA, pluginsB) { + const order = ['remove-dev-mode-blocks', 'esbuild', '...', 'terser', 'license', 'output-base64-worker-script']; const plugins = [...pluginsA, ...pluginsB]; plugins.sort((a, b) => { - // Hacky way to make sure the ones we care about end up where they belong in the order. - // Additionally, the excludeReplay plugin must run before TS/esbuild so that we can eliminate the replay code - // before anything is type-checked (TS-only) and transpiled. - const order = [ - 'remove-dev-mode-blocks', - 'excludeReplay', - 'esbuild', - '...', - 'terser', - 'license', - 'output-base64-worker-script', - ]; const sortKeyA = order.includes(a.name) ? a.name : '...'; const sortKeyB = order.includes(b.name) ? b.name : '...'; - return order.indexOf(sortKeyA) - order.indexOf(sortKeyB); }); - return plugins; } From 60b7cff6f80c63d2940bed5b839dbba161aa3d65 Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 10:44:05 +0200 Subject: [PATCH 03/11] remove dev blocks refactor --- dev-packages/rollup-utils/npmHelpers.mjs | 11 +++++++++-- dev-packages/rollup-utils/plugins/npmPlugins.mjs | 16 +++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index 0ac125755a58..2ea364ba3508 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -152,8 +152,9 @@ export function makeNPMConfigVariants(baseConfig, options = {}) { output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm/prod'), - plugins: [makeProductionReplacePlugin(), makePackageNodeEsm()], + plugins: [makePackageNodeEsm()], }, + plugins: [makeProductionReplacePlugin()], }); } else { variantSpecificConfigs.push({ @@ -166,7 +167,13 @@ export function makeNPMConfigVariants(baseConfig, options = {}) { } } - return variantSpecificConfigs.map(variant => deepMerge(baseConfig, variant)); + return variantSpecificConfigs.map(variant => + // Plugin arrays must be merged in the right order or the build silently misbehaves + // (e.g. esbuild strips dev-mode marker comments before the replace plugin can act). + deepMerge(baseConfig, variant, { + customMerge: key => (key === 'plugins' ? mergePlugins : undefined), + }), + ); } /** diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index db945268b3ba..5678f0061c83 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -138,17 +138,15 @@ export function makeDebugBuildStatementReplacePlugin() { export function makeProductionReplacePlugin() { const pattern = /\/\* rollup-include-development-only \*\/[\s\S]*?\/\* rollup-include-development-only-end \*\/\s*/g; - function stripDevBlocks(code) { - if (!code) return null; - if (!code.includes('rollup-include-development-only')) return null; - const replaced = code.replace(pattern, ''); - return { code: replaced, map: null }; - } - + // Must run as a `transform` (per-module) hook rather than `renderChunk`: esbuild + // strips arbitrary block comments during transpile, so by the time `renderChunk` + // would fire, the `rollup-include-development-only` marker comments are gone. + // The plugin sort order in utils.mjs pins this before `esbuild`. return { name: 'remove-dev-mode-blocks', - renderChunk(code) { - return stripDevBlocks(code); + transform(code) { + if (!code.includes('rollup-include-development-only')) return null; + return { code: code.replace(pattern, ''), map: null }; }, }; } From abb560e9281eee39475b1d4b31707286621125ab Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 11:18:32 +0200 Subject: [PATCH 04/11] use esbuild option directly instead of legacy sucrase options --- dev-packages/rollup-utils/bundleHelpers.mjs | 4 +-- dev-packages/rollup-utils/npmHelpers.mjs | 4 +-- .../rollup-utils/plugins/npmPlugins.mjs | 31 +++++-------------- packages/feedback/rollup.bundle.config.mjs | 20 +++++------- packages/feedback/rollup.npm.config.mjs | 10 +++--- packages/react-router/rollup.npm.config.mjs | 10 +++--- packages/react/rollup.npm.config.mjs | 10 +++--- packages/remix/rollup.npm.config.mjs | 10 +++--- 8 files changed, 35 insertions(+), 64 deletions(-) diff --git a/dev-packages/rollup-utils/bundleHelpers.mjs b/dev-packages/rollup-utils/bundleHelpers.mjs index 96d84d660027..6ac5f6aff06d 100644 --- a/dev-packages/rollup-utils/bundleHelpers.mjs +++ b/dev-packages/rollup-utils/bundleHelpers.mjs @@ -23,10 +23,10 @@ import { makeProductionReplacePlugin } from './plugins/npmPlugins.mjs'; const BUNDLE_VARIANTS = ['.js', '.min.js', '.debug.min.js']; export function makeBaseBundleConfig(options) { - const { bundleType, entrypoints, licenseTitle, outputFileBase, packageSpecificConfig, sucrase } = options; + const { bundleType, entrypoints, licenseTitle, outputFileBase, packageSpecificConfig, esbuild } = options; const nodeResolvePlugin = makeNodeResolvePlugin(); - const transpilePlugin = makeEsbuildPlugin({}, sucrase); + const transpilePlugin = makeEsbuildPlugin(esbuild); const markAsBrowserBuildPlugin = makeBrowserBuildPlugin(true); const licensePlugin = makeLicensePlugin(licenseTitle); const rrwebBuildPlugin = makeRrwebBuildPlugin({ diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index 2ea364ba3508..4a184d1ea4e5 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -33,12 +33,12 @@ export function makeBaseNPMConfig(options = {}) { entrypoints = ['src/index.ts'], hasBundles = false, packageSpecificConfig = {}, - sucrase = {}, + esbuild = {}, bundledBuiltins = [], } = options; const nodeResolvePlugin = makeNodeResolvePlugin(); - const transpilePlugin = makeEsbuildPlugin({}, sucrase); + const transpilePlugin = makeEsbuildPlugin(esbuild); const debugBuildStatementReplacePlugin = makeDebugBuildStatementReplacePlugin(); const rrwebBuildPlugin = makeRrwebBuildPlugin({ excludeShadowDom: undefined, diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index 5678f0061c83..3c1a52340556 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -15,32 +15,16 @@ import esbuild from 'rollup-plugin-esbuild'; * * `target: 'es2020'` keeps ES2020-native syntax (`?.`, `??`, optional catch binding) and * downlevels everything newer (logical assignment, numeric separators, class private - * fields, static class blocks, ...) + * fields, static class blocks, ...). * - * The second argument keeps the legacy `sucrase: { jsxRuntime, jsxPragma, ... }` option - * shape so per-package `rollup.*.config.mjs` files keep working unchanged; we just - * translate the JSX-related keys to their esbuild equivalents. + * `esbuildOptions` are forwarded to `rollup-plugin-esbuild` verbatim and can override + * any of the pinned defaults (e.g. JSX-related keys like `jsxFactory` / `jsxFragment` + * for packages that use a non-React pragma). */ -export function makeEsbuildPlugin(options = {}, transpileOptions = {}) { - const { jsxRuntime, jsxPragma, jsxFragmentPragma, production, transforms: _transforms, ...rest } = transpileOptions; - - const jsxOptions = {}; - if (jsxRuntime === 'automatic') { - jsxOptions.jsx = 'automatic'; - if (typeof production === 'boolean') jsxOptions.jsxDev = !production; - } else if (jsxRuntime === 'preserve') { - jsxOptions.jsx = 'preserve'; - } else { - // legacy default and 'classic' both map to esbuild's 'transform' - jsxOptions.jsx = 'transform'; - } - if (jsxPragma) jsxOptions.jsxFactory = jsxPragma; - if (jsxFragmentPragma) jsxOptions.jsxFragment = jsxFragmentPragma; - +export function makeEsbuildPlugin(esbuildOptions = {}) { const plugin = esbuild({ // `.json` is handled by the JSON plugin further down the pipeline. exclude: ['**/*.json'], - ...options, // ES2020 is our floor — keeps `?.`/`??` native, downlevels everything newer. target: 'es2020', // Don't read per-package tsconfig (they vary and can pull in unrelated settings). @@ -51,13 +35,12 @@ export function makeEsbuildPlugin(options = {}, transpileOptions = {}) { // Match the project tsconfig's effective behavior at target=es2020: class // field initializers compile to `this.x = v` (set semantics), not via the // `Object.defineProperty`-based `__publicField` helper esbuild emits by - // default. This is what sucrase/tsc output too. + // default. This is what tsc itself outputs at this target. useDefineForClassFields: false, }, }, sourceMap: true, - ...jsxOptions, - ...rest, + ...esbuildOptions, }); // Force a stable plugin name so the plugin sort order in utils.mjs can target it. diff --git a/packages/feedback/rollup.bundle.config.mjs b/packages/feedback/rollup.bundle.config.mjs index a5efc6140c06..a7527f58b3b1 100644 --- a/packages/feedback/rollup.bundle.config.mjs +++ b/packages/feedback/rollup.bundle.config.mjs @@ -10,12 +10,10 @@ export default [ jsVersion: 'es6', licenseTitle: '@sentry-internal/feedback', outputFileBase: () => 'bundles/feedback-screenshot', - sucrase: { - // The feedback widget is using preact so we need different pragmas and jsx runtimes - jsxPragma: 'h', - jsxFragmentPragma: 'Fragment', - jsxRuntime: 'classic', - production: true, + esbuild: { + // The feedback widget uses preact, so override esbuild's React defaults. + jsxFactory: 'h', + jsxFragment: 'Fragment', }, }), ), @@ -26,12 +24,10 @@ export default [ jsVersion: 'es6', licenseTitle: '@sentry-internal/feedback', outputFileBase: () => 'bundles/feedback-modal', - sucrase: { - // The feedback widget is using preact so we need different pragmas and jsx runtimes - jsxPragma: 'h', - jsxFragmentPragma: 'Fragment', - jsxRuntime: 'classic', - production: true, + esbuild: { + // The feedback widget uses preact, so override esbuild's React defaults. + jsxFactory: 'h', + jsxFragment: 'Fragment', }, }), ), diff --git a/packages/feedback/rollup.npm.config.mjs b/packages/feedback/rollup.npm.config.mjs index c91c37ec84f8..103eb72c68dc 100644 --- a/packages/feedback/rollup.npm.config.mjs +++ b/packages/feedback/rollup.npm.config.mjs @@ -15,12 +15,10 @@ export default makeNPMConfigVariants( : Boolean(process.env.SENTRY_BUILD_PRESERVE_MODULES), }, }, - sucrase: { - // The feedback widget is using preact so we need different pragmas and jsx runtimes - jsxPragma: 'h', - jsxFragmentPragma: 'Fragment', - jsxRuntime: 'classic', - production: true, + esbuild: { + // The feedback widget uses preact, so override esbuild's React defaults. + jsxFactory: 'h', + jsxFragment: 'Fragment', }, }), ); diff --git a/packages/react-router/rollup.npm.config.mjs b/packages/react-router/rollup.npm.config.mjs index 4a52f4ab57a7..edd3e56f0cb8 100644 --- a/packages/react-router/rollup.npm.config.mjs +++ b/packages/react-router/rollup.npm.config.mjs @@ -1,5 +1,9 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; +// We rely on esbuild's defaults for JSX (`jsx: 'transform'` = classic runtime, no +// __self/__source attributes). React 19 prefers the new automatic transform, but switching +// to it would break React 17 support — so we intentionally stay on classic for now. +// https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html export default [ ...makeNPMConfigVariants( makeBaseNPMConfig({ @@ -11,12 +15,6 @@ export default [ exports: 'named', }, }, - sucrase: { - // React 19 emits a warning if we don't use the newer jsx transform: https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html - // but this breaks react 17, so we keep it at `classic` for now - jsxRuntime: 'classic', - production: true, // This is needed so that sucrase uses the production jsx runtime (ie `import { jsx } from 'react/jsx-runtime'` instead of `import { jsxDEV as _jsxDEV } from 'react/jsx-dev-runtime'`) - }, }), ), ]; diff --git a/packages/react/rollup.npm.config.mjs b/packages/react/rollup.npm.config.mjs index 923dfafb85d7..66c3b16aba58 100644 --- a/packages/react/rollup.npm.config.mjs +++ b/packages/react/rollup.npm.config.mjs @@ -1,15 +1,13 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; +// We rely on esbuild's defaults for JSX (`jsx: 'transform'` = classic runtime, no +// __self/__source attributes). React 19 prefers the new automatic transform, but switching +// to it would break React 17 support — so we intentionally stay on classic for now. +// https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html export default makeNPMConfigVariants( makeBaseNPMConfig({ packageSpecificConfig: { external: ['react', 'react/jsx-runtime'], }, - sucrase: { - // React 19 emits a warning if we don't use the newer jsx transform: https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html - // but this breaks react 17, so we keep it at `classic` for now - jsxRuntime: 'classic', - production: true, // This is needed so that sucrase uses the production jsx runtime (ie `import { jsx } from 'react/jsx-runtime'` instead of `import { jsxDEV as _jsxDEV } from 'react/jsx-dev-runtime'`) - }, }), ); diff --git a/packages/remix/rollup.npm.config.mjs b/packages/remix/rollup.npm.config.mjs index 8ba7eac8051b..23b3b4452816 100644 --- a/packages/remix/rollup.npm.config.mjs +++ b/packages/remix/rollup.npm.config.mjs @@ -1,5 +1,9 @@ import { makeBaseNPMConfig, makeNPMConfigVariants, makeOtelLoaders } from '@sentry-internal/rollup-utils'; +// We rely on esbuild's defaults for JSX (`jsx: 'transform'` = classic runtime, no +// __self/__source attributes). React 19 prefers the new automatic transform, but switching +// to it would break React 17 support — so we intentionally stay on classic for now. +// https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html export default [ ...makeNPMConfigVariants( makeBaseNPMConfig({ @@ -17,12 +21,6 @@ export default [ exports: 'named', }, }, - sucrase: { - // React 19 emits a warning if we don't use the newer jsx transform: https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html - // but this breaks react 17, so we keep it at `classic` for now - jsxRuntime: 'classic', - production: true, // This is needed so that sucrase uses the production jsx runtime (ie `import { jsx } from 'react/jsx-runtime'` instead of `import { jsxDEV as _jsxDEV } from 'react/jsx-dev-runtime'`) - }, }), ), ...makeOtelLoaders('./build', 'sentry-node'), From a3cd1314b064fd9207c4e9e85024351ed8cb38ad Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 11:29:36 +0200 Subject: [PATCH 05/11] fixes for order --- .../rollup-utils/plugins/bundlePlugins.mjs | 19 ++++++++++-- .../rollup-utils/plugins/npmPlugins.mjs | 8 +++-- dev-packages/rollup-utils/utils.mjs | 30 +++++++++++++------ 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/dev-packages/rollup-utils/plugins/bundlePlugins.mjs b/dev-packages/rollup-utils/plugins/bundlePlugins.mjs index 782e5d36c443..f8e16cb4ec37 100644 --- a/dev-packages/rollup-utils/plugins/bundlePlugins.mjs +++ b/dev-packages/rollup-utils/plugins/bundlePlugins.mjs @@ -46,7 +46,7 @@ export function makeLicensePlugin(title) { * 'false` */ export function makeIsDebugBuildPlugin(includeDebugging) { - return replace({ + const plugin = replace({ // TODO `preventAssignment` will default to true in version 5.x of the replace plugin, at which point we can get rid // of this. (It actually makes no difference in this case whether it's true or false, since we never assign to // `__SENTRY_DEBUG__`, but if we don't give it a value, it will spam with warnings.) @@ -58,16 +58,27 @@ export function makeIsDebugBuildPlugin(includeDebugging) { __SENTRY_DEBUG__: includeDebugging, }, }); + plugin.name = 'replace-debug-flags'; + return plugin; } +/** + * Replaces the comment marker `/* __SENTRY_SDK_SOURCE__ *\/` in core's `getSDKSource()` with a + * `return '';` statement so the bundle reports the correct distribution channel. + * + * Because the marker is a block comment, esbuild would strip it during transpile — so the plugin + * sort order in utils.mjs pins this name before `esbuild`. + */ export function makeSetSDKSourcePlugin(sdkSource) { - return replace({ + const plugin = replace({ preventAssignment: false, delimiters: ['', ''], values: { '/* __SENTRY_SDK_SOURCE__ */': `return ${JSON.stringify(sdkSource)};`, }, }); + plugin.name = 'replace-sdk-source'; + return plugin; } /** @@ -77,13 +88,15 @@ export function makeSetSDKSourcePlugin(sdkSource) { * @returns An instance of the `replace` plugin to do the replacement of the magic string with `true` or 'false` */ export function makeBrowserBuildPlugin(isBrowserBuild) { - return replace({ + const plugin = replace({ // TODO This will be the default in the next version of the `replace` plugin preventAssignment: true, values: { __SENTRY_BROWSER_BUNDLE__: isBrowserBuild, }, }); + plugin.name = 'replace-browser-bundle-flag'; + return plugin; } // `terser` options reference: https://github.com/terser/terser#api-reference diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index 3c1a52340556..f48e2a8a1f15 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -110,12 +110,14 @@ export function makeDebuggerPlugin(hookName) { * @returns A `@rollup/plugin-replace` instance. */ export function makeDebugBuildStatementReplacePlugin() { - return replace({ + const plugin = replace({ preventAssignment: false, values: { __DEBUG_BUILD__: "(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__)", }, }); + plugin.name = 'replace-debug-build-statement'; + return plugin; } export function makeProductionReplacePlugin() { @@ -153,8 +155,10 @@ export function makeRrwebBuildPlugin({ excludeShadowDom, excludeIframe } = {}) { values['__RRWEB_EXCLUDE_IFRAME__'] = excludeIframe; } - return replace({ + const plugin = replace({ preventAssignment: true, values, }); + plugin.name = 'replace-rrweb-build-flags'; + return plugin; } diff --git a/dev-packages/rollup-utils/utils.mjs b/dev-packages/rollup-utils/utils.mjs index 29543684ac04..37b19f30962f 100644 --- a/dev-packages/rollup-utils/utils.mjs +++ b/dev-packages/rollup-utils/utils.mjs @@ -32,20 +32,32 @@ export function mergeExternals(base, specific) { /** * Merge two arrays of plugins, making sure they're sorted in the correct order. * - * Each entry below has a real reason to be pinned; `...` is where every other plugin lands: - * - `remove-dev-mode-blocks` (transform) — must run before `esbuild` because esbuild - * strips the `/* rollup-include-development-only *\/` marker comments during transpile. - * - `esbuild` (transform) — produces JS that the rest of the transform plugins - * (replace, etc.) operate on. - * - `terser` (renderChunk) — minifies and strips comments. Anything that contributes - * code to a chunk must run before this. + * Each entry below is pinned for a real reason; `...` is where every other plugin lands. + * Plugins that depend on **comments** in the source MUST run before `esbuild`, because + * esbuild strips non-legal block comments during transpile. + * + * - `remove-dev-mode-blocks` (transform) — strips `/* rollup-include-development-only *\/` + * marker blocks. Comment-dependent → must precede `esbuild`. + * - `replace-sdk-source` (transform) — rewrites the `/* __SENTRY_SDK_SOURCE__ *\/` + * marker in `getSDKSource()` for CDN builds. Comment-dependent → must precede `esbuild`. + * - `esbuild` (transform) — TS/JSX → JS. Everything in `...` runs after this. + * - `terser` (renderChunk) — minifies and strips comments (we use `comments: false`). + * Anything that contributes code to a chunk must run before this. * - `license` (renderChunk) — prepends the license banner, which is a comment. Must run - * after `terser` or terser would strip it (we minify with `comments: false`). + * AFTER `terser`, otherwise terser would strip it. * - `output-base64-worker-script` (renderChunk) — captures the final chunk text as * base64, so it must run last. */ export function mergePlugins(pluginsA, pluginsB) { - const order = ['remove-dev-mode-blocks', 'esbuild', '...', 'terser', 'license', 'output-base64-worker-script']; + const order = [ + 'remove-dev-mode-blocks', + 'replace-sdk-source', + 'esbuild', + '...', + 'terser', + 'license', + 'output-base64-worker-script', + ]; const plugins = [...pluginsA, ...pluginsB]; plugins.sort((a, b) => { const sortKeyA = order.includes(a.name) ? a.name : '...'; From 0fe509add17a3f0f679acadafce2a98ea02e62c6 Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 16:09:36 +0200 Subject: [PATCH 06/11] fix nextjs test for new build output --- .../nextjs/test/config/wrappingLoader.test.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/nextjs/test/config/wrappingLoader.test.ts b/packages/nextjs/test/config/wrappingLoader.test.ts index 97e2b016301e..cdba71caeb17 100644 --- a/packages/nextjs/test/config/wrappingLoader.test.ts +++ b/packages/nextjs/test/config/wrappingLoader.test.ts @@ -100,7 +100,9 @@ describe('wrappingLoader', () => { await loaderPromise; - expect(callback).toHaveBeenCalledWith(null, expect.stringContaining("'/my/route'"), expect.anything()); + // Accept either single- or double-quoted string literals — the wrapper-template source + // uses single quotes, but esbuild rewrites them to double quotes during transpile. + expect(callback).toHaveBeenCalledWith(null, expect.stringMatching(/['"]\/my\/route['"]/), expect.anything()); }); describe('middleware wrapping', () => { @@ -148,8 +150,8 @@ describe('wrappingLoader', () => { expect(wrappedCode).toContain('userProvidedProxy = true'); // Proxy should be wrapped, middleware should be undefined - expect(wrappedCode).toMatch(/const proxy = userProvidedProxy \? wrappedHandler : undefined/); - expect(wrappedCode).toMatch(/const middleware = userProvidedMiddleware \? wrappedHandler : undefined/); + expect(wrappedCode).toMatch(/const proxy = userProvidedProxy \? wrappedHandler : (?:undefined|void 0)/); + expect(wrappedCode).toMatch(/const middleware = userProvidedMiddleware \? wrappedHandler : (?:undefined|void 0)/); }); it('should export middleware when user exports named "middleware" export', async () => { @@ -196,8 +198,8 @@ describe('wrappingLoader', () => { expect(wrappedCode).toContain('userProvidedProxy = false'); // Middleware should be wrapped, proxy should be undefined - expect(wrappedCode).toMatch(/const middleware = userProvidedMiddleware \? wrappedHandler : undefined/); - expect(wrappedCode).toMatch(/const proxy = userProvidedProxy \? wrappedHandler : undefined/); + expect(wrappedCode).toMatch(/const middleware = userProvidedMiddleware \? wrappedHandler : (?:undefined|void 0)/); + expect(wrappedCode).toMatch(/const proxy = userProvidedProxy \? wrappedHandler : (?:undefined|void 0)/); }); it('should export undefined middleware/proxy when user only exports default', async () => { @@ -245,8 +247,8 @@ describe('wrappingLoader', () => { expect(wrappedCode).toContain('userProvidedProxy = false'); // Both middleware and proxy should be undefined (conditionals evaluate to false) - expect(wrappedCode).toMatch(/const middleware = userProvidedMiddleware \? wrappedHandler : undefined/); - expect(wrappedCode).toMatch(/const proxy = userProvidedProxy \? wrappedHandler : undefined/); + expect(wrappedCode).toMatch(/const middleware = userProvidedMiddleware \? wrappedHandler : (?:undefined|void 0)/); + expect(wrappedCode).toMatch(/const proxy = userProvidedProxy \? wrappedHandler : (?:undefined|void 0)/); }); }); From 8dc63cf93e6ea393d3e8c93177fab399b9bd6ab2 Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 16:19:33 +0200 Subject: [PATCH 07/11] make comment-based replacement blocks with legal comment syntax --- dev-packages/rollup-utils/plugins/bundlePlugins.mjs | 9 +++++---- dev-packages/rollup-utils/plugins/npmPlugins.mjs | 12 +++++++----- packages/browser/src/sdk.ts | 4 ++-- packages/core/src/utils/env.ts | 6 ++++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/dev-packages/rollup-utils/plugins/bundlePlugins.mjs b/dev-packages/rollup-utils/plugins/bundlePlugins.mjs index f8e16cb4ec37..56712e33a458 100644 --- a/dev-packages/rollup-utils/plugins/bundlePlugins.mjs +++ b/dev-packages/rollup-utils/plugins/bundlePlugins.mjs @@ -63,18 +63,19 @@ export function makeIsDebugBuildPlugin(includeDebugging) { } /** - * Replaces the comment marker `/* __SENTRY_SDK_SOURCE__ *\/` in core's `getSDKSource()` with a + * Replaces the comment marker `/*! __SENTRY_SDK_SOURCE__ *\/` in core's `getSDKSource()` with a * `return '';` statement so the bundle reports the correct distribution channel. * - * Because the marker is a block comment, esbuild would strip it during transpile — so the plugin - * sort order in utils.mjs pins this name before `esbuild`. + * The marker uses the `/*! ... *\/` legal-comment syntax so it survives esbuild's transpile + * (esbuild strips ordinary block comments). The plugin sort order in utils.mjs also pins + * this name before `esbuild`, in case it ever runs on un-transpiled source directly. */ export function makeSetSDKSourcePlugin(sdkSource) { const plugin = replace({ preventAssignment: false, delimiters: ['', ''], values: { - '/* __SENTRY_SDK_SOURCE__ */': `return ${JSON.stringify(sdkSource)};`, + '/*! __SENTRY_SDK_SOURCE__ */': `return ${JSON.stringify(sdkSource)};`, }, }); plugin.name = 'replace-sdk-source'; diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index f48e2a8a1f15..22e24decdfaf 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -121,12 +121,14 @@ export function makeDebugBuildStatementReplacePlugin() { } export function makeProductionReplacePlugin() { - const pattern = /\/\* rollup-include-development-only \*\/[\s\S]*?\/\* rollup-include-development-only-end \*\/\s*/g; - - // Must run as a `transform` (per-module) hook rather than `renderChunk`: esbuild - // strips arbitrary block comments during transpile, so by the time `renderChunk` - // would fire, the `rollup-include-development-only` marker comments are gone. + // Markers use the `/*! ... */` legal-comment syntax so esbuild preserves them through + // transpile. We still run as a `transform` (per-module) hook rather than `renderChunk`: + // the block typically uses imports declared at the module top, and stripping it before + // rollup analyses module-graph imports lets those now-unused imports be tree-shaken away. // The plugin sort order in utils.mjs pins this before `esbuild`. + const pattern = + /\/\*! rollup-include-development-only \*\/[\s\S]*?\/\*! rollup-include-development-only-end \*\/\s*/g; + return { name: 'remove-dev-mode-blocks', transform(code) { diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index 68a48ec461d1..dc1be3382664 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -98,7 +98,7 @@ export function init(options: BrowserOptions = {}): Client | undefined { let defaultIntegrations = options.defaultIntegrations == null ? getDefaultIntegrations(options) : options.defaultIntegrations; - /* rollup-include-development-only */ + /*! rollup-include-development-only */ if (options.spotlight) { if (!defaultIntegrations) { defaultIntegrations = []; @@ -106,7 +106,7 @@ export function init(options: BrowserOptions = {}): Client | undefined { const args = typeof options.spotlight === 'string' ? { sidecarUrl: options.spotlight } : undefined; defaultIntegrations.push(spotlightBrowserIntegration(args)); } - /* rollup-include-development-only-end */ + /*! rollup-include-development-only-end */ const clientOptions: BrowserClientOptions = { ...options, diff --git a/packages/core/src/utils/env.ts b/packages/core/src/utils/env.ts index 86872017707a..14893b553e15 100644 --- a/packages/core/src/utils/env.ts +++ b/packages/core/src/utils/env.ts @@ -30,6 +30,8 @@ export function isBrowserBundle(): boolean { * Get source of SDK. */ export function getSDKSource(): SdkSource { - // This comment is used to identify this line in the CDN bundle build step and replace this with "return 'cdn';" - /* __SENTRY_SDK_SOURCE__ */ return 'npm'; + // The `/*! ... */` marker is replaced by our CDN bundle build step with `return 'cdn';`. + // It uses the `/*!` legal-comment syntax specifically so it survives esbuild's transpile + // (which strips ordinary `/* ... */` block comments). + /*! __SENTRY_SDK_SOURCE__ */ return 'npm'; } From 2e4f86c150f7ee27909796382756d17e22b34228 Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 16:26:11 +0200 Subject: [PATCH 08/11] add order for all replace stuff --- dev-packages/rollup-utils/utils.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dev-packages/rollup-utils/utils.mjs b/dev-packages/rollup-utils/utils.mjs index 37b19f30962f..04c454e5c2fd 100644 --- a/dev-packages/rollup-utils/utils.mjs +++ b/dev-packages/rollup-utils/utils.mjs @@ -52,6 +52,10 @@ export function mergePlugins(pluginsA, pluginsB) { const order = [ 'remove-dev-mode-blocks', 'replace-sdk-source', + 'replace-debug-build-statement', + 'replace-browser-bundle-flag', + 'replace-debug-flags', + 'replace-rrweb-build-flags', 'esbuild', '...', 'terser', From f3f8808cf5df3c51efa3ad3d70625bb6684c1b85 Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 16:31:11 +0200 Subject: [PATCH 09/11] fix lambda source --- dev-packages/rollup-utils/utils.mjs | 2 +- .../scripts/buildLambdaLayer.ts | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/dev-packages/rollup-utils/utils.mjs b/dev-packages/rollup-utils/utils.mjs index 04c454e5c2fd..c6285ab0bf45 100644 --- a/dev-packages/rollup-utils/utils.mjs +++ b/dev-packages/rollup-utils/utils.mjs @@ -38,7 +38,7 @@ export function mergeExternals(base, specific) { * * - `remove-dev-mode-blocks` (transform) — strips `/* rollup-include-development-only *\/` * marker blocks. Comment-dependent → must precede `esbuild`. - * - `replace-sdk-source` (transform) — rewrites the `/* __SENTRY_SDK_SOURCE__ *\/` + * - `replace-sdk-source` (transform) — rewrites the `/*! __SENTRY_SDK_SOURCE__ *\/` * marker in `getSDKSource()` for CDN builds. Comment-dependent → must precede `esbuild`. * - `esbuild` (transform) — TS/JSX → JS. Everything in `...` runs after this. * - `terser` (renderChunk) — minifies and strips comments (we use `comments: false`). diff --git a/packages/aws-serverless/scripts/buildLambdaLayer.ts b/packages/aws-serverless/scripts/buildLambdaLayer.ts index 520a456c63ce..9d590a96ae22 100644 --- a/packages/aws-serverless/scripts/buildLambdaLayer.ts +++ b/packages/aws-serverless/scripts/buildLambdaLayer.ts @@ -220,21 +220,27 @@ function replaceSDKSource(): void { './build/aws/dist-serverless/nodejs/node_modules/@sentry/core/build/esm/utils/env.js', ]; + // Tolerant of whitespace/quote variations: esbuild emits the marker and `return` on + // separate lines and uses double quotes, while the source uses a single line and single + // quotes. The marker itself uses `/*! */` legal-comment syntax so esbuild preserves it. + const pattern = /\/\*! __SENTRY_SDK_SOURCE__ \*\/\s*return ["']npm["'];/; + const replacement = `/*! __SENTRY_SDK_SOURCE__ */ return 'aws-lambda-layer';`; + for (const envFile of envFiles) { + let content: string; try { - let content = fs.readFileSync(envFile, 'utf-8'); + content = fs.readFileSync(envFile, 'utf-8'); + } catch { + throw new Error(`Could not read ${envFile} while updating the SDK source for the Lambda layer.`); + } - // Replace the line marked with __SENTRY_SDK_SOURCE__ comment - // Change from 'npm' to 'aws-lambda-layer' to identify that this is the AWS Lambda layer - content = content.replace( - "/* __SENTRY_SDK_SOURCE__ */ return 'npm';", - "/* __SENTRY_SDK_SOURCE__ */ return 'aws-lambda-layer';", + if (!pattern.test(content)) { + throw new Error( + `Could not find the __SENTRY_SDK_SOURCE__ marker in ${envFile}. The Lambda layer would silently report its SDK source as 'npm'. Has the marker or the transpile output changed?`, ); - - fs.writeFileSync(envFile, content); - console.log(`Updated SDK source in ${envFile}`); - } catch { - console.warn(`Warning: Could not update SDK source in ${envFile}`); } + + fs.writeFileSync(envFile, content.replace(pattern, replacement)); + console.log(`Updated SDK source in ${envFile}`); } } From c003f6450c6991ad0b04d3aa137a1dfa251293d0 Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 17:11:29 +0200 Subject: [PATCH 10/11] fix order and add comments --- dev-packages/rollup-utils/utils.mjs | 34 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/dev-packages/rollup-utils/utils.mjs b/dev-packages/rollup-utils/utils.mjs index c6285ab0bf45..503a4876d223 100644 --- a/dev-packages/rollup-utils/utils.mjs +++ b/dev-packages/rollup-utils/utils.mjs @@ -32,34 +32,36 @@ export function mergeExternals(base, specific) { /** * Merge two arrays of plugins, making sure they're sorted in the correct order. * - * Each entry below is pinned for a real reason; `...` is where every other plugin lands. - * Plugins that depend on **comments** in the source MUST run before `esbuild`, because - * esbuild strips non-legal block comments during transpile. - * - * - `remove-dev-mode-blocks` (transform) — strips `/* rollup-include-development-only *\/` - * marker blocks. Comment-dependent → must precede `esbuild`. - * - `replace-sdk-source` (transform) — rewrites the `/*! __SENTRY_SDK_SOURCE__ *\/` - * marker in `getSDKSource()` for CDN builds. Comment-dependent → must precede `esbuild`. - * - `esbuild` (transform) — TS/JSX → JS. Everything in `...` runs after this. - * - `terser` (renderChunk) — minifies and strips comments (we use `comments: false`). - * Anything that contributes code to a chunk must run before this. - * - `license` (renderChunk) — prepends the license banner, which is a comment. Must run - * AFTER `terser`, otherwise terser would strip it. - * - `output-base64-worker-script` (renderChunk) — captures the final chunk text as - * base64, so it must run last. + * Each entry in `order` is pinned for a real reason; `...` is where every other plugin lands. */ export function mergePlugins(pluginsA, pluginsB) { const order = [ + // (transform) Strips `/*! rollup-include-development-only */` marker blocks. Must precede `esbuild` so the + // now-unused imports inside the block can be tree-shaken by rollup. 'remove-dev-mode-blocks', + // (transform) Rewrites the `/*! __SENTRY_SDK_SOURCE__ */` comment marker in `getSDKSource()` for CDN builds. + // Comment-based → must precede `esbuild` (the marker uses `/*!` legal-comment syntax, but pinning is defensive). 'replace-sdk-source', + // (transform) TS/JSX → JS, strips non-legal block comments, strips `declare const` lines. + 'esbuild', + // The identifier-based `replace-*` plugins below MUST run AFTER `esbuild`. Each of these identifiers is also + // declared in TS via `declare const __FOO__: ...;` lines. If the replace runs before esbuild, it rewrites the + // declaration's identifier into an expression and produces invalid TS. esbuild strips `declare const` lines, + // so by the time these plugins run the only remaining occurrences are real references. 'replace-debug-build-statement', 'replace-browser-bundle-flag', 'replace-debug-flags', 'replace-rrweb-build-flags', - 'esbuild', + // Every other plugin lands here — including additional identifier-based `replace-*` plugins (e.g. + // `replace-sdk-version`), which intentionally run AFTER `esbuild` for the same reason as the ones pinned above. '...', + // (renderChunk) Minifies and strips comments (we use `comments: false`). Anything that contributes code to a + // chunk must run before this. 'terser', + // (renderChunk) Prepends the license banner, which is a comment. Must run AFTER `terser`, otherwise terser + // would strip it. 'license', + // (renderChunk) Captures the final chunk text as base64, so it must run last. 'output-base64-worker-script', ]; const plugins = [...pluginsA, ...pluginsB]; From db29e47b7a7dc042640b7e1d979a83ef1b13ab7d Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 13 May 2026 17:22:17 +0200 Subject: [PATCH 11/11] move remaining stuff to esbuild and drop unused dependencies --- package.json | 3 - packages/replay-worker/examples/worker.js | 1328 ++++++++--------- packages/replay-worker/examples/worker.min.js | 4 +- .../replay-worker/rollup.examples.config.mjs | 13 +- .../replay-worker/rollup.worker.config.mjs | 10 +- yarn.lock | 15 - 6 files changed, 663 insertions(+), 710 deletions(-) diff --git a/package.json b/package.json index 07aa2877bc8a..947d56a8dd37 100644 --- a/package.json +++ b/package.json @@ -113,13 +113,10 @@ ], "devDependencies": { "@rollup/plugin-commonjs": "^25.0.7", - "@rollup/plugin-esm-shim": "^0.1.5", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", - "@rollup/plugin-typescript": "^11.1.6", - "@rollup/pluginutils": "^5.1.0", "@size-limit/esbuild": "~12.1.0", "@size-limit/file": "~12.1.0", "@size-limit/webpack": "~12.1.0", diff --git a/packages/replay-worker/examples/worker.js b/packages/replay-worker/examples/worker.js index 307084794e96..d825d39fa1e5 100644 --- a/packages/replay-worker/examples/worker.js +++ b/packages/replay-worker/examples/worker.js @@ -1,4 +1,4 @@ -/*! Sentry Replay Worker 8.33.1 (c992b3fad) | https://github.com/getsentry/sentry-javascript */ +/*! Sentry Replay Worker 10.53.1 (c003f6450c) | https://github.com/getsentry/sentry-javascript */ // DEFLATE is a complex format; to read this code, you should probably check the RFC first: // https://tools.ietf.org/html/rfc1951 // You may also wish to take a look at the guide I made about this program: @@ -10,379 +10,371 @@ // is better for memory in most engines (I *think*). // aliases for shorter compressed code (most minifers don't do this) -var u8 = Uint8Array, - u16 = Uint16Array, - i32 = Int32Array; +var u8 = Uint8Array, u16 = Uint16Array, i32 = Int32Array; // fixed length extra bits -var fleb = new u8([ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, - /* impossible */ 0, -]); +var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]); // fixed distance extra bits -var fdeb = new u8([ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0, -]); +var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]); // code length index map var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]); // get base, reverse index map from extra bits var freb = function (eb, start) { - var b = new u16(31); - for (var i = 0; i < 31; ++i) { - b[i] = start += 1 << eb[i - 1]; - } - // numbers here are at max 18 bits - var r = new i32(b[30]); - for (var i = 1; i < 30; ++i) { - for (var j = b[i]; j < b[i + 1]; ++j) { - r[j] = ((j - b[i]) << 5) | i; + var b = new u16(31); + for (var i = 0; i < 31; ++i) { + b[i] = start += 1 << eb[i - 1]; } - } - return { b: b, r: r }; + // numbers here are at max 18 bits + var r = new i32(b[30]); + for (var i = 1; i < 30; ++i) { + for (var j = b[i]; j < b[i + 1]; ++j) { + r[j] = ((j - b[i]) << 5) | i; + } + } + return { b: b, r: r }; }; -var _a = freb(fleb, 2), - fl = _a.b, - revfl = _a.r; +var _a = freb(fleb, 2), fl = _a.b, revfl = _a.r; // we can ignore the fact that the other numbers are wrong; they never happen anyway -((fl[28] = 258), (revfl[258] = 28)); -var _b = freb(fdeb, 0), - revfd = _b.r; +fl[28] = 258, revfl[258] = 28; +var _b = freb(fdeb, 0), revfd = _b.r; // map of value to reverse (assuming 16 bits) var rev = new u16(32768); for (var i = 0; i < 32768; ++i) { - // reverse table algorithm from SO - var x = ((i & 0xaaaa) >> 1) | ((i & 0x5555) << 1); - x = ((x & 0xcccc) >> 2) | ((x & 0x3333) << 2); - x = ((x & 0xf0f0) >> 4) | ((x & 0x0f0f) << 4); - rev[i] = (((x & 0xff00) >> 8) | ((x & 0x00ff) << 8)) >> 1; + // reverse table algorithm from SO + var x = ((i & 0xAAAA) >> 1) | ((i & 0x5555) << 1); + x = ((x & 0xCCCC) >> 2) | ((x & 0x3333) << 2); + x = ((x & 0xF0F0) >> 4) | ((x & 0x0F0F) << 4); + rev[i] = (((x & 0xFF00) >> 8) | ((x & 0x00FF) << 8)) >> 1; } // create huffman tree from u8 "map": index -> code length for code index // mb (max bits) must be at most 15 // TODO: optimize/split up? -var hMap = function (cd, mb, r) { - var s = cd.length; - // index - var i = 0; - // u16 "map": index -> # of codes with bit length = index - var l = new u16(mb); - // length of cd must be 288 (total # of codes) - for (; i < s; ++i) { - if (cd[i]) ++l[cd[i] - 1]; - } - // u16 "map": index -> minimum code for bit length = index - var le = new u16(mb); - for (i = 1; i < mb; ++i) { - le[i] = (le[i - 1] + l[i - 1]) << 1; - } - var co; - if (r) { - // u16 "map": index -> number of actual bits, symbol for code - co = new u16(1 << mb); - // bits to remove for reverser - var rvb = 15 - mb; - for (i = 0; i < s; ++i) { - // ignore 0 lengths - if (cd[i]) { - // num encoding both symbol and bits read - var sv = (i << 4) | cd[i]; - // free bits - var r_1 = mb - cd[i]; - // start value - var v = le[cd[i] - 1]++ << r_1; - // m is end value - for (var m = v | ((1 << r_1) - 1); v <= m; ++v) { - // every 16 bit value starting with the code yields the same result - co[rev[v] >> rvb] = sv; +var hMap = (function (cd, mb, r) { + var s = cd.length; + // index + var i = 0; + // u16 "map": index -> # of codes with bit length = index + var l = new u16(mb); + // length of cd must be 288 (total # of codes) + for (; i < s; ++i) { + if (cd[i]) + ++l[cd[i] - 1]; + } + // u16 "map": index -> minimum code for bit length = index + var le = new u16(mb); + for (i = 1; i < mb; ++i) { + le[i] = (le[i - 1] + l[i - 1]) << 1; + } + var co; + if (r) { + // u16 "map": index -> number of actual bits, symbol for code + co = new u16(1 << mb); + // bits to remove for reverser + var rvb = 15 - mb; + for (i = 0; i < s; ++i) { + // ignore 0 lengths + if (cd[i]) { + // num encoding both symbol and bits read + var sv = (i << 4) | cd[i]; + // free bits + var r_1 = mb - cd[i]; + // start value + var v = le[cd[i] - 1]++ << r_1; + // m is end value + for (var m = v | ((1 << r_1) - 1); v <= m; ++v) { + // every 16 bit value starting with the code yields the same result + co[rev[v] >> rvb] = sv; + } + } } - } } - } else { - co = new u16(s); - for (i = 0; i < s; ++i) { - if (cd[i]) { - co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]); - } + else { + co = new u16(s); + for (i = 0; i < s; ++i) { + if (cd[i]) { + co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]); + } + } } - } - return co; -}; + return co; +}); // fixed length tree var flt = new u8(288); -for (var i = 0; i < 144; ++i) flt[i] = 8; -for (var i = 144; i < 256; ++i) flt[i] = 9; -for (var i = 256; i < 280; ++i) flt[i] = 7; -for (var i = 280; i < 288; ++i) flt[i] = 8; +for (var i = 0; i < 144; ++i) + flt[i] = 8; +for (var i = 144; i < 256; ++i) + flt[i] = 9; +for (var i = 256; i < 280; ++i) + flt[i] = 7; +for (var i = 280; i < 288; ++i) + flt[i] = 8; // fixed distance tree var fdt = new u8(32); -for (var i = 0; i < 32; ++i) fdt[i] = 5; +for (var i = 0; i < 32; ++i) + fdt[i] = 5; // fixed length map var flm = /*#__PURE__*/ hMap(flt, 9, 0); // fixed distance map var fdm = /*#__PURE__*/ hMap(fdt, 5, 0); // get end of byte -var shft = function (p) { - return ((p + 7) / 8) | 0; -}; +var shft = function (p) { return ((p + 7) / 8) | 0; }; // typed array slice - allows garbage collector to free original reference, // while being more compatible than .slice var slc = function (v, s, e) { - if (s == null || s < 0) s = 0; - if (e == null || e > v.length) e = v.length; - // can't use .constructor in case user-supplied - return new u8(v.subarray(s, e)); + if (e == null || e > v.length) + e = v.length; + // can't use .constructor in case user-supplied + return new u8(v.subarray(s, e)); }; // error codes var ec = [ - 'unexpected EOF', - 'invalid block type', - 'invalid length/literal', - 'invalid distance', - 'stream finished', - 'no stream handler', - , - 'no callback', - 'invalid UTF-8 data', - 'extra field too long', - 'date not in range 1980-2099', - 'filename too long', - 'stream finishing', - 'invalid zip data', - // determined by unknown compression method + 'unexpected EOF', + 'invalid block type', + 'invalid length/literal', + 'invalid distance', + 'stream finished', + 'no stream handler', + , + 'no callback', + 'invalid UTF-8 data', + 'extra field too long', + 'date not in range 1980-2099', + 'filename too long', + 'stream finishing', + 'invalid zip data' + // determined by unknown compression method ]; var err = function (ind, msg, nt) { - var e = new Error(msg || ec[ind]); - e.code = ind; - if (Error.captureStackTrace) Error.captureStackTrace(e, err); - if (!nt) throw e; - return e; + var e = new Error(msg || ec[ind]); + e.code = ind; + if (Error.captureStackTrace) + Error.captureStackTrace(e, err); + if (!nt) + throw e; + return e; }; // starting at p, write the minimum number of bits that can hold v to d var wbits = function (d, p, v) { - v <<= p & 7; - var o = (p / 8) | 0; - d[o] |= v; - d[o + 1] |= v >> 8; + v <<= p & 7; + var o = (p / 8) | 0; + d[o] |= v; + d[o + 1] |= v >> 8; }; // starting at p, write the minimum number of bits (>8) that can hold v to d var wbits16 = function (d, p, v) { - v <<= p & 7; - var o = (p / 8) | 0; - d[o] |= v; - d[o + 1] |= v >> 8; - d[o + 2] |= v >> 16; + v <<= p & 7; + var o = (p / 8) | 0; + d[o] |= v; + d[o + 1] |= v >> 8; + d[o + 2] |= v >> 16; }; // creates code lengths from a frequency table var hTree = function (d, mb) { - // Need extra info to make a tree - var t = []; - for (var i = 0; i < d.length; ++i) { - if (d[i]) t.push({ s: i, f: d[i] }); - } - var s = t.length; - var t2 = t.slice(); - if (!s) return { t: et, l: 0 }; - if (s == 1) { - var v = new u8(t[0].s + 1); - v[t[0].s] = 1; - return { t: v, l: 1 }; - } - t.sort(function (a, b) { - return a.f - b.f; - }); - // after i2 reaches last ind, will be stopped - // freq must be greater than largest possible number of symbols - t.push({ s: -1, f: 25001 }); - var l = t[0], - r = t[1], - i0 = 0, - i1 = 1, - i2 = 2; - t[0] = { s: -1, f: l.f + r.f, l: l, r: r }; - // efficient algorithm from UZIP.js - // i0 is lookbehind, i2 is lookahead - after processing two low-freq - // symbols that combined have high freq, will start processing i2 (high-freq, - // non-composite) symbols instead - // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/ - while (i1 != s - 1) { - l = t[t[i0].f < t[i2].f ? i0++ : i2++]; - r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++]; - t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r }; - } - var maxSym = t2[0].s; - for (var i = 1; i < s; ++i) { - if (t2[i].s > maxSym) maxSym = t2[i].s; - } - // code lengths - var tr = new u16(maxSym + 1); - // max bits in tree - var mbt = ln(t[i1 - 1], tr, 0); - if (mbt > mb) { - // more algorithms from UZIP.js - // TODO: find out how this code works (debt) - // ind debt - var i = 0, - dt = 0; - // left cost - var lft = mbt - mb, - cst = 1 << lft; - t2.sort(function (a, b) { - return tr[b.s] - tr[a.s] || a.f - b.f; - }); - for (; i < s; ++i) { - var i2_1 = t2[i].s; - if (tr[i2_1] > mb) { - dt += cst - (1 << (mbt - tr[i2_1])); - tr[i2_1] = mb; - } else break; + // Need extra info to make a tree + var t = []; + for (var i = 0; i < d.length; ++i) { + if (d[i]) + t.push({ s: i, f: d[i] }); } - dt >>= lft; - while (dt > 0) { - var i2_2 = t2[i].s; - if (tr[i2_2] < mb) dt -= 1 << (mb - tr[i2_2]++ - 1); - else ++i; + var s = t.length; + var t2 = t.slice(); + if (!s) + return { t: et, l: 0 }; + if (s == 1) { + var v = new u8(t[0].s + 1); + v[t[0].s] = 1; + return { t: v, l: 1 }; } - for (; i >= 0 && dt; --i) { - var i2_3 = t2[i].s; - if (tr[i2_3] == mb) { - --tr[i2_3]; - ++dt; - } + t.sort(function (a, b) { return a.f - b.f; }); + // after i2 reaches last ind, will be stopped + // freq must be greater than largest possible number of symbols + t.push({ s: -1, f: 25001 }); + var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2; + t[0] = { s: -1, f: l.f + r.f, l: l, r: r }; + // efficient algorithm from UZIP.js + // i0 is lookbehind, i2 is lookahead - after processing two low-freq + // symbols that combined have high freq, will start processing i2 (high-freq, + // non-composite) symbols instead + // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/ + while (i1 != s - 1) { + l = t[t[i0].f < t[i2].f ? i0++ : i2++]; + r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++]; + t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r }; } - mbt = mb; - } - return { t: new u8(tr), l: mbt }; + var maxSym = t2[0].s; + for (var i = 1; i < s; ++i) { + if (t2[i].s > maxSym) + maxSym = t2[i].s; + } + // code lengths + var tr = new u16(maxSym + 1); + // max bits in tree + var mbt = ln(t[i1 - 1], tr, 0); + if (mbt > mb) { + // more algorithms from UZIP.js + // TODO: find out how this code works (debt) + // ind debt + var i = 0, dt = 0; + // left cost + var lft = mbt - mb, cst = 1 << lft; + t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; }); + for (; i < s; ++i) { + var i2_1 = t2[i].s; + if (tr[i2_1] > mb) { + dt += cst - (1 << (mbt - tr[i2_1])); + tr[i2_1] = mb; + } + else + break; + } + dt >>= lft; + while (dt > 0) { + var i2_2 = t2[i].s; + if (tr[i2_2] < mb) + dt -= 1 << (mb - tr[i2_2]++ - 1); + else + ++i; + } + for (; i >= 0 && dt; --i) { + var i2_3 = t2[i].s; + if (tr[i2_3] == mb) { + --tr[i2_3]; + ++dt; + } + } + mbt = mb; + } + return { t: new u8(tr), l: mbt }; }; // get the max length and assign length codes var ln = function (n, l, d) { - return n.s == -1 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) : (l[n.s] = d); + return n.s == -1 + ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) + : (l[n.s] = d); }; // length codes generation var lc = function (c) { - var s = c.length; - // Note that the semicolon was intentional - while (s && !c[--s]); - var cl = new u16(++s); - // ind num streak - var cli = 0, - cln = c[0], - cls = 1; - var w = function (v) { - cl[cli++] = v; - }; - for (var i = 1; i <= s; ++i) { - if (c[i] == cln && i != s) ++cls; - else { - if (!cln && cls > 2) { - for (; cls > 138; cls -= 138) w(32754); - if (cls > 2) { - w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305); - cls = 0; + var s = c.length; + // Note that the semicolon was intentional + while (s && !c[--s]) + ; + var cl = new u16(++s); + // ind num streak + var cli = 0, cln = c[0], cls = 1; + var w = function (v) { cl[cli++] = v; }; + for (var i = 1; i <= s; ++i) { + if (c[i] == cln && i != s) + ++cls; + else { + if (!cln && cls > 2) { + for (; cls > 138; cls -= 138) + w(32754); + if (cls > 2) { + w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305); + cls = 0; + } + } + else if (cls > 3) { + w(cln), --cls; + for (; cls > 6; cls -= 6) + w(8304); + if (cls > 2) + w(((cls - 3) << 5) | 8208), cls = 0; + } + while (cls--) + w(cln); + cls = 1; + cln = c[i]; } - } else if (cls > 3) { - (w(cln), --cls); - for (; cls > 6; cls -= 6) w(8304); - if (cls > 2) (w(((cls - 3) << 5) | 8208), (cls = 0)); - } - while (cls--) w(cln); - cls = 1; - cln = c[i]; } - } - return { c: cl.subarray(0, cli), n: s }; + return { c: cl.subarray(0, cli), n: s }; }; // calculate the length of output from tree, code lengths var clen = function (cf, cl) { - var l = 0; - for (var i = 0; i < cl.length; ++i) l += cf[i] * cl[i]; - return l; + var l = 0; + for (var i = 0; i < cl.length; ++i) + l += cf[i] * cl[i]; + return l; }; // writes a fixed block // returns the new bit pos var wfblk = function (out, pos, dat) { - // no need to write 00 as type: TypedArray defaults to 0 - var s = dat.length; - var o = shft(pos + 2); - out[o] = s & 255; - out[o + 1] = s >> 8; - out[o + 2] = out[o] ^ 255; - out[o + 3] = out[o + 1] ^ 255; - for (var i = 0; i < s; ++i) out[o + i + 4] = dat[i]; - return (o + 4 + s) * 8; + // no need to write 00 as type: TypedArray defaults to 0 + var s = dat.length; + var o = shft(pos + 2); + out[o] = s & 255; + out[o + 1] = s >> 8; + out[o + 2] = out[o] ^ 255; + out[o + 3] = out[o + 1] ^ 255; + for (var i = 0; i < s; ++i) + out[o + i + 4] = dat[i]; + return (o + 4 + s) * 8; }; // writes a block var wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) { - wbits(out, p++, final); - ++lf[256]; - var _a = hTree(lf, 15), - dlt = _a.t, - mlb = _a.l; - var _b = hTree(df, 15), - ddt = _b.t, - mdb = _b.l; - var _c = lc(dlt), - lclt = _c.c, - nlc = _c.n; - var _d = lc(ddt), - lcdt = _d.c, - ndc = _d.n; - var lcfreq = new u16(19); - for (var i = 0; i < lclt.length; ++i) ++lcfreq[lclt[i] & 31]; - for (var i = 0; i < lcdt.length; ++i) ++lcfreq[lcdt[i] & 31]; - var _e = hTree(lcfreq, 7), - lct = _e.t, - mlcb = _e.l; - var nlcc = 19; - for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc); - var flen = (bl + 5) << 3; - var ftlen = clen(lf, flt) + clen(df, fdt) + eb; - var dtlen = - clen(lf, dlt) + - clen(df, ddt) + - eb + - 14 + - 3 * nlcc + - clen(lcfreq, lct) + - 2 * lcfreq[16] + - 3 * lcfreq[17] + - 7 * lcfreq[18]; - if (bs >= 0 && flen <= ftlen && flen <= dtlen) return wfblk(out, p, dat.subarray(bs, bs + bl)); - var lm, ll, dm, dl; - (wbits(out, p, 1 + (dtlen < ftlen)), (p += 2)); - if (dtlen < ftlen) { - ((lm = hMap(dlt, mlb, 0)), (ll = dlt), (dm = hMap(ddt, mdb, 0)), (dl = ddt)); - var llm = hMap(lct, mlcb, 0); - wbits(out, p, nlc - 257); - wbits(out, p + 5, ndc - 1); - wbits(out, p + 10, nlcc - 4); - p += 14; - for (var i = 0; i < nlcc; ++i) wbits(out, p + 3 * i, lct[clim[i]]); - p += 3 * nlcc; - var lcts = [lclt, lcdt]; - for (var it = 0; it < 2; ++it) { - var clct = lcts[it]; - for (var i = 0; i < clct.length; ++i) { - var len = clct[i] & 31; - (wbits(out, p, llm[len]), (p += lct[len])); - if (len > 15) (wbits(out, p, (clct[i] >> 5) & 127), (p += clct[i] >> 12)); - } + wbits(out, p++, final); + ++lf[256]; + var _a = hTree(lf, 15), dlt = _a.t, mlb = _a.l; + var _b = hTree(df, 15), ddt = _b.t, mdb = _b.l; + var _c = lc(dlt), lclt = _c.c, nlc = _c.n; + var _d = lc(ddt), lcdt = _d.c, ndc = _d.n; + var lcfreq = new u16(19); + for (var i = 0; i < lclt.length; ++i) + ++lcfreq[lclt[i] & 31]; + for (var i = 0; i < lcdt.length; ++i) + ++lcfreq[lcdt[i] & 31]; + var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l; + var nlcc = 19; + for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc) + ; + var flen = (bl + 5) << 3; + var ftlen = clen(lf, flt) + clen(df, fdt) + eb; + var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18]; + if (bs >= 0 && flen <= ftlen && flen <= dtlen) + return wfblk(out, p, dat.subarray(bs, bs + bl)); + var lm, ll, dm, dl; + wbits(out, p, 1 + (dtlen < ftlen)), p += 2; + if (dtlen < ftlen) { + lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt; + var llm = hMap(lct, mlcb, 0); + wbits(out, p, nlc - 257); + wbits(out, p + 5, ndc - 1); + wbits(out, p + 10, nlcc - 4); + p += 14; + for (var i = 0; i < nlcc; ++i) + wbits(out, p + 3 * i, lct[clim[i]]); + p += 3 * nlcc; + var lcts = [lclt, lcdt]; + for (var it = 0; it < 2; ++it) { + var clct = lcts[it]; + for (var i = 0; i < clct.length; ++i) { + var len = clct[i] & 31; + wbits(out, p, llm[len]), p += lct[len]; + if (len > 15) + wbits(out, p, (clct[i] >> 5) & 127), p += clct[i] >> 12; + } + } } - } else { - ((lm = flm), (ll = flt), (dm = fdm), (dl = fdt)); - } - for (var i = 0; i < li; ++i) { - var sym = syms[i]; - if (sym > 255) { - var len = (sym >> 18) & 31; - (wbits16(out, p, lm[len + 257]), (p += ll[len + 257])); - if (len > 7) (wbits(out, p, (sym >> 23) & 31), (p += fleb[len])); - var dst = sym & 31; - (wbits16(out, p, dm[dst]), (p += dl[dst])); - if (dst > 3) (wbits16(out, p, (sym >> 5) & 8191), (p += fdeb[dst])); - } else { - (wbits16(out, p, lm[sym]), (p += ll[sym])); + else { + lm = flm, ll = flt, dm = fdm, dl = fdt; } - } - wbits16(out, p, lm[256]); - return p + ll[256]; + for (var i = 0; i < li; ++i) { + var sym = syms[i]; + if (sym > 255) { + var len = (sym >> 18) & 31; + wbits16(out, p, lm[len + 257]), p += ll[len + 257]; + if (len > 7) + wbits(out, p, (sym >> 23) & 31), p += fleb[len]; + var dst = sym & 31; + wbits16(out, p, dm[dst]), p += dl[dst]; + if (dst > 3) + wbits16(out, p, (sym >> 5) & 8191), p += fdeb[dst]; + } + else { + wbits16(out, p, lm[sym]), p += ll[sym]; + } + } + wbits16(out, p, lm[256]); + return p + ll[256]; }; // deflate options (nice << 13) | chain var deo = /*#__PURE__*/ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]); @@ -390,298 +382,295 @@ var deo = /*#__PURE__*/ new i32([65540, 131080, 131088, 131104, 262176, 1048704, var et = /*#__PURE__*/ new u8(0); // compresses data into a raw DEFLATE buffer var dflt = function (dat, lvl, plvl, pre, post, st) { - var s = st.z || dat.length; - var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post); - // writing to this writes to the output buffer - var w = o.subarray(pre, o.length - post); - var lst = st.l; - var pos = (st.r || 0) & 7; - if (lvl) { - if (pos) w[0] = st.r >> 3; - var opt = deo[lvl - 1]; - var n = opt >> 13, - c = opt & 8191; - var msk_1 = (1 << plvl) - 1; - // prev 2-byte val map curr 2-byte val map - var prev = st.p || new u16(32768), - head = st.h || new u16(msk_1 + 1); - var bs1_1 = Math.ceil(plvl / 3), - bs2_1 = 2 * bs1_1; - var hsh = function (i) { - return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; - }; - // 24576 is an arbitrary number of maximum symbols per block - // 424 buffer for last block - var syms = new i32(25000); - // length/literal freq distance freq - var lf = new u16(288), - df = new u16(32); - // l/lcnt exbits index l/lind waitdx blkpos - var lc_1 = 0, - eb = 0, - i = st.i || 0, - li = 0, - wi = st.w || 0, - bs = 0; - for (; i + 2 < s; ++i) { - // hash value - var hv = hsh(i); - // index mod 32768 previous index mod - var imod = i & 32767, - pimod = head[hv]; - prev[imod] = pimod; - head[hv] = imod; - // We always should modify head and prev, but only add symbols if - // this data is not yet processed ("wait" for wait index) - if (wi <= i) { - // bytes remaining - var rem = s - i; - if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) { - pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos); - ((li = lc_1 = eb = 0), (bs = i)); - for (var j = 0; j < 286; ++j) lf[j] = 0; - for (var j = 0; j < 30; ++j) df[j] = 0; - } - // len dist chain - var l = 2, - d = 0, - ch_1 = c, - dif = (imod - pimod) & 32767; - if (rem > 2 && hv == hsh(i - dif)) { - var maxn = Math.min(n, rem) - 1; - var maxd = Math.min(32767, i); - // max possible length - // not capped at dif because decompressors implement "rolling" index population - var ml = Math.min(258, rem); - while (dif <= maxd && --ch_1 && imod != pimod) { - if (dat[i + l] == dat[i + l - dif]) { - var nl = 0; - for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl); - if (nl > l) { - ((l = nl), (d = dif)); - // break out early when we reach "nice" (we are satisfied enough) - if (nl > maxn) break; - // now, find the rarest 2-byte sequence within this - // length of literals and search for that instead. - // Much faster than just using the start - var mmd = Math.min(dif, nl - 2); - var md = 0; - for (var j = 0; j < mmd; ++j) { - var ti = (i - dif + j) & 32767; - var pti = prev[ti]; - var cd = (ti - pti) & 32767; - if (cd > md) ((md = cd), (pimod = ti)); + var s = st.z || dat.length; + var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post); + // writing to this writes to the output buffer + var w = o.subarray(pre, o.length - post); + var lst = st.l; + var pos = (st.r || 0) & 7; + if (lvl) { + if (pos) + w[0] = st.r >> 3; + var opt = deo[lvl - 1]; + var n = opt >> 13, c = opt & 8191; + var msk_1 = (1 << plvl) - 1; + // prev 2-byte val map curr 2-byte val map + var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1); + var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1; + var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; }; + // 24576 is an arbitrary number of maximum symbols per block + // 424 buffer for last block + var syms = new i32(25000); + // length/literal freq distance freq + var lf = new u16(288), df = new u16(32); + // l/lcnt exbits index l/lind waitdx blkpos + var lc_1 = 0, eb = 0, i = st.i || 0, li = 0, wi = st.w || 0, bs = 0; + for (; i + 2 < s; ++i) { + // hash value + var hv = hsh(i); + // index mod 32768 previous index mod + var imod = i & 32767, pimod = head[hv]; + prev[imod] = pimod; + head[hv] = imod; + // We always should modify head and prev, but only add symbols if + // this data is not yet processed ("wait" for wait index) + if (wi <= i) { + // bytes remaining + var rem = s - i; + if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) { + pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos); + li = lc_1 = eb = 0, bs = i; + for (var j = 0; j < 286; ++j) + lf[j] = 0; + for (var j = 0; j < 30; ++j) + df[j] = 0; + } + // len dist chain + var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767; + if (rem > 2 && hv == hsh(i - dif)) { + var maxn = Math.min(n, rem) - 1; + var maxd = Math.min(32767, i); + // max possible length + // not capped at dif because decompressors implement "rolling" index population + var ml = Math.min(258, rem); + while (dif <= maxd && --ch_1 && imod != pimod) { + if (dat[i + l] == dat[i + l - dif]) { + var nl = 0; + for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl) + ; + if (nl > l) { + l = nl, d = dif; + // break out early when we reach "nice" (we are satisfied enough) + if (nl > maxn) + break; + // now, find the rarest 2-byte sequence within this + // length of literals and search for that instead. + // Much faster than just using the start + var mmd = Math.min(dif, nl - 2); + var md = 0; + for (var j = 0; j < mmd; ++j) { + var ti = i - dif + j & 32767; + var pti = prev[ti]; + var cd = ti - pti & 32767; + if (cd > md) + md = cd, pimod = ti; + } + } + } + // check the previous match + imod = pimod, pimod = prev[imod]; + dif += imod - pimod & 32767; + } + } + // d will be nonzero only when a match was found + if (d) { + // store both dist and len data in one int32 + // Make sure this is recognized as a len/dist with 28th bit (2^28) + syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d]; + var lin = revfl[l] & 31, din = revfd[d] & 31; + eb += fleb[lin] + fdeb[din]; + ++lf[257 + lin]; + ++df[din]; + wi = i + l; + ++lc_1; + } + else { + syms[li++] = dat[i]; + ++lf[dat[i]]; } - } } - // check the previous match - ((imod = pimod), (pimod = prev[imod])); - dif += (imod - pimod) & 32767; - } } - // d will be nonzero only when a match was found - if (d) { - // store both dist and len data in one int32 - // Make sure this is recognized as a len/dist with 28th bit (2^28) - syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d]; - var lin = revfl[l] & 31, - din = revfd[d] & 31; - eb += fleb[lin] + fdeb[din]; - ++lf[257 + lin]; - ++df[din]; - wi = i + l; - ++lc_1; - } else { - syms[li++] = dat[i]; - ++lf[dat[i]]; + for (i = Math.max(i, wi); i < s; ++i) { + syms[li++] = dat[i]; + ++lf[dat[i]]; + } + pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos); + if (!lst) { + st.r = (pos & 7) | w[(pos / 8) | 0] << 3; + // shft(pos) now 1 less if pos & 7 != 0 + pos -= 7; + st.h = head, st.p = prev, st.i = i, st.w = wi; } - } - } - for (i = Math.max(i, wi); i < s; ++i) { - syms[li++] = dat[i]; - ++lf[dat[i]]; - } - pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos); - if (!lst) { - st.r = (pos & 7) | (w[(pos / 8) | 0] << 3); - // shft(pos) now 1 less if pos & 7 != 0 - pos -= 7; - ((st.h = head), (st.p = prev), (st.i = i), (st.w = wi)); } - } else { - for (var i = st.w || 0; i < s + lst; i += 65535) { - // end - var e = i + 65535; - if (e >= s) { - // write final block - w[(pos / 8) | 0] = lst; - e = s; - } - pos = wfblk(w, pos + 1, dat.subarray(i, e)); + else { + for (var i = st.w || 0; i < s + lst; i += 65535) { + // end + var e = i + 65535; + if (e >= s) { + // write final block + w[(pos / 8) | 0] = lst; + e = s; + } + pos = wfblk(w, pos + 1, dat.subarray(i, e)); + } + st.i = s; } - st.i = s; - } - return slc(o, 0, pre + shft(pos) + post); + return slc(o, 0, pre + shft(pos) + post); }; // CRC32 table var crct = /*#__PURE__*/ (function () { - var t = new Int32Array(256); - for (var i = 0; i < 256; ++i) { - var c = i, - k = 9; - while (--k) c = (c & 1 && -306674912) ^ (c >>> 1); - t[i] = c; - } - return t; + var t = new Int32Array(256); + for (var i = 0; i < 256; ++i) { + var c = i, k = 9; + while (--k) + c = ((c & 1) && -306674912) ^ (c >>> 1); + t[i] = c; + } + return t; })(); // CRC32 var crc = function () { - var c = -1; - return { - p: function (d) { - // closures have awful performance - var cr = c; - for (var i = 0; i < d.length; ++i) cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8); - c = cr; - }, - d: function () { - return ~c; - }, - }; + var c = -1; + return { + p: function (d) { + // closures have awful performance + var cr = c; + for (var i = 0; i < d.length; ++i) + cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8); + c = cr; + }, + d: function () { return ~c; } + }; }; // Adler32 var adler = function () { - var a = 1, - b = 0; - return { - p: function (d) { - // closures have awful performance - var n = a, - m = b; - var l = d.length | 0; - for (var i = 0; i != l; ) { - var e = Math.min(i + 2655, l); - for (; i < e; ++i) m += n += d[i]; - ((n = (n & 65535) + 15 * (n >> 16)), (m = (m & 65535) + 15 * (m >> 16))); - } - ((a = n), (b = m)); - }, - d: function () { - ((a %= 65521), (b %= 65521)); - return ((a & 255) << 24) | ((a & 0xff00) << 8) | ((b & 255) << 8) | (b >> 8); - }, - }; + var a = 1, b = 0; + return { + p: function (d) { + // closures have awful performance + var n = a, m = b; + var l = d.length | 0; + for (var i = 0; i != l;) { + var e = Math.min(i + 2655, l); + for (; i < e; ++i) + m += n += d[i]; + n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16); + } + a = n, b = m; + }, + d: function () { + a %= 65521, b %= 65521; + return (a & 255) << 24 | (a & 0xFF00) << 8 | (b & 255) << 8 | (b >> 8); + } + }; }; // deflate with opts var dopt = function (dat, opt, pre, post, st) { - if (!st) { - st = { l: 1 }; - if (opt.dictionary) { - var dict = opt.dictionary.subarray(-32768); - var newDat = new u8(dict.length + dat.length); - newDat.set(dict); - newDat.set(dat, dict.length); - dat = newDat; - st.w = dict.length; + if (!st) { + st = { l: 1 }; + if (opt.dictionary) { + var dict = opt.dictionary.subarray(-32768); + var newDat = new u8(dict.length + dat.length); + newDat.set(dict); + newDat.set(dat, dict.length); + dat = newDat; + st.w = dict.length; + } } - } - return dflt( - dat, - opt.level == null ? 6 : opt.level, - opt.mem == null ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 12 + opt.mem, - pre, - post, - st, - ); + return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? (st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20) : (12 + opt.mem), pre, post, st); }; // write bytes var wbytes = function (d, b, v) { - for (; v; ++b) ((d[b] = v), (v >>>= 8)); + for (; v; ++b) + d[b] = v, v >>>= 8; }; // gzip header var gzh = function (c, o) { - var fn = o.filename; - ((c[0] = 31), (c[1] = 139), (c[2] = 8), (c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0), (c[9] = 3)); // assume Unix - if (o.mtime != 0) wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1000)); - if (fn) { - c[3] = 8; - for (var i = 0; i <= fn.length; ++i) c[i + 10] = fn.charCodeAt(i); - } + var fn = o.filename; + c[0] = 31, c[1] = 139, c[2] = 8, c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0, c[9] = 3; // assume Unix + if (o.mtime != 0) + wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1000)); + if (fn) { + c[3] = 8; + for (var i = 0; i <= fn.length; ++i) + c[i + 10] = fn.charCodeAt(i); + } }; // gzip header length -var gzhl = function (o) { - return 10 + (o.filename ? o.filename.length + 1 : 0); -}; +var gzhl = function (o) { return 10 + (o.filename ? o.filename.length + 1 : 0); }; // zlib header var zlh = function (c, o) { - var lv = o.level, - fl = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2; - ((c[0] = 120), (c[1] = (fl << 6) | (o.dictionary && 32))); - c[1] |= 31 - (((c[0] << 8) | c[1]) % 31); - if (o.dictionary) { - var h = adler(); - h.p(o.dictionary); - wbytes(c, 2, h.d()); - } + var lv = o.level, fl = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2; + c[0] = 120, c[1] = (fl << 6) | (o.dictionary && 32); + c[1] |= 31 - ((c[0] << 8) | c[1]) % 31; + if (o.dictionary) { + var h = adler(); + h.p(o.dictionary); + wbytes(c, 2, h.d()); + } }; /** * Streaming DEFLATE compression */ var Deflate = /*#__PURE__*/ (function () { - function Deflate(opts, cb) { - if (typeof opts == 'function') ((cb = opts), (opts = {})); - this.ondata = cb; - this.o = opts || {}; - this.s = { l: 0, i: 32768, w: 32768, z: 32768 }; - // Buffer length must always be 0 mod 32768 for index calculations to be correct when modifying head and prev - // 98304 = 32768 (lookback) + 65536 (common chunk size) - this.b = new u8(98304); - if (this.o.dictionary) { - var dict = this.o.dictionary.subarray(-32768); - this.b.set(dict, 32768 - dict.length); - this.s.i = 32768 - dict.length; + function Deflate(opts, cb) { + if (typeof opts == 'function') + cb = opts, opts = {}; + this.ondata = cb; + this.o = opts || {}; + this.s = { l: 0, i: 32768, w: 32768, z: 32768 }; + // Buffer length must always be 0 mod 32768 for index calculations to be correct when modifying head and prev + // 98304 = 32768 (lookback) + 65536 (common chunk size) + this.b = new u8(98304); + if (this.o.dictionary) { + var dict = this.o.dictionary.subarray(-32768); + this.b.set(dict, 32768 - dict.length); + this.s.i = 32768 - dict.length; + } } - } - Deflate.prototype.p = function (c, f) { - this.ondata(dopt(c, this.o, 0, 0, this.s), f); - }; - /** - * Pushes a chunk to be deflated - * @param chunk The chunk to push - * @param final Whether this is the last chunk - */ - Deflate.prototype.push = function (chunk, final) { - if (!this.ondata) err(5); - if (this.s.l) err(4); - var endLen = chunk.length + this.s.z; - if (endLen > this.b.length) { - if (endLen > 2 * this.b.length - 32768) { - var newBuf = new u8(endLen & -32768); - newBuf.set(this.b.subarray(0, this.s.z)); - this.b = newBuf; - } - var split = this.b.length - this.s.z; - if (split) { - this.b.set(chunk.subarray(0, split), this.s.z); - this.s.z = this.b.length; + Deflate.prototype.p = function (c, f) { + this.ondata(dopt(c, this.o, 0, 0, this.s), f); + }; + /** + * Pushes a chunk to be deflated + * @param chunk The chunk to push + * @param final Whether this is the last chunk + */ + Deflate.prototype.push = function (chunk, final) { + if (!this.ondata) + err(5); + if (this.s.l) + err(4); + var endLen = chunk.length + this.s.z; + if (endLen > this.b.length) { + if (endLen > 2 * this.b.length - 32768) { + var newBuf = new u8(endLen & -32768); + newBuf.set(this.b.subarray(0, this.s.z)); + this.b = newBuf; + } + var split = this.b.length - this.s.z; + this.b.set(chunk.subarray(0, split), this.s.z); + this.s.z = this.b.length; + this.p(this.b, false); + this.b.set(this.b.subarray(-32768)); + this.b.set(chunk.subarray(split), 32768); + this.s.z = chunk.length - split + 32768; + this.s.i = 32766, this.s.w = 32768; + } + else { + this.b.set(chunk, this.s.z); + this.s.z += chunk.length; + } + this.s.l = final & 1; + if (this.s.z > this.s.w + 8191 || final) { + this.p(this.b, final || false); + this.s.w = this.s.i, this.s.i -= 2; + } + }; + /** + * Flushes buffered uncompressed data. Useful to immediately retrieve the + * deflated output for small inputs. + */ + Deflate.prototype.flush = function () { + if (!this.ondata) + err(5); + if (this.s.l) + err(4); this.p(this.b, false); - } - this.b.set(this.b.subarray(-32768)); - this.b.set(chunk.subarray(split), 32768); - this.s.z = chunk.length - split + 32768; - ((this.s.i = 32766), (this.s.w = 32768)); - } else { - this.b.set(chunk, this.s.z); - this.s.z += chunk.length; - } - this.s.l = final & 1; - if (this.s.z > this.s.w + 8191 || final) { - this.p(this.b, final || false); - ((this.s.w = this.s.i), (this.s.i -= 2)); - } - }; - return Deflate; -})(); + this.s.w = this.s.i, this.s.i -= 2; + }; + return Deflate; +}()); /** * Compresses data with GZIP * @param data The data to compress @@ -689,70 +678,81 @@ var Deflate = /*#__PURE__*/ (function () { * @returns The gzipped version of the data */ function gzipSync(data, opts) { - if (!opts) opts = {}; - var c = crc(), - l = data.length; - c.p(data); - var d = dopt(data, opts, gzhl(opts), 8), - s = d.length; - return (gzh(d, opts), wbytes(d, s - 8, c.d()), wbytes(d, s - 4, l), d); + if (!opts) + opts = {}; + var c = crc(), l = data.length; + c.p(data); + var d = dopt(data, opts, gzhl(opts), 8), s = d.length; + return gzh(d, opts), wbytes(d, s - 8, c.d()), wbytes(d, s - 4, l), d; } /** * Streaming Zlib compression */ var Zlib = /*#__PURE__*/ (function () { - function Zlib(opts, cb) { - this.c = adler(); - this.v = 1; - Deflate.call(this, opts, cb); - } - /** - * Pushes a chunk to be zlibbed - * @param chunk The chunk to push - * @param final Whether this is the last chunk - */ - Zlib.prototype.push = function (chunk, final) { - this.c.p(chunk); - Deflate.prototype.push.call(this, chunk, final); - }; - Zlib.prototype.p = function (c, f) { - var raw = dopt(c, this.o, this.v && (this.o.dictionary ? 6 : 2), f && 4, this.s); - if (this.v) (zlh(raw, this.o), (this.v = 0)); - if (f) wbytes(raw, raw.length - 4, this.c.d()); - this.ondata(raw, f); - }; - return Zlib; -})(); + function Zlib(opts, cb) { + this.c = adler(); + this.v = 1; + Deflate.call(this, opts, cb); + } + /** + * Pushes a chunk to be zlibbed + * @param chunk The chunk to push + * @param final Whether this is the last chunk + */ + Zlib.prototype.push = function (chunk, final) { + this.c.p(chunk); + Deflate.prototype.push.call(this, chunk, final); + }; + Zlib.prototype.p = function (c, f) { + var raw = dopt(c, this.o, this.v && (this.o.dictionary ? 6 : 2), f && 4, this.s); + if (this.v) + zlh(raw, this.o), this.v = 0; + if (f) + wbytes(raw, raw.length - 4, this.c.d()); + this.ondata(raw, f); + }; + /** + * Flushes buffered uncompressed data. Useful to immediately retrieve the + * zlibbed output for small inputs. + */ + Zlib.prototype.flush = function () { + Deflate.prototype.flush.call(this); + }; + return Zlib; +}()); // text encoder var te = typeof TextEncoder != 'undefined' && /*#__PURE__*/ new TextEncoder(); // text decoder var td = typeof TextDecoder != 'undefined' && /*#__PURE__*/ new TextDecoder(); try { - td.decode(et, { stream: true }); -} catch {} + td.decode(et, { stream: true }); +} +catch (e) { } /** * Streaming UTF-8 encoding */ var EncodeUTF8 = /*#__PURE__*/ (function () { - /** - * Creates a UTF-8 decoding stream - * @param cb The callback to call whenever data is encoded - */ - function EncodeUTF8(cb) { - this.ondata = cb; - } - /** - * Pushes a chunk to be encoded to UTF-8 - * @param chunk The string data to push - * @param final Whether this is the last chunk - */ - EncodeUTF8.prototype.push = function (chunk, final) { - if (!this.ondata) err(5); - if (this.d) err(4); - this.ondata(strToU8(chunk), (this.d = final || false)); - }; - return EncodeUTF8; -})(); + /** + * Creates a UTF-8 decoding stream + * @param cb The callback to call whenever data is encoded + */ + function EncodeUTF8(cb) { + this.ondata = cb; + } + /** + * Pushes a chunk to be encoded to UTF-8 + * @param chunk The string data to push + * @param final Whether this is the last chunk + */ + EncodeUTF8.prototype.push = function (chunk, final) { + if (!this.ondata) + err(5); + if (this.d) + err(4); + this.ondata(strToU8(chunk), this.d = final || false); + }; + return EncodeUTF8; +}()); /** * Converts a string into a Uint8Array for use with compression/decompression methods * @param str The string to encode @@ -761,41 +761,33 @@ var EncodeUTF8 = /*#__PURE__*/ (function () { * @returns The string encoded in UTF-8/Latin-1 binary */ function strToU8(str, latin1) { - if (latin1) { - var ar_1 = new u8(str.length); - for (var i = 0; i < str.length; ++i) ar_1[i] = str.charCodeAt(i); - return ar_1; - } - if (te) return te.encode(str); - var l = str.length; - var ar = new u8(str.length + (str.length >> 1)); - var ai = 0; - var w = function (v) { - ar[ai++] = v; - }; - for (var i = 0; i < l; ++i) { - if (ai + 5 > ar.length) { - var n = new u8(ai + 8 + ((l - i) << 1)); - n.set(ar); - ar = n; + var i; + if (te) + return te.encode(str); + var l = str.length; + var ar = new u8(str.length + (str.length >> 1)); + var ai = 0; + var w = function (v) { ar[ai++] = v; }; + for (var i = 0; i < l; ++i) { + if (ai + 5 > ar.length) { + var n = new u8(ai + 8 + ((l - i) << 1)); + n.set(ar); + ar = n; + } + var c = str.charCodeAt(i); + if (c < 128 || latin1) + w(c); + else if (c < 2048) + w(192 | (c >> 6)), w(128 | (c & 63)); + else if (c > 55295 && c < 57344) + c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023), + w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63)); + else + w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63)); } - var c = str.charCodeAt(i); - if (c < 128 || latin1) w(c); - else if (c < 2048) (w(192 | (c >> 6)), w(128 | (c & 63))); - else if (c > 55295 && c < 57344) - ((c = (65536 + (c & (1023 << 10))) | (str.charCodeAt(++i) & 1023)), - w(240 | (c >> 18)), - w(128 | ((c >> 12) & 63)), - w(128 | ((c >> 6) & 63)), - w(128 | (c & 63))); - else (w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63))); - } - return slc(ar, 0, ai); + return slc(ar, 0, ai); } -/** - * A stateful compressor that can be used to batch compress events. - */ class Compressor { constructor() { this._init(); @@ -811,11 +803,9 @@ class Compressor { */ addEvent(data) { if (!data) { - throw new Error('Adding invalid event'); + throw new Error("Adding invalid event"); } - // If the event is not the first event, we need to prefix it with a `,` so - // that we end up with a list of events - const prefix = this._hasEvents ? ',' : ''; + const prefix = this._hasEvents ? "," : ""; this.stream.push(prefix + data); this._hasEvents = true; } @@ -823,10 +813,7 @@ class Compressor { * Finish compression of the current buffer. */ finish() { - // We should always have a list, it can be empty - this.stream.push(']', true); - // Copy result before we create a new deflator and return the compressed - // result + this.stream.push("]", true); const result = mergeUInt8Arrays(this._deflatedData); this._init(); return result; @@ -844,26 +831,19 @@ class Compressor { this.stream = new EncodeUTF8((data, final) => { this.deflate.push(data, final); }); - // Fake an array by adding a `[` - this.stream.push('['); + this.stream.push("["); } } -/** - * Compress a string. - */ function compress(data) { return gzipSync(strToU8(data)); } function mergeUInt8Arrays(chunks) { - // calculate data length let len = 0; for (const chunk of chunks) { len += chunk.length; } - // join chunks const result = new Uint8Array(len); for (let i = 0, pos = 0, l = chunks.length; i < l; i++) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const chunk = chunks[i]; result.set(chunk, pos); pos += chunk.length; @@ -871,58 +851,50 @@ function mergeUInt8Arrays(chunks) { return result; } -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ const compressor = new Compressor(); const handlers = { clear: () => { compressor.clear(); }, - addEvent: data => { + addEvent: (data) => { return compressor.addEvent(data); }, finish: () => { return compressor.finish(); }, - compress: data => { + compress: (data) => { return compress(data); - }, + } }; -/** - * Handler for worker messages. - */ function handleMessage(e) { const method = e.data.method; const id = e.data.id; const data = e.data.arg; - // @ts-expect-error this syntax is actually fine - if (method in handlers && typeof handlers[method] === 'function') { + if (method in handlers && typeof handlers[method] === "function") { try { - // @ts-expect-error this syntax is actually fine const response = handlers[method](data); postMessage({ id, method, success: true, - response, + response }); } catch (err) { postMessage({ id, method, success: false, - response: err.message, + response: err.message }); - // eslint-disable-next-line no-console console.error(err); } } } -addEventListener('message', handleMessage); -// Immediately send a message when worker loads, so we know the worker is ready +addEventListener("message", handleMessage); postMessage({ - id: undefined, - method: 'init', + id: void 0, + method: "init", success: true, - response: undefined, + response: void 0 }); diff --git a/packages/replay-worker/examples/worker.min.js b/packages/replay-worker/examples/worker.min.js index fd6909c6b38b..7d9b5727dcc1 100644 --- a/packages/replay-worker/examples/worker.min.js +++ b/packages/replay-worker/examples/worker.min.js @@ -1,2 +1,2 @@ -/*! Sentry Replay Worker 8.33.1 (c992b3fad) | https://github.com/getsentry/sentry-javascript */ -var t=Uint8Array,n=Uint16Array,r=Int32Array,e=new t([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),i=new t([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),a=new t([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),s=function(t,e){for(var i=new n(31),a=0;a<31;++a)i[a]=e+=1<>1|(21845&c)<<1;v=(61680&(v=(52428&v)>>2|(13107&v)<<2))>>4|(3855&v)<<4,u[c]=((65280&v)>>8|(255&v)<<8)>>1}var d=function(t,r,e){for(var i=t.length,a=0,s=new n(r);a>h]=l}else for(o=new n(i),a=0;a>15-t[a]);return o},g=new t(288);for(c=0;c<144;++c)g[c]=8;for(c=144;c<256;++c)g[c]=9;for(c=256;c<280;++c)g[c]=7;for(c=280;c<288;++c)g[c]=8;var w=new t(32);for(c=0;c<32;++c)w[c]=5;var p=d(g,9,0),y=d(w,5,0),m=function(t){return(t+7)/8|0},b=function(n,r,e){return(null==r||r<0)&&(r=0),(null==e||e>n.length)&&(e=n.length),new t(n.subarray(r,e))},M=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],E=function(t,n,r){var e=new Error(n||M[t]);if(e.code=t,Error.captureStackTrace&&Error.captureStackTrace(e,E),!r)throw e;return e},z=function(t,n,r){r<<=7&n;var e=n/8|0;t[e]|=r,t[e+1]|=r>>8},A=function(t,n,r){r<<=7&n;var e=n/8|0;t[e]|=r,t[e+1]|=r>>8,t[e+2]|=r>>16},_=function(r,e){for(var i=[],a=0;ad&&(d=o[a].s);var g=new n(d+1),w=x(i[c-1],g,0);if(w>e){a=0;var p=0,y=w-e,m=1<e))break;p+=m-(1<>=y;p>0;){var M=o[a].s;g[M]=0&&p;--a){var E=o[a].s;g[E]==e&&(--g[E],++p)}w=e}return{t:new t(g),l:w}},x=function(t,n,r){return-1==t.s?Math.max(x(t.l,n,r+1),x(t.r,n,r+1)):n[t.s]=r},D=function(t){for(var r=t.length;r&&!t[--r];);for(var e=new n(++r),i=0,a=t[0],s=1,o=function(t){e[i++]=t},f=1;f<=r;++f)if(t[f]==a&&f!=r)++s;else{if(!a&&s>2){for(;s>138;s-=138)o(32754);s>2&&(o(s>10?s-11<<5|28690:s-3<<5|12305),s=0)}else if(s>3){for(o(a),--s;s>6;s-=6)o(8304);s>2&&(o(s-3<<5|8208),s=0)}for(;s--;)o(a);s=1,a=t[f]}return{c:e.subarray(0,i),n:r}},T=function(t,n){for(var r=0,e=0;e>8,t[i+2]=255^t[i],t[i+3]=255^t[i+1];for(var a=0;a4&&!H[a[K-1]];--K);var N,P,Q,R,V=v+5<<3,W=T(f,g)+T(h,w)+l,X=T(f,M)+T(h,C)+l+14+3*K+T(q,H)+2*q[16]+3*q[17]+7*q[18];if(c>=0&&V<=W&&V<=X)return k(r,m,t.subarray(c,c+v));if(z(r,m,1+(X15&&(z(r,m,tt[B]>>5&127),m+=tt[B]>>12)}}}else N=p,P=g,Q=y,R=w;for(B=0;B255){A(r,m,N[(nt=rt>>18&31)+257]),m+=P[nt+257],nt>7&&(z(r,m,rt>>23&31),m+=e[nt]);var et=31&rt;A(r,m,Q[et]),m+=R[et],et>3&&(A(r,m,rt>>5&8191),m+=i[et])}else A(r,m,N[rt]),m+=P[rt]}return A(r,m,N[256]),m+P[256]},U=new r([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),F=new t(0),I=function(){for(var t=new Int32Array(256),n=0;n<256;++n){for(var r=n,e=9;--e;)r=(1&r&&-306674912)^r>>>1;t[n]=r}return t}(),S=function(){var t=-1;return{p:function(n){for(var r=t,e=0;e>>8;t=r},d:function(){return~t}}},L=function(){var t=1,n=0;return{p:function(r){for(var e=t,i=n,a=0|r.length,s=0;s!=a;){for(var o=Math.min(s+2655,a);s>16),i=(65535&i)+15*(i>>16)}t=e,n=i},d:function(){return(255&(t%=65521))<<24|(65280&t)<<8|(255&(n%=65521))<<8|n>>8}}},O=function(a,s,o,f,u){if(!u&&(u={l:1},s.dictionary)){var c=s.dictionary.subarray(-32768),v=new t(c.length+a.length);v.set(c),v.set(a,c.length),a=v,u.w=c.length}return function(a,s,o,f,u,c){var v=c.z||a.length,d=new t(f+v+5*(1+Math.ceil(v/7e3))+u),g=d.subarray(f,d.length-u),w=c.l,p=7&(c.r||0);if(s){p&&(g[0]=c.r>>3);for(var y=U[s-1],M=y>>13,E=8191&y,z=(1<7e3||q>24576)&&(N>423||!w)){p=C(a,g,0,F,I,S,O,q,G,j-G,p),q=L=O=0,G=j;for(var P=0;P<286;++P)I[P]=0;for(P=0;P<30;++P)S[P]=0}var Q=2,R=0,V=E,W=J-K&32767;if(N>2&&H==T(j-W))for(var X=Math.min(M,N)-1,Y=Math.min(32767,j),Z=Math.min(258,N);W<=Y&&--V&&J!=K;){if(a[j+Q]==a[j+Q-W]){for(var $=0;$Q){if(Q=$,R=W,$>X)break;var tt=Math.min(W,$-2),nt=0;for(P=0;Pnt&&(nt=et,K=rt)}}}W+=(J=K)-(K=A[J])&32767}if(R){F[q++]=268435456|h[Q]<<18|l[R];var it=31&h[Q],at=31&l[R];O+=e[it]+i[at],++I[257+it],++S[at],B=j+Q,++L}else F[q++]=a[j],++I[a[j]]}}for(j=Math.max(j,B);j=v&&(g[p/8|0]=w,st=v),p=k(g,p+1,a.subarray(j,st))}c.i=v}return b(d,0,f+m(p)+u)}(a,null==s.level?6:s.level,null==s.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(a.length)))):12+s.mem,o,f,u)},j=function(t,n,r){for(;r;++n)t[n]=r,r>>>=8},q=function(t,n){var r=n.filename;if(t[0]=31,t[1]=139,t[2]=8,t[8]=n.level<2?4:9==n.level?2:0,t[9]=3,0!=n.mtime&&j(t,4,Math.floor(new Date(n.mtime||Date.now())/1e3)),r){t[3]=8;for(var e=0;e<=r.length;++e)t[e+10]=r.charCodeAt(e)}},B=function(t){return 10+(t.filename?t.filename.length+1:0)},G=function(){function n(n,r){if("function"==typeof n&&(r=n,n={}),this.ondata=r,this.o=n||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new t(98304),this.o.dictionary){var e=this.o.dictionary.subarray(-32768);this.b.set(e,32768-e.length),this.s.i=32768-e.length}}return n.prototype.p=function(t,n){this.ondata(O(t,this.o,0,0,this.s),n)},n.prototype.push=function(n,r){this.ondata||E(5),this.s.l&&E(4);var e=n.length+this.s.z;if(e>this.b.length){if(e>2*this.b.length-32768){var i=new t(-32768&e);i.set(this.b.subarray(0,this.s.z)),this.b=i}var a=this.b.length-this.s.z;a&&(this.b.set(n.subarray(0,a),this.s.z),this.s.z=this.b.length,this.p(this.b,!1)),this.b.set(this.b.subarray(-32768)),this.b.set(n.subarray(a),32768),this.s.z=n.length-a+32768,this.s.i=32766,this.s.w=32768}else this.b.set(n,this.s.z),this.s.z+=n.length;this.s.l=1&r,(this.s.z>this.s.w+8191||r)&&(this.p(this.b,r||!1),this.s.w=this.s.i,this.s.i-=2)},n}();var H=function(){function t(t,n){this.c=L(),this.v=1,G.call(this,t,n)}return t.prototype.push=function(t,n){this.c.p(t),G.prototype.push.call(this,t,n)},t.prototype.p=function(t,n){var r=O(t,this.o,this.v&&(this.o.dictionary?6:2),n&&4,this.s);this.v&&(function(t,n){var r=n.level,e=0==r?0:r<6?1:9==r?3:2;if(t[0]=120,t[1]=e<<6|(n.dictionary&&32),t[1]|=31-(t[0]<<8|t[1])%31,n.dictionary){var i=L();i.p(n.dictionary),j(t,2,i.d())}}(r,this.o),this.v=0),n&&j(r,r.length-4,this.c.d()),this.ondata(r,n)},t}(),J="undefined"!=typeof TextEncoder&&new TextEncoder,K="undefined"!=typeof TextDecoder&&new TextDecoder;try{K.decode(F,{stream:!0})}catch(t){}var N=function(){function t(t){this.ondata=t}return t.prototype.push=function(t,n){this.ondata||E(5),this.d&&E(4),this.ondata(P(t),this.d=n||!1)},t}();function P(n,r){if(r){for(var e=new t(n.length),i=0;i>1)),o=0,f=function(t){s[o++]=t};for(i=0;is.length){var h=new t(o+8+(a-i<<1));h.set(s),s=h}var l=n.charCodeAt(i);l<128||r?f(l):l<2048?(f(192|l>>6),f(128|63&l)):l>55295&&l<57344?(f(240|(l=65536+(1047552&l)|1023&n.charCodeAt(++i))>>18),f(128|l>>12&63),f(128|l>>6&63),f(128|63&l)):(f(224|l>>12),f(128|l>>6&63),f(128|63&l))}return b(s,0,o)}function Q(t){return function(t,n){n||(n={});var r=S(),e=t.length;r.p(t);var i=O(t,n,B(n),8),a=i.length;return q(i,n),j(i,a-8,r.d()),j(i,a-4,e),i}(P(t))}const R=new class{constructor(){this._init()}clear(){this._init()}addEvent(t){if(!t)throw new Error("Adding invalid event");const n=this._hasEvents?",":"";this.stream.push(n+t),this._hasEvents=!0}finish(){this.stream.push("]",!0);const t=function(t){let n=0;for(const r of t)n+=r.length;const r=new Uint8Array(n);for(let n=0,e=0,i=t.length;n{this._deflatedData.push(t)},this.stream=new N(((t,n)=>{this.deflate.push(t,n)})),this.stream.push("[")}},V={clear:()=>{R.clear()},addEvent:t=>R.addEvent(t),finish:()=>R.finish(),compress:t=>Q(t)};addEventListener("message",(function(t){const n=t.data.method,r=t.data.id,e=t.data.arg;if(n in V&&"function"==typeof V[n])try{const t=V[n](e);postMessage({id:r,method:n,success:!0,response:t})}catch(t){postMessage({id:r,method:n,success:!1,response:t.message}),console.error(t)}})),postMessage({id:void 0,method:"init",success:!0,response:void 0}); +/*! Sentry Replay Worker 10.53.1 (c003f6450c) | https://github.com/getsentry/sentry-javascript */ +var t=Uint8Array,n=Uint16Array,r=Int32Array,e=new t([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),i=new t([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),s=new t([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),a=function(t,e){for(var i=new n(31),s=0;s<31;++s)i[s]=e+=1<>1|(21845&c)<<1;v=(61680&(v=(52428&v)>>2|(13107&v)<<2))>>4|(3855&v)<<4,u[c]=((65280&v)>>8|(255&v)<<8)>>1}var d=function(t,r,e){for(var i=t.length,s=0,a=new n(r);s>f]=l}else for(o=new n(i),s=0;s>15-t[s]);return o},p=new t(288);for(c=0;c<144;++c)p[c]=8;for(c=144;c<256;++c)p[c]=9;for(c=256;c<280;++c)p[c]=7;for(c=280;c<288;++c)p[c]=8;var g=new t(32);for(c=0;c<32;++c)g[c]=5;var w=d(p,9,0),y=d(g,5,0),m=function(t){return(t+7)/8|0},b=function(n,r,e){return(null==e||e>n.length)&&(e=n.length),new t(n.subarray(r,e))},M=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],E=function(t,n,r){var e=new Error(n||M[t]);if(e.code=t,Error.captureStackTrace&&Error.captureStackTrace(e,E),!r)throw e;return e},z=function(t,n,r){r<<=7&n;var e=n/8|0;t[e]|=r,t[e+1]|=r>>8},_=function(t,n,r){r<<=7&n;var e=n/8|0;t[e]|=r,t[e+1]|=r>>8,t[e+2]|=r>>16},x=function(r,e){for(var i=[],s=0;sd&&(d=o[s].s);var p=new n(d+1),g=A(i[c-1],p,0);if(g>e){s=0;var w=0,y=g-e,m=1<e))break;w+=m-(1<>=y;w>0;){var M=o[s].s;p[M]=0&&w;--s){var E=o[s].s;p[E]==e&&(--p[E],++w)}g=e}return{t:new t(p),l:g}},A=function(t,n,r){return-1==t.s?Math.max(A(t.l,n,r+1),A(t.r,n,r+1)):n[t.s]=r},D=function(t){for(var r=t.length;r&&!t[--r];);for(var e=new n(++r),i=0,s=t[0],a=1,o=function(t){e[i++]=t},h=1;h<=r;++h)if(t[h]==s&&h!=r)++a;else{if(!s&&a>2){for(;a>138;a-=138)o(32754);a>2&&(o(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(o(s),--a;a>6;a-=6)o(8304);a>2&&(o(a-3<<5|8208),a=0)}for(;a--;)o(s);a=1,s=t[h]}return{c:e.subarray(0,i),n:r}},T=function(t,n){for(var r=0,e=0;e>8,t[i+2]=255^t[i],t[i+3]=255^t[i+1];for(var s=0;s4&&!H[s[K-1]];--K);var N,P,Q,R,V=v+5<<3,W=T(h,p)+T(f,g)+l,X=T(h,M)+T(f,U)+l+14+3*K+T(q,H)+2*q[16]+3*q[17]+7*q[18];if(c>=0&&V<=W&&V<=X)return k(r,m,t.subarray(c,c+v));if(z(r,m,1+(X15&&(z(r,m,tt[B]>>5&127),m+=tt[B]>>12)}}}else N=w,P=p,Q=y,R=g;for(B=0;B255){_(r,m,N[(nt=rt>>18&31)+257]),m+=P[nt+257],nt>7&&(z(r,m,rt>>23&31),m+=e[nt]);var et=31&rt;_(r,m,Q[et]),m+=R[et],et>3&&(_(r,m,rt>>5&8191),m+=i[et])}else _(r,m,N[rt]),m+=P[rt]}return _(r,m,N[256]),m+P[256]},C=new r([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),F=new t(0),I=function(){for(var t=new Int32Array(256),n=0;n<256;++n){for(var r=n,e=9;--e;)r=(1&r&&-306674912)^r>>>1;t[n]=r}return t}(),S=function(){var t=1,n=0;return{p:function(r){for(var e=t,i=n,s=0|r.length,a=0;a!=s;){for(var o=Math.min(a+2655,s);a>16),i=(65535&i)+15*(i>>16)}t=e,n=i},d:function(){return(255&(t%=65521))<<24|(65280&t)<<8|(255&(n%=65521))<<8|n>>8}}},L=function(s,a,o,h,u){if(!u&&(u={l:1},a.dictionary)){var c=a.dictionary.subarray(-32768),v=new t(c.length+s.length);v.set(c),v.set(s,c.length),s=v,u.w=c.length}return function(s,a,o,h,u,c){var v=c.z||s.length,d=new t(h+v+5*(1+Math.ceil(v/7e3))+u),p=d.subarray(h,d.length-u),g=c.l,w=7&(c.r||0);if(a){w&&(p[0]=c.r>>3);for(var y=C[a-1],M=y>>13,E=8191&y,z=(1<7e3||q>24576)&&(N>423||!g)){w=U(s,p,0,F,I,S,O,q,G,j-G,w),q=L=O=0,G=j;for(var P=0;P<286;++P)I[P]=0;for(P=0;P<30;++P)S[P]=0}var Q=2,R=0,V=E,W=J-K&32767;if(N>2&&H==T(j-W))for(var X=Math.min(M,N)-1,Y=Math.min(32767,j),Z=Math.min(258,N);W<=Y&&--V&&J!=K;){if(s[j+Q]==s[j+Q-W]){for(var $=0;$Q){if(Q=$,R=W,$>X)break;var tt=Math.min(W,$-2),nt=0;for(P=0;Pnt&&(nt=et,K=rt)}}}W+=(J=K)-(K=_[J])&32767}if(R){F[q++]=268435456|f[Q]<<18|l[R];var it=31&f[Q],st=31&l[R];O+=e[it]+i[st],++I[257+it],++S[st],B=j+Q,++L}else F[q++]=s[j],++I[s[j]]}}for(j=Math.max(j,B);j=v&&(p[w/8|0]=g,at=v),w=k(p,w+1,s.subarray(j,at))}c.i=v}return b(d,0,h+m(w)+u)}(s,null==a.level?6:a.level,null==a.mem?u.l?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(s.length)))):20:12+a.mem,o,h,u)},O=function(t,n,r){for(;r;++n)t[n]=r,r>>>=8},j=function(){function n(n,r){if("function"==typeof n&&(r=n,n={}),this.ondata=r,this.o=n||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new t(98304),this.o.dictionary){var e=this.o.dictionary.subarray(-32768);this.b.set(e,32768-e.length),this.s.i=32768-e.length}}return n.prototype.p=function(t,n){this.ondata(L(t,this.o,0,0,this.s),n)},n.prototype.push=function(n,r){this.ondata||E(5),this.s.l&&E(4);var e=n.length+this.s.z;if(e>this.b.length){if(e>2*this.b.length-32768){var i=new t(-32768&e);i.set(this.b.subarray(0,this.s.z)),this.b=i}var s=this.b.length-this.s.z;this.b.set(n.subarray(0,s),this.s.z),this.s.z=this.b.length,this.p(this.b,!1),this.b.set(this.b.subarray(-32768)),this.b.set(n.subarray(s),32768),this.s.z=n.length-s+32768,this.s.i=32766,this.s.w=32768}else this.b.set(n,this.s.z),this.s.z+=n.length;this.s.l=1&r,(this.s.z>this.s.w+8191||r)&&(this.p(this.b,r||!1),this.s.w=this.s.i,this.s.i-=2)},n.prototype.flush=function(){this.ondata||E(5),this.s.l&&E(4),this.p(this.b,!1),this.s.w=this.s.i,this.s.i-=2},n}();function q(t,n){n||(n={});var r=function(){var t=-1;return{p:function(n){for(var r=t,e=0;e>>8;t=r},d:function(){return~t}}}(),e=t.length;r.p(t);var i,s=L(t,n,10+((i=n).filename?i.filename.length+1:0),8),a=s.length;return function(t,n){var r=n.filename;if(t[0]=31,t[1]=139,t[2]=8,t[8]=n.level<2?4:9==n.level?2:0,t[9]=3,0!=n.mtime&&O(t,4,Math.floor(new Date(n.mtime||Date.now())/1e3)),r){t[3]=8;for(var e=0;e<=r.length;++e)t[e+10]=r.charCodeAt(e)}}(s,n),O(s,a-8,r.d()),O(s,a-4,e),s}var B=function(){function t(t,n){this.c=S(),this.v=1,j.call(this,t,n)}return t.prototype.push=function(t,n){this.c.p(t),j.prototype.push.call(this,t,n)},t.prototype.p=function(t,n){var r=L(t,this.o,this.v&&(this.o.dictionary?6:2),n&&4,this.s);this.v&&(function(t,n){var r=n.level,e=0==r?0:r<6?1:9==r?3:2;if(t[0]=120,t[1]=e<<6|(n.dictionary&&32),t[1]|=31-(t[0]<<8|t[1])%31,n.dictionary){var i=S();i.p(n.dictionary),O(t,2,i.d())}}(r,this.o),this.v=0),n&&O(r,r.length-4,this.c.d()),this.ondata(r,n)},t.prototype.flush=function(){j.prototype.flush.call(this)},t}(),G="undefined"!=typeof TextEncoder&&new TextEncoder,H="undefined"!=typeof TextDecoder&&new TextDecoder;try{H.decode(F,{stream:!0})}catch(t){}var J=function(){function t(t){this.ondata=t}return t.prototype.push=function(t,n){this.ondata||E(5),this.d&&E(4),this.ondata(K(t),this.d=n||!1)},t}();function K(n,r){if(G)return G.encode(n);for(var e=n.length,i=new t(n.length+(n.length>>1)),s=0,a=function(t){i[s++]=t},o=0;oi.length){var h=new t(s+8+(e-o<<1));h.set(i),i=h}var f=n.charCodeAt(o);f<128||r?a(f):f<2048?(a(192|f>>6),a(128|63&f)):f>55295&&f<57344?(a(240|(f=65536+(1047552&f)|1023&n.charCodeAt(++o))>>18),a(128|f>>12&63),a(128|f>>6&63),a(128|63&f)):(a(224|f>>12),a(128|f>>6&63),a(128|63&f))}return b(i,0,s)}const N=new class{constructor(){this._init()}clear(){this._init()}addEvent(t){if(!t)throw new Error("Adding invalid event");const n=this._hasEvents?",":"";this.stream.push(n+t),this._hasEvents=!0}finish(){this.stream.push("]",!0);const t=function(t){let n=0;for(const r of t)n+=r.length;const r=new Uint8Array(n);for(let n=0,e=0,i=t.length;n{this._deflatedData.push(t)},this.stream=new J((t,n)=>{this.deflate.push(t,n)}),this.stream.push("[")}},P={clear:()=>{N.clear()},addEvent:t=>N.addEvent(t),finish:()=>N.finish(),compress:t=>function(t){return q(K(t))}(t)};addEventListener("message",function(t){const n=t.data.method,r=t.data.id,e=t.data.arg;if(n in P&&"function"==typeof P[n])try{const t=P[n](e);postMessage({id:r,method:n,success:!0,response:t})}catch(t){postMessage({id:r,method:n,success:!1,response:t.message}),console.error(t)}}),postMessage({id:void 0,method:"init",success:!0,response:void 0}); diff --git a/packages/replay-worker/rollup.examples.config.mjs b/packages/replay-worker/rollup.examples.config.mjs index cbaacbfcb245..7ca68e89556d 100644 --- a/packages/replay-worker/rollup.examples.config.mjs +++ b/packages/replay-worker/rollup.examples.config.mjs @@ -1,12 +1,14 @@ import commonjs from '@rollup/plugin-commonjs'; import resolve from '@rollup/plugin-node-resolve'; import terser from '@rollup/plugin-terser'; -import typescript from '@rollup/plugin-typescript'; import { defineConfig } from 'rollup'; +import esbuild from 'rollup-plugin-esbuild'; import { makeLicensePlugin } from '../../dev-packages/rollup-utils/plugins/index.mjs'; const licensePlugin = makeLicensePlugin('Sentry Replay Worker'); +const esbuildPlugin = esbuild({ tsconfig: './tsconfig.json', target: 'es2020', sourceMap: false }); + const config = defineConfig([ { input: ['./src/_worker.ts'], @@ -15,12 +17,7 @@ const config = defineConfig([ format: 'esm', }, treeshake: 'smallest', - plugins: [ - commonjs(), - typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }), - resolve(), - licensePlugin, - ], + plugins: [commonjs(), esbuildPlugin, resolve(), licensePlugin], }, { input: ['./src/_worker.ts'], @@ -31,7 +28,7 @@ const config = defineConfig([ treeshake: 'smallest', plugins: [ commonjs(), - typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }), + esbuildPlugin, resolve(), terser({ mangle: { diff --git a/packages/replay-worker/rollup.worker.config.mjs b/packages/replay-worker/rollup.worker.config.mjs index 556994570335..36f18cb2a7e6 100644 --- a/packages/replay-worker/rollup.worker.config.mjs +++ b/packages/replay-worker/rollup.worker.config.mjs @@ -3,8 +3,10 @@ import commonjs from '@rollup/plugin-commonjs'; import resolve from '@rollup/plugin-node-resolve'; import terser from '@rollup/plugin-terser'; -import typescript from '@rollup/plugin-typescript'; import { defineConfig } from 'rollup'; +import esbuild from 'rollup-plugin-esbuild'; + +const esbuildPlugin = esbuild({ tsconfig: './tsconfig.json', target: 'es2020', sourceMap: false }); const config = defineConfig([ { @@ -16,7 +18,7 @@ const config = defineConfig([ }, external: ['./worker'], plugins: [ - typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }), + esbuildPlugin, terser({ mangle: { module: true, @@ -33,7 +35,7 @@ const config = defineConfig([ treeshake: 'smallest', plugins: [ commonjs(), - typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }), + esbuildPlugin, resolve(), terser({ mangle: { @@ -57,7 +59,7 @@ const config = defineConfig([ treeshake: 'smallest', plugins: [ commonjs(), - typescript({ tsconfig: './tsconfig.json', inlineSourceMap: false, sourceMap: false, inlineSources: false }), + esbuildPlugin, resolve(), terser({ mangle: { diff --git a/yarn.lock b/yarn.lock index 9da6ebb512f7..553dfe24fbc7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7411,13 +7411,6 @@ magic-string "^0.30.3" picomatch "^4.0.2" -"@rollup/plugin-esm-shim@^0.1.5": - version "0.1.5" - resolved "https://registry.yarnpkg.com/@rollup/plugin-esm-shim/-/plugin-esm-shim-0.1.5.tgz#74464e9a8a7e664557aae65592c8a3e317802220" - integrity sha512-xnIjDm/0EbqAw0/rR1UE7eAo9db0ftGPqT8RUCFtkFxtCuspbbmj+wutoyxm32jBytyO3SgkxSG17OR893fV7A== - dependencies: - magic-string "^0.30.3" - "@rollup/plugin-inject@^5.0.5": version "5.0.5" resolved "https://registry.yarnpkg.com/@rollup/plugin-inject/-/plugin-inject-5.0.5.tgz#616f3a73fe075765f91c5bec90176608bed277a3" @@ -7501,14 +7494,6 @@ smob "^1.0.0" terser "^5.17.4" -"@rollup/plugin-typescript@^11.1.6": - version "11.1.6" - resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz#724237d5ec12609ec01429f619d2a3e7d4d1b22b" - integrity sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA== - dependencies: - "@rollup/pluginutils" "^5.1.0" - resolve "^1.22.1" - "@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.0.9", "@rollup/pluginutils@^3.1.0": version "3.1.0" resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"