diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index faad942950..50cc0326e3 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -345,11 +345,12 @@ fn create_lsp_structs( registry_url.clone(), npm_cache.clone(), http_client, - progress_bar, + progress_bar.clone(), ); let resolution = NpmResolution::new(api.clone(), None, None); let fs_resolver = create_npm_fs_resolver( npm_cache.clone(), + &progress_bar, registry_url.clone(), resolution.clone(), None, @@ -609,6 +610,7 @@ impl Inner { resolution.clone(), create_npm_fs_resolver( self.npm_cache.clone(), + &ProgressBar::new(ProgressBarStyle::TextOnly), self.npm_api.base_url().clone(), resolution, None, diff --git a/cli/npm/resolvers/local.rs b/cli/npm/resolvers/local.rs index 3e2710165f..5a026f0a82 100644 --- a/cli/npm/resolvers/local.rs +++ b/cli/npm/resolvers/local.rs @@ -11,6 +11,8 @@ use std::path::PathBuf; use crate::util::fs::symlink_dir; use crate::util::fs::LaxSingleProcessFsFlag; +use crate::util::progress_bar::ProgressBar; +use crate::util::progress_bar::ProgressMessagePrompt; use async_trait::async_trait; use deno_ast::ModuleSpecifier; use deno_core::anyhow::bail; @@ -42,6 +44,7 @@ use super::common::NpmPackageFsResolver; #[derive(Debug, Clone)] pub struct LocalNpmPackageResolver { cache: NpmCache, + progress_bar: ProgressBar, resolution: NpmResolution, registry_url: Url, root_node_modules_path: PathBuf, @@ -51,12 +54,14 @@ pub struct LocalNpmPackageResolver { impl LocalNpmPackageResolver { pub fn new( cache: NpmCache, + progress_bar: ProgressBar, registry_url: Url, node_modules_folder: PathBuf, resolution: NpmResolution, ) -> Self { Self { cache, + progress_bar, resolution, registry_url, 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> { - sync_resolver_with_fs(self).await?; - Ok(()) + sync_resolution_with_fs( + &self.resolution.snapshot(), + &self.cache, + &self.progress_bar, + &self.registry_url, + &self.root_node_modules_path, + ) + .await } 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. async fn sync_resolution_with_fs( snapshot: &NpmResolutionSnapshot, cache: &NpmCache, + progress_bar: &ProgressBar, registry_url: &Url, root_node_modules_dir_path: &Path, ) -> Result<(), AnyError> { @@ -252,6 +252,8 @@ async fn sync_resolution_with_fs( ) .await; + let pb_clear_guard = progress_bar.clear_guard(); // prevent flickering + // 1. Write all the packages out the .deno directory. // // Copy (hardlink in future) // to @@ -277,6 +279,7 @@ async fn sync_resolution_with_fs( .should_use_for_npm_package(&package.pkg_id.nv.name) || !initialized_file.exists() { + let pb = progress_bar.clone(); let cache = cache.clone(); let registry_url = registry_url.clone(); let package = package.clone(); @@ -284,6 +287,10 @@ async fn sync_resolution_with_fs( cache .ensure_package(&package.pkg_id.nv, &package.dist, ®istry_url) .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 package_path = 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)?; // write out a file that indicates this folder has been initialized fs::write(initialized_file, "")?; + // finally stop showing the progress bar + drop(pb_guard); // explicit for clarity Ok(()) }); if sync_download { @@ -411,6 +420,7 @@ async fn sync_resolution_with_fs( } drop(single_process_lock); + drop(pb_clear_guard); Ok(()) } diff --git a/cli/npm/resolvers/mod.rs b/cli/npm/resolvers/mod.rs index 49a3c46f76..61b020885b 100644 --- a/cli/npm/resolvers/mod.rs +++ b/cli/npm/resolvers/mod.rs @@ -27,6 +27,7 @@ use std::sync::Arc; use crate::args::Lockfile; use crate::util::fs::canonicalize_path_maybe_not_exists; +use crate::util::progress_bar::ProgressBar; use self::common::NpmPackageFsResolver; use self::local::LocalNpmPackageResolver; @@ -276,6 +277,7 @@ impl RequireNpmResolver for NpmPackageResolver { pub fn create_npm_fs_resolver( cache: NpmCache, + progress_bar: &ProgressBar, registry_url: Url, resolution: NpmResolution, maybe_node_modules_path: Option, @@ -283,6 +285,7 @@ pub fn create_npm_fs_resolver( match maybe_node_modules_path { Some(node_modules_folder) => Arc::new(LocalNpmPackageResolver::new( cache, + progress_bar.clone(), registry_url, node_modules_folder, resolution, diff --git a/cli/proc_state.rs b/cli/proc_state.rs index 3d7130e5a0..52afcd6313 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -239,6 +239,7 @@ impl ProcState { ); let npm_fs_resolver = create_npm_fs_resolver( npm_cache, + &progress_bar, npm_registry_url, npm_resolution.clone(), cli_options.node_modules_dir_path(), diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index 6a66db35fe..49095b6dfd 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -7,6 +7,7 @@ use util::assert_contains; use util::env_vars_for_npm_tests; use util::env_vars_for_npm_tests_no_sync_download; use util::http_server; +use util::TestContextBuilder; // 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 { args: "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(), http_server: true, temp_cwd: true, @@ -729,7 +730,7 @@ itest!(node_modules_dir_require_added_node_modules_folder { itest!(node_modules_dir_with_deps { 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(), http_server: true, temp_cwd: true, @@ -1392,39 +1393,26 @@ fn auto_discover_lock_file() { #[test] 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 temp_dir = util::TempDir::new(); + let deno_dir = context.deno_dir(); + 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 - temp_dir.write("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); + temp_dir.write("npm/peer_deps_with_copied_folders/deno.json", "{}"); - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .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 output = context.new_command().args("run -A main.ts").run(); + output.assert_exit_code(0); + output.assert_matches_file("npm/peer_deps_with_copied_folders/main.out"); - let expected_output = - 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()); + assert!(temp_dir_sub_path.join("deno.lock").exists()); let grandchild_path = deno_dir .path() .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 // run again - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .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 output = context.new_command().args("run -A main.ts").run(); + output.assert_exit_code(0); + output.assert_matches_text("1\n2\n"); - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--reload") - .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()); + // run with reload + let output = context.new_command().args("run -A --reload main.ts").run(); + output.assert_exit_code(0); + output.assert_matches_file("npm/peer_deps_with_copied_folders/main.out"); // now run with local node modules - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--node-modules-dir") - .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 output = context + .new_command() + .args("run -A --node-modules-dir main.ts") + .run(); + output.assert_exit_code(0); + output.assert_matches_file( + "npm/peer_deps_with_copied_folders/main_node_modules.out", + ); - 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 .join("@denotest+peer-dep-test-grandchild@1.0.0") .exists()); @@ -1491,55 +1453,32 @@ fn peer_deps_with_copied_folders_and_lockfile() { .exists()); // copy folder // now again run with local node modules - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--node-modules-dir") - .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()); - assert_eq!(String::from_utf8(output.stderr).unwrap(), "1\n2\n"); + let output = context + .new_command() + .args("run -A --node-modules-dir main.ts") + .run(); + output.assert_exit_code(0); + output.assert_matches_text("1\n2\n"); // now ensure it works with reloading - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--node-modules-dir") - .arg("--reload") - .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()); - assert_eq!(String::from_utf8(output.stderr).unwrap(), expected_output); + let output = context + .new_command() + .args("run -A --reload --node-modules-dir main.ts") + .run(); + output.assert_exit_code(0); + output.assert_matches_file( + "npm/peer_deps_with_copied_folders/main_node_modules_reload.out", + ); // now ensure it works with reloading and no lockfile - let deno = util::deno_cmd_with_deno_dir(&deno_dir) - .current_dir(temp_dir.path()) - .arg("run") - .arg("--node-modules-dir") - .arg("--no-lock") - .arg("--reload") - .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()); + let output = context + .new_command() + .args("run -A --reload --node-modules-dir --no-lock main.ts") + .run(); + output.assert_exit_code(0); + output.assert_matches_file( + "npm/peer_deps_with_copied_folders/main_node_modules_reload.out", + ); } itest!(info_peer_deps { diff --git a/cli/tests/testdata/npm/cjs_with_deps/main_node_modules.out b/cli/tests/testdata/npm/cjs_with_deps/main_node_modules.out new file mode 100644 index 0000000000..1ae22f5107 --- /dev/null +++ b/cli/tests/testdata/npm/cjs_with_deps/main_node_modules.out @@ -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 diff --git a/cli/tests/testdata/npm/cjs_yargs/main.out b/cli/tests/testdata/npm/cjs_yargs/main.out index ded92a4da5..6aa34bce88 100644 --- a/cli/tests/testdata/npm/cjs_yargs/main.out +++ b/cli/tests/testdata/npm/cjs_yargs/main.out @@ -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/p-try 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 +Initialize ansi-styles@4.3.0 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 +Initialize cliui@6.0.0 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/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 +Initialize emoji-regex@8.0.0 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 +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 +Initialize is-fullwidth-code-point@3.0.0 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 +Initialize p-limit@2.3.0 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 +Initialize p-try@2.2.0 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 +Initialize require-directory@2.1.1 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 +Initialize set-blocking@2.0.0 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 +Initialize strip-ansi@6.0.1 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 +Initialize wrap-ansi@6.2.0 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 +Initialize yargs@15.4.1 Download http://localhost:4545/npm/registry/yargs-parser/yargs-parser-18.1.3.tgz +Initialize yargs-parser@18.1.3 start server on :8000 [WILDCARD] diff --git a/cli/tests/testdata/npm/conditional_exports/main_node_modules.out b/cli/tests/testdata/npm/conditional_exports/main_node_modules.out new file mode 100644 index 0000000000..525f31d5c6 --- /dev/null +++ b/cli/tests/testdata/npm/conditional_exports/main_node_modules.out @@ -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 diff --git a/cli/tests/testdata/npm/mixed_case_package_name/local.out b/cli/tests/testdata/npm/mixed_case_package_name/local.out index b61be3d354..d21377fd6f 100644 --- a/cli/tests/testdata/npm/mixed_case_package_name/local.out +++ b/cli/tests/testdata/npm/mixed_case_package_name/local.out @@ -1,7 +1,9 @@ Download http://localhost:4545/npm/registry/@denotest/MixedCase Download http://localhost:4545/npm/registry/@denotest/CAPITALS 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 +Initialize @denotest/MixedCase@1.0.0 5 true true diff --git a/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules.out b/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules.out new file mode 100644 index 0000000000..6cbadb8e7a --- /dev/null +++ b/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules.out @@ -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 diff --git a/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules_reload.out b/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules_reload.out new file mode 100644 index 0000000000..91a59e1837 --- /dev/null +++ b/cli/tests/testdata/npm/peer_deps_with_copied_folders/main_node_modules_reload.out @@ -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 diff --git a/cli/tests/testdata/package_json/basic/lib.bench.out b/cli/tests/testdata/package_json/basic/lib.bench.out index 589f17655d..b16d9e7acf 100644 --- a/cli/tests/testdata/package_json/basic/lib.bench.out +++ b/cli/tests/testdata/package_json/basic/lib.bench.out @@ -1,5 +1,6 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic 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 cpu: [WILDCARD] runtime: [WILDCARD] diff --git a/cli/tests/testdata/package_json/basic/lib.test.out b/cli/tests/testdata/package_json/basic/lib.test.out index f0fe896120..fa1cbb0f70 100644 --- a/cli/tests/testdata/package_json/basic/lib.test.out +++ b/cli/tests/testdata/package_json/basic/lib.test.out @@ -1,5 +1,6 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic 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 running 1 test from [WILDCARD]lib.test.ts should add ... ok ([WILDCARD]) diff --git a/cli/tests/testdata/package_json/basic/main.cache.out b/cli/tests/testdata/package_json/basic/main.cache.out index 4be62e9eb7..1c729e2a33 100644 --- a/cli/tests/testdata/package_json/basic/main.cache.out +++ b/cli/tests/testdata/package_json/basic/main.cache.out @@ -1,2 +1,3 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 diff --git a/cli/tests/testdata/package_json/basic/main.check.out b/cli/tests/testdata/package_json/basic/main.check.out index 09c3773144..a506cb0edd 100644 --- a/cli/tests/testdata/package_json/basic/main.check.out +++ b/cli/tests/testdata/package_json/basic/main.check.out @@ -1,3 +1,4 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic 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 diff --git a/cli/tests/testdata/package_json/invalid_value/ok.ts.out b/cli/tests/testdata/package_json/invalid_value/ok.ts.out index 3c7e2792f3..17d9bba007 100644 --- a/cli/tests/testdata/package_json/invalid_value/ok.ts.out +++ b/cli/tests/testdata/package_json/invalid_value/ok.ts.out @@ -1,3 +1,4 @@ Download http://localhost:4545/npm/registry/@denotest/esm-basic Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 2 diff --git a/cli/tests/testdata/task/both/package_json_selected.out b/cli/tests/testdata/task/both/package_json_selected.out index 435145debe..06b735c9da 100644 --- a/cli/tests/testdata/task/both/package_json_selected.out +++ b/cli/tests/testdata/task/both/package_json_selected.out @@ -1,5 +1,6 @@ Download http://localhost:4545/npm/registry/@denotest/bin 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. Task bin cli-esm testing this out "asdf" testing diff --git a/cli/tests/testdata/task/package_json/bin.out b/cli/tests/testdata/task/package_json/bin.out index d8594a243c..fac6921156 100644 --- a/cli/tests/testdata/task/package_json/bin.out +++ b/cli/tests/testdata/task/package_json/bin.out @@ -1,6 +1,8 @@ Download http://localhost:4545/npm/registry/@denotest/bin 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 +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. Task bin @denotest/bin hi && cli-esm testing this out && npx cli-cjs test "extra" hi diff --git a/cli/util/progress_bar/mod.rs b/cli/util/progress_bar/mod.rs index 2568710795..65bc00efd0 100644 --- a/cli/util/progress_bar/mod.rs +++ b/cli/util/progress_bar/mod.rs @@ -27,6 +27,7 @@ mod renderer; pub enum ProgressMessagePrompt { Download, Blocking, + Initialize, } impl ProgressMessagePrompt { @@ -34,6 +35,9 @@ impl ProgressMessagePrompt { match self { ProgressMessagePrompt::Download => colors::green("Download").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)] pub struct ProgressBar { - inner: Option, + inner: ProgressBarInner, } impl ProgressBar { @@ -262,17 +266,14 @@ impl ProgressBar { pub fn new(style: ProgressBarStyle) -> Self { Self { - inner: match Self::are_supported() { - true => Some(ProgressBarInner::new(match style { - ProgressBarStyle::DownloadBars => { - Arc::new(renderer::BarProgressBarRenderer) - } - ProgressBarStyle::TextOnly => { - Arc::new(renderer::TextOnlyProgressBarRenderer) - } - })), - false => None, - }, + inner: ProgressBarInner::new(match style { + ProgressBarStyle::DownloadBars => { + Arc::new(renderer::BarProgressBarRenderer) + } + ProgressBarStyle::TextOnly => { + Arc::new(renderer::TextOnlyProgressBarRenderer) + } + }), } } @@ -285,34 +286,29 @@ impl ProgressBar { kind: ProgressMessagePrompt, msg: &str, ) -> UpdateGuard { - match &self.inner { - Some(inner) => { - let entry = inner.add_entry(kind, msg.to_string()); - UpdateGuard { - maybe_entry: Some(entry), - } + // only check if progress bars are supported once we go + // to update so that we lazily initialize the progress bar + if ProgressBar::are_supported() { + let entry = self.inner.add_entry(kind, msg.to_string()); + UpdateGuard { + maybe_entry: Some(entry), } - None => { - // if we're not running in TTY, fallback to using logger crate - if !msg.is_empty() { - log::log!(log::Level::Info, "{} {}", kind.as_text(), msg); - } - UpdateGuard { maybe_entry: None } + } else { + // if we're not running in TTY, fallback to using logger crate + if !msg.is_empty() { + log::log!(log::Level::Info, "{} {}", kind.as_text(), msg); } + UpdateGuard { maybe_entry: None } } } pub fn clear_guard(&self) -> ClearGuard { - if let Some(inner) = &self.inner { - inner.increment_clear(); - } + self.inner.increment_clear(); ClearGuard { pb: self.clone() } } fn decrement_clear(&self) { - if let Some(inner) = &self.inner { - inner.decrement_clear(); - } + self.inner.decrement_clear(); } } diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index e72ce9b635..9b300b9113 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -30,6 +30,7 @@ use crate::TempDir; pub struct TestContextBuilder { use_http_server: bool, use_temp_cwd: bool, + use_separate_deno_dir: bool, /// 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 /// the test creates files in the testdata directory (ex. a node_modules folder) @@ -60,6 +61,15 @@ impl TestContextBuilder { 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 /// 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) @@ -102,12 +112,17 @@ impl TestContextBuilder { pub fn build(&self) -> TestContext { 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 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(); copy_dir_recursive(&test_data_path, &temp_copy_dir).unwrap(); - deno_dir.path().to_owned() + temp_dir.path().to_owned() } else { testdata_path() }; @@ -128,6 +143,7 @@ impl TestContextBuilder { use_temp_cwd: self.use_temp_cwd, _http_server_guard: http_server_guard, deno_dir, + temp_dir, testdata_dir, } } @@ -141,6 +157,7 @@ pub struct TestContext { cwd: Option, _http_server_guard: Option>, deno_dir: TempDir, + temp_dir: TempDir, testdata_dir: PathBuf, } @@ -163,6 +180,10 @@ impl TestContext { &self.deno_dir } + pub fn temp_dir(&self) -> &TempDir { + &self.temp_dir + } + pub fn new_command(&self) -> TestCommandBuilder { TestCommandBuilder { 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 = if self.context.use_temp_cwd { assert!(cwd.is_none()); - self.context.deno_dir.path().to_owned() + self.context.temp_dir.path().to_owned() } else if let Some(cwd_) = cwd { self.context.testdata_dir.join(cwd_) } else {