Skip to content

Commit ca4a554

Browse files
committed
refactor: revamp go build
1 parent ae6a5b0 commit ca4a554

14 files changed

Lines changed: 123 additions & 91 deletions

File tree

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
version: 2
22
updates:
33
- package-ecosystem: "github-actions"
4+
cooldown:
5+
default-days: 7
46
directory: "/"
57
schedule:
68
interval: "weekly"
@@ -24,6 +26,8 @@ updates:
2426
- "*"
2527

2628
- package-ecosystem: "bun"
29+
cooldown:
30+
default-days: 7
2731
directory: "/"
2832
schedule:
2933
interval: "weekly"
@@ -47,6 +51,8 @@ updates:
4751
- "*"
4852

4953
- package-ecosystem: "gomod"
54+
cooldown:
55+
default-days: 7
5056
directory: "/"
5157
schedule:
5258
interval: "weekly"

.github/workflows/build.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ concurrency:
99
group: ${{ github.workflow }}-${{ github.ref }}
1010
cancel-in-progress: true
1111

12+
permissions: {}
13+
1214
jobs:
1315
test:
1416
uses: LouisBrunner/.github/.github/workflows/lint-bun.yml@main
17+
permissions: {}
1518
with:
1619
run: |
1720
bun run all
@@ -22,11 +25,11 @@ jobs:
2225
needs: [test]
2326
permissions:
2427
contents: read
25-
pages: write
26-
id-token: write
2728
steps:
2829
- name: Checkout the repository
2930
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
31+
with:
32+
persist-credentials: false
3033

3134
- name: Build
3235
uses: LouisBrunner/.github/.github/actions/build-bun-go@main
@@ -36,7 +39,7 @@ jobs:
3639
bun build:examples
3740
3841
- name: Upload examples build
39-
uses: actions/upload-artifact@v7
42+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
4043
with:
4144
name: Examples
4245
path: examples
@@ -46,9 +49,11 @@ jobs:
4649
needs: [build]
4750
if: github.ref == 'refs/heads/main'
4851
runs-on: ubuntu-24.04
52+
permissions:
53+
contents: write
4954
steps:
5055
- name: Checkout
51-
uses: actions/checkout@v7
56+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
5257
with:
5358
persist-credentials: false
5459
- name: Clean gitignore
@@ -58,12 +63,12 @@ jobs:
5863
sed -i '/^\/examples/d' .gitignore
5964
6065
- name: Download examples build
61-
uses: actions/download-artifact@v8
66+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
6267
with:
6368
name: Examples
6469
path: examples
6570
- name: Deploy
66-
uses: peaceiris/actions-gh-pages@v4
71+
uses: peaceiris/actions-gh-pages@84c30a85c19949d7eee79c4ff27748b70285e453 # v4.1.0
6772
with:
6873
github_token: ${{ secrets.GITHUB_TOKEN }}
6974
enable_jekyll: true

.github/workflows/lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ concurrency:
99
group: ${{ github.workflow }}-${{ github.ref }}
1010
cancel-in-progress: true
1111

