File tree Expand file tree Collapse file tree 3 files changed +58
-2
lines changed
Expand file tree Collapse file tree 3 files changed +58
-2
lines changed Original file line number Diff line number Diff line change 77 "scripts" : {
88 "dev" : " wxt" ,
99 "dev:firefox" : " wxt -b firefox" ,
10- "build" : " wxt build && pnpm run build:rewriter && pnpm run build:plugins && pnpm run build:readme" ,
10+ "build" : " wxt build && pnpm run build:rewrite && pnpm run build:plugins && pnpm run build:readme" ,
1111 "build:firefox" : " wxt build -b firefox" ,
12- "build:rewrite" : " esbuild ./rewrite/figma.ts --outfile=./dist/figma.js --bundle --format=esm " ,
12+ "build:rewrite" : " esbuild ./rewrite/figma.ts --outfile=./dist/figma.js --bundle --format=iife " ,
1313 "build:plugins" : " tsc -p ./plugins/tsconfig.json" ,
1414 "build:readme" : " tsx ./build/readme.ts" ,
1515 "npm:plugins" : " pnpm build:plugins && cd plugins && pnpm publish --access public && cd .." ,
Original file line number Diff line number Diff line change 11import { matchFile , REWRITE_PATTERN , REWRITE_REPLACER } from './config'
2+ import { patchErrorStack } from './patch'
3+
4+ patchErrorStack ( )
25
36async function rewriteScript ( ) {
47 const current = document . currentScript as HTMLScriptElement
Original file line number Diff line number Diff line change 1+ const EXT_SCHEMES = / (?: c h r o m e | m o z ) - e x t e n s i o n : \/ \/ / g
2+ const PATCHED = Symbol ( )
3+
4+ function sanitizeStack ( text : string = '' ) {
5+ return text . replace ( EXT_SCHEMES , '' )
6+ }
7+
8+ export function patchErrorStack ( ) {
9+ if ( ( globalThis as any ) [ PATCHED ] ) return
10+
11+ const NativeError = globalThis . Error
12+
13+ function Error ( ...args : any [ ] ) {
14+ const error = new NativeError ( ...args )
15+
16+ if ( typeof NativeError . captureStackTrace === 'function' ) {
17+ NativeError . captureStackTrace ( error , Error )
18+ }
19+
20+ let rawStack
21+ try {
22+ rawStack = error . stack
23+ } catch { }
24+
25+ if ( typeof rawStack === 'string' ) {
26+ let stored = rawStack
27+ Object . defineProperty ( error , 'stack' , {
28+ configurable : true ,
29+ enumerable : false ,
30+ get ( ) {
31+ return sanitizeStack ( stored )
32+ } ,
33+ set ( v ) {
34+ stored = v
35+ }
36+ } )
37+ }
38+
39+ return error
40+ }
41+
42+ Object . setPrototypeOf ( Error , NativeError )
43+ Error . prototype = NativeError . prototype
44+
45+ globalThis . Error = Error as ErrorConstructor
46+
47+ Object . defineProperty ( globalThis , PATCHED , {
48+ value : true ,
49+ writable : false ,
50+ enumerable : false ,
51+ configurable : false
52+ } )
53+ }
You can’t perform that action at this time.
0 commit comments