Skip to content

Commit

Permalink
fix: prevent global namespace clash for Buffer (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Nov 15, 2023
1 parent 786c995 commit e2a787f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
11 changes: 7 additions & 4 deletions node/npm_dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,19 @@ const safelyDetectTypes = async (packageJsonPath: string): Promise<string | unde
// Workaround for https://github.com/evanw/esbuild/issues/1921.
const banner = {
js: `
import process from "node:process";
import {setImmediate, clearImmediate} from "node:timers";
import {Buffer} from "node:buffer";
import __nfyProcess from "node:process";
import {setImmediate as __nfySetImmediate, clearImmediate as __nfyClearImmediate} from "node:timers";
import {Buffer as __nfyBuffer} from "node:buffer";
import {createRequire as ___nfyCreateRequire} from "node:module";
import {fileURLToPath as ___nfyFileURLToPath} from "node:url";
import {dirname as ___nfyPathDirname} from "node:path";
let __filename=___nfyFileURLToPath(import.meta.url);
let __dirname=___nfyPathDirname(___nfyFileURLToPath(import.meta.url));
let require=___nfyCreateRequire(import.meta.url);
globalThis.process = __nfyProcess;
globalThis.setImmediate = __nfySetImmediate;
globalThis.clearImmediate = __nfyClearImmediate;
globalThis.Buffer = __nfyBuffer;
`,
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions test/fixtures/tsx/functions/func1.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import React from 'react'

export default () => {
try {
// this is expected to fail
process.env.FOO
} catch {
return new Response(<p>Hello World</p>)
}
}
export default () => new Response(<p>Hello World</p>)

0 comments on commit e2a787f

Please sign in to comment.