storybook 10.2.0-alpha.1 → 10.2.0-alpha.10
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/dist/_browser-chunks/{Color-TNPFN3FC.js → Color-XESOIGZP.js} +9 -568
- package/dist/_browser-chunks/{WithTooltip-IO6J4KBT.js → WithTooltip-65CFNBJE.js} +70 -70
- package/dist/_browser-chunks/{chunk-45UGUKRX.js → chunk-242VQQM5.js} +1 -1
- package/dist/_browser-chunks/{chunk-JP7NCOJX.js → chunk-3LY4VQVK.js} +1 -1
- package/dist/_browser-chunks/{chunk-VYJQ7RU5.js → chunk-G4M6MXF4.js} +31 -27
- package/dist/_browser-chunks/{chunk-BRX2HXH7.js → chunk-IH6QJILI.js} +1 -1
- package/dist/_browser-chunks/{chunk-AS2HQEYC.js → chunk-IWQGIXJS.js} +1 -1
- package/dist/_browser-chunks/{chunk-3IAH5M2U.js → chunk-IYCKG66Y.js} +5 -5
- package/dist/_browser-chunks/{chunk-UD6FQLAF.js → chunk-JK6U3MQW.js} +3 -3
- package/dist/_browser-chunks/{chunk-FQ7SLVLR.js → chunk-JVRDBUUP.js} +20 -1
- package/dist/_browser-chunks/{chunk-GFLS4VP3.js → chunk-LCHBOIHN.js} +6 -6
- package/dist/_browser-chunks/{chunk-CHUV5WSW.js → chunk-LE2LTDW3.js} +1 -1
- package/dist/_browser-chunks/{chunk-IPA5A322.js → chunk-MEXTPDJG.js} +1 -1
- package/dist/_browser-chunks/{chunk-XJNX76GA.js → chunk-NQJGOFZV.js} +4 -4
- package/dist/_browser-chunks/chunk-NZMVUW5T.js +7 -0
- package/dist/_browser-chunks/{chunk-2XZMBGTA.js → chunk-POMIZRJL.js} +3 -3
- package/dist/_browser-chunks/{chunk-RP5RXKFU.js → chunk-Q5RYDXT3.js} +38 -30
- package/dist/_browser-chunks/{chunk-SS2NHR7W.js → chunk-RBABWY22.js} +18 -18
- package/dist/_browser-chunks/{chunk-AXG2BOBL.js → chunk-S6TK43XQ.js} +10 -10
- package/dist/_browser-chunks/{chunk-AIOS4NGK.js → chunk-SWJP5COI.js} +11 -11
- package/dist/_browser-chunks/{chunk-H6XK3RSC.js → chunk-UAYGIC3L.js} +6 -6
- package/dist/_browser-chunks/{chunk-YKE5S47A.js → chunk-V2VKKSMQ.js} +18 -18
- package/dist/_browser-chunks/{chunk-GFY5R5EY.js → chunk-V5NV5R37.js} +1 -1
- package/dist/_browser-chunks/chunk-VIJ7SQRO.js +568 -0
- package/dist/_browser-chunks/{chunk-3OXGAGBE.js → chunk-XLJZ7AOP.js} +14 -14
- package/dist/_browser-chunks/{chunk-P4F4UVXX.js → chunk-YKABRMAI.js} +15 -15
- package/dist/_browser-chunks/{chunk-WJYERY3R.js → chunk-ZCFV7BZB.js} +2 -2
- package/dist/_browser-chunks/{formatter-QJ4M4OGQ.js → formatter-EIJCOSYU.js} +2 -2
- package/dist/_browser-chunks/{syntaxhighlighter-IQDEPFLK.js → syntaxhighlighter-ED5Y7EFY.js} +119 -119
- package/dist/_node-chunks/{builder-manager-LXL5N6M5.js → builder-manager-IL56SHZF.js} +23 -22
- package/dist/_node-chunks/camelcase-P3NIWBZX.js +62 -0
- package/dist/_node-chunks/{chunk-SR5ZYD7K.js → chunk-BP66TAYC.js} +8 -8
- package/dist/_node-chunks/{chunk-R3WYNAT5.js → chunk-D3YJHXPC.js} +6 -6
- package/dist/_node-chunks/{chunk-5GNBLJKS.js → chunk-E2KSZELU.js} +8 -8
- package/dist/_node-chunks/{chunk-KXDU466E.js → chunk-EKU7ASGO.js} +31 -31
- package/dist/_node-chunks/chunk-GLYH3TSV.js +61 -0
- package/dist/_node-chunks/{chunk-GOOBGRAV.js → chunk-JXL37VS7.js} +34 -24
- package/dist/_node-chunks/{chunk-4BQMSZKI.js → chunk-KH2A547Y.js} +165 -191
- package/dist/_node-chunks/{chunk-77APSTTM.js → chunk-KP3IIE5P.js} +8 -9
- package/dist/_node-chunks/{chunk-5NWCBUGD.js → chunk-LZ5NNY6S.js} +6 -6
- package/dist/_node-chunks/{chunk-AJUO2ZU3.js → chunk-MLCI5FPI.js} +9 -9
- package/dist/_node-chunks/{chunk-CLNMK7MP.js → chunk-OVKHHS4W.js} +5434 -1625
- package/dist/_node-chunks/{chunk-ET4VMMZG.js → chunk-OZHIDIRL.js} +77 -16
- package/dist/_node-chunks/{chunk-TX77W2KY.js → chunk-POAHHCVK.js} +597 -593
- package/dist/_node-chunks/chunk-Q6PDB4Y6.js +126 -0
- package/dist/_node-chunks/{chunk-VFTNRF5X.js → chunk-QF3YWFYM.js} +17 -17
- package/dist/_node-chunks/{chunk-KMTK5W6O.js → chunk-RGJIQDLW.js} +48 -26
- package/dist/_node-chunks/{chunk-FTR6MHOX.js → chunk-SME7252C.js} +59 -147
- package/dist/_node-chunks/{chunk-LEDV47V2.js → chunk-TAETXAN6.js} +15 -15
- package/dist/_node-chunks/chunk-TPSZ4QDT.js +20 -0
- package/dist/_node-chunks/{chunk-PGFQADZC.js → chunk-WULYWBBT.js} +7 -7
- package/dist/_node-chunks/{chunk-JYMZJCZ7.js → chunk-XBDIQU4P.js} +62 -124
- package/dist/_node-chunks/chunk-XXOA6ULE.js +18 -0
- package/dist/_node-chunks/{chunk-ZI2RAI3I.js → chunk-YCQRVBE4.js} +26 -7
- package/dist/_node-chunks/{chunk-TP6ICLTL.js → chunk-YELE6V4D.js} +6 -6
- package/dist/_node-chunks/{chunk-GYZQMMTN.js → chunk-Z2CJCEHN.js} +9 -9
- package/dist/_node-chunks/{chunk-F7377GT2.js → chunk-Z2ETF7EI.js} +111 -38
- package/dist/_node-chunks/chunk-ZHSAQXJF.js +23 -0
- package/dist/_node-chunks/{dist-HGQ5R6JU.js → dist-5MXCD6KF.js} +10 -10
- package/dist/_node-chunks/{globby-5XJTXKUJ.js → globby-322GM5CY.js} +155 -164
- package/dist/_node-chunks/{lib-XNLTS2RI.js → lib-IXZT5UQX.js} +16 -16
- package/dist/_node-chunks/{mdx-N42X6CFJ-7WF3QWVO.js → mdx-N42X6CFJ-DBPHTSPN.js} +11 -11
- package/dist/_node-chunks/{p-limit-RBKYTJKF.js → p-limit-TLN4WCPA.js} +19 -15
- package/dist/babel/index.js +10 -10
- package/dist/bin/core.js +40 -34
- package/dist/bin/dispatcher.js +11 -11
- package/dist/bin/loader.js +14 -11
- package/dist/channels/index.js +3 -3
- package/dist/cli/index.d.ts +1330 -250
- package/dist/cli/index.js +18 -18
- package/dist/common/index.d.ts +1344 -289
- package/dist/common/index.js +22 -22
- package/dist/components/index.d.ts +9 -2
- package/dist/components/index.js +339 -317
- package/dist/core-events/index.d.ts +4 -2
- package/dist/core-events/index.js +4 -2
- package/dist/core-server/index.d.ts +71 -2
- package/dist/core-server/index.js +3381 -3529
- package/dist/core-server/presets/common-manager.css +2 -2
- package/dist/core-server/presets/common-manager.js +93 -65
- package/dist/core-server/presets/common-override-preset.js +9 -9
- package/dist/core-server/presets/common-preset.js +86 -118
- package/dist/csf/index.d.ts +41 -11
- package/dist/csf/index.js +46 -39
- package/dist/csf-tools/index.js +9 -9
- package/dist/docs-tools/index.js +5 -5
- package/dist/instrumenter/index.js +1 -1
- package/dist/manager/globals-runtime.js +9402 -7204
- package/dist/manager/runtime.js +186 -143
- package/dist/manager-api/index.js +34 -26
- package/dist/manager-errors.d.ts +24 -0
- package/dist/manager-errors.js +2 -2
- package/dist/mocking-utils/index.js +14 -14
- package/dist/node-logger/index.d.ts +1456 -111
- package/dist/node-logger/index.js +9 -9
- package/dist/preview/runtime.js +4608 -2436
- package/dist/preview-api/index.js +12 -12
- package/dist/preview-errors.d.ts +24 -0
- package/dist/preview-errors.js +3 -3
- package/dist/router/index.js +11 -11
- package/dist/server-errors.d.ts +59 -3
- package/dist/server-errors.js +22 -11
- package/dist/telemetry/index.d.ts +10 -3
- package/dist/telemetry/index.js +27 -25
- package/dist/test/index.js +3237 -1653
- package/dist/theming/create.js +3 -3
- package/dist/theming/index.d.ts +5 -5
- package/dist/theming/index.js +38 -38
- package/dist/types/index.d.ts +12 -6
- package/dist/viewport/index.d.ts +3 -3
- package/package.json +27 -33
- package/dist/_browser-chunks/chunk-EZSQOHRI.js +0 -18
- package/dist/_browser-chunks/chunk-QKODTO7K.js +0 -7
- package/dist/_node-chunks/camelcase-64II7H4U.js +0 -37
- package/dist/_node-chunks/chunk-4EZYJUAC.js +0 -70
- package/dist/_node-chunks/chunk-COQ27OZ3.js +0 -61
- package/dist/_node-chunks/chunk-MC2R4DSD.js +0 -20
- package/dist/_node-chunks/chunk-NEENMS4J.js +0 -18
- package/dist/_node-chunks/chunk-VR5LMO3F.js +0 -72
- package/dist/_node-chunks/chunk-XEPVDCRL.js +0 -23
package/dist/common/index.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import * as storybook_internal_types from 'storybook/internal/types';
|
|
|
2
2
|
import { CLIOptions, LoadOptions, BuilderOptions, StorybookConfigRaw, PresetConfig, CoreCommon_ResolvedAddonPreset, CoreCommon_ResolvedAddonVirtual, LoadedPreset, Presets, CoreCommon_AddonInfo, SupportedFramework, SupportedRenderer, SupportedBuilder, Options as Options$2, CoreWebpackCompiler, CoreCommon_StorybookInfo, Ref, StorybookConfig, StoriesEntry, NormalizedStoriesSpecifier, PackageJson } from 'storybook/internal/types';
|
|
3
3
|
export { PackageJson } from 'storybook/internal/types';
|
|
4
4
|
import { WriteStream } from 'node:fs';
|
|
5
|
-
import { Buffer } from 'node:buffer';
|
|
6
5
|
import { ChildProcess } from 'node:child_process';
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
6
|
+
import { SignalConstants } from 'node:os';
|
|
7
|
+
import { Duplex, Readable, Writable } from 'node:stream';
|
|
8
|
+
import { TransformStream, ReadableStream, WritableStream } from 'node:stream/web';
|
|
9
9
|
import { ConfigFile } from 'storybook/internal/csf-tools';
|
|
10
10
|
import { types } from 'storybook/internal/babel';
|
|
11
11
|
|
|
@@ -582,527 +582,1570 @@ declare function normalizeStoryPath(filename: string): string;
|
|
|
582
582
|
|
|
583
583
|
declare function readTemplate(filename: string): Promise<string>;
|
|
584
584
|
|
|
585
|
-
type
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
585
|
+
type Not<Value extends boolean> = Value extends true ? false : true;
|
|
586
|
+
|
|
587
|
+
type And<First extends boolean, Second extends boolean> = First extends true ? Second : false;
|
|
588
|
+
|
|
589
|
+
type Or<First extends boolean, Second extends boolean> = First extends true ? true : Second;
|
|
590
|
+
|
|
591
|
+
type Unless<Condition extends boolean, ThenValue, ElseValue = never> = Condition extends true ? ElseValue : ThenValue;
|
|
592
|
+
|
|
593
|
+
type AndUnless<Condition extends boolean, ThenValue, ElseValue = unknown> = Condition extends true ? ElseValue : ThenValue;
|
|
594
|
+
|
|
595
|
+
// Whether any of T's union element is the same as one of U's union element.
|
|
596
|
+
// `&` does not work here.
|
|
597
|
+
type Intersects<T, U> = true extends (T extends U ? true : false) ? true : false;
|
|
598
|
+
|
|
599
|
+
// `options.std*: Generator`
|
|
600
|
+
// @todo Use `string`, `Uint8Array` or `unknown` for both the argument and the return type, based on whether `encoding: 'buffer'` and `objectMode: true` are used.
|
|
601
|
+
// See https://github.com/sindresorhus/execa/issues/694
|
|
602
|
+
type GeneratorTransform<IsSync extends boolean> = (chunk: unknown) =>
|
|
603
|
+
| Unless<IsSync, AsyncGenerator<unknown, void, void>>
|
|
604
|
+
| Generator<unknown, void, void>;
|
|
605
|
+
type GeneratorFinal<IsSync extends boolean> = () =>
|
|
606
|
+
| Unless<IsSync, AsyncGenerator<unknown, void, void>>
|
|
607
|
+
| Generator<unknown, void, void>;
|
|
608
|
+
|
|
609
|
+
type TransformCommon = {
|
|
610
|
+
/**
|
|
611
|
+
If `true`, allow `transformOptions.transform` and `transformOptions.final` to return any type, not just `string` or `Uint8Array`.
|
|
612
|
+
*/
|
|
613
|
+
readonly objectMode?: boolean;
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
A transform or an array of transforms can be passed to the `stdin`, `stdout`, `stderr` or `stdio` option.
|
|
618
|
+
|
|
619
|
+
A transform is either a generator function or a plain object with the following members.
|
|
620
|
+
*/
|
|
621
|
+
type GeneratorTransformFull<IsSync extends boolean> = {
|
|
622
|
+
/**
|
|
623
|
+
Map or filter the input or output of the subprocess.
|
|
624
|
+
*/
|
|
625
|
+
readonly transform: GeneratorTransform<IsSync>;
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
Create additional lines after the last one.
|
|
629
|
+
*/
|
|
630
|
+
readonly final?: GeneratorFinal<IsSync>;
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
If `true`, iterate over arbitrary chunks of `Uint8Array`s instead of line `string`s.
|
|
634
|
+
*/
|
|
635
|
+
readonly binary?: boolean;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.
|
|
639
|
+
*/
|
|
640
|
+
readonly preserveNewlines?: boolean;
|
|
641
|
+
} & TransformCommon;
|
|
642
|
+
|
|
643
|
+
// `options.std*: Duplex`
|
|
644
|
+
type DuplexTransform = {
|
|
645
|
+
readonly transform: Duplex;
|
|
646
|
+
} & TransformCommon;
|
|
647
|
+
|
|
648
|
+
// `options.std*: TransformStream`
|
|
649
|
+
type WebTransform = {
|
|
650
|
+
readonly transform: TransformStream;
|
|
651
|
+
} & TransformCommon;
|
|
652
|
+
|
|
653
|
+
type IsStandardStream<FdNumber extends string> = FdNumber extends keyof StandardStreams ? true : false;
|
|
654
|
+
|
|
655
|
+
type StandardStreams = readonly ['stdin', 'stdout', 'stderr'];
|
|
656
|
+
|
|
657
|
+
// When `options.stdin|stdout|stderr|stdio` is set to one of those values, no stream is created
|
|
658
|
+
type NoStreamStdioOption<FdNumber extends string> =
|
|
589
659
|
| 'ignore'
|
|
590
660
|
| 'inherit'
|
|
591
|
-
|
|
|
661
|
+
| 'ipc'
|
|
592
662
|
| number
|
|
593
|
-
|
|
|
663
|
+
| Readable
|
|
664
|
+
| Writable
|
|
665
|
+
| Unless<IsStandardStream<FdNumber>, undefined>
|
|
666
|
+
| readonly [NoStreamStdioOption<FdNumber>];
|
|
667
|
+
|
|
668
|
+
// `options.stdio` when it is not an array
|
|
669
|
+
type SimpleStdioOption<
|
|
670
|
+
IsSync extends boolean,
|
|
671
|
+
IsExtra extends boolean,
|
|
672
|
+
IsArray extends boolean,
|
|
673
|
+
> =
|
|
674
|
+
| undefined
|
|
675
|
+
| 'pipe'
|
|
676
|
+
| Unless<And<And<Not<IsSync>, IsArray>, IsExtra>, 'inherit'>
|
|
677
|
+
| Unless<IsArray, 'ignore'>
|
|
678
|
+
| Unless<IsSync, 'overlapped'>;
|
|
679
|
+
|
|
680
|
+
// Values available in both `options.stdin|stdio` and `options.stdout|stderr|stdio`
|
|
681
|
+
type CommonStdioOption<
|
|
682
|
+
IsSync extends boolean,
|
|
683
|
+
IsExtra extends boolean,
|
|
684
|
+
IsArray extends boolean,
|
|
685
|
+
> =
|
|
686
|
+
| SimpleStdioOption<IsSync, IsExtra, IsArray>
|
|
687
|
+
| URL
|
|
688
|
+
| {readonly file: string; readonly append?: boolean}
|
|
689
|
+
| GeneratorTransform<IsSync>
|
|
690
|
+
| GeneratorTransformFull<IsSync>
|
|
691
|
+
| Unless<And<Not<IsSync>, IsArray>, 3 | 4 | 5 | 6 | 7 | 8 | 9>
|
|
692
|
+
| Unless<Or<IsSync, IsArray>, 'ipc'>
|
|
693
|
+
| Unless<IsSync, DuplexTransform | WebTransform | TransformStream>;
|
|
694
|
+
|
|
695
|
+
// Synchronous iterables excluding strings, Uint8Arrays and Arrays
|
|
696
|
+
type IterableObject<IsArray extends boolean> = Iterable<unknown>
|
|
697
|
+
& object
|
|
698
|
+
& {readonly BYTES_PER_ELEMENT?: never}
|
|
699
|
+
& AndUnless<IsArray, {readonly lastIndexOf?: never}>;
|
|
700
|
+
|
|
701
|
+
// `process.stdin|stdout|stderr` are `Duplex` with a `fd` property.
|
|
702
|
+
// This ensures they can only be passed to `stdin`/`stdout`/`stderr`, based on their direction.
|
|
703
|
+
type ProcessStdinFd = {readonly fd?: 0};
|
|
704
|
+
type ProcessStdoutStderrFd = {readonly fd?: 1 | 2};
|
|
705
|
+
|
|
706
|
+
// Values available only in `options.stdin|stdio`
|
|
707
|
+
type InputStdioOption<
|
|
708
|
+
IsSync extends boolean = boolean,
|
|
709
|
+
IsExtra extends boolean = boolean,
|
|
710
|
+
IsArray extends boolean = boolean,
|
|
711
|
+
> =
|
|
712
|
+
| 0
|
|
713
|
+
| Unless<And<IsSync, IsExtra>, Uint8Array | IterableObject<IsArray>>
|
|
714
|
+
| Unless<And<IsSync, IsArray>, Readable & ProcessStdinFd>
|
|
715
|
+
| Unless<IsSync, (AsyncIterable<unknown> & ProcessStdinFd) | ReadableStream>;
|
|
716
|
+
|
|
717
|
+
// Values available only in `options.stdout|stderr|stdio`
|
|
718
|
+
type OutputStdioOption<
|
|
719
|
+
IsSync extends boolean,
|
|
720
|
+
IsArray extends boolean,
|
|
721
|
+
> =
|
|
722
|
+
| 1
|
|
723
|
+
| 2
|
|
724
|
+
| Unless<And<IsSync, IsArray>, Writable & ProcessStdoutStderrFd>
|
|
725
|
+
| Unless<IsSync, WritableStream>;
|
|
726
|
+
|
|
727
|
+
// `options.stdin` array items
|
|
728
|
+
type StdinSingleOption<
|
|
729
|
+
IsSync extends boolean,
|
|
730
|
+
IsExtra extends boolean,
|
|
731
|
+
IsArray extends boolean,
|
|
732
|
+
> =
|
|
733
|
+
| CommonStdioOption<IsSync, IsExtra, IsArray>
|
|
734
|
+
| InputStdioOption<IsSync, IsExtra, IsArray>;
|
|
735
|
+
|
|
736
|
+
// `options.stdin`
|
|
737
|
+
type StdinOptionCommon<
|
|
738
|
+
IsSync extends boolean = boolean,
|
|
739
|
+
IsExtra extends boolean = boolean,
|
|
740
|
+
> =
|
|
741
|
+
| StdinSingleOption<IsSync, IsExtra, false>
|
|
742
|
+
| ReadonlyArray<StdinSingleOption<IsSync, IsExtra, true>>;
|
|
743
|
+
|
|
744
|
+
// `options.stdout|stderr` array items
|
|
745
|
+
type StdoutStderrSingleOption<
|
|
746
|
+
IsSync extends boolean,
|
|
747
|
+
IsExtra extends boolean,
|
|
748
|
+
IsArray extends boolean,
|
|
749
|
+
> =
|
|
750
|
+
| CommonStdioOption<IsSync, IsExtra, IsArray>
|
|
751
|
+
| OutputStdioOption<IsSync, IsArray>;
|
|
752
|
+
|
|
753
|
+
// `options.stdout|stderr`
|
|
754
|
+
type StdoutStderrOptionCommon<
|
|
755
|
+
IsSync extends boolean = boolean,
|
|
756
|
+
IsExtra extends boolean = boolean,
|
|
757
|
+
> =
|
|
758
|
+
| StdoutStderrSingleOption<IsSync, IsExtra, false>
|
|
759
|
+
| ReadonlyArray<StdoutStderrSingleOption<IsSync, IsExtra, true>>;
|
|
760
|
+
|
|
761
|
+
// `options.stdio[3+]`
|
|
762
|
+
type StdioExtraOptionCommon<IsSync extends boolean> =
|
|
763
|
+
| StdinOptionCommon<IsSync, true>
|
|
764
|
+
| StdoutStderrOptionCommon<IsSync, true>;
|
|
765
|
+
|
|
766
|
+
// `options.stdin|stdout|stderr|stdio` array items
|
|
767
|
+
type StdioSingleOption<
|
|
768
|
+
IsSync extends boolean = boolean,
|
|
769
|
+
IsExtra extends boolean = boolean,
|
|
770
|
+
IsArray extends boolean = boolean,
|
|
771
|
+
> =
|
|
772
|
+
| StdinSingleOption<IsSync, IsExtra, IsArray>
|
|
773
|
+
| StdoutStderrSingleOption<IsSync, IsExtra, IsArray>;
|
|
774
|
+
|
|
775
|
+
// Get `options.stdin|stdout|stderr|stdio` items if it is an array, else keep as is
|
|
776
|
+
type StdioSingleOptionItems<StdioOptionType> = StdioOptionType extends readonly StdioSingleOption[]
|
|
777
|
+
? StdioOptionType[number]
|
|
778
|
+
: StdioOptionType;
|
|
779
|
+
|
|
780
|
+
// `options.stdin|stdout|stderr|stdio`
|
|
781
|
+
type StdioOptionCommon<IsSync extends boolean = boolean> =
|
|
782
|
+
| StdinOptionCommon<IsSync>
|
|
783
|
+
| StdoutStderrOptionCommon<IsSync>;
|
|
784
|
+
|
|
785
|
+
// `options.stdio` when it is an array
|
|
786
|
+
type StdioOptionsArray<IsSync extends boolean = boolean> = readonly [
|
|
787
|
+
StdinOptionCommon<IsSync, false>,
|
|
788
|
+
StdoutStderrOptionCommon<IsSync, false>,
|
|
789
|
+
StdoutStderrOptionCommon<IsSync, false>,
|
|
790
|
+
...ReadonlyArray<StdioExtraOptionCommon<IsSync>>,
|
|
791
|
+
];
|
|
792
|
+
|
|
793
|
+
// `options.stdio`
|
|
794
|
+
type StdioOptionsProperty<IsSync extends boolean = boolean> =
|
|
795
|
+
| SimpleStdioOption<IsSync, false, false>
|
|
796
|
+
| StdioOptionsArray<IsSync>;
|
|
797
|
+
|
|
798
|
+
// Message when the `serialization` option is `'advanced'`
|
|
799
|
+
type AdvancedMessage =
|
|
800
|
+
| string
|
|
801
|
+
| number
|
|
802
|
+
| boolean
|
|
803
|
+
| null
|
|
804
|
+
| object;
|
|
594
805
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
806
|
+
// Message when the `serialization` option is `'json'`
|
|
807
|
+
type JsonMessage =
|
|
808
|
+
| string
|
|
809
|
+
| number
|
|
810
|
+
| boolean
|
|
811
|
+
| null
|
|
812
|
+
| readonly JsonMessage[]
|
|
813
|
+
| {readonly [key: string | number]: JsonMessage};
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
Type of messages exchanged between a process and its subprocess using `sendMessage()`, `getOneMessage()` and `getEachMessage()`.
|
|
817
|
+
|
|
818
|
+
This requires the `ipc` option to be `true`. The type of `message` depends on the `serialization` option.
|
|
819
|
+
*/
|
|
820
|
+
type Message<
|
|
821
|
+
Serialization extends Options['serialization'] = Options['serialization'],
|
|
822
|
+
> = Serialization extends 'json' ? JsonMessage : AdvancedMessage;
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
Options to `sendMessage()` and `subprocess.sendMessage()`
|
|
826
|
+
*/
|
|
827
|
+
type SendMessageOptions = {
|
|
828
|
+
/**
|
|
829
|
+
Throw when the other process is not receiving or listening to messages.
|
|
830
|
+
|
|
831
|
+
@default false
|
|
832
|
+
*/
|
|
833
|
+
readonly strict?: boolean;
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
Options to `getOneMessage()` and `subprocess.getOneMessage()`
|
|
838
|
+
*/
|
|
839
|
+
type GetOneMessageOptions<
|
|
840
|
+
Serialization extends Options['serialization'],
|
|
841
|
+
> = {
|
|
842
|
+
/**
|
|
843
|
+
Ignore any `message` that returns `false`.
|
|
844
|
+
*/
|
|
845
|
+
readonly filter?: (message: Message<Serialization>) => boolean;
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
Keep the subprocess alive while `getOneMessage()` is waiting.
|
|
849
|
+
|
|
850
|
+
@default true
|
|
851
|
+
*/
|
|
852
|
+
readonly reference?: boolean;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
Options to `getEachMessage()` and `subprocess.getEachMessage()`
|
|
857
|
+
*/
|
|
858
|
+
type GetEachMessageOptions = {
|
|
859
|
+
/**
|
|
860
|
+
Keep the subprocess alive while `getEachMessage()` is waiting.
|
|
861
|
+
|
|
862
|
+
@default true
|
|
863
|
+
*/
|
|
864
|
+
readonly reference?: boolean;
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
// IPC methods in the subprocess
|
|
868
|
+
type IpcMethods<
|
|
869
|
+
IpcEnabled extends boolean,
|
|
870
|
+
Serialization extends Options['serialization'],
|
|
871
|
+
> = IpcEnabled extends true
|
|
872
|
+
? {
|
|
873
|
+
/**
|
|
874
|
+
Send a `message` to the subprocess.
|
|
875
|
+
|
|
876
|
+
This requires the `ipc` option to be `true`. The type of `message` depends on the `serialization` option.
|
|
877
|
+
*/
|
|
878
|
+
sendMessage(message: Message<Serialization>, sendMessageOptions?: SendMessageOptions): Promise<void>;
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
Receive a single `message` from the subprocess.
|
|
882
|
+
|
|
883
|
+
This requires the `ipc` option to be `true`. The type of `message` depends on the `serialization` option.
|
|
884
|
+
*/
|
|
885
|
+
getOneMessage(getOneMessageOptions?: GetOneMessageOptions<Serialization>): Promise<Message<Serialization>>;
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
Iterate over each `message` from the subprocess.
|
|
889
|
+
|
|
890
|
+
This requires the `ipc` option to be `true`. The type of `message` depends on the `serialization` option.
|
|
891
|
+
*/
|
|
892
|
+
getEachMessage(getEachMessageOptions?: GetEachMessageOptions): AsyncIterableIterator<Message<Serialization>>;
|
|
893
|
+
}
|
|
894
|
+
// Those methods only work if the `ipc` option is `true`.
|
|
895
|
+
// At runtime, they are actually defined, in order to provide with a nice error message.
|
|
896
|
+
// At type check time, they are typed as `undefined` to prevent calling them.
|
|
897
|
+
: {
|
|
898
|
+
sendMessage: undefined;
|
|
899
|
+
getOneMessage: undefined;
|
|
900
|
+
getEachMessage: undefined;
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
// Whether IPC is enabled, based on the `ipc`, `ipcInput` and `gracefulCancel` options
|
|
904
|
+
type HasIpc<OptionsType extends Options> = HasIpcOption<
|
|
905
|
+
OptionsType['ipc'],
|
|
906
|
+
'ipcInput' extends keyof OptionsType ? OptionsType['ipcInput'] : undefined,
|
|
907
|
+
'gracefulCancel' extends keyof OptionsType ? OptionsType['gracefulCancel'] : undefined
|
|
908
|
+
>;
|
|
909
|
+
|
|
910
|
+
type HasIpcOption<
|
|
911
|
+
IpcOption extends Options['ipc'],
|
|
912
|
+
IpcInputOption extends Options['ipcInput'],
|
|
913
|
+
GracefulCancelOption extends Options['gracefulCancel'],
|
|
914
|
+
> = IpcOption extends true
|
|
915
|
+
? true
|
|
916
|
+
: IpcOption extends false
|
|
917
|
+
? false
|
|
918
|
+
: IpcInputOption extends undefined
|
|
919
|
+
? GracefulCancelOption extends true
|
|
920
|
+
? true
|
|
921
|
+
: false
|
|
922
|
+
: true;
|
|
923
|
+
|
|
924
|
+
type FileDescriptorOption = `fd${number}`;
|
|
925
|
+
|
|
926
|
+
// `from` option of `subprocess.readable|duplex|iterable|pipe()`
|
|
927
|
+
// Also used by fd-specific options
|
|
928
|
+
type FromOption = 'stdout' | 'stderr' | 'all' | FileDescriptorOption;
|
|
929
|
+
|
|
930
|
+
// `to` option of `subprocess.writable|duplex|pipe()`
|
|
931
|
+
type ToOption = 'stdin' | FileDescriptorOption;
|
|
932
|
+
|
|
933
|
+
// Options which can be fd-specific like `{verbose: {stdout: 'none', stderr: 'full'}}`
|
|
934
|
+
type FdGenericOption<OptionType> = OptionType | GenericOptionObject<OptionType>;
|
|
935
|
+
|
|
936
|
+
type GenericOptionObject<OptionType> = {
|
|
937
|
+
readonly [FdName in GenericFromOption]?: OptionType
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
type GenericFromOption = FromOption | 'ipc';
|
|
941
|
+
|
|
942
|
+
// Retrieve fd-specific option's value
|
|
943
|
+
type FdSpecificOption<
|
|
944
|
+
GenericOption extends FdGenericOption<unknown>,
|
|
945
|
+
FdNumber extends string,
|
|
946
|
+
> = GenericOption extends GenericOptionObject<unknown>
|
|
947
|
+
? FdSpecificObjectOption<GenericOption, FdNumber>
|
|
948
|
+
: GenericOption;
|
|
949
|
+
|
|
950
|
+
type FdSpecificObjectOption<
|
|
951
|
+
GenericOption extends GenericOptionObject<unknown>,
|
|
952
|
+
FdNumber extends string,
|
|
953
|
+
> = keyof GenericOption extends GenericFromOption
|
|
954
|
+
? FdNumberToFromOption<FdNumber, keyof GenericOption> extends never
|
|
955
|
+
? undefined
|
|
956
|
+
: GenericOption[FdNumberToFromOption<FdNumber, keyof GenericOption>]
|
|
957
|
+
: GenericOption;
|
|
958
|
+
|
|
959
|
+
type FdNumberToFromOption<
|
|
960
|
+
FdNumber extends string,
|
|
961
|
+
GenericOptionKeys extends GenericFromOption,
|
|
962
|
+
> = FdNumber extends '1'
|
|
963
|
+
? 'stdout' extends GenericOptionKeys
|
|
964
|
+
? 'stdout'
|
|
965
|
+
: 'fd1' extends GenericOptionKeys
|
|
966
|
+
? 'fd1'
|
|
967
|
+
: 'all' extends GenericOptionKeys
|
|
968
|
+
? 'all'
|
|
969
|
+
: never
|
|
970
|
+
: FdNumber extends '2'
|
|
971
|
+
? 'stderr' extends GenericOptionKeys
|
|
972
|
+
? 'stderr'
|
|
973
|
+
: 'fd2' extends GenericOptionKeys
|
|
974
|
+
? 'fd2'
|
|
975
|
+
: 'all' extends GenericOptionKeys
|
|
976
|
+
? 'all'
|
|
977
|
+
: never
|
|
978
|
+
: `fd${FdNumber}` extends GenericOptionKeys
|
|
979
|
+
? `fd${FdNumber}`
|
|
980
|
+
: 'ipc' extends GenericOptionKeys
|
|
981
|
+
? 'ipc'
|
|
982
|
+
: never;
|
|
983
|
+
|
|
984
|
+
// `result.*` defined only on failure, i.e. on `error.*`
|
|
985
|
+
type ErrorProperties =
|
|
986
|
+
| 'name'
|
|
987
|
+
| 'message'
|
|
988
|
+
| 'stack'
|
|
989
|
+
| 'cause'
|
|
990
|
+
| 'shortMessage'
|
|
991
|
+
| 'originalMessage'
|
|
992
|
+
| 'code';
|
|
993
|
+
|
|
994
|
+
// `options.stdio`, normalized as an array
|
|
995
|
+
type StdioOptionNormalizedArray<OptionsType extends CommonOptions> = StdioOptionNormalized<OptionsType['stdio']>;
|
|
996
|
+
|
|
997
|
+
type StdioOptionNormalized<StdioOption extends CommonOptions['stdio']> = StdioOption extends StdioOptionsArray
|
|
998
|
+
? StdioOption
|
|
999
|
+
: StdioOption extends StdinOptionCommon
|
|
1000
|
+
? StdioOption extends StdoutStderrOptionCommon
|
|
1001
|
+
? readonly [StdioOption, StdioOption, StdioOption]
|
|
1002
|
+
: DefaultStdioOption
|
|
1003
|
+
: DefaultStdioOption;
|
|
1004
|
+
|
|
1005
|
+
// `options.stdio` default value
|
|
1006
|
+
type DefaultStdioOption = readonly ['pipe', 'pipe', 'pipe'];
|
|
1007
|
+
|
|
1008
|
+
// `options.stdin|stdout|stderr|stdio` for a given file descriptor
|
|
1009
|
+
type FdStdioOption<
|
|
1010
|
+
FdNumber extends string,
|
|
1011
|
+
OptionsType extends CommonOptions,
|
|
1012
|
+
> = FdStdioOptionProperty<FdNumber, OptionsType>;
|
|
1013
|
+
|
|
1014
|
+
type FdStdioOptionProperty<
|
|
1015
|
+
FdNumber extends string,
|
|
1016
|
+
OptionsType extends CommonOptions,
|
|
1017
|
+
> = string extends FdNumber ? StdioOptionCommon
|
|
1018
|
+
: FdNumber extends keyof StandardStreams
|
|
1019
|
+
? StandardStreams[FdNumber] extends keyof OptionsType
|
|
1020
|
+
? OptionsType[StandardStreams[FdNumber]] extends undefined
|
|
1021
|
+
? FdStdioArrayOption<FdNumber, OptionsType>
|
|
1022
|
+
: OptionsType[StandardStreams[FdNumber]]
|
|
1023
|
+
: FdStdioArrayOption<FdNumber, OptionsType>
|
|
1024
|
+
: FdStdioArrayOption<FdNumber, OptionsType>;
|
|
1025
|
+
|
|
1026
|
+
// `options.stdio[FdNumber]`, excluding `options.stdin|stdout|stderr`
|
|
1027
|
+
type FdStdioArrayOption<
|
|
1028
|
+
FdNumber extends string,
|
|
1029
|
+
OptionsType extends CommonOptions,
|
|
1030
|
+
> = FdStdioArrayOptionProperty<FdNumber, StdioOptionNormalizedArray<OptionsType>>;
|
|
1031
|
+
|
|
1032
|
+
type FdStdioArrayOptionProperty<
|
|
1033
|
+
FdNumber extends string,
|
|
1034
|
+
StdioOptionsType,
|
|
1035
|
+
> = string extends FdNumber
|
|
1036
|
+
? StdioOptionCommon | undefined
|
|
1037
|
+
: StdioOptionsType extends StdioOptionsArray
|
|
1038
|
+
? FdNumber extends keyof StdioOptionsType
|
|
1039
|
+
? StdioOptionsType[FdNumber]
|
|
1040
|
+
: StdioOptionNormalizedArray<CommonOptions> extends StdioOptionsType
|
|
1041
|
+
? StdioOptionsType[number]
|
|
1042
|
+
: undefined
|
|
1043
|
+
: undefined;
|
|
1044
|
+
|
|
1045
|
+
// Whether a file descriptor is in object mode
|
|
1046
|
+
// I.e. whether `result.stdout|stderr|stdio|all` is an array of `unknown` due to `objectMode: true`
|
|
1047
|
+
type IsObjectFd<
|
|
1048
|
+
FdNumber extends string,
|
|
1049
|
+
OptionsType extends CommonOptions,
|
|
1050
|
+
> = IsObjectStdioOption<FdStdioOption<FdNumber, OptionsType>>;
|
|
1051
|
+
|
|
1052
|
+
type IsObjectStdioOption<StdioOptionType> = IsObjectStdioSingleOption<StdioSingleOptionItems<StdioOptionType>>;
|
|
1053
|
+
|
|
1054
|
+
type IsObjectStdioSingleOption<StdioSingleOptionType> = StdioSingleOptionType extends TransformCommon
|
|
1055
|
+
? BooleanObjectMode<StdioSingleOptionType['objectMode']>
|
|
1056
|
+
: StdioSingleOptionType extends DuplexTransform
|
|
1057
|
+
? StdioSingleOptionType['transform']['readableObjectMode']
|
|
1058
|
+
: false;
|
|
1059
|
+
|
|
1060
|
+
type BooleanObjectMode<ObjectModeOption extends boolean | undefined> = ObjectModeOption extends true ? true : false;
|
|
1061
|
+
|
|
1062
|
+
// Whether `result.stdio[FdNumber]` is an input stream
|
|
1063
|
+
type IsInputFd<
|
|
1064
|
+
FdNumber extends string,
|
|
1065
|
+
OptionsType extends CommonOptions,
|
|
1066
|
+
> = FdNumber extends '0'
|
|
1067
|
+
? true
|
|
1068
|
+
: Intersects<StdioSingleOptionItems<FdStdioArrayOption<FdNumber, OptionsType>>, InputStdioOption>;
|
|
1069
|
+
|
|
1070
|
+
// Whether `result.stdin|stdout|stderr|all|stdio[*]` is `undefined`
|
|
1071
|
+
type IgnoresResultOutput<
|
|
1072
|
+
FdNumber extends string,
|
|
1073
|
+
OptionsType extends CommonOptions,
|
|
1074
|
+
> = FdSpecificOption<OptionsType['buffer'], FdNumber> extends false
|
|
1075
|
+
? true
|
|
1076
|
+
: IsInputFd<FdNumber, OptionsType> extends true
|
|
1077
|
+
? true
|
|
1078
|
+
: IgnoresSubprocessOutput<FdNumber, OptionsType>;
|
|
1079
|
+
|
|
1080
|
+
// Whether `subprocess.stdout|stderr|all` is `undefined|null`
|
|
1081
|
+
type IgnoresSubprocessOutput<
|
|
1082
|
+
FdNumber extends string,
|
|
1083
|
+
OptionsType extends CommonOptions,
|
|
1084
|
+
> = IgnoresOutput<FdNumber, FdStdioOption<FdNumber, OptionsType>>;
|
|
1085
|
+
|
|
1086
|
+
type IgnoresOutput<
|
|
1087
|
+
FdNumber extends string,
|
|
1088
|
+
StdioOptionType,
|
|
1089
|
+
> = StdioOptionType extends NoStreamStdioOption<FdNumber> ? true : false;
|
|
1090
|
+
|
|
1091
|
+
type DefaultEncodingOption = 'utf8';
|
|
1092
|
+
type TextEncodingOption =
|
|
1093
|
+
| DefaultEncodingOption
|
|
1094
|
+
| 'utf16le';
|
|
1095
|
+
|
|
1096
|
+
type BufferEncodingOption = 'buffer';
|
|
1097
|
+
type BinaryEncodingOption =
|
|
1098
|
+
| BufferEncodingOption
|
|
606
1099
|
| 'hex'
|
|
607
1100
|
| 'base64'
|
|
608
1101
|
| 'base64url'
|
|
609
|
-
| '
|
|
610
|
-
|
|
|
611
|
-
|
|
612
|
-
|
|
1102
|
+
| 'latin1'
|
|
1103
|
+
| 'ascii';
|
|
1104
|
+
|
|
1105
|
+
// `options.encoding`
|
|
1106
|
+
type EncodingOption =
|
|
1107
|
+
| TextEncodingOption
|
|
1108
|
+
| BinaryEncodingOption
|
|
1109
|
+
| undefined;
|
|
1110
|
+
|
|
1111
|
+
// `result.stdout|stderr|stdio`
|
|
1112
|
+
type ResultStdioNotAll<
|
|
1113
|
+
FdNumber extends string,
|
|
1114
|
+
OptionsType extends CommonOptions,
|
|
1115
|
+
> = ResultStdio<FdNumber, FdNumber, FdNumber, OptionsType>;
|
|
1116
|
+
|
|
1117
|
+
// `result.stdout|stderr|stdio|all`
|
|
1118
|
+
type ResultStdio<
|
|
1119
|
+
MainFdNumber extends string,
|
|
1120
|
+
ObjectFdNumber extends string,
|
|
1121
|
+
LinesFdNumber extends string,
|
|
1122
|
+
OptionsType extends CommonOptions,
|
|
1123
|
+
> = ResultStdioProperty<
|
|
1124
|
+
ObjectFdNumber,
|
|
1125
|
+
LinesFdNumber,
|
|
1126
|
+
IgnoresResultOutput<MainFdNumber, OptionsType>,
|
|
1127
|
+
OptionsType
|
|
1128
|
+
>;
|
|
1129
|
+
|
|
1130
|
+
type ResultStdioProperty<
|
|
1131
|
+
ObjectFdNumber extends string,
|
|
1132
|
+
LinesFdNumber extends string,
|
|
1133
|
+
StreamOutputIgnored,
|
|
1134
|
+
OptionsType extends CommonOptions,
|
|
1135
|
+
> = StreamOutputIgnored extends true
|
|
1136
|
+
? undefined
|
|
1137
|
+
: ResultStdioItem<
|
|
1138
|
+
IsObjectFd<ObjectFdNumber, OptionsType>,
|
|
1139
|
+
FdSpecificOption<OptionsType['lines'], LinesFdNumber>,
|
|
1140
|
+
OptionsType['encoding']
|
|
1141
|
+
>;
|
|
1142
|
+
|
|
1143
|
+
type ResultStdioItem<
|
|
1144
|
+
IsObjectResult,
|
|
1145
|
+
LinesOption extends boolean | undefined,
|
|
1146
|
+
Encoding extends CommonOptions['encoding'],
|
|
1147
|
+
> = IsObjectResult extends true ? unknown[]
|
|
1148
|
+
: Encoding extends BufferEncodingOption
|
|
1149
|
+
? Uint8Array
|
|
1150
|
+
: LinesOption extends true
|
|
1151
|
+
? Encoding extends BinaryEncodingOption
|
|
1152
|
+
? string
|
|
1153
|
+
: string[]
|
|
1154
|
+
: string;
|
|
1155
|
+
|
|
1156
|
+
// `result.all`
|
|
1157
|
+
type ResultAll<OptionsType extends CommonOptions> =
|
|
1158
|
+
ResultAllProperty<OptionsType['all'], OptionsType>;
|
|
1159
|
+
|
|
1160
|
+
type ResultAllProperty<
|
|
1161
|
+
AllOption extends CommonOptions['all'],
|
|
1162
|
+
OptionsType extends CommonOptions,
|
|
1163
|
+
> = AllOption extends true
|
|
1164
|
+
? ResultStdio<
|
|
1165
|
+
AllMainFd<OptionsType>,
|
|
1166
|
+
AllObjectFd<OptionsType>,
|
|
1167
|
+
AllLinesFd<OptionsType>,
|
|
1168
|
+
OptionsType
|
|
1169
|
+
>
|
|
1170
|
+
: undefined;
|
|
1171
|
+
|
|
1172
|
+
type AllMainFd<OptionsType extends CommonOptions> =
|
|
1173
|
+
IgnoresResultOutput<'1', OptionsType> extends true ? '2' : '1';
|
|
1174
|
+
|
|
1175
|
+
type AllObjectFd<OptionsType extends CommonOptions> =
|
|
1176
|
+
IsObjectFd<'1', OptionsType> extends true ? '1' : '2';
|
|
1177
|
+
|
|
1178
|
+
type AllLinesFd<OptionsType extends CommonOptions> =
|
|
1179
|
+
FdSpecificOption<OptionsType['lines'], '1'> extends true ? '1' : '2';
|
|
1180
|
+
|
|
1181
|
+
// `result.stdio`
|
|
1182
|
+
type ResultStdioArray<OptionsType extends CommonOptions> =
|
|
1183
|
+
MapResultStdio<StdioOptionNormalizedArray<OptionsType>, OptionsType>;
|
|
1184
|
+
|
|
1185
|
+
type MapResultStdio<
|
|
1186
|
+
StdioOptionsArrayType,
|
|
1187
|
+
OptionsType extends CommonOptions,
|
|
1188
|
+
> = {
|
|
1189
|
+
-readonly [FdNumber in keyof StdioOptionsArrayType]: ResultStdioNotAll<
|
|
1190
|
+
FdNumber extends string ? FdNumber : string,
|
|
1191
|
+
OptionsType
|
|
1192
|
+
>
|
|
1193
|
+
};
|
|
613
1194
|
|
|
614
|
-
|
|
1195
|
+
// `result.ipcOutput`
|
|
1196
|
+
// This is empty unless the `ipc` option is `true`.
|
|
1197
|
+
// Also, this is empty if the `buffer` option is `false`.
|
|
1198
|
+
type ResultIpcOutput<
|
|
1199
|
+
IsSync,
|
|
1200
|
+
OptionsType extends CommonOptions,
|
|
1201
|
+
> = IsSync extends true
|
|
1202
|
+
? []
|
|
1203
|
+
: ResultIpcAsync<
|
|
1204
|
+
FdSpecificOption<OptionsType['buffer'], 'ipc'>,
|
|
1205
|
+
HasIpc<StricterOptions<OptionsType, Options>>,
|
|
1206
|
+
OptionsType['serialization']
|
|
1207
|
+
>;
|
|
1208
|
+
|
|
1209
|
+
type ResultIpcAsync<
|
|
1210
|
+
BufferOption extends boolean | undefined,
|
|
1211
|
+
IpcEnabled extends boolean,
|
|
1212
|
+
SerializationOption extends CommonOptions['serialization'],
|
|
1213
|
+
> = BufferOption extends false
|
|
1214
|
+
? []
|
|
1215
|
+
: IpcEnabled extends true
|
|
1216
|
+
? Array<Message<SerializationOption>>
|
|
1217
|
+
: [];
|
|
1218
|
+
|
|
1219
|
+
declare abstract class CommonResult<
|
|
1220
|
+
IsSync extends boolean,
|
|
1221
|
+
OptionsType extends CommonOptions,
|
|
1222
|
+
> {
|
|
615
1223
|
/**
|
|
616
|
-
|
|
617
|
-
- the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)
|
|
618
|
-
- the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit
|
|
1224
|
+
The output of the subprocess on [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)).
|
|
619
1225
|
|
|
620
|
-
|
|
1226
|
+
This is `undefined` if the `stdout` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
1227
|
+
|
|
1228
|
+
This is an array if the `lines` option is `true`, or if the `stdout` option is a transform in object mode.
|
|
621
1229
|
*/
|
|
622
|
-
|
|
1230
|
+
stdout: ResultStdioNotAll<'1', OptionsType>;
|
|
623
1231
|
|
|
624
1232
|
/**
|
|
625
|
-
|
|
1233
|
+
The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).
|
|
626
1234
|
|
|
627
|
-
|
|
1235
|
+
This is `undefined` if the `stderr` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
628
1236
|
|
|
629
|
-
|
|
1237
|
+
This is an array if the `lines` option is `true`, or if the `stderr` option is a transform in object mode.
|
|
630
1238
|
*/
|
|
631
|
-
|
|
1239
|
+
stderr: ResultStdioNotAll<'2', OptionsType>;
|
|
632
1240
|
|
|
633
1241
|
/**
|
|
634
|
-
|
|
1242
|
+
The output of the subprocess with `result.stdout` and `result.stderr` interleaved.
|
|
635
1243
|
|
|
636
|
-
|
|
1244
|
+
This requires the `all` option to be `true`.
|
|
1245
|
+
|
|
1246
|
+
This is `undefined` if both `stdout` and `stderr` options are set to only `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
1247
|
+
|
|
1248
|
+
This is an array if the `lines` option is `true`, or if either the `stdout` or `stderr` option is a transform in object mode.
|
|
637
1249
|
*/
|
|
638
|
-
|
|
1250
|
+
all: ResultAll<OptionsType>;
|
|
639
1251
|
|
|
640
1252
|
/**
|
|
641
|
-
|
|
1253
|
+
The output of the subprocess on `stdin`, `stdout`, `stderr` and other file descriptors.
|
|
642
1254
|
|
|
643
|
-
|
|
1255
|
+
Items are `undefined` when their corresponding `stdio` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
644
1256
|
|
|
645
|
-
|
|
1257
|
+
Items are arrays when their corresponding `stdio` option is a transform in object mode.
|
|
1258
|
+
*/
|
|
1259
|
+
stdio: ResultStdioArray<OptionsType>;
|
|
646
1260
|
|
|
647
|
-
|
|
1261
|
+
/**
|
|
1262
|
+
All the messages sent by the subprocess to the current process.
|
|
648
1263
|
|
|
649
|
-
|
|
1264
|
+
This is empty unless the `ipc` option is `true`. Also, this is empty if the `buffer` option is `false`.
|
|
650
1265
|
*/
|
|
651
|
-
|
|
1266
|
+
ipcOutput: ResultIpcOutput<IsSync, OptionsType>;
|
|
652
1267
|
|
|
653
1268
|
/**
|
|
654
|
-
|
|
1269
|
+
Results of the other subprocesses that were piped into this subprocess.
|
|
655
1270
|
|
|
656
|
-
|
|
1271
|
+
This array is initially empty and is populated each time the `subprocess.pipe()` method resolves.
|
|
1272
|
+
*/
|
|
1273
|
+
pipedFrom: Unless<IsSync, Result[], []>;
|
|
657
1274
|
|
|
658
|
-
|
|
1275
|
+
/**
|
|
1276
|
+
The file and arguments that were run.
|
|
659
1277
|
*/
|
|
660
|
-
|
|
1278
|
+
command: string;
|
|
661
1279
|
|
|
662
1280
|
/**
|
|
663
|
-
Same
|
|
1281
|
+
Same as `command` but escaped.
|
|
1282
|
+
*/
|
|
1283
|
+
escapedCommand: string;
|
|
664
1284
|
|
|
665
|
-
|
|
1285
|
+
/**
|
|
1286
|
+
The current directory in which the command was run.
|
|
666
1287
|
*/
|
|
667
|
-
|
|
1288
|
+
cwd: string;
|
|
668
1289
|
|
|
669
1290
|
/**
|
|
670
|
-
|
|
1291
|
+
Duration of the subprocess, in milliseconds.
|
|
1292
|
+
*/
|
|
1293
|
+
durationMs: number;
|
|
671
1294
|
|
|
672
|
-
|
|
1295
|
+
/**
|
|
1296
|
+
Whether the subprocess failed to run.
|
|
1297
|
+
|
|
1298
|
+
When this is `true`, the result is an `ExecaError` instance with additional error-related properties.
|
|
673
1299
|
*/
|
|
674
|
-
|
|
1300
|
+
failed: boolean;
|
|
675
1301
|
|
|
676
1302
|
/**
|
|
677
|
-
|
|
1303
|
+
Whether the subprocess timed out due to the `timeout` option.
|
|
1304
|
+
*/
|
|
1305
|
+
timedOut: boolean;
|
|
678
1306
|
|
|
679
|
-
|
|
1307
|
+
/**
|
|
1308
|
+
Whether the subprocess was canceled using the `cancelSignal` option.
|
|
680
1309
|
*/
|
|
681
|
-
|
|
1310
|
+
isCanceled: boolean;
|
|
682
1311
|
|
|
683
1312
|
/**
|
|
684
|
-
|
|
1313
|
+
Whether the subprocess was canceled using both the `cancelSignal` and the `gracefulCancel` options.
|
|
1314
|
+
*/
|
|
1315
|
+
isGracefullyCanceled: boolean;
|
|
685
1316
|
|
|
686
|
-
|
|
1317
|
+
/**
|
|
1318
|
+
Whether the subprocess failed because its output was larger than the `maxBuffer` option.
|
|
687
1319
|
*/
|
|
688
|
-
|
|
1320
|
+
isMaxBuffer: boolean;
|
|
689
1321
|
|
|
690
1322
|
/**
|
|
691
|
-
|
|
1323
|
+
Whether the subprocess was terminated by a signal (like `SIGTERM`) sent by either:
|
|
1324
|
+
- The current process.
|
|
1325
|
+
- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).
|
|
1326
|
+
*/
|
|
1327
|
+
isTerminated: boolean;
|
|
692
1328
|
|
|
693
|
-
|
|
1329
|
+
/**
|
|
1330
|
+
Whether the subprocess was terminated by the `SIGKILL` signal sent by the `forceKillAfterDelay` option.
|
|
694
1331
|
*/
|
|
695
|
-
|
|
1332
|
+
isForcefullyTerminated: boolean;
|
|
696
1333
|
|
|
697
1334
|
/**
|
|
698
|
-
|
|
1335
|
+
The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.
|
|
699
1336
|
|
|
700
|
-
|
|
1337
|
+
This is `undefined` when the subprocess could not be spawned or was terminated by a signal.
|
|
701
1338
|
*/
|
|
702
|
-
|
|
1339
|
+
exitCode?: number;
|
|
703
1340
|
|
|
704
1341
|
/**
|
|
705
|
-
|
|
1342
|
+
The name of the signal (like `SIGTERM`) that terminated the subprocess, sent by either:
|
|
1343
|
+
- The current process.
|
|
1344
|
+
- Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).
|
|
706
1345
|
|
|
707
|
-
|
|
1346
|
+
If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`.
|
|
708
1347
|
*/
|
|
709
|
-
|
|
1348
|
+
signal?: keyof SignalConstants;
|
|
710
1349
|
|
|
711
1350
|
/**
|
|
712
|
-
|
|
1351
|
+
A human-friendly description of the signal that was used to terminate the subprocess.
|
|
713
1352
|
|
|
714
|
-
|
|
1353
|
+
If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.
|
|
715
1354
|
*/
|
|
716
|
-
|
|
1355
|
+
signalDescription?: string;
|
|
717
1356
|
|
|
718
1357
|
/**
|
|
719
|
-
|
|
1358
|
+
Error message when the subprocess failed to run.
|
|
1359
|
+
*/
|
|
1360
|
+
message?: string;
|
|
720
1361
|
|
|
721
|
-
|
|
1362
|
+
/**
|
|
1363
|
+
This is the same as `error.message` except it does not include the subprocess output.
|
|
722
1364
|
*/
|
|
723
|
-
|
|
1365
|
+
shortMessage?: string;
|
|
724
1366
|
|
|
725
1367
|
/**
|
|
726
|
-
|
|
1368
|
+
Original error message. This is the same as `error.message` excluding the subprocess output and some additional information added by Execa.
|
|
1369
|
+
|
|
1370
|
+
This exists only in specific instances, such as during a timeout.
|
|
727
1371
|
*/
|
|
728
|
-
|
|
1372
|
+
originalMessage?: string;
|
|
729
1373
|
|
|
730
1374
|
/**
|
|
731
|
-
|
|
1375
|
+
Underlying error, if there is one. For example, this is set by `subprocess.kill(error)`.
|
|
732
1376
|
|
|
733
|
-
|
|
1377
|
+
This is usually an `Error` instance.
|
|
1378
|
+
*/
|
|
1379
|
+
cause?: unknown;
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.
|
|
1383
|
+
*/
|
|
1384
|
+
code?: string;
|
|
1385
|
+
|
|
1386
|
+
// We cannot `extend Error` because `message` must be optional. So we copy its types here.
|
|
1387
|
+
readonly name?: Error['name'];
|
|
1388
|
+
stack?: Error['stack'];
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
type SuccessResult<
|
|
1392
|
+
IsSync extends boolean = boolean,
|
|
1393
|
+
OptionsType extends CommonOptions = CommonOptions,
|
|
1394
|
+
> = InstanceType<typeof CommonResult<IsSync, OptionsType>> & OmitErrorIfReject<OptionsType['reject']>;
|
|
1395
|
+
|
|
1396
|
+
type OmitErrorIfReject<RejectOption extends CommonOptions['reject']> = {
|
|
1397
|
+
[ErrorProperty in ErrorProperties]: RejectOption extends false ? unknown : never
|
|
1398
|
+
};
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
Result of a subprocess successful execution.
|
|
1402
|
+
|
|
1403
|
+
When the subprocess fails, it is rejected with an `ExecaError` instead.
|
|
1404
|
+
*/
|
|
1405
|
+
type Result<OptionsType extends Options = Options> = SuccessResult<false, OptionsType>;
|
|
1406
|
+
|
|
1407
|
+
/**
|
|
1408
|
+
Result of a subprocess successful execution.
|
|
1409
|
+
|
|
1410
|
+
When the subprocess fails, it is rejected with an `ExecaError` instead.
|
|
1411
|
+
*/
|
|
1412
|
+
type SyncResult<OptionsType extends SyncOptions = SyncOptions> = SuccessResult<true, OptionsType>;
|
|
1413
|
+
|
|
1414
|
+
type VerboseOption = FdGenericOption<
|
|
1415
|
+
| 'none'
|
|
1416
|
+
| 'short'
|
|
1417
|
+
| 'full'
|
|
1418
|
+
| VerboseFunction
|
|
1419
|
+
>;
|
|
1420
|
+
|
|
1421
|
+
type VerboseFunction = (verboseLine: string, verboseObject: MinimalVerboseObject) => string | void;
|
|
1422
|
+
|
|
1423
|
+
type GenericVerboseObject = {
|
|
1424
|
+
/**
|
|
1425
|
+
Event type. This can be:
|
|
1426
|
+
- `'command'`: subprocess start
|
|
1427
|
+
- `'output'`: `stdout`/`stderr` output
|
|
1428
|
+
- `'ipc'`: IPC output
|
|
1429
|
+
- `'error'`: subprocess failure
|
|
1430
|
+
- `'duration'`: subprocess success or failure
|
|
734
1431
|
*/
|
|
735
|
-
|
|
1432
|
+
type: 'command' | 'output' | 'ipc' | 'error' | 'duration';
|
|
736
1433
|
|
|
737
1434
|
/**
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
1435
|
+
Depending on `verboseObject.type`, this is:
|
|
1436
|
+
- `'command'`: the `result.escapedCommand`
|
|
1437
|
+
- `'output'`: one line from `result.stdout` or `result.stderr`
|
|
1438
|
+
- `'ipc'`: one IPC message from `result.ipcOutput`
|
|
1439
|
+
- `'error'`: the `error.shortMessage`
|
|
1440
|
+
- `'duration'`: the `result.durationMs`
|
|
1441
|
+
*/
|
|
1442
|
+
message: string;
|
|
741
1443
|
|
|
742
|
-
|
|
1444
|
+
/**
|
|
1445
|
+
The file and arguments that were run. This is the same as `result.escapedCommand`.
|
|
1446
|
+
*/
|
|
1447
|
+
escapedCommand: string;
|
|
1448
|
+
|
|
1449
|
+
/**
|
|
1450
|
+
Serial number identifying the subprocess within the current process. It is incremented from `'0'`.
|
|
1451
|
+
|
|
1452
|
+
This is helpful when multiple subprocesses are running at the same time.
|
|
1453
|
+
|
|
1454
|
+
This is similar to a [PID](https://en.wikipedia.org/wiki/Process_identifier) except it has no maximum limit, which means it never repeats. Also, it is usually shorter.
|
|
1455
|
+
*/
|
|
1456
|
+
commandId: string;
|
|
743
1457
|
|
|
744
|
-
|
|
1458
|
+
/**
|
|
1459
|
+
Event date/time.
|
|
745
1460
|
*/
|
|
746
|
-
|
|
1461
|
+
timestamp: Date;
|
|
747
1462
|
|
|
748
1463
|
/**
|
|
749
|
-
|
|
1464
|
+
Whether another subprocess is piped into this subprocess. This is `false` when `result.pipedFrom` is empty.
|
|
1465
|
+
*/
|
|
1466
|
+
piped: boolean;
|
|
1467
|
+
};
|
|
750
1468
|
|
|
751
|
-
|
|
1469
|
+
type MinimalVerboseObject = GenericVerboseObject & {
|
|
1470
|
+
// We cannot use the `CommonOptions` type because it would make this type recursive
|
|
1471
|
+
options: object;
|
|
1472
|
+
result?: never;
|
|
1473
|
+
};
|
|
1474
|
+
|
|
1475
|
+
type CommonOptions<IsSync extends boolean = boolean> = {
|
|
1476
|
+
/**
|
|
1477
|
+
Prefer locally installed binaries when looking for a binary to execute.
|
|
1478
|
+
|
|
1479
|
+
@default `true` with `$`, `false` otherwise
|
|
752
1480
|
*/
|
|
753
|
-
readonly
|
|
1481
|
+
readonly preferLocal?: boolean;
|
|
754
1482
|
|
|
755
1483
|
/**
|
|
756
|
-
|
|
1484
|
+
Preferred path to find locally installed binaries, when using the `preferLocal` option.
|
|
1485
|
+
|
|
1486
|
+
@default `cwd` option
|
|
757
1487
|
*/
|
|
758
|
-
readonly
|
|
1488
|
+
readonly localDir?: string | URL;
|
|
759
1489
|
|
|
760
1490
|
/**
|
|
761
|
-
|
|
1491
|
+
If `true`, runs with Node.js. The first argument must be a Node.js file.
|
|
1492
|
+
|
|
1493
|
+
The subprocess inherits the current Node.js [CLI flags](https://nodejs.org/api/cli.html#options) and version. This can be overridden using the `nodeOptions` and `nodePath` options.
|
|
1494
|
+
|
|
1495
|
+
@default `true` with `execaNode()`, `false` otherwise
|
|
762
1496
|
*/
|
|
763
|
-
readonly
|
|
1497
|
+
readonly node?: boolean;
|
|
764
1498
|
|
|
765
1499
|
/**
|
|
766
|
-
|
|
1500
|
+
List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable.
|
|
767
1501
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
1502
|
+
Requires the `node` option to be `true`.
|
|
1503
|
+
|
|
1504
|
+
@default [`process.execArgv`](https://nodejs.org/api/process.html#process_process_execargv) (current Node.js CLI flags)
|
|
1505
|
+
*/
|
|
1506
|
+
readonly nodeOptions?: readonly string[];
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
Path to the Node.js executable.
|
|
1510
|
+
|
|
1511
|
+
Requires the `node` option to be `true`.
|
|
1512
|
+
|
|
1513
|
+
@default [`process.execPath`](https://nodejs.org/api/process.html#process_process_execpath) (current Node.js executable)
|
|
1514
|
+
*/
|
|
1515
|
+
readonly nodePath?: string | URL;
|
|
1516
|
+
|
|
1517
|
+
/**
|
|
1518
|
+
If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).
|
|
1519
|
+
|
|
1520
|
+
Uses [`/bin/sh`](https://en.wikipedia.org/wiki/Unix_shell) on UNIX and [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows.
|
|
1521
|
+
|
|
1522
|
+
We recommend against using this option.
|
|
772
1523
|
|
|
773
1524
|
@default false
|
|
774
1525
|
*/
|
|
775
|
-
readonly shell?: boolean | string;
|
|
1526
|
+
readonly shell?: boolean | string | URL;
|
|
776
1527
|
|
|
777
1528
|
/**
|
|
778
|
-
|
|
1529
|
+
Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.
|
|
779
1530
|
|
|
780
|
-
|
|
1531
|
+
This is also used to resolve the `nodePath` option when it is a relative path.
|
|
1532
|
+
|
|
1533
|
+
@default process.cwd()
|
|
781
1534
|
*/
|
|
782
|
-
readonly
|
|
1535
|
+
readonly cwd?: string | URL;
|
|
783
1536
|
|
|
784
1537
|
/**
|
|
785
|
-
|
|
1538
|
+
[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).
|
|
786
1539
|
|
|
787
|
-
|
|
1540
|
+
Unless the `extendEnv` option is `false`, the subprocess also uses the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).
|
|
1541
|
+
|
|
1542
|
+
@default [process.env](https://nodejs.org/api/process.html#processenv)
|
|
788
1543
|
*/
|
|
789
|
-
readonly
|
|
1544
|
+
readonly env?: Readonly<Partial<Record<string, string>>>;
|
|
790
1545
|
|
|
791
1546
|
/**
|
|
792
|
-
|
|
1547
|
+
If `true`, the subprocess uses both the `env` option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).
|
|
1548
|
+
If `false`, only the `env` option is used, not `process.env`.
|
|
793
1549
|
|
|
794
|
-
@default
|
|
1550
|
+
@default true
|
|
795
1551
|
*/
|
|
796
|
-
readonly
|
|
1552
|
+
readonly extendEnv?: boolean;
|
|
797
1553
|
|
|
798
1554
|
/**
|
|
799
|
-
|
|
1555
|
+
Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).
|
|
800
1556
|
|
|
801
|
-
|
|
1557
|
+
See also the `inputFile` and `stdin` options.
|
|
802
1558
|
*/
|
|
803
|
-
readonly
|
|
1559
|
+
readonly input?: string | Uint8Array | Readable;
|
|
804
1560
|
|
|
805
1561
|
/**
|
|
806
|
-
|
|
1562
|
+
Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).
|
|
807
1563
|
|
|
808
|
-
|
|
1564
|
+
See also the `input` and `stdin` options.
|
|
1565
|
+
*/
|
|
1566
|
+
readonly inputFile?: string | URL;
|
|
809
1567
|
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
import {execa} from 'execa';
|
|
1568
|
+
/**
|
|
1569
|
+
How to setup the subprocess' [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be `'pipe'`, `'overlapped'`, `'ignore`, `'inherit'`, a file descriptor integer, a Node.js `Readable` stream, a web `ReadableStream`, a `{ file: 'path' }` object, a file URL, an `Iterable`, an `AsyncIterable`, an `Uint8Array`, a generator function, a `Duplex` or a web `TransformStream`.
|
|
813
1570
|
|
|
814
|
-
|
|
815
|
-
const subprocess = execa('node', [], {signal: abortController.signal});
|
|
1571
|
+
This can be an array of values such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.
|
|
816
1572
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
1573
|
+
@default `'inherit'` with `$`, `'pipe'` otherwise
|
|
1574
|
+
*/
|
|
1575
|
+
readonly stdin?: StdinOptionCommon<IsSync>;
|
|
820
1576
|
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
1577
|
+
/**
|
|
1578
|
+
How to setup the subprocess' [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be `'pipe'`, `'overlapped'`, `'ignore`, `'inherit'`, a file descriptor integer, a Node.js `Writable` stream, a web `WritableStream`, a `{ file: 'path' }` object, a file URL, a generator function, a `Duplex` or a web `TransformStream`.
|
|
1579
|
+
|
|
1580
|
+
This can be an array of values such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.
|
|
1581
|
+
|
|
1582
|
+
@default 'pipe'
|
|
1583
|
+
*/
|
|
1584
|
+
readonly stdout?: StdoutStderrOptionCommon<IsSync>;
|
|
1585
|
+
|
|
1586
|
+
/**
|
|
1587
|
+
How to setup the subprocess' [standard error](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). This can be `'pipe'`, `'overlapped'`, `'ignore`, `'inherit'`, a file descriptor integer, a Node.js `Writable` stream, a web `WritableStream`, a `{ file: 'path' }` object, a file URL, a generator function, a `Duplex` or a web `TransformStream`.
|
|
1588
|
+
|
|
1589
|
+
This can be an array of values such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.
|
|
1590
|
+
|
|
1591
|
+
@default 'pipe'
|
|
828
1592
|
*/
|
|
829
|
-
readonly
|
|
1593
|
+
readonly stderr?: StdoutStderrOptionCommon<IsSync>;
|
|
830
1594
|
|
|
831
1595
|
/**
|
|
832
|
-
|
|
1596
|
+
Like the `stdin`, `stdout` and `stderr` options but for all [file descriptors](https://en.wikipedia.org/wiki/File_descriptor) at once. For example, `{stdio: ['ignore', 'pipe', 'pipe']}` is the same as `{stdin: 'ignore', stdout: 'pipe', stderr: 'pipe'}`.
|
|
1597
|
+
|
|
1598
|
+
A single string can be used as a shortcut.
|
|
1599
|
+
|
|
1600
|
+
The array can have more than 3 items, to create additional file descriptors beyond `stdin`/`stdout`/`stderr`.
|
|
1601
|
+
|
|
1602
|
+
@default 'pipe'
|
|
1603
|
+
*/
|
|
1604
|
+
readonly stdio?: StdioOptionsProperty<IsSync>;
|
|
1605
|
+
|
|
1606
|
+
/**
|
|
1607
|
+
Add a `subprocess.all` stream and a `result.all` property. They contain the combined/interleaved output of the subprocess' `stdout` and `stderr`.
|
|
833
1608
|
|
|
834
1609
|
@default false
|
|
835
1610
|
*/
|
|
836
|
-
readonly
|
|
1611
|
+
readonly all?: boolean;
|
|
837
1612
|
|
|
838
1613
|
/**
|
|
839
|
-
|
|
1614
|
+
If the subprocess outputs text, specifies its character encoding, either [`'utf8'`](https://en.wikipedia.org/wiki/UTF-8) or [`'utf16le'`](https://en.wikipedia.org/wiki/UTF-16).
|
|
840
1615
|
|
|
841
|
-
|
|
1616
|
+
If it outputs binary data instead, this should be either:
|
|
1617
|
+
- `'buffer'`: returns the binary output as an `Uint8Array`.
|
|
1618
|
+
- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications), [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.
|
|
1619
|
+
|
|
1620
|
+
The output is available with `result.stdout`, `result.stderr` and `result.stdio`.
|
|
1621
|
+
|
|
1622
|
+
@default 'utf8'
|
|
842
1623
|
*/
|
|
843
|
-
readonly
|
|
1624
|
+
readonly encoding?: EncodingOption;
|
|
844
1625
|
|
|
845
1626
|
/**
|
|
846
|
-
|
|
1627
|
+
Set `result.stdout`, `result.stderr`, `result.all` and `result.stdio` as arrays of strings, splitting the subprocess' output into lines.
|
|
1628
|
+
|
|
1629
|
+
This cannot be used if the `encoding` option is binary.
|
|
847
1630
|
|
|
848
|
-
|
|
1631
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
849
1632
|
|
|
850
1633
|
@default false
|
|
851
1634
|
*/
|
|
852
|
-
readonly
|
|
853
|
-
};
|
|
1635
|
+
readonly lines?: FdGenericOption<boolean>;
|
|
854
1636
|
|
|
855
|
-
type Options<EncodingType extends EncodingOption = DefaultEncodingOption> = {
|
|
856
1637
|
/**
|
|
857
|
-
|
|
1638
|
+
Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.
|
|
1639
|
+
|
|
1640
|
+
If the `lines` option is true, this applies to each output line instead.
|
|
858
1641
|
|
|
859
|
-
|
|
1642
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
1643
|
+
|
|
1644
|
+
@default true
|
|
860
1645
|
*/
|
|
861
|
-
readonly
|
|
1646
|
+
readonly stripFinalNewline?: FdGenericOption<boolean>;
|
|
862
1647
|
|
|
863
1648
|
/**
|
|
864
|
-
|
|
1649
|
+
Largest amount of data allowed on `stdout`, `stderr` and `stdio`.
|
|
1650
|
+
|
|
1651
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
865
1652
|
|
|
866
|
-
|
|
1653
|
+
When reached, `error.isMaxBuffer` becomes `true`.
|
|
1654
|
+
|
|
1655
|
+
@default 100_000_000
|
|
867
1656
|
*/
|
|
868
|
-
readonly
|
|
869
|
-
} & CommonOptions<EncodingType>;
|
|
1657
|
+
readonly maxBuffer?: FdGenericOption<number>;
|
|
870
1658
|
|
|
871
|
-
type NodeOptions<EncodingType extends EncodingOption = DefaultEncodingOption> = {
|
|
872
1659
|
/**
|
|
873
|
-
|
|
1660
|
+
When `buffer` is `false`, the `result.stdout`, `result.stderr`, `result.all` and `result.stdio` properties are not set.
|
|
874
1661
|
|
|
875
|
-
|
|
1662
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
1663
|
+
|
|
1664
|
+
@default true
|
|
876
1665
|
*/
|
|
877
|
-
readonly
|
|
1666
|
+
readonly buffer?: FdGenericOption<boolean>;
|
|
878
1667
|
|
|
879
1668
|
/**
|
|
880
|
-
|
|
1669
|
+
Enables exchanging messages with the subprocess using `subprocess.sendMessage(message)`, `subprocess.getOneMessage()` and `subprocess.getEachMessage()`.
|
|
881
1670
|
|
|
882
|
-
|
|
1671
|
+
The subprocess must be a Node.js file.
|
|
1672
|
+
|
|
1673
|
+
@default `true` if the `node`, `ipcInput` or `gracefulCancel` option is set, `false` otherwise
|
|
883
1674
|
*/
|
|
884
|
-
readonly
|
|
885
|
-
} & Options<EncodingType>;
|
|
1675
|
+
readonly ipc?: Unless<IsSync, boolean>;
|
|
886
1676
|
|
|
887
|
-
|
|
1677
|
+
/**
|
|
1678
|
+
Specify the kind of serialization used for sending messages between subprocesses when using the `ipc` option.
|
|
1679
|
+
|
|
1680
|
+
@default 'advanced'
|
|
1681
|
+
*/
|
|
1682
|
+
readonly serialization?: Unless<IsSync, 'json' | 'advanced'>;
|
|
888
1683
|
|
|
889
|
-
type ExecaReturnBase<StdoutStderrType extends StdoutStderrAll> = {
|
|
890
1684
|
/**
|
|
891
|
-
|
|
1685
|
+
Sends an IPC message when the subprocess starts.
|
|
892
1686
|
|
|
893
|
-
|
|
1687
|
+
The subprocess must be a Node.js file. The value's type depends on the `serialization` option.
|
|
894
1688
|
*/
|
|
895
|
-
|
|
1689
|
+
readonly ipcInput?: Unless<IsSync, Message>;
|
|
896
1690
|
|
|
897
1691
|
/**
|
|
898
|
-
|
|
1692
|
+
If `verbose` is `'short'`, prints the command on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)): its file, arguments, duration and (if it failed) error message.
|
|
1693
|
+
|
|
1694
|
+
If `verbose` is `'full'` or a function, the command's [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)), `stderr` and IPC messages are also printed.
|
|
1695
|
+
|
|
1696
|
+
A function can be passed to customize logging.
|
|
1697
|
+
|
|
1698
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
899
1699
|
|
|
900
|
-
|
|
901
|
-
Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execaCommand()`.
|
|
1700
|
+
@default 'none'
|
|
902
1701
|
*/
|
|
903
|
-
|
|
1702
|
+
readonly verbose?: VerboseOption;
|
|
904
1703
|
|
|
905
1704
|
/**
|
|
906
|
-
|
|
1705
|
+
Setting this to `false` resolves the result's promise with the error instead of rejecting it.
|
|
1706
|
+
|
|
1707
|
+
@default true
|
|
907
1708
|
*/
|
|
908
|
-
|
|
1709
|
+
readonly reject?: boolean;
|
|
909
1710
|
|
|
910
1711
|
/**
|
|
911
|
-
|
|
1712
|
+
If `timeout` is greater than `0`, the subprocess will be terminated if it runs for longer than that amount of milliseconds.
|
|
1713
|
+
|
|
1714
|
+
On timeout, `error.timedOut` becomes `true`.
|
|
1715
|
+
|
|
1716
|
+
@default 0
|
|
912
1717
|
*/
|
|
913
|
-
|
|
1718
|
+
readonly timeout?: number;
|
|
914
1719
|
|
|
915
1720
|
/**
|
|
916
|
-
|
|
1721
|
+
When the `cancelSignal` is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), terminate the subprocess using a `SIGTERM` signal.
|
|
1722
|
+
|
|
1723
|
+
When aborted, `error.isCanceled` becomes `true`.
|
|
1724
|
+
|
|
1725
|
+
@example
|
|
1726
|
+
```
|
|
1727
|
+
import {execaNode} from 'execa';
|
|
1728
|
+
|
|
1729
|
+
const controller = new AbortController();
|
|
1730
|
+
const cancelSignal = controller.signal;
|
|
1731
|
+
|
|
1732
|
+
setTimeout(() => {
|
|
1733
|
+
controller.abort();
|
|
1734
|
+
}, 5000);
|
|
1735
|
+
|
|
1736
|
+
try {
|
|
1737
|
+
await execaNode({cancelSignal})`build.js`;
|
|
1738
|
+
} catch (error) {
|
|
1739
|
+
if (error.isCanceled) {
|
|
1740
|
+
console.error('Canceled by cancelSignal.');
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
throw error;
|
|
1744
|
+
}
|
|
1745
|
+
```
|
|
917
1746
|
*/
|
|
918
|
-
|
|
1747
|
+
readonly cancelSignal?: Unless<IsSync, AbortSignal>;
|
|
919
1748
|
|
|
920
1749
|
/**
|
|
921
|
-
|
|
1750
|
+
When the `cancelSignal` option is [aborted](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort), do not send any `SIGTERM`. Instead, abort the [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) returned by `getCancelSignal()`. The subprocess should use it to terminate gracefully.
|
|
1751
|
+
|
|
1752
|
+
The subprocess must be a Node.js file.
|
|
1753
|
+
|
|
1754
|
+
When aborted, `error.isGracefullyCanceled` becomes `true`.
|
|
1755
|
+
|
|
1756
|
+
@default false
|
|
922
1757
|
*/
|
|
923
|
-
|
|
1758
|
+
readonly gracefulCancel?: Unless<IsSync, boolean>;
|
|
924
1759
|
|
|
925
1760
|
/**
|
|
926
|
-
|
|
1761
|
+
If the subprocess is terminated but does not exit, forcefully exit it by sending [`SIGKILL`](https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL).
|
|
1762
|
+
|
|
1763
|
+
When this happens, `error.isForcefullyTerminated` becomes `true`.
|
|
1764
|
+
|
|
1765
|
+
@default 5000
|
|
927
1766
|
*/
|
|
928
|
-
|
|
1767
|
+
readonly forceKillAfterDelay?: Unless<IsSync, number | boolean>;
|
|
929
1768
|
|
|
930
1769
|
/**
|
|
931
|
-
|
|
1770
|
+
Default [signal](https://en.wikipedia.org/wiki/Signal_(IPC)) used to terminate the subprocess.
|
|
1771
|
+
|
|
1772
|
+
This can be either a name (like `'SIGTERM'`) or a number (like `9`).
|
|
1773
|
+
|
|
1774
|
+
@default 'SIGTERM'
|
|
932
1775
|
*/
|
|
933
|
-
|
|
1776
|
+
readonly killSignal?: keyof SignalConstants | number;
|
|
934
1777
|
|
|
935
1778
|
/**
|
|
936
|
-
|
|
1779
|
+
Run the subprocess independently from the current process.
|
|
937
1780
|
|
|
938
|
-
|
|
1781
|
+
@default false
|
|
939
1782
|
*/
|
|
940
|
-
|
|
1783
|
+
readonly detached?: Unless<IsSync, boolean>;
|
|
941
1784
|
|
|
942
1785
|
/**
|
|
943
|
-
|
|
1786
|
+
Kill the subprocess when the current process exits.
|
|
944
1787
|
|
|
945
|
-
|
|
1788
|
+
@default true
|
|
946
1789
|
*/
|
|
947
|
-
|
|
1790
|
+
readonly cleanup?: Unless<IsSync, boolean>;
|
|
1791
|
+
|
|
1792
|
+
/**
|
|
1793
|
+
Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.
|
|
1794
|
+
|
|
1795
|
+
@default current user identifier
|
|
1796
|
+
*/
|
|
1797
|
+
readonly uid?: number;
|
|
948
1798
|
|
|
949
1799
|
/**
|
|
950
|
-
|
|
1800
|
+
Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.
|
|
1801
|
+
|
|
1802
|
+
@default current group identifier
|
|
951
1803
|
*/
|
|
952
|
-
|
|
1804
|
+
readonly gid?: number;
|
|
1805
|
+
|
|
1806
|
+
/**
|
|
1807
|
+
Value of [`argv[0]`](https://nodejs.org/api/process.html#processargv0) sent to the subprocess.
|
|
1808
|
+
|
|
1809
|
+
@default file being executed
|
|
1810
|
+
*/
|
|
1811
|
+
readonly argv0?: string;
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
On Windows, do not create a new console window.
|
|
1815
|
+
|
|
1816
|
+
@default true
|
|
1817
|
+
*/
|
|
1818
|
+
readonly windowsHide?: boolean;
|
|
1819
|
+
|
|
1820
|
+
/**
|
|
1821
|
+
If `false`, escapes the command arguments on Windows.
|
|
1822
|
+
|
|
1823
|
+
@default `true` if the `shell` option is `true`, `false` otherwise
|
|
1824
|
+
*/
|
|
1825
|
+
readonly windowsVerbatimArguments?: boolean;
|
|
953
1826
|
};
|
|
954
1827
|
|
|
955
|
-
|
|
956
|
-
|
|
1828
|
+
/**
|
|
1829
|
+
Subprocess options.
|
|
1830
|
+
|
|
1831
|
+
Some options are related to the subprocess output: `verbose`, `lines`, `stripFinalNewline`, `buffer`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `all` (both stdout and stderr), `ipc`, `fd3`, etc.
|
|
1832
|
+
|
|
1833
|
+
@example
|
|
1834
|
+
|
|
1835
|
+
```
|
|
1836
|
+
// Same value for stdout and stderr
|
|
1837
|
+
await execa({verbose: 'full'})`npm run build`;
|
|
1838
|
+
|
|
1839
|
+
// Different values for stdout and stderr
|
|
1840
|
+
await execa({verbose: {stdout: 'none', stderr: 'full'}})`npm run build`;
|
|
1841
|
+
```
|
|
1842
|
+
*/
|
|
1843
|
+
type Options = CommonOptions<false>;
|
|
957
1844
|
|
|
958
1845
|
/**
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1846
|
+
Subprocess options, with synchronous methods.
|
|
1847
|
+
|
|
1848
|
+
Some options are related to the subprocess output: `verbose`, `lines`, `stripFinalNewline`, `buffer`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `all` (both stdout and stderr), `ipc`, `fd3`, etc.
|
|
1849
|
+
|
|
1850
|
+
@example
|
|
1851
|
+
|
|
1852
|
+
```
|
|
1853
|
+
// Same value for stdout and stderr
|
|
1854
|
+
execaSync({verbose: 'full'})`npm run build`;
|
|
1855
|
+
|
|
1856
|
+
// Different values for stdout and stderr
|
|
1857
|
+
execaSync({verbose: {stdout: 'none', stderr: 'full'}})`npm run build`;
|
|
1858
|
+
```
|
|
1859
|
+
*/
|
|
1860
|
+
type SyncOptions = CommonOptions<true>;
|
|
1861
|
+
|
|
1862
|
+
type StricterOptions<
|
|
1863
|
+
WideOptions extends CommonOptions,
|
|
1864
|
+
StrictOptions extends CommonOptions,
|
|
1865
|
+
> = WideOptions extends StrictOptions ? WideOptions : StrictOptions;
|
|
1866
|
+
|
|
1867
|
+
type TemplateExpressionItem =
|
|
1868
|
+
| string
|
|
1869
|
+
| number
|
|
1870
|
+
| Result
|
|
1871
|
+
| SyncResult;
|
|
1872
|
+
|
|
1873
|
+
/**
|
|
1874
|
+
Value allowed inside `${...}` when using the template string syntax.
|
|
967
1875
|
*/
|
|
968
|
-
type
|
|
1876
|
+
type TemplateExpression = TemplateExpressionItem | readonly TemplateExpressionItem[];
|
|
1877
|
+
|
|
1878
|
+
// `subprocess.pipe()` options
|
|
1879
|
+
type PipeOptions = {
|
|
969
1880
|
/**
|
|
970
|
-
|
|
1881
|
+
Which stream to pipe from the source subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.
|
|
971
1882
|
|
|
972
|
-
This
|
|
973
|
-
- the `all` option is `false` (default value)
|
|
974
|
-
- `execaSync()` was used
|
|
1883
|
+
`"all"` pipes both `stdout` and `stderr`. This requires the `all` option to be `true`.
|
|
975
1884
|
*/
|
|
976
|
-
|
|
1885
|
+
readonly from?: FromOption;
|
|
977
1886
|
|
|
978
1887
|
/**
|
|
979
|
-
|
|
1888
|
+
Which stream to pipe to the destination subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.
|
|
1889
|
+
*/
|
|
1890
|
+
readonly to?: ToOption;
|
|
980
1891
|
|
|
981
|
-
|
|
1892
|
+
/**
|
|
1893
|
+
Unpipe the subprocess when the signal aborts.
|
|
982
1894
|
*/
|
|
983
|
-
|
|
984
|
-
}
|
|
1895
|
+
readonly unpipeSignal?: AbortSignal;
|
|
1896
|
+
};
|
|
985
1897
|
|
|
986
|
-
|
|
1898
|
+
// `subprocess.pipe()`
|
|
1899
|
+
type PipableSubprocess = {
|
|
987
1900
|
/**
|
|
988
|
-
|
|
1901
|
+
[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the subprocess' `stdout` to a second Execa subprocess' `stdin`. This resolves with that second subprocess' result. If either subprocess is rejected, this is rejected with that subprocess' error instead.
|
|
989
1902
|
|
|
990
|
-
|
|
1903
|
+
This follows the same syntax as `execa(file, arguments?, options?)` except both regular options and pipe-specific options can be specified.
|
|
991
1904
|
*/
|
|
992
|
-
|
|
1905
|
+
pipe<OptionsType extends Options & PipeOptions = {}>(
|
|
1906
|
+
file: string | URL,
|
|
1907
|
+
arguments?: readonly string[],
|
|
1908
|
+
options?: OptionsType,
|
|
1909
|
+
): Promise<Result<OptionsType>> & PipableSubprocess;
|
|
1910
|
+
pipe<OptionsType extends Options & PipeOptions = {}>(
|
|
1911
|
+
file: string | URL,
|
|
1912
|
+
options?: OptionsType,
|
|
1913
|
+
): Promise<Result<OptionsType>> & PipableSubprocess;
|
|
993
1914
|
|
|
994
1915
|
/**
|
|
995
|
-
|
|
1916
|
+
Like `subprocess.pipe(file, arguments?, options?)` but using a `command` template string instead. This follows the same syntax as `$`.
|
|
996
1917
|
*/
|
|
997
|
-
|
|
1918
|
+
pipe(templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[]):
|
|
1919
|
+
Promise<Result<{}>> & PipableSubprocess;
|
|
1920
|
+
pipe<OptionsType extends Options & PipeOptions = {}>(options: OptionsType):
|
|
1921
|
+
(templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[])
|
|
1922
|
+
=> Promise<Result<OptionsType>> & PipableSubprocess;
|
|
998
1923
|
|
|
999
1924
|
/**
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
This is `undefined` unless the child process exited due to an `error` event or a timeout.
|
|
1925
|
+
Like `subprocess.pipe(file, arguments?, options?)` but using the return value of another `execa()` call instead.
|
|
1003
1926
|
*/
|
|
1004
|
-
|
|
1005
|
-
|
|
1927
|
+
pipe<Destination extends ResultPromise>(destination: Destination, options?: PipeOptions):
|
|
1928
|
+
Promise<Awaited<Destination>> & PipableSubprocess;
|
|
1929
|
+
};
|
|
1006
1930
|
|
|
1007
|
-
|
|
1931
|
+
// `subprocess.readable|duplex|iterable()` options
|
|
1932
|
+
type ReadableOptions = {
|
|
1008
1933
|
/**
|
|
1009
|
-
|
|
1934
|
+
Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.
|
|
1010
1935
|
|
|
1011
|
-
This
|
|
1012
|
-
|
|
1013
|
-
|
|
1936
|
+
`"all"` reads both `stdout` and `stderr`. This requires the `all` option to be `true`.
|
|
1937
|
+
|
|
1938
|
+
@default 'stdout'
|
|
1014
1939
|
*/
|
|
1015
|
-
|
|
1940
|
+
readonly from?: FromOption;
|
|
1016
1941
|
|
|
1017
1942
|
/**
|
|
1018
|
-
|
|
1943
|
+
If `false`, iterates over lines. Each line is a string.
|
|
1944
|
+
|
|
1945
|
+
If `true`, iterates over arbitrary chunks of data. Each line is an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) (with `subprocess.iterable()`) or a [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer) (with `subprocess.readable()`/`subprocess.duplex()`).
|
|
1946
|
+
|
|
1947
|
+
This is always `true` when the `encoding` option is binary.
|
|
1948
|
+
|
|
1949
|
+
@default `false` with `subprocess.iterable()`, `true` otherwise
|
|
1019
1950
|
*/
|
|
1020
|
-
|
|
1021
|
-
} & ExecaSyncError<StdoutStderrType>;
|
|
1951
|
+
readonly binary?: boolean;
|
|
1022
1952
|
|
|
1023
|
-
type KillOptions = {
|
|
1024
1953
|
/**
|
|
1025
|
-
|
|
1954
|
+
If both this option and the `binary` option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.
|
|
1026
1955
|
|
|
1027
|
-
|
|
1956
|
+
@default `false` with `subprocess.iterable()`, `true` otherwise
|
|
1957
|
+
*/
|
|
1958
|
+
readonly preserveNewlines?: boolean;
|
|
1959
|
+
};
|
|
1028
1960
|
|
|
1029
|
-
|
|
1961
|
+
// `subprocess.writable|duplex()` options
|
|
1962
|
+
type WritableOptions = {
|
|
1963
|
+
/**
|
|
1964
|
+
Which stream to write to the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.
|
|
1965
|
+
|
|
1966
|
+
@default 'stdin'
|
|
1030
1967
|
*/
|
|
1031
|
-
|
|
1968
|
+
readonly to?: ToOption;
|
|
1032
1969
|
};
|
|
1033
1970
|
|
|
1034
|
-
|
|
1971
|
+
// `subprocess.duplex()` options
|
|
1972
|
+
type DuplexOptions = ReadableOptions & WritableOptions;
|
|
1973
|
+
|
|
1974
|
+
// `subprocess.iterable()` return value
|
|
1975
|
+
type SubprocessAsyncIterable<
|
|
1976
|
+
BinaryOption extends boolean | undefined,
|
|
1977
|
+
EncodingOption extends Options['encoding'],
|
|
1978
|
+
> = AsyncIterableIterator<
|
|
1979
|
+
EncodingOption extends BinaryEncodingOption
|
|
1980
|
+
? Uint8Array
|
|
1981
|
+
: BinaryOption extends true
|
|
1982
|
+
? Uint8Array
|
|
1983
|
+
: string
|
|
1984
|
+
>;
|
|
1985
|
+
|
|
1986
|
+
// `subprocess.stdin|stdout|stderr|stdio`
|
|
1987
|
+
type SubprocessStdioStream<
|
|
1988
|
+
FdNumber extends string,
|
|
1989
|
+
OptionsType extends Options,
|
|
1990
|
+
> = SubprocessStream<FdNumber, IgnoresSubprocessOutput<FdNumber, OptionsType>, OptionsType>;
|
|
1991
|
+
|
|
1992
|
+
type SubprocessStream<
|
|
1993
|
+
FdNumber extends string,
|
|
1994
|
+
StreamResultIgnored,
|
|
1995
|
+
OptionsType extends Options,
|
|
1996
|
+
> = StreamResultIgnored extends true
|
|
1997
|
+
? null
|
|
1998
|
+
: InputOutputStream<IsInputFd<FdNumber, OptionsType>>;
|
|
1999
|
+
|
|
2000
|
+
type InputOutputStream<IsInput extends boolean> = IsInput extends true
|
|
2001
|
+
? Writable
|
|
2002
|
+
: Readable;
|
|
2003
|
+
|
|
2004
|
+
// `subprocess.stdio`
|
|
2005
|
+
type SubprocessStdioArray<OptionsType extends Options> = MapStdioStreams<StdioOptionNormalizedArray<OptionsType>, OptionsType>;
|
|
2006
|
+
|
|
2007
|
+
// We cannot use mapped types because it must be compatible with Node.js `ChildProcess["stdio"]` which uses a tuple with exactly 5 items
|
|
2008
|
+
type MapStdioStreams<
|
|
2009
|
+
StdioOptionsArrayType,
|
|
2010
|
+
OptionsType extends Options,
|
|
2011
|
+
> = [
|
|
2012
|
+
SubprocessStdioStream<'0', OptionsType>,
|
|
2013
|
+
SubprocessStdioStream<'1', OptionsType>,
|
|
2014
|
+
SubprocessStdioStream<'2', OptionsType>,
|
|
2015
|
+
'3' extends keyof StdioOptionsArrayType ? SubprocessStdioStream<'3', OptionsType> : never,
|
|
2016
|
+
'4' extends keyof StdioOptionsArrayType ? SubprocessStdioStream<'4', OptionsType> : never,
|
|
2017
|
+
];
|
|
2018
|
+
|
|
2019
|
+
// `subprocess.all`
|
|
2020
|
+
type SubprocessAll<OptionsType extends Options> = AllStream<AllIgnored<OptionsType['all'], OptionsType>>;
|
|
2021
|
+
|
|
2022
|
+
type AllStream<IsIgnored> = IsIgnored extends true ? undefined : Readable;
|
|
2023
|
+
|
|
2024
|
+
type AllIgnored<
|
|
2025
|
+
AllOption,
|
|
2026
|
+
OptionsType extends Options,
|
|
2027
|
+
> = AllOption extends true
|
|
2028
|
+
? IgnoresSubprocessOutput<'1', OptionsType> extends true
|
|
2029
|
+
? IgnoresSubprocessOutput<'2', OptionsType>
|
|
2030
|
+
: false
|
|
2031
|
+
: true;
|
|
2032
|
+
|
|
2033
|
+
type ExecaCustomSubprocess<OptionsType extends Options> = {
|
|
1035
2034
|
/**
|
|
1036
|
-
|
|
2035
|
+
Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).
|
|
1037
2036
|
|
|
1038
|
-
This is `undefined` if
|
|
1039
|
-
- the `all` option is `false` (the default value)
|
|
1040
|
-
- both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio)
|
|
2037
|
+
This is `undefined` if the subprocess failed to spawn.
|
|
1041
2038
|
*/
|
|
1042
|
-
|
|
2039
|
+
pid?: number;
|
|
2040
|
+
|
|
2041
|
+
/**
|
|
2042
|
+
The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.
|
|
1043
2043
|
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
2044
|
+
This is `null` if the `stdin` option is set to `'inherit'`, `'ignore'`, `Readable` or `integer`.
|
|
2045
|
+
*/
|
|
2046
|
+
stdin: SubprocessStdioStream<'0', OptionsType>;
|
|
1047
2047
|
|
|
1048
2048
|
/**
|
|
1049
|
-
|
|
2049
|
+
The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.
|
|
2050
|
+
|
|
2051
|
+
This is `null` if the `stdout` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
1050
2052
|
*/
|
|
1051
|
-
|
|
2053
|
+
stdout: SubprocessStdioStream<'1', OptionsType>;
|
|
1052
2054
|
|
|
1053
2055
|
/**
|
|
1054
|
-
|
|
2056
|
+
The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.
|
|
2057
|
+
|
|
2058
|
+
This is `null` if the `stderr` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
1055
2059
|
*/
|
|
1056
|
-
|
|
2060
|
+
stderr: SubprocessStdioStream<'2', OptionsType>;
|
|
1057
2061
|
|
|
1058
2062
|
/**
|
|
1059
|
-
|
|
1060
|
-
- Another `execa()` return value
|
|
1061
|
-
- A writable stream
|
|
1062
|
-
- A file path string
|
|
2063
|
+
Stream combining/interleaving `subprocess.stdout` and `subprocess.stderr`.
|
|
1063
2064
|
|
|
1064
|
-
|
|
2065
|
+
This requires the `all` option to be `true`.
|
|
1065
2066
|
|
|
1066
|
-
|
|
2067
|
+
This is `undefined` if `stdout` and `stderr` options are set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
1067
2068
|
*/
|
|
1068
|
-
|
|
1069
|
-
pipeStdout?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
|
|
2069
|
+
all: SubprocessAll<OptionsType>;
|
|
1070
2070
|
|
|
1071
2071
|
/**
|
|
1072
|
-
|
|
2072
|
+
The subprocess `stdin`, `stdout`, `stderr` and other files descriptors as an array of streams.
|
|
1073
2073
|
|
|
1074
|
-
|
|
2074
|
+
Each array item is `null` if the corresponding `stdin`, `stdout`, `stderr` or `stdio` option is set to `'inherit'`, `'ignore'`, `Stream` or `integer`, or if the `buffer` option is `false`.
|
|
1075
2075
|
*/
|
|
1076
|
-
|
|
1077
|
-
pipeStderr?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
|
|
2076
|
+
stdio: SubprocessStdioArray<OptionsType>;
|
|
1078
2077
|
|
|
1079
2078
|
/**
|
|
1080
|
-
|
|
2079
|
+
Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the `killSignal` option. `killSignal` defaults to `SIGTERM`, which terminates the subprocess.
|
|
1081
2080
|
|
|
1082
|
-
|
|
2081
|
+
This returns `false` when the signal could not be sent, for example when the subprocess has already exited.
|
|
2082
|
+
|
|
2083
|
+
When an error is passed as argument, it is set to the subprocess' `error.cause`. The subprocess is then terminated with the default signal. This does not emit the [`error` event](https://nodejs.org/api/child_process.html#event-error).
|
|
2084
|
+
|
|
2085
|
+
[More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)
|
|
1083
2086
|
*/
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
2087
|
+
kill(signal?: keyof SignalConstants | number, error?: Error): boolean;
|
|
2088
|
+
kill(error?: Error): boolean;
|
|
2089
|
+
|
|
2090
|
+
/**
|
|
2091
|
+
Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.
|
|
2092
|
+
*/
|
|
2093
|
+
[Symbol.asyncIterator](): SubprocessAsyncIterable<undefined, OptionsType['encoding']>;
|
|
1087
2094
|
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
2095
|
+
/**
|
|
2096
|
+
Same as `subprocess[Symbol.asyncIterator]` except options can be provided.
|
|
2097
|
+
*/
|
|
2098
|
+
iterable<IterableOptions extends ReadableOptions = {}>(readableOptions?: IterableOptions): SubprocessAsyncIterable<IterableOptions['binary'], OptionsType['encoding']>;
|
|
1091
2099
|
|
|
1092
|
-
|
|
2100
|
+
/**
|
|
2101
|
+
Converts the subprocess to a readable stream.
|
|
2102
|
+
*/
|
|
2103
|
+
readable(readableOptions?: ReadableOptions): Readable;
|
|
2104
|
+
|
|
2105
|
+
/**
|
|
2106
|
+
Converts the subprocess to a writable stream.
|
|
2107
|
+
*/
|
|
2108
|
+
writable(writableOptions?: WritableOptions): Writable;
|
|
2109
|
+
|
|
2110
|
+
/**
|
|
2111
|
+
Converts the subprocess to a duplex stream.
|
|
2112
|
+
*/
|
|
2113
|
+
duplex(duplexOptions?: DuplexOptions): Duplex;
|
|
2114
|
+
}
|
|
2115
|
+
& IpcMethods<HasIpc<OptionsType>, OptionsType['serialization']>
|
|
2116
|
+
& PipableSubprocess;
|
|
2117
|
+
|
|
2118
|
+
/**
|
|
2119
|
+
[`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with additional methods and properties.
|
|
2120
|
+
*/
|
|
2121
|
+
type Subprocess<OptionsType extends Options = Options> =
|
|
2122
|
+
& Omit<ChildProcess, keyof ExecaCustomSubprocess<OptionsType>>
|
|
2123
|
+
& ExecaCustomSubprocess<OptionsType>;
|
|
2124
|
+
|
|
2125
|
+
/**
|
|
2126
|
+
The return value of all asynchronous methods is both:
|
|
2127
|
+
- the subprocess.
|
|
2128
|
+
- a `Promise` either resolving with its successful `result`, or rejecting with its `error`.
|
|
2129
|
+
*/
|
|
2130
|
+
type ResultPromise<OptionsType extends Options = Options> =
|
|
2131
|
+
& Subprocess<OptionsType>
|
|
2132
|
+
& Promise<Result<OptionsType>>;
|
|
2133
|
+
|
|
2134
|
+
type ExecuteCommandOptions = Omit<Options, 'cancelSignal'> & {
|
|
1093
2135
|
command: string;
|
|
1094
2136
|
args?: string[];
|
|
1095
2137
|
cwd?: string;
|
|
1096
2138
|
ignoreError?: boolean;
|
|
1097
|
-
env?: Record<string,
|
|
2139
|
+
env?: Record<string, string>;
|
|
2140
|
+
signal?: AbortSignal;
|
|
1098
2141
|
};
|
|
1099
|
-
declare function executeCommand(options: ExecuteCommandOptions):
|
|
2142
|
+
declare function executeCommand(options: ExecuteCommandOptions): ResultPromise;
|
|
1100
2143
|
declare function executeCommandSync(options: ExecuteCommandOptions): string;
|
|
1101
2144
|
declare function executeNodeCommand({ scriptPath, args, options, }: {
|
|
1102
2145
|
scriptPath: string;
|
|
1103
2146
|
args?: string[];
|
|
1104
|
-
options?:
|
|
1105
|
-
}):
|
|
2147
|
+
options?: Options;
|
|
2148
|
+
}): ResultPromise;
|
|
1106
2149
|
|
|
1107
2150
|
type PackageJsonWithDepsAndDevDeps = PackageJson & Required<Pick<PackageJson, 'dependencies' | 'devDependencies'>>;
|
|
1108
2151
|
type PackageJsonWithMaybeDeps = Partial<Pick<PackageJson, 'dependencies' | 'devDependencies' | 'peerDependencies' | 'files'>>;
|
|
@@ -1126,6 +2169,10 @@ declare enum PackageManagerName {
|
|
|
1126
2169
|
PNPM = "pnpm",
|
|
1127
2170
|
BUN = "bun"
|
|
1128
2171
|
}
|
|
2172
|
+
declare const indentSymbol: unique symbol;
|
|
2173
|
+
type PackageJsonWithIndent = PackageJsonWithDepsAndDevDeps & {
|
|
2174
|
+
[indentSymbol]?: any;
|
|
2175
|
+
};
|
|
1129
2176
|
/**
|
|
1130
2177
|
* Extract package name and version from input
|
|
1131
2178
|
*
|
|
@@ -1162,7 +2209,7 @@ declare abstract class JsPackageManager {
|
|
|
1162
2209
|
/** Cache for installed version results to avoid repeated file system calls. */
|
|
1163
2210
|
static readonly installedVersionCache: Map<string, string | null>;
|
|
1164
2211
|
/** Cache for package.json files to avoid repeated file system calls. */
|
|
1165
|
-
static readonly packageJsonCache: Map<string,
|
|
2212
|
+
static readonly packageJsonCache: Map<string, PackageJsonWithIndent>;
|
|
1166
2213
|
constructor(options?: JsPackageManagerOptions);
|
|
1167
2214
|
/** Runs arbitrary package scripts (as a string for display). */
|
|
1168
2215
|
abstract getRunCommand(command: string): string;
|
|
@@ -1178,7 +2225,7 @@ declare abstract class JsPackageManager {
|
|
|
1178
2225
|
force?: boolean;
|
|
1179
2226
|
}): Promise<void>;
|
|
1180
2227
|
/** Read the `package.json` file available in the provided directory */
|
|
1181
|
-
static getPackageJson(packageJsonPath: string):
|
|
2228
|
+
static getPackageJson(packageJsonPath: string): PackageJsonWithIndent;
|
|
1182
2229
|
writePackageJson(packageJson: PackageJson, directory?: string): void;
|
|
1183
2230
|
getAllDependencies(): Record<string, string>;
|
|
1184
2231
|
isDependencyInstalled(dependency: string): boolean;
|
|
@@ -1208,7 +2255,7 @@ declare abstract class JsPackageManager {
|
|
|
1208
2255
|
type: 'dependencies' | 'devDependencies';
|
|
1209
2256
|
writeOutputToFile?: boolean;
|
|
1210
2257
|
packageJsonInfo?: PackageJsonInfo;
|
|
1211
|
-
}, dependencies: string[]): Promise<void |
|
|
2258
|
+
}, dependencies: string[]): Promise<void | ResultPromise>;
|
|
1212
2259
|
/**
|
|
1213
2260
|
* Removing dependencies from the package.json file, which is found first starting from the
|
|
1214
2261
|
* instance root. The method does not run a package manager install like `npm install`.
|
|
@@ -1287,8 +2334,8 @@ declare abstract class JsPackageManager {
|
|
|
1287
2334
|
addPackageResolutions(versions: Record<string, string>): void;
|
|
1288
2335
|
protected abstract runInstall(options?: {
|
|
1289
2336
|
force?: boolean;
|
|
1290
|
-
}):
|
|
1291
|
-
protected abstract runAddDeps(dependencies: string[], installAsDevDependencies: boolean, writeOutputToFile?: boolean):
|
|
2337
|
+
}): ResultPromise;
|
|
2338
|
+
protected abstract runAddDeps(dependencies: string[], installAsDevDependencies: boolean, writeOutputToFile?: boolean): ResultPromise;
|
|
1292
2339
|
protected abstract getResolutions(packageJson: PackageJson, versions: Record<string, string>): Record<string, any>;
|
|
1293
2340
|
/**
|
|
1294
2341
|
* Get the latest or all versions of the input package available on npmjs.com
|
|
@@ -1298,10 +2345,10 @@ declare abstract class JsPackageManager {
|
|
|
1298
2345
|
*/
|
|
1299
2346
|
protected abstract runGetVersions<T extends boolean>(packageName: string, fetchAllVersions: T): Promise<T extends true ? string[] : string>;
|
|
1300
2347
|
abstract getRegistryURL(): Promise<string | undefined>;
|
|
1301
|
-
abstract runInternalCommand(command: string, args: string[], cwd?: string, stdio?: 'inherit' | 'pipe' | 'ignore'):
|
|
2348
|
+
abstract runInternalCommand(command: string, args: string[], cwd?: string, stdio?: 'inherit' | 'pipe' | 'ignore'): ResultPromise;
|
|
1302
2349
|
abstract runPackageCommand(options: Omit<ExecuteCommandOptions, 'command'> & {
|
|
1303
2350
|
args: string[];
|
|
1304
|
-
}):
|
|
2351
|
+
}): ResultPromise;
|
|
1305
2352
|
abstract findInstallations(pattern?: string[]): Promise<InstallationMetadata | undefined>;
|
|
1306
2353
|
abstract findInstallations(pattern?: string[], options?: {
|
|
1307
2354
|
depth: number;
|
|
@@ -1392,24 +2439,32 @@ declare function validateConfigurationFiles(configDir: string, cwd?: string): Pr
|
|
|
1392
2439
|
/** Mimicking the satisfies operator until we can upgrade to TS4.9 */
|
|
1393
2440
|
declare function satisfies<A>(): <T extends A>(x: T) => T;
|
|
1394
2441
|
|
|
1395
|
-
|
|
1396
|
-
resolveConfig: (
|
|
1397
|
-
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
formatWithCursor(
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
getFileInfo(
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
2442
|
+
interface Prettier {
|
|
2443
|
+
resolveConfig: (filePath: string, options?: {
|
|
2444
|
+
editorconfig?: boolean;
|
|
2445
|
+
}) => Promise<any>;
|
|
2446
|
+
format: (content: string, options?: any) => Promise<string> | string;
|
|
2447
|
+
check: (content: string, options?: any) => Promise<boolean>;
|
|
2448
|
+
clearConfigCache: () => Promise<void>;
|
|
2449
|
+
formatWithCursor: (content: string, options?: any) => Promise<{
|
|
2450
|
+
formatted: string;
|
|
2451
|
+
cursorOffset: number;
|
|
2452
|
+
}>;
|
|
2453
|
+
getFileInfo: (filePath: string, options?: any) => Promise<{
|
|
2454
|
+
ignored: boolean;
|
|
2455
|
+
inferredParser: string | null;
|
|
2456
|
+
}>;
|
|
2457
|
+
getSupportInfo: () => Promise<{
|
|
2458
|
+
languages: any[];
|
|
2459
|
+
options: any[];
|
|
2460
|
+
}>;
|
|
2461
|
+
resolveConfigFile: (filePath?: string) => Promise<string | null>;
|
|
1410
2462
|
version: string;
|
|
1411
|
-
|
|
1412
|
-
|
|
2463
|
+
AstPath: any;
|
|
2464
|
+
doc: any;
|
|
2465
|
+
util: any;
|
|
2466
|
+
}
|
|
2467
|
+
declare function getPrettier(): Promise<Prettier>;
|
|
1413
2468
|
/**
|
|
1414
2469
|
* Format the content of a file using prettier. If prettier is not available in the user's project,
|
|
1415
2470
|
* it will fallback to use editorconfig settings if available and formats the file by a
|