Commit 8f2c4ca
Changed files (7)
build/core.cjs
@@ -286,6 +286,9 @@ var formatters = {
},
end() {
return "";
+ },
+ kill() {
+ return "";
}
};
var log = function(entry) {
build/core.d.ts
@@ -50,7 +50,6 @@ export interface Options {
halt?: boolean;
delimiter?: string | RegExp;
}
-export declare const defaults: Options;
type Snapshot = Options & {
from: string;
pieces: TemplateStringsArray;
@@ -59,6 +58,8 @@ type Snapshot = Options & {
ee: EventEmitter;
ac: AbortController;
};
+export declare const defaults: Options;
+export declare function within<R>(callback: () => R): R;
export interface Shell<S = false, R = S extends true ? ProcessOutput : ProcessPromise> {
(pieces: TemplateStringsArray, ...args: any[]): R;
<O extends Partial<Options> = Partial<Options>, R = O extends {
@@ -69,7 +70,6 @@ export interface Shell<S = false, R = S extends true ? ProcessOutput : ProcessPr
(opts: Partial<Omit<Options, 'sync'>>): Shell<true>;
};
}
-export declare function within<R>(callback: () => R): R;
export type $ = Shell & Options;
export declare const $: $;
type ProcessStage = 'initial' | 'halted' | 'running' | 'fulfilled' | 'rejected';
build/log.d.ts
@@ -39,6 +39,10 @@ export type LogEntry = {
} | {
kind: 'custom';
data: any;
+} | {
+ kind: 'kill';
+ pid: number;
+ signal: NodeJS.Signals | null;
});
type LogFormatters = {
[key in LogEntry['kind']]: (entry: Extract<LogEntry, {
src/core.ts
@@ -120,6 +120,16 @@ export interface Options {
delimiter?: string | RegExp
}
+// prettier-ignore
+type Snapshot = Options & {
+ from: string
+ pieces: TemplateStringsArray
+ args: string[]
+ cmd: string
+ ee: EventEmitter
+ ac: AbortController
+}
+
// prettier-ignore
export const defaults: Options = resolveDefaults({
[CWD]: process.cwd(),
@@ -141,28 +151,6 @@ export const defaults: Options = resolveDefaults({
timeoutSignal: SIGTERM,
})
-type Snapshot = Options & {
- from: string
- pieces: TemplateStringsArray
- args: string[]
- cmd: string
- ee: EventEmitter
- ac: AbortController
-}
-
-// prettier-ignore
-export interface Shell<
- S = false,
- R = S extends true ? ProcessOutput : ProcessPromise,
-> {
- (pieces: TemplateStringsArray, ...args: any[]): R
- <O extends Partial<Options> = Partial<Options>, R = O extends { sync: true } ? Shell<true> : Shell>(opts: O): R
- sync: {
- (pieces: TemplateStringsArray, ...args: any[]): ProcessOutput
- (opts: Partial<Omit<Options, 'sync'>>): Shell<true>
- }
-}
-
const storage = new AsyncLocalStorage<Options>()
const getStore = () => storage.getStore() || defaults
@@ -186,6 +174,19 @@ export function within<R>(callback: () => R): R {
return storage.run({ ...getStore() }, callback)
}
+// prettier-ignore
+export interface Shell<
+ S = false,
+ R = S extends true ? ProcessOutput : ProcessPromise,
+> {
+ (pieces: TemplateStringsArray, ...args: any[]): R
+ <O extends Partial<Options> = Partial<Options>, R = O extends { sync: true } ? Shell<true> : Shell>(opts: O): R
+ sync: {
+ (pieces: TemplateStringsArray, ...args: any[]): ProcessOutput
+ (opts: Partial<Omit<Options, 'sync'>>): Shell<true>
+ }
+}
+
// The zx
export type $ = Shell & Options
src/log.ts
@@ -65,6 +65,11 @@ export type LogEntry = {
kind: 'custom'
data: any
}
+ | {
+ kind: 'kill'
+ pid: number
+ signal: NodeJS.Signals | null
+ }
)
type LogFormatters = {
@@ -102,6 +107,9 @@ const formatters: LogFormatters = {
end() {
return ''
},
+ kill() {
+ return ''
+ },
}
type Log = {
test/log.test.ts
@@ -38,6 +38,7 @@ describe('log', () => {
log({
kind: 'cmd',
cmd: 'echo hi',
+ cwd: process.cwd(),
id: '1',
verbose: false,
})
@@ -48,6 +49,7 @@ describe('log', () => {
log({
kind: 'cmd',
cmd: 'echo hi',
+ cwd: process.cwd(),
id: '1',
verbose: true,
})
@@ -111,6 +113,28 @@ describe('log', () => {
)
})
+ test('end', () => {
+ log({
+ kind: 'end',
+ id: '1',
+ exitCode: null,
+ signal: null,
+ duration: 0,
+ error: null,
+ verbose: true,
+ })
+ assert.equal(data.join(''), '')
+ })
+
+ test('kill', () => {
+ log({
+ kind: 'kill',
+ signal: null,
+ pid: 1234,
+ })
+ assert.equal(data.join(''), '')
+ })
+
test('formatters', () => {
log.formatters = {
cmd: ({ cmd }) => `CMD: ${cmd}`,
@@ -119,6 +143,7 @@ describe('log', () => {
log({
kind: 'cmd',
cmd: 'echo hi',
+ cwd: process.cwd(),
id: '1',
verbose: true,
})
.size-limit.json
@@ -36,7 +36,7 @@
{
"name": "libdefs",
"path": "build/*.d.ts",
- "limit": "40.45 kB",
+ "limit": "40.51 kB",
"brotli": false,
"gzip": false
},
@@ -62,7 +62,7 @@
"README.md",
"LICENSE"
],
- "limit": "872.30 kB",
+ "limit": "872.40 kB",
"brotli": false,
"gzip": false
}