Skip to content

Commit

Permalink
Add require.addon.host and import.meta.addon.host
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed Dec 13, 2023
1 parent 072293a commit cbb947b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ const Module = module.exports = exports = class Module {
const referrer = module
const dirname = path.dirname(module._filename)

addon.host = Bare.Addon.host

meta.url = module._filename
meta.main = module._main === module
meta.resolve = resolve
Expand Down Expand Up @@ -283,6 +285,8 @@ const Module = module.exports = exports = class Module {

const dirname = path.dirname(module._filename)

addon.host = Bare.Addon.host

require.main = module._main
require.cache = self._cache
require.resolve = resolve
Expand Down Expand Up @@ -583,6 +587,8 @@ Module._extensions['.cjs'] = function (module, source, referrer) {

const dirname = path.dirname(module._filename)

addon.host = Bare.Addon.host

require.main = module._main
require.cache = self._cache
require.resolve = resolve
Expand Down
17 changes: 17 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,22 @@ test('require.main', (t) => {
t.is(bar.exports, foo)
})

test('require.addon.host', (t) => {
t.teardown(onteardown)

const protocol = new Module.Protocol({
read (filename) {
if (filename === '/foo.js') {
return 'module.exports = require.addon.host'
}

t.fail()
}
})

t.comment(Module.load('/foo.js', { protocol }).exports)
})

test('import.meta', (t) => {
t.teardown(onteardown)

Expand All @@ -1030,6 +1046,7 @@ test('import.meta', (t) => {
t.is(meta.url, '/foo.mjs')
t.is(meta.main, true)
t.is(meta.resolve('/bar'), '/bar.mjs')
t.comment(meta.addon.host)
})

test('import assertions', (t) => {
Expand Down

0 comments on commit cbb947b

Please sign in to comment.