-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
esm: remove erroneous context.parentURL
property passed to load
hook
#41975
Changes from 1 commit
5a9bf22
f733c70
b008799
f39a2ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Flags: --expose-internals | ||
import '../common/index.mjs'; | ||
import mod from 'internal/modules/esm/loader'; | ||
import assert from 'assert'; | ||
|
||
const { ESMLoader } = mod; | ||
|
||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this big block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, but until you have the other cases it doesn’t make much sense to have just one block. I would also argue that perhaps other cases should be in new files, as this one’s already pretty large. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking it would make sense to keep them in the same file. There are already a lot of files in this directory, many of which SEEM redundant (which makes it difficult to figure out what might or should be where). If the file gets renamed at the same time as more cases are added, git will likely break the history. I could see removing the block for now and add it back when the other cases are added. I would prefer to keep them in the same file though, unless they differ a lot or become unruly. Could I persuade you to wait and see? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ve already approved, so you can do whatever. Maybe just add a comment at the top of the block saying this is here because you anticipate adding more blocks in the future, and what this block is meant to test. |
||
const esmLoader = new ESMLoader(); | ||
Mesteery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const originalSpecifier = 'foo/bar'; | ||
const importAssertions = { type: 'json' }; | ||
const parentURL = 'file:///entrypoint.js'; | ||
const resolvedURL = 'file:///foo/bar.js'; | ||
const suggestedFormat = 'test'; | ||
|
||
const customLoader1 = { | ||
resolve(specifier, context, defaultResolve) { | ||
JakobJingleheimer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert.strictEqual(specifier, originalSpecifier); | ||
assert.deepStrictEqual(Object.keys(context), [ | ||
'conditions', | ||
'importAssertions', | ||
'parentURL', | ||
]); | ||
assert.ok(Array.isArray(context.conditions)); | ||
assert.strictEqual(context.importAssertions, importAssertions); | ||
assert.strictEqual(context.parentURL, parentURL); | ||
assert.strictEqual(typeof defaultResolve, 'function'); | ||
|
||
// This doesn't matter. just to avoid errors | ||
return { | ||
format: suggestedFormat, | ||
url: resolvedURL, | ||
}; | ||
}, | ||
load(resolvedURL, context, defaultLoad) { | ||
assert.strictEqual(resolvedURL, resolvedURL); | ||
assert.ok(new URL(resolvedURL)); | ||
assert.deepStrictEqual(Object.keys(context), [ | ||
'format', | ||
'importAssertions', | ||
]); | ||
assert.strictEqual(context.format, suggestedFormat); | ||
assert.strictEqual(context.importAssertions, importAssertions); | ||
assert.strictEqual(typeof defaultLoad, 'function'); | ||
|
||
// This doesn't matter. just to avoid errors | ||
return { | ||
format: 'module', | ||
source: '', | ||
}; | ||
}, | ||
}; | ||
|
||
esmLoader.addCustomLoaders(customLoader1); | ||
|
||
esmLoader.resolve( | ||
originalSpecifier, | ||
parentURL, | ||
importAssertions, | ||
); | ||
esmLoader.load( | ||
resolvedURL, | ||
{ | ||
format: suggestedFormat, | ||
importAssertions, | ||
}, | ||
function mockDefaultLoad() {}, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find
mod
very descriptive (if it's a well known acronym that I don't know, please ignore)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not super common. I usually use
module
, but some linters freak out when they find it in an ESM file. I consideredloader
, but it's not the loader, so I opted formod
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with
esmLoaderModule
(not married to it).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike default exports in general. As far as I’m concerned,
esm/loader
doesn’t need a default export and you should be able to just import it viaimport { loader } from 'internal/modules/esm/loader'
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I wanted to do. It doesn't work: #41975 (comment)
esmLoaderModule
is an object that contains a property namedESMLoader
; there are no named exports available :(