Skip to content

Commit 53e910a

Browse files
committed
Fix worker interpreter version
1 parent 452e83c commit 53e910a

File tree

12 files changed

+163
-127
lines changed

12 files changed

+163
-127
lines changed

docs/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/zip-BIfA-Q-T.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/zip-BIfA-Q-T.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/zip-C10rja2G.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/zip-C10rja2G.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

esm/custom.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { $$ } from 'basic-devtools';
44
import { JSModules, isSync, assign, create, createOverload, createResolved, dedent, defineProperty, nodeInfo, registerJSModules } from './utils.js';
55
import { getDetails } from './script-handler.js';
66
import { registry as defaultRegistry, prefixes, configs } from './interpreters.js';
7-
import { getRuntimeID } from './loader.js';
7+
import { getRuntimeID, resolveConfig } from './loader.js';
88
import { addAllListeners } from './listeners.js';
99
import { Hook, XWorker as XW } from './xworker.js';
1010
import { workers, workersHandler } from './workers.js';
@@ -62,13 +62,20 @@ export const handleCustomType = async (node) => {
6262
try {
6363
const worker = workerURL(node);
6464
if (worker) {
65+
let v = version;
66+
const cfg = node.getAttribute('config') || config || {};
67+
if (!v) {
68+
const [o] = resolveConfig(cfg, configURL);
69+
const details = await o;
70+
v = details.version || details.interpreter;
71+
}
6572
const xworker = XW.call(new Hook(null, hooks), worker, {
6673
...nodeInfo(node, type),
67-
version,
6874
configURL,
75+
version: v,
6976
type: runtime,
7077
custom: type,
71-
config: node.getAttribute('config') || config || {},
78+
config: cfg,
7279
async: !isSync(node),
7380
serviceWorker: node.getAttribute('service-worker'),
7481
});

esm/loader.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ export const getConfigURLAndType = (config, configURL = './config.txt') => {
1717
return [absoluteURL(config), type];
1818
};
1919

20+
export const resolveConfig = (config, configURL, options = {}) => {
21+
const [absolute, type] = getConfigURLAndType(config, configURL);
22+
if (type === 'json') {
23+
options = fetch(absolute).json();
24+
} else if (type === 'toml') {
25+
options = fetch(absolute).text().then(toml);
26+
} else if (type === 'string') {
27+
options = parseString(config);
28+
} else if (type === 'object' && config) {
29+
options = config;
30+
} else if (type === 'txt' && typeof options === 'string') {
31+
options = parseString(options);
32+
}
33+
config = absolute;
34+
return [options, config];
35+
};
36+
2037
const parseString = config => {
2138
try {
2239
return parse(config);
@@ -43,19 +60,7 @@ export const getRuntime = (id, config, configURL, options = {}) => {
4360
if (config) {
4461
// REQUIRES INTEGRATION TEST
4562
/* c8 ignore start */
46-
const [absolute, type] = getConfigURLAndType(config, configURL);
47-
if (type === 'json') {
48-
options = fetch(absolute).json();
49-
} else if (type === 'toml') {
50-
options = fetch(absolute).text().then(toml);
51-
} else if (type === 'string') {
52-
options = parseString(config);
53-
} else if (type === 'object' && config) {
54-
options = config;
55-
} else if (type === 'txt' && typeof options === 'string') {
56-
options = parseString(options);
57-
}
58-
config = absolute;
63+
[options, config] = resolveConfig(config, configURL, options);
5964
/* c8 ignore stop */
6065
}
6166
return resolve(options).then(options => interpreter[id](options, config));

esm/script-handler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export const handle = async (script) => {
150150
const XWorker = $xworker(type, versionValue);
151151
const xworker = new XWorker(url, {
152152
...nodeInfo(script, type),
153+
version: versionValue,
153154
async: isAsync,
154155
config: configValue,
155156
serviceWorker: sw?.value,

package-lock.json

Lines changed: 108 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)