feat(pgpm): support non-pgpm templates in init command #574
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Extends the
pgpm initcommand to support non-pgpm templates by adding a newrequiresWorkspacefield to.boilerplate.jsonthat specifies what type of workspace a template requires:Behavior:
'pgpm'(default for module type): Requires pgpm workspace AND createspgpm.plan,.control, anddeploy/revert/verifydirectories'pnpm'/'lerna'/'npm': Requires respective workspace type, no pgpm files createdfalse: No workspace required, can scaffold anywhere, no pgpm filesThis replaces the earlier two-field approach (
pgpm+requiresWorkspacebooleans) with a single, cleaner field.Key changes:
WorkspaceTypeunion type and extendedBoilerplateConfigintemplate-scaffold.tsboilerplate-scanner.tsto validate and normalize therequiresWorkspacefield with proper defaultshandleModuleInitto deriveisPgpmTemplatefromrequiresWorkspace === 'pgpm'PgpmPackage.initModuleto conditionally skip pgpm file creation based onpgpmflag@pgpmjs/envfor pnpm, lerna, and npm workspaces (alongside existingresolvePgpmPath)Updates since last revision
@pgpmjs/env: Moved workspace detection functions from CLI to the env package for better reusability and consistency with existingresolvePgpmPathfunctionresolvePnpmWorkspace(looks forpnpm-workspace.yaml)resolveLernaWorkspace(looks forlerna.json)resolveNpmWorkspace(looks forpackage.jsonwith workspaces field)resolveWorkspaceByTypedispatcher functionWorkspaceTypetype from@pgpmjs/envresolveWorkspaceByTypefrom@pgpmjs/envinstead of local implementationsReview & Testing Checklist for Human
resolveWorkspaceByTypefrom@pgpmjs/env- verify this works at runtime"requiresWorkspace": "pnpm"and verify it correctly detectspnpm-workspace.yamlin parent directorieslerna.jsondetection works correctlypackage.jsonwithworkspacesfield workspgpm initwith existing templates (without the new field) to confirm they still create pgpm.plan and .control files as expectedRecommended test plan:
pgpm initwith a standard module template - should work as beforepnpm-workspace.yaml), try a template with"requiresWorkspace": "pnpm"- should succeedpgpm initwith a template that has"requiresWorkspace": false- should scaffold without errors"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 newrequiresWorkspaceformat.Link to Devin run: https://app.devin.ai/sessions/d1d032371bf64d3ba45c1d134004d34c
Requested by: Dan Lynch (@pyramation)