diff --git a/Cargo.lock b/Cargo.lock index 4c3440e8c2a9d4..14db1b8dd6a608 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1151,8 +1151,7 @@ dependencies = [ [[package]] name = "deno_config" version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec482ce578388108cfd4a7ca900be7b8aea5081e1922ff3c5f87f0767c531" +source = "git+https://github.com/denoland/deno_config?rev=133702b208996e293736c82884451f7ec5720a93#133702b208996e293736c82884451f7ec5720a93" dependencies = [ "anyhow", "glob", diff --git a/Cargo.toml b/Cargo.toml index 7486370898a240..c4dbd9834bb5b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -354,3 +354,6 @@ opt-level = 3 opt-level = 3 [profile.release.package.base64-simd] opt-level = 3 + +[patch.crates-io] +deno_config = { git = "https://github.com/denoland/deno_config", "rev" = "133702b208996e293736c82884451f7ec5720a93" } diff --git a/cli/schemas/config-file.v1.json b/cli/schemas/config-file.v1.json index 8e4bc75a4826d3..58293ce8b42330 100644 --- a/cli/schemas/config-file.v1.json +++ b/cli/schemas/config-file.v1.json @@ -487,6 +487,26 @@ } } }, + "publish": { + "description": "Configuration for deno publish", + "type": "object", + "properties": { + "include": { + "type": "array", + "description": "List of files, directories or globs that will be included in the published package.", + "items": { + "type": "string" + } + }, + "exclude": { + "type": "array", + "description": "List of files, directories or globs that will be excluded from the published package.", + "items": { + "type": "string" + } + } + } + }, "bench": { "description": "Configuration for deno bench", "type": "object", diff --git a/cli/tests/integration/publish_tests.rs b/cli/tests/integration/publish_tests.rs index e185065aa5ef4f..784bd0ed74f747 100644 --- a/cli/tests/integration/publish_tests.rs +++ b/cli/tests/integration/publish_tests.rs @@ -119,6 +119,9 @@ fn ignores_directories() { "name": "@foo/bar", "version": "1.0.0", "exclude": [ "ignore" ], + "publish": { + "exclude": [ "ignore2" ] + }, "exports": "./main_included.ts" })); @@ -126,6 +129,7 @@ fn ignores_directories() { temp_dir.join(".git"), temp_dir.join("node_modules"), temp_dir.join("ignore"), + temp_dir.join("ignore2"), ]; for ignored_dir in ignored_dirs { ignored_dir.create_dir_all(); @@ -152,6 +156,34 @@ fn ignores_directories() { assert_not_contains!(output, "ignored.ts"); } +#[test] +fn includes_directories() { + let context = publish_context_builder().build(); + let temp_dir = context.temp_dir().path(); + temp_dir.join("deno.json").write_json(&json!({ + "name": "@foo/bar", + "version": "1.0.0", + "publish": { + "include": [ "deno.json", "main.ts" ] + } + })); + + temp_dir.join("main.ts").write(""); + temp_dir.join("ignored.ts").write(""); + + let output = context + .new_command() + .arg("publish") + .arg("--log-level=debug") + .arg("--token") + .arg("sadfasdf") + .run(); + output.assert_exit_code(0); + let output = output.combined_output(); + assert_contains!(output, "main.ts"); + assert_not_contains!(output, "ignored.ts"); +} + fn publish_context_builder() -> TestContextBuilder { TestContextBuilder::new() .use_http_server() diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index 8eaf6125836a5e..f3439ffe53c432 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -130,9 +130,7 @@ async fn prepare_publish( let Some((scope, package_name)) = name.split_once('/') else { bail!("Invalid package name, use '@/ format"); }; - let exclude_patterns = deno_json - .to_files_config() - .map(|files| files.map(|f| f.exclude).unwrap_or_default())?; + let file_patterns = deno_json.to_publish_config()?.map(|c| c.files); let tarball = deno_core::unsync::spawn_blocking(move || { let unfurler = ImportMapUnfurler::new(&import_map); @@ -140,7 +138,7 @@ async fn prepare_publish( &dir_path, &*source_cache, &unfurler, - &exclude_patterns, + file_patterns, ) .context("Failed to create a tarball") }) diff --git a/cli/tools/registry/tar.rs b/cli/tools/registry/tar.rs index 0f6edbc3a084e8..3554442d6be7a5 100644 --- a/cli/tools/registry/tar.rs +++ b/cli/tools/registry/tar.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use bytes::Bytes; +use deno_config::glob::FilePatterns; use deno_core::anyhow; use deno_core::anyhow::Context; use deno_core::error::AnyError; @@ -13,7 +14,6 @@ use std::path::PathBuf; use tar::Header; use crate::util::import_map::ImportMapUnfurler; -use deno_config::glob::PathOrPatternSet; #[derive(Debug, Clone, PartialEq)] pub struct PublishableTarballFile { @@ -33,7 +33,7 @@ pub fn create_gzipped_tarball( dir: &Path, source_cache: &dyn deno_graph::ParsedSourceStore, unfurler: &ImportMapUnfurler, - exclude_patterns: &PathOrPatternSet, + file_patterns: Option, ) -> Result { let mut tar = TarGzArchive::new(); let mut diagnostics = vec![]; @@ -43,11 +43,13 @@ pub fn create_gzipped_tarball( while let Some(entry) = iterator.next() { let entry = entry?; - if exclude_patterns.matches_path(entry.path()) { - if entry.file_type().is_dir() { - iterator.skip_current_dir(); + if let Some(file_patterns) = &file_patterns { + if !file_patterns.matches_path(entry.path()) { + if entry.file_type().is_dir() { + iterator.skip_current_dir(); + } + continue; } - continue; } if entry.file_type().is_file() {