diff --git a/packages/bundler-plugin-core/package.json b/packages/bundler-plugin-core/package.json index 46255342..90c1c6e9 100644 --- a/packages/bundler-plugin-core/package.json +++ b/packages/bundler-plugin-core/package.json @@ -58,8 +58,7 @@ "dotenv": "^16.3.1", "find-up": "^5.0.0", "glob": "^10.5.0", - "magic-string": "0.30.8", - "unplugin": "1.0.1" + "magic-string": "0.30.8" }, "devDependencies": { "@babel/preset-env": "7.18.2", diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index 4a3758c7..4009360d 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -6,214 +6,7 @@ import SentryCli from "@sentry/cli"; import { logger } from "@sentry/utils"; import * as fs from "fs"; import { glob } from "glob"; -import { createUnplugin, TransformResult, UnpluginInstance, UnpluginOptions } from "unplugin"; -import { createSentryBuildPluginManager } from "./build-plugin-manager"; -import { createDebugIdUploadFunction } from "./debug-id-upload"; -import { Logger } from "./logger"; -import { Options, SentrySDKBuildFlags } from "./types"; -import { - CodeInjection, - containsOnlyImports, - generateReleaseInjectorCode, - generateModuleMetadataInjectorCode, - stripQueryAndHashFromPath, -} from "./utils"; - -type InjectionPlugin = ( - injectionCode: CodeInjection, - debugIds: boolean, - logger: Logger -) => UnpluginOptions; -type LegacyPlugins = { - releaseInjectionPlugin: (injectionCode: string) => UnpluginOptions; - moduleMetadataInjectionPlugin: (injectionCode: string) => UnpluginOptions; - debugIdInjectionPlugin: (logger: Logger) => UnpluginOptions; -}; - -interface SentryUnpluginFactoryOptions { - injectionPlugin: InjectionPlugin | LegacyPlugins; - componentNameAnnotatePlugin?: ( - ignoredComponents: string[], - injectIntoHtml: boolean - ) => UnpluginOptions; - debugIdUploadPlugin: ( - upload: (buildArtifacts: string[]) => Promise, - logger: Logger, - createDependencyOnBuildArtifacts: () => () => void, - webpack_forceExitOnBuildComplete?: boolean - ) => UnpluginOptions; - bundleSizeOptimizationsPlugin: (buildFlags: SentrySDKBuildFlags) => UnpluginOptions; - getBundlerMajorVersion?: () => string | undefined; -} - -/** - * Creates an unplugin instance used to create Sentry plugins for Vite, Rollup, esbuild, and Webpack. - */ -export function sentryUnpluginFactory({ - injectionPlugin, - componentNameAnnotatePlugin, - debugIdUploadPlugin, - bundleSizeOptimizationsPlugin, - getBundlerMajorVersion, -}: SentryUnpluginFactoryOptions): UnpluginInstance { - return createUnplugin((userOptions = {}, unpluginMetaContext) => { - const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, { - loggerPrefix: - userOptions._metaOptions?.loggerPrefixOverride ?? - `[sentry-${unpluginMetaContext.framework}-plugin]`, - buildTool: unpluginMetaContext.framework, - buildToolMajorVersion: getBundlerMajorVersion?.(), - }); - - const { - logger, - normalizedOptions: options, - bundleSizeOptimizationReplacementValues, - } = sentryBuildPluginManager; - - if (options.disable) { - return [ - { - name: "sentry-noop-plugin", - }, - ]; - } - - if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) { - logger.warn( - "Running Sentry plugin from within a `node_modules` folder. Some features may not work." - ); - } - - const plugins: UnpluginOptions[] = []; - - // Add plugin to emit a telemetry signal when the build starts - plugins.push({ - name: "sentry-telemetry-plugin", - buildStart() { - // Technically, for very fast builds we might miss the telemetry signal - // but it's okay because telemetry is not critical for us. - // We cannot await the flush here because it would block the build start - // which in turn would break module federation builds, see - // https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/816 - void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => { - // Nothing for the users to do here. If telemetry fails it's acceptable. - }); - }, - }); - - if (Object.keys(bundleSizeOptimizationReplacementValues).length > 0) { - plugins.push(bundleSizeOptimizationsPlugin(bundleSizeOptimizationReplacementValues)); - } - - const injectionCode = new CodeInjection(); - - if (!options.release.inject) { - logger.debug( - "Release injection disabled via `release.inject` option. Will not inject release." - ); - } else if (!options.release.name) { - logger.debug( - "No release name provided. Will not inject release. Please set the `release.name` option to identify your release." - ); - } else { - const code = generateReleaseInjectorCode({ - release: options.release.name, - injectBuildInformation: options._experiments.injectBuildInformation || false, - }); - if (typeof injectionPlugin !== "function") { - plugins.push(injectionPlugin.releaseInjectionPlugin(code.code())); - } else { - injectionCode.append(code); - } - } - - if (Object.keys(sentryBuildPluginManager.bundleMetadata).length > 0) { - const code = generateModuleMetadataInjectorCode(sentryBuildPluginManager.bundleMetadata); - if (typeof injectionPlugin !== "function") { - plugins.push(injectionPlugin.moduleMetadataInjectionPlugin(code.code())); - } else { - injectionCode.append(code); - } - } - - if ( - typeof injectionPlugin === "function" && - (!injectionCode.isEmpty() || options.sourcemaps?.disable !== true) - ) { - plugins.push(injectionPlugin(injectionCode, options.sourcemaps?.disable !== true, logger)); - } - - // Add plugin to create and finalize releases, and also take care of adding commits and legacy sourcemaps - const freeGlobalDependencyOnBuildArtifacts = - sentryBuildPluginManager.createDependencyOnBuildArtifacts(); - plugins.push({ - name: "sentry-release-management-plugin", - async writeBundle() { - try { - await sentryBuildPluginManager.createRelease(); - } finally { - freeGlobalDependencyOnBuildArtifacts(); - } - }, - }); - - if (options.sourcemaps?.disable !== true) { - if (typeof injectionPlugin !== "function") { - plugins.push(injectionPlugin.debugIdInjectionPlugin(logger)); - } - - if (options.sourcemaps?.disable !== "disable-upload") { - // This option is only strongly typed for the webpack plugin, where it is used. It has no effect on other plugins - const webpack_forceExitOnBuildComplete = - typeof options._experiments["forceExitOnBuildCompletion"] === "boolean" - ? options._experiments["forceExitOnBuildCompletion"] - : undefined; - - plugins.push( - debugIdUploadPlugin( - createDebugIdUploadFunction({ - sentryBuildPluginManager, - }), - logger, - sentryBuildPluginManager.createDependencyOnBuildArtifacts, - webpack_forceExitOnBuildComplete - ) - ); - } - } - - if (options.reactComponentAnnotation) { - if (!options.reactComponentAnnotation.enabled) { - logger.debug( - "The component name annotate plugin is currently disabled. Skipping component name annotations." - ); - } else if (options.reactComponentAnnotation.enabled && !componentNameAnnotatePlugin) { - logger.warn( - "The component name annotate plugin is currently not supported by '@sentry/esbuild-plugin'" - ); - } else { - componentNameAnnotatePlugin && - plugins.push( - componentNameAnnotatePlugin( - options.reactComponentAnnotation.ignoredComponents || [], - !!options.reactComponentAnnotation._experimentalInjectIntoHtml - ) - ); - } - } - - // Add plugin to delete unwanted artifacts like source maps after the uploads have completed - plugins.push({ - name: "sentry-file-deletion-plugin", - async writeBundle() { - await sentryBuildPluginManager.deleteArtifacts(); - }, - }); - - return plugins; - }); -} +import { CodeInjection, containsOnlyImports, stripQueryAndHashFromPath } from "./utils"; /** * Determines whether the Sentry CLI binary is in its expected location. @@ -283,18 +76,17 @@ export function globFiles(outputDir: string): Promise { ); } +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function createComponentNameAnnotateHooks( ignoredComponents: string[], injectIntoHtml: boolean -): { - transform: UnpluginOptions["transform"]; -} { +) { type ParserPlugins = NonNullable< NonNullable[1]>["parserOpts"] >["plugins"]; return { - async transform(this: void, code: string, id: string): Promise { + async transform(this: void, code: string, id: string) { // id may contain query and hash which will trip up our file extension logic below const idWithoutQueryAndHash = stripQueryAndHashFromPath(id); diff --git a/packages/bundler-plugin-core/test/index.test.ts b/packages/bundler-plugin-core/test/index.test.ts index 2b56d984..45cf107d 100644 --- a/packages/bundler-plugin-core/test/index.test.ts +++ b/packages/bundler-plugin-core/test/index.test.ts @@ -1,5 +1,4 @@ -import { Compiler } from "webpack"; -import { getDebugIdSnippet, sentryUnpluginFactory } from "../src"; +import { getDebugIdSnippet } from "../src"; import { containsOnlyImports } from "../src/utils"; describe("getDebugIdSnippet", () => { @@ -141,175 +140,3 @@ app.mount('#app'); }); }); }); - -describe("sentryUnpluginFactory sourcemaps.disable behavior", () => { - const mockComponentNameAnnotatePlugin = jest.fn(() => ({ - name: "mock-component-name-annotate-plugin", - })); - - const mockInjectionPlugin = jest.fn(() => ({ - name: "mock-injection-plugin", - })); - - const mockDebugIdUploadPlugin = jest.fn(() => ({ - name: "mock-debug-id-upload-plugin", - })); - - const mockBundleSizeOptimizationsPlugin = jest.fn(() => ({ - name: "mock-bundle-size-optimizations-plugin", - })); - - const createUnpluginInstance = (): ReturnType => { - return sentryUnpluginFactory({ - injectionPlugin: mockInjectionPlugin, - componentNameAnnotatePlugin: mockComponentNameAnnotatePlugin, - debugIdUploadPlugin: mockDebugIdUploadPlugin, - bundleSizeOptimizationsPlugin: mockBundleSizeOptimizationsPlugin, - }); - }; - - beforeEach(() => { - jest.clearAllMocks(); - }); - - describe("when sourcemaps.disable is true", () => { - it("should not include debug ID injection or upload plugins", () => { - const unpluginInstance = createUnpluginInstance(); - - const plugins = unpluginInstance.raw( - { - authToken: "test-token", - org: "test-org", - project: "test-project", - sourcemaps: { - disable: true, - }, - }, - { framework: "webpack", webpack: { compiler: {} as Compiler } } - ); - - const pluginNames = plugins.map((plugin) => plugin.name); - - // Should not include debug ID related plugins - expect(pluginNames).not.toContain("mock-debug-id-injection-plugin"); - expect(pluginNames).not.toContain("mock-debug-id-upload-plugin"); - - // Should still include other core plugins - expect(pluginNames).toContain("sentry-telemetry-plugin"); - expect(pluginNames).toContain("sentry-release-management-plugin"); - expect(pluginNames).toContain("sentry-file-deletion-plugin"); - }); - }); - - describe('when sourcemaps.disable is "disable-upload"', () => { - it("should include debug ID injection plugin but not upload plugin", () => { - const unpluginInstance = createUnpluginInstance(); - - const plugins = unpluginInstance.raw( - { - authToken: "test-token", - org: "test-org", - project: "test-project", - sourcemaps: { - disable: "disable-upload", - }, - }, - { framework: "webpack", webpack: { compiler: {} as Compiler } } - ); - - const pluginNames = plugins.map((plugin) => plugin.name); - - // Should include debug ID injection but not upload - expect(pluginNames).toContain("mock-injection-plugin"); - expect(pluginNames).not.toContain("mock-debug-id-upload-plugin"); - - // Should still include other core plugins - expect(pluginNames).toContain("sentry-telemetry-plugin"); - expect(pluginNames).toContain("sentry-release-management-plugin"); - expect(pluginNames).toContain("sentry-file-deletion-plugin"); - }); - }); - - describe("when sourcemaps.disable is false", () => { - it("should include both debug ID injection and upload plugins", () => { - const unpluginInstance = createUnpluginInstance(); - - const plugins = unpluginInstance.raw( - { - authToken: "test-token", - org: "test-org", - project: "test-project", - sourcemaps: { - disable: false, - }, - }, - { framework: "webpack", webpack: { compiler: {} as Compiler } } - ); - - const pluginNames = plugins.map((plugin) => plugin.name); - - // Should include both debug ID related plugins - expect(pluginNames).toContain("mock-injection-plugin"); - expect(pluginNames).toContain("mock-debug-id-upload-plugin"); - - // Should include other core plugins - expect(pluginNames).toContain("sentry-telemetry-plugin"); - expect(pluginNames).toContain("sentry-release-management-plugin"); - expect(pluginNames).toContain("sentry-file-deletion-plugin"); - }); - }); - - describe("when sourcemaps.disable is undefined (default)", () => { - it("should include both debug ID injection and upload plugins", () => { - const unpluginInstance = createUnpluginInstance(); - - const plugins = unpluginInstance.raw( - { - authToken: "test-token", - org: "test-org", - project: "test-project", - // sourcemaps.disable not specified (undefined) - }, - { framework: "webpack", webpack: { compiler: {} as Compiler } } - ); - - const pluginNames = plugins.map((plugin) => plugin.name); - - // Should include both debug ID related plugins by default - expect(pluginNames).toContain("mock-injection-plugin"); - expect(pluginNames).toContain("mock-debug-id-upload-plugin"); - - // Should include other core plugins - expect(pluginNames).toContain("sentry-telemetry-plugin"); - expect(pluginNames).toContain("sentry-release-management-plugin"); - expect(pluginNames).toContain("sentry-file-deletion-plugin"); - }); - }); - - describe("when entire sourcemaps option is undefined", () => { - it("should include both debug ID injection and upload plugins", () => { - const unpluginInstance = createUnpluginInstance(); - - const plugins = unpluginInstance.raw( - { - authToken: "test-token", - org: "test-org", - project: "test-project", - // sourcemaps option not specified at all - }, - { framework: "webpack", webpack: { compiler: {} as Compiler } } - ); - - const pluginNames = plugins.map((plugin) => plugin.name); - - // Should include both debug ID related plugins by default - expect(pluginNames).toContain("mock-injection-plugin"); - expect(pluginNames).toContain("mock-debug-id-upload-plugin"); - - // Should include other core plugins - expect(pluginNames).toContain("sentry-telemetry-plugin"); - expect(pluginNames).toContain("sentry-release-management-plugin"); - expect(pluginNames).toContain("sentry-file-deletion-plugin"); - }); - }); -}); diff --git a/packages/e2e-tests/utils/create-cjs-bundles.ts b/packages/e2e-tests/utils/create-cjs-bundles.ts index ebd55151..c66cdd45 100644 --- a/packages/e2e-tests/utils/create-cjs-bundles.ts +++ b/packages/e2e-tests/utils/create-cjs-bundles.ts @@ -14,9 +14,9 @@ import { sentryRollupPlugin } from "@sentry/rollup-plugin"; export function createCjsBundles( entrypoints: { [name: string]: string }, outFolder: string, - sentryUnpluginOptions: Options + sentryPluginOptions: Options ): void { - if (!sentryUnpluginOptions.release) { + if (!sentryPluginOptions.release) { console.error("Config has no release set, aborting"); return; } @@ -36,11 +36,11 @@ export function createCjsBundles( }, plugins: [ sentryVitePlugin({ - ...sentryUnpluginOptions, + ...sentryPluginOptions, release: { - name: `${sentryUnpluginOptions.release.name!}-vite`, + name: `${sentryPluginOptions.release.name!}-vite`, uploadLegacySourcemaps: `${ - sentryUnpluginOptions.release.uploadLegacySourcemaps as string + sentryPluginOptions.release.uploadLegacySourcemaps as string }/vite`, }, }), @@ -52,11 +52,11 @@ export function createCjsBundles( input: entrypoints, plugins: [ sentryRollupPlugin({ - ...sentryUnpluginOptions, + ...sentryPluginOptions, release: { - name: `${sentryUnpluginOptions.release.name!}-rollup`, + name: `${sentryPluginOptions.release.name!}-rollup`, uploadLegacySourcemaps: `${ - sentryUnpluginOptions.release.uploadLegacySourcemaps as string + sentryPluginOptions.release.uploadLegacySourcemaps as string }/rollup`, }, }), @@ -77,11 +77,11 @@ export function createCjsBundles( sourcemap: true, plugins: [ sentryEsbuildPlugin({ - ...sentryUnpluginOptions, + ...sentryPluginOptions, release: { - name: `${sentryUnpluginOptions.release.name!}-esbuild`, + name: `${sentryPluginOptions.release.name!}-esbuild`, uploadLegacySourcemaps: `${ - sentryUnpluginOptions.release.uploadLegacySourcemaps as string + sentryPluginOptions.release.uploadLegacySourcemaps as string }/esbuild`, }, }), @@ -104,11 +104,11 @@ export function createCjsBundles( target: "node", // needed for webpack 4 so we can access node api plugins: [ sentryWebpackPlugin({ - ...sentryUnpluginOptions, + ...sentryPluginOptions, release: { - name: `${sentryUnpluginOptions.release.name!}-webpack4`, + name: `${sentryPluginOptions.release.name!}-webpack4`, uploadLegacySourcemaps: `${ - sentryUnpluginOptions.release.uploadLegacySourcemaps as string + sentryPluginOptions.release.uploadLegacySourcemaps as string }/webpack4`, }, }), @@ -135,11 +135,11 @@ export function createCjsBundles( mode: "production", plugins: [ sentryWebpackPlugin({ - ...sentryUnpluginOptions, + ...sentryPluginOptions, release: { - name: `${sentryUnpluginOptions.release.name!}-webpack5`, + name: `${sentryPluginOptions.release.name!}-webpack5`, uploadLegacySourcemaps: `${ - sentryUnpluginOptions.release.uploadLegacySourcemaps as string + sentryPluginOptions.release.uploadLegacySourcemaps as string }/webpack5`, }, }), diff --git a/packages/esbuild-plugin/test/public-api.test.ts b/packages/esbuild-plugin/test/public-api.test.ts index a428c8be..c9408006 100644 --- a/packages/esbuild-plugin/test/public-api.test.ts +++ b/packages/esbuild-plugin/test/public-api.test.ts @@ -1,5 +1,5 @@ -import { EsbuildPlugin } from "unplugin"; import { sentryEsbuildPlugin } from "../src"; +import { Plugin } from "esbuild"; test("Esbuild plugin should exist", () => { expect(sentryEsbuildPlugin).toBeDefined(); @@ -8,13 +8,13 @@ test("Esbuild plugin should exist", () => { describe("sentryEsbuildPlugin", () => { it("returns an esbuild plugin", () => { - const plugins = sentryEsbuildPlugin({ + const plugin = sentryEsbuildPlugin({ authToken: "test-token", org: "test-org", project: "test-project", - }) as EsbuildPlugin; + }) as Plugin; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - expect(plugins).toEqual({ name: "sentry-esbuild-plugin", setup: expect.any(Function) }); + expect(plugin).toEqual({ name: "sentry-esbuild-plugin", setup: expect.any(Function) }); }); }); diff --git a/packages/integration-tests/utils/create-cjs-bundles-for-react.ts b/packages/integration-tests/utils/create-cjs-bundles-for-react.ts index 757708e9..095784e8 100644 --- a/packages/integration-tests/utils/create-cjs-bundles-for-react.ts +++ b/packages/integration-tests/utils/create-cjs-bundles-for-react.ts @@ -22,7 +22,7 @@ const nodejsMajorversion = process.version.split(".")[0]!.slice(1); export function createCjsBundles( entrypoints: { [name: string]: string }, outFolder: string, - sentryUnpluginOptions: Options, + sentryPluginOptions: Options, plugins: string[] = [] ): void { if (plugins.length === 0 || plugins.includes("vite")) { @@ -38,7 +38,7 @@ export function createCjsBundles( }, }, }, - plugins: [react({ jsxRuntime: "automatic" }), sentryVitePlugin(sentryUnpluginOptions)], + plugins: [react({ jsxRuntime: "automatic" }), sentryVitePlugin(sentryPluginOptions)], }); } if (plugins.length === 0 || plugins.includes("rollup")) { @@ -50,7 +50,7 @@ export function createCjsBundles( extensions: RESOLVABLE_EXTENSIONS, }), commonjs(), - sentryRollupPlugin(sentryUnpluginOptions), + sentryRollupPlugin(sentryPluginOptions), babelPlugin({ babelHelpers: "bundled", presets: [["@babel/preset-react", { runtime: "automatic" }]], @@ -71,7 +71,7 @@ export function createCjsBundles( void esbuild.build({ entryPoints: entrypoints, outdir: path.join(outFolder, "esbuild"), - plugins: [sentryEsbuildPlugin(sentryUnpluginOptions)], + plugins: [sentryEsbuildPlugin(sentryPluginOptions)], minify: true, bundle: true, jsx: "automatic", @@ -111,7 +111,7 @@ export function createCjsBundles( ], }, target: "node", // needed for webpack 4 so we can access node api - plugins: [sentryWebpackPlugin(sentryUnpluginOptions)], + plugins: [sentryWebpackPlugin(sentryPluginOptions)], }, handleWebpack ); @@ -149,7 +149,7 @@ export function createCjsBundles( }, ], }, - plugins: [sentryWebpackPlugin(sentryUnpluginOptions)], + plugins: [sentryWebpackPlugin(sentryPluginOptions)], }, handleWebpack ); diff --git a/packages/integration-tests/utils/create-cjs-bundles-with-query.ts b/packages/integration-tests/utils/create-cjs-bundles-with-query.ts index b3c065ed..59b54994 100644 --- a/packages/integration-tests/utils/create-cjs-bundles-with-query.ts +++ b/packages/integration-tests/utils/create-cjs-bundles-with-query.ts @@ -14,7 +14,7 @@ const nodejsMajorVersion = process.version.split(".")[0]!.slice(1); export function createCjsBundlesWithQueryParam( entrypoints: { [name: string]: string }, outFolder: string, - sentryUnpluginOptions: Options, + sentryPluginOptions: Options, plugins: string[] = [] ): void { if (plugins.length === 0 || plugins.includes("vite")) { @@ -31,14 +31,14 @@ export function createCjsBundlesWithQueryParam( }, }, }, - plugins: [sentryVitePlugin(sentryUnpluginOptions)], + plugins: [sentryVitePlugin(sentryPluginOptions)], }); } if (plugins.length === 0 || plugins.includes("rollup")) { void rollup .rollup({ input: entrypoints, - plugins: [sentryRollupPlugin(sentryUnpluginOptions)], + plugins: [sentryRollupPlugin(sentryPluginOptions)], }) .then((bundle) => bundle.write({ @@ -69,7 +69,7 @@ export function createCjsBundlesWithQueryParam( libraryTarget: "commonjs", }, target: "node", // needed for webpack 4 so we can access node api - plugins: [sentryWebpackPlugin(sentryUnpluginOptions)], + plugins: [sentryWebpackPlugin(sentryPluginOptions)], }, (err) => { if (err) { @@ -93,7 +93,7 @@ export function createCjsBundlesWithQueryParam( }, }, mode: "production", - plugins: [sentryWebpackPlugin(sentryUnpluginOptions)], + plugins: [sentryWebpackPlugin(sentryPluginOptions)], }, (err) => { if (err) { diff --git a/packages/integration-tests/utils/create-cjs-bundles.ts b/packages/integration-tests/utils/create-cjs-bundles.ts index bc60ce2b..631fa288 100644 --- a/packages/integration-tests/utils/create-cjs-bundles.ts +++ b/packages/integration-tests/utils/create-cjs-bundles.ts @@ -17,7 +17,7 @@ type Bundlers = "webpack4" | "webpack5" | "esbuild" | "rollup" | "vite" | string export function createCjsBundles( entrypoints: { [name: string]: string }, outFolder: string, - sentryUnpluginOptions: Options, + sentryPluginOptions: Options, plugins: Bundlers[] = [] ): void { if (plugins.length === 0 || plugins.includes("vite")) { @@ -34,7 +34,7 @@ export function createCjsBundles( }, }, }, - plugins: [sentryVitePlugin(sentryUnpluginOptions)], + plugins: [sentryVitePlugin(sentryPluginOptions)], }); } @@ -42,7 +42,7 @@ export function createCjsBundles( void rollup .rollup({ input: entrypoints, - plugins: [sentryRollupPlugin(sentryUnpluginOptions)], + plugins: [sentryRollupPlugin(sentryPluginOptions)], }) .then((bundle) => bundle.write({ @@ -59,7 +59,7 @@ export function createCjsBundles( sourcemap: true, entryPoints: entrypoints, outdir: path.join(outFolder, "esbuild"), - plugins: [sentryEsbuildPlugin(sentryUnpluginOptions)], + plugins: [sentryEsbuildPlugin(sentryPluginOptions)], minify: true, bundle: true, format: "cjs", @@ -80,7 +80,7 @@ export function createCjsBundles( filename: "[name].js?[contenthash]", }, target: "node", // needed for webpack 4 so we can access node api - plugins: [sentryWebpackPlugin(sentryUnpluginOptions)], + plugins: [sentryWebpackPlugin(sentryPluginOptions)], }, (err) => { if (err) { @@ -103,7 +103,7 @@ export function createCjsBundles( }, }, mode: "production", - plugins: [sentryWebpackPlugin(sentryUnpluginOptions)], + plugins: [sentryWebpackPlugin(sentryPluginOptions)], }, (err) => { if (err) { diff --git a/packages/rollup-plugin/src/index.ts b/packages/rollup-plugin/src/index.ts index 902051cd..3ae57bc7 100644 --- a/packages/rollup-plugin/src/index.ts +++ b/packages/rollup-plugin/src/index.ts @@ -15,7 +15,7 @@ import { CodeInjection, } from "@sentry/bundler-plugin-core"; import MagicString, { SourceMap } from "magic-string"; -import type { TransformHook } from "rollup"; +import type { TransformResult } from "rollup"; import * as path from "node:path"; import { createRequire } from "node:module"; @@ -125,14 +125,12 @@ export function _rollupPluginInternal( }); } - function transform(code: string, id: string): ReturnType { + async function transform(code: string, id: string): Promise { // Component annotations are only in user code and boolean flag replacements are // only in Sentry code. If we successfully add annotations, we can return early. if (transformAnnotations?.transform) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore TS complains about 'this' - const result = transformAnnotations.transform(code, id); + const result = await transformAnnotations.transform(code, id); if (result) { return result; } diff --git a/yarn.lock b/yarn.lock index 4c0e8a6e..cb4861b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3334,7 +3334,19 @@ "@types/source-list-map" "*" source-map "^0.7.3" -"@types/webpack4@npm:@types/webpack@^4", "@types/webpack@npm:@types/webpack@^4": +"@types/webpack4@npm:@types/webpack@^4": + version "4.41.33" + resolved "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.33.tgz#16164845a5be6a306bcbe554a8e67f9cac215ffc" + integrity sha512-PPajH64Ft2vWevkerISMtnZ8rTs4YmRbs+23c402J0INmxDKCrhZNvwZYtzx96gY2wAtXdrK1BS2fiC8MlLr3g== + dependencies: + "@types/node" "*" + "@types/tapable" "^1" + "@types/uglify-js" "*" + "@types/webpack-sources" "*" + anymatch "^3.0.0" + source-map "^0.6.0" + +"@types/webpack@npm:@types/webpack@^4": version "4.41.33" resolved "https://registry.npmjs.org/@types/webpack/-/webpack-4.41.33.tgz#16164845a5be6a306bcbe554a8e67f9cac215ffc" integrity sha512-PPajH64Ft2vWevkerISMtnZ8rTs4YmRbs+23c402J0INmxDKCrhZNvwZYtzx96gY2wAtXdrK1BS2fiC8MlLr3g== @@ -3960,7 +3972,7 @@ acorn@^7.1.1: resolved "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== -acorn@^8.2.4, acorn@^8.4.1, acorn@^8.5.0, acorn@^8.7.1, acorn@^8.8.0, acorn@^8.8.1: +acorn@^8.2.4, acorn@^8.4.1, acorn@^8.5.0, acorn@^8.7.1, acorn@^8.8.0: version "8.8.2" resolved "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a" integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw== @@ -4884,7 +4896,7 @@ chokidar@^2.1.8: optionalDependencies: fsevents "^1.2.7" -chokidar@^3.4.1, chokidar@^3.5.1, chokidar@^3.5.3: +chokidar@^3.4.1, chokidar@^3.5.1: version "3.5.3" resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== @@ -12101,7 +12113,16 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -12183,7 +12204,14 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -12833,16 +12861,6 @@ unpipe@1.0.0, unpipe@~1.0.0: resolved "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" integrity sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ== -unplugin@1.0.1: - version "1.0.1" - resolved "https://registry.npmjs.org/unplugin/-/unplugin-1.0.1.tgz#83b528b981cdcea1cad422a12cd02e695195ef3f" - integrity sha512-aqrHaVBWW1JVKBHmGo33T5TxeL0qWzfvjWokObHA9bYmN7eNDkwOxmLjhioHl9878qDFMAaT51XNroRyuz7WxA== - dependencies: - acorn "^8.8.1" - chokidar "^3.5.3" - webpack-sources "^3.2.3" - webpack-virtual-modules "^0.5.0" - unset-value@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559" @@ -13110,12 +13128,7 @@ webpack-sources@^3.2.3: resolved "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== -webpack-virtual-modules@^0.5.0: - version "0.5.0" - resolved "https://registry.npmjs.org/webpack-virtual-modules/-/webpack-virtual-modules-0.5.0.tgz#362f14738a56dae107937ab98ea7062e8bdd3b6c" - integrity sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw== - -"webpack4@npm:webpack@4.46.0", "webpack4@npm:webpack@^4", "webpack@npm:webpack@^4": +"webpack4@npm:webpack@4.46.0", "webpack4@npm:webpack@^4": version "4.46.0" resolved "https://registry.npmjs.org/webpack/-/webpack-4.46.0.tgz#bf9b4404ea20a073605e0a011d188d77cb6ad542" integrity sha512-6jJuJjg8znb/xRItk7bkT0+Q7AHCYjjFnvKIWQPkNIOyRqoCGvkOs0ipeQzrqz4l5FtN5ZI/ukEHroeX/o1/5Q== @@ -13204,6 +13217,35 @@ webpack-virtual-modules@^0.5.0: watchpack "^2.4.0" webpack-sources "^3.2.3" +"webpack@npm:webpack@^4": + version "4.46.0" + resolved "https://registry.npmjs.org/webpack/-/webpack-4.46.0.tgz#bf9b4404ea20a073605e0a011d188d77cb6ad542" + integrity sha512-6jJuJjg8znb/xRItk7bkT0+Q7AHCYjjFnvKIWQPkNIOyRqoCGvkOs0ipeQzrqz4l5FtN5ZI/ukEHroeX/o1/5Q== + dependencies: + "@webassemblyjs/ast" "1.9.0" + "@webassemblyjs/helper-module-context" "1.9.0" + "@webassemblyjs/wasm-edit" "1.9.0" + "@webassemblyjs/wasm-parser" "1.9.0" + acorn "^6.4.1" + ajv "^6.10.2" + ajv-keywords "^3.4.1" + chrome-trace-event "^1.0.2" + enhanced-resolve "^4.5.0" + eslint-scope "^4.0.3" + json-parse-better-errors "^1.0.2" + loader-runner "^2.4.0" + loader-utils "^1.2.3" + memory-fs "^0.4.1" + micromatch "^3.1.10" + mkdirp "^0.5.3" + neo-async "^2.6.1" + node-libs-browser "^2.2.1" + schema-utils "^1.0.0" + tapable "^1.1.3" + terser-webpack-plugin "^1.4.3" + watchpack "^1.7.4" + webpack-sources "^1.4.1" + whatwg-encoding@^1.0.5: version "1.0.5" resolved "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-1.0.5.tgz#5abacf777c32166a51d085d6b4f3e7d27113ddb0" @@ -13301,7 +13343,16 @@ worker-farm@^1.7.0: dependencies: errno "~0.1.7" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": + version "7.0.0" + resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + +wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==