bare-module 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +22 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,7 +6,6 @@ const Protocol = require('./lib/protocol')
|
|
|
6
6
|
const constants = require('./lib/constants')
|
|
7
7
|
const errors = require('./lib/errors')
|
|
8
8
|
const binding = require('./binding')
|
|
9
|
-
const addon = require.addon.bind(require)
|
|
10
9
|
|
|
11
10
|
const Module = module.exports = exports = class Module {
|
|
12
11
|
constructor (filename) {
|
|
@@ -186,9 +185,10 @@ const Module = module.exports = exports = class Module {
|
|
|
186
185
|
module._protocol = protocol
|
|
187
186
|
|
|
188
187
|
const referrer = module
|
|
188
|
+
const dirname = path.dirname(module._filename)
|
|
189
189
|
|
|
190
190
|
const resolve = (specifier) => {
|
|
191
|
-
return this.resolve(specifier,
|
|
191
|
+
return this.resolve(specifier, dirname, {
|
|
192
192
|
protocol: this._protocolFor(specifier, protocol),
|
|
193
193
|
imports,
|
|
194
194
|
referrer
|
|
@@ -205,10 +205,16 @@ const Module = module.exports = exports = class Module {
|
|
|
205
205
|
return module._exports
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
+
const addon = (specifier = '.') => {
|
|
209
|
+
return Bare.Addon.load(Bare.Addon.resolve(specifier, dirname, {
|
|
210
|
+
referrer
|
|
211
|
+
}))
|
|
212
|
+
}
|
|
213
|
+
|
|
208
214
|
require.main = module._main
|
|
209
215
|
require.cache = this._cache
|
|
210
216
|
require.resolve = resolve
|
|
211
|
-
require.addon =
|
|
217
|
+
require.addon = addon
|
|
212
218
|
|
|
213
219
|
return require
|
|
214
220
|
}
|
|
@@ -624,8 +630,10 @@ Module._extensions['.cjs'] = function (module, source, referrer, protocol, impor
|
|
|
624
630
|
|
|
625
631
|
referrer = module
|
|
626
632
|
|
|
633
|
+
const dirname = path.dirname(module._filename)
|
|
634
|
+
|
|
627
635
|
const resolve = (specifier) => {
|
|
628
|
-
return this.resolve(specifier,
|
|
636
|
+
return this.resolve(specifier, dirname, {
|
|
629
637
|
protocol: this._protocolFor(specifier, protocol),
|
|
630
638
|
imports,
|
|
631
639
|
referrer
|
|
@@ -642,12 +650,18 @@ Module._extensions['.cjs'] = function (module, source, referrer, protocol, impor
|
|
|
642
650
|
return module._exports
|
|
643
651
|
}
|
|
644
652
|
|
|
645
|
-
|
|
653
|
+
const addon = (specifier = '.') => {
|
|
654
|
+
return Bare.Addon.load(Bare.Addon.resolve(specifier, dirname, {
|
|
655
|
+
referrer
|
|
656
|
+
}))
|
|
657
|
+
}
|
|
646
658
|
|
|
647
659
|
require.main = module._main
|
|
648
660
|
require.cache = this._cache
|
|
649
661
|
require.resolve = resolve
|
|
650
|
-
require.addon =
|
|
662
|
+
require.addon = addon
|
|
663
|
+
|
|
664
|
+
module._exports = {}
|
|
651
665
|
|
|
652
666
|
binding.createFunction(module._filename, ['require', 'module', 'exports', '__filename', '__dirname'], source, 0)(
|
|
653
667
|
require,
|
|
@@ -696,7 +710,7 @@ Module._extensions['.bare'] = function (module, source, referrer, protocol, impo
|
|
|
696
710
|
module._protocol = protocol
|
|
697
711
|
module._imports = imports
|
|
698
712
|
|
|
699
|
-
module._exports =
|
|
713
|
+
module._exports = Bare.Addon.load(module._filename)
|
|
700
714
|
}
|
|
701
715
|
|
|
702
716
|
Module._extensions['.node'] = function (module, source, referrer, protocol, imports) {
|
|
@@ -704,7 +718,7 @@ Module._extensions['.node'] = function (module, source, referrer, protocol, impo
|
|
|
704
718
|
module._protocol = protocol
|
|
705
719
|
module._imports = imports
|
|
706
720
|
|
|
707
|
-
module._exports =
|
|
721
|
+
module._exports = Bare.Addon.load(module._filename)
|
|
708
722
|
}
|
|
709
723
|
|
|
710
724
|
Module._extensions['.bundle'] = function (module, source, referrer, protocol, imports) {
|