d2cli: Accept abspaths again
Fixes https://github.com/Homebrew/homebrew-core/pull/124831/files#r1125738853
This commit is contained in:
parent
d028cda9f0
commit
7cd821feb7
7 changed files with 46 additions and 10 deletions
|
|
@ -3,3 +3,5 @@
|
||||||
#### Improvements 🧹
|
#### Improvements 🧹
|
||||||
|
|
||||||
#### Bugfixes ⛑️
|
#### Bugfixes ⛑️
|
||||||
|
|
||||||
|
- Accept absolute paths again on the CLI. [#979](https://github.com/terrastruct/d2/pull/979)
|
||||||
|
|
|
||||||
|
|
@ -154,14 +154,14 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if inputPath != "-" {
|
if inputPath != "-" {
|
||||||
inputPath = filepath.Join(ms.PWD, inputPath)
|
inputPath = ms.AbsPath(inputPath)
|
||||||
d, err := os.Stat(inputPath)
|
d, err := os.Stat(inputPath)
|
||||||
if err == nil && d.IsDir() {
|
if err == nil && d.IsDir() {
|
||||||
inputPath = filepath.Join(inputPath, "index.d2")
|
inputPath = filepath.Join(inputPath, "index.d2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if outputPath != "-" {
|
if outputPath != "-" {
|
||||||
outputPath = filepath.Join(ms.PWD, outputPath)
|
outputPath = ms.AbsPath(outputPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
match := d2themescatalog.Find(*themeFlag)
|
match := d2themescatalog.Find(*themeFlag)
|
||||||
|
|
@ -308,7 +308,7 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketc
|
||||||
|
|
||||||
if filepath.Ext(outputPath) == ".pdf" {
|
if filepath.Ext(outputPath) == ".pdf" {
|
||||||
dur := time.Since(start)
|
dur := time.Since(start)
|
||||||
ms.Log.Success.Printf("successfully compiled %s to %s in %s", inputPath, outputPath, dur)
|
ms.Log.Success.Printf("successfully compiled %s to %s in %s", ms.HumanPath(inputPath), ms.HumanPath(outputPath), dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
return svg, true, nil
|
return svg, true, nil
|
||||||
|
|
@ -383,7 +383,7 @@ func render(ctx context.Context, ms *xmain.State, compileDur time.Duration, plug
|
||||||
return svg, err
|
return svg, err
|
||||||
}
|
}
|
||||||
dur := compileDur + time.Since(start)
|
dur := compileDur + time.Since(start)
|
||||||
ms.Log.Success.Printf("successfully compiled %s to %s in %s", inputPath, boardOutputPath, dur)
|
ms.Log.Success.Printf("successfully compiled %s to %s in %s", ms.HumanPath(inputPath), ms.HumanPath(boardOutputPath), dur)
|
||||||
return svg, nil
|
return svg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ type watcherOpts struct {
|
||||||
port string
|
port string
|
||||||
inputPath string
|
inputPath string
|
||||||
outputPath string
|
outputPath string
|
||||||
|
pwd string
|
||||||
bundle bool
|
bundle bool
|
||||||
forceAppendix bool
|
forceAppendix bool
|
||||||
pw png.Playwright
|
pw png.Playwright
|
||||||
|
|
@ -216,7 +217,7 @@ func (w *watcher) watchLoop(ctx context.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.ms.Log.Info.Printf("compiling %v...", w.inputPath)
|
w.ms.Log.Info.Printf("compiling %v...", w.ms.HumanPath(w.inputPath))
|
||||||
w.requestCompile()
|
w.requestCompile()
|
||||||
|
|
||||||
eatBurstTimer := time.NewTimer(0)
|
eatBurstTimer := time.NewTimer(0)
|
||||||
|
|
@ -270,7 +271,7 @@ func (w *watcher) watchLoop(ctx context.Context) error {
|
||||||
// misleading error.
|
// misleading error.
|
||||||
eatBurstTimer.Reset(time.Millisecond * 16)
|
eatBurstTimer.Reset(time.Millisecond * 16)
|
||||||
case <-eatBurstTimer.C:
|
case <-eatBurstTimer.C:
|
||||||
w.ms.Log.Info.Printf("detected change in %v: recompiling...", w.inputPath)
|
w.ms.Log.Info.Printf("detected change in %v: recompiling...", w.ms.HumanPath(w.inputPath))
|
||||||
w.requestCompile()
|
w.requestCompile()
|
||||||
case err, ok := <-w.fw.Errors:
|
case err, ok := <-w.fw.Errors:
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -300,7 +301,7 @@ func (w *watcher) ensureAddWatch(ctx context.Context) (time.Time, error) {
|
||||||
return mt, nil
|
return mt, nil
|
||||||
}
|
}
|
||||||
if interval >= time.Second {
|
if interval >= time.Second {
|
||||||
w.ms.Log.Error.Printf("failed to watch inputPath %q: %v (retrying in %v)", w.inputPath, err, interval)
|
w.ms.Log.Error.Printf("failed to watch inputPath %q: %v (retrying in %v)", w.ms.HumanPath(w.inputPath), err, interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
tc.Reset(interval)
|
tc.Reset(interval)
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,16 @@ layers: {
|
||||||
assert.Testdata(t, ".svg", stdout.Bytes())
|
assert.Testdata(t, ".svg", stdout.Bytes())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "abspath",
|
||||||
|
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
|
||||||
|
writeFile(t, dir, "hello-world.d2", `x -> y`)
|
||||||
|
err := runTestMain(t, ctx, dir, env, filepath.Join(dir, "hello-world.d2"))
|
||||||
|
assert.Success(t, err)
|
||||||
|
svg := readFile(t, dir, "hello-world.svg")
|
||||||
|
assert.Testdata(t, ".svg", svg)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
||||||
23
e2etests-cli/testdata/TestCLI_E2E/abspath.exp.svg
vendored
Normal file
23
e2etests-cli/testdata/TestCLI_E2E/abspath.exp.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 328 KiB |
2
go.mod
generated
2
go.mod
generated
|
|
@ -23,7 +23,7 @@ require (
|
||||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
|
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
|
||||||
gonum.org/v1/plot v0.12.0
|
gonum.org/v1/plot v0.12.0
|
||||||
nhooyr.io/websocket v1.8.7
|
nhooyr.io/websocket v1.8.7
|
||||||
oss.terrastruct.com/util-go v0.0.0-20230303204624-090ad7923dcb
|
oss.terrastruct.com/util-go v0.0.0-20230305220024-ae08a694f221
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|
|
||||||
4
go.sum
generated
4
go.sum
generated
|
|
@ -283,6 +283,6 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
|
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
|
||||||
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
|
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
|
||||||
oss.terrastruct.com/util-go v0.0.0-20230303204624-090ad7923dcb h1:Zgb7Wf7mTpXmIiYv0bIJ8IULcdJVIxiRihnUvDP9YMQ=
|
oss.terrastruct.com/util-go v0.0.0-20230305220024-ae08a694f221 h1:LbO79j1CUB/mkmPSzLrA/EL4TRK0rjfAq+CejQapHyw=
|
||||||
oss.terrastruct.com/util-go v0.0.0-20230303204624-090ad7923dcb/go.mod h1:eMWv0sOtD9T2RUl90DLWfuShZCYp4NrsqNpI8eqO6U4=
|
oss.terrastruct.com/util-go v0.0.0-20230305220024-ae08a694f221/go.mod h1:eMWv0sOtD9T2RUl90DLWfuShZCYp4NrsqNpI8eqO6U4=
|
||||||
rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4=
|
rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4=
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue