node-modules-tools 0.0.4 → 0.0.6

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.
@@ -0,0 +1,837 @@
1
+ import require$$0 from 'stream';
2
+ import require$$1 from 'string_decoder';
3
+ import require$$0$1 from 'events';
4
+
5
+ function getDefaultExportFromCjs (x) {
6
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
7
+ }
8
+
9
+ var Utf8Stream_1;
10
+ var hasRequiredUtf8Stream;
11
+
12
+ function requireUtf8Stream () {
13
+ if (hasRequiredUtf8Stream) return Utf8Stream_1;
14
+ hasRequiredUtf8Stream = 1;
15
+
16
+ const {Transform} = require$$0;
17
+ const {StringDecoder} = require$$1;
18
+
19
+ class Utf8Stream extends Transform {
20
+ constructor(options) {
21
+ super(Object.assign({}, options, {writableObjectMode: false}));
22
+ this._buffer = '';
23
+ }
24
+
25
+ _transform(chunk, encoding, callback) {
26
+ if (typeof chunk == 'string') {
27
+ this._transform = this._transformString;
28
+ } else {
29
+ this._stringDecoder = new StringDecoder();
30
+ this._transform = this._transformBuffer;
31
+ }
32
+ this._transform(chunk, encoding, callback);
33
+ }
34
+
35
+ _transformBuffer(chunk, _, callback) {
36
+ this._buffer += this._stringDecoder.write(chunk);
37
+ this._processBuffer(callback);
38
+ }
39
+
40
+ _transformString(chunk, _, callback) {
41
+ this._buffer += chunk.toString();
42
+ this._processBuffer(callback);
43
+ }
44
+
45
+ _processBuffer(callback) {
46
+ if (this._buffer) {
47
+ this.push(this._buffer, 'utf8');
48
+ this._buffer = '';
49
+ }
50
+ callback(null);
51
+ }
52
+
53
+ _flushInput() {
54
+ // meant to be called from _flush()
55
+ if (this._stringDecoder) {
56
+ this._buffer += this._stringDecoder.end();
57
+ }
58
+ }
59
+
60
+ _flush(callback) {
61
+ this._flushInput();
62
+ this._processBuffer(callback);
63
+ }
64
+ }
65
+
66
+ Utf8Stream_1 = Utf8Stream;
67
+ return Utf8Stream_1;
68
+ }
69
+
70
+ var Parser_1;
71
+ var hasRequiredParser;
72
+
73
+ function requireParser () {
74
+ if (hasRequiredParser) return Parser_1;
75
+ hasRequiredParser = 1;
76
+
77
+ const Utf8Stream = requireUtf8Stream();
78
+
79
+ const patterns = {
80
+ value1: /^(?:[\"\{\[\]\-\d]|true\b|false\b|null\b|\s{1,256})/,
81
+ string: /^(?:[^\x00-\x1f\"\\]{1,256}|\\[bfnrt\"\\\/]|\\u[\da-fA-F]{4}|\")/,
82
+ key1: /^(?:[\"\}]|\s{1,256})/,
83
+ colon: /^(?:\:|\s{1,256})/,
84
+ comma: /^(?:[\,\]\}]|\s{1,256})/,
85
+ ws: /^\s{1,256}/,
86
+ numberStart: /^\d/,
87
+ numberDigit: /^\d{0,256}/,
88
+ numberFraction: /^[\.eE]/,
89
+ numberExponent: /^[eE]/,
90
+ numberExpSign: /^[-+]/
91
+ };
92
+ const MAX_PATTERN_SIZE = 16;
93
+
94
+ let noSticky = true;
95
+ try {
96
+ new RegExp('.', 'y');
97
+ noSticky = false;
98
+ } catch (e) {
99
+ // suppress
100
+ }
101
+
102
+ !noSticky &&
103
+ Object.keys(patterns).forEach(key => {
104
+ let src = patterns[key].source.slice(1); // lop off ^
105
+ if (src.slice(0, 3) === '(?:' && src.slice(-1) === ')') {
106
+ src = src.slice(3, -1);
107
+ }
108
+ patterns[key] = new RegExp(src, 'y');
109
+ });
110
+
111
+ patterns.numberFracStart = patterns.numberExpStart = patterns.numberStart;
112
+ patterns.numberFracDigit = patterns.numberExpDigit = patterns.numberDigit;
113
+
114
+ const values = {true: true, false: false, null: null},
115
+ expected = {object: 'objectStop', array: 'arrayStop', '': 'done'};
116
+
117
+ // long hexadecimal codes: \uXXXX
118
+ const fromHex = s => String.fromCharCode(parseInt(s.slice(2), 16));
119
+
120
+ // short codes: \b \f \n \r \t \" \\ \/
121
+ const codes = {b: '\b', f: '\f', n: '\n', r: '\r', t: '\t', '"': '"', '\\': '\\', '/': '/'};
122
+
123
+ class Parser extends Utf8Stream {
124
+ static make(options) {
125
+ return new Parser(options);
126
+ }
127
+
128
+ constructor(options) {
129
+ super(Object.assign({}, options, {readableObjectMode: true}));
130
+
131
+ this._packKeys = this._packStrings = this._packNumbers = this._streamKeys = this._streamStrings = this._streamNumbers = true;
132
+ if (options) {
133
+ 'packValues' in options && (this._packKeys = this._packStrings = this._packNumbers = options.packValues);
134
+ 'packKeys' in options && (this._packKeys = options.packKeys);
135
+ 'packStrings' in options && (this._packStrings = options.packStrings);
136
+ 'packNumbers' in options && (this._packNumbers = options.packNumbers);
137
+ 'streamValues' in options && (this._streamKeys = this._streamStrings = this._streamNumbers = options.streamValues);
138
+ 'streamKeys' in options && (this._streamKeys = options.streamKeys);
139
+ 'streamStrings' in options && (this._streamStrings = options.streamStrings);
140
+ 'streamNumbers' in options && (this._streamNumbers = options.streamNumbers);
141
+ this._jsonStreaming = options.jsonStreaming;
142
+ }
143
+ !this._packKeys && (this._streamKeys = true);
144
+ !this._packStrings && (this._streamStrings = true);
145
+ !this._packNumbers && (this._streamNumbers = true);
146
+
147
+ this._done = false;
148
+ this._expect = this._jsonStreaming ? 'done' : 'value';
149
+ this._stack = [];
150
+ this._parent = '';
151
+ this._open_number = false;
152
+ this._accumulator = '';
153
+ }
154
+
155
+ _flush(callback) {
156
+ this._done = true;
157
+ super._flush(error => {
158
+ if (error) return callback(error);
159
+ if (this._open_number) {
160
+ if (this._streamNumbers) {
161
+ this.push({name: 'endNumber'});
162
+ }
163
+ this._open_number = false;
164
+ if (this._packNumbers) {
165
+ this.push({name: 'numberValue', value: this._accumulator});
166
+ this._accumulator = '';
167
+ }
168
+ }
169
+ callback(null);
170
+ });
171
+ }
172
+
173
+ _processBuffer(callback) {
174
+ let match,
175
+ value,
176
+ index = 0;
177
+ main: for (;;) {
178
+ switch (this._expect) {
179
+ case 'value1':
180
+ case 'value':
181
+ patterns.value1.lastIndex = index;
182
+ match = patterns.value1.exec(this._buffer);
183
+ if (!match) {
184
+ if (this._done || index + MAX_PATTERN_SIZE < this._buffer.length) {
185
+ if (index < this._buffer.length) return callback(new Error('Parser cannot parse input: expected a value'));
186
+ return callback(new Error('Parser has expected a value'));
187
+ }
188
+ break main; // wait for more input
189
+ }
190
+ value = match[0];
191
+ switch (value) {
192
+ case '"':
193
+ this._streamStrings && this.push({name: 'startString'});
194
+ this._expect = 'string';
195
+ break;
196
+ case '{':
197
+ this.push({name: 'startObject'});
198
+ this._stack.push(this._parent);
199
+ this._parent = 'object';
200
+ this._expect = 'key1';
201
+ break;
202
+ case '[':
203
+ this.push({name: 'startArray'});
204
+ this._stack.push(this._parent);
205
+ this._parent = 'array';
206
+ this._expect = 'value1';
207
+ break;
208
+ case ']':
209
+ if (this._expect !== 'value1') return callback(new Error("Parser cannot parse input: unexpected token ']'"));
210
+ if (this._open_number) {
211
+ this._streamNumbers && this.push({name: 'endNumber'});
212
+ this._open_number = false;
213
+ if (this._packNumbers) {
214
+ this.push({name: 'numberValue', value: this._accumulator});
215
+ this._accumulator = '';
216
+ }
217
+ }
218
+ this.push({name: 'endArray'});
219
+ this._parent = this._stack.pop();
220
+ this._expect = expected[this._parent];
221
+ break;
222
+ case '-':
223
+ this._open_number = true;
224
+ if (this._streamNumbers) {
225
+ this.push({name: 'startNumber'});
226
+ this.push({name: 'numberChunk', value: '-'});
227
+ }
228
+ this._packNumbers && (this._accumulator = '-');
229
+ this._expect = 'numberStart';
230
+ break;
231
+ case '0':
232
+ this._open_number = true;
233
+ if (this._streamNumbers) {
234
+ this.push({name: 'startNumber'});
235
+ this.push({name: 'numberChunk', value: '0'});
236
+ }
237
+ this._packNumbers && (this._accumulator = '0');
238
+ this._expect = 'numberFraction';
239
+ break;
240
+ case '1':
241
+ case '2':
242
+ case '3':
243
+ case '4':
244
+ case '5':
245
+ case '6':
246
+ case '7':
247
+ case '8':
248
+ case '9':
249
+ this._open_number = true;
250
+ if (this._streamNumbers) {
251
+ this.push({name: 'startNumber'});
252
+ this.push({name: 'numberChunk', value: value});
253
+ }
254
+ this._packNumbers && (this._accumulator = value);
255
+ this._expect = 'numberDigit';
256
+ break;
257
+ case 'true':
258
+ case 'false':
259
+ case 'null':
260
+ if (this._buffer.length - index === value.length && !this._done) break main; // wait for more input
261
+ this.push({name: value + 'Value', value: values[value]});
262
+ this._expect = expected[this._parent];
263
+ break;
264
+ // default: // ws
265
+ }
266
+ if (noSticky) {
267
+ this._buffer = this._buffer.slice(value.length);
268
+ } else {
269
+ index += value.length;
270
+ }
271
+ break;
272
+ case 'keyVal':
273
+ case 'string':
274
+ patterns.string.lastIndex = index;
275
+ match = patterns.string.exec(this._buffer);
276
+ if (!match) {
277
+ if (index < this._buffer.length && (this._done || this._buffer.length - index >= 6))
278
+ return callback(new Error('Parser cannot parse input: escaped characters'));
279
+ if (this._done) return callback(new Error('Parser has expected a string value'));
280
+ break main; // wait for more input
281
+ }
282
+ value = match[0];
283
+ if (value === '"') {
284
+ if (this._expect === 'keyVal') {
285
+ this._streamKeys && this.push({name: 'endKey'});
286
+ if (this._packKeys) {
287
+ this.push({name: 'keyValue', value: this._accumulator});
288
+ this._accumulator = '';
289
+ }
290
+ this._expect = 'colon';
291
+ } else {
292
+ this._streamStrings && this.push({name: 'endString'});
293
+ if (this._packStrings) {
294
+ this.push({name: 'stringValue', value: this._accumulator});
295
+ this._accumulator = '';
296
+ }
297
+ this._expect = expected[this._parent];
298
+ }
299
+ } else if (value.length > 1 && value.charAt(0) === '\\') {
300
+ const t = value.length == 2 ? codes[value.charAt(1)] : fromHex(value);
301
+ if (this._expect === 'keyVal' ? this._streamKeys : this._streamStrings) {
302
+ this.push({name: 'stringChunk', value: t});
303
+ }
304
+ if (this._expect === 'keyVal' ? this._packKeys : this._packStrings) {
305
+ this._accumulator += t;
306
+ }
307
+ } else {
308
+ if (this._expect === 'keyVal' ? this._streamKeys : this._streamStrings) {
309
+ this.push({name: 'stringChunk', value: value});
310
+ }
311
+ if (this._expect === 'keyVal' ? this._packKeys : this._packStrings) {
312
+ this._accumulator += value;
313
+ }
314
+ }
315
+ if (noSticky) {
316
+ this._buffer = this._buffer.slice(value.length);
317
+ } else {
318
+ index += value.length;
319
+ }
320
+ break;
321
+ case 'key1':
322
+ case 'key':
323
+ patterns.key1.lastIndex = index;
324
+ match = patterns.key1.exec(this._buffer);
325
+ if (!match) {
326
+ if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected an object key'));
327
+ break main; // wait for more input
328
+ }
329
+ value = match[0];
330
+ if (value === '"') {
331
+ this._streamKeys && this.push({name: 'startKey'});
332
+ this._expect = 'keyVal';
333
+ } else if (value === '}') {
334
+ if (this._expect !== 'key1') return callback(new Error("Parser cannot parse input: unexpected token '}'"));
335
+ this.push({name: 'endObject'});
336
+ this._parent = this._stack.pop();
337
+ this._expect = expected[this._parent];
338
+ }
339
+ if (noSticky) {
340
+ this._buffer = this._buffer.slice(value.length);
341
+ } else {
342
+ index += value.length;
343
+ }
344
+ break;
345
+ case 'colon':
346
+ patterns.colon.lastIndex = index;
347
+ match = patterns.colon.exec(this._buffer);
348
+ if (!match) {
349
+ if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected ':'"));
350
+ break main; // wait for more input
351
+ }
352
+ value = match[0];
353
+ value === ':' && (this._expect = 'value');
354
+ if (noSticky) {
355
+ this._buffer = this._buffer.slice(value.length);
356
+ } else {
357
+ index += value.length;
358
+ }
359
+ break;
360
+ case 'arrayStop':
361
+ case 'objectStop':
362
+ patterns.comma.lastIndex = index;
363
+ match = patterns.comma.exec(this._buffer);
364
+ if (!match) {
365
+ if (index < this._buffer.length || this._done) return callback(new Error("Parser cannot parse input: expected ','"));
366
+ break main; // wait for more input
367
+ }
368
+ if (this._open_number) {
369
+ this._streamNumbers && this.push({name: 'endNumber'});
370
+ this._open_number = false;
371
+ if (this._packNumbers) {
372
+ this.push({name: 'numberValue', value: this._accumulator});
373
+ this._accumulator = '';
374
+ }
375
+ }
376
+ value = match[0];
377
+ if (value === ',') {
378
+ this._expect = this._expect === 'arrayStop' ? 'value' : 'key';
379
+ } else if (value === '}' || value === ']') {
380
+ if (value === '}' ? this._expect === 'arrayStop' : this._expect !== 'arrayStop') {
381
+ return callback(new Error("Parser cannot parse input: expected '" + (this._expect === 'arrayStop' ? ']' : '}') + "'"));
382
+ }
383
+ this.push({name: value === '}' ? 'endObject' : 'endArray'});
384
+ this._parent = this._stack.pop();
385
+ this._expect = expected[this._parent];
386
+ }
387
+ if (noSticky) {
388
+ this._buffer = this._buffer.slice(value.length);
389
+ } else {
390
+ index += value.length;
391
+ }
392
+ break;
393
+ // number chunks
394
+ case 'numberStart': // [0-9]
395
+ patterns.numberStart.lastIndex = index;
396
+ match = patterns.numberStart.exec(this._buffer);
397
+ if (!match) {
398
+ if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected a starting digit'));
399
+ break main; // wait for more input
400
+ }
401
+ value = match[0];
402
+ this._streamNumbers && this.push({name: 'numberChunk', value: value});
403
+ this._packNumbers && (this._accumulator += value);
404
+ this._expect = value === '0' ? 'numberFraction' : 'numberDigit';
405
+ if (noSticky) {
406
+ this._buffer = this._buffer.slice(value.length);
407
+ } else {
408
+ index += value.length;
409
+ }
410
+ break;
411
+ case 'numberDigit': // [0-9]*
412
+ patterns.numberDigit.lastIndex = index;
413
+ match = patterns.numberDigit.exec(this._buffer);
414
+ if (!match) {
415
+ if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected a digit'));
416
+ break main; // wait for more input
417
+ }
418
+ value = match[0];
419
+ if (value) {
420
+ this._streamNumbers && this.push({name: 'numberChunk', value: value});
421
+ this._packNumbers && (this._accumulator += value);
422
+ if (noSticky) {
423
+ this._buffer = this._buffer.slice(value.length);
424
+ } else {
425
+ index += value.length;
426
+ }
427
+ } else {
428
+ if (index < this._buffer.length) {
429
+ this._expect = 'numberFraction';
430
+ break;
431
+ }
432
+ if (this._done) {
433
+ this._expect = expected[this._parent];
434
+ break;
435
+ }
436
+ break main; // wait for more input
437
+ }
438
+ break;
439
+ case 'numberFraction': // [\.eE]?
440
+ patterns.numberFraction.lastIndex = index;
441
+ match = patterns.numberFraction.exec(this._buffer);
442
+ if (!match) {
443
+ if (index < this._buffer.length || this._done) {
444
+ this._expect = expected[this._parent];
445
+ break;
446
+ }
447
+ break main; // wait for more input
448
+ }
449
+ value = match[0];
450
+ this._streamNumbers && this.push({name: 'numberChunk', value: value});
451
+ this._packNumbers && (this._accumulator += value);
452
+ this._expect = value === '.' ? 'numberFracStart' : 'numberExpSign';
453
+ if (noSticky) {
454
+ this._buffer = this._buffer.slice(value.length);
455
+ } else {
456
+ index += value.length;
457
+ }
458
+ break;
459
+ case 'numberFracStart': // [0-9]
460
+ patterns.numberFracStart.lastIndex = index;
461
+ match = patterns.numberFracStart.exec(this._buffer);
462
+ if (!match) {
463
+ if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected a fractional part of a number'));
464
+ break main; // wait for more input
465
+ }
466
+ value = match[0];
467
+ this._streamNumbers && this.push({name: 'numberChunk', value: value});
468
+ this._packNumbers && (this._accumulator += value);
469
+ this._expect = 'numberFracDigit';
470
+ if (noSticky) {
471
+ this._buffer = this._buffer.slice(value.length);
472
+ } else {
473
+ index += value.length;
474
+ }
475
+ break;
476
+ case 'numberFracDigit': // [0-9]*
477
+ patterns.numberFracDigit.lastIndex = index;
478
+ match = patterns.numberFracDigit.exec(this._buffer);
479
+ value = match[0];
480
+ if (value) {
481
+ this._streamNumbers && this.push({name: 'numberChunk', value: value});
482
+ this._packNumbers && (this._accumulator += value);
483
+ if (noSticky) {
484
+ this._buffer = this._buffer.slice(value.length);
485
+ } else {
486
+ index += value.length;
487
+ }
488
+ } else {
489
+ if (index < this._buffer.length) {
490
+ this._expect = 'numberExponent';
491
+ break;
492
+ }
493
+ if (this._done) {
494
+ this._expect = expected[this._parent];
495
+ break;
496
+ }
497
+ break main; // wait for more input
498
+ }
499
+ break;
500
+ case 'numberExponent': // [eE]?
501
+ patterns.numberExponent.lastIndex = index;
502
+ match = patterns.numberExponent.exec(this._buffer);
503
+ if (!match) {
504
+ if (index < this._buffer.length) {
505
+ this._expect = expected[this._parent];
506
+ break;
507
+ }
508
+ if (this._done) {
509
+ this._expect = 'done';
510
+ break;
511
+ }
512
+ break main; // wait for more input
513
+ }
514
+ value = match[0];
515
+ this._streamNumbers && this.push({name: 'numberChunk', value: value});
516
+ this._packNumbers && (this._accumulator += value);
517
+ this._expect = 'numberExpSign';
518
+ if (noSticky) {
519
+ this._buffer = this._buffer.slice(value.length);
520
+ } else {
521
+ index += value.length;
522
+ }
523
+ break;
524
+ case 'numberExpSign': // [-+]?
525
+ patterns.numberExpSign.lastIndex = index;
526
+ match = patterns.numberExpSign.exec(this._buffer);
527
+ if (!match) {
528
+ if (index < this._buffer.length) {
529
+ this._expect = 'numberExpStart';
530
+ break;
531
+ }
532
+ if (this._done) return callback(new Error('Parser has expected an exponent value of a number'));
533
+ break main; // wait for more input
534
+ }
535
+ value = match[0];
536
+ this._streamNumbers && this.push({name: 'numberChunk', value: value});
537
+ this._packNumbers && (this._accumulator += value);
538
+ this._expect = 'numberExpStart';
539
+ if (noSticky) {
540
+ this._buffer = this._buffer.slice(value.length);
541
+ } else {
542
+ index += value.length;
543
+ }
544
+ break;
545
+ case 'numberExpStart': // [0-9]
546
+ patterns.numberExpStart.lastIndex = index;
547
+ match = patterns.numberExpStart.exec(this._buffer);
548
+ if (!match) {
549
+ if (index < this._buffer.length || this._done) return callback(new Error('Parser cannot parse input: expected an exponent part of a number'));
550
+ break main; // wait for more input
551
+ }
552
+ value = match[0];
553
+ this._streamNumbers && this.push({name: 'numberChunk', value: value});
554
+ this._packNumbers && (this._accumulator += value);
555
+ this._expect = 'numberExpDigit';
556
+ if (noSticky) {
557
+ this._buffer = this._buffer.slice(value.length);
558
+ } else {
559
+ index += value.length;
560
+ }
561
+ break;
562
+ case 'numberExpDigit': // [0-9]*
563
+ patterns.numberExpDigit.lastIndex = index;
564
+ match = patterns.numberExpDigit.exec(this._buffer);
565
+ value = match[0];
566
+ if (value) {
567
+ this._streamNumbers && this.push({name: 'numberChunk', value: value});
568
+ this._packNumbers && (this._accumulator += value);
569
+ if (noSticky) {
570
+ this._buffer = this._buffer.slice(value.length);
571
+ } else {
572
+ index += value.length;
573
+ }
574
+ } else {
575
+ if (index < this._buffer.length || this._done) {
576
+ this._expect = expected[this._parent];
577
+ break;
578
+ }
579
+ break main; // wait for more input
580
+ }
581
+ break;
582
+ case 'done':
583
+ patterns.ws.lastIndex = index;
584
+ match = patterns.ws.exec(this._buffer);
585
+ if (!match) {
586
+ if (index < this._buffer.length) {
587
+ if (this._jsonStreaming) {
588
+ this._expect = 'value';
589
+ break;
590
+ }
591
+ return callback(new Error('Parser cannot parse input: unexpected characters'));
592
+ }
593
+ break main; // wait for more input
594
+ }
595
+ value = match[0];
596
+ if (this._open_number) {
597
+ this._streamNumbers && this.push({name: 'endNumber'});
598
+ this._open_number = false;
599
+ if (this._packNumbers) {
600
+ this.push({name: 'numberValue', value: this._accumulator});
601
+ this._accumulator = '';
602
+ }
603
+ }
604
+ if (noSticky) {
605
+ this._buffer = this._buffer.slice(value.length);
606
+ } else {
607
+ index += value.length;
608
+ }
609
+ break;
610
+ }
611
+ }
612
+ !noSticky && (this._buffer = this._buffer.slice(index));
613
+ callback(null);
614
+ }
615
+ }
616
+ Parser.parser = Parser.make;
617
+ Parser.make.Constructor = Parser;
618
+
619
+ Parser_1 = Parser;
620
+ return Parser_1;
621
+ }
622
+
623
+ var emit_1;
624
+ var hasRequiredEmit;
625
+
626
+ function requireEmit () {
627
+ if (hasRequiredEmit) return emit_1;
628
+ hasRequiredEmit = 1;
629
+
630
+ const emit = stream => stream.on('data', item => stream.emit(item.name, item.value));
631
+
632
+ emit_1 = emit;
633
+ return emit_1;
634
+ }
635
+
636
+ var streamJson;
637
+ var hasRequiredStreamJson;
638
+
639
+ function requireStreamJson () {
640
+ if (hasRequiredStreamJson) return streamJson;
641
+ hasRequiredStreamJson = 1;
642
+
643
+ const Parser = requireParser();
644
+ const emit = requireEmit();
645
+
646
+ const make = options => emit(new Parser(options));
647
+
648
+ make.Parser = Parser;
649
+ make.parser = Parser.parser;
650
+
651
+ streamJson = make;
652
+ return streamJson;
653
+ }
654
+
655
+ var streamJsonExports = requireStreamJson();
656
+ const StreamJSON = /*@__PURE__*/getDefaultExportFromCjs(streamJsonExports);
657
+
658
+ var Assembler_1;
659
+ var hasRequiredAssembler;
660
+
661
+ function requireAssembler () {
662
+ if (hasRequiredAssembler) return Assembler_1;
663
+ hasRequiredAssembler = 1;
664
+
665
+ const EventEmitter = require$$0$1;
666
+
667
+ const startObject = Ctr =>
668
+ function () {
669
+ if (this.done) {
670
+ this.done = false;
671
+ } else {
672
+ this.stack.push(this.current, this.key);
673
+ }
674
+ this.current = new Ctr();
675
+ this.key = null;
676
+ };
677
+
678
+ class Assembler extends EventEmitter {
679
+ static connectTo(stream, options) {
680
+ return new Assembler(options).connectTo(stream);
681
+ }
682
+
683
+ constructor(options) {
684
+ super();
685
+ this.stack = [];
686
+ this.current = this.key = null;
687
+ this.done = true;
688
+ if (options) {
689
+ this.reviver = typeof options.reviver == 'function' && options.reviver;
690
+ if (this.reviver) {
691
+ this.stringValue = this._saveValue = this._saveValueWithReviver;
692
+ }
693
+ if (options.numberAsString) {
694
+ this.numberValue = this.stringValue;
695
+ }
696
+ }
697
+ }
698
+
699
+ connectTo(stream) {
700
+ stream.on('data', chunk => {
701
+ if (this[chunk.name]) {
702
+ this[chunk.name](chunk.value);
703
+ if (this.done) this.emit('done', this);
704
+ }
705
+ });
706
+ return this;
707
+ }
708
+
709
+ get depth() {
710
+ return (this.stack.length >> 1) + (this.done ? 0 : 1);
711
+ }
712
+
713
+ get path() {
714
+ const path = [];
715
+ for (let i = 0; i < this.stack.length; i += 2) {
716
+ const key = this.stack[i + 1];
717
+ path.push(key === null ? this.stack[i].length : key);
718
+ }
719
+ return path;
720
+ }
721
+
722
+ dropToLevel(level) {
723
+ if (level < this.depth) {
724
+ if (level) {
725
+ const index = (level - 1) << 1;
726
+ this.current = this.stack[index];
727
+ this.key = this.stack[index + 1];
728
+ this.stack.splice(index);
729
+ } else {
730
+ this.stack = [];
731
+ this.current = this.key = null;
732
+ this.done = true;
733
+ }
734
+ }
735
+ return this;
736
+ }
737
+
738
+ consume(chunk) {
739
+ this[chunk.name] && this[chunk.name](chunk.value);
740
+ return this;
741
+ }
742
+
743
+ keyValue(value) {
744
+ this.key = value;
745
+ }
746
+
747
+ //stringValue() - aliased below to _saveValue()
748
+
749
+ numberValue(value) {
750
+ this._saveValue(parseFloat(value));
751
+ }
752
+ nullValue() {
753
+ this._saveValue(null);
754
+ }
755
+ trueValue() {
756
+ this._saveValue(true);
757
+ }
758
+ falseValue() {
759
+ this._saveValue(false);
760
+ }
761
+
762
+ //startObject() - assigned below
763
+
764
+ endObject() {
765
+ if (this.stack.length) {
766
+ const value = this.current;
767
+ this.key = this.stack.pop();
768
+ this.current = this.stack.pop();
769
+ this._saveValue(value);
770
+ } else {
771
+ this.done = true;
772
+ }
773
+ }
774
+
775
+ //startArray() - assigned below
776
+ //endArray() - aliased below to endObject()
777
+
778
+ _saveValue(value) {
779
+ if (this.done) {
780
+ this.current = value;
781
+ } else {
782
+ if (this.current instanceof Array) {
783
+ this.current.push(value);
784
+ } else {
785
+ this.current[this.key] = value;
786
+ this.key = null;
787
+ }
788
+ }
789
+ }
790
+ _saveValueWithReviver(value) {
791
+ if (this.done) {
792
+ this.current = this.reviver('', value);
793
+ } else {
794
+ if (this.current instanceof Array) {
795
+ value = this.reviver('' + this.current.length, value);
796
+ this.current.push(value);
797
+ if (value === undefined) {
798
+ delete this.current[this.current.length - 1];
799
+ }
800
+ } else {
801
+ value = this.reviver(this.key, value);
802
+ if (value !== undefined) {
803
+ this.current[this.key] = value;
804
+ }
805
+ this.key = null;
806
+ }
807
+ }
808
+ }
809
+ }
810
+
811
+ Assembler.prototype.stringValue = Assembler.prototype._saveValue;
812
+ Assembler.prototype.startObject = startObject(Object);
813
+ Assembler.prototype.startArray = startObject(Array);
814
+ Assembler.prototype.endArray = Assembler.prototype.endObject;
815
+
816
+ Assembler_1 = Assembler;
817
+ return Assembler_1;
818
+ }
819
+
820
+ var AssemblerExports = requireAssembler();
821
+ const Assembler = /*@__PURE__*/getDefaultExportFromCjs(AssemblerExports);
822
+
823
+ function parseJsonStream(stream) {
824
+ const assembler = new Assembler();
825
+ const parser = StreamJSON.parser();
826
+ return new Promise((resolve) => {
827
+ parser.on("data", (chunk) => {
828
+ assembler[chunk.name]?.(chunk.value);
829
+ });
830
+ stream.pipe(parser);
831
+ parser.on("end", () => {
832
+ resolve(assembler.current);
833
+ });
834
+ });
835
+ }
836
+
837
+ export { parseJsonStream };
@@ -29,9 +29,14 @@ async function getDependenciesTree(options) {
29
29
  const args = ["ls", "--json", "--no-optional", "--depth", String(options.depth)];
30
30
  if (options.monorepo)
31
31
  args.push("--recursive");
32
- const raw = await x("pnpm", args, { throwOnError: true, nodeOptions: { cwd: options.cwd } });
33
- const tree = JSON.parse(raw.stdout);
34
- return tree;
32
+ const process = x("pnpm", args, {
33
+ throwOnError: true,
34
+ nodeOptions: {
35
+ stdio: "pipe",
36
+ cwd: options.cwd
37
+ }
38
+ });
39
+ return await import('./json-parse-stream.mjs').then((r) => r.parseJsonStream(process.process.stdout));
35
40
  }
36
41
  async function listPackageDependencies(options) {
37
42
  const root = await resolveRoot(options) || options.cwd;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-modules-tools",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "description": "Tools for inspecting node_modules",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -38,9 +38,11 @@
38
38
  "tinyexec": "^0.3.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@pnpm/list": "^1000.0.6",
41
+ "@pnpm/list": "^1000.0.7",
42
42
  "@pnpm/types": "^1000.1.1",
43
+ "@types/stream-json": "^1.7.8",
43
44
  "pkg-types": "^1.3.1",
45
+ "stream-json": "^1.9.1",
44
46
  "unbuild": "^3.3.1"
45
47
  },
46
48
  "scripts": {