mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
fix(publish): print a warning when .jsx or .tsx is imported (#22631)
This commit adds a warning when .jsx or .tsx is encountered during publishing. This is a stop-gap solution before we fix it proper.
This commit is contained in:
parent
1dad7bec17
commit
211b3ff244
14 changed files with 115 additions and 2 deletions
|
@ -14,6 +14,8 @@ use deno_ast::diagnostics::DiagnosticSnippetHighlightStyle;
|
||||||
use deno_ast::diagnostics::DiagnosticSourcePos;
|
use deno_ast::diagnostics::DiagnosticSourcePos;
|
||||||
use deno_ast::diagnostics::DiagnosticSourceRange;
|
use deno_ast::diagnostics::DiagnosticSourceRange;
|
||||||
use deno_ast::swc::common::util::take::Take;
|
use deno_ast::swc::common::util::take::Take;
|
||||||
|
use deno_ast::SourcePos;
|
||||||
|
use deno_ast::SourceRanged;
|
||||||
use deno_ast::SourceTextInfo;
|
use deno_ast::SourceTextInfo;
|
||||||
use deno_core::anyhow::anyhow;
|
use deno_core::anyhow::anyhow;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
|
@ -31,7 +33,10 @@ impl PublishDiagnosticsCollector {
|
||||||
pub fn print_and_error(&self) -> Result<(), AnyError> {
|
pub fn print_and_error(&self) -> Result<(), AnyError> {
|
||||||
let mut errors = 0;
|
let mut errors = 0;
|
||||||
let mut has_slow_types_errors = false;
|
let mut has_slow_types_errors = false;
|
||||||
let diagnostics = self.diagnostics.lock().unwrap().take();
|
let mut diagnostics = self.diagnostics.lock().unwrap().take();
|
||||||
|
|
||||||
|
diagnostics.sort_by_cached_key(|d| d.sorting_key());
|
||||||
|
|
||||||
for diagnostic in diagnostics {
|
for diagnostic in diagnostics {
|
||||||
eprint!("{}", diagnostic.display());
|
eprint!("{}", diagnostic.display());
|
||||||
if matches!(diagnostic.level(), DiagnosticLevel::Error) {
|
if matches!(diagnostic.level(), DiagnosticLevel::Error) {
|
||||||
|
@ -92,6 +97,38 @@ pub enum PublishDiagnostic {
|
||||||
text_info: SourceTextInfo,
|
text_info: SourceTextInfo,
|
||||||
referrer: deno_graph::Range,
|
referrer: deno_graph::Range,
|
||||||
},
|
},
|
||||||
|
UnsupportedJsxTsx {
|
||||||
|
specifier: Url,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PublishDiagnostic {
|
||||||
|
fn sorting_key(&self) -> (String, String, Option<SourcePos>) {
|
||||||
|
let loc = self.location();
|
||||||
|
|
||||||
|
let (specifier, source_pos) = match loc {
|
||||||
|
DiagnosticLocation::Module { specifier } => (specifier.to_string(), None),
|
||||||
|
DiagnosticLocation::Path { path } => (path.display().to_string(), None),
|
||||||
|
DiagnosticLocation::ModulePosition {
|
||||||
|
specifier,
|
||||||
|
source_pos,
|
||||||
|
text_info,
|
||||||
|
} => (
|
||||||
|
specifier.to_string(),
|
||||||
|
Some(match source_pos {
|
||||||
|
DiagnosticSourcePos::SourcePos(s) => s,
|
||||||
|
DiagnosticSourcePos::ByteIndex(index) => {
|
||||||
|
text_info.range().start() + index
|
||||||
|
}
|
||||||
|
DiagnosticSourcePos::LineAndCol { line, column } => {
|
||||||
|
text_info.line_start(line) + column
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
(self.code().to_string(), specifier, source_pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic for PublishDiagnostic {
|
impl Diagnostic for PublishDiagnostic {
|
||||||
|
@ -107,6 +144,7 @@ impl Diagnostic for PublishDiagnostic {
|
||||||
DuplicatePath { .. } => DiagnosticLevel::Error,
|
DuplicatePath { .. } => DiagnosticLevel::Error,
|
||||||
UnsupportedFileType { .. } => DiagnosticLevel::Warning,
|
UnsupportedFileType { .. } => DiagnosticLevel::Warning,
|
||||||
InvalidExternalImport { .. } => DiagnosticLevel::Error,
|
InvalidExternalImport { .. } => DiagnosticLevel::Error,
|
||||||
|
UnsupportedJsxTsx { .. } => DiagnosticLevel::Warning,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +157,7 @@ impl Diagnostic for PublishDiagnostic {
|
||||||
DuplicatePath { .. } => Cow::Borrowed("case-insensitive-duplicate-path"),
|
DuplicatePath { .. } => Cow::Borrowed("case-insensitive-duplicate-path"),
|
||||||
UnsupportedFileType { .. } => Cow::Borrowed("unsupported-file-type"),
|
UnsupportedFileType { .. } => Cow::Borrowed("unsupported-file-type"),
|
||||||
InvalidExternalImport { .. } => Cow::Borrowed("invalid-external-import"),
|
InvalidExternalImport { .. } => Cow::Borrowed("invalid-external-import"),
|
||||||
|
UnsupportedJsxTsx { .. } => Cow::Borrowed("unsupported-jsx-tsx"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +174,7 @@ impl Diagnostic for PublishDiagnostic {
|
||||||
Cow::Owned(format!("unsupported file type '{kind}'"))
|
Cow::Owned(format!("unsupported file type '{kind}'"))
|
||||||
}
|
}
|
||||||
InvalidExternalImport { kind, .. } => Cow::Owned(format!("invalid import to a {kind} specifier")),
|
InvalidExternalImport { kind, .. } => Cow::Owned(format!("invalid import to a {kind} specifier")),
|
||||||
|
UnsupportedJsxTsx { .. } => Cow::Borrowed("JSX and TSX files are currently not supported"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +214,9 @@ impl Diagnostic for PublishDiagnostic {
|
||||||
column: referrer.start.character,
|
column: referrer.start.character,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
UnsupportedJsxTsx { specifier } => DiagnosticLocation::Module {
|
||||||
|
specifier: Cow::Borrowed(specifier),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +264,7 @@ impl Diagnostic for PublishDiagnostic {
|
||||||
description: Some("the specifier".into()),
|
description: Some("the specifier".into()),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
PublishDiagnostic::UnsupportedJsxTsx { .. } => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +281,8 @@ impl Diagnostic for PublishDiagnostic {
|
||||||
PublishDiagnostic::UnsupportedFileType { .. } => Some(
|
PublishDiagnostic::UnsupportedFileType { .. } => Some(
|
||||||
Cow::Borrowed("remove the file, or add it to 'publish.exclude' in the config file"),
|
Cow::Borrowed("remove the file, or add it to 'publish.exclude' in the config file"),
|
||||||
),
|
),
|
||||||
PublishDiagnostic::InvalidExternalImport { .. } => Some(Cow::Borrowed("replace this import with one from jsr or npm, or vendor the dependency into your package"))
|
PublishDiagnostic::InvalidExternalImport { .. } => Some(Cow::Borrowed("replace this import with one from jsr or npm, or vendor the dependency into your package")),
|
||||||
|
PublishDiagnostic::UnsupportedJsxTsx { .. } => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,6 +317,9 @@ impl Diagnostic for PublishDiagnostic {
|
||||||
Cow::Borrowed("this specifier is not allowed to be imported on jsr"),
|
Cow::Borrowed("this specifier is not allowed to be imported on jsr"),
|
||||||
Cow::Borrowed("jsr only supports importing `jsr:`, `npm:`, and `data:` specifiers"),
|
Cow::Borrowed("jsr only supports importing `jsr:`, `npm:`, and `data:` specifiers"),
|
||||||
]),
|
]),
|
||||||
|
PublishDiagnostic::UnsupportedJsxTsx { .. } => Cow::Owned(vec![
|
||||||
|
Cow::Borrowed("follow https://github.com/jsr-io/jsr/issues/24 for updates"),
|
||||||
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,6 +341,7 @@ impl Diagnostic for PublishDiagnostic {
|
||||||
PublishDiagnostic::InvalidExternalImport { .. } => {
|
PublishDiagnostic::InvalidExternalImport { .. } => {
|
||||||
Some(Cow::Borrowed("https://jsr.io/go/invalid-external-import"))
|
Some(Cow::Borrowed("https://jsr.io/go/invalid-external-import"))
|
||||||
}
|
}
|
||||||
|
PublishDiagnostic::UnsupportedJsxTsx { .. } => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,6 +154,14 @@ pub fn create_gzipped_tarball(
|
||||||
source_parser,
|
source_parser,
|
||||||
diagnostics_collector,
|
diagnostics_collector,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
let media_type = MediaType::from_specifier(&specifier);
|
||||||
|
if matches!(media_type, MediaType::Jsx | MediaType::Tsx) {
|
||||||
|
diagnostics_collector.push(PublishDiagnostic::UnsupportedJsxTsx {
|
||||||
|
specifier: specifier.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
files.push(PublishableTarballFile {
|
files.push(PublishableTarballFile {
|
||||||
path_str: path_str.clone(),
|
path_str: path_str.clone(),
|
||||||
specifier: specifier.clone(),
|
specifier: specifier.clone(),
|
||||||
|
|
|
@ -257,6 +257,14 @@ itest!(jsr_jsonc {
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(unsupported_jsx_tsx {
|
||||||
|
args: "publish --token 'sadfasdf'",
|
||||||
|
cwd: Some("publish/unsupported_jsx_tsx"),
|
||||||
|
output: "publish/unsupported_jsx_tsx/mod.out",
|
||||||
|
envs: env_vars_for_jsr_npm_tests(),
|
||||||
|
http_server: true,
|
||||||
|
});
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ignores_gitignore() {
|
fn ignores_gitignore() {
|
||||||
let context = publish_context_builder().build();
|
let context = publish_context_builder().build();
|
||||||
|
|
BIN
tests/testdata/npm/registry/preact-render-to-string/preact-render-to-string-6.4.0.tgz
vendored
Normal file
BIN
tests/testdata/npm/registry/preact-render-to-string/preact-render-to-string-6.4.0.tgz
vendored
Normal file
Binary file not shown.
1
tests/testdata/npm/registry/preact-render-to-string/registry.json
vendored
Normal file
1
tests/testdata/npm/registry/preact-render-to-string/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
tests/testdata/npm/registry/preact/preact-10.19.6.tgz
vendored
Normal file
BIN
tests/testdata/npm/registry/preact/preact-10.19.6.tgz
vendored
Normal file
Binary file not shown.
1
tests/testdata/npm/registry/preact/registry.json
vendored
Normal file
1
tests/testdata/npm/registry/preact/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
tests/testdata/npm/registry/pretty-format/pretty-format-3.8.0.tgz
vendored
Normal file
BIN
tests/testdata/npm/registry/pretty-format/pretty-format-3.8.0.tgz
vendored
Normal file
Binary file not shown.
1
tests/testdata/npm/registry/pretty-format/registry.json
vendored
Normal file
1
tests/testdata/npm/registry/pretty-format/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
5
tests/testdata/publish/unsupported_jsx_tsx/foo.jsx
vendored
Normal file
5
tests/testdata/publish/unsupported_jsx_tsx/foo.jsx
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { renderToString } from "npm:preact-render-to-string";
|
||||||
|
|
||||||
|
export default function render() {
|
||||||
|
return renderToString(<div>foo.tsx</div>);
|
||||||
|
}
|
5
tests/testdata/publish/unsupported_jsx_tsx/foo.tsx
vendored
Normal file
5
tests/testdata/publish/unsupported_jsx_tsx/foo.tsx
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { renderToString } from "npm:preact-render-to-string";
|
||||||
|
|
||||||
|
export default function render() {
|
||||||
|
return renderToString(<div>foo.tsx</div>);
|
||||||
|
}
|
11
tests/testdata/publish/unsupported_jsx_tsx/jsr.jsonc
vendored
Normal file
11
tests/testdata/publish/unsupported_jsx_tsx/jsr.jsonc
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "@foo/bar",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"exports": {
|
||||||
|
".": "./mod.ts"
|
||||||
|
},
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "npm:preact"
|
||||||
|
}
|
||||||
|
}
|
17
tests/testdata/publish/unsupported_jsx_tsx/mod.out
vendored
Normal file
17
tests/testdata/publish/unsupported_jsx_tsx/mod.out
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
[WILDCARD]
|
||||||
|
Check file:///[WILDCARD]/publish/unsupported_jsx_tsx/mod.ts
|
||||||
|
Checking for slow types in the public API...
|
||||||
|
Check file:///[WILDCARD]/publish/unsupported_jsx_tsx/mod.ts
|
||||||
|
warning[unsupported-jsx-tsx]: JSX and TSX files are currently not supported
|
||||||
|
--> [WILDCARD]foo.jsx
|
||||||
|
|
||||||
|
info: follow https://github.com/jsr-io/jsr/issues/24 for updates
|
||||||
|
|
||||||
|
warning[unsupported-jsx-tsx]: JSX and TSX files are currently not supported
|
||||||
|
--> [WILDCARD]foo.tsx
|
||||||
|
|
||||||
|
info: follow https://github.com/jsr-io/jsr/issues/24 for updates
|
||||||
|
|
||||||
|
Publishing @foo/bar@1.0.0 ...
|
||||||
|
Successfully published @foo/bar@1.0.0
|
||||||
|
Visit http://127.0.0.1:4250/@foo/bar@1.0.0 for details
|
7
tests/testdata/publish/unsupported_jsx_tsx/mod.ts
vendored
Normal file
7
tests/testdata/publish/unsupported_jsx_tsx/mod.ts
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import fooTsx from "./foo.tsx";
|
||||||
|
import fooJsx from "./foo.jsx";
|
||||||
|
|
||||||
|
export function renderTsxJsx() {
|
||||||
|
console.log(fooTsx());
|
||||||
|
console.log(fooJsx());
|
||||||
|
}
|
Loading…
Reference in a new issue