Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide API to create a custom esbuild CLI with plugins #3539

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1127,7 +1127,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 @@ -1278,6 +1278,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