mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
feat(publish): exclude and include (#22055)
This commit is contained in:
parent
fb24b004ba
commit
176118a046
6 changed files with 66 additions and 13 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1172,9 +1172,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_config"
|
||||
version = "0.8.2"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb5634c4d8f29f62bc4516a3dc474c1a06a6ce1388a139df08cb2020244e7de7"
|
||||
checksum = "aca0a5b9d2693efb14c8c80d66a052464f24cbf6b3473648037e282c0c616917"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"glob",
|
||||
|
|
|
@ -55,7 +55,7 @@ winres.workspace = true
|
|||
[dependencies]
|
||||
deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
|
||||
deno_cache_dir = "=0.6.1"
|
||||
deno_config = "=0.8.2"
|
||||
deno_config = "=0.9.1"
|
||||
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
||||
deno_doc = { version = "=0.94.1", features = ["html"] }
|
||||
deno_emit = "=0.34.0"
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -130,6 +130,9 @@ fn ignores_directories() {
|
|||
"name": "@foo/bar",
|
||||
"version": "1.0.0",
|
||||
"exclude": [ "ignore" ],
|
||||
"publish": {
|
||||
"exclude": [ "ignore2" ]
|
||||
},
|
||||
"exports": "./main_included.ts"
|
||||
}));
|
||||
|
||||
|
@ -137,6 +140,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();
|
||||
|
@ -163,6 +167,35 @@ 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",
|
||||
"exports": "./main.ts",
|
||||
"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()
|
||||
|
|
|
@ -131,9 +131,7 @@ async fn prepare_publish(
|
|||
let Some((scope, package_name)) = name.split_once('/') else {
|
||||
bail!("Invalid package name, use '@<scope_name>/<package_name> 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 diagnostics_collector = diagnostics_collector.clone();
|
||||
let tarball = deno_core::unsync::spawn_blocking(move || {
|
||||
|
@ -143,7 +141,7 @@ async fn prepare_publish(
|
|||
&*source_cache,
|
||||
&diagnostics_collector,
|
||||
&unfurler,
|
||||
&exclude_patterns,
|
||||
file_patterns,
|
||||
)
|
||||
.context("Failed to create a tarball")
|
||||
})
|
||||
|
|
|
@ -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;
|
||||
|
||||
use super::diagnostics::PublishDiagnostic;
|
||||
use super::diagnostics::PublishDiagnosticsCollector;
|
||||
|
@ -37,7 +37,7 @@ pub fn create_gzipped_tarball(
|
|||
source_cache: &dyn deno_graph::ParsedSourceStore,
|
||||
diagnostics_collector: &PublishDiagnosticsCollector,
|
||||
unfurler: &ImportMapUnfurler,
|
||||
exclude_patterns: &PathOrPatternSet,
|
||||
file_patterns: Option<FilePatterns>,
|
||||
) -> Result<PublishableTarball, AnyError> {
|
||||
let mut tar = TarGzArchive::new();
|
||||
let mut diagnostics = vec![];
|
||||
|
@ -47,11 +47,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() {
|
||||
|
|
Loading…
Reference in a new issue