Skip to content

fix(generator): support explicit directory option and use in packagejson/README templates#8897

Draft
quirogas wants to merge 1 commit into
googleapis:mainfrom
quirogas:fix/generator-templates-repository-directory
Draft

fix(generator): support explicit directory option and use in packagejson/README templates#8897
quirogas wants to merge 1 commit into
googleapis:mainfrom
quirogas:fix/generator-templates-repository-directory

Conversation

@quirogas

Copy link
Copy Markdown
Contributor

No description provided.

@quirogas quirogas self-assigned this Jul 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new directory option to allow specifying a custom monorepo directory for the generated TypeScript package, updating the generator logic, schema, and templates (CJS and ESM package.json and README files) to use this directory if provided. The reviewer suggests renaming this option and its associated properties to package-dir / packageDir across all files to avoid confusion with the output directory and to maintain consistency with existing options like package-name.

Comment on lines +83 to +84
.alias('directory', 'package_dir')
.describe('directory', 'Monorepo directory of the package (e.g. packages/google-cloud-workflows)')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using --directory as a CLI option name is highly generic and can easily be confused with the output directory where the generated code is written. To avoid confusion and maintain consistency with --package-name, it is recommended to name this option --package-dir.

Suggested change
.alias('directory', 'package_dir')
.describe('directory', 'Monorepo directory of the package (e.g. packages/google-cloud-workflows)')
.alias('package-dir', 'package_dir')
.describe('package-dir', 'Monorepo directory of the package (e.g. packages/google-cloud-workflows)')

const bundleConfig = argv.bundleConfig as string | undefined;
const serviceYaml = argv.serviceYaml as string | undefined;
const packageName = argv.packageName as string | undefined;
const directory = argv.directory as string | undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Retrieve the option as packageDir to match the renamed --package-dir CLI option.

Suggested change
const directory = argv.directory as string | undefined;
const packageDir = argv.packageDir as string | undefined;

Comment on lines +221 to +223
if (directory) {
protocCommand.push(`--typescript_gapic_opt="directory=${directory}"`);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Pass the option as package-dir to the protoc plugin to match the renamed option.

Suggested change
if (directory) {
protocCommand.push(`--typescript_gapic_opt="directory=${directory}"`);
}
if (packageDir) {
protocCommand.push(`--typescript_gapic_opt="package-dir=${packageDir}"`);
}

paramMap: OptionsMap;
// This field is for users passing proper publish package name like @google-cloud/text-to-speech.
publishName?: string;
directory?: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Rename the property to packageDir to be more descriptive and consistent with the renamed option.

  packageDir?: string;


private readPublishPackageName() {
this.publishName = this.paramMap['package-name'];
this.directory = this.paramMap['directory'];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Read the renamed package-dir option from paramMap.

    this.packageDir = this.paramMap['package-dir'];

},
"license": "Apache-2.0",
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/packages/{{ api.naming.namePath }}",
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.directory or ('packages/' + api.naming.namePath) }}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Use api.packageDir instead of api.directory to match the renamed property.

Suggested change
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.directory or ('packages/' + api.naming.namePath) }}",
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}",

"repository": {
"type": "git",
"directory": "packages/{{ api.naming.namePath }}",
"directory": "{{ api.directory or ('packages/' + api.naming.namePath) }}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Use api.packageDir instead of api.directory to match the renamed property.

Suggested change
"directory": "{{ api.directory or ('packages/' + api.naming.namePath) }}",
"directory": "{{ api.packageDir or ('packages/' + api.naming.namePath) }}",

},
"license": "Apache-2.0",
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/packages/{{ api.naming.namePath }}",
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.directory or ('packages/' + api.naming.namePath) }}",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Use api.packageDir instead of api.directory to match the renamed property.

Suggested change
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.directory or ('packages/' + api.naming.namePath) }}",
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}",

Comment on lines +110 to +112
[homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}/samples
[homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}/CHANGELOG.md
[homepage]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Use api.packageDir instead of api.directory to match the renamed property.

[homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}/samples
[homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}/CHANGELOG.md
[homepage]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}

Comment on lines +110 to +112
[homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}/samples
[homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}/CHANGELOG.md
[homepage]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Use api.packageDir instead of api.directory to match the renamed property.

[homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}/samples
[homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}/CHANGELOG.md
[homepage]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}

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.

1 participant