@oclif/core v4 Proposal #1040
Closed
mdonnalley
announced in
Announcements
Replies: 1 comment
-
Closing this since v4 has now been released: https://github.com/oclif/core/releases/tag/4.0.0 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We've begun thinking about what we'd like to accomplish in the next major version of
@oclif/core
. Below is a list of changes that we're considering - we'd love any and all feedback!Slimmer
ux
moduleAs described here, we're removing most of the methods in the
ux
module. We're simply unable to adequately support the feature set thatux
offers and think that most people would benefit from using dedicated libraries that are better supported.We are, however, keeping some of the functionality. The new
ux
module will contain the following:Unchanged
colorize
error
exit
action
- will be unchanged from previous version except that the spinner color will be configurable using themes.warn
Renamed
stdout
- rename ofux.log
stderr
- rename ofux.logToStderr
New
colorizeJson
- Apply color theme to arbitrary JSON.What you'll need to do
You will need to replace everything that
ux
was doing with dedicated libraries. Here are a few suggestions:Customizable Logger
In the current major version, we exclusively use debug for debug logs. In the next major, we're going to export a
Logger
interface that will allow you to provide a custom logger for@oclif/core
to use. This will be useful if you want all the@oclif/core
debug logs to go through your own logger.The default logger will continue to use
debug
under the hood. So if you choose to use the default, you can continue to use theDEBUG
environment variable to access the debug logs in the console. The only breaking change will be that the namespace for all the logs with be prefixed with a root namespace,oclif
.So if you're used to using
DEBUG=config:* my-cli do stuff
, you'll need to start doing this instead:DEBUG=oclif:config:* my-cli do stuff
Proposed Interface
Proposed Usage
You can also provide the logger to
Config
, in the event that you instantiateConfig
before callingrun
orexecute
Support for
rc
filesCurrently the configuration for oclif must live inside the
oclif
section of your CLI or plugin's package.json. This can be difficult if you have a large amount of configuration, you want to dynamically change the configuration, or want to ensure that your configuration is correctly typed.To solve this, we can use a library like cosmiconfig or lilconfig to read in a variety of rc files.
Despite being able to use an rc file,
@oclif/core
will still be dependent on your package.json to get thename
,version
, anddependencies
. We could ask that you put those value in your rc file, but duplicating that information across two files feels like something people would rather not do.If you choose to use an rc file, one thing you must consider is that there will be a slight performance hit due to needing to search for the rc file in addition to the package.json.
Small Bits
Improved
Interfaces.PJSON
The current interface is not as well organized as we would like. It would also be nice to be able to export an
OclifConfig
interface that people could use for.ts
rc filesImprove types by enabling
exactOptionalPropertyTypes
While we're improving types, we would also address #960
Apply
target
/identifier
logic to custom help classesIn case you missed it, we introduced new command discovery strategies that make bundling possible. In order to do that, the location of commands and hooks needed to be configured using a
target
(i.e. a file or directory containing the commands or hooks) and anidentifier
(i.e. the name of the export inside thetarget
).This change only works for commands and hooks so in the next major we'd apply the same logic to custom help classes so that those can be bundled as well.
Remove
default
property from configThe
default
property was used for single command CLIs before command discovery strategies were added. Instead of using thedefault
property, checkout the documentation on how to use thesingle
strategyTop level exports
We'll have top level exports for:
logger
The current way of accessing these looks like this:
With top level exports, you could access those like this:
The benefit of this is that you'll be able to import those utilities without also importing everything else that
@oclif/core
exports.As a result of this change, deep imports (e.g.
import {Command} from '@oclif/core/lib/command.js
will no longer work.Remove support forbaseFlags
We've decided to NOT move forward with this
Currently, in order for one
Command
class to inherit flags from anotherCommand
class is to use a property calledbaseFlags
(see docs).This solution assumes that you'll only ever have one layer of abstraction, which is not a safe assumption. So in order for commands to inherit flags from multiple parents you have to use the spread operator
Because of this, we're proposing that we remove
baseFlags
and require the spread operator anytime you want flags to be inherited. So the above example would change to this:The downside is that it will require an extra line of code for those who are only using a single base
Command
class but the upside is that there won't be any confusion about the difference betweenbaseFlags
andflags
and when to use each.Beta Was this translation helpful? Give feedback.
All reactions