summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-07-17 23:06:30 -0400
committerGitHub <noreply@github.com>2024-07-17 23:06:30 -0400
commitecd4f900c62d3de1f3e08c5d1f34a5e6430aa413 (patch)
tree9ca5cb90e0f935159963f7e217092f31d7c4698a
parentbf9c08b705725bf35b60fb8a468edbc35ba3cdde (diff)
fix(publish): surface syntax errors when using --no-check (#24620)
-rw-r--r--.dprint.json1
-rw-r--r--cli/tools/registry/diagnostics.rs21
-rw-r--r--cli/tools/registry/graph.rs7
-rw-r--r--tests/specs/npm/lifecycle_scripts/no_deno_json.out1
-rw-r--r--tests/specs/publish/no_check_surfaces_syntax_error/__test__.jsonc5
-rw-r--r--tests/specs/publish/no_check_surfaces_syntax_error/deno.json5
-rw-r--r--tests/specs/publish/no_check_surfaces_syntax_error/mod.ts1
-rw-r--r--tests/specs/publish/no_check_surfaces_syntax_error/publish.out8
8 files changed, 48 insertions, 1 deletions
diff --git a/.dprint.json b/.dprint.json
index 3c56d3e42..f5c6cb10a 100644
--- a/.dprint.json
+++ b/.dprint.json
@@ -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",
diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs
index 3f3e1ee96..34f08b666 100644
--- a/cli/tools/registry/diagnostics.rs
+++ b/cli/tools/registry/diagnostics.rs
@@ -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;
@@ -117,6 +118,7 @@ pub enum PublishDiagnostic {
text_info: SourceTextInfo,
range: SourceRange,
},
+ SyntaxError(ParseDiagnostic),
}
impl PublishDiagnostic {
@@ -165,6 +167,7 @@ impl Diagnostic for PublishDiagnostic {
ExcludedModule { .. } => DiagnosticLevel::Error,
MissingConstraint { .. } => DiagnosticLevel::Error,
BannedTripleSlashDirectives { .. } => DiagnosticLevel::Error,
+ SyntaxError { .. } => DiagnosticLevel::Error,
}
}
@@ -183,6 +186,7 @@ impl Diagnostic for PublishDiagnostic {
BannedTripleSlashDirectives { .. } => {
Cow::Borrowed("banned-triple-slash-directives")
}
+ SyntaxError { .. } => Cow::Borrowed("syntax-error"),
}
}
@@ -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(),
}
}
@@ -269,6 +274,7 @@ impl Diagnostic for PublishDiagnostic {
source_pos: DiagnosticSourcePos::SourcePos(range.start),
text_info: Cow::Borrowed(text_info),
},
+ SyntaxError(diagnostic) => diagnostic.location(),
}
}
@@ -348,6 +354,7 @@ impl Diagnostic for PublishDiagnostic {
description: Some("the triple slash directive".into()),
}],
}),
+ SyntaxError(diagnostic) => diagnostic.snippet(),
}
}
@@ -380,6 +387,7 @@ impl Diagnostic for PublishDiagnostic {
BannedTripleSlashDirectives { .. } => Some(
Cow::Borrowed("remove the triple slash directive"),
),
+ SyntaxError(diagnostic) => diagnostic.hint(),
}
}
@@ -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,
}
}
@@ -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(),
}
}
@@ -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(),
}
}
}
diff --git a/cli/tools/registry/graph.rs b/cli/tools/registry/graph.rs
index 73b72c1b6..bdcb27aa1 100644
--- a/cli/tools/registry/graph.rs
+++ b/cli/tools/registry/graph.rs
@@ -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,
diff --git a/tests/specs/npm/lifecycle_scripts/no_deno_json.out b/tests/specs/npm/lifecycle_scripts/no_deno_json.out
index 38a461449..aa9bc964a 100644
--- a/tests/specs/npm/lifecycle_scripts/no_deno_json.out
+++ b/tests/specs/npm/lifecycle_scripts/no_deno_json.out
@@ -1,6 +1,7 @@
[UNORDERED_START]
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/lifecycle-scripts-cjs@1.0.0
diff --git a/tests/specs/publish/no_check_surfaces_syntax_error/__test__.jsonc b/tests/specs/publish/no_check_surfaces_syntax_error/__test__.jsonc
new file mode 100644
index 000000000..028d3d16d
--- /dev/null
+++ b/tests/specs/publish/no_check_surfaces_syntax_error/__test__.jsonc
@@ -0,0 +1,5 @@
+{
+ "args": "publish --dry-run --no-check",
+ "output": "publish.out",
+ "exitCode": 1
+}
diff --git a/tests/specs/publish/no_check_surfaces_syntax_error/deno.json b/tests/specs/publish/no_check_surfaces_syntax_error/deno.json
new file mode 100644
index 000000000..fe4300ad6
--- /dev/null
+++ b/tests/specs/publish/no_check_surfaces_syntax_error/deno.json
@@ -0,0 +1,5 @@
+{
+ "name": "@scope/pkg",
+ "version": "1.0.0",
+ "exports": "./mod.ts"
+}
diff --git a/tests/specs/publish/no_check_surfaces_syntax_error/mod.ts b/tests/specs/publish/no_check_surfaces_syntax_error/mod.ts
new file mode 100644
index 000000000..fd3886163
--- /dev/null
+++ b/tests/specs/publish/no_check_surfaces_syntax_error/mod.ts
@@ -0,0 +1 @@
++
diff --git a/tests/specs/publish/no_check_surfaces_syntax_error/publish.out b/tests/specs/publish/no_check_surfaces_syntax_error/publish.out
new file mode 100644
index 000000000..57969aeb7
--- /dev/null
+++ b/tests/specs/publish/no_check_surfaces_syntax_error/publish.out
@@ -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