Skip to main content

NODE_OS_STUB

Constant NODE_OS_STUB 

Source
pub const NODE_OS_STUB: &str = r#"
// ESM-compatible stub for node:os

export function platform() {
  try {
    const os = globalThis.Deno?.build?.os;
    if (os === 'darwin') return 'darwin';
    if (os === 'linux') return 'linux';
    if (os === 'windows') return 'win32';
    return 'linux';
  } catch {
    return 'linux';
  }
}

export function arch() {
  try {
    const a = globalThis.Deno?.build?.arch;
    if (a === 'x86_64') return 'x64';
    if (a === 'aarch64') return 'arm64';
    return 'x64';
  } catch {
    return 'x64';
  }
}

export function type() {
  try {
    const os = globalThis.Deno?.build?.os;
    if (os === 'darwin') return 'Darwin';
    if (os === 'linux') return 'Linux';
    if (os === 'windows') return 'Windows_NT';
    return 'Linux';
  } catch {
    return 'Linux';
  }
}

export function homedir() {
  try {
    return globalThis.Deno?.env?.get('HOME') || globalThis.Deno?.env?.get('USERPROFILE') || '/';
  } catch {
    return '/';
  }
}

export function tmpdir() {
  try {
    return globalThis.Deno?.env?.get('TMPDIR') || globalThis.Deno?.env?.get('TMP') || '/tmp';
  } catch {
    return '/tmp';
  }
}

export const EOL = '\n';

export default { platform, arch, type, homedir, tmpdir, EOL };
export const __esModule = true;
"#;