Skip to content

feat(internal/librarian/nodejs): use cache and bin directories for nodejs install - #6680

Merged
suztomo merged 10 commits into
googleapis:mainfrom
suztomo:nodejs-install-cache-dir
Jul 7, 2026
Merged

feat(internal/librarian/nodejs): use cache and bin directories for nodejs install#6680
suztomo merged 10 commits into
googleapis:mainfrom
suztomo:nodejs-install-cache-dir

Conversation

@suztomo

@suztomo suztomo commented Jul 7, 2026

Copy link
Copy Markdown
Member

Update NodeJS tool installation to use $LIBRARIAN_BIN/nodejs_tools for installed executables (aligning with go_tools and java_tools) and LIBRARIAN_CACHE for downloaded google-cloud-node repository and pnpm cache/store.

Fixes #6678

  • Installs Node.js tools in $LIBRARIAN_BIN/nodejs_tools/bin (with PNPM_HOME=$LIBRARIAN_BIN/nodejs_tools and PNPM_CONFIG_GLOBAL_BIN_DIR=$LIBRARIAN_BIN/nodejs_tools/bin).
  • Prepends $LIBRARIAN_BIN/nodejs_tools/bin to PATH during tool installation and generation to prevent pnpm warnings/errors about global bin directory not in PATH.
  • Declares sentinel errors (errMissingExecutable, errMissingPackageURL, errCannotExtractRepo) evaluated with errors.Is.
  • Table-driven tests in internal/librarian/nodejs/install_test.go use a pnpm shell script stub. The stub handles pnpm add -g for non-build tool installations and asserts that required transient environment variables (PNPM_HOME, PNPM_CONFIG_GLOBAL_BIN_DIR, PNPM_CONFIG_GLOBAL_DIR, PNPM_CONFIG_STORE_DIR, and PNPM_CONFIG_DANGEROUSLY_ALLOW_ALL_BUILDS) are present during execution.
I ran `librarian install` and the executables are installed in the cache folder.
suztomo@suztomo:~/librarian-2026/google-cloud-node$ rm $(which pbjs)
suztomo@suztomo:~/librarian-2026/google-cloud-node$ which gapic-node-processing
/usr/local/google/home/suztomo/.nvm/versions/node/v22.22.3/bin/gapic-node-processing
suztomo@suztomo:~/librarian-2026/google-cloud-node$ rm $(which gapic-node-processing)
suztomo@suztomo:~/librarian-2026/google-cloud-node$ which gapic-generator-java
suztomo@suztomo:~/librarian-2026/google-cloud-node$ which gapic-generator-typescript
/usr/local/google/home/suztomo/.nvm/versions/node/v22.22.3/bin/gapic-generator-typescript
suztomo@suztomo:~/librarian-2026/google-cloud-node$ rm $(which gapic-generator-typescript)
suztomo@suztomo:~/librarian-2026/google-cloud-node$ /tmp/librarian install
Already up to date
...

Done in 1s using pnpm v11.10.0
suztomo@suztomo:~/librarian-2026/google-cloud-node$ which gapic-generator-typescript
suztomo@suztomo:~/librarian-2026/google-cloud-node$ /tmp/librarian debug env
LIBRARIAN_CACHE=/usr/local/google/home/suztomo/.cache/librarian
LIBRARIAN_BIN=/usr/local/google/home/suztomo/.cache/librarian/bin

Language-specific tool installation directories:
  golang: /usr/local/google/home/suztomo/.cache/librarian/bin/go_tools
  java: /usr/local/google/home/suztomo/.cache/librarian/bin/java_tools
  nodejs: /usr/local/google/home/suztomo/.cache/librarian/bin/nodejs_tools
