summaryrefslogtreecommitdiff
path: root/test_util/src/builders.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/builders.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/builders.rs')
-rw-r--r--test_util/src/builders.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs
index 17871baa1..39771e088 100644
--- a/test_util/src/builders.rs
+++ b/test_util/src/builders.rs
@@ -227,7 +227,7 @@ pub struct TestCommandBuilder {
}
impl TestCommandBuilder {
- pub fn command_name(mut self, name: impl AsRef<OsStr>) -> Self {
+ pub fn name(mut self, name: impl AsRef<OsStr>) -> Self {
self.command_name = name.as_ref().to_string_lossy().to_string();
self
}
@@ -306,7 +306,11 @@ impl TestCommandBuilder {
}
fn build_command_path(&self) -> PathRef {
- let command_name = &self.command_name;
+ let command_name = if cfg!(windows) && self.command_name == "npm" {
+ "npm.cmd"
+ } else {
+ &self.command_name
+ };
if command_name == "deno" {
deno_exe_path()
} else {
@@ -407,11 +411,11 @@ impl TestCommandBuilder {
command.env_clear();
}
command.env("DENO_DIR", self.context.deno_dir.path());
- let envs = self.build_envs();
+ let mut envs = self.build_envs();
if !envs.contains_key("NPM_CONFIG_REGISTRY") {
- command.env("NPM_CONFIG_REGISTRY", npm_registry_unset_url());
+ envs.insert("NPM_CONFIG_REGISTRY".to_string(), npm_registry_unset_url());
}
- command.envs(self.build_envs());
+ command.envs(envs);
command.current_dir(cwd);
command.stdin(Stdio::piped());
@@ -527,6 +531,7 @@ impl Drop for TestCommandOutput {
// now ensure the exit code was asserted
if !*self.asserted_exit_code.borrow() && self.exit_code != Some(0) {
+ self.print_output();
panic!(
"The non-zero exit code of the command was not asserted: {:?}",
self.exit_code,