12+
permissions: {}
13+
1214
jobs:
1315
configs:
1416
uses: LouisBrunner/.github/.github/workflows/lint-configs.yml@main
17+
permissions: {}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This project is a Drag'n'Drop backend compatible with [DnD Core](https://github.com/react-dnd/react-dnd).
44

5-
It enables your application to use different DnD backends depending on the situation. Different packages are available depending on your front-end framework:
5+
It enables your application to use different DnD backends depending on the situation. Different packages are available depending on your frontend framework:
66

77
- React: [`react-dnd-multi-backend`](packages/react-dnd-multi-backend)
88
- Angular: [`angular-skyhook`](https://github.com/cormacrelf/angular-skyhook) (see [documentation](https://cormacrelf.github.io/angular-skyhook/angular-skyhook-multi-backend/) for more information)

__mocks__/mocks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import type {Mock} from 'bun:test'
22
import {jest} from 'bun:test'
33

4+
// biome-ignore lint/suspicious/noExplicitAny: function generic constraint requires `any`
45
type MockFn<T extends (...args: any[]) => any> = Mock<OmitThisParameter<T>>
56

67
export type Mocked<T> = {
8+
// biome-ignore lint/suspicious/noExplicitAny: same as above
79
[P in keyof T]: T[P] extends (...args: any[]) => any ? MockFn<T[P]> : T[P]
810
}
911

cmd/bundler/main.go

Lines changed: 57 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package main
22

33
import (
4+
"context"
45
"encoding/json"
56
"flag"
67
"log"
8+
"maps"
79
"os"
10+
"os/signal"
811
"path/filepath"
12+
"slices"
13+
"syscall"
914

15+
"github.com/LouisBrunner/esbuild-plugins/pkg/devserver"
1016
"github.com/evanw/esbuild/pkg/api"
1117
)
1218

@@ -36,105 +42,73 @@ func externalsForPackage(dir string) []string {
3642
log.Fatalf("reading %s: %v", path, err)
3743
}
3844
var pkg packageJSON
39-
if err := json.Unmarshal(data, &pkg); err != nil {
45+
err = json.Unmarshal(data, &pkg)
46+
if err != nil {
4047
log.Fatalf("parsing %s: %v", path, err)
4148
}
42-
seen := map[string]bool{}
43-
var externals []string
49+
seen := map[string]struct{}{}
4450
for name := range pkg.Dependencies {
45-
if !seen[name] {
46-
seen[name] = true
47-
externals = append(externals, name)
51+
if _, found := seen[name]; !found {
52+
seen[name] = struct{}{}
4853
}
4954
}
5055
for name := range pkg.PeerDependencies {
51-
if !seen[name] {
52-
seen[name] = true
53-
externals = append(externals, name)
56+
if _, found := seen[name]; !found {
57+
seen[name] = struct{}{}
5458
}
5559
}
56-
return externals
60+
return slices.Collect(maps.Keys(seen))
5761
}
5862

59-
func buildPackage(dir string) {
63+
func buildPackage(dir string) error {
6064
log.Printf("> Building %s\n", dir)
61-
result := api.Build(api.BuildOptions{
62-
EntryPoints: []string{dir + "/src/index.ts"},
63-
Outfile: dir + "/dist/index.js",
64-
Format: api.FormatESModule,
65-
Bundle: true,
66-
MinifyWhitespace: true,
67-
MinifyIdentifiers: true,
68-
MinifySyntax: true,
69-
External: externalsForPackage(dir),
70-
Target: api.ES2020,
71-
Write: true,
65+
return devserver.Build(devserver.Options{
66+
Build: api.BuildOptions{
67+
EntryPoints: []string{dir + "/src/index.ts"},
68+
Outfile: dir + "/dist/index.js",
69+
Format: api.FormatESModule,
70+
Bundle: true,
71+
External: externalsForPackage(dir),
72+
Target: api.ES2020,
73+
},
7274
})
73-
if len(result.Errors) > 0 {
74-
for _, e := range result.Errors {
75-
log.Printf("Error: %s (%s:%d)", e.Text, e.Location.File, e.Location.Line)
76-
}
77-
log.Fatalf("Build failed for %s", dir)
78-
}
7975
}
8076

81-
func buildExamples(outdir string) {
77+
func buildExamples(outdir string) error {
8278
log.Printf("> Building examples -> %s\n", outdir)
8379
entries := make([]api.EntryPoint, 0, len(exampleEntryPoints))
8480
for out, in := range exampleEntryPoints {
8581
entries = append(entries, api.EntryPoint{InputPath: in, OutputPath: out})
8682
}
87-
result := api.Build(api.BuildOptions{
88-
EntryPointsAdvanced: entries,
89-
Outdir: outdir,
90-
Bundle: true,
91-
MinifyWhitespace: true,
92-
MinifyIdentifiers: true,
93-
MinifySyntax: true,
94-
Write: true,
95-
Tsconfig: "./tsconfig.json",
83+
return devserver.Build(devserver.Options{
84+
Build: api.BuildOptions{
85+
EntryPointsAdvanced: entries,
86+
Bundle: true,
87+
Tsconfig: "./tsconfig.json",
88+
},
89+
PublicDir: outdir,
9690
})
97-
if len(result.Errors) > 0 {
98-
for _, e := range result.Errors {
99-
log.Printf("Error: %s (%s:%d)", e.Text, e.Location.File, e.Location.Line)
100-
}
101-
log.Fatalf("Examples build failed")
102-
}
10391
}
10492

105-
func devExamples(port int) {
106-
log.Printf("> Starting dev server on port %d\n", port)
93+
func devExamples(port int) error {
10794
entries := make([]api.EntryPoint, 0, len(exampleEntryPoints))
10895
for out, in := range exampleEntryPoints {
10996
entries = append(entries, api.EntryPoint{InputPath: in, OutputPath: out})
11097
}
111-
ctx, err := api.Context(api.BuildOptions{
112-
EntryPointsAdvanced: entries,
113-
Outdir: "examples/",
114-
Bundle: true,
115-
Sourcemap: api.SourceMapInline,
116-
Write: true,
117-
})
118-
if err != nil {
119-
log.Fatalf("Context: %v", err)
120-
}
12198

122-
if err := ctx.Watch(api.WatchOptions{}); err != nil {
123-
log.Fatalf("Watch: %v", err)
124-
}
125-
126-
_, serveErr := ctx.Serve(api.ServeOptions{
127-
Host: "localhost",
128-
Port: port,
129-
Servedir: "examples/",
99+
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
100+
defer cancel()
101+
102+
return devserver.Start(ctx, devserver.Options{
103+
Build: api.BuildOptions{
104+
EntryPointsAdvanced: entries,
105+
Bundle: true,
106+
Tsconfig: "./tsconfig.json",
107+
},
108+
OpenBrowser: true,
109+
PublicDir: "examples/",
110+
Port: port,
130111
})
131-
if serveErr != nil {
132-
log.Fatalf("Serve: %v", serveErr)
133-
}
134-
135-
log.Printf("Listening on http://localhost:%d", port)
136-
<-make(chan struct{})
137-
ctx.Dispose()
138112
}
139113

140114
func main() {
@@ -146,16 +120,24 @@ func main() {
146120
case "build":
147121
log.Println("Building packages")
148122
for _, pkg := range packages {
149-
buildPackage(pkg)
123+
err := buildPackage(pkg)
124+
if err != nil {
125+
log.Fatalf("Build %s: %v", pkg, err)
126+
}
150127
}
151128
log.Println("Done")
152129

153130
case "examples":
154-
buildExamples("examples/")
155-
log.Println("Done")
131+
err := buildExamples("examples/")
132+
if err != nil {
133+
log.Fatalf("Examples: %v", err)
134+
}
156135

157136
case "dev":
158-
devExamples(*port)
137+
err := devExamples(*port)
138+
if err != nil {
139+
log.Fatalf("Dev: %v", err)
140+
}
159141

160142
default:
161143
log.Fatalf("Unknown mode: %s (use build, examples, or dev)", *mode)

cmd/publish/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func writePackageJSON(dir string, pkg packageJSON) {
5555
if err != nil {
5656
log.Fatalf("❌ failed to marshal package.json: %v", err)
5757
}
58-
err = os.WriteFile(filepath.Join(dir, "package.json"), append(data, '\n'), 0o644)
58+
err = os.WriteFile(filepath.Join(dir, "package.json"), append(data, '\n'), 0o644) // #nosec G306
5959
if err != nil {
6060
log.Fatalf("❌ failed to write %s/package.json: %v", dir, err)
6161
}

go.mod

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
module github.com/LouisBrunner/dnd-multi-backend/build
22

3-
go 1.25.5
3+
go 1.26.2
44

5-
require github.com/evanw/esbuild v0.28.1
5+
tool honnef.co/go/tools/cmd/staticcheck
66

7-
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
7+
require (
8+
github.com/LouisBrunner/esbuild-plugins v0.0.0-20260704011403-6bc0fcee664e
9+
github.com/evanw/esbuild v0.28.1
10+
)
11+
12+
require (
13+
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect
14+
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 // indirect
15+
golang.org/x/mod v0.31.0 // indirect
16+
golang.org/x/sync v0.19.0 // indirect
17+
golang.org/x/sys v0.46.0 // indirect
18+
golang.org/x/tools v0.40.1-0.20260108161641-ca281cf95054 // indirect
19+
honnef.co/go/tools v0.7.0 // indirect
20+
)

go.sum

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1+
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
2+
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
3+
github.com/LouisBrunner/esbuild-plugins v0.0.0-20260704011403-6bc0fcee664e h1:clAHVv4HJFi3lApiIuiySvUVaOfxXuRZtb2y0zA1yW0=
4+
github.com/LouisBrunner/esbuild-plugins v0.0.0-20260704011403-6bc0fcee664e/go.mod h1:6wJ9FSSTJuZYv9brXcy9kT7PHLhC8FZH25zuIuyoH0A=
15
github.com/evanw/esbuild v0.28.1 h1:ds+yuRyUaZGx++GR56CrCeuXh8PVhVM4xq8v7PNELFc=
26
github.com/evanw/esbuild v0.28.1/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48=
3-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
7+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
8+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
9+
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=
10+
golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
11+
golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI=
12+
golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg=
13+
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
14+
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
415
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16+
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
17+
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
18+
golang.org/x/tools v0.40.1-0.20260108161641-ca281cf95054 h1:CHVDrNHx9ZoOrNN9kKWYIbT5Rj+WF2rlwPkhbQQ5V4U=
19+
golang.org/x/tools v0.40.1-0.20260108161641-ca281cf95054/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc=
20+
golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM=
21+
golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
22+
honnef.co/go/tools v0.7.0 h1:w6WUp1VbkqPEgLz4rkBzH/CSU6HkoqNLp6GstyTx3lU=
23+
honnef.co/go/tools v0.7.0/go.mod h1:pm29oPxeP3P82ISxZDgIYeOaf9ta6Pi0EWvCFoLG2vc=

packages/dnd-multi-backend/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
This project is a Drag'n'Drop backend compatible with [DnD Core](https://github.com/react-dnd/react-dnd/tree/master/packages/dnd-core).
66
It enables your application to use different DnD backends depending on the situation.
77
This package is completely frontend-agnostic, you can refer to [this page](https://github.com/LouisBrunner/dnd-multi-backend) for frontend-specific packages.
8-
This means if your front-end is not yet supported, you'll have to roll out your own.
8+
This means if your frontend is not yet supported, you'll have to roll out your own.
99

1010
See the [migration section](#migrating) for instructions when switching from `5.0.x` or `6.x.x`.
1111

0 commit comments

Comments
 (0)