1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

fix: support bun specifiers in JSR publish (#24588)

Fixes https://github.com/denoland/deno/issues/26989

---------

Co-authored-by: Nathan Whitaker <nathan@deno.com>
This commit is contained in:
Luca Casonato 2024-11-28 14:51:24 +01:00 committed by GitHub
parent 1af2d2474e
commit 32e260d55a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 62 additions and 18 deletions

View file

@ -6,6 +6,7 @@ use crate::args::CliLockfile;
use crate::args::CliOptions;
use crate::args::DENO_DISABLE_PEDANTIC_NODE_WARNINGS;
use crate::cache;
use crate::cache::FetchCacher;
use crate::cache::GlobalHttpCache;
use crate::cache::ModuleInfoCache;
use crate::cache::ParsedSourceCache;
@ -254,6 +255,23 @@ impl ModuleGraphCreator {
package_configs: &[JsrPackageConfig],
build_fast_check_graph: bool,
) -> Result<ModuleGraph, AnyError> {
struct PublishLoader(FetchCacher);
impl Loader for PublishLoader {
fn load(
&self,
specifier: &deno_ast::ModuleSpecifier,
options: deno_graph::source::LoadOptions,
) -> deno_graph::source::LoadFuture {
if specifier.scheme() == "bun" {
return Box::pin(std::future::ready(Ok(Some(
deno_graph::source::LoadResponse::External {
specifier: specifier.clone(),
},
))));
}
self.0.load(specifier, options)
}
}
fn graph_has_external_remote(graph: &ModuleGraph) -> bool {
// Earlier on, we marked external non-JSR modules as external.
// If the graph contains any of those, it would cause type checking
@ -271,12 +289,15 @@ impl ModuleGraphCreator {
for package_config in package_configs {
roots.extend(package_config.config_file.resolve_export_value_urls()?);
}
let loader = self.module_graph_builder.create_graph_loader();
let mut publish_loader = PublishLoader(loader);
let mut graph = self
.create_graph_with_options(CreateGraphOptions {
is_dynamic: false,
graph_kind: deno_graph::GraphKind::All,
roots,
loader: None,
loader: Some(&mut publish_loader),
})
.await?;
self.graph_valid(&graph)?;

View file

@ -476,7 +476,7 @@ impl Diagnostic for PublishDiagnostic {
InvalidExternalImport { imported, .. } => Cow::Owned(vec![
Cow::Owned(format!("the import was resolved to '{}'", imported)),
Cow::Borrowed("this specifier is not allowed to be imported on jsr"),
Cow::Borrowed("jsr only supports importing `jsr:`, `npm:`, and `data:` specifiers"),
Cow::Borrowed("jsr only supports importing `jsr:`, `npm:`, `data:`, `bun:`, and `node:` specifiers"),
]),
UnsupportedJsxTsx { .. } => Cow::Owned(vec![
Cow::Borrowed("follow https://github.com/jsr-io/jsr/issues/24 for updates"),

View file

@ -47,7 +47,7 @@ impl GraphDiagnosticsCollector {
resolution: &ResolutionResolved| {
if visited.insert(resolution.specifier.clone()) {
match resolution.specifier.scheme() {
"file" | "data" | "node" => {}
"file" | "data" | "node" | "bun" => {}
"jsr" => {
skip_specifiers.insert(resolution.specifier.clone());

View file

@ -656,17 +656,21 @@ fn op_load_inner(
}
Module::Npm(_) | Module::Node(_) => None,
Module::External(module) => {
// means it's Deno code importing an npm module
let specifier = node::resolve_specifier_into_node_modules(
&module.specifier,
&deno_fs::RealFs,
);
Some(Cow::Owned(load_from_node_modules(
&specifier,
state.maybe_npm.as_ref(),
&mut media_type,
&mut is_cjs,
)?))
if module.specifier.scheme() != "file" {
None
} else {
// means it's Deno code importing an npm module
let specifier = node::resolve_specifier_into_node_modules(
&module.specifier,
&deno_fs::RealFs,
);
Some(Cow::Owned(load_from_node_modules(
&specifier,
state.maybe_npm.as_ref(),
&mut media_type,
&mut is_cjs,
)?))
}
}
}
} else if let Some(npm) = state

View file

@ -0,0 +1,4 @@
{
"args": "publish --token 'sadfasdf'",
"output": "bun_specifier.out"
}

View file

@ -0,0 +1,6 @@
Check file:///[WILDCARD]/mod.ts
Checking for slow types in the public API...
Check file:///[WILDCARD]/mod.ts
Publishing @foo/bar@1.0.0 ...
Successfully published @foo/bar@1.0.0
Visit http://127.0.0.1:4250/@foo/bar@1.0.0 for details

View file

@ -0,0 +1,8 @@
{
"name": "@foo/bar",
"version": "1.0.0",
"exports": {
".": "./mod.ts"
},
"license": "MIT"
}

View file

@ -0,0 +1 @@
import "bun:sqlite";

View file

@ -12,7 +12,7 @@ error[invalid-external-import]: invalid import to a non-JSR 'http' specifier
info: the import was resolved to 'http://localhost:4545/welcome.ts'
info: this specifier is not allowed to be imported on jsr
info: jsr only supports importing `jsr:`, `npm:`, and `data:` specifiers
info: jsr only supports importing `jsr:`, `npm:`, `data:`, `bun:`, and `node:` specifiers
docs: https://jsr.io/go/invalid-external-import
error[invalid-external-import]: invalid import to a non-JSR 'http' specifier
@ -25,7 +25,7 @@ error[invalid-external-import]: invalid import to a non-JSR 'http' specifier
info: the import was resolved to 'http://localhost:4545/echo.ts'
info: this specifier is not allowed to be imported on jsr
info: jsr only supports importing `jsr:`, `npm:`, and `data:` specifiers
info: jsr only supports importing `jsr:`, `npm:`, `data:`, `bun:`, and `node:` specifiers
docs: https://jsr.io/go/invalid-external-import
error: Found 2 problems

View file

@ -13,7 +13,7 @@ error[invalid-external-import]: invalid import to a non-JSR 'http' specifier
info: the import was resolved to 'http://esm.sh/react-dom@18.2.0/server'
info: this specifier is not allowed to be imported on jsr
info: jsr only supports importing `jsr:`, `npm:`, and `data:` specifiers
info: jsr only supports importing `jsr:`, `npm:`, `data:`, `bun:`, and `node:` specifiers
docs: https://jsr.io/go/invalid-external-import
error: Found 1 problem

View file

@ -13,7 +13,7 @@ error[invalid-external-import]: invalid import to a non-JSR 'https' specifier
info: the import was resolved to 'https://deno.land/std/assert/assert.ts'
info: this specifier is not allowed to be imported on jsr
info: jsr only supports importing `jsr:`, `npm:`, and `data:` specifiers
info: jsr only supports importing `jsr:`, `npm:`, `data:`, `bun:`, and `node:` specifiers
docs: https://jsr.io/go/invalid-external-import
error: Found 1 problem