@sentry/remix
Version:
Official Sentry SDK for Remix
62 lines (58 loc) • 2.21 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const path = require('node:path');
const node_url = require('node:url');
const loadHook = require('@sentry/server-utils/orchestrion/load-hook');
const config = require('@sentry/server-utils/orchestrion/config');
function orchestrionLoader(dcModuleUrl) {
const cached = loaders.get(dcModuleUrl);
if (cached) {
return cached;
}
const transform = loadHook.createLoadHookTransform({ dcModule: dcModuleUrl, instrumentations: config.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(node_url.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 = __filename;
return path.join(path.dirname(here), "client", "diagnosticsChannelShim.js");
}
exports.getShimUrl = getShimUrl;
exports.isOrchestrionLoader = isOrchestrionLoader;
exports.orchestrionLoader = orchestrionLoader;
exports.resolveShimPath = resolveShimPath;
//# sourceMappingURL=orchestrionLoader.js.map