aboutsummaryrefslogtreecommitdiffstats
path: root/build/conf/ts.conf
blob: a6fa837ce0238d3bd3c90969e292a9aca544f4a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
NODEJS_ROOT=$NODEJS_RESOURCE_GLOBAL
NODEJS_BIN=$NODEJS_ROOT/node
PNPM_ROOT=$PNPM_RESOURCE_GLOBAL
PNPM_SCRIPT=$PNPM_ROOT/node_modules/pnpm/dist/pnpm.cjs

NOTS_TOOL=${tool:"devtools/frontend_build_platform/nots/builder"}
NOTS_TOOL_CURDIR=$CURDIR
NOTS_TOOL_BINDIR=$BINDIR
NOTS_TOOL_BASE_ARGS=--build-root $ARCADIA_BUILD_ROOT --bindir $NOTS_TOOL_BINDIR --curdir $NOTS_TOOL_CURDIR --nodejs-bin $NODEJS_BIN
NOTS_TOOL_NODE_MODULES_BUNDLE=$BINDIR/$NODE_MODULES_BUNDLE
# Base path for pluggable modules.
NOTS_PLUGINS_PATH=devtools/frontend_build_platform/nots/toolchain_plugins

#
# npm contribs
#

NPM_CONTRIBS_PATH=build/platform/yandex_specific/ts/contribs

### @usage: NPM_CONTRIBS() # internal
###
### Defines special module that provides contrib tarballs from internal npm registry.
### Should be used only with `NODE_MODULES` macro.
###
### @see [FROM_NPM_LOCKFILES()](#macro_FROM_NPM_LOCKFILES)
### @see [NODE_MODULES()](#macro_NODE_MODULES)
module NPM_CONTRIBS: _BASE_UNIT {
    .CMD=TOUCH_UNIT
    .PEERDIR_POLICY=as_build_from
    .FINAL_TARGET=no
    .ALLOWED=FROM_NPM_LOCKFILES
    .RESTRICTED=PEERDIR

    SET(MODULE_TAG NPM_CONTRIBS)

    MODULE_SUFFIX=.fake

    _BARE_MODULE()
}

### @usage: FROM_NPM_LOCKFILES(LOCKFILES...) # internal
###
### Defines lockfile list for `NPM_CONTRIBS` module.
###
### @see [NPM_CONTRIBS()](#module_NPM_CONTRIBS)
macro FROM_NPM_LOCKFILES(LOCKFILES...) {
    SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $LOCKFILES)
    # See implementation in build/plugins/nots.py
    _FROM_NPM_LOCKFILES($LOCKFILES)
}

### @usage: FROM_NPM(NAME VERSION SKY_ID INTEGRITY INTEGRITY_ALGO TARBALL_PATH)
macro FROM_NPM(NAME, VERSION, SKY_ID, INTEGRITY, INTEGRITY_ALGO, TARBALL_PATH) {
    .CMD=${cwd:BINDIR} $YMAKE_PYTHON ${input:"build/scripts/fetch_from_npm.py"} ${input;hide:"build/scripts/fetch_from.py"} ${input;hide:"build/scripts/sky.py"} --name $NAME --version $VERSION --sky-id $SKY_ID --integrity $INTEGRITY --integrity-algorithm $INTEGRITY_ALGO --copy-to ${output:TARBALL_PATH} ${requirements;hide:"network:full"} ${kv;hide:"p NPM"} ${kv;hide:"pc magenta"}
}

#
# node_modules
#

NODE_MODULES_BUNDLE=node_modules.tar
NODE_MODULES_BUNDLE_AS_OUTPUT=

### @usage: NODE_MODULES()
###
### Materializes `node_modules.tar` bundle according to the module's lockfile.
###
### @see [NPM_CONTRIBS()](#module_NPM_CONTRIBS)
macro NODE_MODULES() {
    # See implementation in build/plugins/nots.py
}

macro _NODE_MODULES(IN{input}[], OUT{output}[]) {
    PEERDIR($NPM_CONTRIBS_PATH)
    SET(NODE_MODULES_BUNDLE_AS_OUTPUT \${output;hide:"workspace_node_modules.tar"})

    .CMD=${cwd:BINDIR} $NOTS_TOOL create-node-modules $NOTS_TOOL_BASE_ARGS --pnpm-script $PNPM_SCRIPT --contribs $NPM_CONTRIBS_PATH ${input;hide:IN} ${output;hide:OUT} ${kv;hide:"p NOMO"} ${kv;hide:"pc magenta"}
}

