Skip to content

Refactor: Extract shared code between Neo.Build and Neo.Shell modules #200

@NickSeagull

Description

@NickSeagull

What's happening?

We have two commands (neo build and neo shell) that do almost the exact same thing! They both have about 60 lines of identical code that:

  • Sets up your project configuration
  • Finds all your Haskell modules
  • Generates project files (Cabal, Nix, etc.)
  • Writes everything to disk

The only difference? The last line:

  • neo build → runs nix-build to compile your project
  • neo shell → runs nix-shell to give you a development environment

Why this matters to you

Right now, if you want to fix a bug or add a feature to how we set up projects, you'd need to:

  1. Make the change in Neo.Build.hs
  2. Copy-paste that exact same change to Neo.Shell.hs
  3. Hope you didn't miss anything! 🤞

This is the kind of thing that leads to subtle bugs where one command works slightly differently than the other.

The fix (spoiler: it's straightforward!)

Let's create a shared helper module that both commands can use. Think of it like extracting a function in your IDE, but at the module level.

Step 1: Create a new module

Create cli/src/Neo/Build/Common.hs (or ProjectSetup.hs - we're flexible on naming!)

Step 2: Move the shared code

Extract these shared pieces from both files:

-- All of this is currently duplicated:
- Project path setup
- Module discovery (finding .hs files)
- Template generation
- File writing
- Error handling

Step 3: Update both commands

Make them nice and simple:

-- Neo.Build.hs becomes:
handle config = do
  projectFiles <- setupProject config  -- New shared function!
  -- Just the build-specific part:
  Process.run "nix-build" ...

-- Neo.Shell.hs becomes:  
handle config = do
  projectFiles <- setupProject config  -- Same shared function!
  -- Just the shell-specific part:
  Process.run "nix-shell" ...

Getting started

Time estimate: 1-2 hours

You'll be working with:

  • cli/src/Neo/Build.hs (lines 28-87)
  • cli/src/Neo/Shell.hs (lines 28-87)
  • Creating: cli/src/Neo/Build/Common.hs (or similar name)

Good first issue? Yes! This is mostly copy-paste and organizing code. No complex logic changes needed.

How to test your changes

After refactoring:

  1. Run neo build on a test project - should work exactly as before
  2. Run neo shell on the same project - should also work exactly as before
  3. Both commands should behave identically for the setup phase

Questions?

This is a great refactoring task for getting familiar with the codebase! If you get stuck for more than 15 minutes, hop into our Discord and we'll help you out.

Context: This duplication was spotted during our haskell.nix migration (PR #199). Now's a perfect time to clean it up!

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerspackage: cliRelated to the Command Line Tooltype: chorework: obviousStraightforward tasks with known solutions; follow best practices

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions