Uh oh!
There was an error while loading. Please reload this page.
esm: use undici/fetch data url parser - #54748
Conversation
nodejs-github-bot
commented
Sep 3, 2024
Review requested:
|
| } catch (e) { | ||
| assert.strictEqual(e.code, 'ERR_INVALID_URL'); | ||
| } | ||
| await assert.rejects(import(plainESMURL), { code: 'ERR_UNKNOWN_MODULE_FORMAT' }) |
There was a problem hiding this comment.
data:invalid,null is a valid data url afaik
aduh95
commented
Sep 3, 2024
One of the problem of this approach is that Undici is not at all written in a way to be robust against prototype mutation, which seems to be a deal breaker when it comes to loading modules. |
KhafraDev
commented
Sep 3, 2024
that's true, maybe I could rip the data url parser from undici and implement it here? Could be useful for the node:util or something as well. |
I took undici's data url parser and added primordials, it's entirely possible I missed things or misused them. |
mcollina
commented
Sep 4, 2024
@KhafraDev can you also port the tests for the tests for the data url parser? |
ljharb
left a comment
There was a problem hiding this comment.
feel free to ignore these, but they might make things simpler and faster
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
KhafraDev
commented
Sep 4, 2024
I took the WPTs for fetching data urls, if there's a more complete dataset, or if there's one specifically for imports, let me know. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## main #54748 +/- ##
========================================
Coverage 87.60% 87.61% ========================================
Files 650 651 +1 Lines 182829 183289 +460 Branches 35379 35434 +55 ========================================
+ Hits 160173 160591 +418 - Misses 15928 15950 +22 - Partials 6728 6748 +20
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
aduh95
commented
Sep 7, 2024
Landed in 6c85d40 |
I tried to include this in v20.x, but it broke HTTP imports (which were removed from main/v22.x) See https://github.com/nodejs/node/actions/runs/11102823645/job/30843465228?pr=55170 |
KhafraDev
commented
Sep 30, 2024
The test that failed is: it('data: URL can always import other data:',async()=>{constdata=newURL('data:text/javascript,');data.searchParams.set('body','import \'data:text/javascript,import \'data:\'');// doesn't throwconstempty=awaitimport(data.href);assert.ok(empty);});Where |
Using the fetch parser, rather than a regex, should fix most of these edge cases.
It would probably be better to export the parser directly so we can use it for the sync parsing too. Just wanted to gauge how correct or welcome this change would be.
fetch should also be used for
blob:urls, whenever support is added for them, as it handles edge cases regarding those as well. If someone ever brings back http/https imports, fetch should probably be used there as well. :)Fixes#53775
Fixes#42890
Closes#51324