ts.conf 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. NODEJS_ROOT=
  2. NODEJS_BIN=$NODEJS_ROOT/node
  3. _TS_REQUIRED_MISSING=~~required~~
  4. TS_TRACE=no
  5. TS_LOG=no
  6. TS_LOCAL_CLI=no
  7. TS_YNDEXING=no
  8. # Use outdir defined in tsconfig (actual not for bundlers, they use own way to define output directory)
  9. TS_CONFIG_USE_OUTDIR=
  10. TS_USE_PREBUILT_NOTS_TOOL=yes
  11. NOTS_TOOL=${tool:"devtools/frontend_build_platform/nots/builder"}
  12. # Additional commands that module can add (with `&&` as delimiter), if set those will be executed
  13. # in build phase just before building the module.
  14. _TS_PROJECT_SETUP_CMD=
  15. TS_CONFIG_PATH=tsconfig.json
  16. ### @usage: TS_CONFIG(ConfigPath)
  17. ###
  18. ### Macro sets the path for "TypeScript Config".
  19. ###
  20. ### - ConfigPath - config path (one at least)
  21. ###
  22. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-config
  23. macro TS_CONFIG(FirstConfigPath, ConfigPath...) {
  24. SET(TS_CONFIG_PATH $FirstConfigPath $ConfigPath)
  25. }
  26. # Arguments for the all commands of the `nots/builder`, passed before the command
  27. NOTS_TOOL_BASE_ARGS=\
  28. --arcadia-root $ARCADIA_ROOT \
  29. --arcadia-build-root $ARCADIA_BUILD_ROOT \
  30. --moddir $MODDIR \
  31. --local-cli $TS_LOCAL_CLI \
  32. --nodejs-bin $NODEJS_BIN \
  33. --pm-script $PM_SCRIPT \
  34. --pm-type $PM_TYPE \
  35. --trace $TS_TRACE \
  36. --verbose $TS_LOG \
  37. $_YATOOL_PREBUILDER_ARG
  38. NOTS_TOOL_BUILD_ENV=
  39. # All variable that potentially can affect CMD are listed for UID generation
  40. # Requirements does not have effect on output
  41. # By adding __NO_UID__ suffix we show that this variable is not a part of the UID
  42. NOTS_TOOL_BUILD_REQUIREMENTS__NO_UID__=
  43. when($AUTOCHECK == "yes") {
  44. # we don't want to have requirements for local runs
  45. NOTS_TOOL_BUILD_REQUIREMENTS__NO_UID__=${hide;requirements:"cpu:4"}
  46. }
  47. _RUN_JAVASCRIPT_AFTER_BUILD_ARGS=
  48. _RUN_JAVASCRIPT_AFTER_BUILD_INPUTS=
  49. # Arguments for builders' commands, passed after the command
  50. # TODO FBP-1978 (remove output.tar output)
  51. NOTS_TOOL_COMMON_BUILDER_ARGS=\
  52. --output-file ${output:TARGET} ${hide;output:"output.tar"} ${hide;output:"output.tar.uuid"} \
  53. --tsconfigs $TS_CONFIG_PATH \
  54. --vcs-info "${VCS_INFO_FILE}" \
  55. $NOTS_TOOL_BUILD_REQUIREMENTS__NO_UID__ \
  56. $NOTS_TOOL_BUILD_ENV \
  57. $_RUN_JAVASCRIPT_AFTER_BUILD_ARGS \
  58. $_RENDER_RUN_JAVASCRIPT_AFTER_BUILD_INPUTS($_RUN_JAVASCRIPT_AFTER_BUILD_INPUTS)
  59. ERM_PACKAGES_PATH=devtools/frontend_build_platform/erm/erm-packages.json
  60. TS_EXCLUDE_DIR_GLOB=(.idea|.vscode|node_modules)/**/*
  61. TS_COMMON_OUTDIR_GLOB=(build|dist|bundle|\${join=|:WEBPACK_OUTPUT_DIR}|$TS_NEXT_OUTPUT_DIR|$VITE_OUTPUT_DIR)/**/*
  62. TS_GLOB_EXCLUDE_ADDITIONAL=
  63. ### @usage: TS_EXCLUDE_FILES_GLOB(GlobExpression)
  64. ###
  65. ### Macro sets glob to mark some files to ignore while building.
  66. ### These files won't be copied to BINDIR.
  67. ###
  68. ### - GlobExpression - glob expression
  69. ###
  70. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-exclude-files-glob
  71. macro TS_EXCLUDE_FILES_GLOB(GlobExpression) {
  72. SET(TS_GLOB_EXCLUDE_ADDITIONAL $GlobExpression)
  73. }
  74. module _TS_BASE_UNIT: _BARE_UNIT {
  75. # Propagates peers to related modules
  76. .PEERDIR_POLICY=as_build_from
  77. .NODE_TYPE=Bundle
  78. # Needed for DEPENDS in tests to choose right submodule from multimodule
  79. .FINAL_TARGET=yes
  80. # use TS_FILES instead of FILES
  81. .ALIASES=FILES=TS_FILES
  82. # .NODE_TYPE=Bundle is required for peers propagation, but it also affects
  83. # how merging of pic/nopic graphs. Here we can override this merging behaviour
  84. SET(MODULE_TYPE LIBRARY)
  85. # Include processor works only for TS tag
  86. SET(MODULE_TAG TS)
  87. SET(MODULE_LANG TS)
  88. # TS should peer to TS
  89. SET(PEERDIR_TAGS TS TS_PROTO TS_PROTO_FROM_SCHEMA)
  90. SET(MODULE_SUFFIX .output.tar)
  91. # We read erm-packages.json during configuration, so we have to include it to configuration cache key
  92. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/$ERM_PACKAGES_PATH)
  93. # PEERDIR that reads required version of tool from package.json
  94. _PEERDIR_TS_RESOURCE(nodejs)
  95. _SET_PACKAGE_MANAGER()
  96. }
  97. # tag:test
  98. ESLINT_CONFIG_PATH=.eslintrc.js
  99. ### @usage: TS_ESLINT_CONFIG(ConfigPath)
  100. ###
  101. ### Macro sets the path for ESLint config file.
  102. ###
  103. ### - ConfigPath - config path
  104. ###
  105. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-eslint-config
  106. macro TS_ESLINT_CONFIG(ConfigName) {
  107. SET(ESLINT_CONFIG_PATH $ConfigName)
  108. }
  109. _TS_LINT_SRCS_VALUE=
  110. ### @usage: _TS_CONFIG_EPILOGUE() # internal
  111. ###
  112. ### This macro executes macros which should be invoked after all user specified macros in the ya.make file
  113. macro _TS_CONFIG_EPILOGUE() {
  114. ### Fill $TS_GLOB_FILES with potential inputs.
  115. ### It will be reduced later in _TS_CONFIGURE based on `tsconfig.json` rules.
  116. _GLOB(TS_GLOB_FILES $TS_GLOB_INCLUDE EXCLUDE $TS_GLOB_EXCLUDE)
  117. _GLOB(_TS_LINT_SRCS_VALUE **/*.(ts|tsx|js|jsx) EXCLUDE $TS_EXCLUDE_DIR_GLOB $TS_COMMON_OUTDIR_GLOB $TS_GLOB_EXCLUDE_ADDITIONAL)
  118. _SETUP_BUILD_ENV()
  119. }
  120. TSYNDEXER_OUTPUT_FILE=tsyndex.ydx.pb2
  121. TSYNDEXER_TOOL=${tool:"devtools/codenav/typescript"}
  122. TSYNDEXER_CMD=${cwd:ARCADIA_BUILD_ROOT} \
  123. $TSYNDEXER_TOOL -m ${CURDIR} -o ${output:TSYNDEXER_OUTPUT_FILE} -r ${ARCADIA_ROOT} \
  124. ${hide;kv:"pc magenta"} ${hide;kv:"p YTS"} $_AS_HIDDEN_INPUTS(IN $_TS_LINT_SRCS_VALUE)
  125. ### @usage: _DO_TS_YNDEXING() # internal
  126. ###
  127. ### Adds a command-node for TS-modules codenavigation indexing.
  128. ### Output ydx.pb2 file will be processed along with other indexes for other modules and
  129. ### other languages in ya-bin.
  130. ### (see _gen_merge_node, _gen_upload_node in devtools/ya/build/graph.py) for details.
  131. ### The macro is called from nots.py plugin in case we have `TS_YNDEXING=yes` flag set.
  132. macro _DO_TS_YNDEXING() {
  133. .CMD=$TSYNDEXER_CMD
  134. }
  135. # Used as inputs in TS_COMPILE through `$_AS_HIDDEN_INPUTS(IN $TS_INPUT_FILES)`
  136. TS_INPUT_FILES=
  137. # List of the files, filled in _TS_CONFIG_EPILOGUE. Will be reduced in _TS_CONFIGURE macro to TS_INPUT_FILES.
  138. TS_GLOB_FILES=
  139. # Hardcoded "include" list (all other files will be ignored)
  140. TS_GLOB_INCLUDE=**/*
  141. # Hardcoded "exclude" list (reasonable default).
  142. TS_GLOB_EXCLUDE=$TS_CONFIG_PATH \
  143. ya.make a.yaml \
  144. $TS_EXCLUDE_DIR_GLOB \
  145. $TS_COMMON_OUTDIR_GLOB \
  146. $TS_GLOB_EXCLUDE_ADDITIONAL \
  147. package.json pnpm-lock.yaml .* \
  148. tests/**/* **/*.(test|spec).(ts|tsx|js|jsx)
  149. # Ugly hack for using inputs from the variable
  150. macro _AS_HIDDEN_INPUTS(IN{input}[]) {
  151. # "context=TEXT" exclude file from the "include processing"
  152. .CMD=${hide;context=TEXT;input:IN}
  153. }
  154. # Input/output directives for files set by use with
  155. # SRCS / TS_LARGE_FILES / TS_FILES / TS_FILES_GLOB
  156. _TS_FILES_INOUTS=
  157. ### @usage: TS_FILES(Files...)
  158. ###
  159. ### Adds files to output as is. Does not add a command to copy the file to builddir.
  160. ### Similar to FILES but works for TS build modules
  161. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/TS_PACKAGE#ts-files
  162. macro TS_FILES(Files...) {
  163. # TODO: FBP-1795
  164. _TS_FILES($Files)
  165. }
  166. ### @usage: TS_FILES_GLOB(Glob...)
  167. ###
  168. ### Adds files to output by glob, e.g. TS_FILES_GLOB(**/*.css)
  169. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/TS_PACKAGE#ts-files-glob
  170. macro TS_FILES_GLOB(Glob...) {
  171. _GLOB(FILES_BY_GLOB ${Glob})
  172. TS_FILES(${FILES_BY_GLOB})
  173. }
  174. ### @usage: TS_LARGE_FILES(DESTINATION dest_dir Files...)
  175. ###
  176. ### Use large file ether from working copy or from remote storage via placeholder <File>.external
  177. ### If <File> is present locally (and not a symlink!) it will be copied to build directory.
  178. ### Otherwise macro will try to locate <File>.external, parse it and fetch the file during build phase.
  179. ###
  180. ### Then file will be copied to DESTINATION folder preserving file structure.
  181. ### Copied file becomes output of TS_PACKAGE
  182. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/TS_PACKAGE#ts-large-files
  183. macro TS_LARGE_FILES(DESTINATION="$_TS_REQUIRED_MISSING", FILES...) {
  184. LARGE_FILES($FILES)
  185. # TODO: FBP-1795
  186. _TS_LARGE_FILES($DESTINATION $FILES)
  187. }
  188. ### @usage RUN_JAVASCRIPT_AFTER_BUILD(script_path [args...] [IN inputs...] [OUTDIR outdir])
  189. ###
  190. ### Run JS script after build of TS_* module.
  191. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#run-javascript-after-build
  192. macro RUN_JAVASCRIPT_AFTER_BUILD(JS_SCRIPT, OUTDIR="", IN{input}[], ARGS...) {
  193. # --after-build-args uses `arg=val` format because args can start with --, so value will be parsed as another key.
  194. # With `arg=val` format parser knows that after `=` is a value of the --after-build-args.
  195. # For --after-build-outdir it is used to handle possible empty string in OUTDIR
  196. SET(_RUN_JAVASCRIPT_AFTER_BUILD_ARGS --after-build-js $JS_SCRIPT "--after-build-args=${join="<~~~>":ARGS}" "--after-build-outdir=$OUTDIR")
  197. SET(_RUN_JAVASCRIPT_AFTER_BUILD_INPUTS ${IN})
  198. _RUN_JAVASCRIPT_AFTER_BUILD_ADD_JS_SCRIPT_AS_INPUT($JS_SCRIPT)
  199. }
  200. macro _RENDER_RUN_JAVASCRIPT_AFTER_BUILD_INPUTS(IN{input}[]) {
  201. .CMD=${hide;input:IN}
  202. }
  203. @import "${CONF_ROOT}/conf/ts/node_modules.conf"
  204. @import "${CONF_ROOT}/conf/ts/ts_next.conf"
  205. @import "${CONF_ROOT}/conf/ts/ts_package.conf"
  206. @import "${CONF_ROOT}/conf/ts/ts_proto.conf"
  207. @import "${CONF_ROOT}/conf/ts/ts_test.conf"
  208. @import "${CONF_ROOT}/conf/ts/ts_tsc.conf"
  209. @import "${CONF_ROOT}/conf/ts/ts_vite.conf"
  210. @import "${CONF_ROOT}/conf/ts/ts_webpack.conf"