#
# TS library
#

module _TS_BASE_UNIT: _BASE_UNIT {
    .PEERDIR_POLICY=as_build_from
    .FINAL_TARGET=yes

    DEFAULT(_IGNORE_DUPSRC yes)

    SET(MODULE_TYPE LIBRARY)
    SET(MODULE_TAG TS)
    SET(PEERDIR_TAGS TS NPM_CONTRIBS)

    PEERDIR(build/platform/nodejs)
    PEERDIR(build/external_resources/pnpm)
    PEERDIR(build/external_resources/typescript)
    PEERDIR(build/external_resources/eslint)

    MODULE_SUFFIX=.fake

    _BARE_MODULE()
}

TSC_ROOT=$TYPESCRIPT_RESOURCE_GLOBAL/node_modules
TS_CONFIG_PATH=tsconfig.json
TS_COMPILE_TYPINGS=
TS_COMPILE_PLUGINS=
TS_COMPILE=$TOUCH_UNIT \
    && ${cwd:BINDIR} $NOTS_TOOL compile-ts $NOTS_TOOL_BASE_ARGS --tsc-resource $TSC_ROOT \
    --ts-config ${input:TS_CONFIG_PATH} --node-modules-bundle $NOTS_TOOL_NODE_MODULES_BUNDLE \
    --typings $TS_COMPILE_TYPINGS --plugins $TS_COMPILE_PLUGINS $NODE_MODULES_BUNDLE_AS_OUTPUT \
    ${hide:PEERS} ${input;hide:"./package.json"} ${TS_CONFIG_FILES} \
    ${output;hide:"package.json"} ${output;hide:TS_COMPILE_OUTPUT} ${kv;hide:"p TSC"} ${kv;hide:"pc magenta"}

module _TS_BASE_LIBRARY : _TS_BASE_UNIT {
    .CMD=TS_COMPILE

    SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/${TS_CONFIG_PATH} ${CURDIR}/package.json)
    SET(TS_CONFIG_DEDUCE_OUT yes)

    _TS_CONFIGURE($TS_CONFIG_PATH)
}

### @usage: TS_LIBRARY([name])
###
### The TypeScript/JavaScript library module, compiles TypeScript sources to JavaScript.
### Build results are JavaScript files, typings and source mappings (depending on local tsconfig.json settings).
###
### @see [NODE_MODULES()](#macro_NODE_MODULES)
### @example
###
###     TS_LIBRARY()
###         SRCS(src/index.ts)
###         NODE_MODULES()
###     END()
###
module TS_LIBRARY : _TS_BASE_LIBRARY {
    .EPILOGUE=_TS_LIBRARY_EPILOGUE
}

#
# TS bundle
#

WEBPACK_ROOT=$WEBPACK_RESOURCE_GLOBAL/node_modules
WEBPACK_CONFIG_PATH=webpack.config.js
TS_BUNDLE_WEBPACK=$TOUCH_UNIT \
    && ${cwd:BINDIR} $NOTS_TOOL bundle-webpack $NOTS_TOOL_BASE_ARGS --webpack-resource $WEBPACK_ROOT \
    --webpack-config ${input:WEBPACK_CONFIG_PATH} --ts-config ${input:TS_CONFIG_PATH} \
    --node-modules-bundle $NOTS_TOOL_NODE_MODULES_BUNDLE $NODE_MODULES_BUNDLE_AS_OUTPUT ${hide:PEERS} \
    ${input;hide:"./package.json"} ${TS_CONFIG_FILES} ${output;hide:"bundle.tar"} \
    ${output;hide:"package.json"} ${kv;hide:"p TSWP"} ${kv;hide:"pc magenta"}

### @usage: TS_BUNDLE([name])
###
### The Webpack bundle, bundles JavaScript code.
### Build results are bundle.tar, typings and source mappings (depending on local tsconfig.json settings).
###
### @see [NODE_MODULES()](#macro_NODE_MODULES)
### @example
###
###     TS_BUNDLE()
###         SRCS(src/index.ts)
###         NODE_MODULES()
###     END()
###
module TS_BUNDLE : _TS_BASE_UNIT {
    .CMD=TS_BUNDLE_WEBPACK

