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

Version 3 #767

Merged
merged 57 commits into from
Oct 4, 2023
Merged

Version 3 #767

merged 57 commits into from
Oct 4, 2023

Conversation

mdonnalley
Copy link
Contributor

@mdonnalley mdonnalley commented Aug 21, 2023

BREAKING CHANGES ❗

Dropping node 14 and node 16 support

The end-of-life date for Node.js 14 was April 30, 2023.

The end-of-life date for Node.js 16 was September 11, 2023. This date is earlier than previously published. Node.js’s blog explains why they chose this earlier end-of-life date.

Bin Scripts for ESM/CJS Interoperability

In order to support ESM and CommonJS plugin interoperability you will need to update your bin scripts to match these:

CJS Template

ESM Template

You will also need to update any references to the bin scripts to include the .js extension.

If you'd like to migrate your plugin to ESM, please read our guide here

Dropped ts-node as a dependency

We removed ts-node as a dependency to reduce the package size. By doing this, it means that linked plugin must have ts-node as a devDependency in order for auto-transpilation to work.

Config.plugins

Config.plugins is now a Map where the keys are the plugin names and the values are the loaded Plugin instances. Previously it was an array of loaded Plugin instances.

By using a Map we can now do more efficient lookups during command execution. Config.getPluginsList was added in case you still would like a flat array of Plugin instances.

Readonly properties on Config

Various properties on Config are now readonly

  • name
  • version
  • channel
  • pjson
  • root
  • arch
  • bin
  • cacheDir
  • configDir
  • dataDir
  • dirname
  • errLog
  • home
  • platform
  • shell
  • userAgent
  • windows
  • debug
  • npmRegistry
  • userPJSON
  • plugins
  • binPath
  • binAliases
  • nsisCustomization
  • valid
  • flexibleTaxonomy
  • commands

Private methods on Plugin

The _manifest and warn methods on Plugin are now private

global['cli-ux'] -> global.ux

The global cli-ux object has been renamed to ux to be consistent with the module's name

handle

The exported handle function for handling errors in bin scripts is now asynchronous

noCacheDefault flag property replaces isWritingManifest

Version 2 allowed you to optionally return non-sensitive input if the default or defaultHelp flag/arg properties were called during manifest creation. This is helpful if you don't want sensitive data to be put into the oclif.manifest.json and then released to npm. To do this you had to handle the isWritingManifest parameter passed in to the default and defaultHelp callbacks.

export const mySensitiveFlag = Flags.string({
  default: async (context, isWritingManifest) => {
    if (isWritingManifest) {
      return undefined
    }

    return 'sensitive info'
  },
})

Version 3 removes the isWritingManifest parameter in favor of a flag and arg property, noCacheDefault. Setting it to true will automatically keep it from being cached in the manifest.

export const mySensitiveFlag = Flags.string({
  noCacheDefault: true,
  default: async (context) => {
    return 'sensitive info'
  },
})

Removed Unnecessary Exports

The following exports have been removed:

  • toCached
  • tsPath

Features 🎉

Performance Improvements

  • Cache command permutations for flexible taxonomy in the oclif.manifest.json
  • Cache additional command properties (isESM, relativePath) in the oclif.manifest.json
  • Improved accuracy in the DEBUG=perf output.
  • Remove ts-node from dependencies to reduce the package size.

charAliases Flag Property

You can now define single character flag aliases using the charAliases property.

Flags.option

There's a new flag type that infers the flag's type from the provided options.

In v2 you would have needed to do something like this,

type Options = 'foo' | 'bar'
export default class MyCommand extends Command {
  static flags = {
    name: Flags.custom<Options>({
      options: ['foo', 'bar'],
    })(),
  }
}

Now in v3 you can do this,

export default class MyCommand extends Command {
  static flags = {
    name: Flags.option({
      options: ['foo', 'bar'] as const,
    })(),
  }
}

Set spinner styles

You can now configure the style of the spinner when using ux.action.start. See spinners for all the different options.

ux.action.start('starting spinner', 'spinning', {style: 'arc'})
await ux.wait(2500)
ux.action.status = 'still going'
await ux.wait(2500)
ux.action.stop()

