bare-stow 0.1.4 → 0.1.5

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
@@ -3,11 +3,11 @@ const { fileURLToPath } = require('url')
3
3
  const pack = require('bare-pack')
4
4
  const id = require('bare-bundle-id')
5
5
  const strip = require('bare-type-stripper')
6
+ const { resolve } = require('bare-module-traverse')
6
7
  const fs = require('./lib/fs')
7
8
  const shim = require('./lib/shim')
8
9
  const harness = require('./lib/target')
9
10
  const rpc = require('./lib/rpc')
10
- const resolve = require('./lib/resolve')
11
11
 
12
12
  module.exports = async function* stow(entry, target, out, opts = {}) {
13
13
  if (!target) throw new Error("'target' is required")
@@ -69,7 +69,7 @@ module.exports = async function* stow(entry, target, out, opts = {}) {
69
69
  shimURL,
70
70
  {
71
71
  ...packOpts,
72
- resolve,
72
+ resolve: resolve.bare,
73
73
  aliases: {
74
74
  '.ts': '.js',
75
75
  '.mts': '.mjs',
package/lib/protocol.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const { Duplex, Writable } = require('bare-stream')
2
+ const b4a = require('b4a')
2
3
 
3
4
  const CONTROL = 0x00
4
5
  const USER = 0x01
@@ -25,7 +26,7 @@ class Protocol extends Duplex {
25
26
  }
26
27
 
27
28
  send(type, payload) {
28
- const frame = encodeFrame(CONTROL, Buffer.from(JSON.stringify({ type, ...payload })))
29
+ const frame = encodeFrame(CONTROL, b4a.from(JSON.stringify({ type, ...payload })))
29
30
 
30
31
  this._stream.write(frame)
31
32
 
@@ -58,10 +59,10 @@ class Protocol extends Duplex {
58
59
  _onbeforeframe() {
59
60
  if (this._buffered < 4) return
60
61
 
61
- const buffer = this._buffer.length === 1 ? this._buffer[0] : Buffer.concat(this._buffer)
62
+ const buffer = this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer)
62
63
 
63
64
  this._buffer = [buffer]
64
- this._frame = 4 + buffer.readUInt32LE(0)
65
+ this._frame = 4 + b4a.readUInt32LE(buffer, 0)
65
66
 
66
67
  this._onafterframe()
67
68
  }
@@ -69,7 +70,7 @@ class Protocol extends Duplex {
69
70
  _onafterframe() {
70
71
  if (this._buffered < this._frame) return
71
72
 
72
- const buffer = this._buffer.length === 1 ? this._buffer[0] : Buffer.concat(this._buffer)
73
+ const buffer = this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer)
73
74
  const frame = this._frame
74
75
 
75
76
  this._buffered -= frame
@@ -81,16 +82,16 @@ class Protocol extends Duplex {
81
82
  }
82
83
 
83
84
  _onframe(frame) {
84
- const tag = frame.readUInt8(4)
85
+ const tag = frame[4]
85
86
  const payload = frame.subarray(HEADER_LENGTH)
86
87
 
87
88
  if (tag === USER) {
88
- this.push(Buffer.from(payload))
89
+ this.push(b4a.from(payload))
89
90
  } else if (tag === CONTROL) {
90
91
  let message
91
92
 
92
93
  try {
93
- message = JSON.parse(payload.toString())
94
+ message = JSON.parse(b4a.toString(payload))
94
95
  } catch {
95
96
  return
96
97
  }
@@ -118,12 +119,12 @@ exports.attach = function attach(stream) {
118
119
 
119
120
  function encodeFrame(tag, data) {
120
121
  const length = data.length + 1
121
- const frame = Buffer.alloc(HEADER_LENGTH + data.length)
122
+ const frame = b4a.alloc(HEADER_LENGTH + data.length)
122
123
 
123
- frame.writeUInt32LE(length, 0)
124
- frame.writeUInt8(tag, 4)
124
+ b4a.writeUInt32LE(frame, length, 0)
125
+ frame[4] = tag
125
126
 
126
- data.copy(frame, HEADER_LENGTH)
127
+ b4a.copy(data, frame, HEADER_LENGTH)
127
128
 
128
129
  return frame
129
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-stow",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Module bundling and harness generation for Bare",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -62,12 +62,13 @@
62
62
  },
63
63
  "homepage": "https://github.com/holepunchto/bare-stow#readme",
64
64
  "dependencies": {
65
+ "b4a": "^1.6.0",
65
66
  "bare-bundle": "^1.8.3",
66
67
  "bare-bundle-id": "^1.0.0",
67
68
  "bare-fs": "^4.2.1",
68
- "bare-module-lexer": "^1.5.2",
69
- "bare-module-traverse": "^2.1.1",
70
- "bare-pack": "^2.1.0",
69
+ "bare-module-lexer": "^1.6.0",
70
+ "bare-module-traverse": "^2.2.0",
71
+ "bare-pack": "^2.2.0",
71
72
  "bare-path": "^3.0.0",
72
73
  "bare-stream": "^2.13.1",
73
74
  "bare-type-stripper": "^0.1.2",
package/lib/resolve.js DELETED
@@ -1,40 +0,0 @@
1
- const lex = require('bare-module-lexer')
2
- const { resolve } = require('bare-module-traverse')
3
-
4
- module.exports = function bare(entry, parentURL, opts = {}) {
5
- const { linked = false, hosts } = opts
6
-
7
- let extensions
8
- let conditions = hosts.map((host) => ['bare', 'node', ...host.split('-')])
9
-
10
- if (entry.type & lex.constants.ADDON) {
11
- extensions = linked ? [] : ['.bare', '.node']
12
- conditions = conditions.map((conditions) => ['addon', ...conditions])
13
-
14
- return resolve.addon(entry.specifier || '.', parentURL, {
15
- ...opts,
16
- extensions,
17
- conditions,
18
- hosts,
19
- linked
20
- })
21
- }
22
-
23
- if (entry.type & lex.constants.ASSET) {
24
- conditions = conditions.map((conditions) => ['asset', ...conditions])
25
- } else {
26
- extensions = ['.js', '.cjs', '.mjs', '.ts', '.cts', '.mts', '.json', '.bare', '.node']
27
-
28
- if (entry.type & lex.constants.REQUIRE) {
29
- conditions = conditions.map((conditions) => ['require', ...conditions])
30
- } else if (entry.type & lex.constants.IMPORT) {
31
- conditions = conditions.map((conditions) => ['import', ...conditions])
32
- }
33
- }
34
-
35
- return resolve.module(entry.specifier, parentURL, {
36
- ...opts,
37
- extensions,
38
- conditions
39
- })
40
- }