    PEERDIR(build/external_resources/webpack)
    SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/${TS_CONFIG_PATH} ${CURDIR}/package.json)
    SET(TS_CONFIG_DEDUCE_OUT no)
    SRCS(${CURDIR}/${WEBPACK_CONFIG_PATH})

    _TS_CONFIGURE($TS_CONFIG_PATH)
}

#
# TS NextJS
#
_NEXTJS_SRC_FILES=

macro _NEXTJS_EPILOG() {
    _GLOB(_NEXTJS_SRC_FILES ${CURDIR}/src/pages/**/* ${CURDIR}/pages/**/* ${CURDIR}/src/app/**/* ${CURDIR}/app/**/* ${CURDIR}/public/**/*)
    SRCS($_NEXTJS_SRC_FILES)
}

NEXTJS_ROOT=$NEXTJS_RESOURCE_GLOBAL/node_modules
NEXTJS_CONFIG_PATH=next.config.js
TS_NEXTJS_BUILD=$TOUCH_UNIT \
    && ${cwd:BINDIR} $NOTS_TOOL build-nextjs $NOTS_TOOL_BASE_ARGS \
    --nextjs-resource $NEXTJS_ROOT \
    --nextjs-config ${input:NEXTJS_CONFIG_PATH} --ts-config ${input:TS_CONFIG_PATH} \
    --node-modules-bundle $NOTS_TOOL_NODE_MODULES_BUNDLE $NODE_MODULES_BUNDLE_AS_OUTPUT ${hide:PEERS} \
    ${input;hide:"./package.json"} ${TS_CONFIG_FILES} ${output;hide:"bundle.tar"} \
    ${output;hide:"package.json"} ${kv;hide:"p TSNEXT"} ${kv;hide:"pc magenta"}

### @usage: TS_NEXTJS()
###
### NextJS app, built with `next build`. Requires sources to be under /src folder.
### /pages and /app on the root level ar not supported.
### Build results are bundle.tar.
###
### @see [NODE_MODULES()](#macro_NODE_MODULES)
### @example
###
###     TS_NEXTJS()
###         NODE_MODULES()
###     END()
###
module TS_NEXTJS : _TS_BASE_UNIT {
    .CMD=TS_NEXTJS_BUILD
    .EPILOGUE=_NEXTJS_EPILOG

    SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/${TS_CONFIG_PATH} ${CURDIR}/package.json)
    SET(TS_CONFIG_DEDUCE_OUT no)

    _TS_CONFIGURE($TS_CONFIG_PATH)
}


#
# TS library testing
#

JEST_CONFIG_PATH=jest.config.js
JEST_TEST_EXTENSION=test.(ts|tsx|js|jsx)
JEST_EXTRA_SRCS_MASK=/**/__mocks__/*

HERMIONE_CONFIG_PATH=.hermione.conf.js
HERMIONE_TEST_EXTENSION=hermione.(ts|js)
HERMIONE_EXTRA_SRCS_MASK=

TS_TEST_RUNNER=jest
TS_TEST_CONFIG_PATH_VAR=
TS_TEST_EXTENSION=
TS_TEST_EXTRA_SRCS_MASK=

# tag:test
_TS_TEST_SRCS_VALUE=
_TS_TEST_EXTRA_SRCS_VALUE=
### @usage: TS_TEST_SRCS(DIRS...)
###
### Macro to define directories where the test source files should be located.
###
### - DIRS... - directories.
macro TS_TEST_SRCS(DIRS...) {
    _GLOB(_TS_TEST_SRCS_VALUE ${suf=/**/*.$TS_TEST_EXTENSION:DIRS})
    SRCS($_TS_TEST_SRCS_VALUE)

    _GLOB(_TS_TEST_EXTRA_SRCS_VALUE ${suf=$TS_TEST_EXTRA_SRCS_MASK:DIRS})
    SRCS($_TS_TEST_EXTRA_SRCS_VALUE)
}

