Skip to content

Commit d2c21c1

Browse files
authored
fix: allow setting static patterns when creating a user worker (#471)
* fix: allow setting static patterns when creating a user worker * fix: clippy * fix: make static_patterns optional * formatting * Trigger Build
1 parent 6246a6f commit d2c21c1

File tree

7 files changed

+28
-5
lines changed

7 files changed

+28
-5
lines changed

crates/base/src/worker/pool.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ impl WorkerPool {
365365
maybe_jsx_import_source_config,
366366
maybe_s3_fs_config,
367367
maybe_tmp_fs_config,
368+
static_patterns,
368369
..
369370
} = worker_options;
370371

@@ -381,7 +382,7 @@ impl WorkerPool {
381382
maybe_module_code,
382383
maybe_entrypoint,
383384
maybe_decorator,
384-
static_patterns: vec![],
385+
static_patterns,
385386

386387
maybe_jsx_import_source_config,
387388
maybe_s3_fs_config,
@@ -714,7 +715,7 @@ pub async fn create_user_worker_pool(
714715
None => break,
715716
Some(UserWorkerMsgs::Create(worker_options, tx)) => {
716717
worker_pool.create_user_worker(WorkerContextInitOpts {
717-
static_patterns: static_patterns.clone(),
718+
static_patterns: [worker_options.static_patterns, static_patterns.clone()].concat(),
718719
maybe_jsx_import_source_config: {
719720
if worker_options.maybe_jsx_import_source_config.is_some() {
720721
worker_options.maybe_jsx_import_source_config

deno.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"./crates/base/test_cases"
55
],
66
"fmt": {
7-
"useTabs": true,
7+
"useTabs": false,
88
"lineWidth": 100,
99
"indentWidth": 4,
1010
"singleQuote": true,
@@ -14,4 +14,4 @@
1414
"npm:@meowmeow/foobar": "npm:is-odd",
1515
"openai": "npm:openai"
1616
}
17-
}
17+
}

examples/main/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ Deno.serve(async (req: Request) => {
131131
//
132132
const cpuTimeSoftLimitMs = 10000;
133133
const cpuTimeHardLimitMs = 20000;
134+
const staticPatterns = [
135+
'./examples/**/*.html',
136+
];
134137

135138
return await EdgeRuntime.userWorkers.create({
136139
servicePath,
@@ -143,6 +146,7 @@ Deno.serve(async (req: Request) => {
143146
netAccessDisabled,
144147
cpuTimeSoftLimitMs,
145148
cpuTimeHardLimitMs,
149+
staticPatterns,
146150
// maybeEszip,
147151
// maybeEntrypoint,
148152
// maybeModuleCode,

examples/serve-html/bar.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<html>
2+
<h1>Bar</h1>
3+
</html>

examples/serve-html/foo.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<html>
2+
<h1>Foo</h1>
3+
</html>

examples/serve-html/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { join } from 'https://deno.land/std/path/mod.ts';
2+
3+
Deno.serve(async (req) => {
4+
if (req.url.endsWith('/foo')) {
5+
return new Response(await Deno.readTextFile(join(import.meta.dirname, 'foo.html')));
6+
} else {
7+
return new Response(await Deno.readTextFile(join(import.meta.dirname, 'bar.html')));
8+
}
9+
});

ext/workers/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ pub struct UserWorkerCreateOptions {
9191
tmp_fs_config: Option<TmpFsConfig>,
9292

9393
context: Option<JsonMap>,
94+
#[serde(default)]
95+
static_patterns: Vec<String>,
9496
}
9597

9698
#[op2(async)]
@@ -131,6 +133,7 @@ pub async fn op_user_worker_create(
131133
tmp_fs_config: maybe_tmp_fs_config,
132134

133135
context,
136+
static_patterns,
134137
} = opts;
135138

136139
let user_worker_options = WorkerContextInitOpts {
@@ -165,7 +168,7 @@ pub async fn op_user_worker_create(
165168
}
166169
}),
167170

168-
static_patterns: vec![],
171+
static_patterns,
169172
import_map_path,
170173
timing: None,
171174

0 commit comments

Comments
 (0)