Skip to content

Commit 91663db

Browse files
authored
Provide API to create a custom esbuild CLI with plugins (#3539)
1 parent e01c0e0 commit 91663db

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pkg/cli/cli.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ import (
2828
// "esbuild" executable such as the lack of auxiliary flags (e.g. "--help" and
2929
// "--version") but it is otherwise exactly the same code.
3030
func Run(osArgs []string) int {
31-
return runImpl(osArgs)
31+
return runImpl(osArgs, []api.Plugin{})
32+
}
33+
34+
// This function invokes the esbuild CLI. It takes an array of command-line
35+
// arguments (excluding the executable argument itself) and returns an exit
36+
// code. It also takes adds some plugins that need to be added to the run
37+
func RunWithPlugins(osArgs []string, plugin []api.Plugin) int {
38+
return runImpl(osArgs, plugin)
3239
}
3340

3441
// This parses an array of strings into an options object suitable for passing

pkg/cli/cli_impl.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ func addAnalyzePlugin(buildOptions *api.BuildOptions, analyze analyzeMode, osArg
11291129
buildOptions.Metafile = true
11301130
}
11311131

1132-
func runImpl(osArgs []string) int {
1132+
func runImpl(osArgs []string, plugins []api.Plugin) int {
11331133
// Special-case running a server
11341134
for _, arg := range osArgs {
11351135
if arg == "--serve" ||
@@ -1280,6 +1280,7 @@ func runImpl(osArgs []string) int {
12801280
}
12811281
}
12821282

1283+
buildOptions.Plugins = plugins
12831284
// Handle post-build actions with a plugin so they also work in watch mode
12841285
buildOptions.Plugins = append(buildOptions.Plugins, api.Plugin{
12851286
Name: "PostBuildActions",

0 commit comments

Comments
 (0)