# tag:test
_TS_TEST_DATA_VALUE=
_TS_TEST_DATA_DIRS_RENAME_VALUE=
### @usage: TS_TEST_DATA([RENAME] GLOBS...)
###
### Macro to add tests data (i.e. snapshots) used in testing to a bindir from curdir.
### Creates symbolic links to directories of files found by the specified globs.
###
### Parameters:
### - RENAME - adds ability to rename paths for tests data from curdir to bindir.
###            For example if your tested module located on "module" path and tests data in "module/tests_data".
###            Then you can be able to rename "tests_data" folder to something else - `RENAME tests_data:example`.
###            As a result in your bindir will be created folder - "module/example" which is a symbolic link on "module/tests_data" in curdir.
###            It is possible to specify multiple renaming rules in the following format "dir1:dir2;dir3/foo:dir4/bar", where "dir1" and "dir3" folders in curdir.
### - GLOBS... - globs to tests data files, symbolic links will be created to their folders. For example - "tests_data/**/*".
macro TS_TEST_DATA(RENAME="", GLOBS...) {
    _GLOB(_TS_TEST_DATA_VALUE $GLOBS)
    SET(_TS_TEST_DATA_DIRS_RENAME_VALUE $RENAME)
}

# tag:test
ESLINT_CONFIG_NAME=.eslintrc.js
_TS_LINT_SRCS_VALUE=
### _TS_LIBRARY_EPILOGUE() # internal
###
### This macro executes macros which should be invoked after all user specified macros in the ya.make file
macro _TS_LIBRARY_EPILOGUE() {
    _GLOB(_TS_LINT_SRCS_VALUE ${CURDIR}/**/*.(ts|tsx) EXCLUDE **/node_modules/**/*.(ts|tsx))
}

macro _TS_TEST_EPILOGUE() {
    _TS_TEST_CONFIGURE()
}

# workspace_node_modules.tar has to be in outputs to become available for test_tool.
# we cannot redeclare node_modules.tar (it's in $NOTS_TOOL_NODE_MODULES_BUNDLE) as output,
# because this path is in outputs of create-node-modules command, and we can't have same path
# as output of several graph nodes.
# we use $MOVE_FILE as the most cheap way to get another path for a file.
TS_TEST_CMD=$TOUCH_UNIT \
    && ${cwd:BINDIR} $MOVE_FILE $NOTS_TOOL_NODE_MODULES_BUNDLE ${output:"workspace_node_modules.tar"} \
    ${kv;hide:"p TSTEST"} ${kv;hide:"pc magenta"}

# tag:test
### @usage: TS_TEST()
###
### @see [TS_TEST_SRCS()](#macro_TS_TEST_SRCS)
### @see [TS_TEST_DATA()](#macro_TS_TEST_DATA)
module TS_TEST: _TS_BASE_UNIT {
    .CMD=TS_TEST_CMD
    .EPILOGUE=_TS_TEST_EPILOGUE

    # Disable `SRCS` macro in "parent" module (sources will be added by `TS_TEST_SRCS`).
    .ALIASES=SRCS=_NOOP_MACRO

    # Use "parent's" CURDIR/BINDIR since TS_TEST borrows sources from parent module.
    SET(TEST_FOR_BINDIR $ARCADIA_BUILD_ROOT/$TS_TEST_FOR_PATH)
    SET(TEST_FOR_CURDIR $ARCADIA_ROOT/$TS_TEST_FOR_PATH)
    SET(NOTS_TOOL_CURDIR $TEST_FOR_CURDIR)
    SET(NOTS_TOOL_NODE_MODULES_BUNDLE $TEST_FOR_BINDIR/$NODE_MODULES_BUNDLE)

    PEERDIR(build/external_resources/$TS_TEST_RUNNER)

    when ($TS_TEST_RUNNER == "jest") {
        TS_TEST_CONFIG_PATH_VAR=JEST_CONFIG_PATH
        TS_TEST_EXTENSION=$JEST_TEST_EXTENSION
        TS_TEST_EXTRA_SRCS_MASK=$JEST_EXTRA_SRCS_MASK
    }
    when ($TS_TEST_RUNNER == "hermione") {
        TS_TEST_CONFIG_PATH_VAR=HERMIONE_CONFIG_PATH
        TS_TEST_EXTENSION=$HERMIONE_TEST_EXTENSION
        TS_TEST_EXTRA_SRCS_MASK=$HERMIONE_EXTRA_SRCS_MASK
    }

    DEPENDS(devtools/frontend_build_platform/nots/recipes/extract_node_modules)
    USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_node_modules/recipe $TS_TEST_FOR_PATH workspace_node_modules.tar)
}