From c1fd0c23dfed674477aa77a05d53cd156c11278f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Fri, 4 Feb 2022 12:43:40 +0100 Subject: [PATCH] ref: Check if rawSource is available before use --- src/index.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/index.js b/src/index.js index c48bce65..5e4e6879 100644 --- a/src/index.js +++ b/src/index.js @@ -108,23 +108,29 @@ function attachAfterCodeGenerationHook(compiler, options) { compilation.hooks.afterCodeGeneration.tap('SentryCliPlugin', () => { compilation.modules.forEach(module => { // eslint-disable-next-line no-underscore-dangle - if (module._name !== moduleFederationPlugin._options.name) return; + if (module._name !== moduleFederationPlugin._options.name) { + return; + } + const sourceMap = compilation.codeGenerationResults.get(module) .sources; const rawSource = sourceMap.get('javascript'); - sourceMap.set( - 'javascript', - new RawSource( - `${rawSource.source()} -(function (){ -var globalThis = (typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}); -globalThis.SENTRY_RELEASES = globalThis.SENTRY_RELEASES || {}; -globalThis.SENTRY_RELEASES["${options.project}@${ - options.org - }"] = {"id":"${version}"}; -})();` - ) - ); + + if (rawSource) { + sourceMap.set( + 'javascript', + new RawSource( + `${rawSource.source()} + (function (){ + var globalThis = (typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}); + globalThis.SENTRY_RELEASES = globalThis.SENTRY_RELEASES || {}; + globalThis.SENTRY_RELEASES["${options.project}@${ + options.org + }"] = {"id":"${version}"}; + })();` + ) + ); + } }); }); cb();