suztomo@suztomo:~/librarian-2026/google-cloud-node$ export PATH=$PATH:/usr/local/google/home/suztomo/.cache/librarian/bin/nodejs_tools/bin
suztomo@suztomo:~/librarian-2026/google-cloud-node$ which gapic-generator-typescript
/usr/local/google/home/suztomo/.cache/librarian/bin/nodejs_tools/bin/gapic-generator-typescript
I ran generate without setting the PATH. Librarian used the bin directory.
suztomo@suztomo:~/librarian-2026/google-cloud-node$ which gapic-node-processing
suztomo@suztomo:~/librarian-2026/google-cloud-node$ /tmp/librarian generate google-cloud-agentregistry
suztomo@suztomo:~/librarian-2026/google-cloud-node$ git diff |head -30
diff --git a/packages/google-cloud-agentregistry/protos/protos.js b/packages/google-cloud-agentregistry/protos/protos.js
index e8aaa3ea7c..6154bd8bc0 100644
--- a/packages/google-cloud-agentregistry/protos/protos.js
+++ b/packages/google-cloud-agentregistry/protos/protos.js
@@ -28,7 +28,7 @@
     var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
     
     // Exported root namespace
-    var $root = $protobuf.roots._google_cloud_agentregistry_protos || ($protobuf.roots._google_cloud_agentregistry_protos = {});
+    var $root = $protobuf.roots["_google_cloud_agentregistry_protos"] || ($protobuf.roots["_google_cloud_agentregistry_protos"] = {});
     
     $root.google = (function() {
     
@@ -230,9:13 @@
                          * @param {$protobuf.Writer} [writer] Writer to encode to
                          * @returns {$protobuf.Writer} Writer
                          */
-                        Agent.encode = function encode(message, writer) {
+                        Agent.encode = function encode(message, writer, q) {
                             if (!writer)
                                 writer = $Writer.create();
+                            if (q === undefined)
+                                q = 0;
+                            if (q > $util.recursionLimit)
+                                throw Error("max depth exceeded");
                             if (message.name != null && Object.hasOwnProperty.call(message, "name"))
                                 writer.uint32(/* id 1, wireType 2 =*/10).string(message.name);
                             if (message.agentId != null && Object.hasOwnProperty.call(message, "agentId"))
@@ -247,23 +251,23 @@
                                 writer.uint32(/* id 7, wireType 2 =*/58).string(message.version);

@suztomo
suztomo requested a review from a team as a code owner July 7, 2026 17:20

@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 integrates Node.js tool installation paths into the librarian debug environment and updates Node.js command execution to run with the correct tools environment. It also refactors getPNPMEnv to configure pnpm paths using the librarian cache and bin directories instead of querying Node dynamically. Feedback was provided regarding a hardcoded path separator (:) when updating the PATH environment variable, which could cause issues on Windows; using os.PathListSeparator is recommended for cross-platform compatibility.

Comment thread internal/librarian/nodejs/install.go Outdated
@suztomo

suztomo commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Coverage...

ok  	github.com/googleapis/librarian/internal/librarian/nodejs	1.169s	coverage: 70.8% of statements
Coverage: 70.8% (target: 73%)
FAIL: coverage 70.8% is below target 73%

@suztomo
suztomo marked this pull request as draft July 7, 2026 18:44
Comment thread internal/librarian/nodejs/install_test.go
@suztomo
suztomo force-pushed the nodejs-install-cache-dir branch from 885dd86 to 953f9c6 Compare July 7, 2026 19:10
@suztomo
suztomo requested a review from JoeWang1127 July 7, 2026 19:19
@suztomo
suztomo marked this pull request as ready for review July 7, 2026 19:30
@suztomo

suztomo commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

The rest coverage is good now.

Comment thread internal/librarian/nodejs/install_test.go
Comment thread internal/librarian/nodejs/install.go
@suztomo

suztomo commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Updated to use nodejs_tools:

suztomo@suztomo:~/librarian-2026/librarian$ ls /usr/local/google/home/suztomo/.cache/librarian/bin/nodejs_tools/bin
compileProtos  gapic-generator-typescript  gapic-node-processing  listProtos  minifyProtoJson  pbjs  pbts  prepublishProtos  protoc-gen-typescript_gapic

It's itchy that the 'bin' folder contains a folder that contains 'bin'. But I don't address that in this pull request.

suztomo and others added 10 commits July 7, 2026 21:40
…dejs install

Update NodeJS tool installation to use LIBRARIAN_BIN directly for installed executables and LIBRARIAN_CACHE for downloaded google-cloud-node repository and pnpm cache/store.

Fixes googleapis#6678
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Tomo Suzuki <suztomo@gmail.com>
@suztomo
suztomo force-pushed the nodejs-install-cache-dir branch from 7df341c to 89969a4 Compare July 7, 2026 21:40
@JoeWang1127

Copy link
Copy Markdown
Contributor

It's itchy that the 'bin' folder contains a folder that contains 'bin'. But I don't address that in this pull request.

Could you create an issue for this, I can come up with another directory name.

@suztomo

suztomo commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Filed #6695.

@suztomo
suztomo merged commit 7f88869 into googleapis:main Jul 7, 2026
31 checks passed
sofisl pushed a commit to sofisl/librarian that referenced this pull request Jul 8, 2026
…dejs install (googleapis#6680)

Update NodeJS tool installation to use `$LIBRARIAN_BIN/nodejs_tools` for
installed executables (aligning with `go_tools` and `java_tools`) and
`LIBRARIAN_CACHE` for downloaded `google-cloud-node` repository and pnpm
cache/store.

Fixes googleapis#6678

- Installs Node.js tools in `$LIBRARIAN_BIN/nodejs_tools/bin` (with
`PNPM_HOME=$LIBRARIAN_BIN/nodejs_tools` and
`PNPM_CONFIG_GLOBAL_BIN_DIR=$LIBRARIAN_BIN/nodejs_tools/bin`).
- Prepends `$LIBRARIAN_BIN/nodejs_tools/bin` to `PATH` during tool
installation and generation to prevent `pnpm` warnings/errors about
global bin directory not in `PATH`.
- Declares sentinel errors (`errMissingExecutable`,
`errMissingPackageURL`, `errCannotExtractRepo`) evaluated with
`errors.Is`.
- Table-driven tests in `internal/librarian/nodejs/install_test.go` use
a `pnpm` shell script stub. The stub handles `pnpm add -g` for non-build
tool installations and asserts that required transient environment
variables (`PNPM_HOME`, `PNPM_CONFIG_GLOBAL_BIN_DIR`,
`PNPM_CONFIG_GLOBAL_DIR`, `PNPM_CONFIG_STORE_DIR`, and
`PNPM_CONFIG_DANGEROUSLY_ALLOW_ALL_BUILDS`) are present during
execution.

---------

Signed-off-by: Tomo Suzuki <suztomo@gmail.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
noahdietz pushed a commit that referenced this pull request Jul 13, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.26.0](v0.25.0...v0.26.0)
(2026-07-13)


### Features

* **internal/gem:** add gem package to install Ruby gem tools
([#6724](#6724))
([40ba6df](40ba6df))
* **internal/librarian/java:** add ApplyMoveActionsToLibrary helper and
unit tests
([#6731](#6731))
([f25bd33](f25bd33))
* **internal/librarian/java:** add RestructureToLibrary helper and unit
tests ([#6757](#6757))
([b2ff68c](b2ff68c)),
closes [#6516](#6516)
* **internal/librarian/java:** add ToKeepSet helper and unit tests
([#6730](#6730))
([df99304](df99304)),
closes [#6516](#6516)
* **internal/librarian/java:** integrate native Go postprocessor into
Java generator
([#6768](#6768))
([074059d](074059d)),
closes [#6516](#6516)
* **internal/librarian/java:** mark legacy postprocessing for
deprecation
([#6716](#6716))
([78a4ab6](78a4ab6)),
closes [#6516](#6516)
* **internal/librarian/nodejs:** use cache and bin directories for
nodejs install
([#6680](#6680))
([7f88869](7f88869))
* **internal/librarian/php:** add inital PHP client library generator
([#6703](#6703))
([9a45ab1](9a45ab1))
* **internal/librarian/php:** add tool installation directory helpers
([#6717](#6717))
([9cdf0b5](9cdf0b5)),
closes [#6630](#6630)
* **internal/librarian/ruby:** support installing Ruby gem dependencies
([#6751](#6751))
([bbce2c4](bbce2c4)),
closes [#6634](#6634)
* **internal/librarian:** add ruby tools directory to env output
([#6781](#6781))
([c220d71](c220d71))
* **internal/postprocessing:** add Apply pipeline runner and tests
([#6714](#6714))
([5cb8f66](5cb8f66)),
closes [#6516](#6516)
* **internal/postprocessing:** add ApplyMethodOperations batch runner
and tests ([#6698](#6698))
([8377d53](8377d53)),
closes [#6516](#6516)
* **internal/postprocessing:** add applyToFiles and RemoveFiles
([#6673](#6673))
([2f4b437](2f4b437)),
closes [#6516](#6516)
* **internal/postprocessing:** add CopyFiles batch runner and tests
([#6686](#6686))
([20c3a1a](20c3a1a))
* **internal/postprocessing:** add ReplaceAll and ReplaceRegexAll batch
runners and tests
([#6688](#6688))
([bb18f06](bb18f06))
* **internal/protoc:** add protoc installation and use installed
`protoc` in Java generation
([#6622](#6622))
([00ee24d](00ee24d))
* **internal/protoc:** add Run function
([#6699](#6699))
([cd8a1d4](cd8a1d4)),
closes [#6558](#6558)
* **internal/serviceconfig:** allowlist API paths for php
([#6789](#6789))
([7907686](7907686)),
closes [#6629](#6629)
* **internal/tool/gem:** verify input directories and tools before
installation
([#6778](#6778))
([3086d63](3086d63))
* **java:** append versions.txt on add
([#6653](#6653))
([9e9e645](9e9e645))
* **librarian/internal/config:** add php config
([#6701](#6701))
([939ae6f](939ae6f))
* **migrate:** discover and list PHP libraries during migration
([#6728](#6728))
([e552b89](e552b89))
* **sidekick/parser:** correct LRO poller service
([#6704](#6704))
([1d4b2d1](1d4b2d1))
* **sidekick/rust:** remove unstable gate for LRO tracing
([#6459](#6459))
([8266ce3](8266ce3))
* **sidekick/swift:** discovery LROs
([#6738](#6738))
([c294d15](c294d15))
* **sidekick/swift:** generate deprecation attributes
([#6750](#6750))
([145e8ae](145e8ae))
* **sidekick/swift:** traits with dependencies
([#6709](#6709))
([e8389f2](e8389f2))
* **swift:** add protobuf generation support
([#6697](#6697))
([3bebf26](3bebf26))
* **tool/cmd/migrate/php:** scaffold composer tools for php
([#6736](#6736))
([f23b451](f23b451))
* **tool/cmd/migrate:** add support to php
([#6726](#6726))
([586bac0](586bac0)),
closes [#6723](#6723)
* **tool/cmd/migrate:** support union versions in PHP OwlBot configs
([#6782](#6782))
([7690206](7690206)),
closes [#6779](#6779)


### Bug Fixes

* **internal/librarian/java:** remove excluded_poms from repometadata
([#6676](#6676))
([5e0f7f2](5e0f7f2))
* **internal/librarian/php:** enforce explicit API paths and add default
output path
([#6740](#6740))
([347bbd6](347bbd6))
* **internal/librarian:** preserve gem tools during tidy
([#6783](#6783))
([0150007](0150007))
* **internal/librarian:** preserve maven and protoc configuration during
tidy ([#6702](#6702))
([b439528](b439528)),
closes [#6558](#6558)
* **internal/snippetmetadata:** disable HTML escaping in JSON output
([#6777](#6777))
([4da5e28](4da5e28)),
closes [#6776](#6776)
* **librarian/rust:** detect inconsistent repos
([#6766](#6766))
([82ce5a9](82ce5a9))
* **sidekick/swift:** missing enum value docs
([#6727](#6727))
([e9020d2](e9020d2))
* **tool/cmd/migrate:** populate API paths from .OwlBot.yaml during
migrate for php
([#6739](#6739))
([6a15260](6a15260))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
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.

nodejs: use the cache directory to hold files for the install command

2 participants