Skip to content

Commit

Permalink
Switch to @cspotcode/source-map-support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot committed Dec 14, 2023
1 parent bdb011b commit ae8b919
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"resolve.exports": "^2.0.2",
"selfsigned": "^2.0.1",
"source-map": "0.6.1",
"source-map-support": "0.5.21",
"@cspotcode/source-map-support": "0.8.1",
"xxhash-wasm": "^1.0.1"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/scripts/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const EXTERNAL_DEPENDENCIES = [
// todo - bundle miniflare too
"selfsigned",
"source-map",
"@cspotcode/source-map-support", // Uses `module.require()`
"@esbuild-plugins/node-globals-polyfill",
"@esbuild-plugins/node-modules-polyfill",
"chokidar",
Expand Down
10 changes: 6 additions & 4 deletions packages/wrangler/src/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ function getSourceMappingPrepareStackTrace(): NonNullable<
// affecting external user's use of this package, and so
// `Error.prepareStackTrace` is always updated, load a fresh copy, by
// resetting then restoring the `require` cache.
const originalSupport = require.cache["source-map-support"];
delete require.cache["source-map-support"];
const originalSupport = require.cache["@cspotcode/source-map-support"];
delete require.cache["@cspotcode/source-map-support"];
// eslint-disable-next-line @typescript-eslint/consistent-type-imports,@typescript-eslint/no-var-requires
const support: typeof import("source-map-support") = require("source-map-support");
require.cache["source-map-support"] = originalSupport;
const support: typeof import("@cspotcode/source-map-support") = require("@cspotcode/source-map-support");
require.cache["@cspotcode/source-map-support"] = originalSupport;

const originalPrepareStackTrace = Error.prepareStackTrace;
support.install({
Expand All @@ -28,6 +28,7 @@ function getSourceMappingPrepareStackTrace(): NonNullable<
handleUncaughtExceptions: false,
// Don't hook Node `require` function
hookRequire: false,
redirectConflictingLibrary: false,
// Make sure we're using fresh copies of files each time we source map
emptyCacheBetweenOperations: true,
});
Expand Down Expand Up @@ -78,6 +79,7 @@ export function getSourceMappedString(value: string): string {
// the first instance. If they replace the value with itself, all instances
// of the call site would've been replaced with the same thing.
const callSiteLines = Array.from(value.matchAll(CALL_SITE_REGEXP));
console.log({ callSiteLines: callSiteLines.map((match) => match[0]) });
const callSites = callSiteLines.map(lineMatchToCallSite);
const sourceMappedStackTrace: string = getSourceMappingPrepareStackTrace()(
placeholderError,
Expand Down

0 comments on commit ae8b919

Please sign in to comment.