storybook 10.2.0-alpha.9 → 10.2.0-beta.0
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-E5XDEOX4.js → Color-XESOIGZP.js} +57 -3
- package/dist/_browser-chunks/chunk-AFVOZMXQ.js +23 -0
- package/dist/_browser-chunks/{chunk-3PJE6VLG.js → chunk-ASKQZAOS.js} +1 -12
- package/dist/_browser-chunks/chunk-IYCKG66Y.js +171 -0
- package/dist/_browser-chunks/chunk-LCHBOIHN.js +64 -0
- package/dist/_browser-chunks/{chunk-IPA5A322.js → chunk-MEXTPDJG.js} +1 -1
- package/dist/_browser-chunks/{chunk-54PNNATT.js → chunk-NQJGOFZV.js} +18 -1
- package/dist/_browser-chunks/{chunk-VUZYLZ4B.js → chunk-QOXZ7W26.js} +31 -15
- package/dist/_browser-chunks/{chunk-LOTN4ZCW.js → chunk-SI6AKD4S.js} +2 -2
- package/dist/_browser-chunks/chunk-YK43Z22A.js +263 -0
- package/dist/_node-chunks/{builder-manager-FTCODGJP.js → builder-manager-JEJE63VV.js} +15 -12
- package/dist/_node-chunks/camelcase-HALRJETF.js +62 -0
- package/dist/_node-chunks/{chunk-3Y5VHKPI.js → chunk-3SKE4CCB.js} +9 -9
- package/dist/_node-chunks/chunk-4UYAC7Y2.js +18 -0
- package/dist/_node-chunks/{chunk-NYUFS6LX.js → chunk-6UAQEBJX.js} +10 -10
- package/dist/_node-chunks/{chunk-SPOUBCPJ.js → chunk-72K4WVI5.js} +18 -14
- package/dist/_node-chunks/{chunk-FGI35IGB.js → chunk-7ZX5CX6B.js} +15 -69
- package/dist/_node-chunks/{chunk-6SH5SI6S.js → chunk-ADTWC7QJ.js} +7 -7
- package/dist/_node-chunks/{chunk-OUDQWDHY.js → chunk-APUXGW3Y.js} +7 -7
- package/dist/_node-chunks/{chunk-PZCWRKQE.js → chunk-AXDM43NU.js} +6 -6
- package/dist/_node-chunks/{chunk-73GYSTNZ.js → chunk-B422K4XV.js} +6 -6
- package/dist/_node-chunks/{chunk-WTQGSYRO.js → chunk-BJOXVTWM.js} +12 -571
- package/dist/_node-chunks/{chunk-LRBEW57O.js → chunk-BLGRU6F5.js} +7 -7
- package/dist/_node-chunks/{chunk-6ABJZZWS.js → chunk-CG47ALAV.js} +7 -7
- package/dist/_node-chunks/chunk-FH4FRUMP.js +23 -0
- package/dist/_node-chunks/{chunk-RF3L36MK.js → chunk-GBZ23FIZ.js} +125 -73
- package/dist/_node-chunks/{chunk-MWWAQ5S4.js → chunk-IZ3ATSWZ.js} +5262 -1480
- package/dist/_node-chunks/{chunk-SBPB3VWI.js → chunk-IZFEBWVB.js} +6 -6
- package/dist/_node-chunks/{chunk-33XC4R6P.js → chunk-KL5CKFPT.js} +9 -9
- package/dist/_node-chunks/{chunk-D4TCQXIF.js → chunk-MLXCYULR.js} +7 -7
- package/dist/_node-chunks/{chunk-LB74XOLW.js → chunk-MV2QM7P3.js} +6 -6
- package/dist/_node-chunks/chunk-PHX5XNP7.js +144 -0
- package/dist/_node-chunks/{chunk-XZ6V3G6J.js → chunk-QL6L57W7.js} +533 -143
- package/dist/_node-chunks/{chunk-IIBBQZLT.js → chunk-RPBXVPRB.js} +6 -6
- package/dist/_node-chunks/{chunk-BQX766MA.js → chunk-UH2GWMFP.js} +260 -162
- package/dist/_node-chunks/chunk-WNGL2VRJ.js +126 -0
- package/dist/_node-chunks/{chunk-CO7N5AG7.js → chunk-XAL452XB.js} +36 -14
- package/dist/_node-chunks/{chunk-YN6FEZAF.js → chunk-YVXXMWQO.js} +7 -7
- package/dist/_node-chunks/chunk-YYDL7JOC.js +61 -0
- package/dist/_node-chunks/{chunk-3DPKKQ6P.js → chunk-Z7FLE2TR.js} +6 -6
- package/dist/_node-chunks/{globby-AXGFF6I5.js → globby-4D4NBVG7.js} +11 -20
- package/dist/_node-chunks/{lib-ESB7KQ6D.js → lib-RM2DWHZQ.js} +7 -7
- package/dist/_node-chunks/{mdx-N42X6CFJ-XXQ6YIDF.js → mdx-N42X6CFJ-RAL72UTP.js} +8 -8
- package/dist/_node-chunks/{p-limit-P6ND7SUA.js → p-limit-6PUJQL5X.js} +18 -14
- package/dist/babel/index.js +10 -10
- package/dist/bin/core.js +12 -12
- package/dist/bin/dispatcher.js +11 -11
- package/dist/bin/loader.js +9 -9
- package/dist/cli/index.d.ts +1504 -424
- package/dist/cli/index.js +18 -18
- package/dist/common/index.d.ts +1319 -271
- package/dist/common/index.js +19 -19
- package/dist/components/index.d.ts +4 -1
- package/dist/components/index.js +228 -227
- package/dist/core-events/index.d.ts +23 -7
- package/dist/core-events/index.js +5 -1
- package/dist/core-server/index.d.ts +105 -3
- package/dist/core-server/index.js +992 -613
- package/dist/core-server/presets/common-manager.js +208 -160
- package/dist/core-server/presets/common-override-preset.js +11 -11
- package/dist/core-server/presets/common-preset.js +558 -4534
- package/dist/csf/index.d.ts +147 -15
- package/dist/csf/index.js +52 -23
- package/dist/csf-tools/index.d.ts +19 -1
- package/dist/csf-tools/index.js +11 -9
- package/dist/docs-tools/index.d.ts +2 -2
- package/dist/docs-tools/index.js +4 -5
- package/dist/manager/globals-runtime.js +2749 -6907
- package/dist/manager/runtime.js +2939 -2295
- package/dist/manager-api/index.d.ts +89 -21
- package/dist/manager-api/index.js +82 -23
- package/dist/mocking-utils/index.js +8 -8
- package/dist/node-logger/index.d.ts +1453 -108
- package/dist/node-logger/index.js +9 -9
- package/dist/preview/runtime.js +784 -5059
- package/dist/preview-api/index.d.ts +26 -1
- package/dist/preview-api/index.js +11 -8
- package/dist/router/index.js +5 -4
- package/dist/server-errors.js +11 -11
- package/dist/telemetry/index.d.ts +14 -2
- package/dist/telemetry/index.js +23 -22
- package/dist/theming/index.d.ts +5 -5
- package/dist/theming/index.js +21 -2
- package/dist/types/index.d.ts +21 -9
- package/dist/viewport/index.d.ts +5 -3
- package/dist/viewport/index.js +12 -3
- package/package.json +27 -26
- package/dist/_browser-chunks/chunk-2NDLAB5X.js +0 -363
- package/dist/_browser-chunks/chunk-CLSHX4VX.js +0 -4140
- package/dist/_browser-chunks/chunk-HPYUT3WS.js +0 -199
- package/dist/_browser-chunks/chunk-XCZK5QUJ.js +0 -0
- package/dist/_node-chunks/camelcase-5XDKQT3J.js +0 -37
- package/dist/_node-chunks/chunk-GXQRT5M6.js +0 -61
- package/dist/_node-chunks/chunk-MOQRBTWA.js +0 -70
- package/dist/_node-chunks/chunk-PRNP2HO6.js +0 -23
- package/dist/_node-chunks/chunk-VKMYOVNS.js +0 -18
- package/dist/_node-chunks/dist-YRSVYE5A.js +0 -121
package/dist/common/index.d.ts
CHANGED
|
@@ -2,9 +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 {
|
|
6
|
+
import { SignalConstants } from 'node:os';
|
|
7
|
+
import { Duplex, Readable, Writable } from 'node:stream';
|
|
8
|
+
import { TransformStream, ReadableStream, WritableStream } from 'node:stream/web';
|
|
8
9
|
import { ConfigFile } from 'storybook/internal/csf-tools';
|
|
9
10
|
import { types } from 'storybook/internal/babel';
|
|
10
11
|
|
|
@@ -581,527 +582,1570 @@ declare function normalizeStoryPath(filename: string): string;
|
|
|
581
582
|
|
|
582
583
|
declare function readTemplate(filename: string): Promise<string>;
|
|
583
584
|
|
|
584
|
-
type
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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> =
|
|
588
659
|
| 'ignore'
|
|
589
660
|
| 'inherit'
|
|
590
|
-
|
|
|
661
|
+
| 'ipc'
|
|
591
662
|
| number
|
|
592
|
-
|
|
|
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;
|
|
593
805
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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
|
|
605
1099
|
| 'hex'
|
|
606
1100
|
| 'base64'
|
|
607
1101
|
| 'base64url'
|
|
608
|
-
| '
|
|
609
|
-
|
|
|
610
|
-
|
|
611
|
-
|
|
1102
|
+
| 'latin1'
|
|
1103
|
+
| 'ascii';
|
|
1104
|
+
|
|
1105
|
+
// `options.encoding`
|
|
1106
|
+
type EncodingOption =
|
|
1107
|
+
| TextEncodingOption
|
|
1108
|
+
| BinaryEncodingOption
|
|
1109
|
+
| undefined;
|
|
612
1110
|
|
|
613
|
-
|
|
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
|
+
};
|
|
1194
|
+
|
|
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
|
+
> {
|
|
614
1223
|
/**
|
|
615
|
-
|
|
616
|
-
- the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)
|
|
617
|
-
- 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)).
|
|
618
1225
|
|
|
619
|
-
|
|
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.
|
|
620
1229
|
*/
|
|
621
|
-
|
|
1230
|
+
stdout: ResultStdioNotAll<'1', OptionsType>;
|
|
622
1231
|
|
|
623
1232
|
/**
|
|
624
|
-
|
|
1233
|
+
The output of the subprocess on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).
|
|
625
1234
|
|
|
626
|
-
|
|
1235
|
+
This is `undefined` if the `stderr` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
627
1236
|
|
|
628
|
-
|
|
1237
|
+
This is an array if the `lines` option is `true`, or if the `stderr` option is a transform in object mode.
|
|
629
1238
|
*/
|
|
630
|
-
|
|
1239
|
+
stderr: ResultStdioNotAll<'2', OptionsType>;
|
|
631
1240
|
|
|
632
1241
|
/**
|
|
633
|
-
|
|
1242
|
+
The output of the subprocess with `result.stdout` and `result.stderr` interleaved.
|
|
634
1243
|
|
|
635
|
-
|
|
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.
|
|
636
1249
|
*/
|
|
637
|
-
|
|
1250
|
+
all: ResultAll<OptionsType>;
|
|
1251
|
+
|
|
1252
|
+
/**
|
|
1253
|
+
The output of the subprocess on `stdin`, `stdout`, `stderr` and other file descriptors.
|
|
1254
|
+
|
|
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`.
|
|
1256
|
+
|
|
1257
|
+
Items are arrays when their corresponding `stdio` option is a transform in object mode.
|
|
1258
|
+
*/
|
|
1259
|
+
stdio: ResultStdioArray<OptionsType>;
|
|
638
1260
|
|
|
639
1261
|
/**
|
|
640
|
-
|
|
1262
|
+
All the messages sent by the subprocess to the current process.
|
|
641
1263
|
|
|
642
|
-
This
|
|
1264
|
+
This is empty unless the `ipc` option is `true`. Also, this is empty if the `buffer` option is `false`.
|
|
1265
|
+
*/
|
|
1266
|
+
ipcOutput: ResultIpcOutput<IsSync, OptionsType>;
|
|
643
1267
|
|
|
644
|
-
|
|
1268
|
+
/**
|
|
1269
|
+
Results of the other subprocesses that were piped into this subprocess.
|
|
645
1270
|
|
|
646
|
-
|
|
1271
|
+
This array is initially empty and is populated each time the `subprocess.pipe()` method resolves.
|
|
1272
|
+
*/
|
|
1273
|
+
pipedFrom: Unless<IsSync, Result[], []>;
|
|
647
1274
|
|
|
648
|
-
|
|
1275
|
+
/**
|
|
1276
|
+
The file and arguments that were run.
|
|
649
1277
|
*/
|
|
650
|
-
|
|
1278
|
+
command: string;
|
|
651
1279
|
|
|
652
1280
|
/**
|
|
653
|
-
|
|
1281
|
+
Same as `command` but escaped.
|
|
1282
|
+
*/
|
|
1283
|
+
escapedCommand: string;
|
|
654
1284
|
|
|
655
|
-
|
|
1285
|
+
/**
|
|
1286
|
+
The current directory in which the command was run.
|
|
1287
|
+
*/
|
|
1288
|
+
cwd: string;
|
|
656
1289
|
|
|
657
|
-
|
|
1290
|
+
/**
|
|
1291
|
+
Duration of the subprocess, in milliseconds.
|
|
658
1292
|
*/
|
|
659
|
-
|
|
1293
|
+
durationMs: number;
|
|
660
1294
|
|
|
661
1295
|
/**
|
|
662
|
-
|
|
1296
|
+
Whether the subprocess failed to run.
|
|
663
1297
|
|
|
664
|
-
|
|
1298
|
+
When this is `true`, the result is an `ExecaError` instance with additional error-related properties.
|
|
665
1299
|
*/
|
|
666
|
-
|
|
1300
|
+
failed: boolean;
|
|
667
1301
|
|
|
668
1302
|
/**
|
|
669
|
-
|
|
1303
|
+
Whether the subprocess timed out due to the `timeout` option.
|
|
1304
|
+
*/
|
|
1305
|
+
timedOut: boolean;
|
|
670
1306
|
|
|
671
|
-
|
|
1307
|
+
/**
|
|
1308
|
+
Whether the subprocess was canceled using the `cancelSignal` option.
|
|
672
1309
|
*/
|
|
673
|
-
|
|
1310
|
+
isCanceled: boolean;
|
|
674
1311
|
|
|
675
1312
|
/**
|
|
676
|
-
|
|
1313
|
+
Whether the subprocess was canceled using both the `cancelSignal` and the `gracefulCancel` options.
|
|
1314
|
+
*/
|
|
1315
|
+
isGracefullyCanceled: boolean;
|
|
677
1316
|
|
|
678
|
-
|
|
1317
|
+
/**
|
|
1318
|
+
Whether the subprocess failed because its output was larger than the `maxBuffer` option.
|
|
679
1319
|
*/
|
|
680
|
-
|
|
1320
|
+
isMaxBuffer: boolean;
|
|
681
1321
|
|
|
682
1322
|
/**
|
|
683
|
-
|
|
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;
|
|
684
1328
|
|
|
685
|
-
|
|
1329
|
+
/**
|
|
1330
|
+
Whether the subprocess was terminated by the `SIGKILL` signal sent by the `forceKillAfterDelay` option.
|
|
686
1331
|
*/
|
|
687
|
-
|
|
1332
|
+
isForcefullyTerminated: boolean;
|
|
688
1333
|
|
|
689
1334
|
/**
|
|
690
|
-
|
|
1335
|
+
The numeric [exit code](https://en.wikipedia.org/wiki/Exit_status) of the subprocess that was run.
|
|
691
1336
|
|
|
692
|
-
|
|
1337
|
+
This is `undefined` when the subprocess could not be spawned or was terminated by a signal.
|
|
693
1338
|
*/
|
|
694
|
-
|
|
1339
|
+
exitCode?: number;
|
|
695
1340
|
|
|
696
1341
|
/**
|
|
697
|
-
|
|
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).
|
|
698
1345
|
|
|
699
|
-
|
|
1346
|
+
If a signal terminated the subprocess, this property is defined and included in the error message. Otherwise it is `undefined`.
|
|
700
1347
|
*/
|
|
701
|
-
|
|
1348
|
+
signal?: keyof SignalConstants;
|
|
702
1349
|
|
|
703
1350
|
/**
|
|
704
|
-
|
|
1351
|
+
A human-friendly description of the signal that was used to terminate the subprocess.
|
|
705
1352
|
|
|
706
|
-
|
|
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.
|
|
707
1354
|
*/
|
|
708
|
-
|
|
1355
|
+
signalDescription?: string;
|
|
709
1356
|
|
|
710
1357
|
/**
|
|
711
|
-
|
|
1358
|
+
Error message when the subprocess failed to run.
|
|
1359
|
+
*/
|
|
1360
|
+
message?: string;
|
|
712
1361
|
|
|
713
|
-
|
|
1362
|
+
/**
|
|
1363
|
+
This is the same as `error.message` except it does not include the subprocess output.
|
|
714
1364
|
*/
|
|
715
|
-
|
|
1365
|
+
shortMessage?: string;
|
|
716
1366
|
|
|
717
1367
|
/**
|
|
718
|
-
|
|
1368
|
+
Original error message. This is the same as `error.message` excluding the subprocess output and some additional information added by Execa.
|
|
719
1369
|
|
|
720
|
-
|
|
1370
|
+
This exists only in specific instances, such as during a timeout.
|
|
721
1371
|
*/
|
|
722
|
-
|
|
1372
|
+
originalMessage?: string;
|
|
723
1373
|
|
|
724
1374
|
/**
|
|
725
|
-
|
|
1375
|
+
Underlying error, if there is one. For example, this is set by `subprocess.kill(error)`.
|
|
1376
|
+
|
|
1377
|
+
This is usually an `Error` instance.
|
|
726
1378
|
*/
|
|
727
|
-
|
|
1379
|
+
cause?: unknown;
|
|
728
1380
|
|
|
729
1381
|
/**
|
|
730
|
-
|
|
1382
|
+
Node.js-specific [error code](https://nodejs.org/api/errors.html#errorcode), when available.
|
|
1383
|
+
*/
|
|
1384
|
+
code?: string;
|
|
731
1385
|
|
|
732
|
-
|
|
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
|
|
733
1431
|
*/
|
|
734
|
-
|
|
1432
|
+
type: 'command' | 'output' | 'ipc' | 'error' | 'duration';
|
|
735
1433
|
|
|
736
1434
|
/**
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
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;
|
|
1443
|
+
|
|
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'`.
|
|
740
1451
|
|
|
741
|
-
|
|
1452
|
+
This is helpful when multiple subprocesses are running at the same time.
|
|
742
1453
|
|
|
743
|
-
|
|
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.
|
|
744
1455
|
*/
|
|
745
|
-
|
|
1456
|
+
commandId: string;
|
|
746
1457
|
|
|
747
1458
|
/**
|
|
748
|
-
|
|
1459
|
+
Event date/time.
|
|
1460
|
+
*/
|
|
1461
|
+
timestamp: Date;
|
|
749
1462
|
|
|
750
|
-
|
|
1463
|
+
/**
|
|
1464
|
+
Whether another subprocess is piped into this subprocess. This is `false` when `result.pipedFrom` is empty.
|
|
751
1465
|
*/
|
|
752
|
-
|
|
1466
|
+
piped: boolean;
|
|
1467
|
+
};
|
|
753
1468
|
|
|
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> = {
|
|
754
1476
|
/**
|
|
755
|
-
|
|
1477
|
+
Prefer locally installed binaries when looking for a binary to execute.
|
|
1478
|
+
|
|
1479
|
+
@default `true` with `$`, `false` otherwise
|
|
756
1480
|
*/
|
|
757
|
-
readonly
|
|
1481
|
+
readonly preferLocal?: boolean;
|
|
758
1482
|
|
|
759
1483
|
/**
|
|
760
|
-
|
|
1484
|
+
Preferred path to find locally installed binaries, when using the `preferLocal` option.
|
|
1485
|
+
|
|
1486
|
+
@default `cwd` option
|
|
761
1487
|
*/
|
|
762
|
-
readonly
|
|
1488
|
+
readonly localDir?: string | URL;
|
|
1489
|
+
|
|
1490
|
+
/**
|
|
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
|
|
1496
|
+
*/
|
|
1497
|
+
readonly node?: boolean;
|
|
1498
|
+
|
|
1499
|
+
/**
|
|
1500
|
+
List of [CLI flags](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable.
|
|
1501
|
+
|
|
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;
|
|
763
1516
|
|
|
764
1517
|
/**
|
|
765
|
-
If `true`, runs
|
|
1518
|
+
If `true`, runs the command inside of a [shell](https://en.wikipedia.org/wiki/Shell_(computing)).
|
|
766
1519
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
- unsafe, potentially allowing command injection.
|
|
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.
|
|
771
1523
|
|
|
772
1524
|
@default false
|
|
773
1525
|
*/
|
|
774
|
-
readonly shell?: boolean | string;
|
|
1526
|
+
readonly shell?: boolean | string | URL;
|
|
775
1527
|
|
|
776
1528
|
/**
|
|
777
|
-
|
|
1529
|
+
Current [working directory](https://en.wikipedia.org/wiki/Working_directory) of the subprocess.
|
|
778
1530
|
|
|
779
|
-
|
|
1531
|
+
This is also used to resolve the `nodePath` option when it is a relative path.
|
|
1532
|
+
|
|
1533
|
+
@default process.cwd()
|
|
780
1534
|
*/
|
|
781
|
-
readonly
|
|
1535
|
+
readonly cwd?: string | URL;
|
|
782
1536
|
|
|
783
1537
|
/**
|
|
784
|
-
|
|
1538
|
+
[Environment variables](https://en.wikipedia.org/wiki/Environment_variable).
|
|
785
1539
|
|
|
786
|
-
|
|
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)
|
|
787
1543
|
*/
|
|
788
|
-
readonly
|
|
1544
|
+
readonly env?: Readonly<Partial<Record<string, string>>>;
|
|
789
1545
|
|
|
790
1546
|
/**
|
|
791
|
-
|
|
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`.
|
|
792
1549
|
|
|
793
|
-
@default
|
|
1550
|
+
@default true
|
|
794
1551
|
*/
|
|
795
|
-
readonly
|
|
1552
|
+
readonly extendEnv?: boolean;
|
|
796
1553
|
|
|
797
1554
|
/**
|
|
798
|
-
|
|
1555
|
+
Write some input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).
|
|
799
1556
|
|
|
800
|
-
|
|
1557
|
+
See also the `inputFile` and `stdin` options.
|
|
801
1558
|
*/
|
|
802
|
-
readonly
|
|
1559
|
+
readonly input?: string | Uint8Array | Readable;
|
|
803
1560
|
|
|
804
1561
|
/**
|
|
805
|
-
|
|
1562
|
+
Use a file as input to the subprocess' [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)).
|
|
806
1563
|
|
|
807
|
-
|
|
1564
|
+
See also the `input` and `stdin` options.
|
|
1565
|
+
*/
|
|
1566
|
+
readonly inputFile?: string | URL;
|
|
808
1567
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
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`.
|
|
812
1570
|
|
|
813
|
-
|
|
814
|
-
const subprocess = execa('node', [], {signal: abortController.signal});
|
|
1571
|
+
This can be an array of values such as `['inherit', 'pipe']` or `[fileUrl, 'pipe']`.
|
|
815
1572
|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
1573
|
+
@default `'inherit'` with `$`, `'pipe'` otherwise
|
|
1574
|
+
*/
|
|
1575
|
+
readonly stdin?: StdinOptionCommon<IsSync>;
|
|
819
1576
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
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'
|
|
827
1592
|
*/
|
|
828
|
-
readonly
|
|
1593
|
+
readonly stderr?: StdoutStderrOptionCommon<IsSync>;
|
|
829
1594
|
|
|
830
1595
|
/**
|
|
831
|
-
|
|
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`.
|
|
832
1608
|
|
|
833
1609
|
@default false
|
|
834
1610
|
*/
|
|
835
|
-
readonly
|
|
1611
|
+
readonly all?: boolean;
|
|
836
1612
|
|
|
837
1613
|
/**
|
|
838
|
-
|
|
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).
|
|
839
1615
|
|
|
840
|
-
|
|
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'
|
|
841
1623
|
*/
|
|
842
|
-
readonly
|
|
1624
|
+
readonly encoding?: EncodingOption;
|
|
843
1625
|
|
|
844
1626
|
/**
|
|
845
|
-
|
|
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.
|
|
846
1630
|
|
|
847
|
-
|
|
1631
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
848
1632
|
|
|
849
1633
|
@default false
|
|
850
1634
|
*/
|
|
851
|
-
readonly
|
|
852
|
-
};
|
|
1635
|
+
readonly lines?: FdGenericOption<boolean>;
|
|
853
1636
|
|
|
854
|
-
type Options<EncodingType extends EncodingOption = DefaultEncodingOption> = {
|
|
855
1637
|
/**
|
|
856
|
-
|
|
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.
|
|
857
1641
|
|
|
858
|
-
|
|
1642
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
1643
|
+
|
|
1644
|
+
@default true
|
|
859
1645
|
*/
|
|
860
|
-
readonly
|
|
1646
|
+
readonly stripFinalNewline?: FdGenericOption<boolean>;
|
|
861
1647
|
|
|
862
1648
|
/**
|
|
863
|
-
|
|
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.
|
|
1652
|
+
|
|
1653
|
+
When reached, `error.isMaxBuffer` becomes `true`.
|
|
864
1654
|
|
|
865
|
-
|
|
1655
|
+
@default 100_000_000
|
|
866
1656
|
*/
|
|
867
|
-
readonly
|
|
868
|
-
} & CommonOptions<EncodingType>;
|
|
1657
|
+
readonly maxBuffer?: FdGenericOption<number>;
|
|
869
1658
|
|
|
870
|
-
type NodeOptions<EncodingType extends EncodingOption = DefaultEncodingOption> = {
|
|
871
1659
|
/**
|
|
872
|
-
|
|
1660
|
+
When `buffer` is `false`, the `result.stdout`, `result.stderr`, `result.all` and `result.stdio` properties are not set.
|
|
1661
|
+
|
|
1662
|
+
By default, this applies to both `stdout` and `stderr`, but different values can also be passed.
|
|
873
1663
|
|
|
874
|
-
@default
|
|
1664
|
+
@default true
|
|
875
1665
|
*/
|
|
876
|
-
readonly
|
|
1666
|
+
readonly buffer?: FdGenericOption<boolean>;
|
|
877
1667
|
|
|
878
1668
|
/**
|
|
879
|
-
|
|
1669
|
+
Enables exchanging messages with the subprocess using `subprocess.sendMessage(message)`, `subprocess.getOneMessage()` and `subprocess.getEachMessage()`.
|
|
880
1670
|
|
|
881
|
-
|
|
1671
|
+
The subprocess must be a Node.js file.
|
|
1672
|
+
|
|
1673
|
+
@default `true` if the `node`, `ipcInput` or `gracefulCancel` option is set, `false` otherwise
|
|
882
1674
|
*/
|
|
883
|
-
readonly
|
|
884
|
-
|
|
1675
|
+
readonly ipc?: Unless<IsSync, boolean>;
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
Specify the kind of serialization used for sending messages between subprocesses when using the `ipc` option.
|
|
885
1679
|
|
|
886
|
-
|
|
1680
|
+
@default 'advanced'
|
|
1681
|
+
*/
|
|
1682
|
+
readonly serialization?: Unless<IsSync, 'json' | 'advanced'>;
|
|
887
1683
|
|
|
888
|
-
type ExecaReturnBase<StdoutStderrType extends StdoutStderrAll> = {
|
|
889
1684
|
/**
|
|
890
|
-
|
|
1685
|
+
Sends an IPC message when the subprocess starts.
|
|
891
1686
|
|
|
892
|
-
|
|
1687
|
+
The subprocess must be a Node.js file. The value's type depends on the `serialization` option.
|
|
893
1688
|
*/
|
|
894
|
-
|
|
1689
|
+
readonly ipcInput?: Unless<IsSync, Message>;
|
|
895
1690
|
|
|
896
1691
|
/**
|
|
897
|
-
|
|
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.
|
|
898
1693
|
|
|
899
|
-
|
|
900
|
-
|
|
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.
|
|
1699
|
+
|
|
1700
|
+
@default 'none'
|
|
901
1701
|
*/
|
|
902
|
-
|
|
1702
|
+
readonly verbose?: VerboseOption;
|
|
903
1703
|
|
|
904
1704
|
/**
|
|
905
|
-
|
|
1705
|
+
Setting this to `false` resolves the result's promise with the error instead of rejecting it.
|
|
1706
|
+
|
|
1707
|
+
@default true
|
|
906
1708
|
*/
|
|
907
|
-
|
|
1709
|
+
readonly reject?: boolean;
|
|
908
1710
|
|
|
909
1711
|
/**
|
|
910
|
-
|
|
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
|
|
911
1717
|
*/
|
|
912
|
-
|
|
1718
|
+
readonly timeout?: number;
|
|
913
1719
|
|
|
914
1720
|
/**
|
|
915
|
-
|
|
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
|
+
```
|
|
916
1746
|
*/
|
|
917
|
-
|
|
1747
|
+
readonly cancelSignal?: Unless<IsSync, AbortSignal>;
|
|
918
1748
|
|
|
919
1749
|
/**
|
|
920
|
-
|
|
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
|
|
921
1757
|
*/
|
|
922
|
-
|
|
1758
|
+
readonly gracefulCancel?: Unless<IsSync, boolean>;
|
|
923
1759
|
|
|
924
1760
|
/**
|
|
925
|
-
|
|
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
|
|
926
1766
|
*/
|
|
927
|
-
|
|
1767
|
+
readonly forceKillAfterDelay?: Unless<IsSync, number | boolean>;
|
|
928
1768
|
|
|
929
1769
|
/**
|
|
930
|
-
|
|
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'
|
|
931
1775
|
*/
|
|
932
|
-
|
|
1776
|
+
readonly killSignal?: keyof SignalConstants | number;
|
|
933
1777
|
|
|
934
1778
|
/**
|
|
935
|
-
|
|
1779
|
+
Run the subprocess independently from the current process.
|
|
936
1780
|
|
|
937
|
-
|
|
1781
|
+
@default false
|
|
938
1782
|
*/
|
|
939
|
-
|
|
1783
|
+
readonly detached?: Unless<IsSync, boolean>;
|
|
940
1784
|
|
|
941
1785
|
/**
|
|
942
|
-
|
|
1786
|
+
Kill the subprocess when the current process exits.
|
|
943
1787
|
|
|
944
|
-
|
|
1788
|
+
@default true
|
|
945
1789
|
*/
|
|
946
|
-
|
|
1790
|
+
readonly cleanup?: Unless<IsSync, boolean>;
|
|
947
1791
|
|
|
948
1792
|
/**
|
|
949
|
-
|
|
1793
|
+
Sets the [user identifier](https://en.wikipedia.org/wiki/User_identifier) of the subprocess.
|
|
1794
|
+
|
|
1795
|
+
@default current user identifier
|
|
950
1796
|
*/
|
|
951
|
-
|
|
1797
|
+
readonly uid?: number;
|
|
1798
|
+
|
|
1799
|
+
/**
|
|
1800
|
+
Sets the [group identifier](https://en.wikipedia.org/wiki/Group_identifier) of the subprocess.
|
|
1801
|
+
|
|
1802
|
+
@default current group identifier
|
|
1803
|
+
*/
|
|
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;
|
|
952
1826
|
};
|
|
953
1827
|
|
|
954
|
-
|
|
955
|
-
|
|
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>;
|
|
1844
|
+
|
|
1845
|
+
/**
|
|
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;
|
|
956
1872
|
|
|
957
1873
|
/**
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
The child process fails when:
|
|
961
|
-
- its exit code is not `0`
|
|
962
|
-
- it was killed with a signal
|
|
963
|
-
- timing out
|
|
964
|
-
- being canceled
|
|
965
|
-
- there's not enough memory or there are already too many child processes
|
|
1874
|
+
Value allowed inside `${...}` when using the template string syntax.
|
|
966
1875
|
*/
|
|
967
|
-
type
|
|
1876
|
+
type TemplateExpression = TemplateExpressionItem | readonly TemplateExpressionItem[];
|
|
1877
|
+
|
|
1878
|
+
// `subprocess.pipe()` options
|
|
1879
|
+
type PipeOptions = {
|
|
968
1880
|
/**
|
|
969
|
-
|
|
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.
|
|
970
1882
|
|
|
971
|
-
This
|
|
972
|
-
- the `all` option is `false` (default value)
|
|
973
|
-
- `execaSync()` was used
|
|
1883
|
+
`"all"` pipes both `stdout` and `stderr`. This requires the `all` option to be `true`.
|
|
974
1884
|
*/
|
|
975
|
-
|
|
1885
|
+
readonly from?: FromOption;
|
|
976
1886
|
|
|
977
1887
|
/**
|
|
978
|
-
|
|
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;
|
|
979
1891
|
|
|
980
|
-
|
|
1892
|
+
/**
|
|
1893
|
+
Unpipe the subprocess when the signal aborts.
|
|
981
1894
|
*/
|
|
982
|
-
|
|
983
|
-
}
|
|
1895
|
+
readonly unpipeSignal?: AbortSignal;
|
|
1896
|
+
};
|
|
984
1897
|
|
|
985
|
-
|
|
1898
|
+
// `subprocess.pipe()`
|
|
1899
|
+
type PipableSubprocess = {
|
|
986
1900
|
/**
|
|
987
|
-
|
|
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.
|
|
988
1902
|
|
|
989
|
-
|
|
1903
|
+
This follows the same syntax as `execa(file, arguments?, options?)` except both regular options and pipe-specific options can be specified.
|
|
990
1904
|
*/
|
|
991
|
-
|
|
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;
|
|
992
1914
|
|
|
993
1915
|
/**
|
|
994
|
-
|
|
1916
|
+
Like `subprocess.pipe(file, arguments?, options?)` but using a `command` template string instead. This follows the same syntax as `$`.
|
|
995
1917
|
*/
|
|
996
|
-
|
|
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;
|
|
997
1923
|
|
|
998
1924
|
/**
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
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.
|
|
1002
1926
|
*/
|
|
1003
|
-
|
|
1004
|
-
|
|
1927
|
+
pipe<Destination extends ResultPromise>(destination: Destination, options?: PipeOptions):
|
|
1928
|
+
Promise<Awaited<Destination>> & PipableSubprocess;
|
|
1929
|
+
};
|
|
1005
1930
|
|
|
1006
|
-
|
|
1931
|
+
// `subprocess.readable|duplex|iterable()` options
|
|
1932
|
+
type ReadableOptions = {
|
|
1007
1933
|
/**
|
|
1008
|
-
|
|
1934
|
+
Which stream to read from the subprocess. A [file descriptor](https://en.wikipedia.org/wiki/File_descriptor) like `"fd3"` can also be passed.
|
|
1935
|
+
|
|
1936
|
+
`"all"` reads both `stdout` and `stderr`. This requires the `all` option to be `true`.
|
|
1009
1937
|
|
|
1010
|
-
|
|
1011
|
-
- the `all` option is `false` (default value)
|
|
1012
|
-
- `execaSync()` was used
|
|
1938
|
+
@default 'stdout'
|
|
1013
1939
|
*/
|
|
1014
|
-
|
|
1940
|
+
readonly from?: FromOption;
|
|
1015
1941
|
|
|
1016
1942
|
/**
|
|
1017
|
-
|
|
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
|
|
1018
1950
|
*/
|
|
1019
|
-
|
|
1020
|
-
} & ExecaSyncError<StdoutStderrType>;
|
|
1951
|
+
readonly binary?: boolean;
|
|
1021
1952
|
|
|
1022
|
-
type KillOptions = {
|
|
1023
1953
|
/**
|
|
1024
|
-
|
|
1954
|
+
If both this option and the `binary` option is `false`, [newlines](https://en.wikipedia.org/wiki/Newline) are stripped from each line.
|
|
1955
|
+
|
|
1956
|
+
@default `false` with `subprocess.iterable()`, `true` otherwise
|
|
1957
|
+
*/
|
|
1958
|
+
readonly preserveNewlines?: boolean;
|
|
1959
|
+
};
|
|
1025
1960
|
|
|
1026
|
-
|
|
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.
|
|
1027
1965
|
|
|
1028
|
-
@default
|
|
1966
|
+
@default 'stdin'
|
|
1029
1967
|
*/
|
|
1030
|
-
|
|
1968
|
+
readonly to?: ToOption;
|
|
1031
1969
|
};
|
|
1032
1970
|
|
|
1033
|
-
|
|
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> = {
|
|
1034
2034
|
/**
|
|
1035
|
-
|
|
2035
|
+
Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).
|
|
1036
2036
|
|
|
1037
|
-
This is `undefined` if
|
|
1038
|
-
- the `all` option is `false` (the default value)
|
|
1039
|
-
- 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.
|
|
1040
2038
|
*/
|
|
1041
|
-
|
|
2039
|
+
pid?: number;
|
|
1042
2040
|
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
2041
|
+
/**
|
|
2042
|
+
The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.
|
|
2043
|
+
|
|
2044
|
+
This is `null` if the `stdin` option is set to `'inherit'`, `'ignore'`, `Readable` or `integer`.
|
|
2045
|
+
*/
|
|
2046
|
+
stdin: SubprocessStdioStream<'0', OptionsType>;
|
|
1046
2047
|
|
|
1047
2048
|
/**
|
|
1048
|
-
|
|
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`.
|
|
1049
2052
|
*/
|
|
1050
|
-
|
|
2053
|
+
stdout: SubprocessStdioStream<'1', OptionsType>;
|
|
1051
2054
|
|
|
1052
2055
|
/**
|
|
1053
|
-
|
|
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`.
|
|
1054
2059
|
*/
|
|
1055
|
-
|
|
2060
|
+
stderr: SubprocessStdioStream<'2', OptionsType>;
|
|
1056
2061
|
|
|
1057
2062
|
/**
|
|
1058
|
-
|
|
1059
|
-
- Another `execa()` return value
|
|
1060
|
-
- A writable stream
|
|
1061
|
-
- A file path string
|
|
2063
|
+
Stream combining/interleaving `subprocess.stdout` and `subprocess.stderr`.
|
|
1062
2064
|
|
|
1063
|
-
|
|
2065
|
+
This requires the `all` option to be `true`.
|
|
1064
2066
|
|
|
1065
|
-
|
|
2067
|
+
This is `undefined` if `stdout` and `stderr` options are set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.
|
|
1066
2068
|
*/
|
|
1067
|
-
|
|
1068
|
-
pipeStdout?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
|
|
2069
|
+
all: SubprocessAll<OptionsType>;
|
|
1069
2070
|
|
|
1070
2071
|
/**
|
|
1071
|
-
|
|
2072
|
+
The subprocess `stdin`, `stdout`, `stderr` and other files descriptors as an array of streams.
|
|
1072
2073
|
|
|
1073
|
-
|
|
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`.
|
|
1074
2075
|
*/
|
|
1075
|
-
|
|
1076
|
-
pipeStderr?(target: Writable | string): ExecaChildProcess<StdoutStderrType>;
|
|
2076
|
+
stdio: SubprocessStdioArray<OptionsType>;
|
|
1077
2077
|
|
|
1078
2078
|
/**
|
|
1079
|
-
|
|
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.
|
|
2080
|
+
|
|
2081
|
+
This returns `false` when the signal could not be sent, for example when the subprocess has already exited.
|
|
1080
2082
|
|
|
1081
|
-
|
|
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)
|
|
1082
2086
|
*/
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
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']>;
|
|
2094
|
+
|
|
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']>;
|
|
2099
|
+
|
|
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;
|
|
1086
2117
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
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>>;
|
|
1090
2133
|
|
|
1091
|
-
type ExecuteCommandOptions =
|
|
2134
|
+
type ExecuteCommandOptions = Omit<Options, 'cancelSignal'> & {
|
|
1092
2135
|
command: string;
|
|
1093
2136
|
args?: string[];
|
|
1094
2137
|
cwd?: string;
|
|
1095
2138
|
ignoreError?: boolean;
|
|
1096
|
-
env?: Record<string,
|
|
2139
|
+
env?: Record<string, string>;
|
|
2140
|
+
signal?: AbortSignal;
|
|
1097
2141
|
};
|
|
1098
|
-
declare function executeCommand(options: ExecuteCommandOptions):
|
|
2142
|
+
declare function executeCommand(options: ExecuteCommandOptions): ResultPromise;
|
|
1099
2143
|
declare function executeCommandSync(options: ExecuteCommandOptions): string;
|
|
1100
2144
|
declare function executeNodeCommand({ scriptPath, args, options, }: {
|
|
1101
2145
|
scriptPath: string;
|
|
1102
2146
|
args?: string[];
|
|
1103
|
-
options?:
|
|
1104
|
-
}):
|
|
2147
|
+
options?: Options;
|
|
2148
|
+
}): ResultPromise;
|
|
1105
2149
|
|
|
1106
2150
|
type PackageJsonWithDepsAndDevDeps = PackageJson & Required<Pick<PackageJson, 'dependencies' | 'devDependencies'>>;
|
|
1107
2151
|
type PackageJsonWithMaybeDeps = Partial<Pick<PackageJson, 'dependencies' | 'devDependencies' | 'peerDependencies' | 'files'>>;
|
|
@@ -1125,6 +2169,10 @@ declare enum PackageManagerName {
|
|
|
1125
2169
|
PNPM = "pnpm",
|
|
1126
2170
|
BUN = "bun"
|
|
1127
2171
|
}
|
|
2172
|
+
declare const indentSymbol: unique symbol;
|
|
2173
|
+
type PackageJsonWithIndent = PackageJsonWithDepsAndDevDeps & {
|
|
2174
|
+
[indentSymbol]?: any;
|
|
2175
|
+
};
|
|
1128
2176
|
/**
|
|
1129
2177
|
* Extract package name and version from input
|
|
1130
2178
|
*
|
|
@@ -1161,7 +2209,7 @@ declare abstract class JsPackageManager {
|
|
|
1161
2209
|
/** Cache for installed version results to avoid repeated file system calls. */
|
|
1162
2210
|
static readonly installedVersionCache: Map<string, string | null>;
|
|
1163
2211
|
/** Cache for package.json files to avoid repeated file system calls. */
|
|
1164
|
-
static readonly packageJsonCache: Map<string,
|
|
2212
|
+
static readonly packageJsonCache: Map<string, PackageJsonWithIndent>;
|
|
1165
2213
|
constructor(options?: JsPackageManagerOptions);
|
|
1166
2214
|
/** Runs arbitrary package scripts (as a string for display). */
|
|
1167
2215
|
abstract getRunCommand(command: string): string;
|
|
@@ -1177,7 +2225,7 @@ declare abstract class JsPackageManager {
|
|
|
1177
2225
|
force?: boolean;
|
|
1178
2226
|
}): Promise<void>;
|
|
1179
2227
|
/** Read the `package.json` file available in the provided directory */
|
|
1180
|
-
static getPackageJson(packageJsonPath: string):
|
|
2228
|
+
static getPackageJson(packageJsonPath: string): PackageJsonWithIndent;
|
|
1181
2229
|
writePackageJson(packageJson: PackageJson, directory?: string): void;
|
|
1182
2230
|
getAllDependencies(): Record<string, string>;
|
|
1183
2231
|
isDependencyInstalled(dependency: string): boolean;
|
|
@@ -1207,7 +2255,7 @@ declare abstract class JsPackageManager {
|
|
|
1207
2255
|
type: 'dependencies' | 'devDependencies';
|
|
1208
2256
|
writeOutputToFile?: boolean;
|
|
1209
2257
|
packageJsonInfo?: PackageJsonInfo;
|
|
1210
|
-
}, dependencies: string[]): Promise<void |
|
|
2258
|
+
}, dependencies: string[]): Promise<void | ResultPromise>;
|
|
1211
2259
|
/**
|
|
1212
2260
|
* Removing dependencies from the package.json file, which is found first starting from the
|
|
1213
2261
|
* instance root. The method does not run a package manager install like `npm install`.
|
|
@@ -1286,8 +2334,8 @@ declare abstract class JsPackageManager {
|
|
|
1286
2334
|
addPackageResolutions(versions: Record<string, string>): void;
|
|
1287
2335
|
protected abstract runInstall(options?: {
|
|
1288
2336
|
force?: boolean;
|
|
1289
|
-
}):
|
|
1290
|
-
protected abstract runAddDeps(dependencies: string[], installAsDevDependencies: boolean, writeOutputToFile?: boolean):
|
|
2337
|
+
}): ResultPromise;
|
|
2338
|
+
protected abstract runAddDeps(dependencies: string[], installAsDevDependencies: boolean, writeOutputToFile?: boolean): ResultPromise;
|
|
1291
2339
|
protected abstract getResolutions(packageJson: PackageJson, versions: Record<string, string>): Record<string, any>;
|
|
1292
2340
|
/**
|
|
1293
2341
|
* Get the latest or all versions of the input package available on npmjs.com
|
|
@@ -1297,10 +2345,10 @@ declare abstract class JsPackageManager {
|
|
|
1297
2345
|
*/
|
|
1298
2346
|
protected abstract runGetVersions<T extends boolean>(packageName: string, fetchAllVersions: T): Promise<T extends true ? string[] : string>;
|
|
1299
2347
|
abstract getRegistryURL(): Promise<string | undefined>;
|
|
1300
|
-
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;
|
|
1301
2349
|
abstract runPackageCommand(options: Omit<ExecuteCommandOptions, 'command'> & {
|
|
1302
2350
|
args: string[];
|
|
1303
|
-
}):
|
|
2351
|
+
}): ResultPromise;
|
|
1304
2352
|
abstract findInstallations(pattern?: string[]): Promise<InstallationMetadata | undefined>;
|
|
1305
2353
|
abstract findInstallations(pattern?: string[], options?: {
|
|
1306
2354
|
depth: number;
|