Skip to content

Commit

Permalink
fix: use ES2022 (#793)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mdonnalley authored Sep 28, 2023
1 parent 6702a53 commit 2a3b084
Show file tree
Hide file tree
Showing 40 changed files with 2,326 additions and 673 deletions.
11 changes: 11 additions & 0 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"check-coverage": true,
"lines": 80,
"statements": 70,
"functions": 70,
"branches": 60,
"reporter": ["lcov", "text"],
"extension": [".ts"],
"include": ["**/*.ts"],
"exclude": ["**/*.d.ts", "test/**"]
}
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@oclif/prettier-config"
45 changes: 45 additions & 0 deletions guides/PRE_CORE_MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Migrating to `@oclif/core` from the deprecated oclif libraries (`@oclif/config`,

- [Migrating to @oclif/core from deprecated libraries](#migrating-to-oclifcore-from-deprecated-libraries)
- [Update Imports](#update-imports)
- [Update Command Args](#update-command-args)
- [Update your bin scripts](#update-your-bin-scripts)
- [Add `main` to your package.json](#add-main-to-your-packagejson)
- [Restore `-h`, `-v`, and `version`](#restore--h--v-and-version)
Expand All @@ -30,6 +31,50 @@ With this import:
import {Command, Flags, Topic, Help} from '@oclif/core';
```

## Update Command Args

We updated the `Command.args` to more closely resemble flags

**Before**

```typescript
import { Command } from '@oclif/core'

export default MyCommand extends Command {
static args = [{name: arg1, description: 'an argument', required: true}]

public async run(): Promise<void> {
const {args} = await this.parse(MyCommand) // args is useless {[name: string]: any}
}
}
```

**After**

```typescript
import { Command, Args } from '@oclif/core'

export default MyCommand extends Command {
static args = {
arg1: Args.string({description: 'an argument', required: true})
}

public async run(): Promise<void> {
const {args} = await this.parse(MyCommand) // args is { arg1: string }
}
}
```

These are the available Args:
- string
- integer
- boolean
- url
- file
- directory
- custom


## Update your bin scripts

`@oclif/core` now supports separate bin scripts for production and development.
Expand Down
31 changes: 28 additions & 3 deletions guides/V3_MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ Migrating to @oclif/core@V3
- [BREAKING CHANGES ❗](#breaking-changes-)
- [Dropping node 14 and node 16 support](#dropping-node-14-and-node-16-support)
- [Bin Scripts for ESM/CJS Interoperability](#bin-scripts-for-esmcjs-interoperability)
- [Dropped `ts-node` as a dependency](#dropped-ts-node-as-a-dependency)
- [`Config.plugins`](#configplugins)
- [Readonly properties on `Config`](#readonly-properties-on-config)
- [Private methods on `Plugin`](#private-methods-on-plugin)
- [`global['cli-ux']` -\> `global.ux`](#globalcli-ux---globalux)
- [`handle`](#handle)
- [`noCacheDefault` flag property replaces `isWritingManifest`](#nocachedefault-flag-property-replaces-iswritingmanifest)
- [Removed `toCached` export](#removed-tocached-export)
- [Features 🎉](#features-)
- [Cache Flexible taxonomy Command Permutations](#cache-flexible-taxonomy-command-permutations)
- [Performance Improvements](#performance-improvements)
- [charAliases Flag Property](#charaliases-flag-property)
- [Flags.option](#flagsoption)
- [Set spinner styles](#set-spinner-styles)


## BREAKING CHANGES ❗
Expand All @@ -36,6 +39,10 @@ In order to support ESM and CommonJS plugin interoperability you will need to up

If you'd like to migrate your plugin to ESM, please read our guide [here](https://oclif.io/docs/esm)

### 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.

Expand Down Expand Up @@ -110,12 +117,18 @@ export const mySensitiveFlag = Flags.string({
});
```

### Removed `toCached` export

We removed the `toCached` export since there's no need for consumers of `@oclif/core` to use this function.

## Features 🎉

### Cache Flexible taxonomy Command Permutations
### Performance Improvements

The command permutations for flexible taxonomy are now cached in the oclif.manifest.json allowing for quicker startup times.
- 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

Expand Down Expand Up @@ -149,3 +162,15 @@ export default class MyCommand extends Command {
}
}
```

### Set spinner styles

You can now configure the style of the spinner when using `ux.action.start`. See [spinners](https://github.com/oclif/core/blob/main/src/cli-ux/action/spinners.ts) for all the different options.

```typescript
ux.action.start('starting spinner', 'spinning', {style: 'arc'})
await ux.wait(2500)
ux.action.status = 'still going'
await ux.wait(2500)
ux.action.stop()
```
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"@commitlint/config-conventional": "^12.1.4",
"@oclif/plugin-help": "^5.2.8",
"@oclif/plugin-plugins": "^3.3.0",
"@oclif/test": "^2.4.7",
"@oclif/prettier-config": "^0.1.1",
"@oclif/test": "^3.0.0-beta.1",
"@types/ansi-styles": "^3.2.1",
"@types/benchmark": "^2.1.2",
"@types/chai": "^4.3.4",
Expand Down Expand Up @@ -65,8 +66,10 @@
"fancy-test": "^3.0.0-beta.2",
"globby": "^11.1.0",
"husky": "6",
"madge": "^6.1.0",
"mocha": "^10.2.0",
"nock": "^13.3.0",
"nyc": "^15.1.0",
"shx": "^0.3.4",
"sinon": "^11.1.2",
"tsd": "^0.29.0",
Expand Down Expand Up @@ -105,13 +108,14 @@
"commitlint": "commitlint",
"compile": "tsc",
"lint": "eslint . --ext .ts",
"posttest": "yarn lint",
"posttest": "yarn lint && yarn test:circular-deps",
"prepack": "yarn run build",
"pretest": "yarn build --noEmit && tsc -p test --noEmit --skipLibCheck",
"pretest": "yarn build && tsc -p test --noEmit --skipLibCheck",
"test:circular-deps": "madge lib/ -c",
"test:e2e": "mocha --forbid-only \"test/**/*.e2e.ts\" --parallel --timeout 1200000",
"test:esm-cjs": "cross-env DEBUG=e2e:* ts-node test/integration/esm-cjs.ts",
"test:perf": "ts-node test/perf/parser.perf.ts",
"test": "mocha --forbid-only \"test/**/*.test.ts\""
"test": "nyc mocha --forbid-only \"test/**/*.test.ts\""
},
"types": "lib/index.d.ts"
}
2 changes: 1 addition & 1 deletion src/cli-ux/action/spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class SpinnerAction extends ActionBase {
}

private getFrames(opts?: Options) {
if (opts?.style) return spinners[process.platform === 'win32' ? 'line' : opts.style].frames
if (opts?.style) return spinners[opts.style].frames

return spinners[process.platform === 'win32' ? 'line' : 'dots2'].frames
}
Expand Down
5 changes: 3 additions & 2 deletions src/cli-ux/flush.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Errors, stdout} from '..'
import {error} from '../errors'
import {stdout} from './stream'

function timeout(p: Promise<any>, ms: number) {
function wait(ms: number, unref = false) {
Expand All @@ -8,7 +9,7 @@ function timeout(p: Promise<any>, ms: number) {
})
}

return Promise.race([p, wait(ms, true).then(() => Errors.error('timed out'))])
return Promise.race([p, wait(ms, true).then(() => error('timed out'))])
}

async function _flush() {
Expand Down
8 changes: 5 additions & 3 deletions src/cli-ux/styled/json.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import chalk from 'chalk'
import {format} from 'node:util'
import {stdout} from '../stream'

import {ux} from '../../index'
const info = (output: string) => stdout.write(format(output) + '\n')

export default function styledJSON(obj: unknown): void {
const json = JSON.stringify(obj, null, 2)
if (!chalk.level) {
ux.info(json)
info(json)
return
}

const cardinal = require('cardinal')
const theme = require('cardinal/themes/jq')
ux.info(cardinal.highlight(json, {json: true, theme}))
info(cardinal.highlight(json, {json: true, theme}))
}
Loading

0 comments on commit 2a3b084

Please sign in to comment.