pnp / pnp/cli-microsoft365

Migration to Zod

Open
#6,807 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

epic
Dominant language
TypeScript
Stars
1.5k
Forks
413
Avg merge
5d 6h
Merged PRs (30d)
21

Description

We need to migrate the codebase to zod. This epic issue is for creating issues that have to do with this migration.

Introduction

As CLI team, we're doing a major refactoring of the code base on how we validate incoming options. In the new situation, we're now using Zod. The idea is that we define options as a Zod schema, and parse/validate the incoming options using that schema. This is a major change that needs to be done on every command in the CLI codebase and as such is a lot of work. But you can help 💪...

Implementation

There's some reference material for migrating to Zod. Check out:

  • entra administrativeunit <verb> commands.
  • The login command
  • The adaptivecard send command

There's a couple of things that are important:

  • Define an options object, based on globalOptionsZod.
  • Implement the schema function in the command class to return the options object.
  • Add any options to the schema if options are currently defined on the command
  • Add refinements if necessary for additional validation.
  • Remove the command class constructor and all its functions
  • Update the test file with the schema and safeParse() / parse() function calls.

Do check out our reference implementations to see what we mean here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reference implementations for entra administrativeunit <verb>, login, and adaptivecard send, then inspect the command classes and their test files. Compare their Zod schemas and safeParse() or parse() calls with commands still using the old validation approach. Done means the selected command defines its options from globalOptionsZod, includes needed refinements, and has updated tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.