aboutsummaryrefslogtreecommitdiffstats
path: root/build/plugins/nots.py
diff options
context:
space:
mode:
authorzaverden <zaverden@yandex-team.com>2024-07-18 21:17:16 +0300
committerzaverden <zaverden@yandex-team.com>2024-07-18 21:27:44 +0300
commitbe0dfb42b3e15e4d8ac221200d48a55cead36dd8 (patch)
tree180249315a1fd25c3fb439ca9b13301b9eb710c0 /build/plugins/nots.py
parent0a7acacbbb400208d9bfe3610f1f77c38c3c0d7d (diff)
downloadydb-be0dfb42b3e15e4d8ac221200d48a55cead36dd8.tar.gz
feat(npm): build standalone npm module
f944a35c196f6f7b7d93b7d2e9716fcd57f85d9f
Diffstat (limited to 'build/plugins/nots.py')
-rw-r--r--build/plugins/nots.py55
1 files changed, 45 insertions, 10 deletions
diff --git a/build/plugins/nots.py b/build/plugins/nots.py
index 4a2f8474da..b99de011d4 100644
--- a/build/plugins/nots.py
+++ b/build/plugins/nots.py
@@ -4,7 +4,7 @@ import os
import ymake
import ytest
-from _common import resolve_common_const, get_norm_unit_path, rootrel_arc_src, to_yesno
+from _common import resolve_common_const, get_norm_unit_path, rootrel_arc_src, strip_roots, to_yesno
# 1 is 60 files per chunk for TIMEOUT(60) - default timeout for SIZE(SMALL)
@@ -118,16 +118,28 @@ def _build_cmd_input_paths(paths, hide=False, disable_include_processor=False):
return _build_directives("input", [hide_part, disable_ip_part], paths)
+def _get_pm_type(unit) -> str:
+ resolved = unit.get("PM_TYPE")
+ if not resolved:
+ raise Exception("PM_TYPE is not set yet. Macro _SET_PACKAGE_MANAGER() should be called before.")
+
+ return resolved
+
+
+def _get_source_path(unit):
+ sources_path = unit.get("TS_TEST_FOR_DIR") if unit.get("TS_TEST_FOR") else unit.path()
+ return sources_path
+
+
def _create_pm(unit):
- from lib.nots.package_manager import manager
+ from lib.nots.package_manager import get_package_manager_type
+
+ sources_path = _get_source_path(unit)
+ module_path = unit.get("TS_TEST_FOR_PATH") if unit.get("TS_TEST_FOR") else unit.get("MODDIR")
- sources_path = unit.path()
- module_path = unit.get("MODDIR")
- if unit.get("TS_TEST_FOR"):
- sources_path = unit.get("TS_TEST_FOR_DIR")
- module_path = unit.get("TS_TEST_FOR_PATH")
+ PackageManager = get_package_manager_type(_get_pm_type(unit))
- return manager(
+ return PackageManager(
sources_path=unit.resolve(sources_path),
build_root="$B",
build_path=unit.path().replace("$S", "$B", 1),
@@ -148,6 +160,25 @@ def _create_erm_json(unit):
@_with_report_configure_error
+def on_set_package_manager(unit):
+ pm_type = "pnpm" # projects without any lockfile are processed by pnpm
+
+ source_path = _get_source_path(unit)
+
+ for pm_key, lockfile_name in [("pnpm", "pnpm-lock.yaml"), ("npm", "package-lock.json")]:
+ lf_path = os.path.join(source_path, lockfile_name)
+ lf_path_resolved = unit.resolve_arc_path(strip_roots(lf_path))
+
+ if lf_path_resolved:
+ pm_type = pm_key
+ break
+
+ unit.on_peerdir_ts_resource(pm_type)
+ unit.set(["PM_TYPE", pm_type])
+ unit.set(["PM_SCRIPT", f"${pm_type.upper()}_SCRIPT"])
+
+
+@_with_report_configure_error
def on_set_append_with_directive(unit, var_name, dir, *values):
wrapped = ['${{{dir}:"{v}"}}'.format(dir=dir, v=v) for v in values]
__set_append(unit, var_name, " ".join(wrapped))
@@ -157,6 +188,9 @@ def on_set_append_with_directive(unit, var_name, dir, *values):
def on_from_npm_lockfiles(unit, *args):
from lib.nots.package_manager.base import PackageManagerError
+ # This is contrib with pnpm-lock.yaml files only
+ # Force set to pnpm
+ unit.set(["PM_TYPE", "pnpm"])
pm = _create_pm(unit)
lf_paths = []
@@ -192,8 +226,9 @@ def _check_nodejs_version(unit, major):
@_with_report_configure_error
def on_peerdir_ts_resource(unit, *resources):
- pm = _create_pm(unit)
- pj = pm.load_package_json_from_dir(pm.sources_path)
+ from lib.nots.package_manager import BasePackageManager
+
+ pj = BasePackageManager.load_package_json_from_dir(unit.resolve(_get_source_path(unit)))
erm_json = _create_erm_json(unit)
dirs = []