@zuplo/cli 6.69.10 → 6.69.11

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 (189) hide show
  1. package/dist/__tests__/integration/jest-mocks-setup.js +3 -0
  2. package/dist/__tests__/integration/jest-mocks-setup.js.map +1 -1
  3. package/dist/cli.js +4 -1
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cmds/bucket/list.d.ts.map +1 -1
  6. package/dist/cmds/bucket/list.js +1 -8
  7. package/dist/cmds/bucket/list.js.map +1 -1
  8. package/dist/cmds/build.d.ts.map +1 -1
  9. package/dist/cmds/build.js +1 -2
  10. package/dist/cmds/build.js.map +1 -1
  11. package/dist/cmds/compile.d.ts.map +1 -1
  12. package/dist/cmds/compile.js +1 -2
  13. package/dist/cmds/compile.js.map +1 -1
  14. package/dist/cmds/custom-domain/create.d.ts.map +1 -1
  15. package/dist/cmds/custom-domain/create.js +1 -8
  16. package/dist/cmds/custom-domain/create.js.map +1 -1
  17. package/dist/cmds/custom-domain/delete.d.ts.map +1 -1
  18. package/dist/cmds/custom-domain/delete.js +1 -8
  19. package/dist/cmds/custom-domain/delete.js.map +1 -1
  20. package/dist/cmds/custom-domain/list.d.ts.map +1 -1
  21. package/dist/cmds/custom-domain/list.js +1 -8
  22. package/dist/cmds/custom-domain/list.js.map +1 -1
  23. package/dist/cmds/custom-domain/update.d.ts.map +1 -1
  24. package/dist/cmds/custom-domain/update.js +1 -8
  25. package/dist/cmds/custom-domain/update.js.map +1 -1
  26. package/dist/cmds/delete.d.ts.map +1 -1
  27. package/dist/cmds/delete.js +0 -2
  28. package/dist/cmds/delete.js.map +1 -1
  29. package/dist/cmds/deploy.d.ts.map +1 -1
  30. package/dist/cmds/deploy.js +0 -2
  31. package/dist/cmds/deploy.js.map +1 -1
  32. package/dist/cmds/dev.d.ts.map +1 -1
  33. package/dist/cmds/dev.js +1 -2
  34. package/dist/cmds/dev.js.map +1 -1
  35. package/dist/cmds/docs.d.ts.map +1 -1
  36. package/dist/cmds/docs.js +1 -2
  37. package/dist/cmds/docs.js.map +1 -1
  38. package/dist/cmds/editor.d.ts.map +1 -1
  39. package/dist/cmds/editor.js +1 -2
  40. package/dist/cmds/editor.js.map +1 -1
  41. package/dist/cmds/init.d.ts.map +1 -1
  42. package/dist/cmds/init.js +1 -3
  43. package/dist/cmds/init.js.map +1 -1
  44. package/dist/cmds/link.d.ts.map +1 -1
  45. package/dist/cmds/link.js +0 -2
  46. package/dist/cmds/link.js.map +1 -1
  47. package/dist/cmds/list.d.ts.map +1 -1
  48. package/dist/cmds/list.js +0 -2
  49. package/dist/cmds/list.js.map +1 -1
  50. package/dist/cmds/login.d.ts.map +1 -1
  51. package/dist/cmds/login.js +2 -2
  52. package/dist/cmds/login.js.map +1 -1
  53. package/dist/cmds/logout.d.ts.map +1 -1
  54. package/dist/cmds/logout.js +2 -3
  55. package/dist/cmds/logout.js.map +1 -1
  56. package/dist/cmds/mtls-certificates/create.d.ts.map +1 -1
  57. package/dist/cmds/mtls-certificates/create.js +0 -2
  58. package/dist/cmds/mtls-certificates/create.js.map +1 -1
  59. package/dist/cmds/mtls-certificates/delete.d.ts.map +1 -1
  60. package/dist/cmds/mtls-certificates/delete.js +0 -2
  61. package/dist/cmds/mtls-certificates/delete.js.map +1 -1
  62. package/dist/cmds/mtls-certificates/describe.d.ts.map +1 -1
  63. package/dist/cmds/mtls-certificates/describe.js +0 -2
  64. package/dist/cmds/mtls-certificates/describe.js.map +1 -1
  65. package/dist/cmds/mtls-certificates/disable.d.ts.map +1 -1
  66. package/dist/cmds/mtls-certificates/disable.js +0 -2
  67. package/dist/cmds/mtls-certificates/disable.js.map +1 -1
  68. package/dist/cmds/mtls-certificates/list.d.ts.map +1 -1
  69. package/dist/cmds/mtls-certificates/list.js +0 -2
  70. package/dist/cmds/mtls-certificates/list.js.map +1 -1
  71. package/dist/cmds/mtls-certificates/update.d.ts.map +1 -1
  72. package/dist/cmds/mtls-certificates/update.js +0 -2
  73. package/dist/cmds/mtls-certificates/update.js.map +1 -1
  74. package/dist/cmds/project/create.d.ts.map +1 -1
  75. package/dist/cmds/project/create.js +1 -8
  76. package/dist/cmds/project/create.js.map +1 -1
  77. package/dist/cmds/project/info.d.ts.map +1 -1
  78. package/dist/cmds/project/info.js +1 -2
  79. package/dist/cmds/project/info.js.map +1 -1
  80. package/dist/cmds/proxies/create.d.ts.map +1 -1
  81. package/dist/cmds/proxies/create.js +0 -2
  82. package/dist/cmds/proxies/create.js.map +1 -1
  83. package/dist/cmds/proxies/delete.d.ts.map +1 -1
  84. package/dist/cmds/proxies/delete.js +0 -2
  85. package/dist/cmds/proxies/delete.js.map +1 -1
  86. package/dist/cmds/proxies/describe.d.ts.map +1 -1
  87. package/dist/cmds/proxies/describe.js +0 -2
  88. package/dist/cmds/proxies/describe.js.map +1 -1
  89. package/dist/cmds/proxies/update.d.ts.map +1 -1
  90. package/dist/cmds/proxies/update.js +0 -2
  91. package/dist/cmds/proxies/update.js.map +1 -1
  92. package/dist/cmds/source/migrate.d.ts.map +1 -1
  93. package/dist/cmds/source/migrate.js +1 -2
  94. package/dist/cmds/source/migrate.js.map +1 -1
  95. package/dist/cmds/source/upgrade.d.ts.map +1 -1
  96. package/dist/cmds/source/upgrade.js +1 -2
  97. package/dist/cmds/source/upgrade.js.map +1 -1
  98. package/dist/cmds/test.d.ts.map +1 -1
  99. package/dist/cmds/test.js +1 -2
  100. package/dist/cmds/test.js.map +1 -1
  101. package/dist/cmds/tunnel/create.d.ts.map +1 -1
  102. package/dist/cmds/tunnel/create.js +1 -8
  103. package/dist/cmds/tunnel/create.js.map +1 -1
  104. package/dist/cmds/tunnel/delete.d.ts.map +1 -1
  105. package/dist/cmds/tunnel/delete.js +1 -8
  106. package/dist/cmds/tunnel/delete.js.map +1 -1
  107. package/dist/cmds/tunnel/describe.d.ts.map +1 -1
  108. package/dist/cmds/tunnel/describe.js +1 -8
  109. package/dist/cmds/tunnel/describe.js.map +1 -1
  110. package/dist/cmds/tunnel/list.d.ts.map +1 -1
  111. package/dist/cmds/tunnel/list.js +1 -8
  112. package/dist/cmds/tunnel/list.js.map +1 -1
  113. package/dist/cmds/tunnel/rotate-token.d.ts.map +1 -1
  114. package/dist/cmds/tunnel/rotate-token.js +1 -8
  115. package/dist/cmds/tunnel/rotate-token.js.map +1 -1
  116. package/dist/cmds/tunnel/services/describe.d.ts.map +1 -1
  117. package/dist/cmds/tunnel/services/describe.js +1 -8
  118. package/dist/cmds/tunnel/services/describe.js.map +1 -1
  119. package/dist/cmds/tunnel/services/update.d.ts.map +1 -1
  120. package/dist/cmds/tunnel/services/update.js +1 -8
  121. package/dist/cmds/tunnel/services/update.js.map +1 -1
  122. package/dist/cmds/variable/create.d.ts.map +1 -1
  123. package/dist/cmds/variable/create.js +0 -2
  124. package/dist/cmds/variable/create.js.map +1 -1
  125. package/dist/cmds/variable/update.d.ts.map +1 -1
  126. package/dist/cmds/variable/update.js +0 -2
  127. package/dist/cmds/variable/update.js.map +1 -1
  128. package/dist/cmds/whoami.d.ts.map +1 -1
  129. package/dist/cmds/whoami.js +1 -2
  130. package/dist/cmds/whoami.js.map +1 -1
  131. package/dist/common/middleware/check-pnpm-lifecycle.d.ts +17 -0
  132. package/dist/common/middleware/check-pnpm-lifecycle.d.ts.map +1 -0
  133. package/dist/common/middleware/check-pnpm-lifecycle.js +96 -0
  134. package/dist/common/middleware/check-pnpm-lifecycle.js.map +1 -0
  135. package/dist/common/middleware/check-pnpm-lifecycle.test.d.ts +2 -0
  136. package/dist/common/middleware/check-pnpm-lifecycle.test.d.ts.map +1 -0
  137. package/dist/common/middleware/check-pnpm-lifecycle.test.js +125 -0
  138. package/dist/common/middleware/check-pnpm-lifecycle.test.js.map +1 -0
  139. package/dist/common/utils/pnpm-lifecycle.d.ts +13 -0
  140. package/dist/common/utils/pnpm-lifecycle.d.ts.map +1 -0
  141. package/dist/common/utils/pnpm-lifecycle.js +100 -0
  142. package/dist/common/utils/pnpm-lifecycle.js.map +1 -0
  143. package/dist/common/utils/pnpm-lifecycle.test.d.ts +2 -0
  144. package/dist/common/utils/pnpm-lifecycle.test.d.ts.map +1 -0
  145. package/dist/common/utils/pnpm-lifecycle.test.js +177 -0
  146. package/dist/common/utils/pnpm-lifecycle.test.js.map +1 -0
  147. package/dist/tsconfig.tsbuildinfo +1 -1
  148. package/node_modules/@zuplo/core/package.json +1 -1
  149. package/node_modules/@zuplo/graphql/out/esm/index.js.map +1 -1
  150. package/node_modules/@zuplo/graphql/out/types/index.d.ts +3 -0
  151. package/node_modules/@zuplo/graphql/package.json +1 -1
  152. package/node_modules/@zuplo/openapi-tools/package.json +2 -2
  153. package/node_modules/@zuplo/otel/package.json +1 -1
  154. package/node_modules/@zuplo/runtime/out/esm/index.js +94 -94
  155. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  156. package/node_modules/@zuplo/runtime/out/types/index.d.ts +72 -0
  157. package/node_modules/@zuplo/runtime/package.json +2 -2
  158. package/node_modules/pino-http/node_modules/thread-stream/.github/workflows/ci.yml +4 -4
  159. package/node_modules/pino-http/node_modules/thread-stream/README.md +4 -1
  160. package/node_modules/pino-http/node_modules/thread-stream/index.d.ts +7 -0
  161. package/node_modules/pino-http/node_modules/thread-stream/index.js +120 -21
  162. package/node_modules/pino-http/node_modules/thread-stream/lib/worker.js +101 -0
  163. package/node_modules/pino-http/node_modules/thread-stream/node_modules/real-require/LICENSE.md +21 -0
  164. package/node_modules/pino-http/node_modules/thread-stream/node_modules/real-require/README.md +51 -0
  165. package/node_modules/pino-http/node_modules/thread-stream/node_modules/real-require/package.json +38 -0
  166. package/node_modules/pino-http/node_modules/thread-stream/node_modules/real-require/src/index.js +14 -0
  167. package/node_modules/pino-http/node_modules/thread-stream/package.json +10 -12
  168. package/node_modules/pino-http/node_modules/thread-stream/test/flush-worker.js +68 -0
  169. package/node_modules/pino-http/node_modules/thread-stream/test/flush.test.js +112 -0
  170. package/node_modules/pino-http/node_modules/thread-stream/test/message-without-code.js +19 -0
  171. package/node_modules/pino-http/node_modules/thread-stream/test/report-thread-name.js +16 -0
  172. package/node_modules/pino-http/node_modules/thread-stream/test/thread-management.test.js +12 -0
  173. package/node_modules/pino-http/node_modules/thread-stream/test/watch-mode.test.js +30 -0
  174. package/node_modules/pino-http/node_modules/thread-stream/test/worker-name.test.js +43 -0
  175. package/node_modules/protobufjs/dist/light/protobuf.js +5 -3
  176. package/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
  177. package/node_modules/protobufjs/dist/light/protobuf.min.js +3 -3
  178. package/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
  179. package/node_modules/protobufjs/dist/minimal/protobuf.js +2 -2
  180. package/node_modules/protobufjs/dist/minimal/protobuf.min.js +2 -2
  181. package/node_modules/protobufjs/dist/protobuf.js +5 -3
  182. package/node_modules/protobufjs/dist/protobuf.js.map +1 -1
  183. package/node_modules/protobufjs/dist/protobuf.min.js +3 -3
  184. package/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
  185. package/node_modules/protobufjs/package.json +1 -1
  186. package/node_modules/protobufjs/src/namespace.js +3 -1
  187. package/package.json +7 -7
  188. package/node_modules/pino-http/node_modules/thread-stream/.husky/pre-commit +0 -4
  189. package/node_modules/pino-http/node_modules/thread-stream/CLAUDE.md +0 -53
