bare-module 4.8.4 → 4.8.6

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 CHANGED
@@ -1,4 +1,3 @@
1
- /* global Bare */
2
1
  const path = require('bare-path')
3
2
  const resolve = require('bare-module-resolve')
4
3
  const lex = require('bare-module-lexer')
@@ -114,14 +113,9 @@ module.exports = exports = class Module {
114
113
  Module._modules.delete(this)
115
114
  }
116
115
 
117
- _run() {
118
- binding.runModule(this._handle, Module._handle, Module._onrun)
119
- }
120
-
121
116
  _transform(isImport, isDynamicImport) {
122
117
  if (isDynamicImport) {
123
- this._synthesize()
124
- this._evaluate(true /* eagerRun */)
118
+ this._run()
125
119
  } else if (isImport) {
126
120
  this._synthesize()
127
121
  } else {
@@ -205,7 +199,7 @@ module.exports = exports = class Module {
205
199
  )
206
200
  }
207
201
 
208
- _evaluate(eagerRun = false) {
202
+ _evaluate() {
209
203
  if ((this._state & constants.states.EVALUATED) !== 0) return
210
204
 
211
205
  this._state |= constants.states.EVALUATED
@@ -224,17 +218,23 @@ module.exports = exports = class Module {
224
218
  urlToPath(this._url),
225
219
  urlToDirname(this._url)
226
220
  )
227
-
228
- if (eagerRun) this._run()
229
221
  } else if (this._type === constants.types.MODULE) {
230
222
  this._run()
231
223
 
232
224
  this._exports = binding.getNamespace(this._handle)
233
- } else if (eagerRun) {
234
- this._run()
235
225
  }
236
226
  }
237
227
 
228
+ _run() {
229
+ if ((this._state & constants.states.RUN) !== 0) return
230
+
231
+ this._state |= constants.states.RUN
232
+
233
+ this._synthesize()
234
+
235
+ binding.runModule(this._handle, Module._handle, Module._onrun)
236
+ }
237
+
238
238
  [Symbol.for('bare.inspect')]() {
239
239
  return {
240
240
  __proto__: { constructor: Module },
@@ -978,7 +978,9 @@ Module._protocol = new Protocol({
978
978
  postresolve(url) {
979
979
  switch (url.protocol) {
980
980
  case 'file:':
981
- return pathToFileURL(binding.realpath(fileURLToPath(url)))
981
+ return pathToFileURL(
982
+ binding.realpath(path.toNamespacedPath(fileURLToPath(url)))
983
+ )
982
984
  default:
983
985
  return url
984
986
  }
@@ -988,7 +990,7 @@ Module._protocol = new Protocol({
988
990
  switch (url.protocol) {
989
991
  case 'file:':
990
992
  return binding.exists(
991
- fileURLToPath(url),
993
+ path.toNamespacedPath(fileURLToPath(url)),
992
994
  type === constants.types.ASSET
993
995
  ? binding.FILE | binding.DIR
994
996
  : binding.FILE
@@ -1001,7 +1003,9 @@ Module._protocol = new Protocol({
1001
1003
  read(url) {
1002
1004
  switch (url.protocol) {
1003
1005
  case 'file:':
1004
- return Buffer.from(binding.read(fileURLToPath(url)))
1006
+ return Buffer.from(
1007
+ binding.read(path.toNamespacedPath(fileURLToPath(url)))
1008
+ )
1005
1009
  default:
1006
1010
  throw errors.UNKNOWN_PROTOCOL(`Cannot load module '${url.href}'`)
1007
1011
  }
@@ -2,6 +2,7 @@ declare const constants: {
2
2
  states: {
3
3
  EVALUATED: number
4
4
  SYNTHESIZED: number
5
+ RUN: number
5
6
  DESTROYED: number
6
7
  }
7
8
  types: {
package/lib/constants.js CHANGED
@@ -2,7 +2,8 @@ module.exports = {
2
2
  states: {
3
3
  EVALUATED: 1,
4
4
  SYNTHESIZED: 2,
5
- DESTROYED: 4
5
+ RUN: 4,
6
+ DESTROYED: 8
6
7
  },
7
8
 
8
9
  types: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "4.8.4",
3
+ "version": "4.8.6",
4
4
  "description": "Module support for JavaScript",
5
5
  "exports": {
6
6
  ".": {