-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modules: add import.meta.__dirname and import.meta.__filename #39147
Changes from all commits
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 | ||
---|---|---|---|---|
|
@@ -5,6 +5,7 @@ const { | |||
ArrayPrototypeMap, | ||||
Boolean, | ||||
JSONParse, | ||||
ObjectDefineProperties, | ||||
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.
Suggested change
Unused primordial. |
||||
ObjectGetPrototypeOf, | ||||
ObjectPrototypeHasOwnProperty, | ||||
ObjectKeys, | ||||
|
@@ -39,6 +40,7 @@ const { | |||
cjsParseCache | ||||
} = require('internal/modules/cjs/loader'); | ||||
const internalURLModule = require('internal/url'); | ||||
const internalPathModule = require('path'); | ||||
const { defaultGetSource } = require( | ||||
'internal/modules/esm/get_source'); | ||||
const { defaultTransformSource } = require( | ||||
|
@@ -129,6 +131,11 @@ function createImportMetaResolve(defaultParentUrl) { | |||
|
||||
function initializeImportMeta(meta, { url }) { | ||||
// Alphabetical | ||||
if (StringPrototypeStartsWith(url, 'file:')) { | ||||
meta.__filename = internalURLModule.fileURLToPath(new URL(url)); | ||||
meta.__dirname = internalPathModule.dirname(meta.__filename); | ||||
Comment on lines
+135
to
+136
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. can this be done with getters / lazily? 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. Unfortunately not, there's a test that checks that 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. seems fine |
||||
} | ||||
|
||||
if (experimentalImportMetaResolve) | ||||
meta.resolve = createImportMetaResolve(url); | ||||
meta.url = url; | ||||
|
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.
the check in the impl only uses
file:
should you be using//
in the impl or remove that bit from here to just befile:
? generally when talking about scheme we just havescheme:
(E.G. https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_file_urls )