diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index feb04e4bd684..592b49087eac 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,7 +13,13 @@ jobs: - name: Build package working-directory: src/js - run: bun build pyodide.ts --outdir=dist --sourcemap=linked + run: | + mkdir -p generated + cp ../core/*.ts ./generated/ + sed -i 's@../js/@../@g' ./generated/error_handling.ts + sed -i 's@from "types"@from "../types"@g' ./generated/pyproxy.ts + sed -i 's@from "pyodide-util"@from "../pyodide-util"@g' ./generated/pyproxy.ts + bun build pyodide.ts --outdir=dist --sourcemap=linked - name: Upload artifacts uses: actions/upload-artifact@v4 diff --git a/src/js/api.ts b/src/js/api.ts index df75eefc5cd5..20692a987c23 100644 --- a/src/js/api.ts +++ b/src/js/api.ts @@ -1,18 +1,18 @@ import { ffi } from "./ffi"; -import { CanvasInterface, canvas } from "./canvas"; +import { type CanvasInterface, canvas } from "./canvas"; -import { PackageData, loadPackage, loadedPackages } from "./load-package"; -import { type PyProxy, type PyDict } from "generated/pyproxy"; +import { type PackageData, loadPackage, loadedPackages } from "./load-package"; +import { type PyProxy, type PyDict } from "./generated/pyproxy"; import { loadBinaryFile } from "./compat"; import { version } from "./version"; import { setStdin, setStdout, setStderr } from "./streams"; import { scheduleCallback } from "./scheduler"; -import { TypedArray } from "./types"; +import type { TypedArray } from "./types"; import { detectEnvironment } from "./environments"; import "./literal-map.js"; import { makeGlobalsProxy, - SnapshotConfig, + type SnapshotConfig, syncUpSnapshotLoad1, syncUpSnapshotLoad2, } from "./snapshot"; diff --git a/src/js/compat.ts b/src/js/compat.ts index b5b695684514..45c5e47c9cfc 100644 --- a/src/js/compat.ts +++ b/src/js/compat.ts @@ -3,7 +3,7 @@ import { IN_BROWSER_MAIN_THREAD, IN_BROWSER_WEB_WORKER, } from "./environments"; -import { Lockfile } from "./types"; +import type { Lockfile } from "./types"; declare var globalThis: { importScripts: (url: string) => void; diff --git a/src/js/dynload.ts b/src/js/dynload.ts index 95c2ee93312d..821cdb082df3 100644 --- a/src/js/dynload.ts +++ b/src/js/dynload.ts @@ -4,8 +4,8 @@ declare var DEBUG: boolean; import { createLock } from "./lock"; import { memoize } from "./pyodide-util"; -import { InternalPackageData } from "./load-package"; -import { LoadDynlibFS, ReadFileType } from "./types"; +import type { InternalPackageData } from "./load-package"; +import type { LoadDynlibFS, ReadFileType } from "./types"; // File System-like type which can be passed to // Module.loadDynamicLibrary or Module.loadWebAssemblyModule @@ -153,9 +153,8 @@ export async function loadDynlibsFromPackage( ) { // assume that shared libraries of a package are located in .libs directory, // following the convention of auditwheel. - const auditWheelLibDir = `${API.sitepackages}/${ - pkg.file_name.split("-")[0] - }.libs`; + const auditWheelLibDir = `${API.sitepackages}/${pkg.file_name.split("-")[0] + }.libs`; // This prevents from reading large libraries multiple times. const readFileMemoized: ReadFileType = memoize(Module.FS.readFile); diff --git a/src/js/emscripten-settings.ts b/src/js/emscripten-settings.ts index a5bc6f201856..8283041a0956 100644 --- a/src/js/emscripten-settings.ts +++ b/src/js/emscripten-settings.ts @@ -1,8 +1,8 @@ /** @private */ -import { ConfigType } from "./pyodide"; +import type { ConfigType } from "./pyodide"; import { loadBinaryFile, getBinaryResponse } from "./compat"; -import { API, PreRunFunc } from "./types"; +import type { API, PreRunFunc } from "./types"; /** * @private diff --git a/src/js/ffi.ts b/src/js/ffi.ts index 6f34eb6e0a38..32cd9c83a718 100644 --- a/src/js/ffi.ts +++ b/src/js/ffi.ts @@ -17,8 +17,8 @@ export type { PyBufferView, PySequence, PyMutableSequence, -} from "generated/pyproxy"; -export type { PythonError } from "generated/error_handling"; +} from "./generated/pyproxy"; +export type { PythonError } from "./generated/error_handling"; // These need to be imported for their side effects at startup import "generated/js2python"; import "generated/python2js_buffer"; @@ -44,9 +44,9 @@ import { PyBufferView, PySequence, PyMutableSequence, -} from "generated/pyproxy"; +} from "./generated/pyproxy"; -import { PythonError } from "../core/error_handling"; +import { PythonError } from "./generated/error_handling"; /** * See :ref:`js-api-pyodide-ffi` diff --git a/src/js/load-package.ts b/src/js/load-package.ts index 0237e46839ec..1cd896f807a5 100644 --- a/src/js/load-package.ts +++ b/src/js/load-package.ts @@ -6,13 +6,13 @@ import { } from "./compat.js"; import { createLock } from "./lock"; import { loadDynlibsFromPackage } from "./dynload"; -import { PyProxy } from "generated/pyproxy"; +import { PyProxy } from "./generated/pyproxy"; import { canonicalizePackageName, uriToPackageData, base16ToBase64, } from "./packaging-utils"; -import { Lockfile } from "./types"; +import type { Lockfile } from "./types"; /** * Initialize the packages index. This is called as early as possible in diff --git a/src/js/package.json b/src/js/package.json index 77cd18658db9..a208ee108af4 100644 --- a/src/js/package.json +++ b/src/js/package.json @@ -4,6 +4,7 @@ "access": "public" }, "version": "0.26.2", + "type": "module", "description": "The Pyodide JavaScript package", "keywords": [ "python", @@ -22,18 +23,21 @@ ".": { "import": "./dist/pyodide.js", "types": "./pyodide.ts" + }, + "./version": { + "import": "./version.ts", + "types": "./version.ts" } }, "files": [ + "package.json", "dist", - "pyodide.ts", - "api.ts", - "types.ts", - "emscripten-settings.ts", - "snapshot.ts" + "generated", + "vendor", + "*.ts" ], "types": "./pyodide.ts", "engines": { "node": ">=18.0.0" } -} +} \ No newline at end of file diff --git a/src/js/pyodide.ts b/src/js/pyodide.ts index df3ba0ba5636..9dd8c91804d9 100644 --- a/src/js/pyodide.ts +++ b/src/js/pyodide.ts @@ -15,7 +15,7 @@ import type { PyodideInterface } from "./api.js"; import type { TypedArray, Module } from "./types"; import type { EmscriptenSettings } from "./emscripten-settings"; import type { PackageData } from "./load-package"; -import { SnapshotConfig } from "./snapshot"; +import type { SnapshotConfig } from "./snapshot"; export type { PyodideInterface, TypedArray }; export { version, type PackageData }; diff --git a/src/js/types.ts b/src/js/types.ts index 20e5a98adf6f..00162b8f5b01 100644 --- a/src/js/types.ts +++ b/src/js/types.ts @@ -1,5 +1,5 @@ export { }; -import type { PyProxy, PyAwaitable } from "generated/pyproxy"; +import type { PyProxy, PyAwaitable } from "./generated/pyproxy"; import { type PyodideInterface } from "./api"; import { type ConfigType } from "./pyodide"; import { type InFuncType } from "./streams"; @@ -8,7 +8,7 @@ import { type InternalPackageData, type PackageLoadMetadata, } from "./load-package"; -import { SnapshotConfig } from "./snapshot"; +import type { SnapshotConfig } from "./snapshot"; export type TypedArray = | Int8Array