diff --git a/Cargo.lock b/Cargo.lock index 5d72402044..876beaf1c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1308,9 +1308,9 @@ dependencies = [ [[package]] name = "deno_config" -version = "0.22.0" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866d351087e70f8db42d04a773b9a96444d2653ef4bb0fb104fe562b819a57c9" +checksum = "83df0c14d89f4e6e7ff91bfea0b4d5a0a33b4385c517ff4d8b4236d9834561e3" dependencies = [ "anyhow", "deno_semver", diff --git a/Cargo.toml b/Cargo.toml index 2a9c2b9e40..7ac7842281 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,7 +101,7 @@ console_static_text = "=0.8.1" data-encoding = "2.3.3" data-url = "=0.3.0" deno_cache_dir = "=0.10.0" -deno_config = { version = "=0.22.0", default-features = false } +deno_config = { version = "=0.22.2", default-features = false } dlopen2 = "0.6.1" ecb = "=0.1.2" elliptic-curve = { version = "0.13.4", features = ["alloc", "arithmetic", "ecdh", "std", "pem"] } diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index 3421addae8..fa505e7b1e 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -2,13 +2,12 @@ use std::path::PathBuf; +use deno_config::workspace::Workspace; use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; use deno_core::parking_lot::MutexGuard; -use deno_runtime::deno_node::PackageJson; -use crate::args::ConfigFile; use crate::cache; use crate::util::fs::atomic_write_file_with_retries; use crate::Flags; @@ -92,8 +91,7 @@ impl CliLockfile { pub fn discover( flags: &Flags, - maybe_config_file: Option<&ConfigFile>, - maybe_package_json: Option<&PackageJson>, + workspace: &Workspace, ) -> Result, AnyError> { if flags.no_lock || matches!( @@ -109,23 +107,9 @@ impl CliLockfile { let filename = match flags.lock { Some(ref lock) => PathBuf::from(lock), - None => match maybe_config_file { - Some(config_file) => { - if config_file.specifier.scheme() == "file" { - match config_file.resolve_lockfile_path()? { - Some(path) => path, - None => return Ok(None), - } - } else { - return Ok(None); - } - } - None => match maybe_package_json { - Some(package_json) => { - package_json.path.parent().unwrap().join("deno.lock") - } - None => return Ok(None), - }, + None => match workspace.resolve_lockfile_path()? { + Some(path) => path, + None => return Ok(None), }, }; diff --git a/cli/args/mod.rs b/cli/args/mod.rs index a1c8efc318..aaa8185af1 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -902,11 +902,7 @@ impl CliOptions { }), )?; - let maybe_lock_file = CliLockfile::discover( - &flags, - root_folder.deno_json.as_deref(), - root_folder.pkg_json.as_deref(), - )?; + let maybe_lock_file = CliLockfile::discover(&flags, &workspace)?; log::debug!("Finished config loading."); diff --git a/tests/specs/npm/workspace_sub_deno_json/__test__.jsonc b/tests/specs/npm/workspace_sub_deno_json/__test__.jsonc new file mode 100644 index 0000000000..c96e91abfb --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/__test__.jsonc @@ -0,0 +1,17 @@ +{ + "tempDir": true, + "tests": { + "member": { + "args": "run --allow-read member/main.ts", + "output": "member.out" + }, + "member_with_deno_json": { + "args": "run --allow-read member_with_deno_json/main.ts", + "output": "member.out" + }, + "non_member": { + "args": "run --allow-read non_member/main.ts", + "output": "non_member.out" + } + } +} diff --git a/tests/specs/npm/workspace_sub_deno_json/member.out b/tests/specs/npm/workspace_sub_deno_json/member.out new file mode 100644 index 0000000000..8400023d0b --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/member.out @@ -0,0 +1,6 @@ +Warning "nodeModulesDir" field can only be specified in the workspace root deno.json file. + at file:///[WILDLINE]/member_with_deno_json/deno.jsonc +Download http://localhost:4260/chalk +Download http://localhost:4260/chalk/chalk-5.0.1.tgz +Initialize chalk@5.0.1 +true diff --git a/tests/specs/npm/workspace_sub_deno_json/member/main.ts b/tests/specs/npm/workspace_sub_deno_json/member/main.ts new file mode 100644 index 0000000000..ca686daa06 --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/member/main.ts @@ -0,0 +1,4 @@ +import chalk from "npm:chalk@5"; + +const stat = Deno.statSync(new URL("../node_modules", import.meta.url)); +console.log(chalk.green(stat.isDirectory)); diff --git a/tests/specs/npm/workspace_sub_deno_json/member/package.json b/tests/specs/npm/workspace_sub_deno_json/member/package.json new file mode 100644 index 0000000000..1282b2b341 --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/member/package.json @@ -0,0 +1,4 @@ +{ + "name": "member", + "version": "1.0.0" +} diff --git a/tests/specs/npm/workspace_sub_deno_json/member_with_deno_json/deno.jsonc b/tests/specs/npm/workspace_sub_deno_json/member_with_deno_json/deno.jsonc new file mode 100644 index 0000000000..99bd145fe7 --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/member_with_deno_json/deno.jsonc @@ -0,0 +1,4 @@ +{ + // will cause a warning + "nodeModulesDir": true +} diff --git a/tests/specs/npm/workspace_sub_deno_json/member_with_deno_json/main.ts b/tests/specs/npm/workspace_sub_deno_json/member_with_deno_json/main.ts new file mode 100644 index 0000000000..ca686daa06 --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/member_with_deno_json/main.ts @@ -0,0 +1,4 @@ +import chalk from "npm:chalk@5"; + +const stat = Deno.statSync(new URL("../node_modules", import.meta.url)); +console.log(chalk.green(stat.isDirectory)); diff --git a/tests/specs/npm/workspace_sub_deno_json/member_with_deno_json/package.json b/tests/specs/npm/workspace_sub_deno_json/member_with_deno_json/package.json new file mode 100644 index 0000000000..8dd4919c62 --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/member_with_deno_json/package.json @@ -0,0 +1,4 @@ +{ + "name": "member-with-deno-json", + "version": "1.0.0" +} diff --git a/tests/specs/npm/workspace_sub_deno_json/non_member.out b/tests/specs/npm/workspace_sub_deno_json/non_member.out new file mode 100644 index 0000000000..aabdca94bb --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/non_member.out @@ -0,0 +1,4 @@ +Download http://localhost:4260/chalk +Download http://localhost:4260/chalk/chalk-5.0.1.tgz +Initialize chalk@5.0.1 +true diff --git a/tests/specs/npm/workspace_sub_deno_json/non_member/deno.json b/tests/specs/npm/workspace_sub_deno_json/non_member/deno.json new file mode 100644 index 0000000000..176354f98f --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/non_member/deno.json @@ -0,0 +1,3 @@ +{ + "nodeModulesDir": true +} diff --git a/tests/specs/npm/workspace_sub_deno_json/non_member/deno.lock b/tests/specs/npm/workspace_sub_deno_json/non_member/deno.lock new file mode 100644 index 0000000000..d1a32dd0c8 --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/non_member/deno.lock @@ -0,0 +1,15 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "npm:chalk@5": "npm:chalk@5.0.1" + }, + "npm": { + "chalk@5.0.1": { + "integrity": "sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==", + "dependencies": {} + } + } + }, + "remote": {} +} diff --git a/tests/specs/npm/workspace_sub_deno_json/non_member/main.ts b/tests/specs/npm/workspace_sub_deno_json/non_member/main.ts new file mode 100644 index 0000000000..53bd103396 --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/non_member/main.ts @@ -0,0 +1,4 @@ +import chalk from "npm:chalk@5"; + +const stat = Deno.statSync(new URL("node_modules", import.meta.url)); +console.log(chalk.green(stat.isDirectory)); diff --git a/tests/specs/npm/workspace_sub_deno_json/package.json b/tests/specs/npm/workspace_sub_deno_json/package.json new file mode 100644 index 0000000000..e37c1f2d89 --- /dev/null +++ b/tests/specs/npm/workspace_sub_deno_json/package.json @@ -0,0 +1,3 @@ +{ + "workspaces": ["./member", "./member_with_deno_json"] +}