Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript: NodeJS bootstrapping via binary paths, PATH, asdf or nvm #18520

Merged
merged 17 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 3rdparty/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python_requirements(
"strawberry-graphql": ["strawberry"],
"beautifulsoup4": ["bs4"],
"python-gnupg": ["gnupg"],
"node-semver": ["nodesemver"],
},
overrides={
"humbug": {"dependencies": ["#setuptools"]},
Expand Down
1 change: 1 addition & 0 deletions 3rdparty/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ types-setuptools==62.6.1
types-toml==0.10.8
typing-extensions==4.3.0
mypy-typing-asserts==0.1.1
node-semver==0.9.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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



# This dependency is only for debugging Pants itself, and should never be imported
Expand Down
22 changes: 22 additions & 0 deletions 3rdparty/python/user_reqs.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// "ijson==3.1.4",
// "importlib_resources==5.0.*",
// "mypy-typing-asserts==0.1.1",
// "node-semver==0.9.0",
// "packaging==21.3",
// "pex==2.1.129",
// "psutil==5.9.0",
Expand Down Expand Up @@ -1048,6 +1049,26 @@
"requires_python": "<4.0,>=3.7",
"version": "0.1.1"
},
{
"artifacts": [
{
"algorithm": "sha256",
"hash": "8153270903772b1e59500ced6f0aca0f7bdb021651c27584e9283b7077b4916b",
"url": "https://files.pythonhosted.org/packages/1a/4b/180481021692a76dc91f46fa6a49cdef4c3e630c77a83b7fda3f4eb7aa04/node_semver-0.9.0-py3-none-any.whl"
},
{
"algorithm": "sha256",
"hash": "04aa0b0016dbc06748d6378c42d8cf82a343415bd9fca6284f488041d08b33bb",
"url": "https://files.pythonhosted.org/packages/eb/c5/e823658f716b17ab1c52d68ed13a0e09c0130af052401a26b5738e4290cc/node-semver-0.9.0.tar.gz"
}
],
"project_name": "node-semver",
"requires_dists": [
"pytest; extra == \"testing\""
],
"requires_python": null,
"version": "0.9.0"
},
{
"artifacts": [
{
Expand Down Expand Up @@ -2787,6 +2808,7 @@
"ijson==3.1.4",
"importlib_resources==5.0.*",
"mypy-typing-asserts==0.1.1",
"node-semver==0.9.0",
"packaging==21.3",
"pex==2.1.129",
"psutil==5.9.0",
Expand Down
25 changes: 15 additions & 10 deletions src/python/pants/backend/javascript/subsystems/nodejs.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,24 @@ async def node_process_environment(nodejs: NodeJS, platform: Platform) -> NodeJS
return NodeJSProcessEnvironment(binary_directory=nodejs_bin_dir, npm_config_cache="._npm")


@rule(level=LogLevel.DEBUG)
async def setup_node_tool_process(
request: NodeJSToolProcess,
nodejs: NodeJS,
platform: Platform,
environment: NodeJSProcessEnvironment,
) -> Process:
# Ensure nodejs is installed
downloaded_nodejs = await Get(
@dataclass(frozen=True)
class NodejsBinaries:
digest: Digest


@rule(level=LogLevel.INFO, desc="Determining nodejs binaries.")
async def determine_nodejs_binaries(nodejs: NodeJS, platform: Platform) -> NodejsBinaries:
downloaded = await Get(
DownloadedExternalTool, ExternalToolRequest, nodejs.get_request(platform)
)
return NodejsBinaries(downloaded.digest)


immutable_input_digests = {environment.base_bin_dir: downloaded_nodejs.digest}
@rule(level=LogLevel.DEBUG)
async def setup_node_tool_process(
request: NodeJSToolProcess, binaries: NodejsBinaries, environment: NodeJSProcessEnvironment
) -> Process:
immutable_input_digests = {environment.base_bin_dir: binaries.digest}

return Process(
argv=filter(None, request.args),
Expand Down