Skip to content

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Jan 7, 2026

Summary

Extends the pgpm init command to support non-pgpm templates by adding a new requiresWorkspace field to .boilerplate.json that specifies what type of workspace a template requires:

requiresWorkspace?: 'pgpm' | 'pnpm' | 'lerna' | 'npm' | false

Behavior:

  • 'pgpm' (default for module type): Requires pgpm workspace AND creates pgpm.plan, .control, and deploy/revert/verify directories
  • 'pnpm' / 'lerna' / 'npm': Requires respective workspace type, no pgpm files created
  • false: No workspace required, can scaffold anywhere, no pgpm files

This replaces the earlier two-field approach (pgpm + requiresWorkspace booleans) with a single, cleaner field.

Key changes:

  • Added WorkspaceType union type and extended BoilerplateConfig in template-scaffold.ts
  • Updated boilerplate-scanner.ts to validate and normalize the requiresWorkspace field with proper defaults
  • Updated handleModuleInit to derive isPgpmTemplate from requiresWorkspace === 'pgpm'
  • Updated PgpmPackage.initModule to conditionally skip pgpm file creation based on pgpm flag
  • Added new code path for direct scaffolding when not in a workspace
  • Added workspace detection functions to @pgpmjs/env for pnpm, lerna, and npm workspaces (alongside existing resolvePgpmPath)

Updates since last revision

  • Refactored workspace detection to @pgpmjs/env: Moved workspace detection functions from CLI to the env package for better reusability and consistency with existing resolvePgpmPath function
  • Added resolvePnpmWorkspace (looks for pnpm-workspace.yaml)
  • Added resolveLernaWorkspace (looks for lerna.json)
  • Added resolveNpmWorkspace (looks for package.json with workspaces field)
  • Added resolveWorkspaceByType dispatcher function
  • Exported WorkspaceType type from @pgpmjs/env
  • CLI now imports and uses resolveWorkspaceByType from @pgpmjs/env instead of local implementations

Review & Testing Checklist for Human

  • Verify workspace detection imports work: The CLI now imports resolveWorkspaceByType from @pgpmjs/env - verify this works at runtime
  • Test pnpm workspace detection: Create a template with "requiresWorkspace": "pnpm" and verify it correctly detects pnpm-workspace.yaml in parent directories
  • Test lerna workspace detection: Verify lerna.json detection works correctly
  • Test npm workspace detection: Verify detection of package.json with workspaces field works
  • Verify backward compatibility: Run pgpm init with existing templates (without the new field) to confirm they still create pgpm.plan and .control files as expected

Recommended test plan:

  1. In an existing pgpm workspace, run pgpm init with a standard module template - should work as before
  2. In a pnpm workspace (with pnpm-workspace.yaml), try a template with "requiresWorkspace": "pnpm" - should succeed
  3. Outside any workspace, try pgpm init with a template that has "requiresWorkspace": false - should scaffold without errors
  4. Outside a pnpm workspace, try a template with "requiresWorkspace": "pnpm" - should show "Not inside a PNPM workspace" error (no offer to create workspace)

Notes

This PR is part of a two-repo change. The companion PR for pgpm-boilerplates (#21) updates existing templates to use the new requiresWorkspace format.

Link to Devin run: https://app.devin.ai/sessions/d1d032371bf64d3ba45c1d134004d34c
Requested by: Dan Lynch (@pyramation)

- Extend BoilerplateConfig with pgpm and requiresWorkspace fields
- Update init command to respect these fields from .boilerplate.json
- Allow modules to be created outside workspaces when requiresWorkspace is false
- Skip pgpm.plan and .control file creation when pgpm is false
- Maintain backward compatibility (defaults to pgpm=true, requiresWorkspace=true)
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Replace pgpm + requiresWorkspace boolean fields with a single requiresWorkspace
field that accepts workspace type strings:
- 'pgpm': Requires pgpm workspace AND creates pgpm.plan/.control files
- 'pnpm': Requires pnpm workspace (pnpm-workspace.yaml)
- 'lerna': Requires lerna workspace (lerna.json)
- 'npm': Requires npm workspace (package.json with workspaces)
- false: No workspace required, no pgpm files

This simplifies the config and makes the behavior more intuitive.
Add helper functions to detect different workspace types:
- findPnpmWorkspace: looks for pnpm-workspace.yaml
- findLernaWorkspace: looks for lerna.json
- findNpmWorkspace: looks for package.json with workspaces field

Update handleModuleInit to use these detection functions based on
the requiresWorkspace value from the template config.
Move workspace detection functions from CLI to the env package for better
reusability and consistency with existing resolvePgpmPath function:

- Add resolvePnpmWorkspace (looks for pnpm-workspace.yaml)
- Add resolveLernaWorkspace (looks for lerna.json)
- Add resolveNpmWorkspace (looks for package.json with workspaces field)
- Add resolveWorkspaceByType dispatcher function
- Export WorkspaceType type

Update CLI to import and use resolveWorkspaceByType from @pgpmjs/env.
@pyramation pyramation merged commit 9fec6b1 into main Jan 7, 2026
36 checks passed
@pyramation pyramation deleted the devin/1767782092-non-pgpm-templates branch January 7, 2026 15:38
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