ts.conf 7.6 KB

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