Merge branch 'master' into packaged-on-void

This commit is contained in:
Anmol Sethi 2022-12-08 00:51:23 -08:00
commit 13c317037b
No known key found for this signature in database
GPG key ID: 25BC68888A99A8BA
24 changed files with 597 additions and 58 deletions

6
.prettierignore Normal file
View file

@ -0,0 +1,6 @@
d2layouts/d2dagrelayout/dagre.js
d2layouts/d2elklayout/setup.js
d2renderers/d2latex/mathjax.js
d2renderers/d2latex/polyfills.js
d2renderers/d2latex/setup.js
lib/png/generate_png.js

View file

@ -5,7 +5,7 @@ all: fmt gen lint build test
.PHONY: fmt
fmt:
prefix "$@" ./ci/fmt.sh
prefix "$@" ./ci/sub/bin/fmt.sh
.PHONY: gen
gen:
prefix "$@" ./ci/gen.sh

View file

@ -7,6 +7,7 @@
[Language docs](https://d2lang.com) | [Cheat sheet](./docs/assets/cheat_sheet.pdf) | [Comparisons](https://text-to-diagram.com)
[![ci](https://github.com/terrastruct/d2/actions/workflows/ci.yml/badge.svg)](https://github.com/terrastruct/d2/actions/workflows/ci.yml)
[![daily](https://github.com/terrastruct/d2/actions/workflows/daily.yml/badge.svg)](https://github.com/terrastruct/d2/actions/workflows/daily.yml)
[![release](https://img.shields.io/github/v/release/terrastruct/d2)](https://github.com/terrastruct/d2/releases)
[![discord](https://img.shields.io/discord/1039184639652265985?label=discord)](https://discord.gg/NF6X8K4eDq)
[![twitter](https://img.shields.io/twitter/follow/terrastruct?style=social)](https://twitter.com/terrastruct)

View file

@ -1,12 +0,0 @@
#!/bin/sh
set -eu
. "$(dirname "$0")/sub/lib.sh"
cd -- "$(dirname "$0")/.."
if is_changed README.md; then
sh_c tocsubst --skip 1 README.md
fi
if is_changed docs/INSTALL.md; then
sh_c tocsubst --skip 1 docs/INSTALL.md
fi
./ci/sub/fmt/make.sh

View file

@ -4,19 +4,23 @@ cd -- "$(dirname "$0")/../.."
. ./ci/sub/lib.sh
sh_c mkdir -p "$HW_BUILD_DIR"
sh_c rsync --recursive --perms --delete \
--human-readable --copy-links ./ci/release/template/ "$HW_BUILD_DIR/"
VERSION=$VERSION sh_c eval "'$HW_BUILD_DIR/README.md.sh'" \> "'$HW_BUILD_DIR/README.md'"
sh_c rm -f "$HW_BUILD_DIR/README.md.sh"
sh_c find "$HW_BUILD_DIR" -exec touch {} \\\;
sh_c cp ./ci/release/template/LICENSE.txt "$HW_BUILD_DIR"
sh_c cp ./ci/release/template/Makefile "$HW_BUILD_DIR"
sh_c cp -R ./ci/release/template/man "$HW_BUILD_DIR"
sh_c cp -Rf ./ci/release/template/scripts "$HW_BUILD_DIR"
sh_c VERSION="$VERSION" ./ci/release/template/README.md.sh \> "'$HW_BUILD_DIR/README.md'"
ensure_goos
ensure_goarch
sh_c mkdir -p "$HW_BUILD_DIR/bin"
sh_c CGO_ENABLED=0 go build -trimpath \
sh_c GOOS="$GOOS" GOARCH="$GOARCH" CGO_ENABLED=0 go build -trimpath \
-ldflags "'-X oss.terrastruct.com/d2/lib/version.Version=$VERSION'" \
-o "$HW_BUILD_DIR/bin/d2" .
if [ "$GOOS" = windows ]; then
sh_c mv "$HW_BUILD_DIR/bin/d2" "$HW_BUILD_DIR/bin/d2.exe"
fi
ARCHIVE=$PWD/$ARCHIVE
cd "$(dirname "$HW_BUILD_DIR")"
sh_c tar -czf "$ARCHIVE" "$(basename "$HW_BUILD_DIR")"

View file

@ -347,7 +347,7 @@ install_d2_standalone() {
install_d2_brew() {
header "installing d2 with homebrew"
sh_c brew tap terrastruct/d2
sh_c brew update
sh_c brew install d2
}
@ -390,8 +390,8 @@ install_tala_standalone() {
install_tala_brew() {
header "installing tala with homebrew"
sh_c brew tap terrastruct/d2
sh_c brew install tala
sh_c brew update
sh_c brew install terrastruct/tap/tala
}
uninstall() {
@ -502,11 +502,6 @@ fetch_gh() {
sh_c mv "$file.inprogress" "$file"
}
brew() {
# Makes brew sane.
HOMEBREW_NO_INSTALL_CLEANUP=1 HOMEBREW_NO_AUTO_UPDATE=1 command brew "$@"
}
# The main function does more than provide organization. It provides robustness in that if
# the install script was to only partial download into sh, sh will not execute it because
# main is not invoked until the very last byte.

View file

@ -2,4 +2,8 @@
#### Improvements 🧹
- The Windows release binary is now suffixed correctly with `.exe` [#388](https://github.com/terrastruct/d2/issues/388)
#### Bugfixes ⛑️
- Fixed sequence diagram span size for self-edges [#397](https://github.com/terrastruct/d2/pull/397)

View file

@ -1,5 +1,7 @@
#!/bin/sh
set -eu
cd -- "$(dirname "$0")/../../.."
. ./ci/sub/lib.sh
cat <<EOF
# d2
@ -7,6 +9,42 @@ cat <<EOF
For docs, more installation options and the source code see https://oss.terrastruct.com/d2
version: $VERSION
os: $OS
arch: $ARCH
Built with $(go version | grep -o 'go[^ ]\+').
EOF
ensure_os
if [ "$OS" = windows ]; then
cat <<EOF
We currently do not have an \`.msi\` for automatic installation on Windows so this release
is structured the same as our Unix releases.
Easiest way to use d2 on Windows is to just \`chdir\` into the bin directory of this release
and invoke d2 like \`./d2 <full-input-file-path>\`
For installation you'll have to add the \`./bin/d2.exe\` binary to your \`\$PATH\`. Or add
the \`./bin\` directory of this release to your \`\$PATH\`.
See https://www.wikihow.com/Change-the-PATH-Environment-Variable-on-Windows
Then you'll be able to call \`d2\` from the commandline in \`cmd.exe\` or \`pwsh.exe\`.
We intend to have a \`.msi\` release installer sometime soon that handles putting \`d2\` into
your \`\$PATH\` for you.
You can also use \`make install\` to install on Windows after first installing
[MSYS2](https://www.msys2.org/) which emulates a Linux shell for Windows. Its terminal
also enables d2 to show colors in its output. The manpage will also become accessible
with \`man d2\`.
See https://github.com/terrastruct/d2/blob/master/docs/INSTALL.md#windows
EOF
fi
cat <<EOF
## Install

2
ci/sub

@ -1 +1 @@
Subproject commit 79b9dadce090a95b5a50d32f9ea3927845e5cce1
Subproject commit 72046740162cff9799a94a8e1a8e4f4d7de73407

View file

@ -7,13 +7,13 @@ import (
"testing"
tassert "github.com/stretchr/testify/assert"
"oss.terrastruct.com/util-go/assert"
"oss.terrastruct.com/util-go/diff"
"oss.terrastruct.com/d2/d2compiler"
"oss.terrastruct.com/d2/d2format"
"oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2target"
"oss.terrastruct.com/util-go/assert"
"oss.terrastruct.com/util-go/diff"
)
func TestCompile(t *testing.T) {

View file

@ -261,7 +261,7 @@ func escapeID(id string) string {
// fixes \\
id = strings.ReplaceAll(id, "\\", `\\`)
// replaces \n with \\n whenever \n is not preceded by \ (does not replace \\n)
re := regexp.MustCompile(`[^\\](\n)`)
re := regexp.MustCompile(`[^\\]\n`)
id = re.ReplaceAllString(id, `\\n`)
// avoid an unescaped \r becoming a \n in the layout result
id = strings.ReplaceAll(id, "\r", `\r`)

View file

@ -12,6 +12,7 @@ import (
"math"
"github.com/dop251/goja"
"oss.terrastruct.com/util-go/xdefer"
"oss.terrastruct.com/util-go/go2"

View file

@ -5,12 +5,11 @@ import (
"sort"
"strings"
"oss.terrastruct.com/util-go/go2"
"oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/d2/d2target"
"oss.terrastruct.com/d2/lib/geo"
"oss.terrastruct.com/d2/lib/label"
"oss.terrastruct.com/util-go/go2"
)
// Layout runs the sequence diagram layout engine on objects of shape sequence_diagram

View file

@ -402,8 +402,7 @@ func (sd *sequenceDiagram) placeSpans() {
// finds the position if there are messages to this span
minMessageY := math.Inf(1)
if firstMessage, exists := sd.firstMessage[span]; exists {
// needs to check Src/Dst because of self-edges or edges to/from descendants
if span == firstMessage.Src {
if firstMessage.Src == firstMessage.Dst || span == firstMessage.Src {
minMessageY = firstMessage.Route[0].Y
} else {
minMessageY = firstMessage.Route[len(firstMessage.Route)-1].Y
@ -411,10 +410,10 @@ func (sd *sequenceDiagram) placeSpans() {
}
maxMessageY := math.Inf(-1)
if lastMessage, exists := sd.lastMessage[span]; exists {
if span == lastMessage.Src {
maxMessageY = lastMessage.Route[0].Y
} else {
if lastMessage.Src == lastMessage.Dst || span == lastMessage.Dst {
maxMessageY = lastMessage.Route[len(lastMessage.Route)-1].Y
} else {
maxMessageY = lastMessage.Route[0].Y
}
}

View file

@ -8,9 +8,9 @@ import (
"io"
"github.com/spf13/pflag"
"oss.terrastruct.com/util-go/xmain"
"oss.terrastruct.com/d2/d2graph"
"oss.terrastruct.com/util-go/xmain"
)
// Serve returns a xmain.RunFunc that will invoke the plugin p as necessary to service the

View file

@ -8,6 +8,7 @@ import (
"strconv"
"github.com/dop251/goja"
"oss.terrastruct.com/util-go/xdefer"
)

View file

@ -73,13 +73,18 @@ but that is coming soon. [#315](https://github.com/terrastruct/d2/issues/315)
If you're on macOS, you can install with `brew`.
```sh
brew tap terrastruct/d2
brew install d2
```
> The install script above does this automatically if you have `brew` installed and
> are running it on macOS.
You can also install from source with:
```d2
brew install d2 --HEAD
```
## Linux
The following distributions have packages for d2:
@ -154,7 +159,7 @@ go install oss.terrastruct.com/d2@latest
### Source Release
To install a proper release from source clone the repository and then:
To install a release from source clone the repository and then:
```sh
./ci/release/build.sh --install
@ -163,17 +168,22 @@ To install a proper release from source clone the repository and then:
```
Installing a real release will also install manpages and in the future other assets like
fonts and icons. Furthermore, when installing a non versioned commit, installing a proper
release will ensure that `d2 --version` works correctly by embedding the commit hash into
the `d2` binary.
fonts and icons. Furthermore, when installing a non versioned commit, installing a release
will ensure that `d2 --version` works correctly by embedding the commit hash into the `d2`
binary.
## Windows
d2 builds and runs on Windows:
We have prebuilt standalone releases for Windows though they're structured in the same way
as our Unix releases. So after extracting a release, you'll have to manually put the d2
binary into your `$PATH` or add the `bin` directory of the release into your `$PATH`.
as our Unix releases.
Easiest way to use d2 on Windows is to just `chdir` into the bin directory of the release
and invoke d2 like `./d2 <full-input-file-path>`
For installation, you'll have to put the `bin/d2.exe` binary into your `$PATH` or add the
`bin` directory of the release into your `$PATH`.
See https://www.wikihow.com/Change-the-PATH-Environment-Variable-on-Windows
@ -191,7 +201,7 @@ Bash](https://gitforwindows.org/#bash) (Git Bash is based on MSYS2) for an impro
terminal experience.
MSYS2 provides a unix style shell environment that is native to Windows (unlike
[Cygwin](https://www.cygwin.com/)). MSYS2 allows `install.sh` to work, enables proper
[Cygwin](https://www.cygwin.com/)). MSYS2 allows `install.sh` to work, enables automatic
installation of our standalone releases via `make install` and makes the manpage
accessible via `man d2`.

View file

@ -28,8 +28,12 @@ B: goodbye {
shape: sequence_diagram
}
A->B
`,
A->B`,
}, {
name: "sequence_diagram_span_cover",
script: `shape: sequence_diagram
b.1 -> b.1
b.1 -> b.1`,
},
}

View file

@ -0,0 +1,219 @@
{
"name": "",
"shapes": [
{
"id": "b",
"type": "",
"pos": {
"x": 24,
"y": 74
},
"width": 150,
"height": 126,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#EDF0FD",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "b",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 13,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "b.1",
"type": "rectangle",
"pos": {
"x": 93,
"y": 314
},
"width": 12,
"height": 242,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#E3E9FD",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 12,
"labelHeight": 26,
"zIndex": 2,
"level": 2
}
],
"connections": [
{
"id": "b.(1 -> 1)[0]",
"src": "b.1",
"srcArrow": "none",
"srcLabel": "",
"dst": "b.1",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 105,
"y": 330
},
{
"x": 199,
"y": 330
},
{
"x": 199,
"y": 410
},
{
"x": 105,
"y": 410
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "b.(1 -> 1)[1]",
"src": "b.1",
"srcArrow": "none",
"srcLabel": "",
"dst": "b.1",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 105,
"y": 460
},
{
"x": 199,
"y": 460
},
{
"x": 199,
"y": 540
},
{
"x": 105,
"y": 540
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(b -- )[0]",
"src": "b",
"srcArrow": "none",
"srcLabel": "",
"dst": "b-lifeline-end-668380428",
"dstArrow": "none",
"dstLabel": "",
"opacity": 1,
"strokeDash": 6,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 99,
"y": 200
},
{
"x": 99,
"y": 670
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 1
}
]
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 326 KiB

View file

@ -0,0 +1,219 @@
{
"name": "",
"shapes": [
{
"id": "b",
"type": "",
"pos": {
"x": 24,
"y": 74
},
"width": 150,
"height": 126,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#EDF0FD",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "b",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 13,
"labelHeight": 26,
"labelPosition": "INSIDE_MIDDLE_CENTER",
"zIndex": 0,
"level": 1
},
{
"id": "b.1",
"type": "rectangle",
"pos": {
"x": 93,
"y": 314
},
"width": 12,
"height": 242,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "#E3E9FD",
"stroke": "#0D32B2",
"shadow": false,
"3d": false,
"multiple": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#0A0F25",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 12,
"labelHeight": 26,
"zIndex": 2,
"level": 2
}
],
"connections": [
{
"id": "b.(1 -> 1)[0]",
"src": "b.1",
"srcArrow": "none",
"srcLabel": "",
"dst": "b.1",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 105,
"y": 330
},
{
"x": 199,
"y": 330
},
{
"x": 199,
"y": 410
},
{
"x": 105,
"y": 410
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "b.(1 -> 1)[1]",
"src": "b.1",
"srcArrow": "none",
"srcLabel": "",
"dst": "b.1",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 105,
"y": 460
},
{
"x": 199,
"y": 460
},
{
"x": 199,
"y": 540
},
{
"x": 105,
"y": 540
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 4
},
{
"id": "(b -- )[0]",
"src": "b",
"srcArrow": "none",
"srcLabel": "",
"dst": "b-lifeline-end-668380428",
"dstArrow": "none",
"dstLabel": "",
"opacity": 1,
"strokeDash": 6,
"strokeWidth": 2,
"stroke": "#0D32B2",
"label": "",
"fontSize": 16,
"fontFamily": "DEFAULT",
"language": "",
"color": "#676C7E",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 99,
"y": 200
},
{
"x": 99,
"y": 670
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 1
}
]
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 326 KiB

View file

@ -930,7 +930,7 @@ install_d2_standalone() {
install_d2_brew() {
header "installing d2 with homebrew"
sh_c brew tap terrastruct/d2
sh_c brew update
sh_c brew install d2
}
@ -973,8 +973,8 @@ install_tala_standalone() {
install_tala_brew() {
header "installing tala with homebrew"
sh_c brew tap terrastruct/d2
sh_c brew install tala
sh_c brew update
sh_c brew install terrastruct/tap/tala
}
uninstall() {
@ -1085,11 +1085,6 @@ fetch_gh() {
sh_c mv "$file.inprogress" "$file"
}
brew() {
# Makes brew sane.
HOMEBREW_NO_INSTALL_CLEANUP=1 HOMEBREW_NO_AUTO_UPDATE=1 command brew "$@"
}
# The main function does more than provide organization. It provides robustness in that if
# the install script was to only partial download into sh, sh will not execute it because
# main is not invoked until the very last byte.

View file

@ -17,8 +17,8 @@ import (
"time"
"golang.org/x/xerrors"
"oss.terrastruct.com/util-go/xdefer"
"oss.terrastruct.com/util-go/xdefer"
"oss.terrastruct.com/util-go/xmain"
)