mdonnalley and others added 10 commits August 21, 2023 14:59
* fix: set moduleResolution to Node16

* fix: use file urls

* chore: add types

* feat: support linking CJS plugins into ESM plugins

* chore: integration tests for module interoperability

* test: add CJS/ESM interoperability tests

* fix: e2e tests

* test: isolate cache, config, and data dir for e2e tests

* test: test bug

* test: make less noisy

* test: esm/cjs hooks

* chore: parallelize e2e tests

* chore: typo

* test: parallelize e2e tests

* test: no more hanging tests

* chore: un-parallelize esm-cjs tests

* chore: add DEBUG to esm-cjs interop tests

* chore: add DEBUG to esm-cjs interop tests

* chore: try enabling debug again

* test: fix node 20 tests

* chore: update DEBUG env var

* chore: debug tests

* chore: debug tests

* test: more debugging

* test: more debugging

* test: more debugging

* test: more debugging

* test: more debugging

* test: more debugging

* test: more debugging

* test: use path.join

* test: stop using replace-in-file

* chore: more test debugging

* fix: use path.join when registering ts-node

* test: run in parallel

* test: run tests serially

* fix: dont remove undefined values from tsconfig

* fix: further isolate ts-configs

* feat: throw error when loading ESM paths from linked plugins

* fix: default esm to true

* test: compilation errors

* feat: better developer experience

* fix: add getPluginsList

* chore(release): 2.11.9 [skip ci]

* fix: add getPluginsList to Config interface

* chore(release): 2.11.10 [skip ci]

---------

Co-authored-by: svc-cli-bot <[email protected]>
* fix: set moduleResolution to Node16

* fix: use file urls

* chore: add types

* feat: support linking CJS plugins into ESM plugins

* chore: integration tests for module interoperability

* test: add CJS/ESM interoperability tests

* fix: e2e tests

* test: isolate cache, config, and data dir for e2e tests

* test: test bug

* test: make less noisy

* test: esm/cjs hooks

* chore: parallelize e2e tests

* chore: typo

* test: parallelize e2e tests

* test: no more hanging tests

* chore: un-parallelize esm-cjs tests

* chore: add DEBUG to esm-cjs interop tests

* chore: add DEBUG to esm-cjs interop tests

* chore: try enabling debug again

* test: fix node 20 tests

* chore: update DEBUG env var

* chore: debug tests

* chore: debug tests

* test: more debugging

* test: more debugging

* test: more debugging

* test: more debugging

* test: more debugging

* test: more debugging

* test: more debugging

* test: use path.join

* test: stop using replace-in-file

* chore: more test debugging

* fix: use path.join when registering ts-node

* test: run in parallel

* test: run tests serially

* fix: dont remove undefined values from tsconfig

* fix: further isolate ts-configs

* feat: throw error when loading ESM paths from linked plugins

* fix: default esm to true

* test: compilation errors

* feat: better developer experience

* fix: add getPluginsList

* chore(release): 2.11.9 [skip ci]

* fix: add getPluginsList to Config interface

* chore(release): 2.11.10 [skip ci]

* feat: use exports

* fix: ux class

* fix: add exports for help and perf

* chore: tests

* feat: use Map for config.plugins

* feat: add noCacheDefault

* feat: add exports for Args and Flags

* chore: fix tests

* feat: put permutations into manifest

* fix: add return to execute

* fix: add version to PJSON interface

* feat: drop node 14 and 16 support

* fix: use CLIError for integer flag errors

* fix: skip findRoot for linked plugins

* chore: remove console.log

* fix: dont load core plugin if already loaded as linked or user plugin

* fix: ux export

* chore: making things readonly

* feat: add config export

* test: make tests passing again

* feat: rename cli-ux global to ux global

* chore: go back to node 16 support

* chore: migration guide

* chore: remove source-map register

* test: remove resolution

* chore: update migration guide

* fix: revert link findRoot optimization

* fix: remove unneeded exports

* feat: add PluginLoader

* chore: update migration guide

* chore: merge conflict

