Skip to content

Commit

Permalink
feat(publish): error on missing license file (#25011)
Browse files Browse the repository at this point in the history
Closes #24676
  • Loading branch information
dsherret authored Aug 12, 2024
1 parent 631e175 commit 39a21fd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cli/tools/registry/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
17 changes: 15 additions & 2 deletions tests/integration/publish_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';");

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -185,6 +189,7 @@ fn not_include_gitignored_file_unless_exact_match_in_include() {
]
}
}));
temp_dir.join("LICENSE").write("");

temp_dir
.join(".gitignore")
Expand Down Expand Up @@ -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();

Expand All @@ -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");
Expand All @@ -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("");
Expand Down Expand Up @@ -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();
Expand 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("");
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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("");

Expand Down
3 changes: 2 additions & 1 deletion tests/specs/publish/missing_license/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"args": "publish --token 'sadfasdf'",
"output": "mod.out"
"output": "mod.out",
"exitCode": 1
}
6 changes: 2 additions & 4 deletions tests/specs/publish/missing_license/mod.out
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 39a21fd

Please # to comment.