Skip to content

Commit 3f57db8

Browse files
committed
release notes for #3539
1 parent 91663db commit 3f57db8

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
5151
Plugins that return values from `onResolve` without resolving the path (i.e. without setting either `path` or `external: true`) will now cause a warning. This is because esbuild only uses return values from `onResolve` if it successfully resolves the path, and it's not good for invalid input to be silently ignored.
5252
53+
* Add a new Go API for running the CLI with plugins ([#3539](https://github.com/evanw/esbuild/pull/3539))
54+
55+
With esbuild's Go API, you can now call `cli.RunWithPlugins(args, plugins)` to pass an array of esbuild plugins to be used during the build process. This allows you to create a CLI that behaves similarly to esbuild's CLI but with additional Go plugins enabled.
56+
57+
This was contributed by [@edewit](https://github.com/edewit).
58+
5359
## 0.21.5
5460
5561
* Fix `Symbol.metadata` on classes without a class decorator ([#3781](https://github.com/evanw/esbuild/issues/3781))

pkg/cli/cli.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ func Run(osArgs []string) int {
3131
return runImpl(osArgs, []api.Plugin{})
3232
}
3333

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)
34+
// This is similar to "Run()" but also takes an array of plugins to be used
35+
// during the build process.
36+
func RunWithPlugins(osArgs []string, plugins []api.Plugin) int {
37+
return runImpl(osArgs, plugins)
3938
}
4039

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

pkg/cli/cli_impl.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,12 @@ func runImpl(osArgs []string, plugins []api.Plugin) int {
11431143

11441144
osArgs, analyze := filterAnalyzeFlags(osArgs)
11451145
buildOptions, transformOptions, extras, err := parseOptionsForRun(osArgs)
1146+
1147+
// Add any plugins from the caller after parsing the build options
1148+
if buildOptions != nil {
1149+
buildOptions.Plugins = append(buildOptions.Plugins, plugins...)
1150+
}
1151+
11461152
if analyze != analyzeDisabled {
11471153
addAnalyzePlugin(buildOptions, analyze, osArgs)
11481154
}
@@ -1280,7 +1286,6 @@ func runImpl(osArgs []string, plugins []api.Plugin) int {
12801286
}
12811287
}
12821288

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

0 commit comments

Comments
 (0)