mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(npm): show a progress bar when initializing the node_modules folder (#18136)
Creating the node_modules folder when the packages are already downloaded can take a bit of time and not knowing what is going on can be confusing. It's better to show a progress bar.
This commit is contained in:
parent
e8f22c0765
commit
44b0d4cb11
20 changed files with 256 additions and 165 deletions
|
@ -345,11 +345,12 @@ fn create_lsp_structs(
|
||||||
registry_url.clone(),
|
registry_url.clone(),
|
||||||
npm_cache.clone(),
|
npm_cache.clone(),
|
||||||
http_client,
|
http_client,
|
||||||
progress_bar,
|
progress_bar.clone(),
|
||||||
);
|
);
|
||||||
let resolution = NpmResolution::new(api.clone(), None, None);
|
let resolution = NpmResolution::new(api.clone(), None, None);
|
||||||
let fs_resolver = create_npm_fs_resolver(
|
let fs_resolver = create_npm_fs_resolver(
|
||||||
npm_cache.clone(),
|
npm_cache.clone(),
|
||||||
|
&progress_bar,
|
||||||
registry_url.clone(),
|
registry_url.clone(),
|
||||||
resolution.clone(),
|
resolution.clone(),
|
||||||
None,
|
None,
|
||||||
|
@ -609,6 +610,7 @@ impl Inner {
|
||||||
resolution.clone(),
|
resolution.clone(),
|
||||||
create_npm_fs_resolver(
|
create_npm_fs_resolver(
|
||||||
self.npm_cache.clone(),
|
self.npm_cache.clone(),
|
||||||
|
&ProgressBar::new(ProgressBarStyle::TextOnly),
|
||||||
self.npm_api.base_url().clone(),
|
self.npm_api.base_url().clone(),
|
||||||
resolution,
|
resolution,
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -11,6 +11,8 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::util::fs::symlink_dir;
|
use crate::util::fs::symlink_dir;
|
||||||
use crate::util::fs::LaxSingleProcessFsFlag;
|
use crate::util::fs::LaxSingleProcessFsFlag;
|
||||||
|
use crate::util::progress_bar::ProgressBar;
|
||||||
|
use crate::util::progress_bar::ProgressMessagePrompt;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use deno_ast::ModuleSpecifier;
|
use deno_ast::ModuleSpecifier;
|
||||||
use deno_core::anyhow::bail;
|
use deno_core::anyhow::bail;
|
||||||
|
@ -42,6 +44,7 @@ use super::common::NpmPackageFsResolver;
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LocalNpmPackageResolver {
|
pub struct LocalNpmPackageResolver {
|
||||||
cache: NpmCache,
|
cache: NpmCache,
|
||||||
|
progress_bar: ProgressBar,
|
||||||
resolution: NpmResolution,
|
resolution: NpmResolution,
|
||||||
registry_url: Url,
|
registry_url: Url,
|
||||||
root_node_modules_path: PathBuf,
|
root_node_modules_path: PathBuf,
|
||||||
|
@ -51,12 +54,14 @@ pub struct LocalNpmPackageResolver {
|
||||||
impl LocalNpmPackageResolver {
|
impl LocalNpmPackageResolver {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
cache: NpmCache,
|
cache: NpmCache,
|
||||||
|
progress_bar: ProgressBar,
|
||||||
registry_url: Url,
|
registry_url: Url,
|
||||||
node_modules_folder: PathBuf,
|
node_modules_folder: PathBuf,
|
||||||
resolution: NpmResolution,
|
resolution: NpmResolution,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
cache,
|
cache,
|
||||||
|
progress_bar,
|
||||||
resolution,
|
resolution,
|
||||||
registry_url,
|
registry_url,
|
||||||
root_node_modules_url: Url::from_directory_path(&node_modules_folder)
|
root_node_modules_url: Url::from_directory_path(&node_modules_folder)
|
||||||
|
@ -200,8 +205,14 @@ impl NpmPackageFsResolver for LocalNpmPackageResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cache_packages(&self) -> Result<(), AnyError> {
|
async fn cache_packages(&self) -> Result<(), AnyError> {
|
||||||
sync_resolver_with_fs(self).await?;
|
sync_resolution_with_fs(
|
||||||
Ok(())
|
&self.resolution.snapshot(),
|
||||||
|
&self.cache,
|
||||||
|
&self.progress_bar,
|
||||||
|
&self.registry_url,
|
||||||
|
&self.root_node_modules_path,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_read_permission(
|
fn ensure_read_permission(
|
||||||
|
@ -217,22 +228,11 @@ impl NpmPackageFsResolver for LocalNpmPackageResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn sync_resolver_with_fs(
|
|
||||||
resolver: &LocalNpmPackageResolver,
|
|
||||||
) -> Result<(), AnyError> {
|
|
||||||
sync_resolution_with_fs(
|
|
||||||
&resolver.resolution.snapshot(),
|
|
||||||
&resolver.cache,
|
|
||||||
&resolver.registry_url,
|
|
||||||
&resolver.root_node_modules_path,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a pnpm style folder structure.
|
/// Creates a pnpm style folder structure.
|
||||||
async fn sync_resolution_with_fs(
|
async fn sync_resolution_with_fs(
|
||||||
snapshot: &NpmResolutionSnapshot,
|
snapshot: &NpmResolutionSnapshot,
|
||||||
cache: &NpmCache,
|
cache: &NpmCache,
|
||||||
|
progress_bar: &ProgressBar,
|
||||||
registry_url: &Url,
|
registry_url: &Url,
|
||||||
root_node_modules_dir_path: &Path,
|
root_node_modules_dir_path: &Path,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
|
@ -252,6 +252,8 @@ async fn sync_resolution_with_fs(
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
let pb_clear_guard = progress_bar.clear_guard(); // prevent flickering
|
||||||
|
|
||||||
// 1. Write all the packages out the .deno directory.
|
// 1. Write all the packages out the .deno directory.
|
||||||
//
|
//
|
||||||
// Copy (hardlink in future) <global_registry_cache>/<package_id>/ to
|
// Copy (hardlink in future) <global_registry_cache>/<package_id>/ to
|
||||||
|
@ -277,6 +279,7 @@ async fn sync_resolution_with_fs(
|
||||||
.should_use_for_npm_package(&package.pkg_id.nv.name)
|
.should_use_for_npm_package(&package.pkg_id.nv.name)
|
||||||
|| !initialized_file.exists()
|
|| !initialized_file.exists()
|
||||||
{
|
{
|
||||||
|
let pb = progress_bar.clone();
|
||||||
let cache = cache.clone();
|
let cache = cache.clone();
|
||||||
let registry_url = registry_url.clone();
|
let registry_url = registry_url.clone();
|
||||||
let package = package.clone();
|
let package = package.clone();
|
||||||
|
@ -284,6 +287,10 @@ async fn sync_resolution_with_fs(
|
||||||
cache
|
cache
|
||||||
.ensure_package(&package.pkg_id.nv, &package.dist, ®istry_url)
|
.ensure_package(&package.pkg_id.nv, &package.dist, ®istry_url)
|
||||||
.await?;
|
.await?;
|
||||||
|
let pb_guard = pb.update_with_prompt(
|
||||||
|
ProgressMessagePrompt::Initialize,
|
||||||
|
&package.pkg_id.nv.to_string(),
|
||||||
|
);
|
||||||
let sub_node_modules = folder_path.join("node_modules");
|
let sub_node_modules = folder_path.join("node_modules");
|
||||||
let package_path =
|
let package_path =
|
||||||
join_package_name(&sub_node_modules, &package.pkg_id.nv.name);
|
join_package_name(&sub_node_modules, &package.pkg_id.nv.name);
|
||||||
|
@ -297,6 +304,8 @@ async fn sync_resolution_with_fs(
|
||||||
copy_dir_recursive(&cache_folder, &package_path)?;
|
copy_dir_recursive(&cache_folder, &package_path)?;
|
||||||
// write out a file that indicates this folder has been initialized
|
// write out a file that indicates this folder has been initialized
|
||||||
fs::write(initialized_file, "")?;
|
fs::write(initialized_file, "")?;
|
||||||
|
// finally stop showing the progress bar
|
||||||
|
drop(pb_guard); // explicit for clarity
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
if sync_download {
|
if sync_download {
|
||||||
|
@ -411,6 +420,7 @@ async fn sync_resolution_with_fs(
|
||||||
}
|
}
|
||||||
|
|
||||||
drop(single_process_lock);
|
drop(single_process_lock);
|
||||||
|
drop(pb_clear_guard);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use crate::args::Lockfile;
|
use crate::args::Lockfile;
|
||||||
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
||||||
|
use crate::util::progress_bar::ProgressBar;
|
||||||
|
|
||||||
use self::common::NpmPackageFsResolver;
|
use self::common::NpmPackageFsResolver;
|
||||||
use self::local::LocalNpmPackageResolver;
|
use self::local::LocalNpmPackageResolver;
|
||||||
|
@ -276,6 +277,7 @@ impl RequireNpmResolver for NpmPackageResolver {
|
||||||
|
|
||||||
pub fn create_npm_fs_resolver(
|
pub fn create_npm_fs_resolver(
|
||||||
cache: NpmCache,
|
cache: NpmCache,
|
||||||
|
progress_bar: &ProgressBar,
|
||||||
registry_url: Url,
|
registry_url: Url,
|
||||||
resolution: NpmResolution,
|
resolution: NpmResolution,
|
||||||
maybe_node_modules_path: Option<PathBuf>,
|
maybe_node_modules_path: Option<PathBuf>,
|
||||||
|
@ -283,6 +285,7 @@ pub fn create_npm_fs_resolver(
|
||||||
match maybe_node_modules_path {
|
match maybe_node_modules_path {
|
||||||
Some(node_modules_folder) => Arc::new(LocalNpmPackageResolver::new(
|
Some(node_modules_folder) => Arc::new(LocalNpmPackageResolver::new(
|
||||||
cache,
|
cache,
|
||||||
|
progress_bar.clone(),
|
||||||
registry_url,
|
registry_url,
|
||||||
node_modules_folder,
|
node_modules_folder,
|
||||||
resolution,
|
resolution,
|
||||||
|
|
|
@ -239,6 +239,7 @@ impl ProcState {
|
||||||
);
|
);
|
||||||
let npm_fs_resolver = create_npm_fs_resolver(
|
let npm_fs_resolver = create_npm_fs_resolver(
|
||||||
npm_cache,
|
npm_cache,
|
||||||
|
&progress_bar,
|
||||||
npm_registry_url,
|
npm_registry_url,
|
||||||
npm_resolution.clone(),
|
npm_resolution.clone(),
|
||||||
cli_options.node_modules_dir_path(),
|
cli_options.node_modules_dir_path(),
|
||||||
|
|
|
@ -7,6 +7,7 @@ use util::assert_contains;
|
||||||
use util::env_vars_for_npm_tests;
|
use util::env_vars_for_npm_tests;
|
||||||
use util::env_vars_for_npm_tests_no_sync_download;
|
use util::env_vars_for_npm_tests_no_sync_download;
|
||||||
use util::http_server;
|
use util::http_server;
|
||||||
|
use util::TestContextBuilder;
|
||||||
|
|
||||||
// NOTE: See how to make test npm packages at ./testdata/npm/README.md
|
// NOTE: See how to make test npm packages at ./testdata/npm/README.md
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@ itest!(conditional_exports {
|
||||||
itest!(conditional_exports_node_modules_dir {
|
itest!(conditional_exports_node_modules_dir {
|
||||||
args:
|
args:
|
||||||
"run --allow-read --node-modules-dir $TESTDATA/npm/conditional_exports/main.js",
|
"run --allow-read --node-modules-dir $TESTDATA/npm/conditional_exports/main.js",
|
||||||
output: "npm/conditional_exports/main.out",
|
output: "npm/conditional_exports/main_node_modules.out",
|
||||||
envs: env_vars_for_npm_tests(),
|
envs: env_vars_for_npm_tests(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
temp_cwd: true,
|
temp_cwd: true,
|
||||||
|
@ -729,7 +730,7 @@ itest!(node_modules_dir_require_added_node_modules_folder {
|
||||||
|
|
||||||
itest!(node_modules_dir_with_deps {
|
itest!(node_modules_dir_with_deps {
|
||||||
args: "run --allow-read --allow-env --node-modules-dir $TESTDATA/npm/cjs_with_deps/main.js",
|
args: "run --allow-read --allow-env --node-modules-dir $TESTDATA/npm/cjs_with_deps/main.js",
|
||||||
output: "npm/cjs_with_deps/main.out",
|
output: "npm/cjs_with_deps/main_node_modules.out",
|
||||||
envs: env_vars_for_npm_tests(),
|
envs: env_vars_for_npm_tests(),
|
||||||
http_server: true,
|
http_server: true,
|
||||||
temp_cwd: true,
|
temp_cwd: true,
|
||||||
|
@ -1392,39 +1393,26 @@ fn auto_discover_lock_file() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn peer_deps_with_copied_folders_and_lockfile() {
|
fn peer_deps_with_copied_folders_and_lockfile() {
|
||||||
let _server = http_server();
|
let context = TestContextBuilder::for_npm()
|
||||||
|
.use_sync_npm_download()
|
||||||
|
.use_separate_deno_dir() // the "npm" folder means something in the deno dir, so use a separate folder
|
||||||
|
.use_copy_temp_dir("npm/peer_deps_with_copied_folders")
|
||||||
|
.cwd("npm/peer_deps_with_copied_folders")
|
||||||
|
.build();
|
||||||
|
|
||||||
let deno_dir = util::new_deno_dir();
|
let deno_dir = context.deno_dir();
|
||||||
let temp_dir = util::TempDir::new();
|
let temp_dir = context.temp_dir();
|
||||||
|
let temp_dir_sub_path =
|
||||||
|
temp_dir.path().join("npm/peer_deps_with_copied_folders");
|
||||||
|
|
||||||
// write empty config file
|
// write empty config file
|
||||||
temp_dir.write("deno.json", "{}");
|
temp_dir.write("npm/peer_deps_with_copied_folders/deno.json", "{}");
|
||||||
let test_folder_path = test_util::testdata_path()
|
|
||||||
.join("npm")
|
|
||||||
.join("peer_deps_with_copied_folders");
|
|
||||||
let main_contents =
|
|
||||||
std::fs::read_to_string(test_folder_path.join("main.ts")).unwrap();
|
|
||||||
temp_dir.write("./main.ts", main_contents);
|
|
||||||
|
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let output = context.new_command().args("run -A main.ts").run();
|
||||||
.current_dir(temp_dir.path())
|
output.assert_exit_code(0);
|
||||||
.arg("run")
|
output.assert_matches_file("npm/peer_deps_with_copied_folders/main.out");
|
||||||
.arg("-A")
|
|
||||||
.arg("main.ts")
|
|
||||||
.envs(env_vars_for_npm_tests())
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
let output = deno.wait_with_output().unwrap();
|
|
||||||
assert!(output.status.success());
|
|
||||||
|
|
||||||
let expected_output =
|
assert!(temp_dir_sub_path.join("deno.lock").exists());
|
||||||
std::fs::read_to_string(test_folder_path.join("main.out")).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(String::from_utf8(output.stderr).unwrap(), expected_output);
|
|
||||||
|
|
||||||
assert!(temp_dir.path().join("deno.lock").exists());
|
|
||||||
let grandchild_path = deno_dir
|
let grandchild_path = deno_dir
|
||||||
.path()
|
.path()
|
||||||
.join("npm")
|
.join("npm")
|
||||||
|
@ -1437,52 +1425,26 @@ fn peer_deps_with_copied_folders_and_lockfile() {
|
||||||
assert!(grandchild_path.join("1.0.0_1").exists()); // copy folder, which is hardlinked
|
assert!(grandchild_path.join("1.0.0_1").exists()); // copy folder, which is hardlinked
|
||||||
|
|
||||||
// run again
|
// run again
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let output = context.new_command().args("run -A main.ts").run();
|
||||||
.current_dir(temp_dir.path())
|
output.assert_exit_code(0);
|
||||||
.arg("run")
|
output.assert_matches_text("1\n2\n");
|
||||||
.arg("-A")
|
|
||||||
.arg("main.ts")
|
|
||||||
.envs(env_vars_for_npm_tests())
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
let output = deno.wait_with_output().unwrap();
|
|
||||||
assert_eq!(String::from_utf8(output.stderr).unwrap(), "1\n2\n");
|
|
||||||
assert!(output.status.success());
|
|
||||||
|
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
// run with reload
|
||||||
.current_dir(temp_dir.path())
|
let output = context.new_command().args("run -A --reload main.ts").run();
|
||||||
.arg("run")
|
output.assert_exit_code(0);
|
||||||
.arg("--reload")
|
output.assert_matches_file("npm/peer_deps_with_copied_folders/main.out");
|
||||||
.arg("-A")
|
|
||||||
.arg("main.ts")
|
|
||||||
.envs(env_vars_for_npm_tests())
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
let output = deno.wait_with_output().unwrap();
|
|
||||||
assert_eq!(String::from_utf8(output.stderr).unwrap(), expected_output);
|
|
||||||
assert!(output.status.success());
|
|
||||||
|
|
||||||
// now run with local node modules
|
// now run with local node modules
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let output = context
|
||||||
.current_dir(temp_dir.path())
|
.new_command()
|
||||||
.arg("run")
|
.args("run -A --node-modules-dir main.ts")
|
||||||
.arg("--node-modules-dir")
|
.run();
|
||||||
.arg("-A")
|
output.assert_exit_code(0);
|
||||||
.arg("main.ts")
|
output.assert_matches_file(
|
||||||
.envs(env_vars_for_npm_tests())
|
"npm/peer_deps_with_copied_folders/main_node_modules.out",
|
||||||
.stdout(Stdio::piped())
|
);
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
let output = deno.wait_with_output().unwrap();
|
|
||||||
assert_eq!(String::from_utf8(output.stderr).unwrap(), "1\n2\n");
|
|
||||||
assert!(output.status.success());
|
|
||||||
|
|
||||||
let deno_folder = temp_dir.path().join("node_modules").join(".deno");
|
let deno_folder = temp_dir_sub_path.join("node_modules").join(".deno");
|
||||||
assert!(deno_folder
|
assert!(deno_folder
|
||||||
.join("@denotest+peer-dep-test-grandchild@1.0.0")
|
.join("@denotest+peer-dep-test-grandchild@1.0.0")
|
||||||
.exists());
|
.exists());
|
||||||
|
@ -1491,55 +1453,32 @@ fn peer_deps_with_copied_folders_and_lockfile() {
|
||||||
.exists()); // copy folder
|
.exists()); // copy folder
|
||||||
|
|
||||||
// now again run with local node modules
|
// now again run with local node modules
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let output = context
|
||||||
.current_dir(temp_dir.path())
|
.new_command()
|
||||||
.arg("run")
|
.args("run -A --node-modules-dir main.ts")
|
||||||
.arg("--node-modules-dir")
|
.run();
|
||||||
.arg("-A")
|
output.assert_exit_code(0);
|
||||||
.arg("main.ts")
|
output.assert_matches_text("1\n2\n");
|
||||||
.envs(env_vars_for_npm_tests())
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
let output = deno.wait_with_output().unwrap();
|
|
||||||
assert!(output.status.success());
|
|
||||||
assert_eq!(String::from_utf8(output.stderr).unwrap(), "1\n2\n");
|
|
||||||
|
|
||||||
// now ensure it works with reloading
|
// now ensure it works with reloading
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let output = context
|
||||||
.current_dir(temp_dir.path())
|
.new_command()
|
||||||
.arg("run")
|
.args("run -A --reload --node-modules-dir main.ts")
|
||||||
.arg("--node-modules-dir")
|
.run();
|
||||||
.arg("--reload")
|
output.assert_exit_code(0);
|
||||||
.arg("-A")
|
output.assert_matches_file(
|
||||||
.arg("main.ts")
|
"npm/peer_deps_with_copied_folders/main_node_modules_reload.out",
|
||||||
.envs(env_vars_for_npm_tests())
|
);
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
let output = deno.wait_with_output().unwrap();
|
|
||||||
assert!(output.status.success());
|
|
||||||
assert_eq!(String::from_utf8(output.stderr).unwrap(), expected_output);
|
|
||||||
|
|
||||||
// now ensure it works with reloading and no lockfile
|
// now ensure it works with reloading and no lockfile
|
||||||
let deno = util::deno_cmd_with_deno_dir(&deno_dir)
|
let output = context
|
||||||
.current_dir(temp_dir.path())
|
.new_command()
|
||||||
.arg("run")
|
.args("run -A --reload --node-modules-dir --no-lock main.ts")
|
||||||
.arg("--node-modules-dir")
|
.run();
|
||||||
.arg("--no-lock")
|
output.assert_exit_code(0);
|
||||||
.arg("--reload")
|
output.assert_matches_file(
|
||||||
.arg("-A")
|
"npm/peer_deps_with_copied_folders/main_node_modules_reload.out",
|
||||||
.arg("main.ts")
|
);
|
||||||
.envs(env_vars_for_npm_tests())
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
let output = deno.wait_with_output().unwrap();
|
|
||||||
assert_eq!(String::from_utf8(output.stderr).unwrap(), expected_output,);
|
|
||||||
assert!(output.status.success());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
itest!(info_peer_deps {
|
itest!(info_peer_deps {
|
||||||
|
|
43
cli/tests/testdata/npm/cjs_with_deps/main_node_modules.out
vendored
Normal file
43
cli/tests/testdata/npm/cjs_with_deps/main_node_modules.out
vendored
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
Download http://localhost:4545/npm/registry/chalk
|
||||||
|
Download http://localhost:4545/npm/registry/chai
|
||||||
|
Download http://localhost:4545/npm/registry/ansi-styles
|
||||||
|
Download http://localhost:4545/npm/registry/supports-color
|
||||||
|
Download http://localhost:4545/npm/registry/assertion-error
|
||||||
|
Download http://localhost:4545/npm/registry/check-error
|
||||||
|
Download http://localhost:4545/npm/registry/deep-eql
|
||||||
|
Download http://localhost:4545/npm/registry/get-func-name
|
||||||
|
Download http://localhost:4545/npm/registry/loupe
|
||||||
|
Download http://localhost:4545/npm/registry/pathval
|
||||||
|
Download http://localhost:4545/npm/registry/type-detect
|
||||||
|
Download http://localhost:4545/npm/registry/color-convert
|
||||||
|
Download http://localhost:4545/npm/registry/has-flag
|
||||||
|
Download http://localhost:4545/npm/registry/color-name
|
||||||
|
Download http://localhost:4545/npm/registry/ansi-styles/ansi-styles-4.3.0.tgz
|
||||||
|
Initialize ansi-styles@4.3.0
|
||||||
|
Download http://localhost:4545/npm/registry/assertion-error/assertion-error-1.1.0.tgz
|
||||||
|
Initialize assertion-error@1.1.0
|
||||||
|
Download http://localhost:4545/npm/registry/chai/chai-4.3.6.tgz
|
||||||
|
Initialize chai@4.3.6
|
||||||
|
Download http://localhost:4545/npm/registry/chalk/chalk-4.1.2.tgz
|
||||||
|
Initialize chalk@4.1.2
|
||||||
|
Download http://localhost:4545/npm/registry/check-error/check-error-1.0.2.tgz
|
||||||
|
Initialize check-error@1.0.2
|
||||||
|
Download http://localhost:4545/npm/registry/color-convert/color-convert-2.0.1.tgz
|
||||||
|
Initialize color-convert@2.0.1
|
||||||
|
Download http://localhost:4545/npm/registry/color-name/color-name-1.1.4.tgz
|
||||||
|
Initialize color-name@1.1.4
|
||||||
|
Download http://localhost:4545/npm/registry/deep-eql/deep-eql-3.0.1.tgz
|
||||||
|
Initialize deep-eql@3.0.1
|
||||||
|
Download http://localhost:4545/npm/registry/get-func-name/get-func-name-2.0.0.tgz
|
||||||
|
Initialize get-func-name@2.0.0
|
||||||
|
Download http://localhost:4545/npm/registry/has-flag/has-flag-4.0.0.tgz
|
||||||
|
Initialize has-flag@4.0.0
|
||||||
|
Download http://localhost:4545/npm/registry/loupe/loupe-2.3.4.tgz
|
||||||
|
Initialize loupe@2.3.4
|
||||||
|
Download http://localhost:4545/npm/registry/pathval/pathval-1.1.1.tgz
|
||||||
|
Initialize pathval@1.1.1
|
||||||
|
Download http://localhost:4545/npm/registry/supports-color/supports-color-7.2.0.tgz
|
||||||
|
Initialize supports-color@7.2.0
|
||||||
|
Download http://localhost:4545/npm/registry/type-detect/type-detect-4.0.8.tgz
|
||||||
|
Initialize type-detect@4.0.8
|
||||||
|
chalk cjs loads
|
26
cli/tests/testdata/npm/cjs_yargs/main.out
vendored
26
cli/tests/testdata/npm/cjs_yargs/main.out
vendored
|
@ -25,30 +25,56 @@ Download http://localhost:4545/npm/registry/p-limit
|
||||||
Download http://localhost:4545/npm/registry/color-name
|
Download http://localhost:4545/npm/registry/color-name
|
||||||
Download http://localhost:4545/npm/registry/p-try
|
Download http://localhost:4545/npm/registry/p-try
|
||||||
Download http://localhost:4545/npm/registry/ansi-regex/ansi-regex-5.0.1.tgz
|
Download http://localhost:4545/npm/registry/ansi-regex/ansi-regex-5.0.1.tgz
|
||||||
|
Initialize ansi-regex@5.0.1
|
||||||
Download http://localhost:4545/npm/registry/ansi-styles/ansi-styles-4.3.0.tgz
|
Download http://localhost:4545/npm/registry/ansi-styles/ansi-styles-4.3.0.tgz
|
||||||
|
Initialize ansi-styles@4.3.0
|
||||||
Download http://localhost:4545/npm/registry/camelcase/camelcase-5.3.1.tgz
|
Download http://localhost:4545/npm/registry/camelcase/camelcase-5.3.1.tgz
|
||||||
|
Initialize camelcase@5.3.1
|
||||||
Download http://localhost:4545/npm/registry/cliui/cliui-6.0.0.tgz
|
Download http://localhost:4545/npm/registry/cliui/cliui-6.0.0.tgz
|
||||||
|
Initialize cliui@6.0.0
|
||||||
Download http://localhost:4545/npm/registry/color-convert/color-convert-2.0.1.tgz
|
Download http://localhost:4545/npm/registry/color-convert/color-convert-2.0.1.tgz
|
||||||
|
Initialize color-convert@2.0.1
|
||||||
Download http://localhost:4545/npm/registry/color-name/color-name-1.1.4.tgz
|
Download http://localhost:4545/npm/registry/color-name/color-name-1.1.4.tgz
|
||||||
|
Initialize color-name@1.1.4
|
||||||
Download http://localhost:4545/npm/registry/decamelize/decamelize-1.2.0.tgz
|
Download http://localhost:4545/npm/registry/decamelize/decamelize-1.2.0.tgz
|
||||||
|
Initialize decamelize@1.2.0
|
||||||
Download http://localhost:4545/npm/registry/emoji-regex/emoji-regex-8.0.0.tgz
|
Download http://localhost:4545/npm/registry/emoji-regex/emoji-regex-8.0.0.tgz
|
||||||
|
Initialize emoji-regex@8.0.0
|
||||||
Download http://localhost:4545/npm/registry/find-up/find-up-4.1.0.tgz
|
Download http://localhost:4545/npm/registry/find-up/find-up-4.1.0.tgz
|
||||||
|
Initialize find-up@4.1.0
|
||||||
Download http://localhost:4545/npm/registry/get-caller-file/get-caller-file-2.0.5.tgz
|
Download http://localhost:4545/npm/registry/get-caller-file/get-caller-file-2.0.5.tgz
|
||||||
|
Initialize get-caller-file@2.0.5
|
||||||
Download http://localhost:4545/npm/registry/is-fullwidth-code-point/is-fullwidth-code-point-3.0.0.tgz
|
Download http://localhost:4545/npm/registry/is-fullwidth-code-point/is-fullwidth-code-point-3.0.0.tgz
|
||||||
|
Initialize is-fullwidth-code-point@3.0.0
|
||||||
Download http://localhost:4545/npm/registry/locate-path/locate-path-5.0.0.tgz
|
Download http://localhost:4545/npm/registry/locate-path/locate-path-5.0.0.tgz
|
||||||
|
Initialize locate-path@5.0.0
|
||||||
Download http://localhost:4545/npm/registry/p-limit/p-limit-2.3.0.tgz
|
Download http://localhost:4545/npm/registry/p-limit/p-limit-2.3.0.tgz
|
||||||
|
Initialize p-limit@2.3.0
|
||||||
Download http://localhost:4545/npm/registry/p-locate/p-locate-4.1.0.tgz
|
Download http://localhost:4545/npm/registry/p-locate/p-locate-4.1.0.tgz
|
||||||
|
Initialize p-locate@4.1.0
|
||||||
Download http://localhost:4545/npm/registry/p-try/p-try-2.2.0.tgz
|
Download http://localhost:4545/npm/registry/p-try/p-try-2.2.0.tgz
|
||||||
|
Initialize p-try@2.2.0
|
||||||
Download http://localhost:4545/npm/registry/path-exists/path-exists-4.0.0.tgz
|
Download http://localhost:4545/npm/registry/path-exists/path-exists-4.0.0.tgz
|
||||||
|
Initialize path-exists@4.0.0
|
||||||
Download http://localhost:4545/npm/registry/require-directory/require-directory-2.1.1.tgz
|
Download http://localhost:4545/npm/registry/require-directory/require-directory-2.1.1.tgz
|
||||||
|
Initialize require-directory@2.1.1
|
||||||
Download http://localhost:4545/npm/registry/require-main-filename/require-main-filename-2.0.0.tgz
|
Download http://localhost:4545/npm/registry/require-main-filename/require-main-filename-2.0.0.tgz
|
||||||
|
Initialize require-main-filename@2.0.0
|
||||||
Download http://localhost:4545/npm/registry/set-blocking/set-blocking-2.0.0.tgz
|
Download http://localhost:4545/npm/registry/set-blocking/set-blocking-2.0.0.tgz
|
||||||
|
Initialize set-blocking@2.0.0
|
||||||
Download http://localhost:4545/npm/registry/string-width/string-width-4.2.3.tgz
|
Download http://localhost:4545/npm/registry/string-width/string-width-4.2.3.tgz
|
||||||
|
Initialize string-width@4.2.3
|
||||||
Download http://localhost:4545/npm/registry/strip-ansi/strip-ansi-6.0.1.tgz
|
Download http://localhost:4545/npm/registry/strip-ansi/strip-ansi-6.0.1.tgz
|
||||||
|
Initialize strip-ansi@6.0.1
|
||||||
Download http://localhost:4545/npm/registry/which-module/which-module-2.0.0.tgz
|
Download http://localhost:4545/npm/registry/which-module/which-module-2.0.0.tgz
|
||||||
|
Initialize which-module@2.0.0
|
||||||
Download http://localhost:4545/npm/registry/wrap-ansi/wrap-ansi-6.2.0.tgz
|
Download http://localhost:4545/npm/registry/wrap-ansi/wrap-ansi-6.2.0.tgz
|
||||||
|
Initialize wrap-ansi@6.2.0
|
||||||
Download http://localhost:4545/npm/registry/y18n/y18n-4.0.3.tgz
|
Download http://localhost:4545/npm/registry/y18n/y18n-4.0.3.tgz
|
||||||
|
Initialize y18n@4.0.3
|
||||||
Download http://localhost:4545/npm/registry/yargs/yargs-15.4.1.tgz
|
Download http://localhost:4545/npm/registry/yargs/yargs-15.4.1.tgz
|
||||||
|
Initialize yargs@15.4.1
|
||||||
Download http://localhost:4545/npm/registry/yargs-parser/yargs-parser-18.1.3.tgz
|
Download http://localhost:4545/npm/registry/yargs-parser/yargs-parser-18.1.3.tgz
|
||||||
|
Initialize yargs-parser@18.1.3
|
||||||
start server on :8000
|
start server on :8000
|
||||||
[WILDCARD]
|
[WILDCARD]
|
||||||
|
|
18
cli/tests/testdata/npm/conditional_exports/main_node_modules.out
vendored
Normal file
18
cli/tests/testdata/npm/conditional_exports/main_node_modules.out
vendored
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/conditional-exports
|
||||||
|
Download http://localhost:4545/npm/registry/supports-esm
|
||||||
|
Download http://localhost:4545/npm/registry/has-package-exports
|
||||||
|
Download http://localhost:4545/npm/registry/@ljharb/has-package-exports-patterns
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/conditional-exports/1.0.0.tgz
|
||||||
|
Initialize @denotest/conditional-exports@1.0.0
|
||||||
|
Download http://localhost:4545/npm/registry/@ljharb/has-package-exports-patterns/has-package-exports-patterns-0.0.2.tgz
|
||||||
|
Initialize @ljharb/has-package-exports-patterns@0.0.2
|
||||||
|
Download http://localhost:4545/npm/registry/has-package-exports/has-package-exports-1.3.0.tgz
|
||||||
|
Initialize has-package-exports@1.3.0
|
||||||
|
Download http://localhost:4545/npm/registry/supports-esm/supports-esm-1.0.0.tgz
|
||||||
|
Initialize supports-esm@1.0.0
|
||||||
|
{ hello: "from esm" }
|
||||||
|
{ hello: "from foo" }
|
||||||
|
{ hello: "from esm client" }
|
||||||
|
{ hello: "from esm client foo" }
|
||||||
|
{ hello: "from esm client bar" }
|
||||||
|
true
|
|
@ -1,7 +1,9 @@
|
||||||
Download http://localhost:4545/npm/registry/@denotest/MixedCase
|
Download http://localhost:4545/npm/registry/@denotest/MixedCase
|
||||||
Download http://localhost:4545/npm/registry/@denotest/CAPITALS
|
Download http://localhost:4545/npm/registry/@denotest/CAPITALS
|
||||||
Download http://localhost:4545/npm/registry/@denotest/CAPITALS/1.0.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/CAPITALS/1.0.0.tgz
|
||||||
|
Initialize @denotest/CAPITALS@1.0.0
|
||||||
Download http://localhost:4545/npm/registry/@denotest/MixedCase/1.0.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/MixedCase/1.0.0.tgz
|
||||||
|
Initialize @denotest/MixedCase@1.0.0
|
||||||
5
|
5
|
||||||
true
|
true
|
||||||
true
|
true
|
||||||
|
|
7
cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules.out
vendored
Normal file
7
cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules.out
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Initialize @denotest/peer-dep-test-child@1.0.0
|
||||||
|
Initialize @denotest/peer-dep-test-child@2.0.0
|
||||||
|
Initialize @denotest/peer-dep-test-grandchild@1.0.0
|
||||||
|
Initialize @denotest/peer-dep-test-peer@1.0.0
|
||||||
|
Initialize @denotest/peer-dep-test-peer@2.0.0
|
||||||
|
1
|
||||||
|
2
|
15
cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules_reload.out
vendored
Normal file
15
cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules_reload.out
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-child
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-grandchild
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-peer
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-child/1.0.0.tgz
|
||||||
|
Initialize @denotest/peer-dep-test-child@1.0.0
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-child/2.0.0.tgz
|
||||||
|
Initialize @denotest/peer-dep-test-child@2.0.0
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-grandchild/1.0.0.tgz
|
||||||
|
Initialize @denotest/peer-dep-test-grandchild@1.0.0
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-peer/1.0.0.tgz
|
||||||
|
Initialize @denotest/peer-dep-test-peer@1.0.0
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/peer-dep-test-peer/2.0.0.tgz
|
||||||
|
Initialize @denotest/peer-dep-test-peer@2.0.0
|
||||||
|
1
|
||||||
|
2
|
|
@ -1,5 +1,6 @@
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
||||||
|
Initialize @denotest/esm-basic@1.0.0
|
||||||
Check file:///[WILDCARD]/lib.bench.ts
|
Check file:///[WILDCARD]/lib.bench.ts
|
||||||
cpu: [WILDCARD]
|
cpu: [WILDCARD]
|
||||||
runtime: [WILDCARD]
|
runtime: [WILDCARD]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
||||||
|
Initialize @denotest/esm-basic@1.0.0
|
||||||
Check file://[WILDCARD]/lib.test.ts
|
Check file://[WILDCARD]/lib.test.ts
|
||||||
running 1 test from [WILDCARD]lib.test.ts
|
running 1 test from [WILDCARD]lib.test.ts
|
||||||
should add ... ok ([WILDCARD])
|
should add ... ok ([WILDCARD])
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
||||||
|
Initialize @denotest/esm-basic@1.0.0
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
||||||
|
Initialize @denotest/esm-basic@1.0.0
|
||||||
Check file://[WILDCARD]/main.ts
|
Check file://[WILDCARD]/main.ts
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic
|
||||||
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz
|
||||||
|
Initialize @denotest/esm-basic@1.0.0
|
||||||
2
|
2
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
Download http://localhost:4545/npm/registry/@denotest/bin
|
Download http://localhost:4545/npm/registry/@denotest/bin
|
||||||
Download http://localhost:4545/npm/registry/@denotest/bin/1.0.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/bin/1.0.0.tgz
|
||||||
|
Initialize @denotest/bin@1.0.0
|
||||||
Warning Currently only basic package.json `scripts` are supported. Programs like `rimraf` or `cross-env` will not work correctly. This will be fixed in the upcoming release.
|
Warning Currently only basic package.json `scripts` are supported. Programs like `rimraf` or `cross-env` will not work correctly. This will be fixed in the upcoming release.
|
||||||
Task bin cli-esm testing this out "asdf"
|
Task bin cli-esm testing this out "asdf"
|
||||||
testing
|
testing
|
||||||
|
|
2
cli/tests/testdata/task/package_json/bin.out
vendored
2
cli/tests/testdata/task/package_json/bin.out
vendored
|
@ -1,6 +1,8 @@
|
||||||
Download http://localhost:4545/npm/registry/@denotest/bin
|
Download http://localhost:4545/npm/registry/@denotest/bin
|
||||||
Download http://localhost:4545/npm/registry/@denotest/bin/0.5.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/bin/0.5.0.tgz
|
||||||
|
Initialize @denotest/bin@0.5.0
|
||||||
Download http://localhost:4545/npm/registry/@denotest/bin/1.0.0.tgz
|
Download http://localhost:4545/npm/registry/@denotest/bin/1.0.0.tgz
|
||||||
|
Initialize @denotest/bin@1.0.0
|
||||||
Warning Currently only basic package.json `scripts` are supported. Programs like `rimraf` or `cross-env` will not work correctly. This will be fixed in the upcoming release.
|
Warning Currently only basic package.json `scripts` are supported. Programs like `rimraf` or `cross-env` will not work correctly. This will be fixed in the upcoming release.
|
||||||
Task bin @denotest/bin hi && cli-esm testing this out && npx cli-cjs test "extra"
|
Task bin @denotest/bin hi && cli-esm testing this out && npx cli-cjs test "extra"
|
||||||
hi
|
hi
|
||||||
|
|
|
@ -27,6 +27,7 @@ mod renderer;
|
||||||
pub enum ProgressMessagePrompt {
|
pub enum ProgressMessagePrompt {
|
||||||
Download,
|
Download,
|
||||||
Blocking,
|
Blocking,
|
||||||
|
Initialize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgressMessagePrompt {
|
impl ProgressMessagePrompt {
|
||||||
|
@ -34,6 +35,9 @@ impl ProgressMessagePrompt {
|
||||||
match self {
|
match self {
|
||||||
ProgressMessagePrompt::Download => colors::green("Download").to_string(),
|
ProgressMessagePrompt::Download => colors::green("Download").to_string(),
|
||||||
ProgressMessagePrompt::Blocking => colors::cyan("Blocking").to_string(),
|
ProgressMessagePrompt::Blocking => colors::cyan("Blocking").to_string(),
|
||||||
|
ProgressMessagePrompt::Initialize => {
|
||||||
|
colors::green("Initialize").to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +255,7 @@ impl DrawThreadRenderer for ProgressBarInner {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ProgressBar {
|
pub struct ProgressBar {
|
||||||
inner: Option<ProgressBarInner>,
|
inner: ProgressBarInner,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgressBar {
|
impl ProgressBar {
|
||||||
|
@ -262,17 +266,14 @@ impl ProgressBar {
|
||||||
|
|
||||||
pub fn new(style: ProgressBarStyle) -> Self {
|
pub fn new(style: ProgressBarStyle) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: match Self::are_supported() {
|
inner: ProgressBarInner::new(match style {
|
||||||
true => Some(ProgressBarInner::new(match style {
|
ProgressBarStyle::DownloadBars => {
|
||||||
ProgressBarStyle::DownloadBars => {
|
Arc::new(renderer::BarProgressBarRenderer)
|
||||||
Arc::new(renderer::BarProgressBarRenderer)
|
}
|
||||||
}
|
ProgressBarStyle::TextOnly => {
|
||||||
ProgressBarStyle::TextOnly => {
|
Arc::new(renderer::TextOnlyProgressBarRenderer)
|
||||||
Arc::new(renderer::TextOnlyProgressBarRenderer)
|
}
|
||||||
}
|
}),
|
||||||
})),
|
|
||||||
false => None,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,34 +286,29 @@ impl ProgressBar {
|
||||||
kind: ProgressMessagePrompt,
|
kind: ProgressMessagePrompt,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
) -> UpdateGuard {
|
) -> UpdateGuard {
|
||||||
match &self.inner {
|
// only check if progress bars are supported once we go
|
||||||
Some(inner) => {
|
// to update so that we lazily initialize the progress bar
|
||||||
let entry = inner.add_entry(kind, msg.to_string());
|
if ProgressBar::are_supported() {
|
||||||
UpdateGuard {
|
let entry = self.inner.add_entry(kind, msg.to_string());
|
||||||
maybe_entry: Some(entry),
|
UpdateGuard {
|
||||||
}
|
maybe_entry: Some(entry),
|
||||||
}
|
}
|
||||||
None => {
|
} else {
|
||||||
// if we're not running in TTY, fallback to using logger crate
|
// if we're not running in TTY, fallback to using logger crate
|
||||||
if !msg.is_empty() {
|
if !msg.is_empty() {
|
||||||
log::log!(log::Level::Info, "{} {}", kind.as_text(), msg);
|
log::log!(log::Level::Info, "{} {}", kind.as_text(), msg);
|
||||||
}
|
|
||||||
UpdateGuard { maybe_entry: None }
|
|
||||||
}
|
}
|
||||||
|
UpdateGuard { maybe_entry: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_guard(&self) -> ClearGuard {
|
pub fn clear_guard(&self) -> ClearGuard {
|
||||||
if let Some(inner) = &self.inner {
|
self.inner.increment_clear();
|
||||||
inner.increment_clear();
|
|
||||||
}
|
|
||||||
ClearGuard { pb: self.clone() }
|
ClearGuard { pb: self.clone() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decrement_clear(&self) {
|
fn decrement_clear(&self) {
|
||||||
if let Some(inner) = &self.inner {
|
self.inner.decrement_clear();
|
||||||
inner.decrement_clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ use crate::TempDir;
|
||||||
pub struct TestContextBuilder {
|
pub struct TestContextBuilder {
|
||||||
use_http_server: bool,
|
use_http_server: bool,
|
||||||
use_temp_cwd: bool,
|
use_temp_cwd: bool,
|
||||||
|
use_separate_deno_dir: bool,
|
||||||
/// Copies the files at the specified directory in the "testdata" directory
|
/// Copies the files at the specified directory in the "testdata" directory
|
||||||
/// to the temp folder and runs the test from there. This is useful when
|
/// to the temp folder and runs the test from there. This is useful when
|
||||||
/// the test creates files in the testdata directory (ex. a node_modules folder)
|
/// the test creates files in the testdata directory (ex. a node_modules folder)
|
||||||
|
@ -60,6 +61,15 @@ impl TestContextBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// By default, the temp_dir and the deno_dir will be shared.
|
||||||
|
/// In some cases, that might cause an issue though, so calling
|
||||||
|
/// this will use a separate directory for the deno dir and the
|
||||||
|
/// temp directory.
|
||||||
|
pub fn use_separate_deno_dir(&mut self) -> &mut Self {
|
||||||
|
self.use_separate_deno_dir = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Copies the files at the specified directory in the "testdata" directory
|
/// Copies the files at the specified directory in the "testdata" directory
|
||||||
/// to the temp folder and runs the test from there. This is useful when
|
/// to the temp folder and runs the test from there. This is useful when
|
||||||
/// the test creates files in the testdata directory (ex. a node_modules folder)
|
/// the test creates files in the testdata directory (ex. a node_modules folder)
|
||||||
|
@ -102,12 +112,17 @@ impl TestContextBuilder {
|
||||||
|
|
||||||
pub fn build(&self) -> TestContext {
|
pub fn build(&self) -> TestContext {
|
||||||
let deno_dir = new_deno_dir(); // keep this alive for the test
|
let deno_dir = new_deno_dir(); // keep this alive for the test
|
||||||
|
let temp_dir = if self.use_separate_deno_dir {
|
||||||
|
TempDir::new()
|
||||||
|
} else {
|
||||||
|
deno_dir.clone()
|
||||||
|
};
|
||||||
let testdata_dir = if let Some(temp_copy_dir) = &self.copy_temp_dir {
|
let testdata_dir = if let Some(temp_copy_dir) = &self.copy_temp_dir {
|
||||||
let test_data_path = testdata_path().join(temp_copy_dir);
|
let test_data_path = testdata_path().join(temp_copy_dir);
|
||||||
let temp_copy_dir = deno_dir.path().join(temp_copy_dir);
|
let temp_copy_dir = temp_dir.path().join(temp_copy_dir);
|
||||||
std::fs::create_dir_all(&temp_copy_dir).unwrap();
|
std::fs::create_dir_all(&temp_copy_dir).unwrap();
|
||||||
copy_dir_recursive(&test_data_path, &temp_copy_dir).unwrap();
|
copy_dir_recursive(&test_data_path, &temp_copy_dir).unwrap();
|
||||||
deno_dir.path().to_owned()
|
temp_dir.path().to_owned()
|
||||||
} else {
|
} else {
|
||||||
testdata_path()
|
testdata_path()
|
||||||
};
|
};
|
||||||
|
@ -128,6 +143,7 @@ impl TestContextBuilder {
|
||||||
use_temp_cwd: self.use_temp_cwd,
|
use_temp_cwd: self.use_temp_cwd,
|
||||||
_http_server_guard: http_server_guard,
|
_http_server_guard: http_server_guard,
|
||||||
deno_dir,
|
deno_dir,
|
||||||
|
temp_dir,
|
||||||
testdata_dir,
|
testdata_dir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,6 +157,7 @@ pub struct TestContext {
|
||||||
cwd: Option<String>,
|
cwd: Option<String>,
|
||||||
_http_server_guard: Option<Rc<HttpServerGuard>>,
|
_http_server_guard: Option<Rc<HttpServerGuard>>,
|
||||||
deno_dir: TempDir,
|
deno_dir: TempDir,
|
||||||
|
temp_dir: TempDir,
|
||||||
testdata_dir: PathBuf,
|
testdata_dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +180,10 @@ impl TestContext {
|
||||||
&self.deno_dir
|
&self.deno_dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn temp_dir(&self) -> &TempDir {
|
||||||
|
&self.temp_dir
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_command(&self) -> TestCommandBuilder {
|
pub fn new_command(&self) -> TestCommandBuilder {
|
||||||
TestCommandBuilder {
|
TestCommandBuilder {
|
||||||
command_name: self.deno_exe.to_string_lossy().to_string(),
|
command_name: self.deno_exe.to_string_lossy().to_string(),
|
||||||
|
@ -268,7 +289,7 @@ impl TestCommandBuilder {
|
||||||
let cwd = self.cwd.as_ref().or(self.context.cwd.as_ref());
|
let cwd = self.cwd.as_ref().or(self.context.cwd.as_ref());
|
||||||
let cwd = if self.context.use_temp_cwd {
|
let cwd = if self.context.use_temp_cwd {
|
||||||
assert!(cwd.is_none());
|
assert!(cwd.is_none());
|
||||||
self.context.deno_dir.path().to_owned()
|
self.context.temp_dir.path().to_owned()
|
||||||
} else if let Some(cwd_) = cwd {
|
} else if let Some(cwd_) = cwd {
|
||||||
self.context.testdata_dir.join(cwd_)
|
self.context.testdata_dir.join(cwd_)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue