Commit bcaa9ab

Anton Golub <antongolub@antongolub.com>
2025-07-23 15:08:00
feat: export `$` as type (#1283)
feat: export `$` type feat: pass `cwd` to command log event chore: update size-limit
1 parent a994e01
build/cli.js
build/core.cjs
@@ -463,12 +463,11 @@ var $ = new Proxy(
   },
   {
     set(t, key, value) {
-      Reflect.set(
+      return Reflect.set(
         key in Function.prototype ? t : getStore(),
         key === "sync" ? SYNC : key,
         value
       );
-      return true;
     },
     get(t, key) {
       return key === "sync" ? $({ sync: true }) : Reflect.get(key in Function.prototype ? t : getStore(), key);
@@ -547,7 +546,7 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
       },
       on: {
         start: () => {
-          $2.log({ kind: "cmd", cmd: self.cmd, verbose: self.isVerbose(), id });
+          $2.log({ kind: "cmd", cmd: self.cmd, cwd, verbose: self.isVerbose(), id });
           self.timeout($2.timeout, $2.timeoutSignal);
         },
         stdout: (data) => {
build/core.d.ts
@@ -58,7 +58,8 @@ export interface Shell<S = false, R = S extends true ? ProcessOutput : ProcessPr
     };
 }
 export declare function within<R>(callback: () => R): R;
-export declare const $: Shell & Options;
+export type $ = Shell & Options;
+export declare const $: $;
 type ProcessStage = 'initial' | 'halted' | 'running' | 'fulfilled' | 'rejected';
 type Resolve = (out: ProcessOutput) => void;
 type PromisifiedStream<D extends Writable> = D & PromiseLike<ProcessOutput & D>;
build/log.d.ts
@@ -5,6 +5,7 @@ export type LogEntry = {
 } & ({
     kind: 'cmd';
     cmd: string;
+    cwd: string;
     id: string;
 } | {
     kind: 'stdout';
src/core.ts
@@ -189,7 +189,9 @@ export function within<R>(callback: () => R): R {
 }
 
 // The zx
-export const $: Shell & Options = new Proxy<Shell & Options>(
+export type $ = Shell & Options
+
+export const $: $ = new Proxy<$>(
   function (pieces: TemplateStringsArray | Partial<Options>, ...args: any[]) {
     const snapshot = getStore()
     if (!Array.isArray(pieces)) {
@@ -217,15 +219,14 @@ export const $: Shell & Options = new Proxy<Shell & Options>(
     if (!pp.isHalted()) pp.run()
 
     return pp.sync ? pp.output : pp
-  } as Shell & Options,
+  } as $,
   {
     set(t, key, value) {
-      Reflect.set(
+      return Reflect.set(
         key in Function.prototype ? t : getStore(),
         key === 'sync' ? SYNC : key,
         value
       )
-      return true
     },
     get(t, key) {
       return key === 'sync'
@@ -326,7 +327,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
       },
       on: {
         start: () => {
-          $.log({ kind: 'cmd', cmd: self.cmd, verbose: self.isVerbose(), id })
+          $.log({ kind: 'cmd', cmd: self.cmd, cwd, verbose: self.isVerbose(), id })
           self.timeout($.timeout, $.timeoutSignal)
         },
         stdout: (data) => {
src/log.ts
@@ -23,6 +23,7 @@ export type LogEntry = {
   | {
       kind: 'cmd'
       cmd: string
+      cwd: string
       id: string
     }
   | {
test/core.test.js
@@ -449,11 +449,13 @@ describe('core', () => {
       const p = $({ log })`echo foo`
       const { id } = p
       const { duration } = await p
+      const cwd = process.cwd()
 
       assert.equal(entries.length, 3)
       assert.deepEqual(entries[0], {
         kind: 'cmd',
         cmd: 'echo foo',
+        cwd,
         verbose: false,
         id,
       })