Skip to content

Conversation

@Tobbe
Copy link
Member

@Tobbe Tobbe commented Dec 21, 2025

This is a new CLI command that lets you generate a package for code that can be shared between both the web and api sides.

The command is yarn cedar generate package <name>

Here's a checklist of things I want to add for this feature: #725
I won't do them all in this PR though. I'll release this as soon as I have an MVP working. I might put it behind a feature flag

The most annoying missing feature right now is full support for yarn cedar dev. Currently you have to manually go and run yarn build (no "cedar") inside the package directory after any change to the package before you run yarn cedar dev. To make your life slightly less painful you can start a separate terminal and run yarn watch and the package will be automatically rebuilt on changes. If you have more than one package you need to open a separate terminal and run yarn watch for each package.
There is also no HMR for the api side. You need to restart the yarn cedar dev process for every change to a package that affects the api side.

@github-actions github-actions bot added this to the next-release milestone Dec 21, 2025
@netlify
Copy link

netlify bot commented Dec 21, 2025

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit bad9ba7
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/6956fb55a192b10008555ce1

@nx-cloud
Copy link

nx-cloud bot commented Dec 21, 2025

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit bad9ba7

Command Status Duration Result
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 1m 32s View ↗
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 7s View ↗
nx run-many -t build ✅ Succeeded 3m 30s View ↗
nx run-many -t test:types ✅ Succeeded 9s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-01 23:10:43 UTC

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 21, 2025

Greptile Summary

This PR adds a new generate package command that creates shared workspace packages in the packages/ directory. The generator follows the established pattern used by other generators (like job/service) and includes:

  • Core functionality: Generates package scaffolding with package.json, tsconfig.json, README.md, source files, and test files
  • Naming flexibility: Supports both scoped (@my-org/package-name) and unscoped package names, automatically applying organization scope from project name
  • Test infrastructure: Includes unit tests and scenario fixtures following Cedar patterns
  • Path system integration: Adds packages path to project configuration

Key changes:

  • Modified yargsHandlerHelpers.js to support optional sidePathSection parameter, enabling generators to target top-level paths like packages/
  • Added validation to ensure package names contain at most one slash
  • Generated packages use kebab-case folder names and camelCase for function/variable names

Issues found:

  • JSON syntax error: trailing comma in tsconfig.json.template will cause runtime errors
  • Debugging console.log statements left in yargsHandlerHelpers.js should be removed

Confidence Score: 3/5

  • This PR contains a JSON syntax error that will cause generation failures
  • While the implementation follows established patterns and includes comprehensive tests, the trailing comma in tsconfig.json.template will cause JSON parse errors when the generated package is used with TypeScript. The debugging console.log statements are style issues that don't affect functionality. Once the JSON syntax error is fixed, this would be safe to merge.
  • Pay attention to packages/cli/src/commands/generate/package/templates/tsconfig.json.template (JSON syntax error) and packages/cli/src/commands/generate/yargsHandlerHelpers.js (debugging statements)

Important Files Changed

Filename Overview
packages/cli/src/commands/generate/package/packageHandler.js Implements package generator with console.logs still present and proper handling of side: 'packages'
packages/cli/src/commands/generate/yargsHandlerHelpers.js Modified to support optional sidePathSection and handle packages side, but contains debugging console.logs
packages/cli/src/commands/generate/package/tests/package.test.ts Comprehensive tests for package generation with single/multi-word names and JS/TS support
packages/cli/src/commands/generate/package/templates/tsconfig.json.template Template for TypeScript configuration

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant packageHandler
    participant yargsHandlerHelpers
    participant templateForFile
    participant getPaths
    participant generateTemplate
    participant writeFilesTask
    participant eslint

    User->>CLI: cedar generate package @org/name
    CLI->>packageHandler: handler({ name, typescript, tests, ... })
    packageHandler->>packageHandler: Validate name (max 1 slash)
    packageHandler->>packageHandler: Parse org and name from input
    packageHandler->>packageHandler: Generate folderName (param-case)
    
    loop For each template file
        packageHandler->>templateForFile: Request file generation
        templateForFile->>getPaths: Get packages path
        getPaths-->>templateForFile: Return /path/to/project/packages
        templateForFile->>templateForFile: Build full output path
        templateForFile->>generateTemplate: Render template with vars
        generateTemplate-->>templateForFile: Return rendered content
        templateForFile-->>packageHandler: Return [outputPath, content]
    end
    
    packageHandler->>packageHandler: Transform TS to JS if needed
    packageHandler->>writeFilesTask: Write all files
    writeFilesTask-->>packageHandler: Files written
    
    packageHandler->>eslint: Run eslint --fix on generated files
    eslint-->>packageHandler: Files formatted
    
    packageHandler-->>CLI: Success
    CLI-->>User: Package generated at packages/folder-name/
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11 files reviewed, 13 comments

Edit Code Review Agent Settings | Greptile

@Tobbe Tobbe force-pushed the tobbe-feat-generate-package branch from c31387f to ef038a8 Compare December 22, 2025 10:03
@Tobbe
Copy link
Member Author

Tobbe commented Dec 27, 2025

@greptileai Please do a full review again

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

14 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@Tobbe Tobbe merged commit 8048c72 into main Jan 1, 2026
41 checks passed
@Tobbe Tobbe deleted the tobbe-feat-generate-package branch January 1, 2026 23:12
Tobbe added a commit that referenced this pull request Jan 2, 2026
@Tobbe Tobbe modified the milestones: next-release, v2.3.0 Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants