Skip to content

fix(nimbus): support type generation hook for consumers#998

Merged
jaikamat merged 4 commits intomainfrom
CRAFT-consumer-types
Feb 2, 2026
Merged

fix(nimbus): support type generation hook for consumers#998
jaikamat merged 4 commits intomainfrom
CRAFT-consumer-types

Conversation

@jaikamat
Copy link
Contributor

I had to timebox myself, and chose to abandon this PR in favor of Michael's suggested solution from earlier in the day, which seems to work just fine in the wild.

@jaikamat jaikamat requested a review from a team January 30, 2026 21:07
@jaikamat jaikamat self-assigned this Jan 30, 2026
@jaikamat jaikamat requested review from ByronDWall, ddouglasz, misama-ct, stephsprinkle, tylermorrisford and valoriecarli and removed request for a team January 30, 2026 21:07
@jaikamat jaikamat added the bug Something isn't working label Jan 30, 2026
@vercel
Copy link

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nimbus-documentation Ready Ready Preview Jan 30, 2026 9:30pm
nimbus-storybook Ready Ready Preview, Comment Jan 30, 2026 9:30pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2026

🦋 Changeset detected

Latest commit: 8a4dd01

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@commercetools/nimbus Patch
@commercetools/nimbus-tokens Patch
@commercetools/nimbus-icons Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

"test": "vitest --run",
"typecheck": "tsc --noEmit",
"build-theme-typings": "pnpm chakra typegen ./src/theme/index.ts",
"postinstall": "chakra typegen ./dist/index.es.js || true",
Copy link
Contributor Author

@jaikamat jaikamat Jan 30, 2026

Choose a reason for hiding this comment

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

The key insight is that ./dist/index.es.js refers to Nimbus's own bundled code, not a file the consumer creates.

How it works

When a consumer runs pnpm add @commercetools/nimbus:

  1. Package extraction: Nimbus is extracted to node_modules/@commercetools/nimbus/
  2. Postinstall runs: The script executes with the working directory set to the package folder (node_modules/@commercetools/nimbus/)
  3. Path resolution: ./dist/index.es.js resolves to: node_modules/@commercetools/nimbus/dist/index.es.js
  4. This is Nimbus's own built bundle, which exports system.
  5. Type generation: Chakra CLI imports that file, finds the system export, analyzes the theme config, and writes type declarations to: node_modules/@chakra-ui/react/dist/types/
  6. Consumer benefits: The consumer's TypeScript now sees the augmented types.

}
},
"dependencies": {
"@chakra-ui/cli": "catalog:react",
Copy link
Contributor Author

@jaikamat jaikamat Jan 30, 2026

Choose a reason for hiding this comment

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

Had to move this to dependencies so consumers can have access to it

Copy link
Collaborator

@misama-ct misama-ct Feb 2, 2026

Choose a reason for hiding this comment

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

Did you test it, I don't think this works, does it?

If it doesn't, you might want to try running npx chakra typegen ... down here.

I believe npx should always be available to consumers if node is. But I am not sure if it works in a postinstall scenario as npx commands sometimes (usually?) present (y/n) confirmation prompts.

Worst case, the chaka-cli package needs to be a another peer-dependency of the consuming app like chakra itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested this locally with the MC using pack, seemed to work just fine

### TypeScript Support

TypeScript types for component variants, sizes, and design tokens are generated
automatically during installation. No additional setup required.
Copy link
Contributor

@ByronDWall ByronDWall Jan 30, 2026

Choose a reason for hiding this comment

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

we should probably specify this is done as a post-install hook that may need to be whitelisted?

Modern package managers increasingly block postinstall scripts by default.           
                                                                                                                                             
 Package Manager Behavior                                                                                                                    
 ┌──────────────────┬────────────────────────────────────────────────────────────────────────┐                                               
 │ Package Manager  │                            Default Behavior                            │                                               
 ├──────────────────┼────────────────────────────────────────────────────────────────────────┤                                               
 │ npm              │ Runs by default, but users can disable with --ignore-scripts or .npmrc │                                               
 ├──────────────────┼────────────────────────────────────────────────────────────────────────┤                                               
 │ pnpm (v8+)       │ Blocked by default - requires explicit allowlist                       │                                               
 ├──────────────────┼────────────────────────────────────────────────────────────────────────┤                                               
 │ yarn (v2+/Berry) │ Blocked by default - requires explicit allowlist                       │                                               
 └──────────────────┴────────────────────────────────────────────────────────────────────────┘                                               
 pnpm Specifically                                                                                                                           
                                                                                                                                             
 Since this is a pnpm monorepo and many consumers likely use pnpm, they'd need to add this to their package.json or .npmrc:                  
                                                                                                                                             
 // package.json                                                                                                                             
 {                                                                                                                                           
   "pnpm": {                                                                                                                                 
     "onlyBuiltDependencies": ["@commercetools/nimbus"]                                                                                      
   }                                                                                                                                         
 }                                                                                                                                           
                                                                                                                                             
 Or in .npmrc:                                                                                                                               
 enable-pre-post-scripts=true                                                                                                                
                                                                                                                                             
 Implications for Nimbus                                                                                                                     
                                                                                                                                             
 This means the postinstall hook:                                                                                                            
 "postinstall": "chakra typegen ./dist/index.es.js || true"                                                                                  
                                                                                                                                             
 Likely doesn't run for most consumers - which explains why the docs include the manual troubleshooting step:                                
 npx @chakra-ui/cli typegen node_modules/@commercetools/nimbus/dist/index.es.js                                                              
                                                                                                                                             
 Bottom Line                                                                                                                                 
                                                                                                                                             
 Given that postinstall hooks are often blocked anyway, having @chakra-ui/cli in dependencies provides little benefit while adding install   
 overhead. Moving it to devDependencies and relying on the documented manual command would be cleaner - it's effectively what most consumers 
 already experience.       ```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 8a4dd01

}
},
"dependencies": {
"@chakra-ui/cli": "catalog:react",
Copy link
Collaborator

@misama-ct misama-ct Feb 2, 2026

Choose a reason for hiding this comment

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

Did you test it, I don't think this works, does it?

If it doesn't, you might want to try running npx chakra typegen ... down here.

I believe npx should always be available to consumers if node is. But I am not sure if it works in a postinstall scenario as npx commands sometimes (usually?) present (y/n) confirmation prompts.

Worst case, the chaka-cli package needs to be a another peer-dependency of the consuming app like chakra itself.

Copy link
Contributor

@stephsprinkle stephsprinkle left a comment

Choose a reason for hiding this comment

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

Does the thing!

@jaikamat jaikamat merged commit a0db354 into main Feb 2, 2026
15 of 16 checks passed
@jaikamat jaikamat deleted the CRAFT-consumer-types branch February 2, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants