Skip to content

Commit cddbfcc

Browse files
zaverdenalexv-smirnov
authored andcommitted
feat(conf): move nots from internal
1 parent dd72a9a commit cddbfcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4919
-0
lines changed

build/conf/ts/node_modules.conf

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
PNPM_ROOT=
2+
PNPM_SCRIPT=$PNPM_ROOT/node_modules/pnpm/dist/pnpm.cjs
3+
NPM_CONTRIBS_PATH=contrib/typescript
4+
# inputs list, just paths, deprecated (use _NODE_MODULES_INOUTS instead), used only for eslint/jest/hermione
5+
_NODE_MODULES_INS=
6+
# outputs list, just paths, deprecated (use _NODE_MODULES_INOUTS instead), used only for eslint/jest/hermione
7+
_NODE_MODULES_OUTS=
8+
# combined input/outputs records as list of directives ${input;hide:<path>} ${output;hide:<path>}, used in builders
9+
_NODE_MODULES_INOUTS=
10+
_YATOOL_PREBUILDER_ARG=
11+
12+
# TOUCH_UNIT is required to create module identity file.
13+
# We can "call" macro as `$_GET_NODE_MODULES_INS_OUTS(...)`. in this case we will get .CMD from it.
14+
# This is the only way to process a variable data as an array.
15+
# ${output;hide:_NODE_MODULES_OUTS} does not produce list of paths, but a single value (space-separeted paths)
16+
_NODE_MODULES_CMD=$TOUCH_UNIT \
17+
&& $NOTS_TOOL $NOTS_TOOL_BASE_ARGS create-node-modules \
18+
$_GET_NODE_MODULES_INS_OUTS(IN $_NODE_MODULES_INS OUT $_NODE_MODULES_OUTS) \
19+
${kv;hide:"pc magenta"} ${kv;hide:"p TS_NM"}
20+
21+
22+
module _NODE_MODULES_BASE: _BARE_UNIT {
23+
.CMD=_NODE_MODULES_CMD
24+
# ignore SRCS macro, use TS_FILES instead of FILES
25+
.ALIASES=SRCS=_NOOP_MACRO FILES=TS_FILES
26+
# Propagates peers to related modules
27+
.PEERDIR_POLICY=as_build_from
28+
.NODE_TYPE=Bundle
29+
30+
# TODO: remove this. YMAKE-1096 / FBP-1184
31+
_NEVERCACHE()
32+
33+
# we have several modules in the same dir (.PEERDIRSELF=NODE_MODULES in BUILD)
34+
# we need different names for module identity file
35+
# .fake tells builder to not materialize it in results
36+
SET(MODULE_SUFFIX .n_m.fake)
37+
# .NODE_TYPE=Bundle is required for peers propagation, but it also affects
38+
# how merging of pic/nopic graphs. Here we can override this merging behaviour
39+
SET(MODULE_TYPE LIBRARY)
40+
# define own tag
41+
SET(MODULE_TAG NODE_MODULES)
42+
# what modules it can PEERDIR to
43+
SET(PEERDIR_TAGS TS NPM_CONTRIBS)
44+
# do not include it into "results" of graph
45+
DISABLE(START_TARGET)
46+
47+
# we read package.json and erm-packages.json during configuration
48+
SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/pnpm-lock.yaml ${CURDIR}/package.json ${ARCADIA_ROOT}/$ERM_PACKAGES_PATH)
49+
50+
PEERDIR($NPM_CONTRIBS_PATH)
51+
# PEERDIR to the right version of nodejs and pnpm
52+
_PEERDIR_TS_RESOURCE(nodejs pnpm)
53+
54+
# run py logic
55+
_NODE_MODULES_CONFIGURE()
56+
}
57+
58+
# called in on_node_modules_configure
59+
macro _SET_NODE_MODULES_INS_OUTS(IN{input}[], OUT{output}[]) {
60+
SET(_NODE_MODULES_INS $IN)
61+
SET(_NODE_MODULES_OUTS $OUT)
62+
}
63+
64+
macro _GET_NODE_MODULES_INS_OUTS(IN{input}[], OUT{output}[]) {
65+
.CMD=${input;hide:IN} ${output;hide:OUT}
66+
}
67+
68+
69+
### @usage: NPM_CONTRIBS() # internal
70+
###
71+
### Defines special module that provides contrib tarballs from internal npm registry.
72+
###
73+
### @see [FROM_NPM_LOCKFILES()](#macro_FROM_NPM_LOCKFILES)
74+
module NPM_CONTRIBS: _BARE_UNIT {
75+
.CMD=TOUCH_UNIT
76+
.PEERDIR_POLICY=as_build_from
77+
.FINAL_TARGET=no
78+
.ALLOWED=FROM_NPM_LOCKFILES
79+
.RESTRICTED=PEERDIR
80+
.EXTS=_ # Ignore all files, so module is not affected by FROM_NPM output (.EXTS=* is inherited from _BARE_UNIT)
81+
82+
SET(MODULE_TAG NPM_CONTRIBS)
83+
84+
# .fake tells builder to not materialize it in results
85+
SET(MODULE_SUFFIX .fake)
86+
}
87+
88+
### @usage: FROM_NPM_LOCKFILES(LOCKFILES...) # internal
89+
###
90+
### Defines lockfile list for `NPM_CONTRIBS` module.
91+
###
92+
### @see [NPM_CONTRIBS()](#module_NPM_CONTRIBS)
93+
macro FROM_NPM_LOCKFILES(LOCKFILES...) {
94+
SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $LOCKFILES)
95+
# See implementation in build/plugins/nots.py
96+
_FROM_NPM_LOCKFILES($LOCKFILES)
97+
}
98+
99+
FROM_NPM_CWD=$ARCADIA_BUILD_ROOT/$NPM_CONTRIBS_PATH
100+
macro _FROM_NPM(TARBALL_URL, SKY_ID, INTEGRITY, INTEGRITY_ALGO, TARBALL_PATH) {
101+
.CMD=${cwd:FROM_NPM_CWD} $YMAKE_PYTHON ${input:"build/scripts/fetch_from_npm.py"} ${input;hide:"build/scripts/fetch_from.py"} ${input;hide:"build/scripts/sky.py"} --tarball-url $TARBALL_URL --sky-id $SKY_ID --integrity $INTEGRITY --integrity-algorithm $INTEGRITY_ALGO --copy-to ${output;noauto:TARBALL_PATH} ${requirements;hide:"network:full"} ${kv;hide:"p TS_FNPM"} ${kv;hide:"pc magenta"}
102+
# we want output to be available for other modules without affecting NPM_CONTRIBS
103+
# we need to expose it (some details in https://st.yandex-team.ru/YMAKE-34)
104+
_EXPOSE($TARBALL_PATH)
105+
}
106+
107+
macro _TS_ADD_NODE_MODULES_FOR_BUILDER() {
108+
# Provide downloaded dependencies in `/contrib/typescript/-`
109+
PEERDIR($NPM_CONTRIBS_PATH)
110+
111+
# Calculate inputs and outputs of node_modules, fill `_NODE_MODULES_INOUTS` variable
112+
_NODE_MODULES_CONFIGURE()
113+
}

