From 39a21fd78eb6d9a13d46d108af35c58a3f550332 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 12 Aug 2024 19:51:58 -0400 Subject: [PATCH] feat(publish): error on missing license file (#25011) Closes https://github.com/denoland/deno/issues/24676 --- cli/tools/registry/diagnostics.rs | 3 +-- tests/integration/publish_tests.rs | 17 +++++++++++++++-- .../publish/missing_license/__test__.jsonc | 3 ++- tests/specs/publish/missing_license/mod.out | 6 ++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs index 54b2811941..e1c6e4e655 100644 --- a/cli/tools/registry/diagnostics.rs +++ b/cli/tools/registry/diagnostics.rs @@ -172,8 +172,7 @@ impl Diagnostic for PublishDiagnostic { MissingConstraint { .. } => DiagnosticLevel::Error, BannedTripleSlashDirectives { .. } => DiagnosticLevel::Error, SyntaxError { .. } => DiagnosticLevel::Error, - // todo(#24676): make this an error in Deno 1.46 - MissingLicense { .. } => DiagnosticLevel::Warning, + MissingLicense { .. } => DiagnosticLevel::Error, } } diff --git a/tests/integration/publish_tests.rs b/tests/integration/publish_tests.rs index 013bf39732..b97479e78e 100644 --- a/tests/integration/publish_tests.rs +++ b/tests/integration/publish_tests.rs @@ -22,6 +22,7 @@ fn publish_non_exported_files_using_import_map() { "@denotest/add": "jsr:@denotest/add@1" } })); + temp_dir.join("LICENSE").write(""); // file not in the graph let other_ts = temp_dir.join("_other.ts"); other_ts @@ -52,6 +53,7 @@ fn publish_warning_not_in_graph() { "version": "1.0.0", "exports": "./mod.ts", })); + temp_dir.join("LICENSE").write(""); // file not in the graph that uses a non-analyzable dynamic import (cause a diagnostic) let other_ts = temp_dir.join("_other.ts"); other_ts @@ -92,6 +94,7 @@ fn ignores_gitignore() { "version": "1.0.0", "exports": "./main.ts" })); + temp_dir.join("LICENSE").write(""); temp_dir.join("main.ts").write("import './sub_dir/b.ts';"); @@ -151,6 +154,7 @@ fn ignores_directories() { sub_dir.join("sub_included.ts").write(""); temp_dir.join("main_included.ts").write(""); + temp_dir.join("LICENSE").write(""); let output = context .new_command() @@ -185,6 +189,7 @@ fn not_include_gitignored_file_unless_exact_match_in_include() { ] } })); + temp_dir.join("LICENSE").write(""); temp_dir .join(".gitignore") @@ -217,7 +222,7 @@ fn not_include_gitignored_file_unless_exact_match_in_include() { } #[test] -fn gitignore_everything_exlcuded_override() { +fn gitignore_everything_excluded_override() { let context = publish_context_builder().build(); let temp_dir = context.temp_dir().path(); @@ -232,6 +237,7 @@ fn gitignore_everything_exlcuded_override() { "exclude": ["!**"] } })); + temp_dir.join("LICENSE").write(""); temp_dir.join("root_main.ts").write(""); let sub_dir = temp_dir.join("sub"); @@ -257,6 +263,7 @@ fn includes_directories_with_gitignore_when_unexcluded() { "exclude": [ "!ignored.ts" ] } })); + temp_dir.join("LICENSE").write(""); temp_dir.join(".gitignore").write("ignored.ts"); temp_dir.join("main.ts").write(""); @@ -284,6 +291,7 @@ fn includes_unexcluded_sub_dir() { ] } })); + temp_dir.join("LICENSE").write(""); temp_dir.join("included1.ts").write(""); temp_dir.join("ignored/unexcluded").create_dir_all(); @@ -310,6 +318,7 @@ fn includes_directories() { "include": [ "deno.json", "main.ts" ] } })); + temp_dir.join("LICENSE").write(""); temp_dir.join("main.ts").write(""); temp_dir.join("ignored.ts").write(""); @@ -335,6 +344,7 @@ fn not_includes_gitignored_dotenv() { "version": "1.0.0", "exports": "./main.ts", })); + temp_dir.join("LICENSE").write(""); temp_dir.join("main.ts").write(""); temp_dir.join(".env").write("FOO=BAR"); @@ -356,6 +366,7 @@ fn not_includes_vendor_dir_only_when_vendor_true() { "version": "1.0.0", "exports": "./main.ts", })); + temp_dir.join("LICENSE").write(""); temp_dir.join("main.ts").write(""); let vendor_folder = temp_dir.join("vendor"); @@ -396,9 +407,9 @@ fn allow_dirty() { "version": "1.0.0", "exports": "./main.ts", })); + temp_dir.join("LICENSE").write(""); temp_dir.join("main.ts").write(""); - temp_dir.join("LICENSE").write(""); let cmd = Command::new("git") .arg("init") @@ -447,6 +458,7 @@ fn allow_dirty_not_in_repo() { "version": "1.0.0", "exports": "./main.ts", })); + temp_dir.join("LICENSE").write(""); temp_dir.join("main.ts").write(""); // At this point there are untracked files, but we're not in Git repo, @@ -472,6 +484,7 @@ fn allow_dirty_dry_run() { "version": "1.0.0", "exports": "./main.ts", })); + temp_dir.join("LICENSE").write(""); temp_dir.join("main.ts").write(""); diff --git a/tests/specs/publish/missing_license/__test__.jsonc b/tests/specs/publish/missing_license/__test__.jsonc index 774d5a534e..1b96278a08 100644 --- a/tests/specs/publish/missing_license/__test__.jsonc +++ b/tests/specs/publish/missing_license/__test__.jsonc @@ -1,4 +1,5 @@ { "args": "publish --token 'sadfasdf'", - "output": "mod.out" + "output": "mod.out", + "exitCode": 1 } diff --git a/tests/specs/publish/missing_license/mod.out b/tests/specs/publish/missing_license/mod.out index 721fefd9c6..d3e183662a 100644 --- a/tests/specs/publish/missing_license/mod.out +++ b/tests/specs/publish/missing_license/mod.out @@ -1,12 +1,10 @@ Check file:///[WILDLINE]/missing_license/mod.ts Checking for slow types in the public API... Check file:///[WILDLINE]/missing_license/mod.ts -warning[missing-license]: missing license file +error[missing-license]: missing license file --> [WILDLINE]LICENSE = hint: add a LICENSE file to the package and ensure it is not ignored from being published docs: https://jsr.io/go/missing-license -Publishing @scope/pkg@1.0.0 ... -Successfully published @scope/pkg@1.0.0 -Visit http://127.0.0.1:4250/@scope/pkg@1.0.0 for details +error: Found 1 problem