@sentry/rollup-plugin 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/cjs/index.js +13 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +15 -13
package/README.md
CHANGED
|
@@ -247,10 +247,12 @@ Default: `[]`
|
|
|
247
247
|
|
|
248
248
|
### `sourcemaps.rewriteSources`
|
|
249
249
|
|
|
250
|
-
Type: `(source: string, map: any) => string`
|
|
250
|
+
Type: `(source: string, map: any, context?: { mapDir: string }) => string`
|
|
251
251
|
|
|
252
252
|
Hook to rewrite the `sources` field inside the source map before being uploaded to Sentry. Does not modify the actual source map. Effectively, this modifies how files inside the stacktrace will show up in Sentry.
|
|
253
253
|
|
|
254
|
+
The `context.mapDir` parameter provides the directory path of the source map file, which is useful for resolving relative source paths (e.g. `path.resolve(context.mapDir, source)`).
|
|
255
|
+
|
|
254
256
|
Defaults to making all sources relative to `process.cwd()` while building.
|
|
255
257
|
|
|
256
258
|
### `sourcemaps.resolveSourceMap`
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value:
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -7,16 +7,12 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
20
16
|
}
|
|
21
17
|
return to;
|
|
22
18
|
};
|
|
@@ -24,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
20
|
value: mod,
|
|
25
21
|
enumerable: true
|
|
26
22
|
}) : target, mod));
|
|
27
|
-
|
|
28
23
|
//#endregion
|
|
29
24
|
let _sentry_bundler_plugin_core = require("@sentry/bundler-plugin-core");
|
|
30
25
|
let magic_string = require("magic-string");
|
|
@@ -32,7 +27,6 @@ magic_string = __toESM(magic_string);
|
|
|
32
27
|
let node_path = require("node:path");
|
|
33
28
|
node_path = __toESM(node_path);
|
|
34
29
|
let node_module = require("node:module");
|
|
35
|
-
|
|
36
30
|
//#region src/index.ts
|
|
37
31
|
function hasExistingDebugID(code) {
|
|
38
32
|
const chunkStartSnippet = code.slice(0, 6e3);
|
|
@@ -142,14 +136,14 @@ function _rollupPluginInternal(userOptions = {}, buildTool, buildToolMajorVersio
|
|
|
142
136
|
function sentryRollupPlugin(userOptions = {}) {
|
|
143
137
|
return [_rollupPluginInternal(userOptions, "rollup")];
|
|
144
138
|
}
|
|
145
|
-
|
|
146
139
|
//#endregion
|
|
147
140
|
exports._rollupPluginInternal = _rollupPluginInternal;
|
|
148
|
-
Object.defineProperty(exports,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
141
|
+
Object.defineProperty(exports, "sentryCliBinaryExists", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function() {
|
|
144
|
+
return _sentry_bundler_plugin_core.sentryCliBinaryExists;
|
|
145
|
+
}
|
|
153
146
|
});
|
|
154
147
|
exports.sentryRollupPlugin = sentryRollupPlugin;
|
|
148
|
+
|
|
155
149
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["CodeInjection","MagicString","COMMENT_USE_STRICT_REGEX","path"],"sources":["../../src/index.ts"],"sourcesContent":["import {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n isJsFile,\n shouldSkipCodeInjection,\n Options,\n getDebugIdSnippet,\n stringToUUID,\n COMMENT_USE_STRICT_REGEX,\n createDebugIdUploadFunction,\n globFiles,\n createComponentNameAnnotateHooks,\n replaceBooleanFlagsInCode,\n CodeInjection,\n} from \"@sentry/bundler-plugin-core\";\nimport MagicString, { SourceMap } from \"magic-string\";\nimport type { TransformResult } from \"rollup\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\n\nfunction hasExistingDebugID(code: string): boolean {\n // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)\n const chunkStartSnippet = code.slice(0, 6000);\n const chunkEndSnippet = code.slice(-500);\n\n if (\n chunkStartSnippet.includes(\"_sentryDebugIdIdentifier\") ||\n chunkEndSnippet.includes(\"//# debugId=\")\n ) {\n return true; // Debug ID already present, skip injection\n }\n\n return false;\n}\n\nfunction getRollupMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Rollup already transpiles this for us\n const req = createRequire(import.meta.url);\n const rollup = req(\"rollup\") as { VERSION?: string };\n return rollup.VERSION?.split(\".\")[0];\n } catch (err) {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\n/**\n * @ignore - this is the internal plugin factory function only used for the Vite plugin!\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function _rollupPluginInternal(\n userOptions: Options = {},\n buildTool: \"rollup\" | \"vite\",\n buildToolMajorVersion?: string\n) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[sentry-${buildTool}-plugin]`,\n buildTool,\n buildToolMajorVersion: buildToolMajorVersion || getRollupMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n name: \"sentry-noop-plugin\",\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn(\n \"Running Sentry plugin from within a `node_modules` folder. Some features may not work.\"\n );\n }\n\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug(\n \"Release injection disabled via `release.inject` option. Will not inject release.\"\n );\n } else if (!options.release.name) {\n logger.debug(\n \"No release name provided. Will not inject release. Please set the `release.name` option to identify your release.\"\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n })\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n const transformAnnotations = options.reactComponentAnnotation?.enabled\n ? createComponentNameAnnotateHooks(\n options.reactComponentAnnotation?.ignoredComponents || [],\n !!options.reactComponentAnnotation?._experimentalInjectIntoHtml\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n const shouldTransform = transformAnnotations || transformReplace;\n\n function buildStart(): void {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n }\n\n async function transform(code: string, id: string): Promise<TransformResult> {\n // Component annotations are only in user code and boolean flag replacements are\n // only in Sentry code. If we successfully add annotations, we can return early.\n\n if (transformAnnotations?.transform) {\n const result = await transformAnnotations.transform(code, id);\n if (result) {\n return result;\n }\n }\n\n if (transformReplace) {\n return replaceBooleanFlagsInCode(code, replacementValues);\n }\n\n return null;\n }\n\n function renderChunk(\n code: string,\n chunk: { fileName: string; facadeModuleId?: string | null },\n _?: unknown,\n meta?: { magicString?: MagicString }\n ): {\n code: string;\n map?: SourceMap;\n } | null {\n if (!isJsFile(chunk.fileName)) {\n return null; // returning null means not modifying the chunk at all\n }\n\n // Skip empty chunks and HTML facade chunks (Vite MPA)\n if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {\n return null;\n }\n\n const injectCode = staticInjectionCode.clone();\n\n if (sourcemapsEnabled && !hasExistingDebugID(code)) {\n const debugId = stringToUUID(code); // generate a deterministic debug ID\n injectCode.append(getDebugIdSnippet(debugId));\n }\n\n if (injectCode.isEmpty()) {\n return null;\n }\n\n const ms = meta?.magicString || new MagicString(code, { filename: chunk.fileName });\n const match = code.match(COMMENT_USE_STRICT_REGEX)?.[0];\n\n if (match) {\n // Add injected code after any comments or \"use strict\" at the beginning of the bundle.\n ms.appendLeft(match.length, injectCode.code());\n } else {\n // ms.replace() doesn't work when there is an empty string match (which happens if\n // there is neither, a comment, nor a \"use strict\" at the top of the chunk) so we\n // need this special case here.\n ms.prepend(injectCode.code());\n }\n\n // Rolldown can pass a native MagicString instance in meta.magicString\n // https://rolldown.rs/in-depth/native-magic-string#usage-examples\n if (ms?.constructor?.name === \"BindingMagicString\") {\n // Rolldown docs say to return the magic string instance directly in this case\n return { code: ms as unknown as string };\n }\n\n return {\n code: ms.toString(),\n map: ms.generateMap({ file: chunk.fileName, hires: \"boundary\" as unknown as undefined }),\n };\n }\n\n async function writeBundle(\n outputOptions: { dir?: string; file?: string },\n bundle: { [fileName: string]: unknown }\n ): Promise<void> {\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (sourcemapsEnabled && options.sourcemaps?.disable !== \"disable-upload\") {\n if (outputOptions.dir) {\n const outputDir = outputOptions.dir;\n const JS_AND_MAP_PATTERNS = [\n \"/**/*.js\",\n \"/**/*.mjs\",\n \"/**/*.cjs\",\n \"/**/*.js.map\",\n \"/**/*.mjs.map\",\n \"/**/*.cjs.map\",\n ].map((q) => `${q}?(\\\\?*)?(#*)`); // We want to allow query and hash strings at the end of files\n const buildArtifacts = await globFiles(JS_AND_MAP_PATTERNS, { root: outputDir });\n await upload(buildArtifacts);\n } else if (outputOptions.file) {\n await upload([outputOptions.file]);\n } else {\n const buildArtifacts = Object.keys(bundle).map((asset) =>\n path.join(path.resolve(), asset)\n );\n await upload(buildArtifacts);\n }\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n }\n\n const name = `sentry-${buildTool}-plugin`;\n\n if (shouldTransform) {\n return {\n name,\n buildStart,\n transform,\n renderChunk,\n writeBundle,\n };\n }\n\n return {\n name,\n buildStart,\n renderChunk,\n writeBundle,\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any\nexport function sentryRollupPlugin(userOptions: Options = {}): any {\n // We return an array here so we don't break backwards compatibility with what\n // unplugin used to return\n return [_rollupPluginInternal(userOptions, \"rollup\")];\n}\n\nexport type { Options as SentryRollupPluginOptions } from \"@sentry/bundler-plugin-core\";\nexport { sentryCliBinaryExists } from \"@sentry/bundler-plugin-core\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAS,mBAAmB,MAAuB;CAEjD,MAAM,oBAAoB,KAAK,MAAM,GAAG,IAAK;CAC7C,MAAM,kBAAkB,KAAK,MAAM,KAAK;AAExC,K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CAAC,cAAc,KAAK,CAAC;OAKlC,OAAM,OAHiB,OAAO,KAAK,OAAO,CAAC,KAAK,UAC9CC,UAAK,KAAKA,UAAK,SAAS,EAAE,MAAM,CACjC,CAC2B;YAGxB;AACR,yCAAsC;AACtC,SAAM,yBAAyB,iBAAiB;;;CAIpD,MAAM,OAAO,UAAU,UAAU;AAEjC,KAAI,gBACF,QAAO;EACL;EACA;EACA;EACA;EACA;EACD;AAGH,QAAO;EACL;EACA;EACA;EACA;EACD;;AAIH,SAAgB,mBAAmB,cAAuB,EAAE,EAAO;AAGjE,QAAO,CAAC,sBAAsB,aAAa,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["CodeInjection","MagicString","COMMENT_USE_STRICT_REGEX","path"],"sources":["../../src/index.ts"],"sourcesContent":["import {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n isJsFile,\n shouldSkipCodeInjection,\n Options,\n getDebugIdSnippet,\n stringToUUID,\n COMMENT_USE_STRICT_REGEX,\n createDebugIdUploadFunction,\n globFiles,\n createComponentNameAnnotateHooks,\n replaceBooleanFlagsInCode,\n CodeInjection,\n} from \"@sentry/bundler-plugin-core\";\nimport MagicString, { SourceMap } from \"magic-string\";\nimport type { TransformResult } from \"rollup\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\n\nfunction hasExistingDebugID(code: string): boolean {\n // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)\n const chunkStartSnippet = code.slice(0, 6000);\n const chunkEndSnippet = code.slice(-500);\n\n if (\n chunkStartSnippet.includes(\"_sentryDebugIdIdentifier\") ||\n chunkEndSnippet.includes(\"//# debugId=\")\n ) {\n return true; // Debug ID already present, skip injection\n }\n\n return false;\n}\n\nfunction getRollupMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Rollup already transpiles this for us\n const req = createRequire(import.meta.url);\n const rollup = req(\"rollup\") as { VERSION?: string };\n return rollup.VERSION?.split(\".\")[0];\n } catch (err) {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\n/**\n * @ignore - this is the internal plugin factory function only used for the Vite plugin!\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function _rollupPluginInternal(\n userOptions: Options = {},\n buildTool: \"rollup\" | \"vite\",\n buildToolMajorVersion?: string\n) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[sentry-${buildTool}-plugin]`,\n buildTool,\n buildToolMajorVersion: buildToolMajorVersion || getRollupMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n name: \"sentry-noop-plugin\",\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn(\n \"Running Sentry plugin from within a `node_modules` folder. Some features may not work.\"\n );\n }\n\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug(\n \"Release injection disabled via `release.inject` option. Will not inject release.\"\n );\n } else if (!options.release.name) {\n logger.debug(\n \"No release name provided. Will not inject release. Please set the `release.name` option to identify your release.\"\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n })\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n const transformAnnotations = options.reactComponentAnnotation?.enabled\n ? createComponentNameAnnotateHooks(\n options.reactComponentAnnotation?.ignoredComponents || [],\n !!options.reactComponentAnnotation?._experimentalInjectIntoHtml\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n const shouldTransform = transformAnnotations || transformReplace;\n\n function buildStart(): void {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n }\n\n async function transform(code: string, id: string): Promise<TransformResult> {\n // Component annotations are only in user code and boolean flag replacements are\n // only in Sentry code. If we successfully add annotations, we can return early.\n\n if (transformAnnotations?.transform) {\n const result = await transformAnnotations.transform(code, id);\n if (result) {\n return result;\n }\n }\n\n if (transformReplace) {\n return replaceBooleanFlagsInCode(code, replacementValues);\n }\n\n return null;\n }\n\n function renderChunk(\n code: string,\n chunk: { fileName: string; facadeModuleId?: string | null },\n _?: unknown,\n meta?: { magicString?: MagicString }\n ): {\n code: string;\n map?: SourceMap;\n } | null {\n if (!isJsFile(chunk.fileName)) {\n return null; // returning null means not modifying the chunk at all\n }\n\n // Skip empty chunks and HTML facade chunks (Vite MPA)\n if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {\n return null;\n }\n\n const injectCode = staticInjectionCode.clone();\n\n if (sourcemapsEnabled && !hasExistingDebugID(code)) {\n const debugId = stringToUUID(code); // generate a deterministic debug ID\n injectCode.append(getDebugIdSnippet(debugId));\n }\n\n if (injectCode.isEmpty()) {\n return null;\n }\n\n const ms = meta?.magicString || new MagicString(code, { filename: chunk.fileName });\n const match = code.match(COMMENT_USE_STRICT_REGEX)?.[0];\n\n if (match) {\n // Add injected code after any comments or \"use strict\" at the beginning of the bundle.\n ms.appendLeft(match.length, injectCode.code());\n } else {\n // ms.replace() doesn't work when there is an empty string match (which happens if\n // there is neither, a comment, nor a \"use strict\" at the top of the chunk) so we\n // need this special case here.\n ms.prepend(injectCode.code());\n }\n\n // Rolldown can pass a native MagicString instance in meta.magicString\n // https://rolldown.rs/in-depth/native-magic-string#usage-examples\n if (ms?.constructor?.name === \"BindingMagicString\") {\n // Rolldown docs say to return the magic string instance directly in this case\n return { code: ms as unknown as string };\n }\n\n return {\n code: ms.toString(),\n map: ms.generateMap({ file: chunk.fileName, hires: \"boundary\" as unknown as undefined }),\n };\n }\n\n async function writeBundle(\n outputOptions: { dir?: string; file?: string },\n bundle: { [fileName: string]: unknown }\n ): Promise<void> {\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (sourcemapsEnabled && options.sourcemaps?.disable !== \"disable-upload\") {\n if (outputOptions.dir) {\n const outputDir = outputOptions.dir;\n const JS_AND_MAP_PATTERNS = [\n \"/**/*.js\",\n \"/**/*.mjs\",\n \"/**/*.cjs\",\n \"/**/*.js.map\",\n \"/**/*.mjs.map\",\n \"/**/*.cjs.map\",\n ].map((q) => `${q}?(\\\\?*)?(#*)`); // We want to allow query and hash strings at the end of files\n const buildArtifacts = await globFiles(JS_AND_MAP_PATTERNS, { root: outputDir });\n await upload(buildArtifacts);\n } else if (outputOptions.file) {\n await upload([outputOptions.file]);\n } else {\n const buildArtifacts = Object.keys(bundle).map((asset) =>\n path.join(path.resolve(), asset)\n );\n await upload(buildArtifacts);\n }\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n }\n\n const name = `sentry-${buildTool}-plugin`;\n\n if (shouldTransform) {\n return {\n name,\n buildStart,\n transform,\n renderChunk,\n writeBundle,\n };\n }\n\n return {\n name,\n buildStart,\n renderChunk,\n writeBundle,\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any\nexport function sentryRollupPlugin(userOptions: Options = {}): any {\n // We return an array here so we don't break backwards compatibility with what\n // unplugin used to return\n return [_rollupPluginInternal(userOptions, \"rollup\")];\n}\n\nexport type { Options as SentryRollupPluginOptions } from \"@sentry/bundler-plugin-core\";\nexport { sentryCliBinaryExists } from \"@sentry/bundler-plugin-core\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SA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K,GAAG,YAAY;IAAE,MAAM,MAAM;IAAU,OAAO;IAAoC,CAAC;GACzF;;CAGH,eAAe,YACb,eACA,QACe;AACf,MAAI;AACF,SAAM,yBAAyB,eAAe;AAE9C,OAAI,qBAAqB,QAAQ,YAAY,YAAY,iBACvD,KAAI,cAAc,KAAK;IACrB,MAAM,YAAY,cAAc;AAUhC,UAAM,OADiB,OAAA,GAAA,4BAAA,WARK;KAC1B;KACA;KACA;KACA;KACA;KACA;KACD,CAAC,KAAK,MAAM,GAAG,EAAE,cAAc,EAC4B,EAAE,MAAM,WAAW,CAAC,CACpD;cACnB,cAAc,KACvB,OAAM,OAAO,CAAC,cAAc,KAAK,CAAC;OAKlC,OAAM,OAHiB,OAAO,KAAK,OAAO,CAAC,KAAK,UAC9CC,UAAK,KAAKA,UAAK,SAAS,EAAE,MAAM,CACjC,CAC2B;YAGxB;AACR,yCAAsC;AACtC,SAAM,yBAAyB,iBAAiB;;;CAIpD,MAAM,OAAO,UAAU,UAAU;AAEjC,KAAI,gBACF,QAAO;EACL;EACA;EACA;EACA;EACA;EACD;AAGH,QAAO;EACL;EACA;EACA;EACA;EACD;;AAIH,SAAgB,mBAAmB,cAAuB,EAAE,EAAO;AAGjE,QAAO,CAAC,sBAAsB,aAAa,SAAS,CAAC"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { COMMENT_USE_STRICT_REGEX, CodeInjection, createComponentNameAnnotateHooks, createDebugIdUploadFunction, createSentryBuildPluginManager, generateModuleMetadataInjectorCode, generateReleaseInjectorCode, getDebugIdSnippet, globFiles, isJsFile, replaceBooleanFlagsInCode, sentryCliBinaryExists, shouldSkipCodeInjection, stringToUUID } from "@sentry/bundler-plugin-core";
|
|
3
3
|
import MagicString from "magic-string";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
-
|
|
6
5
|
//#region src/index.ts
|
|
7
6
|
function hasExistingDebugID(code) {
|
|
8
7
|
const chunkStartSnippet = code.slice(0, 6e3);
|
|
@@ -112,7 +111,7 @@ function _rollupPluginInternal(userOptions = {}, buildTool, buildToolMajorVersio
|
|
|
112
111
|
function sentryRollupPlugin(userOptions = {}) {
|
|
113
112
|
return [_rollupPluginInternal(userOptions, "rollup")];
|
|
114
113
|
}
|
|
115
|
-
|
|
116
114
|
//#endregion
|
|
117
115
|
export { _rollupPluginInternal, sentryCliBinaryExists, sentryRollupPlugin };
|
|
116
|
+
|
|
118
117
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n isJsFile,\n shouldSkipCodeInjection,\n Options,\n getDebugIdSnippet,\n stringToUUID,\n COMMENT_USE_STRICT_REGEX,\n createDebugIdUploadFunction,\n globFiles,\n createComponentNameAnnotateHooks,\n replaceBooleanFlagsInCode,\n CodeInjection,\n} from \"@sentry/bundler-plugin-core\";\nimport MagicString, { SourceMap } from \"magic-string\";\nimport type { TransformResult } from \"rollup\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\n\nfunction hasExistingDebugID(code: string): boolean {\n // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)\n const chunkStartSnippet = code.slice(0, 6000);\n const chunkEndSnippet = code.slice(-500);\n\n if (\n chunkStartSnippet.includes(\"_sentryDebugIdIdentifier\") ||\n chunkEndSnippet.includes(\"//# debugId=\")\n ) {\n return true; // Debug ID already present, skip injection\n }\n\n return false;\n}\n\nfunction getRollupMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Rollup already transpiles this for us\n const req = createRequire(import.meta.url);\n const rollup = req(\"rollup\") as { VERSION?: string };\n return rollup.VERSION?.split(\".\")[0];\n } catch (err) {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\n/**\n * @ignore - this is the internal plugin factory function only used for the Vite plugin!\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function _rollupPluginInternal(\n userOptions: Options = {},\n buildTool: \"rollup\" | \"vite\",\n buildToolMajorVersion?: string\n) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[sentry-${buildTool}-plugin]`,\n buildTool,\n buildToolMajorVersion: buildToolMajorVersion || getRollupMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n name: \"sentry-noop-plugin\",\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn(\n \"Running Sentry plugin from within a `node_modules` folder. Some features may not work.\"\n );\n }\n\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug(\n \"Release injection disabled via `release.inject` option. Will not inject release.\"\n );\n } else if (!options.release.name) {\n logger.debug(\n \"No release name provided. Will not inject release. Please set the `release.name` option to identify your release.\"\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n })\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n const transformAnnotations = options.reactComponentAnnotation?.enabled\n ? createComponentNameAnnotateHooks(\n options.reactComponentAnnotation?.ignoredComponents || [],\n !!options.reactComponentAnnotation?._experimentalInjectIntoHtml\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n const shouldTransform = transformAnnotations || transformReplace;\n\n function buildStart(): void {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n }\n\n async function transform(code: string, id: string): Promise<TransformResult> {\n // Component annotations are only in user code and boolean flag replacements are\n // only in Sentry code. If we successfully add annotations, we can return early.\n\n if (transformAnnotations?.transform) {\n const result = await transformAnnotations.transform(code, id);\n if (result) {\n return result;\n }\n }\n\n if (transformReplace) {\n return replaceBooleanFlagsInCode(code, replacementValues);\n }\n\n return null;\n }\n\n function renderChunk(\n code: string,\n chunk: { fileName: string; facadeModuleId?: string | null },\n _?: unknown,\n meta?: { magicString?: MagicString }\n ): {\n code: string;\n map?: SourceMap;\n } | null {\n if (!isJsFile(chunk.fileName)) {\n return null; // returning null means not modifying the chunk at all\n }\n\n // Skip empty chunks and HTML facade chunks (Vite MPA)\n if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {\n return null;\n }\n\n const injectCode = staticInjectionCode.clone();\n\n if (sourcemapsEnabled && !hasExistingDebugID(code)) {\n const debugId = stringToUUID(code); // generate a deterministic debug ID\n injectCode.append(getDebugIdSnippet(debugId));\n }\n\n if (injectCode.isEmpty()) {\n return null;\n }\n\n const ms = meta?.magicString || new MagicString(code, { filename: chunk.fileName });\n const match = code.match(COMMENT_USE_STRICT_REGEX)?.[0];\n\n if (match) {\n // Add injected code after any comments or \"use strict\" at the beginning of the bundle.\n ms.appendLeft(match.length, injectCode.code());\n } else {\n // ms.replace() doesn't work when there is an empty string match (which happens if\n // there is neither, a comment, nor a \"use strict\" at the top of the chunk) so we\n // need this special case here.\n ms.prepend(injectCode.code());\n }\n\n // Rolldown can pass a native MagicString instance in meta.magicString\n // https://rolldown.rs/in-depth/native-magic-string#usage-examples\n if (ms?.constructor?.name === \"BindingMagicString\") {\n // Rolldown docs say to return the magic string instance directly in this case\n return { code: ms as unknown as string };\n }\n\n return {\n code: ms.toString(),\n map: ms.generateMap({ file: chunk.fileName, hires: \"boundary\" as unknown as undefined }),\n };\n }\n\n async function writeBundle(\n outputOptions: { dir?: string; file?: string },\n bundle: { [fileName: string]: unknown }\n ): Promise<void> {\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (sourcemapsEnabled && options.sourcemaps?.disable !== \"disable-upload\") {\n if (outputOptions.dir) {\n const outputDir = outputOptions.dir;\n const JS_AND_MAP_PATTERNS = [\n \"/**/*.js\",\n \"/**/*.mjs\",\n \"/**/*.cjs\",\n \"/**/*.js.map\",\n \"/**/*.mjs.map\",\n \"/**/*.cjs.map\",\n ].map((q) => `${q}?(\\\\?*)?(#*)`); // We want to allow query and hash strings at the end of files\n const buildArtifacts = await globFiles(JS_AND_MAP_PATTERNS, { root: outputDir });\n await upload(buildArtifacts);\n } else if (outputOptions.file) {\n await upload([outputOptions.file]);\n } else {\n const buildArtifacts = Object.keys(bundle).map((asset) =>\n path.join(path.resolve(), asset)\n );\n await upload(buildArtifacts);\n }\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n }\n\n const name = `sentry-${buildTool}-plugin`;\n\n if (shouldTransform) {\n return {\n name,\n buildStart,\n transform,\n renderChunk,\n writeBundle,\n };\n }\n\n return {\n name,\n buildStart,\n renderChunk,\n writeBundle,\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any\nexport function sentryRollupPlugin(userOptions: Options = {}): any {\n // We return an array here so we don't break backwards compatibility with what\n // unplugin used to return\n return [_rollupPluginInternal(userOptions, \"rollup\")];\n}\n\nexport type { Options as SentryRollupPluginOptions } from \"@sentry/bundler-plugin-core\";\nexport { sentryCliBinaryExists } from \"@sentry/bundler-plugin-core\";\n"],"mappings":";;;;;;AAqBA,SAAS,mBAAmB,MAAuB;CAEjD,MAAM,oBAAoB,KAAK,MAAM,GAAG,IAAK;CAC7C,MAAM,kBAAkB,K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,CAAC,KAAK,MAAM,GAAG,EAAE,cAAc,EAC4B,EAAE,MAAM,WAAW,CAAC,CACpD;cACnB,cAAc,KACvB,OAAM,OAAO,CAAC,cAAc,KAAK,CAAC;OAKlC,OAAM,OAHiB,OAAO,KAAK,OAAO,CAAC,KAAK,UAC9C,KAAK,KAAK,KAAK,SAAS,EAAE,MAAM,CACjC,CAC2B;YAGxB;AACR,yCAAsC;AACtC,SAAM,yBAAyB,iBAAiB;;;CAIpD,MAAM,OAAO,UAAU,UAAU;AAEjC,KAAI,gBACF,QAAO;EACL;EACA;EACA;EACA;EACA;EACD;AAGH,QAAO;EACL;EACA;EACA;EACA;EACD;;AAIH,SAAgB,mBAAmB,cAAuB,EAAE,EAAO;AAGjE,QAAO,CAAC,sBAAsB,aAAa,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n isJsFile,\n shouldSkipCodeInjection,\n Options,\n getDebugIdSnippet,\n stringToUUID,\n COMMENT_USE_STRICT_REGEX,\n createDebugIdUploadFunction,\n globFiles,\n createComponentNameAnnotateHooks,\n replaceBooleanFlagsInCode,\n CodeInjection,\n} from \"@sentry/bundler-plugin-core\";\nimport MagicString, { SourceMap } from \"magic-string\";\nimport type { TransformResult } from \"rollup\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\n\nfunction hasExistingDebugID(code: string): boolean {\n // Check if a debug ID has already been injected to avoid duplicate injection (e.g. by another plugin or Sentry CLI)\n const chunkStartSnippet = code.slice(0, 6000);\n const chunkEndSnippet = code.slice(-500);\n\n if (\n chunkStartSnippet.includes(\"_sentryDebugIdIdentifier\") ||\n chunkEndSnippet.includes(\"//# debugId=\")\n ) {\n return true; // Debug ID already present, skip injection\n }\n\n return false;\n}\n\nfunction getRollupMajorVersion(): string | undefined {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Rollup already transpiles this for us\n const req = createRequire(import.meta.url);\n const rollup = req(\"rollup\") as { VERSION?: string };\n return rollup.VERSION?.split(\".\")[0];\n } catch (err) {\n // do nothing, we'll just not report a version\n }\n\n return undefined;\n}\n\n/**\n * @ignore - this is the internal plugin factory function only used for the Vite plugin!\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function _rollupPluginInternal(\n userOptions: Options = {},\n buildTool: \"rollup\" | \"vite\",\n buildToolMajorVersion?: string\n) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? `[sentry-${buildTool}-plugin]`,\n buildTool,\n buildToolMajorVersion: buildToolMajorVersion || getRollupMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n name: \"sentry-noop-plugin\",\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn(\n \"Running Sentry plugin from within a `node_modules` folder. Some features may not work.\"\n );\n }\n\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug(\n \"Release injection disabled via `release.inject` option. Will not inject release.\"\n );\n } else if (!options.release.name) {\n logger.debug(\n \"No release name provided. Will not inject release. Please set the `release.name` option to identify your release.\"\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n })\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n const transformAnnotations = options.reactComponentAnnotation?.enabled\n ? createComponentNameAnnotateHooks(\n options.reactComponentAnnotation?.ignoredComponents || [],\n !!options.reactComponentAnnotation?._experimentalInjectIntoHtml\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n const shouldTransform = transformAnnotations || transformReplace;\n\n function buildStart(): void {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n }\n\n async function transform(code: string, id: string): Promise<TransformResult> {\n // Component annotations are only in user code and boolean flag replacements are\n // only in Sentry code. If we successfully add annotations, we can return early.\n\n if (transformAnnotations?.transform) {\n const result = await transformAnnotations.transform(code, id);\n if (result) {\n return result;\n }\n }\n\n if (transformReplace) {\n return replaceBooleanFlagsInCode(code, replacementValues);\n }\n\n return null;\n }\n\n function renderChunk(\n code: string,\n chunk: { fileName: string; facadeModuleId?: string | null },\n _?: unknown,\n meta?: { magicString?: MagicString }\n ): {\n code: string;\n map?: SourceMap;\n } | null {\n if (!isJsFile(chunk.fileName)) {\n return null; // returning null means not modifying the chunk at all\n }\n\n // Skip empty chunks and HTML facade chunks (Vite MPA)\n if (shouldSkipCodeInjection(code, chunk.facadeModuleId)) {\n return null;\n }\n\n const injectCode = staticInjectionCode.clone();\n\n if (sourcemapsEnabled && !hasExistingDebugID(code)) {\n const debugId = stringToUUID(code); // generate a deterministic debug ID\n injectCode.append(getDebugIdSnippet(debugId));\n }\n\n if (injectCode.isEmpty()) {\n return null;\n }\n\n const ms = meta?.magicString || new MagicString(code, { filename: chunk.fileName });\n const match = code.match(COMMENT_USE_STRICT_REGEX)?.[0];\n\n if (match) {\n // Add injected code after any comments or \"use strict\" at the beginning of the bundle.\n ms.appendLeft(match.length, injectCode.code());\n } else {\n // ms.replace() doesn't work when there is an empty string match (which happens if\n // there is neither, a comment, nor a \"use strict\" at the top of the chunk) so we\n // need this special case here.\n ms.prepend(injectCode.code());\n }\n\n // Rolldown can pass a native MagicString instance in meta.magicString\n // https://rolldown.rs/in-depth/native-magic-string#usage-examples\n if (ms?.constructor?.name === \"BindingMagicString\") {\n // Rolldown docs say to return the magic string instance directly in this case\n return { code: ms as unknown as string };\n }\n\n return {\n code: ms.toString(),\n map: ms.generateMap({ file: chunk.fileName, hires: \"boundary\" as unknown as undefined }),\n };\n }\n\n async function writeBundle(\n outputOptions: { dir?: string; file?: string },\n bundle: { [fileName: string]: unknown }\n ): Promise<void> {\n try {\n await sentryBuildPluginManager.createRelease();\n\n if (sourcemapsEnabled && options.sourcemaps?.disable !== \"disable-upload\") {\n if (outputOptions.dir) {\n const outputDir = outputOptions.dir;\n const JS_AND_MAP_PATTERNS = [\n \"/**/*.js\",\n \"/**/*.mjs\",\n \"/**/*.cjs\",\n \"/**/*.js.map\",\n \"/**/*.mjs.map\",\n \"/**/*.cjs.map\",\n ].map((q) => `${q}?(\\\\?*)?(#*)`); // We want to allow query and hash strings at the end of files\n const buildArtifacts = await globFiles(JS_AND_MAP_PATTERNS, { root: outputDir });\n await upload(buildArtifacts);\n } else if (outputOptions.file) {\n await upload([outputOptions.file]);\n } else {\n const buildArtifacts = Object.keys(bundle).map((asset) =>\n path.join(path.resolve(), asset)\n );\n await upload(buildArtifacts);\n }\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n }\n\n const name = `sentry-${buildTool}-plugin`;\n\n if (shouldTransform) {\n return {\n name,\n buildStart,\n transform,\n renderChunk,\n writeBundle,\n };\n }\n\n return {\n name,\n buildStart,\n renderChunk,\n writeBundle,\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any\nexport function sentryRollupPlugin(userOptions: Options = {}): any {\n // We return an array here so we don't break backwards compatibility with what\n // unplugin used to return\n return [_rollupPluginInternal(userOptions, \"rollup\")];\n}\n\nexport type { Options as SentryRollupPluginOptions } from \"@sentry/bundler-plugin-core\";\nexport { sentryCliBinaryExists } from \"@sentry/bundler-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,YAAY,iBACvD,KAAI,cAAc,KAAK;IACrB,MAAM,YAAY,cAAc;AAUhC,UAAM,OADiB,MAAM,UARD;KAC1B;KACA;KACA;KACA;KACA;KACA;KACD,CAAC,KAAK,MAAM,GAAG,EAAE,cAAc,EAC4B,EAAE,MAAM,WAAW,CAAC,CACpD;cACnB,cAAc,KACvB,OAAM,OAAO,CAAC,cAAc,KAAK,CAAC;OAKlC,OAAM,OAHiB,OAAO,KAAK,OAAO,CAAC,KAAK,UAC9C,KAAK,KAAK,KAAK,SAAS,EAAE,MAAM,CACjC,CAC2B;YAGxB;AACR,yCAAsC;AACtC,SAAM,yBAAyB,iBAAiB;;;CAIpD,MAAM,OAAO,UAAU,UAAU;AAEjC,KAAI,gBACF,QAAO;EACL;EACA;EACA;EACA;EACA;EACD;AAGH,QAAO;EACL;EACA;EACA;EACA;EACD;;AAIH,SAAgB,mBAAmB,cAAuB,EAAE,EAAO;AAGjE,QAAO,CAAC,sBAAsB,aAAa,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/rollup-plugin",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Official Sentry Rollup plugin",
|
|
5
5
|
"repository": "git://github.com/getsentry/sentry-javascript-bundler-plugins.git",
|
|
6
6
|
"homepage": "https://github.com/getsentry/sentry-javascript-bundler-plugins/tree/main/packages/rollup-plugin",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"module": "dist/esm/index.mjs",
|
|
31
31
|
"types": "dist/types/index.d.ts",
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "premove ./out && run-p build:rollup build:types",
|
|
33
|
+
"build": "premove ./out && run-p build:rollup build:types && run-s build:npm",
|
|
34
34
|
"build:watch": "run-p build:rollup:watch build:types:watch",
|
|
35
35
|
"build:rollup": "rolldown --config rollup.config.mjs",
|
|
36
36
|
"build:rollup:watch": "rolldown --config rollup.config.mjs --watch --no-watch.clearScreen",
|
|
@@ -44,28 +44,30 @@
|
|
|
44
44
|
"clean:all": "run-p clean clean:deps",
|
|
45
45
|
"clean:build": "premove ./dist *.tgz",
|
|
46
46
|
"clean:deps": "premove node_modules",
|
|
47
|
-
"test": "
|
|
47
|
+
"test": "vitest run",
|
|
48
48
|
"lint": "eslint ./src ./test",
|
|
49
49
|
"prepack": "ts-node ./src/prepack.ts"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@sentry/bundler-plugin-core": "5.
|
|
53
|
-
"magic-string": "0.30.8"
|
|
52
|
+
"@sentry/bundler-plugin-core": "5.2.0",
|
|
53
|
+
"magic-string": "~0.30.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"rollup": ">=3.2.0"
|
|
57
57
|
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"rollup": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
58
63
|
"devDependencies": {
|
|
59
|
-
"@sentry-internal/eslint-config": "5.
|
|
60
|
-
"@sentry-internal/sentry-bundler-plugin-tsconfig": "5.
|
|
61
|
-
"@swc/core": "^1.2.205",
|
|
62
|
-
"@swc/jest": "^0.2.21",
|
|
63
|
-
"@types/jest": "^28.1.3",
|
|
64
|
+
"@sentry-internal/eslint-config": "5.2.0",
|
|
65
|
+
"@sentry-internal/sentry-bundler-plugin-tsconfig": "5.2.0",
|
|
64
66
|
"@types/node": "^18.6.3",
|
|
65
67
|
"eslint": "^8.18.0",
|
|
66
|
-
"
|
|
68
|
+
"vitest": "^4.0.0",
|
|
67
69
|
"premove": "^4.0.0",
|
|
68
|
-
"rolldown": "
|
|
70
|
+
"rolldown": "1.0.0-rc.10",
|
|
69
71
|
"ts-node": "^10.9.1",
|
|
70
72
|
"typescript": "^4.7.4"
|
|
71
73
|
},
|
|
@@ -73,6 +75,6 @@
|
|
|
73
75
|
"extends": "../../package.json"
|
|
74
76
|
},
|
|
75
77
|
"engines": {
|
|
76
|
-
"node": ">=
|
|
78
|
+
"node": ">= 18"
|
|
77
79
|
}
|
|
78
80
|
}
|