feat(generator): update package.json template for monorepo compatibility#8694
Open
suztomo wants to merge 9 commits into
Open
feat(generator): update package.json template for monorepo compatibility#8694suztomo wants to merge 9 commits into
suztomo wants to merge 9 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the CJS and ESM package.json templates to conditionally set the repository and homepage fields depending on whether the API publish name contains a slash. The reviewer noted that using whitespace-stripping tags (both {%- and -%}) on both sides of the control blocks will strip newlines and cause fields to concatenate onto the same line, resulting in poorly formatted JSON. They suggested only stripping the preceding newline to maintain proper formatting.
0a74544 to
36c0a43
Compare
36c0a43 to
1dc7de5
Compare
suztomo
commented
Jun 22, 2026
…mplates" This reverts commit d7ef2c7.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR updates the package.json templates in gapic-generator-typescript to generate monorepo-compatible repository and homepage fields.
It introduces the
monorepoDirectorygetter to theAPIclass (defaulting tonaming.namePath) and uses it in the templates (asapi.monorepoDirectory) to determine the repository directory and homepage.Examples of resolved directories:
google-cloud-kms(proto packagegoogle.cloud.kms.v1), it generatespackages/google-cloud-kms(correct).google-maps-mapmanagement(proto packagegoogle.maps.mapmanagement.v2beta), it generatespackages/google-maps-mapmanagement(correct).google-cloud-monitoringwhich has proto packagegoogle.monitoring.v3), it defaults topackages/google-monitoring(non-existent URL in baselines, but accepted for now to keep generator changes minimal).Note
Generator Limitation: Because the generator runs as a
protocplugin, it only generates files with relative paths to the output root. It does not know the actual absolute path or the monorepo structure where these files will be written (that is handled byprotocorlibrarianwhich calls it). This is why it cannot dynamically resolve the correct monorepo directory name without complex lookup logic or external options.This avoids manual fixes when onboarding new packages (like google-cloud-agentregistry) to this monorepo, and correctly handles packages where the npm scope name doesn't match the directory prefix (e.g.,
@google-cloud/mapmanagement->packages/google-maps-mapmanagement).Changes:
api.naming.monorepoDirectory.api.naming.monorepoDirectory.0.0.0in templates (updated from0.1.0).Why do we have two package.json templates?
The generator maintains two sets of templates under
templates/cjs(CommonJS) andtemplates/esm(ESM).format=esmflag).Both CJS and ESM templates must be kept in sync so that future ESM-enabled libraries are generated with the correct monorepo metadata.