Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
220 lines
10 KiB
Plaintext
220 lines
10 KiB
Plaintext
'use strict';
|
|
|
|
var bundlerPluginCore = require('@sentry/bundler-plugin-core');
|
|
var node_module = require('node:module');
|
|
var path = require('path');
|
|
var uuid = require('uuid');
|
|
|
|
function _interopNamespace(e) {
|
|
if (e && e.__esModule) return e;
|
|
var n = Object.create(null);
|
|
if (e) {
|
|
Object.keys(e).forEach(function (k) {
|
|
if (k !== 'default') {
|
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
Object.defineProperty(n, k, d.get ? d : {
|
|
enumerable: true,
|
|
get: function () { return e[k]; }
|
|
});
|
|
}
|
|
});
|
|
}
|
|
n["default"] = e;
|
|
return Object.freeze(n);
|
|
}
|
|
|
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
|
|
function ownKeys(object, enumerableOnly) {
|
|
var keys = Object.keys(object);
|
|
if (Object.getOwnPropertySymbols) {
|
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
})), keys.push.apply(keys, symbols);
|
|
}
|
|
return keys;
|
|
}
|
|
function _objectSpread2(target) {
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
var source = null != arguments[i] ? arguments[i] : {};
|
|
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
_defineProperty(target, key, source[key]);
|
|
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
});
|
|
}
|
|
return target;
|
|
}
|
|
function _defineProperty(obj, key, value) {
|
|
key = _toPropertyKey(key);
|
|
if (key in obj) {
|
|
Object.defineProperty(obj, key, {
|
|
value: value,
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true
|
|
});
|
|
} else {
|
|
obj[key] = value;
|
|
}
|
|
return obj;
|
|
}
|
|
function _toPrimitive(input, hint) {
|
|
if (typeof input !== "object" || input === null) return input;
|
|
var prim = input[Symbol.toPrimitive];
|
|
if (prim !== undefined) {
|
|
var res = prim.call(input, hint || "default");
|
|
if (typeof res !== "object") return res;
|
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
}
|
|
return (hint === "string" ? String : Number)(input);
|
|
}
|
|
function _toPropertyKey(arg) {
|
|
var key = _toPrimitive(arg, "string");
|
|
return typeof key === "symbol" ? key : String(key);
|
|
}
|
|
|
|
// since webpack 5.1 compiler contains webpack module so plugins always use correct webpack version
|
|
// https://github.com/webpack/webpack/commit/65eca2e529ce1d79b79200d4bdb1ce1b81141459
|
|
function webpackInjectionPlugin(UnsafeBannerPlugin) {
|
|
return function (injectionCode, debugIds) {
|
|
return {
|
|
name: "sentry-webpack-injection-plugin",
|
|
webpack: function webpack(compiler) {
|
|
var _compiler$webpack;
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore webpack version compatibility shenanigans
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
var BannerPlugin =
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore webpack version compatibility shenanigans
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
(compiler === null || compiler === void 0 ? void 0 : (_compiler$webpack = compiler.webpack) === null || _compiler$webpack === void 0 ? void 0 : _compiler$webpack.BannerPlugin) || UnsafeBannerPlugin;
|
|
compiler.options.plugins = compiler.options.plugins || [];
|
|
compiler.options.plugins.push(
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
|
|
new BannerPlugin({
|
|
raw: true,
|
|
include: /\.(js|ts|jsx|tsx|mjs|cjs)(\?[^?]*)?(#[^#]*)?$/,
|
|
banner: function banner(arg) {
|
|
var codeToInject = injectionCode.clone();
|
|
if (debugIds) {
|
|
var _arg$chunk$contentHas, _arg$chunk, _arg$chunk$contentHas2, _arg$chunk2;
|
|
var hash = (_arg$chunk$contentHas = arg === null || arg === void 0 ? void 0 : (_arg$chunk = arg.chunk) === null || _arg$chunk === void 0 ? void 0 : (_arg$chunk$contentHas2 = _arg$chunk.contentHash) === null || _arg$chunk$contentHas2 === void 0 ? void 0 : _arg$chunk$contentHas2.javascript) !== null && _arg$chunk$contentHas !== void 0 ? _arg$chunk$contentHas : arg === null || arg === void 0 ? void 0 : (_arg$chunk2 = arg.chunk) === null || _arg$chunk2 === void 0 ? void 0 : _arg$chunk2.hash;
|
|
var debugId = hash ? bundlerPluginCore.stringToUUID(hash) : uuid.v4();
|
|
codeToInject.append(bundlerPluginCore.getDebugIdSnippet(debugId));
|
|
}
|
|
return codeToInject.code();
|
|
}
|
|
}));
|
|
}
|
|
};
|
|
};
|
|
}
|
|
function webpackComponentNameAnnotatePlugin() {
|
|
return function (ignoredComponents, injectIntoHtml) {
|
|
return {
|
|
name: "sentry-webpack-component-name-annotate-plugin",
|
|
enforce: "pre",
|
|
// Webpack needs this hook for loader logic, so the plugin is not run on unsupported file types
|
|
transformInclude: function transformInclude(id) {
|
|
return id.endsWith(".tsx") || id.endsWith(".jsx");
|
|
},
|
|
transform: bundlerPluginCore.createComponentNameAnnotateHooks(ignoredComponents, injectIntoHtml).transform
|
|
};
|
|
};
|
|
}
|
|
function webpackBundleSizeOptimizationsPlugin(UnsafeDefinePlugin) {
|
|
return function (replacementValues) {
|
|
return {
|
|
name: "sentry-webpack-bundle-size-optimizations-plugin",
|
|
webpack: function webpack(compiler) {
|
|
var _compiler$webpack2;
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore webpack version compatibility shenanigans
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
var DefinePlugin =
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore webpack version compatibility shenanigans
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
(compiler === null || compiler === void 0 ? void 0 : (_compiler$webpack2 = compiler.webpack) === null || _compiler$webpack2 === void 0 ? void 0 : _compiler$webpack2.DefinePlugin) || UnsafeDefinePlugin;
|
|
compiler.options.plugins = compiler.options.plugins || [];
|
|
compiler.options.plugins.push(
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
|
|
new DefinePlugin(_objectSpread2({}, replacementValues)));
|
|
}
|
|
};
|
|
};
|
|
}
|
|
function webpackDebugIdUploadPlugin(upload, logger, createDependencyOnBuildArtifacts, forceExitOnBuildCompletion) {
|
|
var pluginName = "sentry-webpack-debug-id-upload-plugin";
|
|
return {
|
|
name: pluginName,
|
|
webpack: function webpack(compiler) {
|
|
var freeGlobalDependencyOnDebugIdSourcemapArtifacts = createDependencyOnBuildArtifacts();
|
|
compiler.hooks.afterEmit.tapAsync(pluginName, function (compilation, callback) {
|
|
var _ref;
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
var outputPath = (_ref = compilation.outputOptions.path) !== null && _ref !== void 0 ? _ref : path__namespace.resolve();
|
|
var buildArtifacts = Object.keys(compilation.assets).map(function (asset) {
|
|
return path__namespace.join(outputPath, asset);
|
|
});
|
|
void upload(buildArtifacts).then(function () {
|
|
callback();
|
|
})["finally"](function () {
|
|
freeGlobalDependencyOnDebugIdSourcemapArtifacts();
|
|
});
|
|
});
|
|
if (forceExitOnBuildCompletion && compiler.options.mode === "production") {
|
|
compiler.hooks.done.tap(pluginName, function () {
|
|
setTimeout(function () {
|
|
logger.debug("Exiting process after debug file upload");
|
|
process.exit(0);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
// Detect webpack major version for telemetry (helps differentiate webpack 4 vs 5 usage)
|
|
function getWebpackMajorVersion() {
|
|
try {
|
|
var _webpack$version, _webpack$default;
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore - Rollup already transpiles this for us
|
|
var req = node_module.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT' && document.currentScript.src || new URL('webpack4and5.js', document.baseURI).href)));
|
|
var webpack = req("webpack");
|
|
var version = (_webpack$version = webpack === null || webpack === void 0 ? void 0 : webpack.version) !== null && _webpack$version !== void 0 ? _webpack$version : webpack === null || webpack === void 0 ? void 0 : (_webpack$default = webpack["default"]) === null || _webpack$default === void 0 ? void 0 : _webpack$default.version;
|
|
var webpackMajorVersion = version === null || version === void 0 ? void 0 : version.split(".")[0]; // "4" or "5"
|
|
return webpackMajorVersion;
|
|
} catch (error) {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* The factory function accepts BannerPlugin and DefinePlugin classes in
|
|
* order to avoid direct dependencies on webpack.
|
|
*
|
|
* This allow us to export version of the plugin for webpack 5.1+ and compatible environments.
|
|
*
|
|
* Since webpack 5.1 compiler contains webpack module so plugins always use correct webpack version.
|
|
*/
|
|
function sentryWebpackUnpluginFactory() {
|
|
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
BannerPlugin = _ref2.BannerPlugin,
|
|
DefinePlugin = _ref2.DefinePlugin;
|
|
return bundlerPluginCore.sentryUnpluginFactory({
|
|
injectionPlugin: webpackInjectionPlugin(BannerPlugin),
|
|
componentNameAnnotatePlugin: webpackComponentNameAnnotatePlugin(),
|
|
debugIdUploadPlugin: webpackDebugIdUploadPlugin,
|
|
bundleSizeOptimizationsPlugin: webpackBundleSizeOptimizationsPlugin(DefinePlugin),
|
|
getBundlerMajorVersion: getWebpackMajorVersion
|
|
});
|
|
}
|
|
|
|
exports.sentryWebpackUnpluginFactory = sentryWebpackUnpluginFactory;
|
|
//# sourceMappingURL=webpack4and5.js.map
|