Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,14 @@ A boolean representing whether the current module is the entry script where the

A cache of loaded modules for this module. The same value as `module.cache` for the current module.

#### `import.meta.dirname`

The directory name of the current module.

#### `import.meta.filename`

The file name of the current module.

#### `const href = import.meta.resolve(specifier[, parentURL])`

A module-relative resolution function which returns the URL string for the module. The `specifier` is a string which is resolved relative to the `parentURL` which is a WHATWG URL.
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ module.exports = exports = class Module {
meta.main = module._main === module
meta.cache = module._cache

meta.dirname = module.dirname // For Node.js compatibility
meta.filename = module.filename // For Node.js compatibility

meta.resolve = function resolve(specifier, parentURL = referrer._url) {
return self.resolve(specifier, toURL(parentURL, referrer._url), {
referrer
Expand Down
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1469,13 +1469,13 @@ test('import.meta', (t) => {
}
})

const { default: meta } = Module.load(new URL(root + '/foo.mjs'), {
protocol
}).exports
const { default: meta } = Module.load(new URL(root + '/foo.mjs'), { protocol }).exports

t.is(meta.url, root + '/foo.mjs')
t.is(meta.main, true)
t.is(meta.resolve('/bar'), root + '/bar.mjs')
t.is(meta.dirname, isWindows ? 'c:\\' : '/')
t.is(meta.filename, isWindows ? 'c:\\foo.mjs' : '/foo.mjs')
t.comment(meta.addon.host)
})

Expand Down
Loading