ts.conf 8.7 KB

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