bare-module 1.14.0 → 1.14.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.
Files changed (2) hide show
  1. package/index.js +17 -13
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -19,6 +19,8 @@ module.exports = exports = class Module {
19
19
  this._info = null
20
20
  this._protocol = null
21
21
  this._handle = null
22
+
23
+ Module._modules.add(this)
22
24
  }
23
25
 
24
26
  get type () {
@@ -66,6 +68,8 @@ module.exports = exports = class Module {
66
68
  binding.deleteModule(this._handle)
67
69
  this._handle = null
68
70
  }
71
+
72
+ Module._modules.delete(this)
69
73
  }
70
74
 
71
75
  [Symbol.for('bare.inspect')] () {
@@ -87,16 +91,9 @@ module.exports = exports = class Module {
87
91
  static _imports = Object.create(null)
88
92
  static _cache = Object.create(null)
89
93
  static _bundles = Object.create(null)
94
+ static _modules = new Set()
90
95
 
91
- static _context = binding.init(this, this._onimport, this._onevaluate, this._onmeta)
92
-
93
- static _ondestroy () {
94
- for (const specifier in this._cache) {
95
- this._cache[specifier].destroy()
96
- }
97
-
98
- binding.destroy(this._context)
99
- }
96
+ static _handle = binding.init(this, this._onimport, this._onevaluate, this._onmeta)
100
97
 
101
98
  static _onimport (specifier, assertions, referrerFilename, dynamic) {
102
99
  const referrer = this._cache[referrerFilename]
@@ -520,7 +517,7 @@ module.exports = exports = class Module {
520
517
  static _evaluate (module) {
521
518
  if ((module._state & constants.states.EVALUATED) !== 0) return
522
519
 
523
- binding.runModule(module._handle, this._context)
520
+ binding.runModule(module._handle, this._handle)
524
521
 
525
522
  if (module._type === constants.types.MODULE) {
526
523
  module._exports = binding.getNamespace(module._handle)
@@ -538,7 +535,7 @@ module.exports = exports = class Module {
538
535
  if (key !== 'default') names.push(key)
539
536
  }
540
537
 
541
- module._handle = binding.createSyntheticModule(module._filename, names, this._context)
538
+ module._handle = binding.createSyntheticModule(module._filename, names, this._handle)
542
539
 
543
540
  module._state |= constants.states.SYNTHESIZED
544
541
  }
@@ -612,7 +609,7 @@ exports._extensions['.mjs'] = function (module, source, referrer, protocol, impo
612
609
  module._type = constants.types.MODULE
613
610
  module._protocol = protocol
614
611
  module._imports = imports
615
- module._handle = binding.createModule(module._filename, source, 0, this._context)
612
+ module._handle = binding.createModule(module._filename, source, 0, this._handle)
616
613
  }
617
614
 
618
615
  exports._extensions['.json'] = function (module, source, referrer, protocol, imports) {
@@ -688,4 +685,11 @@ exports._protocols['data:'] = new Protocol({
688
685
  }
689
686
  })
690
687
 
691
- process.on('exit', exports._ondestroy.bind(exports))
688
+ process
689
+ .on('exit', () => {
690
+ for (const module of exports._modules) {
691
+ module.destroy()
692
+ }
693
+
694
+ binding.destroy(exports._handle)
695
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "1.14.0",
3
+ "version": "1.14.2",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [