Skip to content

Question: how can the values provided by process.platform and process.arch better reflect the underlying system #1236

Open
@lovell

Description

@lovell

Thank you for all your work on WebContainers, they are really exciting technology. My thoughts below are about (hopefully) making the use of native modules slightly easier for the multiple parties involved.

The value currently provided by process.arch is always x64 and the value provided by process.platform is always linux.

According to lovell/sharp#3750 (comment) "WebContainers specifically aims to comply with Linux behavior", however from what can tell, WebContainers do not expose or provide any underlying Linux APIs.

It looks like at least one other person has been confused and has questioned this, e.g. #1095 states unexpected behaviour: "...reports Linux x64 rather than the expected WASM"

Many native dependencies are either using or are migrating to the use of optionalDependencies with os and cpu filters to tell package managers to download only the relevant binaries. In the case of WebContainers, the current values on the process global would imply the installation of a package and therefore native binary that defines the following filters:

  "os": [
    "linux"
  ],
  "cpu": [
    "x64"
  ]

The current approach to deal with this appears to be that package maintainers should include custom logic via @webcontainer/env or that end-users must add Wasm-specific dependencies, or that StackBlitz will automagically polyfill certain dependencies.

I feel like some consensus could be reached here around more appropriate values for process.platform and process.arch to allow Node.js compatible WebAssembly runtimes to work with existing package manager logic rather than against it, and that perhaps StackBlitz could be able to lead this.

Here's a very quick worked example (and it is only an example). Let's say process.platform is wasm and process.arch is 32. A maintainer of a native package might then be able to include the following in a published package.json file to make it explicit that this is the relevant package to install and use with a Wasm32 runtime.

  "os": [
    "wasm"
  ],
  "cpu": [
    "32"
  ]

The underlying aim for this question/discussion is an attempt to make life easier for StackBlitz (you can start to remove polyfills), make life easier for end-users (no manually-added Wasm-specific dependencies) and make life easier for package maintainers (the method already used for platform-specific binaries will "just work"). Thank you for reading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions