aboutsummaryrefslogtreecommitdiffstats
path: root/build/conf/ts/node_modules.conf
blob: 5567455cb0de16aacf34e5156b3558cd041908e3 (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
PNPM_ROOT=
PNPM_SCRIPT=$PNPM_ROOT/node_modules/pnpm/dist/pnpm.cjs
NPM_CONTRIBS_PATH=contrib/typescript
NODE_MODULES_BUNDLE_AS_OUTPUT=
_NODE_MODULES_INS=
_NODE_MODULES_OUTS=

# TOUCH_UNIT is required to create module identity file.
# we can "call" macro as `$_NODE_MODULES(...)`. in this case we will get .CMD from it.
# this is the only way to process a variable data as an array.
# ${output;hide:_NODE_MODULES_OUTS} does not produce list of paths, but a single value (space-separeted paths)
_NODE_MODULES_CMD=$TOUCH_UNIT && $_NODE_MODULES(IN $_NODE_MODULES_INS OUT $_NODE_MODULES_OUTS)

module _NODE_MODULES_BASE: _BARE_UNIT {
    .CMD=_NODE_MODULES_CMD
    # ignore SRCS macro, use TS_FILES instead of FILES
    .ALIASES=SRCS=_NOOP_MACRO FILES=TS_FILES
    # Propagates peers to related modules
    .PEERDIR_POLICY=as_build_from
    .NODE_TYPE=Bundle

    # we have several modules in the same dir (.PEERDIRSELF=NODE_MODULES in BUILD)
    # we need different names for module identity file
    # .fake tells builder to not materialize it in results
    SET(MODULE_SUFFIX .n_m.fake)
    # .NODE_TYPE=Bundle is required for peers propagation, but it also affects
    # how merging of pic/nopic graphs. Here we can override this merging behaviour
    SET(MODULE_TYPE LIBRARY)
    # define own tag
    SET(MODULE_TAG NODE_MODULES)
    # what modules it can PEERDIR to
    SET(PEERDIR_TAGS TS NPM_CONTRIBS)
    # do not include it into "results" of graph
    DISABLE(START_TARGET)

    # we read package.json and erm-packages.json during configuration
    SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${CURDIR}/package.json ${ARCADIA_ROOT}/$ERM_PACKAGES_PATH)

    PEERDIR($NPM_CONTRIBS_PATH)
    # PEERDIR to the right version of nodejs and pnpm
    _PEERDIR_TS_RESOURCE(nodejs pnpm)

    # run py logic
    _NODE_MODULES_CONFIGURE()
}

# called in on_node_modules_configure
macro _SET_NODE_MODULES_INS_OUTS(IN{input}[], OUT{output}[]) {
    SET(_NODE_MODULES_INS $IN)
    SET(_NODE_MODULES_OUTS $OUT)
}

macro _NODE_MODULES(IN{input}[], OUT{output}[]) {
    .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"}
}


### @usage: NPM_CONTRIBS() # internal
###
### Defines special module that provides contrib tarballs from internal npm registry.
###
### @see [FROM_NPM_LOCKFILES()](#macro_FROM_NPM_LOCKFILES)
module NPM_CONTRIBS: _BARE_UNIT {
    .CMD=TOUCH_UNIT
    .PEERDIR_POLICY=as_build_from
    .FINAL_TARGET=no
    .ALLOWED=FROM_NPM_LOCKFILES
    .RESTRICTED=PEERDIR
    .EXTS=_ # Ignore all files, so module is not affected by FROM_NPM output (.EXTS=* is inherited from _BARE_UNIT)

    SET(MODULE_TAG NPM_CONTRIBS)

    # .fake tells builder to not materialize it in results
    SET(MODULE_SUFFIX .fake)
}

### @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)
}

FROM_NPM_CWD=$ARCADIA_BUILD_ROOT/$NPM_CONTRIBS_PATH
macro _FROM_NPM(NAME, VERSION, SKY_ID, INTEGRITY, INTEGRITY_ALGO, TARBALL_PATH) {
    .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"} --name $NAME --version $VERSION --sky-id $SKY_ID --integrity $INTEGRITY --integrity-algorithm $INTEGRITY_ALGO --copy-to ${output;noauto:TARBALL_PATH} ${requirements;hide:"network:full"} ${kv;hide:"p NPM"} ${kv;hide:"pc magenta"}
    # we want output to be available for other modules without affecting NPM_CONTRIBS
    # we need to expose it (some details in https://st.yandex-team.ru/YMAKE-34)
    _EXPOSE($TARBALL_PATH)
}

macro NODE_MODULES() {
    MESSAGE(Remove NODE_MODULES())
}