Skip to content

Local fetches from imported local modules are not detected as file attachments #77

@mbostock

Description

@mbostock

Currently we only detect and rewrite local fetches from within Markdown, not within imported ES modules. For example, if I have a JavaScript cell in a Markdown file, docs/index.md:

```js
import {foo}  from "./foo.js";
```

And then in foo.js:

export const foo = await fetch("./foo.json").then((response) => response.json());

Then we would want foo.json to be identified as a file attachment.

Furthermore, if foo.js uses an absolute path (starting with a /):

export const foo = await fetch("/foo.json").then((response) => response.json());

Then foo.js would need to be rewritten to append /_file as per #78.

One of the challenges is whether fetch, like import, should be considered relative to the calling JavaScript source file (here foo.js) or relative to the serving page (index.md) which could be in a different directory. But I think since we’re already doing static analysis to find the fetches, it makes sense for fetch to be relative to the calling JavaScript source file for consistency; we think that’s “what people want”.

Metadata

Metadata

Assignees

Labels

bugSomething isn’t working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions