Skip to content

Commit

Permalink
Fix node process compatibility (close #253)
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Jan 21, 2022
1 parent f349133 commit c2e488a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions server/build-npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,18 @@ esbuild:
// add nodejs/deno compatibility
if task.Target != "node" {
if bytes.Contains(outputContent, []byte("__Process$")) {
fmt.Fprintf(buf, `import __Process$ from "/v%d/node_process.js";%s__Process$.env.NODE_ENV="%s";%s`, task.BuildVersion, eol, nodeEnv, eol)
if task.Target == "deno" {
fmt.Fprintf(buf, `import __Process$ from "https://deno.land/std@%s/node/process.ts";%s__Process$.env.NODE_ENV="%s";%s`, denoStdNodeVersion, eol, nodeEnv, eol)
} else {
fmt.Fprintf(buf, `import __Process$ from "/v%d/node_process.js";%s__Process$.env.NODE_ENV="%s";%s`, task.BuildVersion, eol, nodeEnv, eol)
}
}
if bytes.Contains(outputContent, []byte("__Buffer$")) {
fmt.Fprintf(buf, `import { Buffer as __Buffer$ } from "/v%d/node_buffer.js";%s`, task.BuildVersion, eol)
if task.Target == "deno" {
fmt.Fprintf(buf, `import { Buffer as __Buffer$ } from "https://deno.land/std@%s/node/buffer.ts";%s`, denoStdNodeVersion, eol)
} else {
fmt.Fprintf(buf, `import { Buffer as __Buffer$ } from "/v%d/node_buffer.js";%s`, task.BuildVersion, eol)
}
}
if bytes.Contains(outputContent, []byte("__global$")) {
fmt.Fprintf(buf, `var __global$ = globalThis || (typeof window !== "undefined" ? window : self);%s`, eol)
Expand Down
6 changes: 4 additions & 2 deletions server/embed/polyfills/node_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
process.version = 'v16.13.1';
process.versions = {
node: '16.13.1'
};

function noop() { }

Expand Down

0 comments on commit c2e488a

Please sign in to comment.