@sentry/webpack-plugin 1.17.3 → 1.18.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/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/index.js +67 -0
- package/src/sentry.loader.js +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
- "Would I rather be feared or loved? Easy. Both. I want people to be afraid of
|
|
6
6
|
how much they love me." — Michael Scott
|
|
7
7
|
|
|
8
|
+
## v1.18.0
|
|
9
|
+
|
|
10
|
+
- feat: Add support for multiple apps using Webpack Module Federation (#307)
|
|
11
|
+
|
|
8
12
|
## v1.17.3
|
|
9
13
|
|
|
10
14
|
- fix: Switch compilation type in error handler to `unknown` (#322)
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -74,6 +74,63 @@ function attachAfterEmitHook(compiler, callback) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
function attachAfterCodeGenerationHook(compiler, options) {
|
|
78
|
+
if (!compiler.hooks || !compiler.hooks.make) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let webpackSources;
|
|
83
|
+
try {
|
|
84
|
+
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
|
|
85
|
+
webpackSources = require('webpack-sources');
|
|
86
|
+
} catch (_e) {
|
|
87
|
+
console.warn(
|
|
88
|
+
'Coud not resolve package: webpack-sources. Skipping injection for the remote entry file.'
|
|
89
|
+
);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const { RawSource } = webpackSources;
|
|
94
|
+
const moduleFederationPlugin =
|
|
95
|
+
compiler.options &&
|
|
96
|
+
compiler.options.plugins &&
|
|
97
|
+
compiler.options.plugins.find(
|
|
98
|
+
x => x.constructor.name === 'ModuleFederationPlugin'
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
if (!moduleFederationPlugin) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
compiler.hooks.make.tapAsync('SentryCliPlugin', (compilation, cb) => {
|
|
106
|
+
options.releasePromise.then(version => {
|
|
107
|
+
compilation.hooks.afterCodeGeneration.tap('SentryCliPlugin', () => {
|
|
108
|
+
compilation.modules.forEach(module => {
|
|
109
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
110
|
+
if (module._name !== moduleFederationPlugin._options.name) return;
|
|
111
|
+
const sourceMap = compilation.codeGenerationResults.get(module)
|
|
112
|
+
.sources;
|
|
113
|
+
const rawSource = sourceMap.get('javascript');
|
|
114
|
+
sourceMap.set(
|
|
115
|
+
'javascript',
|
|
116
|
+
new RawSource(
|
|
117
|
+
`${rawSource.source()}
|
|
118
|
+
(function (){
|
|
119
|
+
var globalThis = (typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {});
|
|
120
|
+
globalThis.SENTRY_RELEASES = globalThis.SENTRY_RELEASES || {};
|
|
121
|
+
globalThis.SENTRY_RELEASES["${options.project}@${
|
|
122
|
+
options.org
|
|
123
|
+
}"] = {"id":"${version}"};
|
|
124
|
+
})();`
|
|
125
|
+
)
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
cb();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
77
134
|
class SentryCliPlugin {
|
|
78
135
|
constructor(options = {}) {
|
|
79
136
|
const defaults = {
|
|
@@ -318,6 +375,8 @@ class SentryCliPlugin {
|
|
|
318
375
|
loader: SENTRY_LOADER,
|
|
319
376
|
options: {
|
|
320
377
|
releasePromise: this.release,
|
|
378
|
+
org: this.options.org || process.env.SENTRY_ORG,
|
|
379
|
+
project: this.options.project || process.env.SENTRY_PROJECT,
|
|
321
380
|
},
|
|
322
381
|
};
|
|
323
382
|
|
|
@@ -333,6 +392,8 @@ class SentryCliPlugin {
|
|
|
333
392
|
loader: SENTRY_LOADER,
|
|
334
393
|
options: {
|
|
335
394
|
releasePromise: this.release,
|
|
395
|
+
org: this.options.org || process.env.SENTRY_ORG,
|
|
396
|
+
project: this.options.project || process.env.SENTRY_PROJECT,
|
|
336
397
|
},
|
|
337
398
|
},
|
|
338
399
|
],
|
|
@@ -501,6 +562,12 @@ class SentryCliPlugin {
|
|
|
501
562
|
this.injectRelease(compilerOptions);
|
|
502
563
|
}
|
|
503
564
|
|
|
565
|
+
attachAfterCodeGenerationHook(compiler, {
|
|
566
|
+
releasePromise: this.release,
|
|
567
|
+
org: this.options.org || process.env.SENTRY_ORG,
|
|
568
|
+
project: this.options.project || process.env.SENTRY_PROJECT,
|
|
569
|
+
});
|
|
570
|
+
|
|
504
571
|
attachAfterEmitHook(compiler, (compilation, cb) => {
|
|
505
572
|
if (!this.options.include || !this.options.include.length) {
|
|
506
573
|
ensure(compilerOptions, 'output', Object);
|
package/src/sentry.loader.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
module.exports = function sentryLoader(content, map, meta) {
|
|
2
|
-
const { releasePromise } = this.query;
|
|
2
|
+
const { releasePromise, org, project } = this.query;
|
|
3
3
|
const callback = this.async();
|
|
4
4
|
releasePromise.then(version => {
|
|
5
|
-
|
|
5
|
+
let sentryRelease = `const _global = (typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}); _global.SENTRY_RELEASE={id:"${version}"};`;
|
|
6
|
+
if (project) {
|
|
7
|
+
const key = org ? `${project}@${org}` : project;
|
|
8
|
+
sentryRelease += `
|
|
9
|
+
_global.SENTRY_RELEASES=_global.SENTRY_RELEASES || {};
|
|
10
|
+
_global.SENTRY_RELEASES["${key}"]={id:"${version}"};
|
|
11
|
+
`;
|
|
12
|
+
}
|
|
6
13
|
callback(null, sentryRelease, map, meta);
|
|
7
14
|
});
|
|
8
15
|
};
|