mirror of
https://github.com/denoland/deno.git
synced 2024-12-26 00:59:24 -05:00
Resolve worker specifiers relative to main module of host. (#2751)
This commit is contained in:
parent
520bdb6c31
commit
56a82e72d9
7 changed files with 21 additions and 11 deletions
16
cli/ops.rs
16
cli/ops.rs
|
@ -2095,9 +2095,21 @@ fn op_create_worker(
|
|||
|
||||
let parent_state = state.clone();
|
||||
|
||||
let mut module_specifier = ModuleSpecifier::resolve_url_or_path(specifier)?;
|
||||
|
||||
let mut child_argv = parent_state.argv.clone();
|
||||
|
||||
if !has_source_code {
|
||||
if let Some(module) = state.main_module() {
|
||||
module_specifier =
|
||||
ModuleSpecifier::resolve_import(specifier, &module.to_string())?;
|
||||
child_argv[1] = module_specifier.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
let child_state = ThreadSafeState::new(
|
||||
parent_state.flags.clone(),
|
||||
parent_state.argv.clone(),
|
||||
child_argv,
|
||||
op_selector_std,
|
||||
parent_state.progress.clone(),
|
||||
include_deno_namespace,
|
||||
|
@ -2134,8 +2146,6 @@ fn op_create_worker(
|
|||
return ok_buf(exec_cb(worker));
|
||||
}
|
||||
|
||||
let module_specifier = ModuleSpecifier::resolve_url_or_path(specifier)?;
|
||||
|
||||
let op = worker
|
||||
.execute_mod_async(&module_specifier, false)
|
||||
.and_then(move |()| Ok(exec_cb(worker)));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const jsWorker = new Worker("./tests/subdir/test_worker.js");
|
||||
const tsWorker = new Worker("./tests/subdir/test_worker.ts");
|
||||
const jsWorker = new Worker("./subdir/test_worker.js");
|
||||
const tsWorker = new Worker("./subdir/test_worker.ts");
|
||||
|
||||
tsWorker.onmessage = (e): void => {
|
||||
console.log("Received ts: " + e.data);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const w1 = new Worker("./tests/039_worker_deno_ns/has_ns.ts");
|
||||
const w2 = new Worker("./tests/039_worker_deno_ns/no_ns.ts", {
|
||||
const w1 = new Worker("./039_worker_deno_ns/has_ns.ts");
|
||||
const w2 = new Worker("./039_worker_deno_ns/no_ns.ts", {
|
||||
noDenoNamespace: true
|
||||
});
|
||||
let w1MsgCount = 0;
|
||||
|
|
|
@ -2,7 +2,7 @@ onmessage = (msg): void => {
|
|||
if (msg.data === "START") {
|
||||
postMessage("has_ns.ts: is window.Deno available: " + !!window.Deno);
|
||||
} else {
|
||||
const worker = new Worker("./tests/039_worker_deno_ns/maybe_ns.ts");
|
||||
const worker = new Worker("./maybe_ns.ts");
|
||||
worker.onmessage = (msg): void => {
|
||||
postMessage("[SPAWNED BY has_ns.ts] " + msg.data);
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ onmessage = (msg): void => {
|
|||
if (msg.data === "START") {
|
||||
postMessage("no_ns.ts: is window.Deno available: " + !!window.Deno);
|
||||
} else {
|
||||
const worker = new Worker("./tests/039_worker_deno_ns/maybe_ns.ts");
|
||||
const worker = new Worker("./maybe_ns.ts");
|
||||
worker.onmessage = (msg): void => {
|
||||
postMessage("[SPAWNED BY no_ns.ts] " + msg.data);
|
||||
};
|
||||
|
|
|
@ -39,7 +39,7 @@ function handleAsyncMsgFromWorker(
|
|||
async function main(): Promise<void> {
|
||||
const workers: Array<[Map<number, Resolvable<string>>, Worker]> = [];
|
||||
for (var i = 1; i <= workerCount; ++i) {
|
||||
const worker = new Worker("tests/subdir/bench_worker.ts");
|
||||
const worker = new Worker("./subdir/bench_worker.ts");
|
||||
const promise = new Promise(
|
||||
(resolve): void => {
|
||||
worker.onmessage = (e): void => {
|
||||
|
|
|
@ -4,7 +4,7 @@ const workerCount = 50;
|
|||
async function bench(): Promise<void> {
|
||||
const workers: Worker[] = [];
|
||||
for (var i = 1; i <= workerCount; ++i) {
|
||||
const worker = new Worker("tests/subdir/bench_worker.ts");
|
||||
const worker = new Worker("./subdir/bench_worker.ts");
|
||||
const promise = new Promise(
|
||||
(resolve): void => {
|
||||
worker.onmessage = (e): void => {
|
||||
|
|
Loading…
Reference in a new issue