Skip to content

Commit a38c00c

Browse files
Fix types
1 parent fac4e21 commit a38c00c

File tree

11 files changed

+69
-60
lines changed

11 files changed

+69
-60
lines changed

.github/workflows/publish.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ jobs:
1313

1414
- name: Build package
1515
working-directory: src/js
16-
run: bun build pyodide.ts --outdir=dist --sourcemap=linked
16+
run: |
17+
mkdir -p generated
18+
cp ../core/*.ts ./generated/
19+
sed -i 's@../js/@../@g' ./generated/error_handling.ts
20+
sed -i 's@from "types"@from "../types"@g' ./generated/pyproxy.ts
21+
sed -i 's@from "pyodide-util"@from "../pyodide-util"@g' ./generated/pyproxy.ts
22+
bun build pyodide.ts --outdir=dist --sourcemap=linked
1723
1824
- name: Upload artifacts
1925
uses: actions/upload-artifact@v4

src/core/pyproxy.ts

+31-31
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ declare var Tests: any;
1818
declare var Module: any;
1919
declare var validSuspender: { value: boolean };
2020

21-
import { TypedArray } from "types";
21+
import type { TypedArray } from "types";
2222
import { warnOnce } from "pyodide-util";
2323

2424
// pyodide-skip
@@ -102,7 +102,7 @@ if (globalThis.FinalizationRegistry) {
102102
// }
103103
// });
104104
} else {
105-
Module.finalizationRegistry = { register() {}, unregister() {} };
105+
Module.finalizationRegistry = { register() { }, unregister() { } };
106106
// Module.bufferFinalizationRegistry = finalizationRegistry;
107107
}
108108

@@ -120,8 +120,8 @@ Module.enable_pyproxy_allocation_tracing = function () {
120120
};
121121
};
122122
Module.disable_pyproxy_allocation_tracing = function () {
123-
trace_pyproxy_alloc = function (proxy: any) {};
124-
trace_pyproxy_dealloc = function (proxy: any) {};
123+
trace_pyproxy_alloc = function (proxy: any) { };
124+
trace_pyproxy_dealloc = function (proxy: any) { };
125125
};
126126
Module.disable_pyproxy_allocation_tracing();
127127

@@ -237,7 +237,7 @@ function pyproxy_new(
237237
// `setPrototypeOf`. The documentation for `setPrototypeOf` says to use
238238
// `Object.create` or `Reflect.construct` instead for performance reasons
239239
// but neither of those work here.
240-
target = function () {};
240+
target = function () { };
241241
Object.setPrototypeOf(target, cls.prototype);
242242
// Remove undesirable properties added by Function constructor. Note: we
243243
// can't remove "arguments" or "caller" because they are not configurable
@@ -409,7 +409,7 @@ Module.getPyProxyClass = function (flags: number) {
409409
);
410410
const super_proto = flags & IS_CALLABLE ? PyProxyFunctionProto : PyProxyProto;
411411
const sub_proto = Object.create(super_proto, descriptors);
412-
function NewPyProxyClass() {}
412+
function NewPyProxyClass() { }
413413
NewPyProxyClass.prototype = sub_proto;
414414
pyproxyClassMap.set(flags, NewPyProxyClass);
415415
return NewPyProxyClass;
@@ -820,7 +820,7 @@ const PyProxyFunctionProto = Object.create(
820820
Function.prototype,
821821
Object.getOwnPropertyDescriptors(PyProxyProto),
822822
);
823-
function PyProxyFunction() {}
823+
function PyProxyFunction() { }
824824
PyProxyFunction.prototype = PyProxyFunctionProto;
825825

826826
/**
@@ -834,7 +834,7 @@ export class PyProxyWithLength extends PyProxy {
834834
}
835835
}
836836

837-
export interface PyProxyWithLength extends PyLengthMethods {}
837+
export interface PyProxyWithLength extends PyLengthMethods { }
838838

839839
// Controlled by HAS_LENGTH, appears for any object with __len__ or sq_length
840840
// or mp_length methods
@@ -870,7 +870,7 @@ export class PyProxyWithGet extends PyProxy {
870870
}
871871
}
872872

873-
export interface PyProxyWithGet extends PyGetItemMethods {}
873+
export interface PyProxyWithGet extends PyGetItemMethods { }
874874

875875
class PyAsJsonAdaptorMethods {
876876
asJsJson() {
@@ -955,7 +955,7 @@ export class PyProxyWithSet extends PyProxy {
955955
}
956956
}
957957

958-
export interface PyProxyWithSet extends PySetItemMethods {}
958+
export interface PyProxyWithSet extends PySetItemMethods { }
959959
// Controlled by HAS_SET, appears for any class with __setitem__, __delitem__,
960960
// mp_ass_subscript, or sq_ass_item.
961961
export class PySetItemMethods {
@@ -1011,7 +1011,7 @@ export class PyProxyWithHas extends PyProxy {
10111011
}
10121012
}
10131013

1014-
export interface PyProxyWithHas extends PyContainsMethods {}
1014+
export interface PyProxyWithHas extends PyContainsMethods { }
10151015

10161016
// Controlled by HAS_CONTAINS flag, appears for any class with __contains__ or
10171017
// sq_contains
@@ -1090,7 +1090,7 @@ function* iter_helper(
10901090
"This borrowed proxy was automatically destroyed when an iterator was exhausted.",
10911091
),
10921092
);
1093-
} catch (e) {}
1093+
} catch (e) { }
10941094
if (_PyErr_Occurred()) {
10951095
_pythonexc2js();
10961096
}
@@ -1109,7 +1109,7 @@ export class PyIterable extends PyProxy {
11091109
}
11101110
}
11111111

1112-
export interface PyIterable extends PyIterableMethods {}
1112+
export interface PyIterable extends PyIterableMethods { }
11131113

11141114
// Controlled by IS_ITERABLE, appears for any object with __iter__ or tp_iter,
11151115
// unless they are iterators. See: https://docs.python.org/3/c-api/iter.html
@@ -1217,7 +1217,7 @@ export class PyAsyncIterable extends PyProxy {
12171217
}
12181218
}
12191219

1220-
export interface PyAsyncIterable extends PyAsyncIterableMethods {}
1220+
export interface PyAsyncIterable extends PyAsyncIterableMethods { }
12211221

12221222
export class PyAsyncIterableMethods {
12231223
/**
@@ -1258,7 +1258,7 @@ export class PyIterator extends PyProxy {
12581258
}
12591259
}
12601260

1261-
export interface PyIterator extends PyIteratorMethods {}
1261+
export interface PyIterator extends PyIteratorMethods { }
12621262

12631263
// Controlled by IS_ITERATOR, appears for any object with a __next__ or
12641264
// tp_iternext method.
@@ -1311,7 +1311,7 @@ export class PyGenerator extends PyProxy {
13111311
}
13121312
}
13131313

1314-
export interface PyGenerator extends PyGeneratorMethods {}
1314+
export interface PyGenerator extends PyGeneratorMethods { }
13151315

13161316
export class PyGeneratorMethods {
13171317
/**
@@ -1387,7 +1387,7 @@ export class PyAsyncIterator extends PyProxy {
13871387
}
13881388
}
13891389

1390-
export interface PyAsyncIterator extends PyAsyncIteratorMethods {}
1390+
export interface PyAsyncIterator extends PyAsyncIteratorMethods { }
13911391

13921392
export class PyAsyncIteratorMethods {
13931393
/** @private */
@@ -1451,7 +1451,7 @@ export class PyAsyncGenerator extends PyProxy {
14511451
}
14521452
}
14531453

