@jointhedots/gear 1.1.15 → 1.1.16

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.
@@ -38,7 +38,7 @@ function flush() {
38
38
  flushing = false;
39
39
  }
40
40
 
41
- var scope = typeof globalThis !== "undefined" ? globalThis : (typeof self !== "undefined" ? self : window);
41
+ var scope = typeof globalThis !== "undefined" ? globalThis : (typeof self !== "undefined" ? self : globalThis);
42
42
  var BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
43
43
 
44
44
  if (typeof BrowserMutationObserver === "function") {
@@ -227,7 +227,7 @@ const process = {
227
227
  config,
228
228
  uptime,
229
229
  }
230
- window.process = process
230
+ globalThis.process = process
231
231
 
232
232
  export {
233
233
  nextTick,
@@ -4,5 +4,214 @@
4
4
  import './process.js'
5
5
  import './buffer.js'
6
6
 
7
- // Make Buffer available globally
8
- globalThis.Buffer = Buffer
7
+ // Add Node.js-specific API to W3C ReadableStream
8
+ {
9
+ const proto = ReadableStream.prototype
10
+
11
+ // Start consuming the stream, emitting 'data'/'end'/'error'/'close' events
12
+ function _startReading(stream) {
13
+ if (stream._reading) return
14
+ stream._reading = true
15
+ stream._paused = false
16
+ const reader = stream.getReader()
17
+ const pump = () => reader.read().then(({ done, value }) => {
18
+ if (done) {
19
+ stream._reading = false
20
+ stream._emit('end')
21
+ stream._emit('close')
22
+ return
23
+ }
24
+ stream._emit('data', value)
25
+ if (!stream._paused) return pump()
26
+ stream._pump = pump
27
+ }).catch(err => {
28
+ stream._reading = false
29
+ stream._emit('error', err)
30
+ })
31
+ pump()
32
+ }
33
+
34
+ proto._emit = function (event, ...args) {
35
+ this._listeners?.[event]?.slice().forEach(fn => fn(...args))
36
+ }
37
+
38
+ proto.on = proto.addListener = function (event, fn) {
39
+ this._listeners ??= {}
40
+ ; (this._listeners[event] ??= []).push(fn)
41
+ if (event === 'data') _startReading(this)
42
+ return this
43
+ }
44
+
45
+ proto.once = function (event, fn) {
46
+ const wrapped = (...args) => { this.off(event, wrapped); fn(...args) }
47
+ return this.on(event, wrapped)
48
+ }
49
+
50
+ proto.off = proto.removeListener = function (event, fn) {
51
+ const list = this._listeners?.[event]
52
+ if (list) { const i = list.indexOf(fn); if (i >= 0) list.splice(i, 1) }
53
+ return this
54
+ }
55
+
56
+ proto.pipe = function (dest) {
57
+ this.on('data', chunk => dest.write?.(chunk))
58
+ this.once('end', () => dest.end?.())
59
+ this.once('error', err => dest.destroy?.(err))
60
+ return dest
61
+ }
62
+
63
+ proto.pause = function () {
64
+ this._paused = true
65
+ return this
66
+ }
67
+
68
+ proto.resume = function () {
69
+ this._paused = false
70
+ this._pump?.()
71
+ return this
72
+ }
73
+
74
+ proto.destroy = function (err) {
75
+ if (err) this._emit('error', err)
76
+ this._emit('close')
77
+ this.cancel(err).catch(() => { })
78
+ return this
79
+ }
80
+
81
+ proto.unpipe = function (dest) {
82
+ this._listeners = {}
83
+ return this
84
+ }
85
+ }
86
+
87
+ // Add Node.js-specific API to W3C WritableStream
88
+ {
89
+ const proto = WritableStream.prototype
90
+
91
+ proto._emit = function (event, ...args) {
92
+ this._listeners?.[event]?.slice().forEach(fn => fn(...args))
93
+ }
94
+
95
+ proto.on = proto.addListener = function (event, fn) {
96
+ this._listeners ??= {}
97
+ ; (this._listeners[event] ??= []).push(fn)
98
+ return this
99
+ }
100
+
101
+ proto.once = function (event, fn) {
102
+ const wrapped = (...args) => { this.off(event, wrapped); fn(...args) }
103
+ return this.on(event, wrapped)
104
+ }
105
+
106
+ proto.off = proto.removeListener = function (event, fn) {
107
+ const list = this._listeners?.[event]
108
+ if (list) { const i = list.indexOf(fn); if (i >= 0) list.splice(i, 1) }
109
+ return this
110
+ }
111
+
112
+ proto._getWriter = function () {
113
+ if (!this._writer) this._writer = this.getWriter()
114
+ return this._writer
115
+ }
116
+
117
+ proto.write = function (chunk, encoding, callback) {
118
+ if (typeof encoding === 'function') { callback = encoding; encoding = undefined }
119
+ const writer = this._getWriter()
120
+ writer.ready.then(() => writer.write(chunk)).then(
121
+ () => { this._emit('drain'); callback?.() },
122
+ err => { this._emit('error', err); callback?.(err) }
123
+ )
124
+ return true
125
+ }
126
+
127
+ proto.end = function (chunk, encoding, callback) {
128
+ if (typeof chunk === 'function') { callback = chunk; chunk = null }
129
+ else if (typeof encoding === 'function') { callback = encoding; encoding = null }
130
+ const writer = this._getWriter()
131
+ const finish = () => writer.close().then(
132
+ () => { this._emit('finish'); this._emit('close'); callback?.() },
133
+ err => { this._emit('error', err); callback?.(err) }
134
+ )
135
+ if (chunk != null) {
136
+ writer.ready.then(() => writer.write(chunk)).then(finish, finish)
137
+ } else {
138
+ finish()
139
+ }
140
+ return this
141
+ }
142
+
143
+ proto.destroy = function (err) {
144
+ const writer = this._getWriter()
145
+ if (err) {
146
+ writer.abort(err).catch(() => { })
147
+ this._emit('error', err)
148
+ } else {
149
+ writer.close().catch(() => { })
150
+ }
151
+ this._emit('close')
152
+ return this
153
+ }
154
+
155
+ proto.cork = function () { this._corked = (this._corked || 0) + 1 }
156
+ proto.uncork = function () { if (this._corked > 0) this._corked-- }
157
+
158
+ proto.setDefaultEncoding = function (encoding) {
159
+ this._defaultEncoding = encoding
160
+ return this
161
+ }
162
+ }
163
+
164
+ // Add Node.js-specific API to W3C TransformStream
165
+ {
166
+ const proto = TransformStream.prototype
167
+
168
+ proto._emit = function (event, ...args) {
169
+ this._listeners?.[event]?.slice().forEach(fn => fn(...args))
170
+ }
171
+
172
+ proto.on = proto.addListener = function (event, fn) {
173
+ this._listeners ??= {}
174
+ ; (this._listeners[event] ??= []).push(fn)
175
+ if (event === 'data') this.readable.on('data', chunk => this._emit('data', chunk))
176
+ return this
177
+ }
178
+
179
+ proto.once = function (event, fn) {
180
+ const wrapped = (...args) => { this.off(event, wrapped); fn(...args) }
181
+ return this.on(event, wrapped)
182
+ }
183
+
184
+ proto.off = proto.removeListener = function (event, fn) {
185
+ const list = this._listeners?.[event]
186
+ if (list) { const i = list.indexOf(fn); if (i >= 0) list.splice(i, 1) }
187
+ return this
188
+ }
189
+
190
+ proto.write = function (chunk, encoding, callback) {
191
+ return this.writable.write(chunk, encoding, callback)
192
+ }
193
+
194
+ proto.end = function (chunk, encoding, callback) {
195
+ return this.writable.end(chunk, encoding, callback)
196
+ }
197
+
198
+ proto.pipe = function (dest) {
199
+ return this.readable.pipe(dest)
200
+ }
201
+
202
+ proto.pause = function () {
203
+ this.readable.pause()
204
+ return this
205
+ }
206
+
207
+ proto.resume = function () {
208
+ this.readable.resume()
209
+ return this
210
+ }
211
+
212
+ proto.destroy = function (err) {
213
+ this.readable.destroy(err)
214
+ this.writable.destroy(err)
215
+ return this
216
+ }
217
+ }
@@ -21,7 +21,7 @@ function getEsbuildLogLevel(mode) {
21
21
  return "silent";
22
22
  }
23
23
  }
24
- export async function create_esbuild_context(task, devmode) {
24
+ async function create_esbuild_context(task, devmode, onReady) {
25
25
  const ws = task.target.workspace;
26
26
  // Define modules mapping - using @jspm/core polyfills (same as Vite)
27
27
  const jspmPolyfills = Path.resolve(PackageRootDir, "node_modules/@jspm/core/nodelibs/browser");
@@ -111,7 +111,7 @@ export async function create_esbuild_context(task, devmode) {
111
111
  ESModuleResolverPlugin(modules_mapping, tsconfig),
112
112
  ...task.plugins,
113
113
  StyleSheetPlugin(task),
114
- StoragePlugin(task),
114
+ StoragePlugin(task, onReady),
115
115
  ],
116
116
  loader: {
117
117
  '.jpg': 'file',
@@ -255,7 +255,7 @@ function hasTailwindConfig(workspacePath) {
255
255
  catch { }
256
256
  return false;
257
257
  }
258
- export function StoragePlugin(task) {
258
+ export function StoragePlugin(task, onReady) {
259
259
  return {
260
260
  name: "dipatch-files",
261
261
  setup: (build) => {
@@ -290,7 +290,11 @@ export function StoragePlugin(task) {
290
290
  task.target.store();
291
291
  const storeTime = (Date.now() - storeStart) / 1000;
292
292
  const buildTime = (Date.now() - buildStartTime) / 1000;
293
- task.log.info(`Build ES modules in ${result.outputFiles.length} file(s) (compile: ${buildTime.toFixed(2)}s, store: ${storeTime.toFixed(2)}s)`);
293
+ task.log.info(`Store ES graph in ${result.outputFiles.length} file(s) (compile: ${buildTime.toFixed(2)}s, store: ${storeTime.toFixed(2)}s)`);
294
+ }
295
+ if (onReady) {
296
+ onReady();
297
+ onReady = null;
294
298
  }
295
299
  return null;
296
300
  });
@@ -602,11 +606,14 @@ export class ESModulesTask extends BuildTask {
602
606
  await prev_ctx.dispose();
603
607
  }
604
608
  const { target } = this;
605
- this.context = await create_esbuild_context(this, target.devmode);
606
609
  if (target.watch) {
607
- await this.context.watch();
610
+ return new Promise(async (resolve, reject) => {
611
+ this.context = await create_esbuild_context(this, target.devmode, resolve);
612
+ await this.context.watch();
613
+ });
608
614
  }
609
615
  else {
616
+ this.context = await create_esbuild_context(this, target.devmode);
610
617
  await this.context.rebuild();
611
618
  await this.context.dispose();
612
619
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jointhedots/gear",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "jointhedots-gear": "esm/cli.js"