Skip to content

Commit

Permalink
WIP for action based yarn install
Browse files Browse the repository at this point in the history
  • Loading branch information
Silic0nS0ldier committed Feb 7, 2024
1 parent 88361df commit 98ab7d2
Show file tree
Hide file tree
Showing 23 changed files with 254 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0rc6
7.0.2
126 changes: 109 additions & 17 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion e2e/bazel_6_litmus/.bazelversion

This file was deleted.

1 change: 0 additions & 1 deletion e2e/bazel_6_litmus_workspace/.bazelversion

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions e2e/bazel_7_litmus/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.0.2
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module(
name = "bazel_6_litmus",
name = "bazel_7_litmus",
version = "0.0.0",
compatibility_level = 0,
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions e2e/bazel_7_litmus_workspace/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.0.2
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
53 changes: 50 additions & 3 deletions lib/private/extensions/node_modules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
`node_modules` module extension implementation.
"""

load("//lib/private:repositories.bzl", "yarn_install", "YARN_INSTALL_ATTRS")
load("//lib/private:repositories.bzl", "yarn_install", "yarn_install_via_action", "YARN_INSTALL_ATTRS")

visibility(["//lib/private"])

def _node_modules_impl(mctx):
root_modules = []
for mod in mctx.modules:
# TODO Use mod.is_root to detect root module and include in returns
for attrs in mod.tags.yarn:
if mod.is_root:
root_modules.append(attrs.name)
Expand All @@ -31,6 +30,18 @@ def _node_modules_impl(mctx):
host_node_bin = attrs.host_node_bin,
host_yarn_bin = attrs.host_yarn_bin,
)
for attrs in mod.tags.yarn_via_action:
if mod.is_root:
root_modules.append(attrs.name)
yarn_install_via_action(
name = attrs.name,
package_json = attrs.package_json,
yarn_lock = attrs.yarn_lock,
package_path = attrs.package_path,
host_node_bin = attrs.host_node_bin,
data = attrs.data,
quiet = attrs.quiet,
)

return mctx.extension_metadata(
root_module_direct_deps = root_modules,
Expand All @@ -47,7 +58,43 @@ node_modules = module_extension(
),
}),
doc = "",
)
),
# The Plan
#
# 1. Repo rule parses package.json and yarn.lock
# 2. Repo rule generates `BUILD.bazel` file that calls `yarn_install_via_action`
# This is done so that outputs go to the same directory as the `yarn_install` repo rule.
# 3. Existing interface is preserved, work is just deferred to exec stage.
"yarn_via_action": tag_class(
attrs = {
"name": attr.string(
mandatory = True,
),
"package_json": attr.label(
allow_single_file = True,
mandatory = True,
),
"yarn_lock": attr.label(
allow_single_file = True,
mandatory = True,
),
"package_path": attr.string(
mandatory = True,
),
"host_node_bin": attr.label(
allow_single_file = True,
mandatory = True,
),
"data": attr.label(
allow_files = True,
),
"quiet": attr.bool(
default = True,
doc = "Hides output, except in the event of install failure.",
),
},
doc = "",
),
},
doc = "",
)
2 changes: 2 additions & 0 deletions lib/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ load("//lib/private:repositories/nodejs_toolchain_configure/impl.bzl", _nodejs_t
load("//lib/private:repositories/nodejs_toolchains.bzl", _nodejs_toolchains = "nodejs_toolchains")
load("//lib/private:repositories/yarn_install/attrs.bzl", _YARN_INSTALL_ATTRS = "YARN_INSTALL_ATTRS")
load("//lib/private:repositories/yarn_install/impl.bzl", _yarn_install = "yarn_install")
load("//lib/private:repositories/yarn_install_via_action/impl.bzl", _yarn_install_via_action = "yarn_install_via_action")

visibility(["//", "//lib"])

YARN_INSTALL_ATTRS = _YARN_INSTALL_ATTRS
yarn_install = _yarn_install
yarn_install_via_action = _yarn_install_via_action
nodejs_download = _nodejs_download
nodejs_download_host = _nodejs_download_host
nodejs_toolchain_configure = _nodejs_toolchain_configure
Expand Down
52 changes: 52 additions & 0 deletions lib/private/repositories/yarn_install_via_action/impl.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
"""

visibility(["//lib/private"])

def _impl(rctx):
pass
# 1. Resolve `package.json` and `yarn.lock` paths.

# 2. Process in their original location using API from forked Yarn.

# 3. Using data from `hoisted` API, generate `BUILD.bazel` file.
# Required targets to match existing API follow.
# - `:node_modules`, catch-all target that includes all dependencies.
# Rule type: `js_library`.
# - `:node_modules/{package_name}`, an alias that allows a subset of outputs to be referenced.
# Rule type: NA, source files.
# - `[{package_scope}/]{package_name}:{package_name}`, normal way packages are referenced
# Rule type: `js_library`.
# - `[{package_scope}/]{package_name}:{package_name}__contents`, implementation detail.
# Rule type: `js_library`.
# - `[{package_scope}/]{package_name}:{package_name}__files`, implementation detail.
# Rule type: `filegroup`.
# - `[{package_scope}/]{package_name}:{package_name}__typings`, implementation detail.
# Rule type: `alias`.
# - `[{package_scope}/]{package_name}:{package_name}__umd`, implementation detail, unused.
# Rule type: `npm_umd_bundle`.
# - `[{package_scope}/]{package_name}:{package_name}__umd_directory_file_path`, implementation detail, unused.
# Rule type: `directory_file_path`.

yarn_install_via_action = repository_rule(
implementation = _impl,
attrs = {
"package_json": attr.label(
mandatory = True,
allow_single_file = True,
),
"yarn_lock": attr.label(
mandatory = True,
allow_single_file = True,
),
"host_node_bin": attr.label(
mandatory = True,
allow_single_file = True,
),
},
doc = """
Parses `package.json` and `yarn.lock`, extracting data required for the `yarn_install` rule.
The result is similar to the `yarn_install` repository rule when operating in directory mode.
""",
)
Loading

0 comments on commit 98ab7d2

Please sign in to comment.