Skip to content

Commit 7b3429f

Browse files
authored
feat: markdown media type (#633)
1 parent 069a493 commit 7b3429f

File tree

7 files changed

+101
-35
lines changed

7 files changed

+101
-35
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ capacity_builder = "0.5.0"
4848
chrono = { version = "0.4.42", default-features = false, features = ["serde"] }
4949
data-url = "0.3.0"
5050
# this is optional in order to support using parsers other than swc
51-
deno_ast = { version = "0.52.0", features = ["emit"], optional = true }
51+
deno_ast = { version = "0.53.0", features = ["emit"], optional = true }
5252
deno_error.workspace = true
53-
deno_media_type = { version = "0.3.0", features = ["decoding", "data_url", "module_specifier"] }
53+
deno_media_type = { version = "0.4.0", features = ["decoding", "data_url", "module_specifier"] }
5454
deno_path_util = "0.6.4"
5555
deno_semver = "0.9.0"
5656
deno_unsync.workspace = true

js/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ Deno.test({
719719
await assertRejects(
720720
async () => {
721721
await parseModule(
722-
"file:///a/test.md",
722+
"file:///a/test.js",
723723
new TextEncoder().encode(`# Some Markdown\n\n**bold**`),
724724
);
725725
},

src/graph.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ pub struct JsonModule {
13921392
}
13931393

13941394
impl JsonModule {
1395-
/// Return the size in bytes of the content of the JSON module.
1395+
/// Return the size in bytes of the content of the module.
13961396
pub fn size(&self) -> usize {
13971397
self.source.text.len()
13981398
}
@@ -1888,6 +1888,7 @@ impl<'a, 'options> ModuleEntryIterator<'a, 'options> {
18881888
MediaType::Css
18891889
| MediaType::SourceMap
18901890
| MediaType::Html
1891+
| MediaType::Markdown
18911892
| MediaType::Sql
18921893
| MediaType::Jsonc
18931894
| MediaType::Json5
@@ -2951,6 +2952,19 @@ pub(crate) async fn parse_module_source_and_info(
29512952
);
29522953
}
29532954

2955+
if let Some(attribute_type) = opts.maybe_attribute_type
2956+
&& !matches!(attribute_type.kind.as_str(), "json" | "text" | "bytes")
2957+
{
2958+
return Err(
2959+
ModuleErrorKind::UnsupportedImportAttributeType {
2960+
specifier: opts.specifier,
2961+
referrer: attribute_type.range.clone(),
2962+
kind: attribute_type.kind.clone(),
2963+
}
2964+
.into_box(),
2965+
);
2966+
}
2967+
29542968
// here we check any media types that should have assertions made against them
29552969
// if they aren't the root and add them to the graph, otherwise we continue
29562970
if media_type == MediaType::Json
@@ -2974,27 +2988,18 @@ pub(crate) async fn parse_module_source_and_info(
29742988
});
29752989
}
29762990

2977-
if let Some(attribute_type) = opts.maybe_attribute_type {
2978-
if attribute_type.kind == "json" {
2979-
return Err(
2980-
ModuleErrorKind::InvalidTypeAssertion {
2981-
specifier: opts.specifier.clone(),
2982-
referrer: attribute_type.range.clone(),
2983-
actual_media_type: media_type,
2984-
expected_media_type: MediaType::Json,
2985-
}
2986-
.into_box(),
2987-
);
2988-
} else if !matches!(attribute_type.kind.as_str(), "text" | "bytes") {
2989-
return Err(
2990-
ModuleErrorKind::UnsupportedImportAttributeType {
2991-
specifier: opts.specifier,
2992-
referrer: attribute_type.range.clone(),
2993-
kind: attribute_type.kind.clone(),
2994-
}
2995-
.into_box(),
2996-
);
2997-
}
2991+
if let Some(attribute_type) = opts.maybe_attribute_type
2992+
&& attribute_type.kind == "json"
2993+
{
2994+
return Err(
2995+
ModuleErrorKind::InvalidTypeAssertion {
2996+
specifier: opts.specifier.clone(),
2997+
referrer: attribute_type.range.clone(),
2998+
actual_media_type: media_type,
2999+
expected_media_type: MediaType::Json,
3000+
}
3001+
.into_box(),
3002+
);
29983003
}
29993004

30003005
if matches!(media_type, MediaType::Cjs | MediaType::Cts)
@@ -3100,6 +3105,7 @@ pub(crate) async fn parse_module_source_and_info(
31003105
| MediaType::Sql
31013106
| MediaType::Jsonc
31023107
| MediaType::Json5
3108+
| MediaType::Markdown
31033109
| MediaType::Unknown => Err(
31043110
ModuleErrorKind::UnsupportedMediaType {
31053111
specifier: opts.specifier,

tests/specs/ecosystem/happy_js/happy_opfs/1_0_0.test

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ happy-js/happy-opfs/1.0.0
1010
-- stdout --
1111

1212
-- stderr --
13-
error: npm package '@jsr/happy-js__happy-rusty' does not exist.
14-
at file://<tmpdir>/src/fs/opfs_ext.ts:1:29
13+
TS2304 [ERROR]: Cannot find name 'FileSystemHandle'.
14+
*/ export function readDir(dirPath: string): Promise<Result<AsyncIterableIterator<[string, FileSystemHandle]>, Error>> {
15+
~~~~~~~~~~~~~~~~
16+
at file://<tmpdir>/src/fs/opfs_core.ts:13:93
17+
18+
TS2304 [ERROR]: Cannot find name 'FileSystemHandle'.
19+
*/ export function stat(path: string): Promise<Result<FileSystemHandle, Error>> {
20+
~~~~~~~~~~~~~~~~
21+
at file://<tmpdir>/src/fs/opfs_core.ts:35:56
22+
23+
Found 2 errors.
24+
25+
error: Type checking failed.
1526

tests/specs/ecosystem/stump/adapter_filesystem/0_0_1.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ stump/adapter-filesystem/0.0.1
1010
-- stdout --
1111

1212
-- stderr --
13-
error: npm package '@jsr/stump__core' does not exist.
14-
at file://<tmpdir>/src/base.ts:1:62
13+
TS4114 [ERROR]: This member must have an 'override' modifier because it overrides a member in the base class 'FileSystemAdapter<Meta>'.
14+
public ingestLogs(logs: Array<Log<Meta>>): Promise<void> {
15+
~~~~~~~~~~
16+
at file://<tmpdir>/src/drivers/bun/index.ts:7:10
17+
18+
error: Type checking failed.
1519

tests/specs/ecosystem/zeppet/actions/2_1_3.test

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,51 @@ zeppet/actions/2.1.3
1010
-- stdout --
1111

1212
-- stderr --
13-
error: npm package '@jsr/zeppet__core' does not exist.
14-
at file://<tmpdir>/src/index.ts:1:44
13+
TS2304 [ERROR]: Cannot find name 'HTMLElementEventMap'.
14+
export const listen = <K extends keyof HTMLElementEventMap>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void): ActionFn =>({} as never);
15+
~~~~~~~~~~~~~~~~~~~
16+
at file://<tmpdir>/src/index.ts:5:40
17+
18+
TS2304 [ERROR]: Cannot find name 'HTMLElementEventMap'.
19+
export const listen = <K extends keyof HTMLElementEventMap>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void): ActionFn =>({} as never);
20+
~~~~~~~~~~~~~~~~~~~
21+
at file://<tmpdir>/src/index.ts:5:92
22+
23+
TS2304 [ERROR]: Cannot find name 'HTMLElement'.
24+
export const bindFieldToObs = <T extends HTMLElement, K extends keyof T>(field: K, obs: Observer<NonNullable<T[K]>>)=>(element: T): T =>({} as never);
25+
~~~~~~~~~~~
26+
at file://<tmpdir>/src/index.ts:6:42
27+
28+
TS2304 [ERROR]: Cannot find name 'HTMLElement'.
29+
at file://<tmpdir>/src/index.ts:7:48
30+
31+
TS2304 [ERROR]: Cannot find name 'HTMLElement'.
32+
at file://<tmpdir>/src/index.ts:8:41
33+
34+
TS2304 [ERROR]: Cannot find name 'HTMLElementEventMap'.
35+
at file://<tmpdir>/src/index.ts:8:73
36+
37+
TS2304 [ERROR]: Cannot find name 'HTMLElementEventMap'.
38+
at file://<tmpdir>/src/index.ts:8:154
39+
40+
TS2304 [ERROR]: Cannot find name 'HTMLInputElement'.
41+
export const bindInput = <T extends HTMLInputElement>(obs: Observer<string>): Action<T> =>({} as never);
42+
~~~~~~~~~~~~~~~~
43+
at file://<tmpdir>/src/index.ts:9:37
44+
45+
TS2304 [ERROR]: Cannot find name 'HTMLElement'.
46+
at file://<tmpdir>/src/index.ts:10:34
47+
48+
TS2304 [ERROR]: Cannot find name 'HTMLElementTagNameMap'.
49+
at file://<tmpdir>/src/index.ts:10:63
50+
51+
TS2304 [ERROR]: Cannot find name 'HTMLElementTagNameMap'.
52+
at file://<tmpdir>/src/index.ts:10:179
53+
54+
TS2304 [ERROR]: Cannot find name 'HTMLElementTagNameMap'.
55+
at file://<tmpdir>/src/index.ts:10:208
56+
57+
Found 12 errors.
58+
59+
error: Type checking failed.
1560

0 commit comments

Comments
 (0)