diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index d8a9e1e57ee..3bde32aa45c 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -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 diff --git a/pkg/cli/cli_impl.go b/pkg/cli/cli_impl.go index 2f591b784df..b3345ef4591 100644 --- a/pkg/cli/cli_impl.go +++ b/pkg/cli/cli_impl.go @@ -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" || @@ -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",