fix: startup error
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
export function resolvePyodideIndexURL(workerModuleUrl: string): string {
|
export function resolvePyodideIndexURL(workerModuleUrl: string): string | undefined {
|
||||||
|
const parsed = new URL(workerModuleUrl);
|
||||||
|
|
||||||
|
if (parsed.protocol !== 'file:') {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return new URL('../../../node_modules/pyodide/', workerModuleUrl).toString();
|
return new URL('../../../node_modules/pyodide/', workerModuleUrl).toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,8 +183,9 @@ json.dumps(__bds_entrypoints)
|
|||||||
|
|
||||||
async function bootstrapRuntime(): Promise<void> {
|
async function bootstrapRuntime(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
const indexURL = resolvePyodideIndexURL(import.meta.url);
|
||||||
runtime = await loadPyodide({
|
runtime = await loadPyodide({
|
||||||
indexURL: resolvePyodideIndexURL(import.meta.url),
|
...(indexURL ? { indexURL } : {}),
|
||||||
stdout: (chunk) => {
|
stdout: (chunk) => {
|
||||||
if (!activeRequestId) {
|
if (!activeRequestId) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -9,8 +9,13 @@ describe('resolvePyodideIndexURL', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resolves to vite node_modules path for dev worker urls', () => {
|
it('returns undefined for dev worker urls to let pyodide use module-relative defaults', () => {
|
||||||
const workerUrl = 'http://localhost:5173/src/renderer/python/pythonRuntime.worker.ts';
|
const workerUrl = 'http://localhost:5173/src/renderer/python/pythonRuntime.worker.ts';
|
||||||
expect(resolvePyodideIndexURL(workerUrl)).toBe('http://localhost:5173/node_modules/pyodide/');
|
expect(resolvePyodideIndexURL(workerUrl)).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns undefined for vite worker_file urls with query parameters', () => {
|
||||||
|
const workerUrl = 'http://localhost:5173/python/pythonRuntime.worker.ts?worker_file&type=module';
|
||||||
|
expect(resolvePyodideIndexURL(workerUrl)).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user