Skip to content

Commit

Permalink
Provide API to create a custom esbuild CLI with plugins (#3539)
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit authored Jun 30, 2024
1 parent e01c0e0 commit 91663db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ import (
// "esbuild" executable such as the lack of auxiliary flags (e.g. "--help" and
// "--version") but it is otherwise exactly the same code.
func Run(osArgs []string) int {
return runImpl(osArgs)
return runImpl(osArgs, []api.Plugin{})
}

// This function invokes the esbuild CLI. It takes an array of command-line
// arguments (excluding the executable argument itself) and returns an exit
// code. It also takes adds some plugins that need to be added to the run
func RunWithPlugins(osArgs []string, plugin []api.Plugin) int {
return runImpl(osArgs, plugin)
}

// This parses an array of strings into an options object suitable for passing
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/cli_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ func addAnalyzePlugin(buildOptions *api.BuildOptions, analyze analyzeMode, osArg
buildOptions.Metafile = true
}

func runImpl(osArgs []string) int {
func runImpl(osArgs []string, plugins []api.Plugin) int {
// Special-case running a server
for _, arg := range osArgs {
if arg == "--serve" ||
Expand Down Expand Up @@ -1280,6 +1280,7 @@ func runImpl(osArgs []string) int {
}
}

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

0 comments on commit 91663db

Please sign in to comment.