mirror of https://github.com/pyodide/pyodide.git
Support `bun` (#4916)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
parent
262f1c4a85
commit
c03b2dcd02
|
@ -225,6 +225,36 @@ jobs:
|
|||
paths: "test-results/*.xml"
|
||||
if: always()
|
||||
|
||||
test-bun:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
needs: [build-core]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Download build artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: core-build-${{ runner.os }}
|
||||
path: ./dist/
|
||||
|
||||
- uses: oven-sh/setup-bun@v1
|
||||
|
||||
- name: install test requirements
|
||||
working-directory: src/test-bun
|
||||
run: |
|
||||
bun --version
|
||||
bun install
|
||||
|
||||
- name: run bun tests
|
||||
working-directory: src/test-bun
|
||||
run: bun smoke-test.js
|
||||
|
||||
test-deno:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
|
|
|
@ -262,6 +262,10 @@ export async function calculateDirname(): Promise<string> {
|
|||
}
|
||||
let fileName = ErrorStackParser.parse(err)[0].fileName!;
|
||||
|
||||
if (IN_NODE && !fileName.startsWith("file://")) {
|
||||
fileName = `file://${fileName}`; // Error stack filenames are not starting with `file://` in `Bun`
|
||||
}
|
||||
|
||||
if (IN_NODE_ESM) {
|
||||
const nodePath = await import("node:path");
|
||||
const nodeUrl = await import("node:url");
|
||||
|
|
|
@ -5,8 +5,7 @@ export const IN_NODE =
|
|||
typeof process === "object" &&
|
||||
typeof process.versions === "object" &&
|
||||
typeof process.versions.node === "string" &&
|
||||
typeof process.browser ===
|
||||
"undefined"; /* This last condition checks if we run the browser shim of process */
|
||||
!process.browser; /* This last condition checks if we run the browser shim of process */
|
||||
|
||||
/** @private */
|
||||
export const IN_NODE_COMMONJS =
|
||||
|
@ -19,6 +18,9 @@ export const IN_NODE_COMMONJS =
|
|||
/** @private */
|
||||
export const IN_NODE_ESM = IN_NODE && !IN_NODE_COMMONJS;
|
||||
|
||||
/** @private */
|
||||
export const IN_BUN = typeof globalThis.Bun !== "undefined";
|
||||
|
||||
/** @private */
|
||||
export const IN_DENO = typeof Deno !== "undefined"; // just in case...
|
||||
|
||||
|
@ -55,6 +57,7 @@ export function detectEnvironment(): Record<string, boolean> {
|
|||
IN_NODE: IN_NODE,
|
||||
IN_NODE_COMMONJS: IN_NODE_COMMONJS,
|
||||
IN_NODE_ESM: IN_NODE_ESM,
|
||||
IN_BUN: IN_BUN,
|
||||
IN_DENO: IN_DENO,
|
||||
IN_BROWSER: IN_BROWSER,
|
||||
IN_BROWSER_MAIN_THREAD: IN_BROWSER_MAIN_THREAD,
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "test-bun",
|
||||
"module": "smoke-test.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "bun --watch smoke-test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"pyodide": "../../dist/"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import { loadPyodide } from "pyodide";
|
||||
|
||||
console.time("[load pyodide]");
|
||||
const pyodide = await loadPyodide();
|
||||
console.timeEnd("[load pyodide]");
|
||||
|
||||
console.time("[run pyodide]");
|
||||
const result = await pyodide.runPythonAsync(`
|
||||
3+4
|
||||
`);
|
||||
console.timeEnd("[run pyodide]");
|
||||
|
||||
console.log("result:", result.toString());
|
Loading…
Reference in New Issue