build/conf/ts/ts.conf

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
NODEJS_ROOT=
2+
NODEJS_BIN=$NODEJS_ROOT/node
3+
4+
TS_TRACE=no
5+
TS_LOCAL_CLI=no
6+
# Use outdir defined in tsconfig
7+
TS_CONFIG_USE_OUTDIR=
8+
9+
NOTS_TOOL=${tool:"devtools/frontend_build_platform/nots/builder"}
10+
11+
# Arguments for the all commands of the `nots/builder`, passed before the command
12+
NOTS_TOOL_BASE_ARGS=\
13+
--arcadia-root $ARCADIA_ROOT \
14+
--arcadia-build-root $ARCADIA_BUILD_ROOT \
15+
--moddir $MODDIR \
16+
--local-cli $TS_LOCAL_CLI \
17+
--nodejs-bin $NODEJS_BIN \
18+
--pnpm-script $PNPM_SCRIPT \
19+
--contribs $NPM_CONTRIBS_PATH \
20+
--trace $TS_TRACE \
21+
--verbose $TS_LOG \
22+
$_YATOOL_PREBUILDER_ARG
23+
24+
# Arguments for builders' commands, passed after the command
25+
NOTS_TOOL_COMMON_BUILDER_ARGS=\
26+
--output-file ${output:TS_OUTPUT_FILE} \
27+
--tsconfigs $TS_CONFIG_PATH \
28+
--vcs-info "${VCS_INFO_FILE}"
29+
30+
ERM_PACKAGES_PATH=devtools/frontend_build_platform/erm/erm-packages.json
31+
32+
TS_CONFIG_PATH=tsconfig.json
33+
TS_OUTPUT_FILE=output.tar
34+
TS_EXCLUDE_DIR_GLOB=(.idea|.vscode|node_modules)/**/*
35+
TS_COMMON_OUTDIR_GLOB=(build|dist|bundle|$WEBPACK_OUTPUT_DIR|$TS_NEXT_OUTPUT_DIR|$VITE_OUTPUT_DIR)/**/*
36+
TS_GLOB_EXCLUDE_ADDITIONAL=
37+
38+
module _TS_BASE_UNIT: _BARE_UNIT {
39+
# Propagates peers to related modules
40+
.PEERDIR_POLICY=as_build_from
41+
.NODE_TYPE=Bundle
42+
# Needed for DEPENDS in tests to choose right submodule from multimodule
43+
.FINAL_TARGET=yes
44+
# use TS_FILES instead of FILES
45+
.ALIASES=FILES=TS_FILES
46+
47+
# TODO: remove this. YMAKE-1096 / FBP-1184
48+
_NEVERCACHE()
49+
50+
# .NODE_TYPE=Bundle is required for peers propagation, but it also affects
51+
# how merging of pic/nopic graphs. Here we can override this merging behaviour
52+
SET(MODULE_TYPE LIBRARY)
53+
# Include processor works only for TS tag
54+
SET(MODULE_TAG TS)
55+
# TS should peer to TS
56+
SET(PEERDIR_TAGS TS)
57+
# .fake tells builder to not materialize it in results
58+
SET(MODULE_SUFFIX .ts.fake)
59+
60+
# We read erm-packages.json during configuration, so we have to include it to configuration cache key
61+
SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/$ERM_PACKAGES_PATH)
62+
63+
# PEERDIR that reads required version of tool from package.json
64+
_PEERDIR_TS_RESOURCE(nodejs pnpm)
65+
}
66+
67+
68+
# tag:test
69+
ESLINT_CONFIG_PATH=.eslintrc.js
70+
_TS_LINT_SRCS_VALUE=
71+
### _TS_CONFIG_EPILOGUE() # internal
72+
###
73+
### This macro executes macros which should be invoked after all user specified macros in the ya.make file
74+
macro _TS_CONFIG_EPILOGUE() {
75+
### Fill $TS_GLOB_FILES with potential inputs.
76+
### It will be reduced later in _TS_CONFIGURE based on `tsconfig.json` rules.
77+
_GLOB(TS_GLOB_FILES $TS_GLOB_INCLUDE EXCLUDE $TS_GLOB_EXCLUDE)
78+
79+
_GLOB(_TS_LINT_SRCS_VALUE **/*.(ts|tsx|js|jsx) EXCLUDE $TS_EXCLUDE_DIR_GLOB $TS_COMMON_OUTDIR_GLOB $TS_GLOB_EXCLUDE_ADDITIONAL)
80+
81+
_SETUP_EXTRACT_NODE_MODULES_RECIPE(${MODDIR})
82+
}
83+
84+
# Used as inputs in TS_COMPILE through `$_AS_HIDDEN_INPUTS(IN $TS_INPUT_FILES)`
85+
TS_INPUT_FILES=
86+
87+
# List of the files, filled in _TS_CONFIG_EPILOGUE. Will be reduced in _TS_CONFIGURE macro to TS_INPUT_FILES.
88+
TS_GLOB_FILES=
89+
90+
# Hardcoded "include" list (all other files will be ignored)
91+
TS_GLOB_INCLUDE=**/*
92+
93+
# Hardcoded "exclude" list (reasonable default).
94+
TS_GLOB_EXCLUDE=$TS_CONFIG_PATH \
95+
ya.make a.yaml \
96+
$TS_EXCLUDE_DIR_GLOB \
97+
$TS_COMMON_OUTDIR_GLOB \
98+
$TS_GLOB_EXCLUDE_ADDITIONAL \
99+
package.json pnpm-lock.yaml .* \
100+
tests/**/* **/*.(test|spec).(ts|tsx|js|jsx)
101+
102+
103+
# Ugly hack for using inputs from the variable
104+
macro _AS_HIDDEN_INPUTS(IN{input}[]) {
105+
# "context=TEXT" exclude file from the "include processing"
106+
.CMD=${input;hide;context=TEXT:IN}
107+
}
108+
109+
110+
_TS_FILES_COPY_CMD=
111+
112+
### TS_FILES(Files...)
113+
###
114+
### Adds files to output as is. Similar to FILES but works for TS build modules
115+
macro TS_FILES(Files...) {
116+
_TS_FILES($Files)
117+
}
118+
119+
@import "${CONF_ROOT}/conf/ts/node_modules.conf"
120+
@import "${CONF_ROOT}/conf/ts/ts_next.conf"
121+
@import "${CONF_ROOT}/conf/ts/ts_package.conf"
122+
@import "${CONF_ROOT}/conf/ts/ts_test.conf"
123+
@import "${CONF_ROOT}/conf/ts/ts_tsc.conf"
124+
@import "${CONF_ROOT}/conf/ts/ts_vite.conf"
125+
@import "${CONF_ROOT}/conf/ts/ts_webpack.conf"

build/conf/ts/ts_next.conf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
TS_NEXT_OUTPUT_DIR=.next
2+
TS_NEXT_CONFIG_PATH=next.config.js
3+
4+
TS_NEXT_CMD=$TOUCH_UNIT \
5+
&& $_TS_FILES_COPY_CMD \
6+
&& $ADD_VCS_INFO_FILE_CMD \
7+
&& $NOTS_TOOL $NOTS_TOOL_BASE_ARGS build-next $NOTS_TOOL_COMMON_BUILDER_ARGS \
8+
--bundler-config-path ${input:TS_NEXT_CONFIG_PATH} \
9+
--output-dir ${TS_NEXT_OUTPUT_DIR} \
10+
$_NODE_MODULES_INOUTS ${hide:PEERS} \
11+
${input;hide:"package.json"} ${TS_CONFIG_FILES} $_AS_HIDDEN_INPUTS(IN $TS_INPUT_FILES) \
12+
${output;hide:"package.json"} \
13+
${kv;hide:"pc magenta"} ${kv;hide:"p TS_NXT"}
14+
15+
### @usage: TS_NEXT()
16+
###
17+
### NextJS app, built with `next build`. Requires sources to be under /src folder.
18+
### /pages and /app on the root level ar not supported.
19+
### Build results are output.tar.
20+
###
21+
### @example
22+
###
23+
### TS_NEXT()
24+
### END()
25+
###
26+
multimodule TS_NEXT {
27+
module BUILD: _TS_BASE_UNIT {
28+
.CMD=TS_NEXT_CMD
29+
.EPILOGUE=_TS_CONFIG_EPILOGUE
30+
31+
# by default multimodule overrides inherited MODULE_TAG to submodule name (BUILD in this case)
32+
# but we have to set it to TS for include processor to work
33+
SET(MODULE_TAG TS)
34+
35+
_PEERDIR_TS_RESOURCE(next)
36+
37+
DISABLE(TS_CONFIG_DEDUCE_OUT)
38+
DISABLE(TS_CONFIG_USE_OUTDIR)
39+
40+
_TS_CONFIGURE($TS_CONFIG_PATH)
41+
42+
SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/package.json ${CURDIR}/pnpm-lock.yaml ${CURDIR}/${TS_CONFIG_PATH})
43+
_TS_ADD_NODE_MODULES_FOR_BUILDER()
44+
}
45+
}
46+
47+
macro TS_NEXT_CONFIG(Path) {
48+
SET(TS_NEXT_CONFIG_PATH $Path)
49+
}
50+
51+
52+
### @usage: TS_NEXT_OUTPUT(DirName)
53+
###
54+
### Macro sets the output directory name for TS_NEXT module.
55+
###
56+
### - DirName - output directory name ("bundle" by default).
57+
macro TS_NEXT_OUTPUT(DirName) {
58+
SET(TS_NEXT_OUTPUT_DIR $DirName)
59+
}

build/conf/ts/ts_package.conf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
TS_PACK=$TOUCH_UNIT \
3+
&& $NOTS_TOOL $NOTS_TOOL_BASE_ARGS build-package $_NODE_MODULES_INOUTS \
4+
&& $COPY_CMD ${input:"package.json"} ${output:"package.json"} \
5+
&& $_TS_FILES_COPY_CMD \
6+
${kv;hide:"p TS_PKG"} ${kv;hide:"pc magenta"}
7+
8+
### @usage: TS_PACKAGE()
9+
###
10+
### The TypeScript/JavaScript library module, that does not need any compilation,
11+
### and is just a set of files and NPM dependencies. List required files in TS_FILES macro.
12+
### `package.json` is included by default.
13+
###
14+
### @example
15+
###
16+
### TS_PACKAGE()
17+
### TS_FILES(
18+
### eslint.config.json
19+
### prettierrc.json
20+
### )
21+
### END()
22+
###
23+
multimodule TS_PACKAGE {
24+
module BUILD: _TS_BASE_UNIT {
25+
.CMD=TS_PACK
26+
.ALLOWED=TS_FILES
27+
.ALIASES=FILES=TS_FILES SRCS=TS_FILES
28+
29+
# by default multimodule overrides inherited MODULE_TAG to submodule name (BUILD in this case)
30+
# but we have to set it to TS for include processor to work
31+
SET(MODULE_TAG TS)
32+
33+
SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/package.json ${CURDIR}/pnpm-lock.yaml)
34+
_TS_ADD_NODE_MODULES_FOR_BUILDER()
35+
}
36+
}

0 commit comments

Comments
 (0)