bare-module 7.3.0 → 7.4.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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import Buffer from 'bare-buffer'
2
+ import Bundle from 'bare-bundle'
2
3
  import URL from 'bare-url'
3
4
  import { ResolutionsMap } from 'bare-module-resolve'
4
5
  import { constants } from 'bare-module-traverse'
@@ -151,7 +152,7 @@ declare namespace Module {
151
152
  export function load(url: URL, opts: LoadOptions): Promise<Module>
152
153
  export function load(
153
154
  url: URL,
154
- source?: Buffer | string | null,
155
+ source?: Buffer | Bundle | string | null,
155
156
  opts?: LoadOptions
156
157
  ): Promise<Module>
157
158
 
@@ -169,7 +170,11 @@ declare namespace Module {
169
170
  * the requested `type`.
170
171
  */
171
172
  export function loadSync(url: URL, opts: LoadOptions): Module
172
- export function loadSync(url: URL, source?: Buffer | string | null, opts?: LoadOptions): Module
173
+ export function loadSync(
174
+ url: URL,
175
+ source?: Buffer | Bundle | string | null,
176
+ opts?: LoadOptions
177
+ ): Module
173
178
 
174
179
  /**
175
180
  * Resolve the module `specifier` relative to the `parentURL`. `specifier` is a string and
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const { isURL, pathToFileURL } = require('bare-url')
2
+ const Bundle = require('bare-bundle')
2
3
  const { constants } = require('bare-module-traverse')
3
4
  const Module = require('./lib/module')
4
5
  const ModuleProtocol = require('./lib/protocol')
@@ -15,7 +16,7 @@ exports.constants = constants
15
16
  exports.load = async function load(url, source = null, opts = {}) {
16
17
  if (typeof url === 'string') url = new URL(url)
17
18
 
18
- if (source !== null && typeof source !== 'string' && !ArrayBuffer.isView(source)) {
19
+ if (source !== null && !isSource(source)) {
19
20
  opts = source
20
21
  source = null
21
22
  }
@@ -32,7 +33,7 @@ exports.load = async function load(url, source = null, opts = {}) {
32
33
  exports.loadSync = function loadSync(url, source = null, opts = {}) {
33
34
  if (typeof url === 'string') url = new URL(url)
34
35
 
35
- if (source !== null && typeof source !== 'string' && !ArrayBuffer.isView(source)) {
36
+ if (source !== null && !isSource(source)) {
36
37
  opts = source
37
38
  source = null
38
39
  }
@@ -102,6 +103,10 @@ function assertURL(url, name) {
102
103
  throw new TypeError(`${name} must be a URL. Received type ${typeof url} (${url})`)
103
104
  }
104
105
 
106
+ function isSource(value) {
107
+ return typeof value === 'string' || ArrayBuffer.isView(value) || Bundle.isBundle(value)
108
+ }
109
+
105
110
  function optionsFor(opts) {
106
111
  if (opts === undefined || opts === null) return {}
107
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "7.3.0",
3
+ "version": "7.4.0",
4
4
  "description": "The module system that powers Bare",
5
5
  "exports": {
6
6
  "./package": "./package.json",