GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: improve package.json lookup for root name (#1530) · googleapis/gax-nodejs@3ec09cf

This repository was archived by the owner on Nov 18, 2025. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • tools
    • package.json
    • src
      • compileProtos.ts
    • test
      • compileProtos.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎tools/package.json‎

Copy file name to clipboardExpand all lines: tools/package.json
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
"author": "Google API Authors",
2929
"license": "Apache-2.0",
3030
"dependencies": {
31+
"@babel/core": "^7.22.5",
32+
"@babel/traverse": "^7.22.5",
3133
"google-gax": "^4.1.0",
3234
"google-proto-files": "^4.1.0",
3335
"protobufjs-cli": "1.1.2",
3436
"rimraf": "^5.0.1",
35-
"@babel/core": "^7.22.5",
36-
"@babel/traverse": "^7.22.5",
3737
"uglify-js": "^3.17.0",
38+
"walk-up-path": "^3.0.1",
3839
"walkdir": "^0.4.0"
3940
},
4041
"repository": {
Collapse file

‎tools/src/compileProtos.ts‎

Copy file name to clipboardExpand all lines: tools/src/compileProtos.ts
+11-8Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as path from 'path';
2121
import * as util from 'util';
2222
import * as pbjs from 'protobufjs-cli/pbjs';
2323
import * as pbts from 'protobufjs-cli/pbts';
24+
import {walkUp} from 'walk-up-path';
2425

2526
export const gaxProtos = path.join(
2627
require.resolve('google-gax'),
@@ -360,14 +361,16 @@ export async function generateRootName(directories: string[]): Promise<string> {
360361
// It's OK to play some guessing game here: if we locate `package.json`
361362
// with a package name, we'll use it; otherwise, we'll fallback to 'default'.
362363
for (const directory of directories) {
363-
const packageJson = path.resolve(directory, '..', 'package.json');
364-
if (fs.existsSync(packageJson)) {
365-
const json = JSON.parse((await readFile(packageJson)).toString()) as {
366-
name: string;
367-
};
368-
const name = json.name.replace(/[^\w\d]/g, '_');
369-
const hopefullyUniqueName = `${name}_protos`;
370-
return hopefullyUniqueName;
364+
for (const p of walkUp(path.resolve(directory, '..'))) {
365+
const packageJson = path.join(p, 'package.json');
366+
if (fs.existsSync(packageJson)) {
367+
const json = JSON.parse((await readFile(packageJson)).toString()) as {
368+
name: string;
369+
};
370+
const name = json.name.replace(/[^\w\d]/g, '_');
371+
const hopefullyUniqueName = `${name}_protos`;
372+
return hopefullyUniqueName;
373+
}
371374
}
372375
}
373376
return 'default';
Collapse file

‎tools/test/compileProtos.ts‎

Copy file name to clipboardExpand all lines: tools/test/compileProtos.ts
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,17 @@ describe('compileProtos tool', () => {
281281
assert.strictEqual(rootName, '_org_fake_package_protos');
282282
});
283283

284-
it('falls back to the default name for protobuf root if unable to guess', async () => {
284+
it('uses the nearest package.json to guess the root name', async () => {
285285
const rootName = await compileProtos.generateRootName([
286286
path.join(__dirname, 'protoLists', 'empty'),
287287
]);
288+
assert.strictEqual(rootName, 'gapic_tools_protos');
289+
});
290+
291+
it('falls back to the default name for protobuf root if unable to guess', async () => {
292+
const rootName = await compileProtos.generateRootName([
293+
'/nonexistent/empty',
294+
]);
288295
assert.strictEqual(rootName, 'default');
289296
});
290297

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.