ts.conf 7.5 KB

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