Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(publish): surface syntax errors when using --no-check #24620

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"tests/registry/",
"tests/specs/fmt",
"tests/specs/lint/bom",
"tests/specs/publish/no_check_surfaces_syntax_error",
"tests/testdata/byte_order_mark.ts",
"tests/testdata/encoding",
"tests/testdata/file_extensions/ts_with_js_extension.js",
Expand Down
21 changes: 20 additions & 1 deletion cli/tools/registry/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use deno_ast::diagnostics::DiagnosticSnippetHighlightStyle;
use deno_ast::diagnostics::DiagnosticSourcePos;
use deno_ast::diagnostics::DiagnosticSourceRange;
use deno_ast::swc::common::util::take::Take;
use deno_ast::ParseDiagnostic;
use deno_ast::SourcePos;
use deno_ast::SourceRange;
use deno_ast::SourceRanged;
Expand Down Expand Up @@ -117,6 +118,7 @@ pub enum PublishDiagnostic {
text_info: SourceTextInfo,
range: SourceRange,
},
SyntaxError(ParseDiagnostic),
}

impl PublishDiagnostic {
Expand Down Expand Up @@ -165,6 +167,7 @@ impl Diagnostic for PublishDiagnostic {
ExcludedModule { .. } => DiagnosticLevel::Error,
MissingConstraint { .. } => DiagnosticLevel::Error,
BannedTripleSlashDirectives { .. } => DiagnosticLevel::Error,
SyntaxError { .. } => DiagnosticLevel::Error,
}
}

Expand All @@ -183,6 +186,7 @@ impl Diagnostic for PublishDiagnostic {
BannedTripleSlashDirectives { .. } => {
Cow::Borrowed("banned-triple-slash-directives")
}
SyntaxError { .. } => Cow::Borrowed("syntax-error"),
}
}

Expand All @@ -203,6 +207,7 @@ impl Diagnostic for PublishDiagnostic {
ExcludedModule { .. } => Cow::Borrowed("module in package's module graph was excluded from publishing"),
MissingConstraint { specifier, .. } => Cow::Owned(format!("specifier '{}' is missing a version constraint", specifier)),
BannedTripleSlashDirectives { .. } => Cow::Borrowed("triple slash directives that modify globals are not allowed"),
SyntaxError(diagnostic) => diagnostic.message(),
}
}

Expand Down Expand Up @@ -269,6 +274,7 @@ impl Diagnostic for PublishDiagnostic {
source_pos: DiagnosticSourcePos::SourcePos(range.start),
text_info: Cow::Borrowed(text_info),
},
SyntaxError(diagnostic) => diagnostic.location(),
}
}

Expand Down Expand Up @@ -348,6 +354,7 @@ impl Diagnostic for PublishDiagnostic {
description: Some("the triple slash directive".into()),
}],
}),
SyntaxError(diagnostic) => diagnostic.snippet(),
}
}

Expand Down Expand Up @@ -380,6 +387,7 @@ impl Diagnostic for PublishDiagnostic {
BannedTripleSlashDirectives { .. } => Some(
Cow::Borrowed("remove the triple slash directive"),
),
SyntaxError(diagnostic) => diagnostic.hint(),
}
}

Expand Down Expand Up @@ -407,7 +415,16 @@ impl Diagnostic for PublishDiagnostic {
None => None,
}
}
_ => None,
SyntaxError(diagnostic) => diagnostic.snippet_fixed(),
FastCheck(_)
| SpecifierUnfurl(_)
| InvalidPath { .. }
| DuplicatePath { .. }
| UnsupportedFileType { .. }
| UnsupportedJsxTsx { .. }
| ExcludedModule { .. }
| MissingConstraint { .. }
| BannedTripleSlashDirectives { .. } => None,
}
}

Expand Down Expand Up @@ -456,6 +473,7 @@ impl Diagnostic for PublishDiagnostic {
Cow::Borrowed("instead instruct the user of your package to specify these directives"),
Cow::Borrowed("or set their 'lib' compiler option appropriately"),
]),
SyntaxError(diagnostic) => diagnostic.info(),
}
}

Expand Down Expand Up @@ -488,6 +506,7 @@ impl Diagnostic for PublishDiagnostic {
BannedTripleSlashDirectives { .. } => Some(Cow::Borrowed(
"https://jsr.io/go/banned-triple-slash-directives",
)),
SyntaxError(diagnostic) => diagnostic.docs_url(),
}
}
}
7 changes: 7 additions & 0 deletions cli/tools/registry/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ impl GraphDiagnosticsCollector {
let parsed_source = self
.parsed_source_cache
.get_parsed_source_from_js_module(module)?;

// surface syntax errors
for diagnostic in parsed_source.diagnostics() {
diagnostics_collector
.push(PublishDiagnostic::SyntaxError(diagnostic.clone()));
}

check_for_banned_triple_slash_directives(
&parsed_source,
diagnostics_collector,
Expand Down
2 changes: 2 additions & 0 deletions tests/specs/npm/lifecycle_scripts/no_deno_json.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Download http://localhost:4260/@denotest/lifecycle-scripts-cjs
Download http://localhost:4260/@denotest/bin
[UNORDERED_START]
Download http://localhost:4260/@denotest/lifecycle-scripts-cjs/1.0.0.tgz
Download http://localhost:4260/@denotest/bin/1.0.0.tgz
Initialize @denotest/[email protected]
Initialize @denotest/[email protected]
[UNORDERED_END]
preinstall
install
hello from install script
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "publish --dry-run --no-check",
"output": "publish.out",
"exitCode": 1
}
5 changes: 5 additions & 0 deletions tests/specs/publish/no_check_surfaces_syntax_error/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@scope/pkg",
"version": "1.0.0",
"exports": "./mod.ts"
}
1 change: 1 addition & 0 deletions tests/specs/publish/no_check_surfaces_syntax_error/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
+
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Checking for slow types in the public API...
error[syntax-error]: Expression expected
--> [WILDLINE]mod.ts:1:1
|
1 | +
| ^

error: Found 1 problem