* chore: more merge conflicts

* test: recursive mkdir

---------

Co-authored-by: svc-cli-bot <[email protected]>
mdonnalley and others added 18 commits August 31, 2023 14:05
* feat: revert exports changes

* fix: run e2e tests even if linting error

* fix: revert cli-ux dir renaming
* feat: skip ts-node register for ESM plugins

* chore: update debug message
* feat: add charAliases

* feat: add Flags.option

* fix: undo default options

* fix: allow bin/dev.js to auto-transpile ESM plugin

* chore: update execute examples

* fix: update tsnode skip logic

* chore: test debugging

* fix: ts-node skip logic

* fix: ts-node skip logic

* feat: cache relativePath and isESM in manifest

* fix: calculate id permutations at runtime to support backwards compatability

* perf: avoid findLegacyRoot for linked plugins

* chore: remove env var

* fix: improve perf metrics

* perf: improve perf debug output

* perf: more debug improvements

* test: compilation errors

* fix: make relativePath OS safe

* test: use sf esm branch

* perf: give full hook path

* chore: test debugging

* chore: test debugging

* chore: test debugging

* test: set shell for e2e tests

* fix: flag types respect defaults

* feat: node protocol

* test: move windows sf integration tests into separate job

* test: update assertion on plugins install test

* test: use correct file path

* test: use -Force

* test: use bash shell

* test: clean up

* test: remove shell option

* test: oclif/config, core v1, and core v2 interop tests

* chore: drop node 16

* test: remove lts/-1

* chore: code review

* chore: add pre core migration guide

* refactor: break up ModuleLoader

* chore: remove unicorn/consistent-function-scoping

* chore: remove unicorn/no-missing-imports

* chore: remove @typescript-eslint/no-empty-function

* chore: remove ban-ts-comment and ban-ts-ignore

* chore: add sort-import rule

* fix: throw error if non-multiple flag provided more than once

* test: mutliples of non-multiple flag test

* test: ut for charAliases (#791)

* test: duplicate aliases tests

* test: extend timeout

* test: split windows esm-cjs tests

* test: parallelize linux interop tests too

* test: typo

* test: use right executor

* test: use right executor for clean up

* chore: update eslint libs (#792)

* chore: update eslint libs

* chore: clean up

* chore: tests and linting

* test: windows paths

* fix: exports

* test: update run import

* chore: replaceAll

* fix: error exit codes

* fix: use es2021

* feat: use ES2022

* fix: use ES2021 again

* test: incorporate flags and args in esm-cjs tests

* test: use correct expected values

---------

Co-authored-by: Shane McLaughlin <[email protected]>
mdonnalley and others added 18 commits September 28, 2023 13:18
* fix: use ES2022

* test: use --json for config unset

* feat: stop using getters and setters for flags

* chore: clean up

* feat: expose json flag

* feat: remove pass through getter and setter

* fix: correct order of flags in toCached

* chore: clean up

* fix: flag merge order

* chore: documentation

* test: use oclif/test v3

* feat: set spinner style on windows too

* fix: handle cmd with baseFlags but no flags

* fix: some circular deps

* fix: circular deps in help

* fix: ts-node and config circular deps

* fix: toCached circular dep in help

* chore: organize utils

* test: enforce no circular deps

* chore: remove Flags.json

* chore: add prettier config

* test: add nyc

* test: improve test coverage

* test: windows unit tests

* chore: revert change to automerge.yml

* chore: code review

* perf: parallelize cacheCommand
* chore: update prettier config

* chore: prettier and lint-staged

* chore: reformat everything

* chore: deal with reformat aftermath

* chore: update configs and deps

* perf: move ansi-escapes require to top level

* chore: automerge.yml

* chore: unpin eslint-plugin-prettier

* chore: remove prettier plugin

* chore: update lint-staged config
* feat: collect perf results from outside oclif

* chore: pr feedback

* refactor: naming for non-core perf
@mdonnalley mdonnalley merged commit f6e7286 into main Oct 4, 2023
35 checks passed
@mdonnalley mdonnalley deleted the prerelease/v3 branch October 4, 2023 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants