Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent global namespace clash for Buffer #535

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>)