Rich-Harris / magic-string

Manipulate strings like a wizard
MIT License
2.34k stars 113 forks source link

service worker should be supported #258

Closed loynoir closed 1 year ago

loynoir commented 1 year ago

Env

service worker

Detail

> JSON.stringify([typeof window, typeof Buffer, typeof btoa, typeof self, typeof self.btoa, typeof globalThis.btoa])
 '["undefined","undefined","function","object","function","function"]' 

Actual

Got Error.

Unsupported environment: window.btoa or Buffer should be supported

Expected

service worker should be supported

loynoir commented 1 year ago

@antfu

Given

I suggest check Buffer first

if (typeof Buffer === "function") {
  // ...
} else if (typeof btoa === "function") {
  // ...
}
curran commented 9 months ago

It still fails as this logic was not updated:

https://github.com/Rich-Harris/magic-string/blob/master/src/SourceMap.js#L3