bare-module 1.9.5 → 1.10.0

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/binding.c CHANGED
@@ -242,7 +242,7 @@ bare_module_create_module (js_env_t *env, js_callback_info_t *info) {
242
242
  if (err < 0) return NULL;
243
243
 
244
244
  js_module_t *module;
245
- err = js_create_module(env, (char *) file, file_len, offset, source, &module);
245
+ err = js_create_module(env, (char *) file, file_len, offset, source, NULL, NULL, &module);
246
246
  if (err < 0) return NULL;
247
247
 
248
248
  js_value_t *result;
package/index.js CHANGED
@@ -92,12 +92,12 @@ const Module = module.exports = class Module {
92
92
 
93
93
  if (this._cache[specifier]) return this._transform(this._cache[specifier], referrer, dynamic)
94
94
 
95
- const bundle = this._bundleFor(specifier, protocol, source)
95
+ const bundle = this._bundleFor(path.dirname(specifier), protocol, source)
96
96
 
97
97
  if (bundle) {
98
- imports = { ...imports, ...bundle.imports }
99
-
100
98
  protocol = new Protocol({
99
+ imports: bundle.imports,
100
+
101
101
  exists (filename) {
102
102
  return bundle.exists(filename)
103
103
  },
@@ -149,12 +149,12 @@ const Module = module.exports = class Module {
149
149
  referrer = null
150
150
  } = opts
151
151
 
152
- const bundle = this._bundleFor(specifier, protocol)
152
+ const bundle = this._bundleFor(path.dirname(specifier), protocol)
153
153
 
154
154
  if (bundle) {
155
- imports = { ...imports, ...bundle.imports }
156
-
157
155
  protocol = new Protocol({
156
+ imports: bundle.imports,
157
+
158
158
  exists (filename) {
159
159
  return bundle.exists(filename)
160
160
  },
@@ -180,6 +180,7 @@ const Module = module.exports = class Module {
180
180
 
181
181
  static * _resolve (specifier, dirname, protocol, imports) {
182
182
  if (specifier in imports) specifier = imports[specifier]
183
+ else if (specifier in protocol.imports) specifier = protocol.imports[specifier]
183
184
 
184
185
  protocol = this._protocolFor(specifier, protocol)
185
186
 
@@ -296,6 +297,22 @@ const Module = module.exports = class Module {
296
297
 
297
298
  if (bundle) return bundle
298
299
 
300
+ const parent = this._bundleFor(path.dirname(name), protocol)
301
+
302
+ if (parent) {
303
+ protocol = new Protocol({
304
+ imports: parent.imports,
305
+
306
+ exists (filename) {
307
+ return parent.exists(filename)
308
+ },
309
+
310
+ read (filename) {
311
+ return parent.read(filename)
312
+ }
313
+ })
314
+ }
315
+
299
316
  if (source === null || name !== specifier) source = protocol.read(name)
300
317
 
301
318
  bundle = this._bundles[name] = Bundle.from(source).mount(name)
package/lib/protocol.js CHANGED
@@ -1,12 +1,15 @@
1
1
  module.exports = class Protocol {
2
2
  constructor (opts = {}) {
3
3
  const {
4
+ imports = Object.create(null),
4
5
  map = null,
5
6
  resolve = null,
6
7
  exists = null,
7
8
  read = null
8
9
  } = opts
9
10
 
11
+ this.imports = imports
12
+
10
13
  if (map) this.map = map.bind(this)
11
14
  if (resolve) this.resolve = resolve.bind(this)
12
15
  else this.resolve = null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "1.9.5",
3
+ "version": "1.10.0",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -12,9 +12,7 @@
12
12
  "prebuilds"
13
13
  ],
14
14
  "scripts": {
15
- "test": "standard && bare test.js",
16
- "install": "bare-dev rebuild",
17
- "prebuild": "bare-dev prebuild"
15
+ "test": "standard && bare test.js"
18
16
  },
19
17
  "repository": {
20
18
  "type": "git",