@sentry/remix
Version:
Official Sentry SDK for Remix
57 lines (54 loc) • 2.06 kB
JavaScript
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import { createLoadHookTransform } from '@sentry/server-utils/orchestrion/load-hook';
import { remixV3Config } from '@sentry/server-utils/orchestrion/config';
function orchestrionLoader(dcModuleUrl) {
const cached = loaders.get(dcModuleUrl);
if (cached) {
return cached;
}
const transform = createLoadHookTransform({ dcModule: dcModuleUrl, instrumentations: remixV3Config });
const loader = (url, context, nextLoad) => {
const result = nextLoad(url, context);
if (result.format !== "module" || typeof result.source !== "string") {
return result;
}
try {
const transformed = transform(fileURLToPath(url), result.source);
return transformed === void 0 ? result : { ...result, source: transformed };
} catch {
return result;
}
};
loaders.set(dcModuleUrl, loader);
return loader;
}
const loaders = /* @__PURE__ */ new Map();
function isOrchestrionLoader(loader) {
for (const known of loaders.values()) {
if (known === loader) {
return true;
}
}
return false;
}
function getShimUrl(basePath, rootDir, mounts, shimPath) {
const nodeModulesRoot = path.join(rootDir, "node_modules");
const relativePath = path.relative(nodeModulesRoot, shimPath);
if (relativePath.startsWith("..") || path.isAbsolute(relativePath)) {
return void 0;
}
const encoded = relativePath.split(path.sep).map((segment) => encodeURIComponent(segment)).join("/");
return `${basePath.replace(/\/$/, "")}/${npmMount(mounts)}/${encoded}`;
}
function npmMount(mounts) {
const entry = mounts && Object.entries(mounts).find(([, dir]) => dir === "node_modules" || dir === "./node_modules");
return entry ? entry[0] : "npm";
}
function resolveShimPath() {
let here;
here = fileURLToPath(import.meta.url);
return path.join(path.dirname(here), "client", "diagnosticsChannelShim.js");
}
export { getShimUrl, isOrchestrionLoader, orchestrionLoader, resolveShimPath };
//# sourceMappingURL=orchestrionLoader.js.map