Skip to content

Fix worker interpreter version #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/zip-BIfA-Q-T.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/zip-BIfA-Q-T.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions docs/zip-C10rja2G.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/zip-C10rja2G.js.map

This file was deleted.

13 changes: 10 additions & 3 deletions esm/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { $$ } from 'basic-devtools';
import { JSModules, isSync, assign, create, createOverload, createResolved, dedent, defineProperty, nodeInfo, registerJSModules } from './utils.js';
import { getDetails } from './script-handler.js';
import { registry as defaultRegistry, prefixes, configs } from './interpreters.js';
import { getRuntimeID } from './loader.js';
import { getRuntimeID, resolveConfig } from './loader.js';
import { addAllListeners } from './listeners.js';
import { Hook, XWorker as XW } from './xworker.js';
import { workers, workersHandler } from './workers.js';
Expand Down Expand Up @@ -62,13 +62,20 @@ export const handleCustomType = async (node) => {
try {
const worker = workerURL(node);
if (worker) {
let v = version;
const cfg = node.getAttribute('config') || config || {};
if (!v) {
const [o] = resolveConfig(cfg, configURL);
const details = await o;
v = details.version || details.interpreter;
}
const xworker = XW.call(new Hook(null, hooks), worker, {
...nodeInfo(node, type),
version,
configURL,
version: v,
type: runtime,
custom: type,
config: node.getAttribute('config') || config || {},
config: cfg,
async: !isSync(node),
serviceWorker: node.getAttribute('service-worker'),
});
Expand Down
31 changes: 18 additions & 13 deletions esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ export const getConfigURLAndType = (config, configURL = './config.txt') => {
return [absoluteURL(config), type];
};

export const resolveConfig = (config, configURL, options = {}) => {
const [absolute, type] = getConfigURLAndType(config, configURL);
if (type === 'json') {
options = fetch(absolute).json();
} else if (type === 'toml') {
options = fetch(absolute).text().then(toml);
} else if (type === 'string') {
options = parseString(config);
} else if (type === 'object' && config) {
options = config;
} else if (type === 'txt' && typeof options === 'string') {
options = parseString(options);
}
config = absolute;
return [options, config];
};

const parseString = config => {
try {
return parse(config);
Expand All @@ -43,19 +60,7 @@ export const getRuntime = (id, config, configURL, options = {}) => {
if (config) {
// REQUIRES INTEGRATION TEST
/* c8 ignore start */
const [absolute, type] = getConfigURLAndType(config, configURL);
if (type === 'json') {
options = fetch(absolute).json();
} else if (type === 'toml') {
options = fetch(absolute).text().then(toml);
} else if (type === 'string') {
options = parseString(config);
} else if (type === 'object' && config) {
options = config;
} else if (type === 'txt' && typeof options === 'string') {
options = parseString(options);
}
config = absolute;
[options, config] = resolveConfig(config, configURL, options);
/* c8 ignore stop */
}
return resolve(options).then(options => interpreter[id](options, config));
Expand Down
1 change: 1 addition & 0 deletions esm/script-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const handle = async (script) => {
const XWorker = $xworker(type, versionValue);
const xworker = new XWorker(url, {
...nodeInfo(script, type),
version: versionValue,
async: isAsync,
config: configValue,
serviceWorker: sw?.value,
Expand Down
208 changes: 108 additions & 100 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
"license": "APACHE-2.0",
"devDependencies": {
"@node-loader/import-maps": "^1.1.0",
"@playwright/test": "^1.45.3",
"@playwright/test": "^1.46.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@zip.js/zip.js": "^2.7.48",
"@zip.js/zip.js": "^2.7.51",
"c8": "^10.1.2",
"chokidar": "^3.6.0",
"eslint": "^9.8.0",
"eslint": "^9.9.1",
"linkedom": "^0.18.4",
"rollup": "^4.20.0",
"rollup": "^4.21.1",
"static-handler": "^0.4.3",
"typescript": "^5.5.4"
},
Expand Down Expand Up @@ -78,14 +78,14 @@
"@webreflection/idb-map": "^0.3.1",
"basic-devtools": "^0.1.6",
"codedent": "^0.1.2",
"coincident": "^2.0.6",
"coincident": "^2.0.7",
"gc-hook": "^0.4.1",
"html-escaper": "^3.0.3",
"proxy-target": "^3.0.2",
"sticky-module": "^0.1.1",
"to-json-callback": "^0.1.1"
},
"worker": {
"blob": "sha256-Hx4kuOT2gB4ft8/m8SE8oCI1P5VB96BdAgxbyFBOBN0="
"blob": "sha256-QDmhtpGRALCZn/gNlUmUSRUiiNDmiCk9Pn61k6Addho="
}
}
15 changes: 15 additions & 0 deletions test/interpreter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pyodide Worker Version</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<script type="module" src="../../dist/index.js"></script>
</head>
<body>
<script type="pyodide" version='https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.mjs' worker>
import pyodide
print(pyodide.__version__)
</script>
</body>
</html>