Skip to content

Commit db3ccdf

Browse files
author
Elad Ben-Israel
authored
feat: pass data types (structs) by-value instead of by-ref (#376)
Data types ("structs") are defined through a TypeScript interface that only contains properties and doesn't begin with an `I`. This change also adds a requirement that all properties (shallow) are marked `readonly`. This allows passing around structs by-value safely because any consuming code would not expect to be able to write to the object. Python already passes structs by value, especially in the context of when a struct is used as keyword arguments. This use case will also exist in Ruby. This is also the general perception around data that's passed around in most programming languages. To enforce this, the jsii compiler will now fail if a struct includes properties that are not marked `readonly`. Both the Java and .NET generators have been modified to generate builders which allow users to construct structs by serializing them as JSON hashes instead of passed down by reference. Existing compliance tests in all languages have been fixed. This change fixes aws/aws-cdk#965 and fixes #375 by erasing any `null`s or `undefined` values from passed in objects, so they do not appear to have been defined at all. Added a compliance test called **erase-unset-data-values** to verify. BREAKING CHANGE: all properties in interfaces which represent data types must be marked as `readonly`. Otherwise, jsii compilation will fail.
1 parent b5d49de commit db3ccdf

File tree

150 files changed

+8787
-8849
lines changed

Some content is hidden

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

150 files changed

+8787
-8849
lines changed

foreach.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
# --------------------------------------------------------------------------------------------------
3+
#
4+
# this wonderful tool allows you to execute a command for all modules in this repo
5+
# in topological order, but has the incredible property of being stateful.
6+
# this means that if a command fails, you can fix the issue and resume from where
7+
# you left off.
8+
#
9+
# to start a session, run:
10+
# foreach.sh COMMAND
11+
#
12+
# this will execute "COMMAND" for each module in the repo (cwd will be the directory of the module).
13+
# if a task fails, it will stop, and then to resume, simply run `foreach.sh` again (with or without the same command).
14+
#
15+
# to reset the session (either when all tasks finished or if you wish to run a different session), run:
16+
# rm -f ~/.foreach.*
17+
#
18+
# this will effectively delete the state files.
19+
#
20+
# --------------------------------------------------------------------------------------------------
21+
set -euo pipefail
22+
statefile="${HOME}/.foreach.state"
23+
commandfile="${HOME}/.foreach.command"
24+
command_arg="${@:-}"
25+
26+
function heading {
27+
printf "\e[38;5;81m$@\e[0m\n"
28+
}
29+
30+
function error {
31+
printf "\e[91;5;81m$@\e[0m\n"
32+
}
33+
34+
function success {
35+
printf "\e[32;5;81m$@\e[0m\n"
36+
}
37+
38+
if [ -f "${statefile}" ] && [ -f "${commandfile}" ]; then
39+
command="$(cat ${commandfile})"
40+
if [ ! -z "${command_arg}" ] && [ "${command}" != "${command_arg}" ]; then
41+
error "error: there is still an active session for: \"${command}\". to reset:"
42+
error " rm -f ~/.foreach.*"
43+
exit 1
44+
fi
45+
fi
46+
47+
if [ ! -f "${statefile}" ] && [ ! -f "${commandfile}" ]; then
48+
if [ ! -z "${command_arg}" ]; then
49+
command="${command_arg}"
50+
success "starting new session"
51+
npx lerna ls --all --toposort -p > ${statefile}
52+
echo "${command}" > ${commandfile}
53+
else
54+
error "no active session, use \"$(basename $0) COMMAND\" to start a new session"
55+
exit 0
56+
fi
57+
fi
58+
59+
next="$(head -n1 ${statefile})"
60+
if [ -z "${next}" ]; then
61+
success "done (queue is empty). to reset:"
62+
success " rm -f ~/.foreach.*"
63+
exit 0
64+
fi
65+
66+
remaining=$(cat ${statefile} | wc -l | xargs -n1)
67+
68+
heading "---------------------------------------------------------------------------------"
69+
heading "${next}: ${command} (${remaining} remaining)"
70+
71+
(
72+
cd ${next}
73+
${command} || {
74+
error "error: last command failed. fix problem and resume by executing:"
75+
error " $0"
76+
exit 1
77+
}
78+
)
79+
80+
tail -n +2 "${statefile}" > "${statefile}.tmp"
81+
cp "${statefile}.tmp" "${statefile}"
82+
exec $0

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lerna": "2.11.0",
2+
"lerna": "3.13.1",
33
"packages": [
44
"packages/*"
55
],

0 commit comments

Comments
 (0)