@@ -18,6 +18,8 @@ const kImpl = Symbol('kImpl')
18
18
  // V8 limit for string size
19
19
  const MAX_STRING = buffer.constants.MAX_STRING_LENGTH
20
20
 
21
+ function noop () {}
22
+
21
23
  class FakeWeakRef {
22
24
  constructor (value) {
23
25
  this._value = value
@@ -54,6 +56,7 @@ function createWorker (stream, opts) {
54
56
 
55
57
  const worker = new Worker(toExecute, {
56
58
  ...opts.workerOpts,
59
+ name: opts.workerOpts?.name || 'thread-stream',
57
60
  trackUnmanagedFds: false,
58
61
  workerData: {
59
62
  filename: filename.indexOf('file://') === 0
@@ -114,8 +117,8 @@ function nextFlush (stream) {
114
117
  write(stream, toWrite, nextFlush.bind(null, stream))
115
118
  } else {
116
119
  // multi-byte utf-8
117
- stream.flush(() => {
118
- // err is already handled in flush()
120
+ waitForRead(stream, () => {
121
+ // err is already handled in waitForRead()
119
122
  if (stream.destroyed) {
120
123
  return
121
124
  }
@@ -141,7 +144,7 @@ function nextFlush (stream) {
141
144
  // we had a flushSync in the meanwhile
142
145
  return
143
146
  }
144
- stream.flush(() => {
147
+ waitForRead(stream, () => {
145
148
  Atomics.store(stream[kImpl].state, READ_INDEX, 0)
146
149
  Atomics.store(stream[kImpl].state, WRITE_INDEX, 0)
147
150
  Atomics.notify(stream[kImpl].state, READ_INDEX)
@@ -162,13 +165,19 @@ function onWorkerMessage (msg) {
162
165
  return
163
166
  }
164
167
 
168
+ // Node.js watch mode may send internal worker messages that do not
169
+ // participate in thread-stream's worker protocol.
170
+ if (msg?.code == null) {
171
+ return
172
+ }
173
+
165
174
  switch (msg.code) {
166
175
  case 'READY':
167
176
  // Replace the FakeWeakRef with a
168
177
  // proper one.
169
178
  this.stream = new WeakRef(stream)
170
179
 
171
- stream.flush(() => {
180
+ waitForRead(stream, () => {
172
181
  stream[kImpl].ready = true
173
182
  stream.emit('ready')
174
183
  })
@@ -183,6 +192,19 @@ function onWorkerMessage (msg) {
183
192
  stream.emit(msg.name, msg.args)
184
193
  }
185
194
  break
195
+ case 'FLUSHED': {
196
+ if (msg.context !== 'thread-stream') {
197
+ destroy(stream, new Error('this should not happen: ' + msg.code))
198
+ break
199
+ }
200
+
201
+ const cb = stream[kImpl].flushCallbacks.get(msg.id)
202
+ if (cb) {
203
+ stream[kImpl].flushCallbacks.delete(msg.id)
204
+ process.nextTick(cb)
205
+ }
206
+ break
207
+ }
186
208
  case 'WARNING':
187
209
  process.emitWarning(msg.err)
188
210
  break
@@ -227,6 +249,8 @@ class ThreadStream extends EventEmitter {
227
249
  this[kImpl].errored = null
228
250
  this[kImpl].closed = false
229
251
  this[kImpl].buf = ''
252
+ this[kImpl].flushCallbacks = new Map()
253
+ this[kImpl].nextFlushId = 0
230
254
 
231
255
  // TODO (fix): Make private?
232
256
  this.worker = createWorker(this, opts) // TODO (fix): make private
@@ -287,28 +311,15 @@ class ThreadStream extends EventEmitter {
287
311
  }
288
312
 
289
313
  flush (cb) {
290
- if (this[kImpl].destroyed) {
291
- if (typeof cb === 'function') {
292
- process.nextTick(cb, new Error('the worker has exited'))
293
- }
294
- return
295
- }
314
+ cb = typeof cb === 'function' ? cb : noop
296
315
 
297
- // TODO write all .buf
298
- const writeIndex = Atomics.load(this[kImpl].state, WRITE_INDEX)
299
- // process._rawDebug(`(flush) readIndex (${Atomics.load(this.state, READ_INDEX)}) writeIndex (${Atomics.load(this.state, WRITE_INDEX)})`)
300
- wait(this[kImpl].state, READ_INDEX, writeIndex, Infinity, (err, res) => {
316
+ flushBuffer(this, (err) => {
301
317
  if (err) {
302
- destroy(this, err)
303
318
  process.nextTick(cb, err)
304
319
  return
305
320
  }
306
- if (res === 'not-equal') {
307
- // TODO handle deadlock
308
- this.flush(cb)
309
- return
310
- }
311
- process.nextTick(cb)
321
+
322
+ requestWorkerFlush(this, cb)
312
323
  })
313
324
  }
314
325
 
@@ -366,6 +377,93 @@ class ThreadStream extends EventEmitter {
366
377
  }
367
378
  }
368
379
 
380
+ function flushBuffer (stream, cb) {
381
+ if (stream[kImpl].destroyed) {
382
+ process.nextTick(cb, new Error('the worker has exited'))
383
+ return
384
+ }
385
+
386
+ if (!stream[kImpl].sync && (stream[kImpl].flushing || stream[kImpl].buf.length > 0)) {
387
+ setImmediate(flushBuffer, stream, cb)
388
+ return
389
+ }
390
+
391
+ waitForRead(stream, cb)
392
+ }
393
+
394
+ function waitForRead (stream, cb) {
395
+ const writeIndex = Atomics.load(stream[kImpl].state, WRITE_INDEX)
396
+ wait(stream[kImpl].state, READ_INDEX, writeIndex, Infinity, (err, res) => {
397
+ if (err) {
398
+ destroy(stream, err)
399
+ cb(err)
400
+ return
401
+ }
402
+
403
+ if (res !== 'ok') {
404
+ waitForRead(stream, cb)
405
+ return
406
+ }
407
+
408
+ cb()
409
+ })
410
+ }
411
+
412
+ function requestWorkerFlush (stream, cb) {
413
+ if (stream[kImpl].destroyed) {
414
+ process.nextTick(cb, new Error('the worker has exited'))
415
+ return
416
+ }
417
+
418
+ if (!stream[kImpl].ready) {
419
+ const onReady = () => {
420
+ cleanup()
421
+ requestWorkerFlush(stream, cb)
422
+ }
423
+ const onClose = () => {
424
+ cleanup()
425
+ process.nextTick(cb, new Error('the worker has exited'))
426
+ }
427
+ const cleanup = () => {
428
+ stream.off('ready', onReady)
429
+ stream.off('close', onClose)
430
+ }
431
+
432
+ stream.once('ready', onReady)
433
+ stream.once('close', onClose)
434
+ return
435
+ }
436
+
437
+ const id = ++stream[kImpl].nextFlushId
438
+ stream[kImpl].flushCallbacks.set(id, cb)
439
+
440
+ try {
441
+ stream.worker.postMessage({
442
+ code: 'FLUSH',
443
+ context: 'thread-stream',
444
+ id
445
+ })
446
+ } catch (err) {
447
+ stream[kImpl].flushCallbacks.delete(id)
448
+ destroy(stream, err)
449
+ process.nextTick(cb, err)
450
+ }
451
+ }
452
+
453
+ function failPendingFlushCallbacks (stream, err) {
454
+ const callbacks = stream[kImpl].flushCallbacks
455
+ if (callbacks.size === 0) {
456
+ return
457
+ }
458
+
459
+ const flushErr = err || new Error('the worker has exited')
460
+
461
+ for (const cb of callbacks.values()) {
462
+ process.nextTick(cb, flushErr)
463
+ }
464
+ callbacks.clear()
465
+ }
466
+
369
467
  function error (stream, err) {
370
468
  setImmediate(() => {
371
469
  stream.emit('error', err)
@@ -377,6 +475,7 @@ function destroy (stream, err) {
377
475
  return
378
476
  }
379
477
  stream[kImpl].destroyed = true
478
+ failPendingFlushCallbacks(stream, err)
380
479
 
381
480
  if (err) {
382
481
  stream[kImpl].errored = err
@@ -12,6 +12,8 @@ const {
12
12
  } = workerData
13
13
 
14
14
  let destination
15
+ const flushQueue = []
16
+ let flushing = false
15
17
 
16
18
  const state = new Int32Array(stateBuf)
17
19
  const data = Buffer.from(dataBuf)
@@ -19,6 +21,101 @@ const data = Buffer.from(dataBuf)
19
21
  // Keep the event loop alive - Atomics.waitAsync promises don't prevent worker exit
20
22
  const keepAlive = setInterval(() => {}, 60 * 60 * 1000)
21
23
 
24
+ function onParentPortMessage (msg) {
25
+ if (!msg || msg.code !== 'FLUSH' || msg.context !== 'thread-stream') {
26
+ return
27
+ }
28
+
29
+ flushQueue.push(msg.id)
30
+ processFlushQueue()
31
+ }
32
+
33
+ function processFlushQueue () {
34
+ if (flushing || !destination) {
35
+ return
36
+ }
37
+
38
+ const id = flushQueue.shift()
39
+ if (id === undefined) {
40
+ return
41
+ }
42
+
43
+ flushing = true
44
+ flushDestination((err) => {
45
+ flushing = false
46
+
47
+ if (err) {
48
+ parentPort.postMessage({
49
+ code: 'ERROR',
50
+ err
51
+ })
52
+ return
53
+ }
54
+
55
+ parentPort.postMessage({
56
+ code: 'FLUSHED',
57
+ context: 'thread-stream',
58
+ id
59
+ })
60
+
61
+ processFlushQueue()
62
+ })
63
+ }
64
+
65
+ function flushDestination (cb) {
66
+ if (typeof destination?.flush === 'function') {
67
+ if (destination.flush.length === 0) {
68
+ try {
69
+ const result = destination.flush()
70
+ if (result && typeof result.then === 'function') {
71
+ result.then(() => cb(), cb)
72
+ } else {
73
+ cb()
74
+ }
75
+ } catch (err) {
76
+ cb(err)
77
+ }
78
+ return
79
+ }
80
+
81
+ let done = false
82
+ const onDone = (err) => {
83
+ if (done) {
84
+ return
85
+ }
86
+ done = true
87
+ cb(err)
88
+ }
89
+
90
+ try {
91
+ const result = destination.flush(onDone)
92
+ if (result && typeof result.then === 'function') {
93
+ result.then(() => onDone(), onDone)
94
+ }
95
+ } catch (err) {
96
+ onDone(err)
97
+ }
98
+ return
99
+ }
100
+
101
+ if (typeof destination?.flushSync === 'function') {
102
+ try {
103
+ destination.flushSync()
104
+ cb()
105
+ } catch (err) {
106
+ cb(err)
107
+ }
108
+ return
109
+ }
110
+
111
+ if (destination?.writableNeedDrain && !destination?.writableEnded) {
112
+ destination.once('drain', cb)
113
+ return
114
+ }
115
+
116
+ cb()
117
+ }
118
+
22
119
  async function start () {
23
120
  let worker
24
121
  try {
@@ -93,12 +190,16 @@ async function start () {
93
190
  process.exit(0)
94
191
  })
95
192
  })
193
+
194
+ processFlushQueue()
96
195
  }
97
196
 
98
197
  // No .catch() handler,
99
198
  // in case there is an error it goes
100
199
  // to unhandledRejection
101
200
  start().then(function () {
201
+ parentPort.on('message', onParentPortMessage)
202
+
102
203
  parentPort.postMessage({
103
204
  code: 'READY'
104
205
  })
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Paolo Insogna and the real-require contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # real-require
2
+
3
+ Keep require and import consistent after bundling or transpiling.
4
+
5
+ ## Installation
6
+
7
+ Just run:
8
+
9
+ ```bash
10
+ npm install real-require
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ The package provides two drop-ins functions, `realRequire` and `realImport`,
16
+ which can be used in scenarios where tools like transpilers or bundlers change
17
+ the native `require` or `await import` calls.
18
+
19
+ The current `realRequire` functions only handles webpack at the moment, wrapping
20
+ the `__non_webpack__require__` implementation that webpack provides for the
21
+ final bundle.
22
+
23
+ ### Example
24
+
25
+ ```js
26
+ // After bundling, real-require will be embedded in the bundle
27
+ const { realImport, realRequire } = require('real-require')
28
+
29
+ /*
30
+ By using realRequire, at build time the module will not be embedded and at runtime it will try to load path from the local filesytem.
31
+ This is useful in situations where the build tool does not support skipping modules to embed.
32
+ */
33
+ const { join } = realRequire('path')
34
+
35
+ async function main() {
36
+ // Similarly, this make sure the import call is not modified by the build tools
37
+ const localFunction = await realImport('./source.js')
38
+
39
+ localFunction()
40
+ }
41
+
42
+ main().catch(console.error)
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ See [CONTRIBUTING.md](./CONTRIBUTING.md)
48
+
49
+ ## License
50
+
51
+ Copyright Paolo Insogna and real-require contributors 2021. Licensed under the [MIT License](http://www.apache.org/licenses/MIT).
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "real-require",
3
+ "version": "1.0.0",
4
+ "description": "Keep require and import consistent after bundling or transpiling",
5
+ "author": "Paolo Insogna <shogun@cowtech.it>",
6
+ "homepage": "https://github.com/pinojs/real-require",
7
+ "contributors": [
8
+ {
9
+ "name": "Paolo Insogna",
10
+ "url": "https://github.com/ShogunPanda"
11
+ }
12
+ ],
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/pinojs/real-require.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/pinojs/real-require/issues"
20
+ },
21
+ "main": "src/index.js",
22
+ "files": [
23
+ "src"
24
+ ],
25
+ "scripts": {
26
+ "lint": "eslint .",
27
+ "lint:fix": "eslint --fix .",
28
+ "test": "c8 --reporter=text --reporter=html borp 'test/*.test.js'",
29
+ "test:ci": "c8 --reporter=text --reporter=json --check-coverage --branches 90 --functions 90 --lines 90 --statements 90 borp 'test/*.test.js'",
30
+ "ci": "npm run lint && npm run test:ci"
31
+ },
32
+ "devDependencies": {
33
+ "borp": "^1.0.0",
34
+ "c8": "^8.0.0",
35
+ "eslint": "^9.39.4",
36
+ "neostandard": "^0.13.0"
37
+ }
38
+ }
@@ -0,0 +1,14 @@
1
+ /* eslint-disable no-new-func */
2
+ /* globals __non_webpack__require__ */
3
+
4
+ const realImport = new Function('modulePath', 'return import(modulePath)')
5
+
6
+ function realRequire (modulePath) {
7
+ if (typeof __non_webpack__require__ === 'function') {
8
+ return __non_webpack__require__(modulePath)
9
+ }
10
+
11
+ return require(modulePath)
12
+ }
13
+
14
+ module.exports = { realImport, realRequire }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thread-stream",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "A streaming way to send data to a Node.js Worker Thread",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -8,30 +8,28 @@
8
8
  "node": ">=20"
9
9
  },
10
10
  "dependencies": {
11
- "real-require": "^0.2.0"
11
+ "real-require": "^1.0.0"
12
12
  },
13
13
  "devDependencies": {
14
- "@types/node": "^22.0.0",
14
+ "@types/node": "^25.0.2",
15
15
  "@yao-pkg/pkg": "^6.0.0",
16
- "borp": "^0.21.0",
16
+ "borp": "^1.0.0",
17
17
  "desm": "^1.3.0",
18
18
  "eslint": "^9.39.1",
19
19
  "fastbench": "^1.0.1",
20
- "husky": "^9.0.6",
21
- "neostandard": "^0.12.2",
20
+ "neostandard": "^0.13.0",
22
21
  "pino-elasticsearch": "^8.0.0",
23
- "sonic-boom": "^4.0.1",
22
+ "sonic-boom": "^5.0.0",
24
23
  "ts-node": "^10.8.0",
25
24
  "typescript": "~5.7.3"
26
25
  },
27
26
  "scripts": {
28
27
  "build": "tsc --noEmit",
29
28
  "lint": "eslint",
30
- "test": "npm run lint && npm run build && npm run transpile && borp --pattern 'test/*.test.{js,mjs}'",
31
- "test:ci": "npm run lint && npm run transpile && borp --pattern 'test/*.test.{js,mjs}'",
32
- "test:yarn": "npm run transpile && borp --pattern 'test/*.test.js'",
33
- "transpile": "sh ./test/ts/transpile.sh",
34
- "prepare": "husky install"
29
+ "test": "npm run lint && npm run build && npm run transpile && borp --pattern \"test/*.test.{js,mjs}\"",
30
+ "test:ci": "npm run lint && npm run transpile && borp --pattern \"test/*.test.{js,mjs}\"",
31
+ "test:yarn": "npm run transpile && borp --pattern \"test/*.test.js\"",
32
+ "transpile": "sh ./test/ts/transpile.sh"
35
33
  },
36
34
  "repository": {
37
35
  "type": "git",
@@ -0,0 +1,68 @@
1
+ 'use strict'
2
+
3
+ const { EventEmitter } = require('events')
4
+ const { parentPort } = require('worker_threads')
5
+
6
+ function createDestination (mode) {
7
+ const destination = new EventEmitter()
8
+ destination.writableEnded = false
9
+ destination.writableNeedDrain = false
10
+
11
+ destination.write = function () {
12
+ if (mode === 'drain') {
13
+ destination.writableNeedDrain = true
14
+ setTimeout(() => {
15
+ destination.writableNeedDrain = false
16
+ parentPort.postMessage({
17
+ code: 'EVENT',
18
+ name: 'destination-drain'
19
+ })
20
+ destination.emit('drain')
21
+ }, 50)
22
+ }
23
+
24
+ return true
25
+ }
26
+
27
+ destination.end = function () {
28
+ destination.writableEnded = true
29
+ destination.emit('close')
30
+ }
31
+
32
+ if (mode === 'flush') {
33
+ destination.flush = function (cb) {
34
+ setTimeout(() => {
35
+ parentPort.postMessage({
36
+ code: 'EVENT',
37
+ name: 'destination-flushed'
38
+ })
39
+ cb()
40
+ }, 50)
41
+ }
42
+ }
43
+
44
+ if (mode === 'flush-sync') {
45
+ destination.flushSync = function () {
46
+ parentPort.postMessage({
47
+ code: 'EVENT',
48
+ name: 'destination-flush-sync'
49
+ })
50
+ }
51
+ }
52
+
53
+ if (mode === 'exit-on-flush') {
54
+ destination.flush = function (_cb) {
55
+ setTimeout(() => {
56
+ process.exit(0)
57
+ }, 20)
58
+ }
59
+ }
60
+
61
+ return destination
62
+ }
63
+
64
+ async function run (opts) {
65
+ return createDestination(opts.mode)
66
+ }
67
+
68
+ module.exports = run
@@ -0,0 +1,112 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const assert = require('node:assert')
5
+ const { once } = require('node:events')
6
+ const { join } = require('node:path')
7
+ const ThreadStream = require('..')
8
+
9
+ function createStream (mode) {
10
+ return new ThreadStream({
11
+ filename: join(__dirname, 'flush-worker.js'),
12
+ workerData: { mode },
13
+ sync: false
14
+ })
15
+ }
16
+
17
+ test('flush waits for worker destination.flush(cb)', async function () {
18
+ const stream = createStream('flush')
19
+ let flushed = false
20
+
21
+ stream.on('destination-flushed', () => {
22
+ flushed = true
23
+ })
24
+
25
+ assert.ok(stream.write('hello'))
26
+
27
+ await new Promise((resolve, reject) => {
28
+ stream.flush((err) => {
29
+ if (err) {
30
+ reject(err)
31
+ return
32
+ }
33
+ resolve()
34
+ })
35
+ })
36
+
37
+ assert.strictEqual(flushed, true)
38
+
39
+ const close = once(stream, 'close')
40
+ stream.end()
41
+ await close
42
+ })
43
+
44
+ test('flush falls back to destination.flushSync()', async function () {
45
+ const stream = createStream('flush-sync')
46
+ let called = false
47
+
48
+ stream.on('destination-flush-sync', () => {
49
+ called = true
50
+ })
51
+
52
+ assert.ok(stream.write('hello'))
53
+
54
+ await new Promise((resolve, reject) => {
55
+ stream.flush((err) => {
56
+ if (err) {
57
+ reject(err)
58
+ return
59
+ }
60
+ resolve()
61
+ })
62
+ })
63
+
64
+ assert.strictEqual(called, true)
65
+
66
+ const close = once(stream, 'close')
67
+ stream.end()
68
+ await close
69
+ })
70
+
71
+ test('flush waits for drain when destination has no flush API', async function () {
72
+ const stream = createStream('drain')
73
+ let drained = false
74
+
75
+ stream.on('destination-drain', () => {
76
+ drained = true
77
+ })
78
+
79
+ assert.ok(stream.write('hello'))
80
+
81
+ await new Promise((resolve, reject) => {
82
+ stream.flush((err) => {
83
+ if (err) {
84
+ reject(err)
85
+ return
86
+ }
87
+ resolve()
88
+ })
89
+ })
90
+
91
+ assert.strictEqual(drained, true)
92
+
93
+ const close = once(stream, 'close')
94
+ stream.end()
95
+ await close
96
+ })
97
+
98
+ test('pending flush callbacks fail when worker exits', async function () {
99
+ const stream = createStream('exit-on-flush')
100
+ const close = once(stream, 'close')
101
+
102
+ assert.ok(stream.write('hello'))
103
+
104
+ const err = await new Promise((resolve) => {
105
+ stream.flush(resolve)
106
+ })
107
+
108
+ assert.ok(err)
109
+ assert.strictEqual(err.message, 'the worker has exited')
110
+
111
+ await close
112
+ })