a submodule for cross-runtime environment utility functions.

the functions in this submodule do not place a "hard" dependency on the runtime environments. instead, the various runtime-globals are defined as "soft" objects/symbols which may or may not exist. as a result, some of the functions (such as getRuntime) are very weakly/generically typed, and their results are not narrowed based on your input arguments. the advantage of such is that this submodule will not choke your LSP. not to mention that you'll probably be aware of what runtime you're working with anyway, so you can always use the as assertions to confine the return value to a certain runtime's feature.

for most functions in here, you will need to provide the RUNTIME enum that you are querying for.

to identify your script's current RUNTIME environment, you'd want to use the identifyCurrentRuntime function.

TODO: additional features to add in the future:

  • [x] filesystem read/writing on system runtimes (deno, bun, and node).
  • [ ] filesystem read/writing on web/extension runtimes will use the browser's FileAccess API (and prompt the user to select the folder)
  • [ ] filesystem read/writing on web/extension runtimes will use window.navigator.storage.getDirectory(). and for web workers, we may use self.navigator.storage.getDirectory() instead.
  • [ ] persistent key-value storage: such as localStorage or sessionStorage or chrome.storage.sync or kv-storage of window.navigator.storage.persist(). copy these from your github-aid browser extension project.
  • [x] system environment variables.
  • [ ] shell/commandline/terminal command execution.
  • [ ] (breaking change) consider using a class based approach to calling these functions as methods, where the currently selected runtime will be known by the class instance, so that the user will not have to pass down which runtime they are querying for all the time.
  • [ ] (RISKY) add a setEnvVariable function. but it may corrupt the user's variables if they're not careful, so I don't want to implement it unless I find myself needing it.

Enumerations

RUNTIME

Interfaces

ExecShellCommandConfig
ExecShellCommandResult
WriteFileConfig
ReadFileConfig

Variables

currentRuntimeValidationFnMap

Functions

identifyCurrentRuntime
getRuntime
getRuntimeCwd
getEnvVariable
execShellCommand
writeTextFile
writeFile
readTextFile
readFile