DEV Community

Ramu Narasinga
Ramu Narasinga

Posted on • Edited on • Originally published at thinkthroo.com

Execa usage in Zod source code.

In this article, we will review execa usage in zod source code. 

We will look at:

  1. What is Execa?

  2. Execa usage in Zod source code.

What is Execa?

Execa runs commands in your script, application or library. Unlike shells, it is optimized for programmatic usage. Built on top of the child_process core module.

Install

npm install execa
Enter fullscreen mode Exit fullscreen mode

Example

Array Syntax:

import {execa} from 'execa';

await execa('npm', ['run', 'build']);
Enter fullscreen mode Exit fullscreen mode

For more examples, checkout the documentation.

Execa usage in Zod source code

At line 5, you will find this below import in zod/build.mts file

import { execaSync } from "execa";
Enter fullscreen mode Exit fullscreen mode

At line 8, execaSync is assigned to a dollor sign variable.

const $ = execaSync({ stdio: "inherit" });
Enter fullscreen mode Exit fullscreen mode

Now, let’s find out how execa is used.

Example 1:

Removing dist folder.

$`rm -rf ./dist`;
Enter fullscreen mode Exit fullscreen mode

Example 2:

At line 24, you will find the below code:

$`pnpm tsc -p tsconfig.esm.json`;
Enter fullscreen mode Exit fullscreen mode

For more examples, checkout build.mts.

About me:

Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.

Build Shadcn CLI from scratch.

Email — [email protected]

My Github — https://github.com/ramu-narasinga

My website — https://ramunarasinga.com

My YouTube channel — https://www.youtube.com/@ramu-narasinga

Learning platform — https://thinkthroo.com

Codebase Architecture — https://app.thinkthroo.com/architecture

Best practices — https://app.thinkthroo.com/best-practices

Production-grade projects — https://app.thinkthroo.com/production-grade-projects

References

  1. https://github.com/colinhacks/zod/blob/main/packages/zod/build.mts

  2. https://www.npmjs.com/package/execa

  3. https://github.com/sindresorhus/execa/blob/HEAD/docs/execution.md

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.