nots.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os
  2. from _common import to_yesno
  3. from lib.nots.package_manager import manager
  4. from lib.nots.typescript import TsConfig
  5. def _create_pm(unit):
  6. return manager(
  7. sources_path=unit.resolve(unit.path()),
  8. build_root="$B",
  9. build_path=unit.path().replace("$S", "$B", 1),
  10. contribs_path=unit.get("NPM_CONTRIBS_PATH"),
  11. nodejs_bin_path=None,
  12. script_path=None,
  13. )
  14. def on_from_npm_lockfiles(unit, *args):
  15. lf_paths = map(lambda p: unit.resolve(unit.resolve_arc_path(p)), args)
  16. for pkg in _create_pm(unit).extract_packages_meta_from_lockfiles(lf_paths):
  17. unit.onfrom_npm([pkg.name, pkg.version, pkg.sky_id, pkg.integrity, pkg.integrity_algorithm, pkg.tarball_path])
  18. def onnode_modules(unit):
  19. pm = _create_pm(unit)
  20. unit.onpeerdir(pm.get_peer_paths_from_package_json())
  21. ins, outs = pm.calc_node_modules_inouts()
  22. unit.on_node_modules(["IN"] + sorted(ins) + ["OUT"] + sorted(outs))
  23. def on_ts_configure(unit, tsconfig_path):
  24. abs_tsconfig_path = unit.resolve(unit.resolve_arc_path(tsconfig_path))
  25. if not abs_tsconfig_path:
  26. raise Exception("tsconfig not found: {}".format(tsconfig_path))
  27. tsconfig = TsConfig.load(abs_tsconfig_path)
  28. tsconfig.validate()
  29. unit.set(["TS_CONFIG_ROOT_DIR", tsconfig.compiler_option("rootDir")])
  30. unit.set(["TS_CONFIG_OUT_DIR", tsconfig.compiler_option("outDir")])
  31. unit.set(["TS_CONFIG_SOURCE_MAP", to_yesno(tsconfig.compiler_option("sourceMap"))])
  32. unit.set(["TS_CONFIG_DECLARATION", to_yesno(tsconfig.compiler_option("declaration"))])
  33. unit.set(["TS_CONFIG_DECLARATION_MAP", to_yesno(tsconfig.compiler_option("declarationMap"))])
  34. unit.set(["TS_CONFIG_PRESERVE_JSX", to_yesno(tsconfig.compiler_option("jsx") == "preserve")])