1454-
export interface PyAsyncGenerator extends PyAsyncGeneratorMethods {}
1454+
export interface PyAsyncGenerator extends PyAsyncGeneratorMethods { }
14551455

14561456
export class PyAsyncGeneratorMethods {
14571457
/**
@@ -1554,7 +1554,7 @@ export class PySequence extends PyProxy {
15541554
}
15551555
}
15561556

1557-
export interface PySequence extends PySequenceMethods {}
1557+
export interface PySequence extends PySequenceMethods { }
15581558

15591559
// JS default comparison is to convert to strings and compare lexicographically
15601560
function defaultCompareFunc(a: any, b: any): number {
@@ -1861,7 +1861,7 @@ export class PyMutableSequence extends PyProxy {
18611861
}
18621862
}
18631863

1864-
export interface PyMutableSequence extends PyMutableSequenceMethods {}
1864+
export interface PyMutableSequence extends PyMutableSequenceMethods { }
18651865

18661866
export class PyMutableSequenceMethods {
18671867
/**
@@ -2434,7 +2434,7 @@ export class PyAwaitable extends PyProxy {
24342434
}
24352435
}
24362436

2437-
export interface PyAwaitable extends Promise<any> {}
2437+
export interface PyAwaitable extends Promise<any> { }
24382438

24392439
/**
24402440
* The Promise / JavaScript awaitable API.
@@ -2848,7 +2848,7 @@ export class PyBuffer extends PyProxy {
28482848
}
28492849
}
28502850

2851-
export interface PyBuffer extends PyBufferMethods {}
2851+
export interface PyBuffer extends PyBufferMethods { }
28522852

28532853
export class PyBufferMethods {
28542854
/**
@@ -2923,11 +2923,11 @@ export class PyBufferMethods {
29232923
if (bigEndian && alignment > 1) {
29242924
throw new Error(
29252925
"Javascript has no native support for big endian buffers. " +
2926-
"In this case, you can pass an explicit type argument. " +
2927-
"For instance, `getBuffer('dataview')` will return a `DataView`" +
2928-
"which has native support for reading big endian data. " +
2929-
"Alternatively, toJs will automatically convert the buffer " +
2930-
"to little endian.",
2926+
"In this case, you can pass an explicit type argument. " +
2927+
"For instance, `getBuffer('dataview')` will return a `DataView`" +
2928+
"which has native support for reading big endian data. " +
2929+
"Alternatively, toJs will automatically convert the buffer " +
2930+
"to little endian.",
29312931
);
29322932
}
29332933
let numBytes = largest_ptr - smallest_ptr;
@@ -3002,10 +3002,10 @@ export class PyDict extends PyProxy {
30023002

30033003
export interface PyDict
30043004
extends PyProxyWithGet,
3005-
PyProxyWithSet,
3006-
PyProxyWithHas,
3007-
PyProxyWithLength,
3008-
PyIterable {}
3005+
PyProxyWithSet,
3006+
PyProxyWithHas,
3007+
PyProxyWithLength,
3008+
PyIterable { }
30093009

30103010
/**
30113011
* A class to allow access to Python data buffers from JavaScript. These are

src/js/api.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { ffi } from "./ffi";
2-
import { CanvasInterface, canvas } from "./canvas";
2+
import { type CanvasInterface, canvas } from "./canvas";
33

4-
import { PackageData, loadPackage, loadedPackages } from "./load-package";
5-
import { type PyProxy, type PyDict } from "generated/pyproxy";
4+
import { type PackageData, loadPackage, loadedPackages } from "./load-package";
5+
import { type PyProxy, type PyDict } from "./generated/pyproxy";
66
import { loadBinaryFile } from "./compat";
77
import { version } from "./version";
88
import { setStdin, setStdout, setStderr } from "./streams";
99
import { scheduleCallback } from "./scheduler";
10-
import { TypedArray } from "./types";
10+
import type { TypedArray } from "./types";
1111
import { detectEnvironment } from "./environments";
1212
import "./literal-map.js";
1313
import {
1414
makeGlobalsProxy,
15-
SnapshotConfig,
15+
type SnapshotConfig,
1616
syncUpSnapshotLoad1,
1717
syncUpSnapshotLoad2,
1818
} from "./snapshot";

src/js/compat.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
IN_BROWSER_MAIN_THREAD,
44
IN_BROWSER_WEB_WORKER,
55
} from "./environments";
6-
import { Lockfile } from "./types";
6+
import type { Lockfile } from "./types";
77

88
declare var globalThis: {
99
importScripts: (url: string) => void;

src/js/dynload.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ declare var DEBUG: boolean;
44

55
import { createLock } from "./lock";
66
import { memoize } from "./pyodide-util";
7-
import { InternalPackageData } from "./load-package";
8-
import { LoadDynlibFS, ReadFileType } from "./types";
7+
import type { InternalPackageData } from "./load-package";
8+
import type { LoadDynlibFS, ReadFileType } from "./types";
99

1010
// File System-like type which can be passed to
1111
// Module.loadDynamicLibrary or Module.loadWebAssemblyModule
@@ -153,9 +153,8 @@ export async function loadDynlibsFromPackage(
153153
) {
154154
// assume that shared libraries of a package are located in <package-name>.libs directory,
155155
// following the convention of auditwheel.
156-
const auditWheelLibDir = `${API.sitepackages}/${
157-
pkg.file_name.split("-")[0]
158-
}.libs`;
156+
const auditWheelLibDir = `${API.sitepackages}/${pkg.file_name.split("-")[0]
157+
}.libs`;
159158

160159
// This prevents from reading large libraries multiple times.
161160
const readFileMemoized: ReadFileType = memoize(Module.FS.readFile);

src/js/emscripten-settings.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** @private */
22

3-
import { ConfigType } from "./pyodide";
3+
import type { ConfigType } from "./pyodide";
44
import { loadBinaryFile, getBinaryResponse } from "./compat";
5-
import { API, PreRunFunc } from "./types";
5+
import type { API, PreRunFunc } from "./types";
66

77
/**
88
* @private

src/js/ffi.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export type {
1717
PyBufferView,
1818
PySequence,
1919
PyMutableSequence,
20-
} from "generated/pyproxy";
21-
export type { PythonError } from "generated/error_handling";
20+
} from "./generated/pyproxy";
21+
export type { PythonError } from "./generated/error_handling";
2222
// These need to be imported for their side effects at startup
2323
import "generated/js2python";
2424
import "generated/python2js_buffer";
@@ -44,9 +44,9 @@ import {
4444
PyBufferView,
4545
PySequence,
4646
PyMutableSequence,
47-
} from "generated/pyproxy";
47+
} from "./generated/pyproxy";
4848

49-
import { PythonError } from "../core/error_handling";
49+
import { PythonError } from "./generated/error_handling";
5050

5151
/**
5252
* See :ref:`js-api-pyodide-ffi`

src/js/load-package.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import {
66
} from "./compat.js";
77
import { createLock } from "./lock";
88
import { loadDynlibsFromPackage } from "./dynload";
9-
import { PyProxy } from "generated/pyproxy";
9+
import { PyProxy } from "./generated/pyproxy";
1010
import {
1111
canonicalizePackageName,
1212
uriToPackageData,
1313
base16ToBase64,
1414
} from "./packaging-utils";
15-
import { Lockfile } from "./types";
15+
import type { Lockfile } from "./types";
1616

1717
/**
1818
* Initialize the packages index. This is called as early as possible in

src/js/package.json

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"access": "public"
55
},
66
"version": "0.26.3",
7+
"type": "module",
78
"description": "The Pyodide JavaScript package",
89
"keywords": [
910
"python",
@@ -22,18 +23,21 @@
2223
".": {
2324
"import": "./dist/pyodide.js",
2425
"types": "./pyodide.ts"
26+
},
27+
"./version": {
28+
"import": "./version.ts",
29+
"types": "./version.ts"
2530
}
2631
},
2732
"files": [
33+
"package.json",
2834
"dist",
29-
"pyodide.ts",
30-
"api.ts",
31-
"types.ts",
32-
"emscripten-settings.ts",
33-
"snapshot.ts"
35+
"generated",
36+
"vendor",
37+
"*.ts"
3438
],
3539
"types": "./pyodide.ts",
3640
"engines": {
3741
"node": ">=18.0.0"
3842
}
39-
}
43+
}

src/js/pyodide.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { PyodideInterface } from "./api.js";
1515
import type { TypedArray, Module } from "./types";
1616
import type { EmscriptenSettings } from "./emscripten-settings";
1717
import type { PackageData } from "./load-package";
18-
import { SnapshotConfig } from "./snapshot";
18+
import type { SnapshotConfig } from "./snapshot";
1919
export type { PyodideInterface, TypedArray };
2020

2121
export { version, type PackageData };

0 commit comments

Comments
 (0)