Skip to content

Commit

Permalink
feat/fix: Remove version requirement from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
tobni committed May 9, 2023
1 parent 20bbcca commit 919abae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/python/pants/backend/javascript/package/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
NodeBuildScriptSourcesField,
NodePackageNameField,
NodePackageVersionField,
NPMDistributionTarget,
PackageJsonSourceField,
)
from pants.build_graph.address import Address
Expand Down Expand Up @@ -85,6 +86,10 @@ async def pack_node_package_into_tgz_for_publication(
node_package = installation.project_env.ensure_target()
name = node_package.get(NodePackageNameField).value
version = node_package.get(NodePackageVersionField).value
if version is None:
raise ValueError(
f"{field_set.source.file_path}#version must be set in order to package a {NPMDistributionTarget.alias}."
)
archive_file = f"{name}-{version}.tgz"
result = await Get(
ProcessResult,
Expand Down
8 changes: 4 additions & 4 deletions src/python/pants/backend/javascript/package_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ class NodePackageVersionField(StringField):
This field should not be overridden; use the value from target generation.
"""
)
required = True
value: str
required = False
value: str | None


class NodeThirdPartyPackageVersionField(NodePackageVersionField):
Expand Down Expand Up @@ -533,7 +533,7 @@ def from_package_json(cls, pkg_json: PackageJson) -> PackageJsonScripts:
class PackageJson:
content: FrozenDict[str, Any]
name: str
version: str
version: str | None
snapshot: Snapshot
workspaces: tuple[str, ...] = ()
module: Literal["commonjs", "module"] | None = None
Expand Down Expand Up @@ -632,7 +632,7 @@ async def parse_package_json(content: FileContent) -> PackageJson:
return PackageJson(
content=parsed_package_json,
name=parsed_package_json["name"],
version=parsed_package_json["version"],
version=parsed_package_json.get("version"),
snapshot=await Get(Snapshot, PathGlobs([content.path])),
module=parsed_package_json.get("type"),
workspaces=tuple(parsed_package_json.get("workspaces", ())),
Expand Down

0 comments on commit 919abae

Please sign in to comment.