Skip to content
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
24 changes: 23 additions & 1 deletion cli/tools/publish/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ pub enum PublishDiagnostic {
text_info: SourceTextInfo,
range: SourceRange,
},
UnstableRawImport {
text_info: SourceTextInfo,
referrer: deno_graph::Range,
},
SyntaxError(ParseDiagnostic),
MissingLicense {
config_specifier: Url,
Expand Down Expand Up @@ -176,6 +180,7 @@ impl Diagnostic for PublishDiagnostic {
BannedTripleSlashDirectives { .. } => DiagnosticLevel::Error,
SyntaxError { .. } => DiagnosticLevel::Error,
MissingLicense { .. } => DiagnosticLevel::Error,
UnstableRawImport { .. } => DiagnosticLevel::Error,
}
}

Expand All @@ -195,6 +200,7 @@ impl Diagnostic for PublishDiagnostic {
}
SyntaxError { .. } => Cow::Borrowed("syntax-error"),
MissingLicense { .. } => Cow::Borrowed("missing-license"),
UnstableRawImport { .. } => Cow::Borrowed("unstable-raw-import"),
}
}

Expand All @@ -216,6 +222,7 @@ impl Diagnostic for PublishDiagnostic {
BannedTripleSlashDirectives { .. } => Cow::Borrowed("triple slash directives that modify globals are not allowed"),
SyntaxError(diagnostic) => diagnostic.message(),
MissingLicense { .. } => Cow::Borrowed("missing license field or file"),
UnstableRawImport { .. } => Cow::Borrowed("raw imports have not been stabilized"),
}
}

Expand Down Expand Up @@ -251,6 +258,10 @@ impl Diagnostic for PublishDiagnostic {
referrer,
text_info,
..
}
| UnstableRawImport {
referrer,
text_info,
} => from_referrer_range(referrer, text_info),
ExcludedModule { specifier } => DiagnosticLocation::Module {
specifier: Cow::Borrowed(specifier),
Expand Down Expand Up @@ -315,6 +326,11 @@ impl Diagnostic for PublishDiagnostic {
referrer,
text_info,
..
}
| UnstableRawImport {
referrer,
text_info,
..
} => from_range(text_info, referrer),
ExcludedModule { .. } => None,
MissingConstraint {
Expand Down Expand Up @@ -372,6 +388,7 @@ impl Diagnostic for PublishDiagnostic {
MissingLicense { .. } => Some(
Cow::Borrowed("add a \"license\" field. Alternatively, add a LICENSE file to the package and ensure it is not ignored from being published"),
),
UnstableRawImport { .. } => Some(Cow::Borrowed("for the time being, embed the data directly into a JavaScript file (ex. as encoded base64 text)"))
}
}

Expand Down Expand Up @@ -408,7 +425,8 @@ impl Diagnostic for PublishDiagnostic {
| ExcludedModule { .. }
| MissingConstraint { .. }
| BannedTripleSlashDirectives { .. }
| MissingLicense { .. } => None,
| MissingLicense { .. }
| UnstableRawImport { .. } => None,
}
}

Expand Down Expand Up @@ -448,6 +466,7 @@ impl Diagnostic for PublishDiagnostic {
]),
SyntaxError(diagnostic) => diagnostic.info(),
MissingLicense { .. } => Cow::Borrowed(&[]),
UnstableRawImport { .. } => Cow::Borrowed(&[]),
}
}

Expand Down Expand Up @@ -481,6 +500,9 @@ impl Diagnostic for PublishDiagnostic {
MissingLicense { .. } => {
Some(Cow::Borrowed("https://jsr.io/go/missing-license"))
}
UnstableRawImport { .. } => Some(Cow::Borrowed(
"https://github.com/denoland/deno/issues/29904",
)),
}
}
}
9 changes: 9 additions & 0 deletions cli/tools/publish/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ impl GraphDiagnosticsCollector {
);

for (specifier_text, dep) in &module.dependencies {
for asset_import in
dep.imports.iter().filter(|i| i.attributes.has_asset())
{
diagnostics_collector.push(PublishDiagnostic::UnstableRawImport {
text_info: parsed_source.text_info_lazy().clone(),
referrer: asset_import.specifier_range.clone(),
});
}

if let Some(resolved) = dep.maybe_code.ok() {
collect_if_invalid(
&mut skip_specifiers,
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/publish/raw_imports/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "publish --dry-run",
"output": "publish.out",
"exitCode": 1
}
1 change: 1 addition & 0 deletions tests/specs/publish/raw_imports/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data
7 changes: 7 additions & 0 deletions tests/specs/publish/raw_imports/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@denotest/raw-imports",
"version": "0.0.0",
"exports": "./main.ts",
"license": "MIT",
"unstable": ["raw-imports"]
}
3 changes: 3 additions & 0 deletions tests/specs/publish/raw_imports/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import data from "./data.txt" with { type: "text" };

export { data };
13 changes: 13 additions & 0 deletions tests/specs/publish/raw_imports/publish.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Check file:///[WILDLINE]/main.ts
Checking for slow types in the public API...
error[unstable-raw-import]: raw imports have not been stabilized
--> [WILDLINE]main.ts:1:18
|
1 | import data from "./data.txt" with { type: "text" };
| ^^^^^^^^^^^^ the specifier
|
= hint: for the time being, embed the data directly into a JavaScript file (ex. as encoded base64 text)

docs: https://github.com/denoland/deno/issues/29904

error: Found 1 problem
Loading