summaryrefslogtreecommitdiff
path: root/test_util/src/lib.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-10-25 14:39:00 -0400
committerGitHub <noreply@github.com>2023-10-25 14:39:00 -0400
commitbe97170a193e8cecc5ce03ecd3c1d0add4a06bf7 (patch)
treefab7d266e208db93dcf0870dda70f7da56ade735 /test_util/src/lib.rs
parent093b3eee58181ec45839d0fe10b8157326a102b2 (diff)
feat(unstable): ability to `npm install` then `deno run main.ts` (#20967)
This PR adds a new unstable "bring your own node_modules" (BYONM) functionality currently behind a `--unstable-byonm` flag (`"unstable": ["byonm"]` in a deno.json). This enables users to run a separate install command (ex. `npm install`, `pnpm install`) then run `deno run main.ts` and Deno will respect the layout of the node_modules directory as setup by the separate install command. It also works with npm/yarn/pnpm workspaces. For this PR, the behaviour is opted into by specifying `--unstable-byonm`/`"unstable": ["byonm"]`, but in the future we may make this the default behaviour as outlined in https://github.com/denoland/deno/issues/18967#issuecomment-1761248941 This is an extremely rough initial implementation. Errors are terrible in this and the LSP requires frequent restarts. Improvements will be done in follow up PRs.
Diffstat (limited to 'test_util/src/lib.rs')
-rw-r--r--test_util/src/lib.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs
index 07ed55822..9f764007c 100644
--- a/test_util/src/lib.rs
+++ b/test_util/src/lib.rs
@@ -37,7 +37,9 @@ use std::env;
use std::io;
use std::io::Write;
use std::mem::replace;
+use std::net::Ipv6Addr;
use std::net::SocketAddr;
+use std::net::SocketAddrV6;
use std::ops::Deref;
use std::ops::DerefMut;
use std::path::Path;
@@ -1316,15 +1318,18 @@ async fn main_server(
}
_ => {
let mut file_path = testdata_path().to_path_buf();
- file_path.push(&req.uri().path()[1..]);
+ file_path.push(&req.uri().path()[1..].replace("%2f", "/"));
if let Ok(file) = tokio::fs::read(&file_path).await {
let file_resp = custom_headers(req.uri().path(), file);
return Ok(file_resp);
}
// serve npm registry files
- if let Some(suffix) =
- req.uri().path().strip_prefix("/npm/registry/@denotest/")
+ if let Some(suffix) = req
+ .uri()
+ .path()
+ .strip_prefix("/npm/registry/@denotest/")
+ .or_else(|| req.uri().path().strip_prefix("/npm/registry/@denotest%2f"))
{
// serve all requests to /npm/registry/@deno using the file system
// at that path
@@ -1571,10 +1576,22 @@ async fn wrap_abs_redirect_server() {
}
async fn wrap_main_server() {
+ let main_server_addr = SocketAddr::from(([127, 0, 0, 1], PORT));
+ wrap_main_server_for_addr(&main_server_addr).await
+}
+
+// necessary because on Windows the npm binary will resolve localhost to ::1
+async fn wrap_main_ipv6_server() {
+ let ipv6_loopback = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1);
+ let main_server_addr =
+ SocketAddr::V6(SocketAddrV6::new(ipv6_loopback, PORT, 0, 0));
+ wrap_main_server_for_addr(&main_server_addr).await
+}
+
+async fn wrap_main_server_for_addr(main_server_addr: &SocketAddr) {
let main_server_svc =
make_service_fn(|_| async { Ok::<_, Infallible>(service_fn(main_server)) });
- let main_server_addr = SocketAddr::from(([127, 0, 0, 1], PORT));
- let main_server = Server::bind(&main_server_addr).serve(main_server_svc);
+ let main_server = Server::bind(main_server_addr).serve(main_server_svc);
if let Err(e) = main_server.await {
eprintln!("HTTP server error: {e:?}");
}
@@ -1922,6 +1939,7 @@ pub async fn run_all_servers() {
let tls_client_auth_server_fut = run_tls_client_auth_server();
let client_auth_server_https_fut = wrap_client_auth_https_server();
let main_server_fut = wrap_main_server();
+ let main_server_ipv6_fut = wrap_main_ipv6_server();
let main_server_https_fut = wrap_main_https_server();
let h1_only_server_tls_fut = wrap_https_h1_only_tls_server();
let h2_only_server_tls_fut = wrap_https_h2_only_tls_server();
@@ -1945,6 +1963,7 @@ pub async fn run_all_servers() {
double_redirects_server_fut,
abs_redirect_server_fut,
main_server_fut,
+ main_server_ipv6_fut,
main_server_https_fut,
client_auth_server_https_fut,
h1_only_server_tls_fut,