From f1c58ec041a05276d9f33562a5843c0bb7fb95b3 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 20 Aug 2024 10:11:43 -0400 Subject: [PATCH 01/14] feat(unstable): ability to use a local copy of jsr packages (#25068) --- Cargo.lock | 4 +-- cli/Cargo.toml | 2 +- cli/args/mod.rs | 2 +- cli/lsp/config.rs | 2 +- cli/npm/managed/mod.rs | 2 +- cli/resolver.rs | 23 +++++++++++++-- cli/schemas/config-file.v1.json | 7 +++++ cli/standalone/mod.rs | 5 ++-- cli/tools/lint/rules/no_sloppy_imports.rs | 28 ++++++++++--------- cli/tools/registry/unfurl.rs | 5 ++-- tests/specs/compile/patch/__test__.jsonc | 22 +++++++++++++++ tests/specs/compile/patch/add/deno.json | 4 +++ tests/specs/compile/patch/add/mod.ts | 3 ++ tests/specs/compile/patch/main.out | 1 + tests/specs/compile/patch/main/deno.json | 5 ++++ tests/specs/compile/patch/main/main.ts | 3 ++ tests/specs/mod.rs | 11 +++++++- tests/specs/run/patch/__test__.jsonc | 25 +++++++++++++++++ tests/specs/run/patch/add/deno.json | 5 ++++ tests/specs/run/patch/add/mod.test.ts | 9 ++++++ tests/specs/run/patch/add/mod.ts | 4 +++ tests/specs/run/patch/modify_version.ts | 3 ++ tests/specs/run/patch/my-pkg/deno.json | 11 ++++++++ tests/specs/run/patch/my-pkg/mod.test.ts | 7 +++++ tests/specs/run/patch/my-pkg/mod.ts | 2 ++ .../specs/run/patch/not_matching_version.out | 11 ++++++++ tests/specs/run/patch/test.out | 10 +++++++ .../__test__.jsonc | 4 +++ .../member_not_match_constraint/add/deno.json | 5 ++++ .../member_not_match_constraint/add/mod.ts | 4 +++ .../member_not_match_constraint/deno.json | 3 ++ .../member_not_match_constraint/deno.lock | 23 +++++++++++++++ .../subtract/deno.json | 8 ++++++ .../subtract/mod.test.ts | 7 +++++ .../subtract/mod.ts | 5 ++++ .../member_not_match_constraint/test.out | 11 ++++++++ tests/specs/workspaces/patch/__test__.jsonc | 13 +++++++++ tests/specs/workspaces/patch/add/deno.json | 5 ++++ tests/specs/workspaces/patch/add/mod.test.ts | 9 ++++++ tests/specs/workspaces/patch/add/mod.ts | 4 +++ tests/specs/workspaces/patch/test.out | 10 +++++++ .../workspaces/patch/workspace/deno.json | 6 ++++ .../patch/workspace/my-pkg/deno.json | 8 ++++++ .../patch/workspace/my-pkg/mod.test.ts | 7 +++++ .../workspaces/patch/workspace/my-pkg/mod.ts | 1 + 45 files changed, 323 insertions(+), 26 deletions(-) create mode 100644 tests/specs/compile/patch/__test__.jsonc create mode 100644 tests/specs/compile/patch/add/deno.json create mode 100644 tests/specs/compile/patch/add/mod.ts create mode 100644 tests/specs/compile/patch/main.out create mode 100644 tests/specs/compile/patch/main/deno.json create mode 100644 tests/specs/compile/patch/main/main.ts create mode 100644 tests/specs/run/patch/__test__.jsonc create mode 100644 tests/specs/run/patch/add/deno.json create mode 100644 tests/specs/run/patch/add/mod.test.ts create mode 100644 tests/specs/run/patch/add/mod.ts create mode 100644 tests/specs/run/patch/modify_version.ts create mode 100644 tests/specs/run/patch/my-pkg/deno.json create mode 100644 tests/specs/run/patch/my-pkg/mod.test.ts create mode 100644 tests/specs/run/patch/my-pkg/mod.ts create mode 100644 tests/specs/run/patch/not_matching_version.out create mode 100644 tests/specs/run/patch/test.out create mode 100644 tests/specs/run/workspaces/member_not_match_constraint/__test__.jsonc create mode 100644 tests/specs/run/workspaces/member_not_match_constraint/add/deno.json create mode 100644 tests/specs/run/workspaces/member_not_match_constraint/add/mod.ts create mode 100644 tests/specs/run/workspaces/member_not_match_constraint/deno.json create mode 100644 tests/specs/run/workspaces/member_not_match_constraint/deno.lock create mode 100644 tests/specs/run/workspaces/member_not_match_constraint/subtract/deno.json create mode 100644 tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.test.ts create mode 100644 tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.ts create mode 100644 tests/specs/run/workspaces/member_not_match_constraint/test.out create mode 100644 tests/specs/workspaces/patch/__test__.jsonc create mode 100644 tests/specs/workspaces/patch/add/deno.json create mode 100644 tests/specs/workspaces/patch/add/mod.test.ts create mode 100644 tests/specs/workspaces/patch/add/mod.ts create mode 100644 tests/specs/workspaces/patch/test.out create mode 100644 tests/specs/workspaces/patch/workspace/deno.json create mode 100644 tests/specs/workspaces/patch/workspace/my-pkg/deno.json create mode 100644 tests/specs/workspaces/patch/workspace/my-pkg/mod.test.ts create mode 100644 tests/specs/workspaces/patch/workspace/my-pkg/mod.ts diff --git a/Cargo.lock b/Cargo.lock index d2202a7e7b..debd091e87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1360,9 +1360,9 @@ dependencies = [ [[package]] name = "deno_config" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bc5aa53d1c3a3d0b9fd218e3f30f1080312f811b60e1866b88ec9f665447c4e" +checksum = "e287a8ab3552cf3ef8fc41b2bd7cc041c5e8e1a76de3aeb26e804b570bab37d7" dependencies = [ "anyhow", "deno_package_json", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index acda2292c4..920f0d795d 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -65,7 +65,7 @@ winres.workspace = true [dependencies] deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } deno_cache_dir = { workspace = true } -deno_config = { version = "=0.29.0", features = ["workspace", "sync"] } +deno_config = { version = "=0.30.0", features = ["workspace", "sync"] } deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_doc = { version = "0.146.0", features = ["html", "syntect"] } deno_emit = "=0.44.0" diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 68cf916b24..056dcb2af5 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1085,7 +1085,7 @@ impl CliOptions { }; Ok( self - .start_dir + .workspace() .create_resolver( CreateResolverOptions { pkg_json_dep_resolution, diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index 1d6601933b..e32303baa9 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1491,7 +1491,7 @@ impl ConfigData { } }; let resolver = deno_core::unsync::spawn({ - let workspace = member_dir.clone(); + let workspace = member_dir.workspace.clone(); let file_fetcher = file_fetcher.cloned(); async move { workspace diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs index 1561d39699..8f82ddea20 100644 --- a/cli/npm/managed/mod.rs +++ b/cli/npm/managed/mod.rs @@ -324,7 +324,7 @@ impl ManagedCliNpmResolver { Ok(path) } - /// Resolves the package nv from the provided specifier. + /// Resolves the package id from the provided specifier. pub fn resolve_pkg_id_from_specifier( &self, specifier: &ModuleSpecifier, diff --git a/cli/resolver.rs b/cli/resolver.rs index b72fcd322c..a62828b6ec 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -5,6 +5,7 @@ use dashmap::DashMap; use dashmap::DashSet; use deno_ast::MediaType; use deno_config::workspace::MappedResolution; +use deno_config::workspace::MappedResolutionDiagnostic; use deno_config::workspace::MappedResolutionError; use deno_config::workspace::WorkspaceResolver; use deno_core::anyhow::anyhow; @@ -21,6 +22,7 @@ use deno_graph::NpmLoadError; use deno_graph::NpmResolvePkgReqsResult; use deno_npm::resolution::NpmResolutionError; use deno_package_json::PackageJsonDepValue; +use deno_runtime::colors; use deno_runtime::deno_fs; use deno_runtime::deno_fs::FileSystem; use deno_runtime::deno_node::is_builtin_node_module; @@ -434,6 +436,7 @@ pub struct CliGraphResolver { maybe_vendor_specifier: Option, found_package_json_dep_flag: AtomicFlag, bare_node_builtins_enabled: bool, + warned_pkgs: DashSet, } pub struct CliGraphResolverOptions<'a> { @@ -469,6 +472,7 @@ impl CliGraphResolver { .and_then(|v| ModuleSpecifier::from_directory_path(v).ok()), found_package_json_dep_flag: Default::default(), bare_node_builtins_enabled: options.bare_node_builtins_enabled, + warned_pkgs: Default::default(), } } @@ -541,8 +545,23 @@ impl Resolver for CliGraphResolver { }); let result = match result { Ok(resolution) => match resolution { - MappedResolution::Normal(specifier) - | MappedResolution::ImportMap(specifier) => { + MappedResolution::Normal { + specifier, + maybe_diagnostic, + } + | MappedResolution::ImportMap { + specifier, + maybe_diagnostic, + } => { + if let Some(diagnostic) = maybe_diagnostic { + match &*diagnostic { + MappedResolutionDiagnostic::ConstraintNotMatchedLocalVersion { reference, .. } => { + if self.warned_pkgs.insert(reference.req().clone()) { + log::warn!("{} {}\n at {}", colors::yellow("Warning"), diagnostic, referrer_range); + } + } + } + } // do sloppy imports resolution if enabled if let Some(sloppy_imports_resolver) = &self.sloppy_imports_resolver { Ok( diff --git a/cli/schemas/config-file.v1.json b/cli/schemas/config-file.v1.json index e74df9f2fc..adfe3b0c20 100644 --- a/cli/schemas/config-file.v1.json +++ b/cli/schemas/config-file.v1.json @@ -608,6 +608,13 @@ } ] }, + "patch": { + "type": "array", + "items": { + "type": "string" + }, + "description": "UNSTABLE: List of relative paths to folders containing JSR packages to use local versions of." + }, "workspace": { "oneOf": [ { diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 020561ece2..68e1334762 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -227,8 +227,8 @@ impl ModuleLoader for EmbeddedModuleLoader { ) } }, - Ok(MappedResolution::Normal(specifier)) - | Ok(MappedResolution::ImportMap(specifier)) => { + Ok(MappedResolution::Normal { specifier, .. }) + | Ok(MappedResolution::ImportMap { specifier, .. }) => { if let Ok(reference) = NpmPackageReqReference::from_specifier(&specifier) { @@ -622,6 +622,7 @@ pub async fn run( .jsr_pkgs .iter() .map(|pkg| ResolverWorkspaceJsrPackage { + is_patch: false, // only used for enhancing the diagnostic, which isn't shown in deno compile base: root_dir_url.join(&pkg.relative_base).unwrap(), name: pkg.name.clone(), version: pkg.version.clone(), diff --git a/cli/tools/lint/rules/no_sloppy_imports.rs b/cli/tools/lint/rules/no_sloppy_imports.rs index 1ae792e083..4180be5be1 100644 --- a/cli/tools/lint/rules/no_sloppy_imports.rs +++ b/cli/tools/lint/rules/no_sloppy_imports.rs @@ -189,20 +189,22 @@ impl<'a> deno_graph::source::Resolver for SloppyImportCaptureResolver<'a> { .map_err(|err| ResolveError::Other(err.into()))?; match resolution { - deno_config::workspace::MappedResolution::Normal(specifier) - | deno_config::workspace::MappedResolution::ImportMap(specifier) => { - match self.sloppy_imports_resolver.resolve(&specifier, mode) { - Some(res) => { - self - .captures - .borrow_mut() - .entry(referrer_range.clone()) - .or_insert_with(|| res.clone()); - Ok(res.into_specifier()) - } - None => Ok(specifier), - } + deno_config::workspace::MappedResolution::Normal { + specifier, .. } + | deno_config::workspace::MappedResolution::ImportMap { + specifier, .. + } => match self.sloppy_imports_resolver.resolve(&specifier, mode) { + Some(res) => { + self + .captures + .borrow_mut() + .entry(referrer_range.clone()) + .or_insert_with(|| res.clone()); + Ok(res.into_specifier()) + } + None => Ok(specifier), + }, deno_config::workspace::MappedResolution::WorkspaceJsrPackage { .. } diff --git a/cli/tools/registry/unfurl.rs b/cli/tools/registry/unfurl.rs index 489c9a1be6..2babedb367 100644 --- a/cli/tools/registry/unfurl.rs +++ b/cli/tools/registry/unfurl.rs @@ -73,8 +73,8 @@ impl SpecifierUnfurler { self.workspace_resolver.resolve(specifier, referrer) { match resolved { - MappedResolution::Normal(specifier) - | MappedResolution::ImportMap(specifier) => Some(specifier), + MappedResolution::Normal { specifier, .. } + | MappedResolution::ImportMap { specifier, .. } => Some(specifier), MappedResolution::WorkspaceJsrPackage { pkg_req_ref, .. } => { Some(ModuleSpecifier::parse(&pkg_req_ref.to_string()).unwrap()) } @@ -443,6 +443,7 @@ mod tests { Arc::new(ModuleSpecifier::from_directory_path(&cwd).unwrap()), Some(import_map), vec![ResolverWorkspaceJsrPackage { + is_patch: false, base: ModuleSpecifier::from_directory_path(cwd.join("jsr-package")) .unwrap(), name: "@denotest/example".to_string(), diff --git a/tests/specs/compile/patch/__test__.jsonc b/tests/specs/compile/patch/__test__.jsonc new file mode 100644 index 0000000000..87abf82a72 --- /dev/null +++ b/tests/specs/compile/patch/__test__.jsonc @@ -0,0 +1,22 @@ +{ + "tempDir": true, + "steps": [{ + "if": "unix", + "args": "compile --output my-app main/main.ts", + "output": "[WILDCARD]" + }, { + "if": "unix", + "commandName": "./my-app", + "args": [], + "output": "main.out" + }, { + "if": "windows", + "args": "compile --output my-app.exe main/main.ts", + "output": "[WILDCARD]" + }, { + "if": "windows", + "commandName": "./my-app.exe", + "args": [], + "output": "main.out" + }] +} diff --git a/tests/specs/compile/patch/add/deno.json b/tests/specs/compile/patch/add/deno.json new file mode 100644 index 0000000000..40e4179932 --- /dev/null +++ b/tests/specs/compile/patch/add/deno.json @@ -0,0 +1,4 @@ +{ + "name": "@denotest/add", + "exports": "./mod.ts" +} diff --git a/tests/specs/compile/patch/add/mod.ts b/tests/specs/compile/patch/add/mod.ts new file mode 100644 index 0000000000..7e841b3bf2 --- /dev/null +++ b/tests/specs/compile/patch/add/mod.ts @@ -0,0 +1,3 @@ +export function add(a: number, b: number): number { + return (a + b) * 2; // it adds wrong +} diff --git a/tests/specs/compile/patch/main.out b/tests/specs/compile/patch/main.out new file mode 100644 index 0000000000..1e8b314962 --- /dev/null +++ b/tests/specs/compile/patch/main.out @@ -0,0 +1 @@ +6 diff --git a/tests/specs/compile/patch/main/deno.json b/tests/specs/compile/patch/main/deno.json new file mode 100644 index 0000000000..5d341f168f --- /dev/null +++ b/tests/specs/compile/patch/main/deno.json @@ -0,0 +1,5 @@ +{ + "patch": [ + "../add" + ] +} diff --git a/tests/specs/compile/patch/main/main.ts b/tests/specs/compile/patch/main/main.ts new file mode 100644 index 0000000000..8fb44d2ed9 --- /dev/null +++ b/tests/specs/compile/patch/main/main.ts @@ -0,0 +1,3 @@ +import { add } from "jsr:@denotest/add"; + +console.log(add(1, 2)); diff --git a/tests/specs/mod.rs b/tests/specs/mod.rs index c46969f4e1..7a3572a942 100644 --- a/tests/specs/mod.rs +++ b/tests/specs/mod.rs @@ -53,6 +53,8 @@ struct MultiTestMetaData { #[serde(default)] pub envs: HashMap, #[serde(default)] + pub cwd: Option, + #[serde(default)] pub tests: BTreeMap, } @@ -73,6 +75,10 @@ impl MultiTestMetaData { if multi_test_meta_data.temp_dir && !value.contains_key("tempDir") { value.insert("tempDir".to_string(), true.into()); } + if multi_test_meta_data.cwd.is_some() && !value.contains_key("cwd") { + value + .insert("cwd".to_string(), multi_test_meta_data.cwd.clone().into()); + } if !multi_test_meta_data.envs.is_empty() { if !value.contains_key("envs") { value.insert("envs".to_string(), JsonMap::default().into()); @@ -112,6 +118,8 @@ struct MultiStepMetaData { #[serde(default)] pub base: Option, #[serde(default)] + pub cwd: Option, + #[serde(default)] pub envs: HashMap, #[serde(default)] pub repeat: Option, @@ -136,6 +144,7 @@ impl SingleTestMetaData { pub fn into_multi(self) -> MultiStepMetaData { MultiStepMetaData { base: self.base, + cwd: None, temp_dir: self.temp_dir, repeat: self.repeat, envs: Default::default(), @@ -371,7 +380,7 @@ fn run_step( VecOrString::Vec(args) => command.args_vec(args), VecOrString::String(text) => command.args(text), }; - let command = match &step.cwd { + let command = match step.cwd.as_ref().or(metadata.cwd.as_ref()) { Some(cwd) => command.current_dir(cwd), None => command, }; diff --git a/tests/specs/run/patch/__test__.jsonc b/tests/specs/run/patch/__test__.jsonc new file mode 100644 index 0000000000..00ae3baac2 --- /dev/null +++ b/tests/specs/run/patch/__test__.jsonc @@ -0,0 +1,25 @@ +{ + "tempDir": true, + "tests": { + "matching_version": { + "cwd": "./my-pkg", + "steps": [{ + "args": "test", + "output": "test.out" + }, { + "args": "lint", + "output": "Checked 2 files\n" + }] + }, + "not_matching_version": { + "steps": [{ + "args": "run --allow-read=. --allow-write=. modify_version.ts", + "output": "[WILDCARD]" + }, { + "cwd": "./my-pkg", + "args": "test", + "output": "not_matching_version.out" + }] + } + } +} diff --git a/tests/specs/run/patch/add/deno.json b/tests/specs/run/patch/add/deno.json new file mode 100644 index 0000000000..05d24d7b5a --- /dev/null +++ b/tests/specs/run/patch/add/deno.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/add", + "version": "1.0.0", + "exports": "./mod.ts" +} diff --git a/tests/specs/run/patch/add/mod.test.ts b/tests/specs/run/patch/add/mod.test.ts new file mode 100644 index 0000000000..3d3804e07a --- /dev/null +++ b/tests/specs/run/patch/add/mod.test.ts @@ -0,0 +1,9 @@ +import { add } from "./mod.ts"; + +// this test should not be run or linted +Deno.test("add", () => { + let unusedVar = 5; // purposefully causing a lint error to ensure it's not linted + if (add(1, 2) !== 3) { + throw new Error("fail"); + } +}); diff --git a/tests/specs/run/patch/add/mod.ts b/tests/specs/run/patch/add/mod.ts new file mode 100644 index 0000000000..97a779a44e --- /dev/null +++ b/tests/specs/run/patch/add/mod.ts @@ -0,0 +1,4 @@ +export function add(a: number, b: number): number { + console.log("adding", a, "and", b); + return a + b; +} diff --git a/tests/specs/run/patch/modify_version.ts b/tests/specs/run/patch/modify_version.ts new file mode 100644 index 0000000000..3d59aa1b90 --- /dev/null +++ b/tests/specs/run/patch/modify_version.ts @@ -0,0 +1,3 @@ +const data = JSON.parse(Deno.readTextFileSync("./add/deno.json")); +data.version = "2.0.0"; +Deno.writeTextFileSync("./add/deno.json", JSON.stringify(data, null, 2)); diff --git a/tests/specs/run/patch/my-pkg/deno.json b/tests/specs/run/patch/my-pkg/deno.json new file mode 100644 index 0000000000..0303c9974a --- /dev/null +++ b/tests/specs/run/patch/my-pkg/deno.json @@ -0,0 +1,11 @@ +{ + "name": "@scope/my-pkg", + "version": "1.0.0", + "exports": "./mod.ts", + "imports": { + "@denotest/add": "jsr:@denotest/add@1" + }, + "patch": [ + "../add" + ] +} diff --git a/tests/specs/run/patch/my-pkg/mod.test.ts b/tests/specs/run/patch/my-pkg/mod.test.ts new file mode 100644 index 0000000000..1c694298c9 --- /dev/null +++ b/tests/specs/run/patch/my-pkg/mod.test.ts @@ -0,0 +1,7 @@ +import { add } from "./mod.ts"; + +Deno.test("add", () => { + if (add(1, 2) !== 3) { + throw new Error("fail"); + } +}); diff --git a/tests/specs/run/patch/my-pkg/mod.ts b/tests/specs/run/patch/my-pkg/mod.ts new file mode 100644 index 0000000000..41389ed658 --- /dev/null +++ b/tests/specs/run/patch/my-pkg/mod.ts @@ -0,0 +1,2 @@ +export { add } from "@denotest/add"; +import "@denotest/add"; // ensure it only warns once diff --git a/tests/specs/run/patch/not_matching_version.out b/tests/specs/run/patch/not_matching_version.out new file mode 100644 index 0000000000..7a9ee6f39d --- /dev/null +++ b/tests/specs/run/patch/not_matching_version.out @@ -0,0 +1,11 @@ +Warning Patch '@denotest/add@2.0.0' was not used because it did not match '@denotest/add@1' + at file:///[WILDLINE]/my-pkg/mod.ts:1:21 +Download http://127.0.0.1:4250/@denotest/add/meta.json +Download http://127.0.0.1:4250/@denotest/add/1.0.0_meta.json +Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts +Check file:///[WILDLINE]/mod.test.ts +running 1 test from ./mod.test.ts +add ... ok ([WILDLINE]) + +ok | 1 passed | 0 failed ([WILDLINE]) + diff --git a/tests/specs/run/patch/test.out b/tests/specs/run/patch/test.out new file mode 100644 index 0000000000..4eb9f33836 --- /dev/null +++ b/tests/specs/run/patch/test.out @@ -0,0 +1,10 @@ +Check file:///[WILDLINE]/mod.test.ts +running 1 test from ./mod.test.ts +add ... +------- output ------- +adding 1 and 2 +----- output end ----- +add ... ok ([WILDLINE]) + +ok | 1 passed | 0 failed ([WILDLINE]) + diff --git a/tests/specs/run/workspaces/member_not_match_constraint/__test__.jsonc b/tests/specs/run/workspaces/member_not_match_constraint/__test__.jsonc new file mode 100644 index 0000000000..5327059399 --- /dev/null +++ b/tests/specs/run/workspaces/member_not_match_constraint/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "test", + "output": "test.out" +} diff --git a/tests/specs/run/workspaces/member_not_match_constraint/add/deno.json b/tests/specs/run/workspaces/member_not_match_constraint/add/deno.json new file mode 100644 index 0000000000..ff1abb9fee --- /dev/null +++ b/tests/specs/run/workspaces/member_not_match_constraint/add/deno.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/add", + "version": "2.0.0", + "exports": "./mod.ts" +} diff --git a/tests/specs/run/workspaces/member_not_match_constraint/add/mod.ts b/tests/specs/run/workspaces/member_not_match_constraint/add/mod.ts new file mode 100644 index 0000000000..2c8d7ef7a1 --- /dev/null +++ b/tests/specs/run/workspaces/member_not_match_constraint/add/mod.ts @@ -0,0 +1,4 @@ +export function add(a: number, b: number): number { + console.log("local"); + return a + b; +} diff --git a/tests/specs/run/workspaces/member_not_match_constraint/deno.json b/tests/specs/run/workspaces/member_not_match_constraint/deno.json new file mode 100644 index 0000000000..ec5dc2bdf8 --- /dev/null +++ b/tests/specs/run/workspaces/member_not_match_constraint/deno.json @@ -0,0 +1,3 @@ +{ + "workspace": ["./add", "./subtract"] +} diff --git a/tests/specs/run/workspaces/member_not_match_constraint/deno.lock b/tests/specs/run/workspaces/member_not_match_constraint/deno.lock new file mode 100644 index 0000000000..373359d72a --- /dev/null +++ b/tests/specs/run/workspaces/member_not_match_constraint/deno.lock @@ -0,0 +1,23 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0" + }, + "jsr": { + "@denotest/add@1.0.0": { + "integrity": "3b2e675c1ad7fba2a45bc251992e01aff08a3c974ac09079b11e6a5b95d4bfcb" + } + } + }, + "remote": {}, + "workspace": { + "members": { + "subtract": { + "dependencies": [ + "jsr:@denotest/add@1" + ] + } + } + } +} diff --git a/tests/specs/run/workspaces/member_not_match_constraint/subtract/deno.json b/tests/specs/run/workspaces/member_not_match_constraint/subtract/deno.json new file mode 100644 index 0000000000..e585197c0e --- /dev/null +++ b/tests/specs/run/workspaces/member_not_match_constraint/subtract/deno.json @@ -0,0 +1,8 @@ +{ + "name": "@denotest/subtract", + "version": "1.0.0", + "exports": "./mod.ts", + "imports": { + "@denotest/add": "jsr:@denotest/add@1" + } +} diff --git a/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.test.ts b/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.test.ts new file mode 100644 index 0000000000..7d699d4d71 --- /dev/null +++ b/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.test.ts @@ -0,0 +1,7 @@ +import { subtract } from "./mod.ts"; + +Deno.test("subtract", () => { + if (subtract(3, 2) !== 1) { + throw new Error("fail"); + } +}); diff --git a/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.ts b/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.ts new file mode 100644 index 0000000000..6e301511b1 --- /dev/null +++ b/tests/specs/run/workspaces/member_not_match_constraint/subtract/mod.ts @@ -0,0 +1,5 @@ +import { add } from "@denotest/add"; + +export function subtract(a: number, b: number): number { + return add(a, -b); +} diff --git a/tests/specs/run/workspaces/member_not_match_constraint/test.out b/tests/specs/run/workspaces/member_not_match_constraint/test.out new file mode 100644 index 0000000000..0e16426c64 --- /dev/null +++ b/tests/specs/run/workspaces/member_not_match_constraint/test.out @@ -0,0 +1,11 @@ +Warning Workspace member '@denotest/add@2.0.0' was not used because it did not match '@denotest/add@1' + at file:///[WILDLINE]/mod.ts:1:21 +Download http://127.0.0.1:4250/@denotest/add/meta.json +Download http://127.0.0.1:4250/@denotest/add/1.0.0_meta.json +Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts +Check file:///[WILDLINE]/mod.test.ts +running 1 test from ./subtract/mod.test.ts +subtract ... ok ([WILDLINE]) + +ok | 1 passed | 0 failed ([WILDLINE]) + diff --git a/tests/specs/workspaces/patch/__test__.jsonc b/tests/specs/workspaces/patch/__test__.jsonc new file mode 100644 index 0000000000..90a54086e2 --- /dev/null +++ b/tests/specs/workspaces/patch/__test__.jsonc @@ -0,0 +1,13 @@ +{ + "cwd": "./workspace", + "tests": { + "lint": { + "args": "lint", + "output": "Checked 2 files\n" + }, + "test": { + "args": "test", + "output": "test.out" + } + } +} diff --git a/tests/specs/workspaces/patch/add/deno.json b/tests/specs/workspaces/patch/add/deno.json new file mode 100644 index 0000000000..05d24d7b5a --- /dev/null +++ b/tests/specs/workspaces/patch/add/deno.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/add", + "version": "1.0.0", + "exports": "./mod.ts" +} diff --git a/tests/specs/workspaces/patch/add/mod.test.ts b/tests/specs/workspaces/patch/add/mod.test.ts new file mode 100644 index 0000000000..3d3804e07a --- /dev/null +++ b/tests/specs/workspaces/patch/add/mod.test.ts @@ -0,0 +1,9 @@ +import { add } from "./mod.ts"; + +// this test should not be run or linted +Deno.test("add", () => { + let unusedVar = 5; // purposefully causing a lint error to ensure it's not linted + if (add(1, 2) !== 3) { + throw new Error("fail"); + } +}); diff --git a/tests/specs/workspaces/patch/add/mod.ts b/tests/specs/workspaces/patch/add/mod.ts new file mode 100644 index 0000000000..97a779a44e --- /dev/null +++ b/tests/specs/workspaces/patch/add/mod.ts @@ -0,0 +1,4 @@ +export function add(a: number, b: number): number { + console.log("adding", a, "and", b); + return a + b; +} diff --git a/tests/specs/workspaces/patch/test.out b/tests/specs/workspaces/patch/test.out new file mode 100644 index 0000000000..c35ac0e45a --- /dev/null +++ b/tests/specs/workspaces/patch/test.out @@ -0,0 +1,10 @@ +Check file:///[WILDLINE]/my-pkg/mod.test.ts +running 1 test from ./my-pkg/mod.test.ts +add ... +------- output ------- +adding 1 and 2 +----- output end ----- +add ... ok ([WILDLINE]) + +ok | 1 passed | 0 failed ([WILDLINE]) + diff --git a/tests/specs/workspaces/patch/workspace/deno.json b/tests/specs/workspaces/patch/workspace/deno.json new file mode 100644 index 0000000000..510351c44b --- /dev/null +++ b/tests/specs/workspaces/patch/workspace/deno.json @@ -0,0 +1,6 @@ +{ + "workspace": ["./my-pkg"], + "patch": [ + "../add" + ] +} diff --git a/tests/specs/workspaces/patch/workspace/my-pkg/deno.json b/tests/specs/workspaces/patch/workspace/my-pkg/deno.json new file mode 100644 index 0000000000..8b2e887e78 --- /dev/null +++ b/tests/specs/workspaces/patch/workspace/my-pkg/deno.json @@ -0,0 +1,8 @@ +{ + "name": "@scope/my-pkg", + "version": "1.0.0", + "exports": "./mod.ts", + "imports": { + "@denotest/add": "jsr:@denotest/add@1" + } +} diff --git a/tests/specs/workspaces/patch/workspace/my-pkg/mod.test.ts b/tests/specs/workspaces/patch/workspace/my-pkg/mod.test.ts new file mode 100644 index 0000000000..1c694298c9 --- /dev/null +++ b/tests/specs/workspaces/patch/workspace/my-pkg/mod.test.ts @@ -0,0 +1,7 @@ +import { add } from "./mod.ts"; + +Deno.test("add", () => { + if (add(1, 2) !== 3) { + throw new Error("fail"); + } +}); diff --git a/tests/specs/workspaces/patch/workspace/my-pkg/mod.ts b/tests/specs/workspaces/patch/workspace/my-pkg/mod.ts new file mode 100644 index 0000000000..11501ab398 --- /dev/null +++ b/tests/specs/workspaces/patch/workspace/my-pkg/mod.ts @@ -0,0 +1 @@ +export { add } from "@denotest/add"; From 5168700be669179382462214724115a3013cb58e Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Tue, 20 Aug 2024 07:55:47 -0700 Subject: [PATCH 02/14] feat(config): Support frozen lockfile config option in deno.json (#25100) Closes #24544 --- cli/args/flags.rs | 12 ++++---- cli/args/lockfile.rs | 18 ++++++++---- cli/lsp/config.rs | 14 +++++++-- cli/schemas/config-file.v1.json | 16 ++++++++-- cli/tools/installer.rs | 2 +- .../lockfile/frozen_lockfile/__test__.jsonc | 29 +++++++++++++++++++ 6 files changed, 73 insertions(+), 18 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 0ceac4563e..a273d8b370 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -589,7 +589,7 @@ pub struct Flags { pub argv: Vec, pub subcommand: DenoSubcommand, - pub frozen_lockfile: bool, + pub frozen_lockfile: Option, pub ca_stores: Option>, pub ca_data: Option, pub cache_blocklist: Vec, @@ -5231,7 +5231,7 @@ fn cached_only_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) { fn frozen_lockfile_arg_parse(flags: &mut Flags, matches: &mut ArgMatches) { if let Some(&v) = matches.get_one::("frozen") { - flags.frozen_lockfile = v; + flags.frozen_lockfile = Some(v); } } @@ -10923,10 +10923,10 @@ mod tests { #[test] fn run_with_frozen_lockfile() { let cases = [ - (Some("--frozen"), true), - (Some("--frozen=true"), true), - (Some("--frozen=false"), false), - (None, false), + (Some("--frozen"), Some(true)), + (Some("--frozen=true"), Some(true)), + (Some("--frozen=false"), Some(false)), + (None, None), ]; for (flag, frozen) in cases { let mut args = svec!["deno", "run"]; diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index 953278e7dc..00d1f929d8 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -147,22 +147,28 @@ impl CliLockfile { }, }; + let root_folder = workspace.root_folder_configs(); + // CLI flag takes precedence over the config + let frozen = flags.frozen_lockfile.unwrap_or_else(|| { + root_folder + .deno_json + .as_ref() + .and_then(|c| c.to_lock_config().ok().flatten().map(|c| c.frozen())) + .unwrap_or(false) + }); + let lockfile = if flags.lock_write { log::warn!( "{} \"--lock-write\" flag is deprecated and will be removed in Deno 2.", crate::colors::yellow("Warning") ); - CliLockfile::new( - Lockfile::new_empty(filename, true), - flags.frozen_lockfile, - ) + CliLockfile::new(Lockfile::new_empty(filename, true), frozen) } else { - Self::read_from_path(filename, flags.frozen_lockfile)? + Self::read_from_path(filename, frozen)? }; // initialize the lockfile with the workspace's configuration let root_url = workspace.root_dir(); - let root_folder = workspace.root_folder_configs(); let config = deno_lockfile::WorkspaceConfig { root: WorkspaceMemberConfig { package_json_deps: pkg_json_deps(root_folder.pkg_json.as_deref()), diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index e32303baa9..f99f1fa103 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1846,7 +1846,12 @@ fn resolve_lockfile_from_workspace( return None; } }; - resolve_lockfile_from_path(lockfile_path) + let frozen = workspace + .workspace + .root_deno_json() + .and_then(|c| c.to_lock_config().ok().flatten().map(|c| c.frozen())) + .unwrap_or(false); + resolve_lockfile_from_path(lockfile_path, frozen) } fn resolve_node_modules_dir( @@ -1875,8 +1880,11 @@ fn resolve_node_modules_dir( canonicalize_path_maybe_not_exists(&node_modules_dir).ok() } -fn resolve_lockfile_from_path(lockfile_path: PathBuf) -> Option { - match CliLockfile::read_from_path(lockfile_path, false) { +fn resolve_lockfile_from_path( + lockfile_path: PathBuf, + frozen: bool, +) -> Option { + match CliLockfile::read_from_path(lockfile_path, frozen) { Ok(value) => { if value.filename.exists() { if let Ok(specifier) = ModuleSpecifier::from_file_path(&value.filename) diff --git a/cli/schemas/config-file.v1.json b/cli/schemas/config-file.v1.json index adfe3b0c20..733a9cab60 100644 --- a/cli/schemas/config-file.v1.json +++ b/cli/schemas/config-file.v1.json @@ -552,8 +552,20 @@ }, "lock": { "description": "Whether to use a lock file or the path to use for the lock file. Can be overridden by CLI arguments.", - "type": ["string", "boolean"], - "default": true + "type": ["string", "boolean", "object"], + "default": true, + "properties": { + "path": { + "type": "string", + "description": "The path to use for the lock file.", + "default": "deno.lock" + }, + "frozen": { + "type": "boolean", + "description": "Whether to exit with an error if lock file is out of date.", + "default": false + } + } }, "unstable": { "type": "array", diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index 648b766b85..456e5c1a68 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -472,7 +472,7 @@ async fn resolve_shim_data( executable_args.push("--cached-only".to_string()); } - if flags.frozen_lockfile { + if flags.frozen_lockfile.unwrap_or(false) { executable_args.push("--frozen".to_string()); } diff --git a/tests/specs/lockfile/frozen_lockfile/__test__.jsonc b/tests/specs/lockfile/frozen_lockfile/__test__.jsonc index 8faa45b4e3..3036c8db52 100644 --- a/tests/specs/lockfile/frozen_lockfile/__test__.jsonc +++ b/tests/specs/lockfile/frozen_lockfile/__test__.jsonc @@ -123,6 +123,35 @@ } ] }, + + "lockfile_config": { + "steps": [ + { + "args": [ + "eval", + "Deno.writeTextFileSync('deno.json', JSON.stringify({ lock: { frozen: true }, ...JSON.parse(Deno.readTextFileSync('deno.json')) }))" + ], + "output": "" + }, + { + "args": "cache --frozen=false add.ts", + "output": "[WILDCARD]" + }, + { + // sub.ts imports from an npm package + // that's not in the lockfile + "args": "run sub.ts", + "output": "frozen_new_dep_run.out", + "exitCode": 1 + }, + { + "args": "cache sub.ts", + "output": "frozen_new_dep_cache.out", + "exitCode": 1 + } + ] + }, + "non_analyzable_dynamic_npm": { "steps": [ { From 07044547559cafe1a86afc0f1dec13967803eb11 Mon Sep 17 00:00:00 2001 From: HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> Date: Tue, 20 Aug 2024 20:53:53 +0300 Subject: [PATCH 03/14] feat: Print deprecation message for npm packages (#24992) This commit adds ability to print deprecation notices for npm packages that have been marked as deprecated. Closes #24013 --- cli/npm/managed/resolvers/local.rs | 9 +++++++ .../deprecated-package/1.0.0/main.d.mts | 3 +++ .../deprecated-package/1.0.0/main.mjs | 11 ++++++++ .../deprecated-package/1.0.0/package.json | 9 +++++++ .../install_deprecated_package/__test__.jsonc | 25 +++++++++++++++++++ .../install_deprecated_package/install.out | 5 ++++ .../install_deprecated_package/main.js | 2 ++ .../install_deprecated_package/package.json | 3 +++ .../package.json.out | 3 +++ 9 files changed, 70 insertions(+) create mode 100644 tests/registry/npm/@denotest/deprecated-package/1.0.0/main.d.mts create mode 100644 tests/registry/npm/@denotest/deprecated-package/1.0.0/main.mjs create mode 100644 tests/registry/npm/@denotest/deprecated-package/1.0.0/package.json create mode 100644 tests/specs/install/install_deprecated_package/__test__.jsonc create mode 100644 tests/specs/install/install_deprecated_package/install.out create mode 100644 tests/specs/install/install_deprecated_package/main.js create mode 100644 tests/specs/install/install_deprecated_package/package.json create mode 100644 tests/specs/install/install_deprecated_package/package.json.out diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs index adfd04b9e4..61e50ba8d3 100644 --- a/cli/npm/managed/resolvers/local.rs +++ b/cli/npm/managed/resolvers/local.rs @@ -515,6 +515,15 @@ async fn sync_resolution_with_fs( .add(package.clone(), package_path); } + if let Some(deprecated) = &package.deprecated { + log::info!( + "{} {:?} is deprecated: {}", + crate::colors::yellow("Warning"), + package.id, + crate::colors::gray(deprecated), + ); + } + // finally stop showing the progress bar drop(pb_guard); // explicit for clarity Ok::<_, AnyError>(()) diff --git a/tests/registry/npm/@denotest/deprecated-package/1.0.0/main.d.mts b/tests/registry/npm/@denotest/deprecated-package/1.0.0/main.d.mts new file mode 100644 index 0000000000..29da1e6d7b --- /dev/null +++ b/tests/registry/npm/@denotest/deprecated-package/1.0.0/main.d.mts @@ -0,0 +1,3 @@ +export declare function setValue(val: number): void; +export declare function getValue(): number; +export declare const url: string; diff --git a/tests/registry/npm/@denotest/deprecated-package/1.0.0/main.mjs b/tests/registry/npm/@denotest/deprecated-package/1.0.0/main.mjs new file mode 100644 index 0000000000..0a44f75859 --- /dev/null +++ b/tests/registry/npm/@denotest/deprecated-package/1.0.0/main.mjs @@ -0,0 +1,11 @@ +let value = 0; + +export function setValue(newValue) { + value = newValue; +} + +export function getValue() { + return value; +} + +export const url = import.meta.url; diff --git a/tests/registry/npm/@denotest/deprecated-package/1.0.0/package.json b/tests/registry/npm/@denotest/deprecated-package/1.0.0/package.json new file mode 100644 index 0000000000..af82efef00 --- /dev/null +++ b/tests/registry/npm/@denotest/deprecated-package/1.0.0/package.json @@ -0,0 +1,9 @@ +{ + "name": "@denotest/deprecated-package", + "version": "1.0.0", + "type": "module", + "main": "main.mjs", + "types": "main.d.mts", + "deprecated": "Deprecated version" + } + \ No newline at end of file diff --git a/tests/specs/install/install_deprecated_package/__test__.jsonc b/tests/specs/install/install_deprecated_package/__test__.jsonc new file mode 100644 index 0000000000..23c9cdb3f0 --- /dev/null +++ b/tests/specs/install/install_deprecated_package/__test__.jsonc @@ -0,0 +1,25 @@ +{ + "tempDir": true, + "envs": { + "DENO_FUTURE": "1" + }, + "steps": [ + { + "args": "install npm:@denotest/deprecated-package", + "output": "install.out" + }, + { + // make sure the dep got cached + "args": "run --cached-only main.js", + "exitCode": 0, + "output": "" + }, + { + "args": [ + "eval", + "console.log(Deno.readTextFileSync('package.json').trim())" + ], + "output": "package.json.out" + } + ] +} diff --git a/tests/specs/install/install_deprecated_package/install.out b/tests/specs/install/install_deprecated_package/install.out new file mode 100644 index 0000000000..9dc84fbc1a --- /dev/null +++ b/tests/specs/install/install_deprecated_package/install.out @@ -0,0 +1,5 @@ +Add npm:@denotest/deprecated-package@1.0.0 +Download http://localhost:4260/@denotest/deprecated-package +Download http://localhost:4260/@denotest/deprecated-package/1.0.0.tgz +Initialize @denotest/deprecated-package@1.0.0 +Warning @denotest/deprecated-package@1.0.0 is deprecated: Deprecated version diff --git a/tests/specs/install/install_deprecated_package/main.js b/tests/specs/install/install_deprecated_package/main.js new file mode 100644 index 0000000000..de5026c50e --- /dev/null +++ b/tests/specs/install/install_deprecated_package/main.js @@ -0,0 +1,2 @@ +import { setValue } from "@denotest/deprecated-package"; +setValue(5); diff --git a/tests/specs/install/install_deprecated_package/package.json b/tests/specs/install/install_deprecated_package/package.json new file mode 100644 index 0000000000..18a1e415e5 --- /dev/null +++ b/tests/specs/install/install_deprecated_package/package.json @@ -0,0 +1,3 @@ +{ + "dependencies": {} +} diff --git a/tests/specs/install/install_deprecated_package/package.json.out b/tests/specs/install/install_deprecated_package/package.json.out new file mode 100644 index 0000000000..4b4b08087a --- /dev/null +++ b/tests/specs/install/install_deprecated_package/package.json.out @@ -0,0 +1,3 @@ +{ + "dependencies": { "@denotest/deprecated-package": "^1.0.0" } +} From 1f47248143b2298d38dbada5b431570c067ed663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 20 Aug 2024 19:13:17 +0100 Subject: [PATCH 04/14] fix: adjust suggestion for lockfile regeneration (#25107) Ref https://github.com/denoland/deno/pull/24436#issuecomment-2288568645 --- Cargo.lock | 4 ++-- cli/Cargo.toml | 2 +- cli/graph_util.rs | 4 ++-- tests/integration/jsr_tests.rs | 2 +- tests/integration/npm_tests.rs | 4 ++-- tests/specs/bundle/lockfile/check_error.out | 2 +- tests/specs/install/future_install_node_modules/corrupted.out | 2 +- tests/specs/lockfile/auto_discover_lockfile/main.out | 2 +- tests/specs/lockfile/checksum_at_redirect/run.out | 2 +- tests/specs/lockfile/config_file_lock_boolean/true.main.out | 2 +- .../lockfile/config_file_lock_path/config_file_lock_path.out | 2 +- .../specs/lockfile/config_file_lock_path/lock_check_err2.out | 2 +- tests/specs/lockfile/lock_check_err/lock_check_err.out | 2 +- tests/specs/lockfile/lock_check_err2/lock_check_err2.out | 2 +- .../lockfile/lock_dynamic_imports/lock_dynamic_imports.out | 2 +- tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out | 2 +- .../specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out | 2 +- .../lock_v2_dynamic_imports/lock_v2_dynamic_imports.out | 2 +- tests/specs/lockfile/no_lock/fail.out | 2 +- tests/specs/npm/lock_file_integrity_failure/main.out | 2 +- 20 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index debd091e87..e43bfcc949 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1869,9 +1869,9 @@ dependencies = [ [[package]] name = "deno_npm" -version = "0.23.0" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceef28152643a021fc3487a3ec93ae83996972c087547d97f425c83e15dca932" +checksum = "96d72068f4292455d48ac3b90c644ebf3150fb78c26a480cfb235a9642afe95c" dependencies = [ "anyhow", "async-trait", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 920f0d795d..c3fc704f16 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -72,7 +72,7 @@ deno_emit = "=0.44.0" deno_graph = { version = "=0.81.2" } deno_lint = { version = "=0.63.1", features = ["docs"] } deno_lockfile.workspace = true -deno_npm = "=0.23.0" +deno_npm = "=0.23.1" deno_package_json.workspace = true deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_semver = "=0.5.10" diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 647307bd91..6f0e6acd90 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -803,7 +803,7 @@ fn enhanced_lockfile_error_message(err: &ModuleError) -> Option { "This could be caused by:\n", " * the lock file may be corrupt\n", " * the source itself may be corrupt\n\n", - "Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server." + "Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server." ), package_nv, checksum_err.actual, @@ -824,7 +824,7 @@ fn enhanced_lockfile_error_message(err: &ModuleError) -> Option { "This could be caused by:\n", " * the lock file may be corrupt\n", " * the source itself may be corrupt\n\n", - "Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server." + "Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server." ), specifier, checksum_err.actual, diff --git a/tests/integration/jsr_tests.rs b/tests/integration/jsr_tests.rs index a9397af72e..ef074987eb 100644 --- a/tests/integration/jsr_tests.rs +++ b/tests/integration/jsr_tests.rs @@ -282,7 +282,7 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. ", actual_integrity); test_context .new_command() diff --git a/tests/integration/npm_tests.rs b/tests/integration/npm_tests.rs index 6be0298d89..86db962f43 100644 --- a/tests/integration/npm_tests.rs +++ b/tests/integration/npm_tests.rs @@ -1200,7 +1200,7 @@ fn lock_file_missing_top_level_package() { "error: failed reading lockfile 'deno.lock'\n", "\n", "Caused by:\n", - " 0: The lockfile is corrupt. You can recreate it with --lock-write\n", + " 0: The lockfile is corrupt. Remove the lockfile to regenerate it.\n", " 1: Could not find 'cowsay@1.5.0' in the list of packages.\n" ) ); @@ -1483,7 +1483,7 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile at "[WILDCARD]deno.lock". +Investigate the lockfile; delete it to regenerate the lockfile at "[WILDCARD]deno.lock". "#) .assert_exit_code(10); } diff --git a/tests/specs/bundle/lockfile/check_error.out b/tests/specs/bundle/lockfile/check_error.out index 2b8bdfc96e..6a63a01b43 100644 --- a/tests/specs/bundle/lockfile/check_error.out +++ b/tests/specs/bundle/lockfile/check_error.out @@ -9,4 +9,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/install/future_install_node_modules/corrupted.out b/tests/specs/install/future_install_node_modules/corrupted.out index ade0757447..abfbeadda1 100644 --- a/tests/specs/install/future_install_node_modules/corrupted.out +++ b/tests/specs/install/future_install_node_modules/corrupted.out @@ -1,2 +1,2 @@ error: Integrity check failed for package: "npm:@denotest/esm-basic@1.0.0".[WILDCARD] -Use the --lock-write flag to regenerate the lockfile at [WILDCARD] \ No newline at end of file +Investigate the lockfile; delete it to regenerate the lockfile at [WILDCARD] \ No newline at end of file diff --git a/tests/specs/lockfile/auto_discover_lockfile/main.out b/tests/specs/lockfile/auto_discover_lockfile/main.out index aa24320d14..110f7e85ba 100644 --- a/tests/specs/lockfile/auto_discover_lockfile/main.out +++ b/tests/specs/lockfile/auto_discover_lockfile/main.out @@ -10,4 +10,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/checksum_at_redirect/run.out b/tests/specs/lockfile/checksum_at_redirect/run.out index 75a34777f5..6180bf55d2 100644 --- a/tests/specs/lockfile/checksum_at_redirect/run.out +++ b/tests/specs/lockfile/checksum_at_redirect/run.out @@ -9,4 +9,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/config_file_lock_boolean/true.main.out b/tests/specs/lockfile/config_file_lock_boolean/true.main.out index 11dfc07408..69b467ef0c 100644 --- a/tests/specs/lockfile/config_file_lock_boolean/true.main.out +++ b/tests/specs/lockfile/config_file_lock_boolean/true.main.out @@ -8,4 +8,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/config_file_lock_path/config_file_lock_path.out b/tests/specs/lockfile/config_file_lock_path/config_file_lock_path.out index 1383d945d0..3043b102a5 100644 --- a/tests/specs/lockfile/config_file_lock_path/config_file_lock_path.out +++ b/tests/specs/lockfile/config_file_lock_path/config_file_lock_path.out @@ -8,4 +8,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/config_file_lock_path/lock_check_err2.out b/tests/specs/lockfile/config_file_lock_path/lock_check_err2.out index 1383d945d0..3043b102a5 100644 --- a/tests/specs/lockfile/config_file_lock_path/lock_check_err2.out +++ b/tests/specs/lockfile/config_file_lock_path/lock_check_err2.out @@ -8,4 +8,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/lock_check_err/lock_check_err.out b/tests/specs/lockfile/lock_check_err/lock_check_err.out index 25d22490da..031ae85e61 100644 --- a/tests/specs/lockfile/lock_check_err/lock_check_err.out +++ b/tests/specs/lockfile/lock_check_err/lock_check_err.out @@ -8,4 +8,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/lock_check_err2/lock_check_err2.out b/tests/specs/lockfile/lock_check_err2/lock_check_err2.out index 1383d945d0..3043b102a5 100644 --- a/tests/specs/lockfile/lock_check_err2/lock_check_err2.out +++ b/tests/specs/lockfile/lock_check_err2/lock_check_err2.out @@ -8,4 +8,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.out b/tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.out index 2b8bdfc96e..6a63a01b43 100644 --- a/tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.out +++ b/tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.out @@ -9,4 +9,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out b/tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out index 25d22490da..031ae85e61 100644 --- a/tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out +++ b/tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out @@ -8,4 +8,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out b/tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out index 1383d945d0..3043b102a5 100644 --- a/tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out +++ b/tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out @@ -8,4 +8,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out b/tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out index 2b8bdfc96e..6a63a01b43 100644 --- a/tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out +++ b/tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out @@ -9,4 +9,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/no_lock/fail.out b/tests/specs/lockfile/no_lock/fail.out index 0d67cd4788..14a8d19cfe 100644 --- a/tests/specs/lockfile/no_lock/fail.out +++ b/tests/specs/lockfile/no_lock/fail.out @@ -9,4 +9,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. +Investigate the lockfile; delete it to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/npm/lock_file_integrity_failure/main.out b/tests/specs/npm/lock_file_integrity_failure/main.out index 741edd9d22..1f0fca91ec 100644 --- a/tests/specs/npm/lock_file_integrity_failure/main.out +++ b/tests/specs/npm/lock_file_integrity_failure/main.out @@ -9,4 +9,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use the --lock-write flag to regenerate the lockfile at "[WILDCARD]lock.json". +Investigate the lockfile; delete it to regenerate the lockfile at "[WILDCARD]lock.json". From a7c8bb1596411f91e20ddd5cd54c9dbd055d1059 Mon Sep 17 00:00:00 2001 From: Yazan AbdAl-Rahman Date: Tue, 20 Aug 2024 21:38:06 +0300 Subject: [PATCH 05/14] feat: glob and directory support for `deno check` and `deno cache` cli arg paths (#25001) Closes #24668 Closes #20813 --------- Co-authored-by: David Sherret --- Cargo.lock | 4 +-- cli/Cargo.toml | 2 +- cli/graph_container.rs | 37 +++++++++++----------- tests/specs/cache/globbing/__test__.jsonc | 5 +++ tests/specs/cache/globbing/excluded.tsx | 1 + tests/specs/cache/globbing/main.ts | 1 + tests/specs/check/globbing/__test__.jsonc | 24 ++++++++++++++ tests/specs/check/globbing/excluded.tsx | 0 tests/specs/check/globbing/main.ts | 1 + tests/specs/check/globbing/sub_dir/main.ts | 1 + 10 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 tests/specs/cache/globbing/__test__.jsonc create mode 100644 tests/specs/cache/globbing/excluded.tsx create mode 100644 tests/specs/cache/globbing/main.ts create mode 100644 tests/specs/check/globbing/__test__.jsonc create mode 100644 tests/specs/check/globbing/excluded.tsx create mode 100644 tests/specs/check/globbing/main.ts create mode 100644 tests/specs/check/globbing/sub_dir/main.ts diff --git a/Cargo.lock b/Cargo.lock index e43bfcc949..32454d5163 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1360,9 +1360,9 @@ dependencies = [ [[package]] name = "deno_config" -version = "0.30.0" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e287a8ab3552cf3ef8fc41b2bd7cc041c5e8e1a76de3aeb26e804b570bab37d7" +checksum = "9657dbcc5210407fd9a1b1571310f2fe25c6dd6be2195c964d19f43d70045a95" dependencies = [ "anyhow", "deno_package_json", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c3fc704f16..06384f479c 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -65,7 +65,7 @@ winres.workspace = true [dependencies] deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } deno_cache_dir = { workspace = true } -deno_config = { version = "=0.30.0", features = ["workspace", "sync"] } +deno_config = { version = "=0.30.1", features = ["workspace", "sync"] } deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_doc = { version = "0.146.0", features = ["html", "syntect"] } deno_emit = "=0.44.0" diff --git a/cli/graph_container.rs b/cli/graph_container.rs index cf913464fd..9f71045c69 100644 --- a/cli/graph_container.rs +++ b/cli/graph_container.rs @@ -3,15 +3,18 @@ use std::sync::Arc; use deno_ast::ModuleSpecifier; +use deno_config::glob::FilePatterns; +use deno_config::glob::PathOrPatternSet; use deno_core::error::AnyError; use deno_core::parking_lot::RwLock; -use deno_core::resolve_url_or_path; use deno_graph::ModuleGraph; use deno_runtime::colors; use deno_runtime::deno_permissions::PermissionsContainer; use crate::args::CliOptions; use crate::module_loader::ModuleLoadPreparer; +use crate::util::fs::collect_specifiers; +use crate::util::path::is_script_ext; pub trait ModuleGraphContainer: Clone + 'static { /// Acquires a permit to modify the module graph without other code @@ -99,24 +102,20 @@ impl MainModuleGraphContainer { files: &[String], ) -> Result, AnyError> { let excludes = self.cli_options.workspace().resolve_config_excludes()?; - Ok( - files - .iter() - .filter_map(|file| { - let file_url = - resolve_url_or_path(file, self.cli_options.initial_cwd()).ok()?; - if file_url.scheme() != "file" { - return Some(file_url); - } - // ignore local files that match any of files listed in `exclude` option - let file_path = file_url.to_file_path().ok()?; - if excludes.matches_path(&file_path) { - None - } else { - Some(file_url) - } - }) - .collect::>(), + let include_patterns = + PathOrPatternSet::from_include_relative_path_or_patterns( + self.cli_options.initial_cwd(), + files, + )?; + let file_patterns = FilePatterns { + base: self.cli_options.initial_cwd().to_path_buf(), + include: Some(include_patterns), + exclude: excludes, + }; + collect_specifiers( + file_patterns, + self.cli_options.vendor_dir_path().map(ToOwned::to_owned), + |e| is_script_ext(e.path), ) } } diff --git a/tests/specs/cache/globbing/__test__.jsonc b/tests/specs/cache/globbing/__test__.jsonc new file mode 100644 index 0000000000..9bf210bb41 --- /dev/null +++ b/tests/specs/cache/globbing/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "cache *.ts", + "output": "Download http://localhost:4545/echo.ts\n", + "exitCode": 0 +} diff --git a/tests/specs/cache/globbing/excluded.tsx b/tests/specs/cache/globbing/excluded.tsx new file mode 100644 index 0000000000..b21a330c79 --- /dev/null +++ b/tests/specs/cache/globbing/excluded.tsx @@ -0,0 +1 @@ +import "http://localhost:4545/non-existent.ts"; diff --git a/tests/specs/cache/globbing/main.ts b/tests/specs/cache/globbing/main.ts new file mode 100644 index 0000000000..fe49641188 --- /dev/null +++ b/tests/specs/cache/globbing/main.ts @@ -0,0 +1 @@ +import "http://localhost:4545/echo.ts"; diff --git a/tests/specs/check/globbing/__test__.jsonc b/tests/specs/check/globbing/__test__.jsonc new file mode 100644 index 0000000000..92d9f4d807 --- /dev/null +++ b/tests/specs/check/globbing/__test__.jsonc @@ -0,0 +1,24 @@ +{ + "tests": { + "star": { + "args": "check *.ts", + "output": "Check [WILDLINE]main.ts\n", + "exitCode": 0 + }, + "star_not_found": { + "args": "check *.js", + "output": "Warning No matching files found.\n", + "exitCode": 0 + }, + "glob_star": { + "args": "check **/*.ts", + "output": "Check [WILDLINE]main.ts\nCheck [WILDLINE]sub_dir/main.ts\nerror: TS2322[WILDCARD]", + "exitCode": 1 + }, + "sub_dir": { + "args": "check sub_dir", + "output": "Check [WILDLINE]sub_dir/main.ts\nerror: TS2322[WILDCARD]", + "exitCode": 1 + } + } +} diff --git a/tests/specs/check/globbing/excluded.tsx b/tests/specs/check/globbing/excluded.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/specs/check/globbing/main.ts b/tests/specs/check/globbing/main.ts new file mode 100644 index 0000000000..efa57a7ed3 --- /dev/null +++ b/tests/specs/check/globbing/main.ts @@ -0,0 +1 @@ +console.log("globbing_support_done"); diff --git a/tests/specs/check/globbing/sub_dir/main.ts b/tests/specs/check/globbing/sub_dir/main.ts new file mode 100644 index 0000000000..4f4c3ce9c2 --- /dev/null +++ b/tests/specs/check/globbing/sub_dir/main.ts @@ -0,0 +1 @@ +const value: number = ""; From acba2cd48c3b8725c93513edc291a107bdc7eeaf Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 20 Aug 2024 19:38:47 +0100 Subject: [PATCH 06/14] fix(lsp): include scoped import map keys in completions (#25047) --- cli/lsp/completions.rs | 16 ++++++++-------- tests/integration/lsp_tests.rs | 35 ++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index 7e0705e99d..ab2d8000c7 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -249,7 +249,7 @@ pub async fn get_import_completions( .collect(); let mut is_incomplete = false; if let Some(import_map) = maybe_import_map { - items.extend(get_base_import_map_completions(import_map)); + items.extend(get_base_import_map_completions(import_map, specifier)); } if let Some(origin_items) = module_registries.get_origin_completions(&text, &range) @@ -268,20 +268,20 @@ pub async fn get_import_completions( /// map as completion items. fn get_base_import_map_completions( import_map: &ImportMap, + referrer: &ModuleSpecifier, ) -> Vec { import_map - .imports() - .keys() - .map(|key| { + .entries_for_referrer(referrer) + .map(|entry| { // for some strange reason, keys that start with `/` get stored in the // import map as `file:///`, and so when we pull the keys out, we need to // change the behavior - let mut label = if key.starts_with("file://") { - FILE_PROTO_RE.replace(key, "").to_string() + let mut label = if entry.key.starts_with("file://") { + FILE_PROTO_RE.replace(entry.key, "").to_string() } else { - key.to_string() + entry.key.to_string() }; - let kind = if key.ends_with('/') { + let kind = if entry.key.ends_with('/') { label.pop(); Some(lsp::CompletionItemKind::FOLDER) } else { diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 3d20efbba0..cacd05d9fb 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -1346,23 +1346,27 @@ fn lsp_import_map_import_completions() { let context = TestContextBuilder::new().use_temp_cwd().build(); let temp_dir = context.temp_dir(); temp_dir.write( - "import-map.json", - r#"{ - "imports": { - "/~/": "./lib/", - "/#/": "./src/", - "fs": "https://example.com/fs/index.js", - "std/": "https://example.com/std@0.123.0/" - } -}"#, + "deno.json", + json!({ + "imports": { + "/~/": "./lib/", + "/#/": "./src/", + "fs": "https://example.com/fs/index.js", + "std/": "https://example.com/std@0.123.0/", + }, + "scopes": { + "file:///": { + "file": "./file.ts", + }, + }, + }) + .to_string(), ); temp_dir.create_dir_all("lib"); temp_dir.write("lib/b.ts", r#"export const b = "b";"#); let mut client = context.new_lsp_command().build(); - client.initialize(|builder| { - builder.set_import_map("import-map.json"); - }); + client.initialize_default(); let uri = temp_dir.uri().join("a.ts").unwrap(); @@ -1403,6 +1407,13 @@ fn lsp_import_map_import_completions() { "insertText": "..", "commitCharacters": ["\"", "'"], }, { + "label": "file", + "kind": 17, + "detail": "(import map)", + "sortText": "file", + "insertText": "file", + "commitCharacters": ["\"", "'"], + }, { "label": "std", "kind": 19, "detail": "(import map)", From 7bfb93135d8ee526a8de32d7025896caed3acf21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 20 Aug 2024 20:02:26 +0100 Subject: [PATCH 07/14] chore(release): Release Deno v1.46.0-rc.3 (#25112) --- Cargo.lock | 2 +- cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 32454d5163..552c02e2b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1144,7 +1144,7 @@ dependencies = [ [[package]] name = "deno" -version = "1.46.0-rc.2" +version = "1.46.0-rc.3" dependencies = [ "async-trait", "base32", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 06384f479c..d0b871f493 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno" -version = "1.46.0-rc.2" +version = "1.46.0-rc.3" authors.workspace = true default-run = "deno" edition.workspace = true From 2f47b4d1fd8e37a5e45bc1b8f3623708e0f95e2e Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:07:11 -0700 Subject: [PATCH 08/14] chore: Remove stray `console.error` log in `node:child_process` (#25111) Missed removing it before committing --- ext/node/polyfills/internal/child_process.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/node/polyfills/internal/child_process.ts b/ext/node/polyfills/internal/child_process.ts index edc11df736..3547897b9a 100644 --- a/ext/node/polyfills/internal/child_process.ts +++ b/ext/node/polyfills/internal/child_process.ts @@ -55,7 +55,6 @@ import process from "node:process"; import { StringPrototypeSlice } from "ext:deno_node/internal/primordials.mjs"; import { StreamBase } from "ext:deno_node/internal_binding/stream_wrap.ts"; import { Pipe, socketType } from "ext:deno_node/internal_binding/pipe_wrap.ts"; -import console from "node:console"; import { Socket } from "node:net"; export function mapValues( @@ -1387,7 +1386,6 @@ export function setupChannel(target: any, ipc: number) { if (!target.connected) { const err = new ERR_IPC_CHANNEL_CLOSED(); if (typeof callback === "function") { - console.error("ChildProcess.send with callback"); process.nextTick(callback, err); } else { nextTick(() => target.emit("error", err)); From a7c002ae634b20a2f84c90417327a88c9ac2df99 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 20 Aug 2024 15:14:37 -0400 Subject: [PATCH 09/14] chore: enable no-console dlint rule (#25113) --- .dlint.json | 1 + cli/bench/console.js | 3 ++ cli/bench/encode_into.js | 3 ++ cli/bench/getrandom.js | 3 ++ cli/bench/http/deno_tcp.ts | 1 + cli/bench/op_now.js | 3 ++ cli/bench/secure_curves.js | 3 ++ cli/bench/stdio/stdio.js | 2 ++ cli/bench/tty.js | 3 ++ cli/bench/url_parse.js | 3 ++ cli/bench/webstorage.js | 2 ++ cli/bench/write_file.js | 3 ++ ext/cron/01_cron.ts | 1 + ext/http/00_serve.ts | 7 ++++ ext/kv/01_db.ts | 1 + ext/node/polyfills/_utils.ts | 1 + ext/node/polyfills/http.ts | 1 + ext/node/polyfills/http2.ts | 4 +++ ext/node/polyfills/internal/util/debuglog.ts | 2 ++ ext/node/polyfills/testing.ts | 1 + ext/node/polyfills/util.ts | 1 + ext/node/polyfills/worker_threads.ts | 2 +- ext/web/06_streams.js | 1 + runtime/js/99_main.js | 35 +++++++++++++------ tests/ffi/tests/event_loop_integration.ts | 2 ++ tests/ffi/tests/ffi_callback_errors.ts | 2 ++ tests/napi/cleanup_hook_test.js | 2 ++ tests/node_compat/runner/setup.ts | 2 ++ tests/node_compat/test.ts | 2 ++ .../test/fixtures/child-process-spawn-node.js | 4 +-- tests/unit/console_test.ts | 2 ++ tests/unit/fetch_test.ts | 3 ++ tests/unit/serve_test.ts | 2 ++ tests/unit/timers_test.ts | 3 ++ tests/unit/worker_test.ts | 2 ++ tests/unit_node/_fs/_fs_write_test.ts | 3 ++ tests/unit_node/http2_test.ts | 2 ++ tests/unit_node/http_test.ts | 2 ++ tests/unit_node/net_test.ts | 2 ++ tests/unit_node/process_test.ts | 3 +- tests/wpt/wpt.ts | 2 ++ tools/copyright_checker.js | 2 ++ tools/lint.js | 23 +++++------- tools/release/00_start_release.ts | 3 ++ tools/release/03_publish_crates.ts | 3 ++ tools/release/promote_to_rc.ts | 2 ++ tools/upload_wptfyi.js | 2 ++ tools/util.js | 3 ++ tools/verify_pr_title.js | 3 ++ 49 files changed, 138 insertions(+), 30 deletions(-) diff --git a/.dlint.json b/.dlint.json index d25defffb1..f84d2b233c 100644 --- a/.dlint.json +++ b/.dlint.json @@ -4,6 +4,7 @@ "include": [ "ban-untagged-todo", "camelcase", + "no-console", "guard-for-in" ], "exclude": [ diff --git a/cli/bench/console.js b/cli/bench/console.js index 947061a3b9..1d336fbbde 100644 --- a/cli/bench/console.js +++ b/cli/bench/console.js @@ -1,3 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + const count = 100000; for (let i = 0; i < count; i++) console.log("Hello World"); diff --git a/cli/bench/encode_into.js b/cli/bench/encode_into.js index 4881f87528..11f5a56d90 100644 --- a/cli/bench/encode_into.js +++ b/cli/bench/encode_into.js @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + let [total, count] = typeof Deno !== "undefined" ? Deno.args : [process.argv[2], process.argv[3]]; diff --git a/cli/bench/getrandom.js b/cli/bench/getrandom.js index 87149afebd..3c3ec4aa19 100644 --- a/cli/bench/getrandom.js +++ b/cli/bench/getrandom.js @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + let [total, count] = typeof Deno !== "undefined" ? Deno.args : [process.argv[2], process.argv[3]]; diff --git a/cli/bench/http/deno_tcp.ts b/cli/bench/http/deno_tcp.ts index bac9ac4973..b795910737 100644 --- a/cli/bench/http/deno_tcp.ts +++ b/cli/bench/http/deno_tcp.ts @@ -3,6 +3,7 @@ // TODO(bartlomieju): Replace this with a real HTTP server once // https://github.com/denoland/deno/issues/726 is completed. // Note: this is a keep-alive server. +// deno-lint-ignore-file no-console const addr = Deno.args[0] || "127.0.0.1:4500"; const [hostname, port] = addr.split(":"); const listener = Deno.listen({ hostname, port: Number(port) }); diff --git a/cli/bench/op_now.js b/cli/bench/op_now.js index ba6be9c3a0..bcc3ea3c56 100644 --- a/cli/bench/op_now.js +++ b/cli/bench/op_now.js @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + const queueMicrotask = globalThis.queueMicrotask || process.nextTick; let [total, count] = typeof Deno !== "undefined" ? Deno.args diff --git a/cli/bench/secure_curves.js b/cli/bench/secure_curves.js index d1e909c4c8..02d248b23f 100644 --- a/cli/bench/secure_curves.js +++ b/cli/bench/secure_curves.js @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + let [total, count] = typeof Deno !== "undefined" ? Deno.args : [process.argv[2], process.argv[3]]; diff --git a/cli/bench/stdio/stdio.js b/cli/bench/stdio/stdio.js index 7f0e16b4a0..81bea835a6 100644 --- a/cli/bench/stdio/stdio.js +++ b/cli/bench/stdio/stdio.js @@ -2,6 +2,8 @@ // // From https://github.com/just-js/benchmarks/tree/main/01-stdio +// deno-lint-ignore-file no-console + const blocksize = parseInt(Deno.args[0] || 65536); const buf = new Uint8Array(blocksize); let size = 0; diff --git a/cli/bench/tty.js b/cli/bench/tty.js index 62319c71f2..248a901137 100644 --- a/cli/bench/tty.js +++ b/cli/bench/tty.js @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + const queueMicrotask = globalThis.queueMicrotask || process.nextTick; let [total, count] = typeof Deno !== "undefined" ? Deno.args diff --git a/cli/bench/url_parse.js b/cli/bench/url_parse.js index c9b62107f5..367cf73f46 100644 --- a/cli/bench/url_parse.js +++ b/cli/bench/url_parse.js @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + const queueMicrotask = globalThis.queueMicrotask || process.nextTick; let [total, count] = typeof Deno !== "undefined" ? Deno.args diff --git a/cli/bench/webstorage.js b/cli/bench/webstorage.js index b200ef2532..d19f024c63 100644 --- a/cli/bench/webstorage.js +++ b/cli/bench/webstorage.js @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + // Note: when benchmarking across different Deno version, make sure to clear // the DENO_DIR cache. let [total, count] = typeof Deno !== "undefined" ? Deno.args : []; diff --git a/cli/bench/write_file.js b/cli/bench/write_file.js index ab1e2280ee..104a23a8db 100644 --- a/cli/bench/write_file.js +++ b/cli/bench/write_file.js @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + const queueMicrotask = globalThis.queueMicrotask || process.nextTick; let [total, count] = typeof Deno !== "undefined" ? Deno.args diff --git a/ext/cron/01_cron.ts b/ext/cron/01_cron.ts index 7592e75ef5..017da8ae2f 100644 --- a/ext/cron/01_cron.ts +++ b/ext/cron/01_cron.ts @@ -157,6 +157,7 @@ function cron( const _res = isPromise(result) ? (await result) : result; success = true; } catch (error) { + // deno-lint-ignore no-console console.error(`Exception in cron handler ${name}`, error); success = false; } diff --git a/ext/http/00_serve.ts b/ext/http/00_serve.ts index 9c6f805528..02910d580d 100644 --- a/ext/http/00_serve.ts +++ b/ext/http/00_serve.ts @@ -525,6 +525,7 @@ function mapToCallback(context, callback, onError) { ); } } catch (error) { + // deno-lint-ignore no-console console.error("Exception in onError while handling exception", error); response = internalServerError(); } @@ -533,6 +534,7 @@ function mapToCallback(context, callback, onError) { if (innerRequest?.[_upgraded]) { // We're done here as the connection has been upgraded during the callback and no longer requires servicing. if (response !== UPGRADE_RESPONSE_SENTINEL) { + // deno-lint-ignore no-console console.error("Upgrade response was not returned from callback"); context.close(); } @@ -612,6 +614,7 @@ function serve(arg1, arg2) { const wantsUnix = ObjectHasOwn(options, "path"); const signal = options.signal; const onError = options.onError ?? function (error) { + // deno-lint-ignore no-console console.error(error); return internalServerError(); }; @@ -627,6 +630,7 @@ function serve(arg1, arg2) { if (options.onListen) { options.onListen(listener.addr); } else { + // deno-lint-ignore no-console console.log(`Listening on ${path}`); } }); @@ -684,6 +688,7 @@ function serve(arg1, arg2) { const host = StringPrototypeIncludes(addr.hostname, ":") ? `[${addr.hostname}]` : addr.hostname; + // deno-lint-ignore no-console console.log(`Listening on ${scheme}${host}:${addr.port}/`); } }; @@ -729,6 +734,7 @@ function serveHttpOn(context, addr, callback) { const promiseErrorHandler = (error) => { // Abnormal exit + // deno-lint-ignore no-console console.error( "Terminating Deno.serve loop due to unexpected error", error, @@ -856,6 +862,7 @@ function registerDeclarativeServer(exports) { const nThreads = serveWorkerCount > 1 ? ` with ${serveWorkerCount} threads` : ""; + // deno-lint-ignore no-console console.debug( `%cdeno serve%c: Listening on %chttp://${hostname}:${port}/%c${nThreads}`, "color: green", diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts index 9aa2036dd5..418ce3ff26 100644 --- a/ext/kv/01_db.ts +++ b/ext/kv/01_db.ts @@ -318,6 +318,7 @@ class Kv { const _res = isPromise(result) ? (await result) : result; success = true; } catch (error) { + // deno-lint-ignore no-console console.error("Exception in queue handler", error); } finally { const promise: Promise = op_kv_finish_dequeued_message( diff --git a/ext/node/polyfills/_utils.ts b/ext/node/polyfills/_utils.ts index 78b9bdddc3..b50c113e14 100644 --- a/ext/node/polyfills/_utils.ts +++ b/ext/node/polyfills/_utils.ts @@ -42,6 +42,7 @@ export function warnNotImplemented(msg?: string) { const message = msg ? `Warning: Not implemented: ${msg}` : "Warning: Not implemented"; + // deno-lint-ignore no-console console.warn(message); } diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 920f3a5b09..76291490e3 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -1836,6 +1836,7 @@ export class ServerImpl extends EventEmitter { } setTimeout() { + // deno-lint-ignore no-console console.error("Not implemented: Server.setTimeout()"); } diff --git a/ext/node/polyfills/http2.ts b/ext/node/polyfills/http2.ts index baa2c6e219..98edf40f4e 100644 --- a/ext/node/polyfills/http2.ts +++ b/ext/node/polyfills/http2.ts @@ -127,6 +127,7 @@ type Http2Headers = Record; const debugHttp2Enabled = false; function debugHttp2(...args) { if (debugHttp2Enabled) { + // deno-lint-ignore no-console console.log(...args); } } @@ -1636,16 +1637,19 @@ export class Http2Server extends Server { this.emit("stream", stream, headers); return await stream._deferred.promise; } catch (e) { + // deno-lint-ignore no-console console.log(">>> Error in serveHttpOnConnection", e); } return new Response(""); }, () => { + // deno-lint-ignore no-console console.log(">>> error"); }, () => {}, ); } catch (e) { + // deno-lint-ignore no-console console.log(">>> Error in Http2Server", e); } }, diff --git a/ext/node/polyfills/internal/util/debuglog.ts b/ext/node/polyfills/internal/util/debuglog.ts index 9bbaed606f..bbaba7b6fc 100644 --- a/ext/node/polyfills/internal/util/debuglog.ts +++ b/ext/node/polyfills/internal/util/debuglog.ts @@ -30,6 +30,7 @@ export function initializeDebugEnv(debugEnv: string) { // NODE_DEBUG=http or NODE_DEBUG=http2. function emitWarningIfNeeded(set: string) { if ("HTTP" === set || "HTTP2" === set) { + // deno-lint-ignore no-console console.warn( "Setting the NODE_DEBUG environment variable " + "to '" + set.toLowerCase() + "' can expose sensitive " + @@ -50,6 +51,7 @@ function debuglogImpl( emitWarningIfNeeded(set); debugImpls[set] = function debug(...args: unknown[]) { const msg = args.map((arg) => inspect(arg)).join(" "); + // deno-lint-ignore no-console console.error("%s %s: %s", set, String(Deno.pid), msg); }; } else { diff --git a/ext/node/polyfills/testing.ts b/ext/node/polyfills/testing.ts index 92900e6323..901c38ed36 100644 --- a/ext/node/polyfills/testing.ts +++ b/ext/node/polyfills/testing.ts @@ -28,6 +28,7 @@ class NodeTestContext { } diagnostic(message) { + // deno-lint-ignore no-console console.log("DIAGNOSTIC:", message); } diff --git a/ext/node/polyfills/util.ts b/ext/node/polyfills/util.ts index eee171ccf0..cb4e6498a4 100644 --- a/ext/node/polyfills/util.ts +++ b/ext/node/polyfills/util.ts @@ -234,6 +234,7 @@ function timestamp(): string { */ // deno-lint-ignore no-explicit-any export function log(...args: any[]) { + // deno-lint-ignore no-console console.log("%s - %s", timestamp(), ReflectApply(format, undefined, args)); } diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts index 3519ae217a..eaabe9cd7e 100644 --- a/ext/node/polyfills/worker_threads.ts +++ b/ext/node/polyfills/worker_threads.ts @@ -47,7 +47,7 @@ const { const debugWorkerThreads = false; function debugWT(...args) { if (debugWorkerThreads) { - // deno-lint-ignore prefer-primordials + // deno-lint-ignore prefer-primordials no-console console.log(...args); } } diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index ea3a3110f6..69d333c0d0 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -164,6 +164,7 @@ function resolvePromiseWith(value) { function rethrowAssertionErrorRejection(e) { if (e && ObjectPrototypeIsPrototypeOf(AssertionError.prototype, e)) { queueMicrotask(() => { + // deno-lint-ignore no-console console.error(`Internal Error: ${e.stack}`); }); } diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 013f4996fe..8b0d579ab5 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -125,12 +125,15 @@ function warnOnDeprecatedApi(apiName, stack, ...suggestions) { return; } + // deno-lint-ignore no-console + const logError = console.error; + if (!verboseDeprecatedApiWarning) { if (ALREADY_WARNED_DEPRECATED.has(apiName)) { return; } ALREADY_WARNED_DEPRECATED.add(apiName); - console.error( + logError( `%cwarning: %cUse of deprecated "${apiName}" API. This API will be removed in Deno 2. Run again with DENO_VERBOSE_WARNINGS=1 to get more details.`, "color: yellow;", "font-weight: bold;", @@ -176,40 +179,40 @@ function warnOnDeprecatedApi(apiName, stack, ...suggestions) { } ALREADY_WARNED_DEPRECATED.add(apiName + stack); - console.error( + logError( `%cwarning: %cUse of deprecated "${apiName}" API. This API will be removed in Deno 2.`, "color: yellow;", "font-weight: bold;", ); - console.error(); - console.error( + logError(); + logError( "See the Deno 1 to 2 Migration Guide for more information at https://docs.deno.com/runtime/manual/advanced/migrate_deprecations", ); - console.error(); + logError(); if (stackLines.length > 0) { - console.error("Stack trace:"); + logError("Stack trace:"); for (let i = 0; i < stackLines.length; i++) { - console.error(` ${StringPrototypeTrim(stackLines[i])}`); + logError(` ${StringPrototypeTrim(stackLines[i])}`); } - console.error(); + logError(); } for (let i = 0; i < suggestions.length; i++) { const suggestion = suggestions[i]; - console.error( + logError( `%chint: ${suggestion}`, "font-weight: bold;", ); } if (isFromRemoteDependency) { - console.error( + logError( `%chint: It appears this API is used by a remote dependency. Try upgrading to the latest version of that dependency.`, "font-weight: bold;", ); } - console.error(); + logError(); } function windowClose() { @@ -716,25 +719,33 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) { if (mode === executionModes.serve) { if (serveIsMain && serveWorkerCount) { + // deno-lint-ignore no-console const origLog = console.log; + // deno-lint-ignore no-console const origError = console.error; const prefix = `[serve-worker-0 ]`; + // deno-lint-ignore no-console console.log = (...args) => { return origLog(prefix, ...new primordials.SafeArrayIterator(args)); }; + // deno-lint-ignore no-console console.error = (...args) => { return origError(prefix, ...new primordials.SafeArrayIterator(args)); }; } else if (serveWorkerCount !== null) { + // deno-lint-ignore no-console const origLog = console.log; + // deno-lint-ignore no-console const origError = console.error; const base = `serve-worker-${serveWorkerCount + 1}`; // 15 = "serve-worker-nn".length, assuming // serveWorkerCount < 100 const prefix = `[${StringPrototypePadEnd(base, 15, " ")}]`; + // deno-lint-ignore no-console console.log = (...args) => { return origLog(prefix, ...new primordials.SafeArrayIterator(args)); }; + // deno-lint-ignore no-console console.error = (...args) => { return origError(prefix, ...new primordials.SafeArrayIterator(args)); }; @@ -757,6 +768,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) { if (mode === executionModes.serve && !serve) { if (serveIsMain) { // Only error if main worker + // deno-lint-ignore no-console console.error( `%cerror: %cdeno serve requires %cexport default { fetch }%c in the main module, did you mean to run \"deno run\"?`, "color: yellow;", @@ -770,6 +782,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) { if (serve) { if (mode === executionModes.run) { + // deno-lint-ignore no-console console.error( `%cwarning: %cDetected %cexport default { fetch }%c, did you mean to run \"deno serve\"?`, "color: yellow;", diff --git a/tests/ffi/tests/event_loop_integration.ts b/tests/ffi/tests/event_loop_integration.ts index d9ada60273..e3914d9662 100644 --- a/tests/ffi/tests/event_loop_integration.ts +++ b/tests/ffi/tests/event_loop_integration.ts @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + const targetDir = Deno.execPath().replace(/[^\/\\]+$/, ""); const [libPrefix, libSuffix] = { darwin: ["lib", "dylib"], diff --git a/tests/ffi/tests/ffi_callback_errors.ts b/tests/ffi/tests/ffi_callback_errors.ts index dbd60636ca..797ff236c1 100644 --- a/tests/ffi/tests/ffi_callback_errors.ts +++ b/tests/ffi/tests/ffi_callback_errors.ts @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + const targetDir = Deno.execPath().replace(/[^\/\\]+$/, ""); const [libPrefix, libSuffix] = { darwin: ["lib", "dylib"], diff --git a/tests/napi/cleanup_hook_test.js b/tests/napi/cleanup_hook_test.js index 0d83bc5b4c..017674ad49 100644 --- a/tests/napi/cleanup_hook_test.js +++ b/tests/napi/cleanup_hook_test.js @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + import { assertEquals, loadTestLibrary } from "./common.js"; const properties = loadTestLibrary(); diff --git a/tests/node_compat/runner/setup.ts b/tests/node_compat/runner/setup.ts index 95fee6a20a..37f1aba9b2 100755 --- a/tests/node_compat/runner/setup.ts +++ b/tests/node_compat/runner/setup.ts @@ -1,6 +1,8 @@ #!/usr/bin/env -S deno run --allow-read=. --allow-write=. --allow-run=git --config=tests/config/deno.json // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + /** This copies the test files according to the config file `tests/node_compat/config.jsonc` */ import { walk } from "@std/fs/walk"; diff --git a/tests/node_compat/test.ts b/tests/node_compat/test.ts index b5c9514a33..f6db4ee1ae 100644 --- a/tests/node_compat/test.ts +++ b/tests/node_compat/test.ts @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + /** * This script will run the test files specified in the configuration file. * diff --git a/tests/node_compat/test/fixtures/child-process-spawn-node.js b/tests/node_compat/test/fixtures/child-process-spawn-node.js index da2b557c96..d403aabf91 100644 --- a/tests/node_compat/test/fixtures/child-process-spawn-node.js +++ b/tests/node_compat/test/fixtures/child-process-spawn-node.js @@ -1,7 +1,5 @@ const assert = require("assert"); -// TODO(kt3k): Uncomment this when util.debuglog is added -// const debug = require('util').debuglog('test'); -const debug = console.log; +const debug = require('util').debuglog('test'); function onmessage(m) { debug("CHILD got message:", m); diff --git a/tests/unit/console_test.ts b/tests/unit/console_test.ts index c133624196..63ffff0dcb 100644 --- a/tests/unit/console_test.ts +++ b/tests/unit/console_test.ts @@ -8,6 +8,8 @@ // std/fmt/colors auto determines whether to put colors in or not. We need // better infrastructure here so we can properly test the colors. +// deno-lint-ignore-file no-console + import { assert, assertEquals, diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts index 9b2463bcc3..aa4ff30671 100644 --- a/tests/unit/fetch_test.ts +++ b/tests/unit/fetch_test.ts @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + import { assert, assertEquals, diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index 353621154e..827a094dc4 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + import { assertMatch, assertRejects } from "@std/assert"; import { Buffer, BufReader, BufWriter } from "@std/io"; import { TextProtoReader } from "../testdata/run/textproto.ts"; diff --git a/tests/unit/timers_test.ts b/tests/unit/timers_test.ts index 6e829c07fc..70619ae355 100644 --- a/tests/unit/timers_test.ts +++ b/tests/unit/timers_test.ts @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + import { assert, assertEquals, diff --git a/tests/unit/worker_test.ts b/tests/unit/worker_test.ts index 526618d548..e5966348fe 100644 --- a/tests/unit/worker_test.ts +++ b/tests/unit/worker_test.ts @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + // Requires to be run with `--allow-net` flag import { assert, assertEquals, assertMatch, assertThrows } from "@std/assert"; diff --git a/tests/unit_node/_fs/_fs_write_test.ts b/tests/unit_node/_fs/_fs_write_test.ts index a140548e12..2b07d600bf 100644 --- a/tests/unit_node/_fs/_fs_write_test.ts +++ b/tests/unit_node/_fs/_fs_write_test.ts @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + import { write, writeSync } from "node:fs"; import { assertEquals } from "@std/assert"; import { Buffer } from "node:buffer"; diff --git a/tests/unit_node/http2_test.ts b/tests/unit_node/http2_test.ts index 7cffd04322..8e98bd28d9 100644 --- a/tests/unit_node/http2_test.ts +++ b/tests/unit_node/http2_test.ts @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + import * as http2 from "node:http2"; import { Buffer } from "node:buffer"; import { readFile } from "node:fs/promises"; diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index ec20ec7d7c..2043a00044 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + import EventEmitter from "node:events"; import http, { type RequestOptions, type ServerResponse } from "node:http"; import url from "node:url"; diff --git a/tests/unit_node/net_test.ts b/tests/unit_node/net_test.ts index 521de1e73d..f49ff0ef08 100644 --- a/tests/unit_node/net_test.ts +++ b/tests/unit_node/net_test.ts @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + import * as net from "node:net"; import { assert, assertEquals } from "@std/assert"; import * as path from "@std/path"; diff --git a/tests/unit_node/process_test.ts b/tests/unit_node/process_test.ts index cc9e4dbd4d..a647b0369e 100644 --- a/tests/unit_node/process_test.ts +++ b/tests/unit_node/process_test.ts @@ -1,6 +1,7 @@ -// deno-lint-ignore-file no-undef // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-undef no-console + import process, { arch as importedArch, argv, diff --git a/tests/wpt/wpt.ts b/tests/wpt/wpt.ts index 8879de1332..c42ff51e6e 100755 --- a/tests/wpt/wpt.ts +++ b/tests/wpt/wpt.ts @@ -1,6 +1,8 @@ #!/usr/bin/env -S deno run --allow-write --allow-read --allow-net --allow-env --allow-run --config=tests/config/deno.json // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + // This script is used to run WPT tests for Deno. import { diff --git a/tools/copyright_checker.js b/tools/copyright_checker.js index 3c46f3b1ed..24afe1dfd7 100755 --- a/tools/copyright_checker.js +++ b/tools/copyright_checker.js @@ -1,6 +1,8 @@ #!/usr/bin/env -S deno run --allow-read=. --allow-run=git --config=tests/config/deno.json // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + import { getSources, ROOT_PATH } from "./util.js"; const copyrightYear = 2024; diff --git a/tools/lint.js b/tools/lint.js index aa02a3e2b3..8c2e0f5949 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -1,5 +1,8 @@ #!/usr/bin/env -S deno run --allow-write --allow-read --allow-run --allow-net --config=tests/config/deno.json // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + import { buildMode, getPrebuilt, getSources, join, ROOT_PATH } from "./util.js"; import { checkCopyright } from "./copyright_checker.js"; import * as ciFile from "../.github/workflows/ci.generate.ts"; @@ -44,27 +47,19 @@ async function dlint() { "*.js", "*.ts", ":!:.github/mtime_cache/action.js", - ":!:tests/testdata/swc_syntax_error.ts", - ":!:tests/testdata/error_008_checkjs.js", ":!:cli/bench/testdata/npm/*", ":!:cli/bench/testdata/express-router.js", ":!:cli/bench/testdata/react-dom.js", ":!:cli/compilers/wasm_wrap.js", ":!:cli/tsc/dts/**", + ":!:cli/tsc/*typescript.js", + ":!:cli/tsc/compiler.d.ts", + ":!:runtime/examples/", ":!:target/", ":!:tests/registry/**", ":!:tests/specs/**", - ":!:tests/testdata/encoding/**", - ":!:tests/testdata/error_syntax.js", - ":!:tests/testdata/file_extensions/ts_with_js_extension.js", - ":!:tests/testdata/fmt/**", - ":!:tests/testdata/lint/**", - ":!:tests/testdata/npm/**", - ":!:tests/testdata/run/**", - ":!:tests/testdata/tsc/**", - ":!:tests/testdata/test/glob/**", - ":!:cli/tsc/*typescript.js", - ":!:cli/tsc/compiler.d.ts", + ":!:tests/testdata/**", + ":!:tests/unit_node/testdata/**", ":!:tests/wpt/suite/**", ":!:tests/wpt/runner/**", ]); @@ -93,7 +88,7 @@ async function dlint() { }), ); } - await Promise.all(pending); + await Promise.allSettled(pending); } // `prefer-primordials` has to apply only to files related to bootstrapping, diff --git a/tools/release/00_start_release.ts b/tools/release/00_start_release.ts index b5c35ae5a5..125a76af66 100755 --- a/tools/release/00_start_release.ts +++ b/tools/release/00_start_release.ts @@ -1,5 +1,8 @@ #!/usr/bin/env -S deno run -A --quiet --lock=tools/deno.lock.json // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + import { $, createOctoKit, semver } from "./deps.ts"; const currentDirPath = $.path(import.meta).parentOrThrow(); diff --git a/tools/release/03_publish_crates.ts b/tools/release/03_publish_crates.ts index dcad8ed928..ecfb75e796 100755 --- a/tools/release/03_publish_crates.ts +++ b/tools/release/03_publish_crates.ts @@ -1,5 +1,8 @@ #!/usr/bin/env -S deno run -A --lock=tools/deno.lock.json // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + import { DenoWorkspace } from "./deno_workspace.ts"; import { $, getCratesPublishOrder } from "./deps.ts"; diff --git a/tools/release/promote_to_rc.ts b/tools/release/promote_to_rc.ts index eb49336783..297f5f4628 100644 --- a/tools/release/promote_to_rc.ts +++ b/tools/release/promote_to_rc.ts @@ -1,6 +1,8 @@ #!/usr/bin/env -S deno run -A --lock=tools/deno.lock.json // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-console + import { $ } from "jsr:@david/dax@0.41.0"; import { gray } from "jsr:@std/fmt@1/colors"; import { patchver } from "jsr:@deno/patchver@0.1.0"; diff --git a/tools/upload_wptfyi.js b/tools/upload_wptfyi.js index b8f6d7c5ab..23dd4c6602 100644 --- a/tools/upload_wptfyi.js +++ b/tools/upload_wptfyi.js @@ -4,6 +4,8 @@ // passed, will automatically add a status check to the commit with a link to // the wpt.fyi page. +// deno-lint-ignore-file no-console + import { gzip } from "https://deno.land/x/compress@v0.4.1/gzip/mod.ts"; const user = Deno.env.get("WPT_FYI_USER"); diff --git a/tools/util.js b/tools/util.js index ed322d0d87..99133628ce 100644 --- a/tools/util.js +++ b/tools/util.js @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + import { dirname, fromFileUrl, join, resolve, toFileUrl } from "@std/path"; import { wait } from "https://deno.land/x/wait@0.1.13/mod.ts"; export { dirname, fromFileUrl, join, resolve, toFileUrl }; diff --git a/tools/verify_pr_title.js b/tools/verify_pr_title.js index d7b393bcd3..98cc30aa7e 100644 --- a/tools/verify_pr_title.js +++ b/tools/verify_pr_title.js @@ -1,4 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +// deno-lint-ignore-file no-console + const prTitle = Deno.args[0]; if (prTitle == null) { From 37279e0b0a4300318da472bf0a8bdb894746537f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 20 Aug 2024 16:32:01 -0400 Subject: [PATCH 10/14] fix(add): error when config file contains importMap field (#25115) The "imports" field has higher precedence than "importMap", so we should error when `deno add` goes to add an `"imports"` field. Closes https://github.com/denoland/deno/issues/24264 Closes https://github.com/denoland/deno/pull/24478 --- cli/tools/registry/pm.rs | 11 +++++++++++ tests/specs/add/error_import_map_field/__test__.jsonc | 5 +++++ tests/specs/add/error_import_map_field/add.out | 2 ++ tests/specs/add/error_import_map_field/deno.json | 3 +++ .../specs/add/error_import_map_field/import_map.json | 1 + 5 files changed, 22 insertions(+) create mode 100644 tests/specs/add/error_import_map_field/__test__.jsonc create mode 100644 tests/specs/add/error_import_map_field/add.out create mode 100644 tests/specs/add/error_import_map_field/deno.json create mode 100644 tests/specs/add/error_import_map_field/import_map.json diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index 52f3310ba4..3cdef071f9 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -289,6 +289,17 @@ pub async fn add( _ => bail!("Failed updating config file due to no object."), }; + if obj.get_string("importMap").is_some() { + bail!( + concat!( + "`deno add` is not supported when configuration file contains an \"importMap\" field. ", + "Inline the import map into the Deno configuration file.\n", + " at {}", + ), + config_specifier + ); + } + let mut existing_imports = config_file.existing_imports()?; let is_npm = config_file.is_npm(); diff --git a/tests/specs/add/error_import_map_field/__test__.jsonc b/tests/specs/add/error_import_map_field/__test__.jsonc new file mode 100644 index 0000000000..bf26b74e43 --- /dev/null +++ b/tests/specs/add/error_import_map_field/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "add jsr:@denotest/add", + "output": "add.out", + "exitCode": 1 +} diff --git a/tests/specs/add/error_import_map_field/add.out b/tests/specs/add/error_import_map_field/add.out new file mode 100644 index 0000000000..ab787ea78e --- /dev/null +++ b/tests/specs/add/error_import_map_field/add.out @@ -0,0 +1,2 @@ +error: `deno add` is not supported when configuration file contains an "importMap" field. Inline the import map into the Deno configuration file. + at file:///[WILDLINE]/deno.json diff --git a/tests/specs/add/error_import_map_field/deno.json b/tests/specs/add/error_import_map_field/deno.json new file mode 100644 index 0000000000..12a79304f3 --- /dev/null +++ b/tests/specs/add/error_import_map_field/deno.json @@ -0,0 +1,3 @@ +{ + "importMap": "./import_map.json" +} diff --git a/tests/specs/add/error_import_map_field/import_map.json b/tests/specs/add/error_import_map_field/import_map.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/tests/specs/add/error_import_map_field/import_map.json @@ -0,0 +1 @@ +{} From a3a54bc747abe8ca4cd7b0bdbb3e5276a062e914 Mon Sep 17 00:00:00 2001 From: seb Date: Tue, 20 Aug 2024 14:25:41 -0700 Subject: [PATCH 11/14] fix(ext/net): validate port in Deno.{connect,serve,listen} (#24399) Co-authored-by: Will Leach <4619280+melbourne2991@users.noreply.github.com> Co-authored-by: Luca Casonato Co-authored-by: David Sherret --- ext/net/01_net.js | 31 +++++++++++++-- ext/net/02_tls.js | 6 +-- tests/unit/serve_test.ts | 82 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 6 deletions(-) diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 536f79bbfa..a41a27543a 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -33,9 +33,12 @@ const UDP_DGRAM_MAXSIZE = 65507; const { Error, Number, + NumberIsNaN, + NumberIsInteger, ObjectPrototypeIsPrototypeOf, ObjectDefineProperty, PromiseResolve, + RangeError, SafeSet, SetPrototypeAdd, SetPrototypeDelete, @@ -531,10 +534,11 @@ const listenOptionApiName = Symbol("listenOptionApiName"); function listen(args) { switch (args.transport ?? "tcp") { case "tcp": { + const port = validatePort(args.port); const { 0: rid, 1: addr } = op_net_listen_tcp( { hostname: args.hostname ?? "0.0.0.0", - port: Number(args.port), + port, }, args.reusePort, args.loadBalanced ?? false, @@ -558,14 +562,33 @@ function listen(args) { } } +function validatePort(maybePort) { + if (typeof maybePort !== "number" && typeof maybePort !== "string") { + throw new TypeError(`Invalid port (expected number): ${maybePort}`); + } + if (maybePort === "") throw new TypeError("Invalid port: ''"); + const port = Number(maybePort); + if (!NumberIsInteger(port)) { + if (NumberIsNaN(port) && !NumberIsNaN(maybePort)) { + throw new TypeError(`Invalid port: '${maybePort}'`); + } else { + throw new TypeError(`Invalid port: ${maybePort}`); + } + } else if (port < 0 || port > 65535) { + throw new RangeError(`Invalid port (out of range): ${maybePort}`); + } + return port; +} + function createListenDatagram(udpOpFn, unixOpFn) { return function listenDatagram(args) { switch (args.transport) { case "udp": { + const port = validatePort(args.port); const { 0: rid, 1: addr } = udpOpFn( { hostname: args.hostname ?? "127.0.0.1", - port: args.port, + port, }, args.reuseAddress ?? false, args.loopback ?? false, @@ -590,10 +613,11 @@ function createListenDatagram(udpOpFn, unixOpFn) { async function connect(args) { switch (args.transport ?? "tcp") { case "tcp": { + const port = validatePort(args.port); const { 0: rid, 1: localAddr, 2: remoteAddr } = await op_net_connect_tcp( { hostname: args.hostname ?? "127.0.0.1", - port: args.port, + port, }, ); localAddr.transport = "tcp"; @@ -626,4 +650,5 @@ export { shutdown, TcpConn, UnixConn, + validatePort, }; diff --git a/ext/net/02_tls.js b/ext/net/02_tls.js index 81bcfb3bd1..f6197e1599 100644 --- a/ext/net/02_tls.js +++ b/ext/net/02_tls.js @@ -17,13 +17,12 @@ import { op_tls_start, } from "ext:core/ops"; const { - Number, ObjectDefineProperty, TypeError, SymbolFor, } = primordials; -import { Conn, Listener } from "ext:deno_net/01_net.js"; +import { Conn, Listener, validatePort } from "ext:deno_net/01_net.js"; class TlsConn extends Conn { #rid = 0; @@ -259,6 +258,7 @@ function listenTls({ if (transport !== "tcp") { throw new TypeError(`Unsupported transport: '${transport}'`); } + port = validatePort(port); if (!hasTlsKeyPairOptions(arguments[0])) { throw new TypeError( @@ -267,7 +267,7 @@ function listenTls({ } const keyPair = loadTlsKeyPair("Deno.listenTls", arguments[0]); const { 0: rid, 1: localAddr } = op_net_listen_tls( - { hostname, port: Number(port) }, + { hostname, port }, { alpnProtocols, reusePort }, keyPair, ); diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index 827a094dc4..ea5a7d3efc 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -861,6 +861,88 @@ Deno.test( }, ); +Deno.test({ permissions: { net: true } }, async function validPortString() { + const server = Deno.serve({ + handler: (_request) => new Response(), + port: "4501" as unknown as number, + }); + assertEquals(server.addr.transport, "tcp"); + assertEquals(server.addr.port, 4501); + await server.shutdown(); +}); + +Deno.test({ permissions: { net: true } }, function invalidPortFloat() { + assertThrows( + () => + Deno.serve({ + handler: (_request) => new Response(), + port: 45.1, + }), + TypeError, + `Invalid port: 45.1`, + ); +}); + +Deno.test({ permissions: { net: true } }, function invalidPortNaN() { + assertThrows( + () => + Deno.serve({ + handler: (_request) => new Response(), + port: NaN, + }), + TypeError, + `Invalid port: NaN`, + ); +}); + +Deno.test({ permissions: { net: true } }, function invalidPortString() { + assertThrows( + () => + Deno.serve({ + handler: (_request) => new Response(), + port: "some-non-number-string" as unknown as number, + }), + TypeError, + `Invalid port: 'some-non-number-string'`, + ); +}); + +Deno.test({ permissions: { net: true } }, function invalidPortTooSmall() { + assertThrows( + () => + Deno.serve({ + handler: (_request) => new Response(), + port: -111, + }), + RangeError, + `Invalid port (out of range): -111`, + ); +}); + +Deno.test({ permissions: { net: true } }, function invalidPortTooLarge() { + assertThrows( + () => + Deno.serve({ + handler: (_request) => new Response(), + port: 100000, + }), + RangeError, + `Invalid port (out of range): 100000`, + ); +}); + +Deno.test({ permissions: { net: true } }, function invalidPortType() { + assertThrows( + () => + Deno.serve({ + handler: (_request) => new Response(), + port: true as unknown as number, + }), + TypeError, + `Invalid port (expected number): true`, + ); +}); + function createUrlTest( name: string, methodAndPath: string, From f2668b3a0d2e96f42c21898a1fe7c98ea40fd2a7 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 20 Aug 2024 18:36:53 -0400 Subject: [PATCH 12/14] fix: deserialize lockfile v3 straight (#25121) v4 is a somewhat lossy format and so we can't actually work with v3 by upgrading to v4 and then downgrading. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 552c02e2b2..42b099eec7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1721,9 +1721,9 @@ dependencies = [ [[package]] name = "deno_lockfile" -version = "0.21.1" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b01138860cdf20cfca4c9e6bcda2bbe577f0c784f6f6938205d522ee2b6327ed" +checksum = "04beb67705d894d688e818870a701829223f6f485ef3ce0b8b2a7adac98d9583" dependencies = [ "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 1176656e20..f9f9fb1cd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ deno_ast = { version = "=0.41.2", features = ["transpiling"] } deno_core = { version = "0.304.0" } deno_bench_util = { version = "0.158.0", path = "./bench_util" } -deno_lockfile = "0.21.1" +deno_lockfile = "0.21.2" deno_media_type = { version = "0.1.4", features = ["module_specifier"] } deno_permissions = { version = "0.24.0", path = "./runtime/permissions" } deno_runtime = { version = "0.173.0", path = "./runtime" } From dd8a9c509f0c7c643f60e4b5aee6233383e0dc80 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:47:20 -0700 Subject: [PATCH 13/14] fix: Don't panic if fail to handle JS stack frame (#25122) --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 42b099eec7..65e70f9b41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1389,9 +1389,9 @@ dependencies = [ [[package]] name = "deno_core" -version = "0.304.0" +version = "0.305.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcb02f25a743fe58a117ed5cfd47c4e640761926e294a1f4ba964a0e2c68b4dc" +checksum = "e7c823d9ee0cf31b4b8b6be65bc87a9e6ecb3ed5b244a68bbf25b6b8a477da25" dependencies = [ "anyhow", "bincode", @@ -1888,9 +1888,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.180.0" +version = "0.181.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bbba184551dfe009836a42c0268fea6b4ad036b5154aec5a7625e7a7ce4e315" +checksum = "6c06bd7a0fa5a7bc531a544a889eaf8f3594c22aba147e2efb820c4d8c547a91" dependencies = [ "proc-macro-rules", "proc-macro2", @@ -6252,9 +6252,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.213.0" +version = "0.214.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1831a65bad8086cfc993eaead4cbcb00579c085e43b4952a90024e1243f23b4e" +checksum = "77304686fddb9b8c915396512a2e7bca70b0b2d07edd1898eeefa22918ef45fb" dependencies = [ "num-bigint", "serde", diff --git a/Cargo.toml b/Cargo.toml index f9f9fb1cd9..2ae25e08af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ repository = "https://github.com/denoland/deno" [workspace.dependencies] deno_ast = { version = "=0.41.2", features = ["transpiling"] } -deno_core = { version = "0.304.0" } +deno_core = { version = "0.305.0" } deno_bench_util = { version = "0.158.0", path = "./bench_util" } deno_lockfile = "0.21.2" From e920835417d10f3735645c910e513886cdda6a39 Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Wed, 21 Aug 2024 15:43:17 +0530 Subject: [PATCH 14/14] fix(ext/node): pass content-disposition header as string instead of bytes (#25128) Closes https://github.com/denoland/deno/issues/25117 --- ext/node/polyfills/http.ts | 2 +- tests/unit_node/http_test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 76291490e3..a9eee00191 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -906,7 +906,7 @@ class ClientRequest extends OutgoingMessage { // https://www.rfc-editor.org/rfc/rfc6266#section-4.3 // Refs: https://github.com/nodejs/node/pull/46528 if (isContentDispositionField(key) && this._contentLength) { - value = Buffer.from(value, "latin1"); + value = Buffer.from(value).toString("latin1"); } if (Array.isArray(value)) { diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index 2043a00044..a599754b9f 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -1559,3 +1559,30 @@ Deno.test("[node/http] req.url equals pathname + search", async () => { await promise; }); + +Deno.test("[node/http] ClientRequest content-disposition header works", async () => { + const payload = Buffer.from("hello world"); + let body = ""; + let headers = {} as http.IncomingHttpHeaders; + const { promise, resolve, reject } = Promise.withResolvers(); + const req = http.request("http://localhost:4545/echo_server", { + method: "PUT", + headers: { + "content-disposition": "attachment", + }, + }, (resp) => { + headers = resp.headers; + resp.on("data", (chunk) => { + body += chunk; + }); + + resp.on("end", () => { + resolve(); + }); + }); + req.once("error", (e) => reject(e)); + req.end(payload); + await promise; + assertEquals(body, "hello world"); + assertEquals(headers["content-disposition"], "attachment"); +});