The _options property of the browserify instance passed as parameter to the plugin is protected - as per naming convention and the TypeScript definition.
How are plugins supposed to get the options of the Browserify instance?
Many plugins rely on b._options, so that should be treated as effectively public. We could add an alias .options.
Every public property is public, regardless of what TS types or convention says. Adding an underscore never adds any privacy to anything.
It's not because it is public at the language level that it is public at the API level. If you confuse both layers, then you can't change anything without creating a breaking change.
A public property is a property that is declared public in the documentation. And _options is documented nowhere. Which is reflected by the TypeScript definitions. It is de facto not public.
A public property is a property that is declared public in the documentation. And _options is documented nowhere. Which is reflected by the TypeScript definitions. It is de facto not public.
I would say this means that it was _de jure_ private, but is _de facto_ public since that is how it is treated in the wild :)
The _ properties in browserify were probably intended as a marker of privacy, but _options, _bpack and other underscored properties are now vital to the functioning of the ecosystem. Whatever the original intent was no longer matters. Because of this precedent, we won't change it unless there is a very good reason to intentionally break all those users. It is just as safe to rely on ._options as it is to rely on .plugin().
I totally agree with you, especially this part:
The _ properties in browserify were probably intended as a marker of privacy, but _options, _bpack and other underscored properties are now vital to the functioning of the ecosystem.
I think though that this reality of things should be documented. As you say, it is vital to the ecosystem but right now, and if I'm not mistaken (maybe it is documented and I missed it), it only relies on word of mouth. When I started working on my own plugins, I had no idea of the existence of these properties or what they contained exactly.
I also think that this reality should be reflected by the TypeScript definitions, although I know this is not the responsibility of the maintainers of Browserify to update those definitions. About that, I'd like to update them (and add some sugar like a definition for Plugin and Transform), and I will, now that I'm sure that _options should definitely be considered as public.
I close the issue as I consider that the question has been fully answered. Thanks to all for your help. :)
Most helpful comment
I would say this means that it was _de jure_ private, but is _de facto_ public since that is how it is treated in the wild :)
The
_properties in browserify were probably intended as a marker of privacy, but_options,_bpackand other underscored properties are now vital to the functioning of the ecosystem. Whatever the original intent was no longer matters. Because of this precedent, we won't change it unless there is a very good reason to intentionally break all those users. It is just as safe to rely on._optionsas it is to rely on.plugin().