@sentry/remix
Version:
Official Sentry SDK for Remix
62 lines (58 loc) • 2.44 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const vite = require('@sentry/server-utils/orchestrion/vite');
const WORKER_RESOLVE_CONDITIONS = ["workerd", "worker"];
function isWorkerTarget(config) {
const ssr = config?.ssr;
if (ssr?.target === "webworker") {
return true;
}
return [ssr?.resolve?.conditions, ssr?.resolve?.externalConditions].some(
(conditions) => conditions?.some((condition) => WORKER_RESOLVE_CONDITIONS.includes(condition))
);
}
function hookHandler(hook) {
return typeof hook === "function" ? hook : hook?.handler;
}
function gateHook(hook, isDisabled) {
if (!hook) {
return hook;
}
const handler = hookHandler(hook);
const gated = function(...args) {
return isDisabled() ? null : handler.apply(this, args);
};
return typeof hook === "function" ? gated : { ...hook, handler: gated };
}
function makeOrchestrionPlugin(options) {
const orchestrion = vite.sentryOrchestrionPlugin({ buildTimeInstrumentation: options.buildTimeInstrumentation });
const { renderChunk } = orchestrion;
const config = hookHandler(orchestrion.config);
const configResolved = hookHandler(orchestrion.configResolved);
let isWorkerConfig = false;
let isWorkerBuild = false;
return {
...orchestrion,
// Upstream ships the plugin with `enforce: 'pre'`, which would run this hook before the
// framework plugins that set `ssr.target`. `order: 'post'` moves it after them.
config: {
order: "post",
handler(userConfig, env) {
isWorkerConfig = isWorkerTarget(userConfig);
return isWorkerConfig ? null : config?.(userConfig, env) ?? null;
}
},
// Gated on the worker check from the `config` hook, because Vite calls `configEnvironment`
// before `configResolved`.
configEnvironment: gateHook(orchestrion.configEnvironment, () => isWorkerConfig),
// The authoritative check: the resolved config reflects every plugin regardless of ordering,
// and this always runs before the first `transform`.
configResolved(resolvedConfig) {
isWorkerBuild = isWorkerTarget(resolvedConfig);
return isWorkerBuild ? void 0 : configResolved?.(resolvedConfig);
},
transform: gateHook(orchestrion.transform, () => isWorkerBuild),
renderChunk: gateHook(renderChunk, () => isWorkerBuild)
};
}
exports.makeOrchestrionPlugin = makeOrchestrionPlugin;
//# sourceMappingURL=orchestrionPlugin.js.map