From 4d2d764816d266e42f3b2251248b100abb667c83 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 10 Jul 2024 14:46:09 -0400 Subject: [PATCH] feat(jsr): support publishing jsr packages in npm workspaces (#24507) Supports publishing an npm workspace with a directory structure similar to the following: - workspace - package.json - package-a - package.json - jsr.json - package-b - package.json - jsr.json deno_config PR: https://github.com/denoland/deno_config/pull/77 Closes https://github.com/denoland/deno/issues/23638 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- cli/args/mod.rs | 21 +++++++++++-------- cli/lsp/resolver.rs | 2 +- .../publish/npm_workspace/__test__.jsonc | 4 ++++ .../specs/publish/npm_workspace/add/index.ts | 3 +++ .../specs/publish/npm_workspace/add/jsr.json | 5 +++++ .../publish/npm_workspace/add/package.json | 4 ++++ .../specs/publish/npm_workspace/package.json | 3 +++ tests/specs/publish/npm_workspace/publish.out | 15 +++++++++++++ .../publish/npm_workspace/subtract/index.ts | 3 +++ .../publish/npm_workspace/subtract/jsr.json | 5 +++++ .../npm_workspace/subtract/package.json | 4 ++++ 13 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 tests/specs/publish/npm_workspace/__test__.jsonc create mode 100644 tests/specs/publish/npm_workspace/add/index.ts create mode 100644 tests/specs/publish/npm_workspace/add/jsr.json create mode 100644 tests/specs/publish/npm_workspace/add/package.json create mode 100644 tests/specs/publish/npm_workspace/package.json create mode 100644 tests/specs/publish/npm_workspace/publish.out create mode 100644 tests/specs/publish/npm_workspace/subtract/index.ts create mode 100644 tests/specs/publish/npm_workspace/subtract/jsr.json create mode 100644 tests/specs/publish/npm_workspace/subtract/package.json diff --git a/Cargo.lock b/Cargo.lock index 30470c81f3..d8b881b37c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1308,9 +1308,9 @@ dependencies = [ [[package]] name = "deno_config" -version = "0.20.4" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96119386ea33783e2a35a3f0c5a960f88edda53f34df9594c9bb8017dcae2367" +checksum = "47d457bbaff2200897ab1f635863c477f10524412a1f568535ea26763b96d5c9" dependencies = [ "anyhow", "deno_semver", diff --git a/Cargo.toml b/Cargo.toml index 13e19979f4..1117d3a6bd 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.20.4", default-features = false } +deno_config = { version = "=0.21.0", 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/mod.rs b/cli/args/mod.rs index 6a8eaa2680..60cc97e2d8 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1297,15 +1297,18 @@ impl CliOptions { pub fn to_compiler_option_types( &self, ) -> Result, AnyError> { - self.workspace.to_maybe_imports().map(|maybe_imports| { - maybe_imports - .into_iter() - .map(|(referrer, imports)| deno_graph::ReferrerImports { - referrer, - imports, - }) - .collect() - }) + self + .workspace + .to_compiler_option_types() + .map(|maybe_imports| { + maybe_imports + .into_iter() + .map(|(referrer, imports)| deno_graph::ReferrerImports { + referrer, + imports, + }) + .collect() + }) } pub fn npmrc(&self) -> &Arc { diff --git a/cli/lsp/resolver.rs b/cli/lsp/resolver.rs index d6414697b0..f160622abc 100644 --- a/cli/lsp/resolver.rs +++ b/cli/lsp/resolver.rs @@ -115,7 +115,7 @@ impl LspScopeResolver { let npm_graph_resolver = graph_resolver.create_graph_npm_resolver(); let graph_imports = config_data .and_then(|d| d.config_file.as_ref()) - .and_then(|cf| cf.to_maybe_imports().ok()) + .and_then(|cf| cf.to_compiler_option_types().ok()) .map(|imports| { Arc::new( imports diff --git a/tests/specs/publish/npm_workspace/__test__.jsonc b/tests/specs/publish/npm_workspace/__test__.jsonc new file mode 100644 index 0000000000..27e899aaa7 --- /dev/null +++ b/tests/specs/publish/npm_workspace/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "publish --dry-run", + "output": "publish.out" +} diff --git a/tests/specs/publish/npm_workspace/add/index.ts b/tests/specs/publish/npm_workspace/add/index.ts new file mode 100644 index 0000000000..8d9b8a22a1 --- /dev/null +++ b/tests/specs/publish/npm_workspace/add/index.ts @@ -0,0 +1,3 @@ +export function add(a: number, b: number): number { + return a + b; +} diff --git a/tests/specs/publish/npm_workspace/add/jsr.json b/tests/specs/publish/npm_workspace/add/jsr.json new file mode 100644 index 0000000000..2f20d67946 --- /dev/null +++ b/tests/specs/publish/npm_workspace/add/jsr.json @@ -0,0 +1,5 @@ +{ + "name": "@scope/add", + "version": "1.0.0", + "exports": "./index.ts" +} diff --git a/tests/specs/publish/npm_workspace/add/package.json b/tests/specs/publish/npm_workspace/add/package.json new file mode 100644 index 0000000000..af9d7b7525 --- /dev/null +++ b/tests/specs/publish/npm_workspace/add/package.json @@ -0,0 +1,4 @@ +{ + "name": "add", + "version": "1.0.0" +} diff --git a/tests/specs/publish/npm_workspace/package.json b/tests/specs/publish/npm_workspace/package.json new file mode 100644 index 0000000000..a5d8565f4e --- /dev/null +++ b/tests/specs/publish/npm_workspace/package.json @@ -0,0 +1,3 @@ +{ + "workspaces": ["./add", "./subtract"] +} diff --git a/tests/specs/publish/npm_workspace/publish.out b/tests/specs/publish/npm_workspace/publish.out new file mode 100644 index 0000000000..21c91ae191 --- /dev/null +++ b/tests/specs/publish/npm_workspace/publish.out @@ -0,0 +1,15 @@ +Publishing a workspace... +Check file:///[WILDLINE]/npm_workspace/add/index.ts +Check file:///[WILDLINE]/npm_workspace/subtract/index.ts +Checking for slow types in the public API... +Check file:///[WILDLINE]/npm_workspace/add/index.ts +Check file:///[WILDLINE]/npm_workspace/subtract/index.ts +Simulating publish of @scope/add@1.0.0 with files: + file:///[WILDLINE]/npm_workspace/add/index.ts ([WILDLINE]) + file:///[WILDLINE]/npm_workspace/add/jsr.json ([WILDLINE]) + file:///[WILDLINE]/npm_workspace/add/package.json ([WILDLINE]) +Simulating publish of @scope/subtract@1.0.0 with files: + file:///[WILDLINE]/npm_workspace/subtract/index.ts ([WILDLINE]) + file:///[WILDLINE]/npm_workspace/subtract/jsr.json ([WILDLINE]) + file:///[WILDLINE]/npm_workspace/subtract/package.json ([WILDLINE]) +Warning Aborting due to --dry-run diff --git a/tests/specs/publish/npm_workspace/subtract/index.ts b/tests/specs/publish/npm_workspace/subtract/index.ts new file mode 100644 index 0000000000..b5bd2dfcf4 --- /dev/null +++ b/tests/specs/publish/npm_workspace/subtract/index.ts @@ -0,0 +1,3 @@ +export function subtract(a: number, b: number): number { + return a - b; +} diff --git a/tests/specs/publish/npm_workspace/subtract/jsr.json b/tests/specs/publish/npm_workspace/subtract/jsr.json new file mode 100644 index 0000000000..cb003e3740 --- /dev/null +++ b/tests/specs/publish/npm_workspace/subtract/jsr.json @@ -0,0 +1,5 @@ +{ + "name": "@scope/subtract", + "version": "1.0.0", + "exports": "./index.ts" +} diff --git a/tests/specs/publish/npm_workspace/subtract/package.json b/tests/specs/publish/npm_workspace/subtract/package.json new file mode 100644 index 0000000000..64507c3c7e --- /dev/null +++ b/tests/specs/publish/npm_workspace/subtract/package.json @@ -0,0 +1,4 @@ +{ + "name": "subtract", + "version": "1.0.0" +}