pnp / pnp/cli-microsoft365

Migrate 'context init' to Zod

Open
#6,909 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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 💪...

This issue

Refactor the 'context init' command to use Zod for schema validation.

Implementation

There's some reference material for migrating to Zod. Check out the entra administrativeunit <verb> commands for that. 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.

Help by Copilot

If you are able to use Github Copilot, you may do so. There's a prompt file that's available to use for migration (.github\prompts\migrate-command-to-zod.prompt.md) You can let Copilot work on a command using the prompt file. Some tips here:

  • Use a Claude Sonnet model, not a GPT model.
  • Check the changes afterwards, Copilot may forget things are change too much.

Good luck! 🎉💪

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 existing context init command and compare it with the entra administrativeunit <verb> reference implementations. Review the command's test file and the migration prompt for the expected schema and safeParse() or parse() usage. Done means the command uses a Zod-based options schema, its constructor and old validation functions are removed, and the tests cover the new schema behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, testing-qa
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.