summaryrefslogtreecommitdiff
path: root/test_util/src/lib.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-02-20 19:14:06 +0100
committerGitHub <noreply@github.com>2023-02-20 19:14:06 +0100
commit4d1a14ca7fa9496f36470a7771448a9b006b0204 (patch)
treede226f6368faec98065bf14382f23541484cfe72 /test_util/src/lib.rs
parent88f6fc6a1684326ae1f947ea8ec24ad0bff0f449 (diff)
feat: auto-discover package.json for npm dependencies (#17272)
This commits adds auto-discovery of "package.json" file when running "deno run" and "deno task" subcommands. In case of "deno run" the "package.json" is being looked up starting from the directory of the script that is being run, stopping early if "deno.json(c)" file is found (ie. FS tree won't be traversed "up" from "deno.json"). When "package.json" is discovered the "--node-modules-dir" flag is implied, leading to creation of local "node_modules/" directory - we did that, because most tools relying on "package.json" will expect "node_modules/" directory to be present (eg. Vite). Additionally "dependencies" and "devDependencies" specified in the "package.json" are downloaded on startup. This is a stepping stone to supporting bare specifier imports, but the actual integration will be done in a follow up commit. --------- Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'test_util/src/lib.rs')
-rw-r--r--test_util/src/lib.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs
index 5aac13855..555c26ffe 100644
--- a/test_util/src/lib.rs
+++ b/test_util/src/lib.rs
@@ -1923,6 +1923,8 @@ pub struct CheckOutputIntegrationTest<'a> {
pub envs: Vec<(String, String)>,
pub env_clear: bool,
pub temp_cwd: bool,
+ // Relative to "testdata" directory
+ pub maybe_cwd: Option<&'a str>,
}
impl<'a> CheckOutputIntegrationTest<'a> {
@@ -1954,9 +1956,11 @@ impl<'a> CheckOutputIntegrationTest<'a> {
let deno_dir = new_deno_dir(); // keep this alive for the test
let mut command = deno_cmd_with_deno_dir(&deno_dir);
let cwd = if self.temp_cwd {
- deno_dir.path()
+ deno_dir.path().to_owned()
+ } else if let Some(cwd_) = &self.maybe_cwd {
+ testdata_dir.join(cwd_)
} else {
- testdata_dir.as_path()
+ testdata_dir.clone()
};
println!("deno_exe args {}", args.join(" "));
println!("deno_exe cwd {:?}", &cwd);