Skip to content

Commit 2643dfe

Browse files
authored
chore(node): handle when package.json does not have a version
* test: failing test for repo without version in package.json * fix(node): handle when package.json does not have a version * chore: fix lint
1 parent 453a5d9 commit 2643dfe

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

synthtool/languages/node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ def owlbot_main(
340340
templates = common_templates.node_library(source_location="build/src")
341341
s_copy([templates], excludes=templates_excludes)
342342

343-
library_version = template_metadata()["version"]
344-
common.update_library_version(library_version, _GENERATED_SAMPLES_DIRECTORY)
343+
library_version = template_metadata().get("version")
344+
if library_version:
345+
common.update_library_version(library_version, _GENERATED_SAMPLES_DIRECTORY)
345346

346347

347348
if __name__ == "__main__":
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "repo-automation-bots",
3+
"name_pretty": "Repo Automation Bots",
4+
"release_level": "stable",
5+
"language": "nodejs",
6+
"repo": "googleapis/repo-automation-bots",
7+
"distribution_name": "repo-automation-bots",
8+
"codeowner_team": "@googleapis/github-automation",
9+
"client_documentation": "https://cloud.google.com/nodejs/docs/reference/repo-automation-bots/latest",
10+
"library_type": "OTHER"
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "repo-automation-bots",
3+
"private": true,
4+
"license": "Apache-2.0",
5+
"repository": "googleapis/repo-automation-bots",
6+
"engines": {
7+
"node": ">=12.0.0"
8+
},
9+
"scripts": {
10+
"run": "./scripts/scripts.js",
11+
"fix": "npm run run -- npm run fix",
12+
"test": "c8 npm run run -- npm test",
13+
"proxy": "smee",
14+
"generate-bot": "node ./packages/generate-bot/run.js"
15+
},
16+
"devDependencies": {
17+
"c8": "^7.1.0",
18+
"gaxios": "^5.0.0",
19+
"smee-client": "^1.1.0",
20+
"@google-cloud/mono-repo-publish": "^1.0.0"
21+
}
22+
}

tests/test_node.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,9 @@ def patch(library: Path):
276276
assert "import * as v2" in staging_text
277277
assert "export * as v2" not in staging_text
278278
assert "export * as v2" in text
279+
280+
281+
def test_owlbot_main_without_version():
282+
with util.copied_fixtures_dir(FIXTURES / "node_templates" / "no_version"):
283+
# just confirm it doesn't throw an exception.
284+
node.owlbot_main(TEMPLATES)

0 commit comments

Comments
 (0)