Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/prerelease/v3' into sm/custom-pe…
Browse files Browse the repository at this point in the history
…rf-markers
  • Loading branch information
mshanemc committed Oct 2, 2023
2 parents 3a1c6e7 + c696a24 commit c73fadf
Show file tree
Hide file tree
Showing 145 changed files with 7,651 additions and 5,088 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}
11 changes: 0 additions & 11 deletions .editorconfig

This file was deleted.

3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": [
"oclif",
"oclif-typescript"
"oclif-typescript",
"prettier"
],
"rules": {
"sort-imports": "error",
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ name: automerge
on:
workflow_dispatch:
schedule:
- cron: '17 2,5,8,11 * * *'
- cron: "17 2,5,8,11 * * *"

jobs:
automerge:
uses: oclif/github-workflows/.github/workflows/automerge.yml@main
secrets: inherit
uses: salesforcecli/github-workflows/.github/workflows/automerge.yml@main
secrets:
SVC_CLI_BOT_GITHUB_TOKEN: ${{ secrets.SVC_CLI_BOT_GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged --concurrent false
5 changes: 5 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"*.json": ["prettier --write"],
"*.md": ["prettier --write"],
"+(src|test)/**/*.+(ts|js)": ["eslint --fix", "prettier --write"]
}
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"
1 change: 0 additions & 1 deletion commitlint.config.js

This file was deleted.

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
80 changes: 41 additions & 39 deletions guides/V3_MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
Migrating to @oclif/core@V3
==============
# Migrating to @oclif/core@V3

- [Migrating to @oclif/core@V3](#migrating-to-oclifcorev3)
- [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 Unnecessary Exports](#removed-unnecessary-exports)
- [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 ❗

### Dropping node 14 and node 16 support
The end-of-life date for Node.js 14 was [April 30, 2023](https://nodejs.org/en/about/releases/).

The end-of-life date for Node.js 14 was [April 30, 2023](https://nodejs.org/en/about/releases/).

The end-of-life date for Node.js 16 was [September 11, 2023](https://nodejs.org/en/about/releases/). This date is earlier than previously published. Node.js’s [blog](https://nodejs.org/en/blog/announcements/nodejs16-eol/) explains why they chose this earlier end-of-life date.

Expand All @@ -36,44 +38,23 @@ 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.

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`

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`

The `_manifest` and `warn` methods on `Plugin` are now `private`

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

Expand All @@ -91,12 +72,12 @@ Version 2 allowed you to optionally return non-sensitive input if the `default`
export const mySensitiveFlag = Flags.string({
default: async (context, isWritingManifest) => {
if (isWritingManifest) {
return undefined;
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.
Expand All @@ -107,15 +88,24 @@ export const mySensitiveFlag = Flags.string({
default: async (context) => {
return 'sensitive info'
},
});
})
```

### Removed Unnecessary Exports

The following exports have been removed:

- `toCached`
- `tsPath`

## 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 +139,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()
```
36 changes: 21 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "3.0.0-beta.17",
"version": "3.0.0-beta.22",
"author": "Salesforce",
"bugs": "https://github.com/oclif/core/issues",
"dependencies": {
"@types/cli-progress": "^3.11.0",
"ansi-escapes": "^4.3.2",
"ansi-styles": "^4.3.0",
"cardinal": "^2.1.1",
Expand Down Expand Up @@ -33,22 +32,23 @@
"wrap-ansi": "^7.0.0"
},
"devDependencies": {
"@commitlint/config-conventional": "^12.1.4",
"@commitlint/config-conventional": "^17.7.0",
"@oclif/plugin-help": "^5.2.8",
"@oclif/plugin-plugins": "^3.3.0",
"@oclif/test": "^2.4.7",
"@oclif/prettier-config": "^0.2.1",
"@oclif/test": "^3.0.1",
"@types/ansi-styles": "^3.2.1",
"@types/benchmark": "^2.1.2",
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
"@types/chai": "^4.3.4",
"@types/clean-stack": "^2.1.1",
"@types/cli-progress": "^3.11.0",
"@types/ejs": "^3.1.2",
"@types/indent-string": "^4.0.1",
"@types/js-yaml": "^3.12.7",
"@types/mocha": "^8.2.3",
"@types/nock": "^11.1.0",
"@types/node": "^18",
"@types/mocha": "^10.0.2",
"@types/node-notifier": "^8.0.2",
"@types/node": "^18",
"@types/slice-ansi": "^4.0.0",
"@types/strip-ansi": "^5.2.1",
"@types/supports-color": "^8.1.1",
Expand All @@ -57,16 +57,20 @@
"benchmark": "^2.1.4",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
"commitlint": "^12.1.4",
"commitlint": "^17.7.2",
"cross-env": "^7.0.3",
"eslint": "^8.50.0",
"eslint-config-oclif": "^5.0.0",
"eslint-config-oclif-typescript": "^2.0.1",
"fancy-test": "^3.0.0-beta.2",
"eslint-config-prettier": "^9.0.0",
"fancy-test": "^3.0.1",
"globby": "^11.1.0",
"husky": "6",
"husky": "^8",
"lint-staged": "^14.0.1",
"madge": "^6.1.0",
"mocha": "^10.2.0",
"nock": "^13.3.0",
"nyc": "^15.1.0",
"prettier": "^3.0.3",
"shx": "^0.3.4",
"sinon": "^11.1.2",
"ts-node": "^10.9.1",
Expand Down Expand Up @@ -104,14 +108,16 @@
"build": "shx rm -rf lib && tsc",
"commitlint": "commitlint",
"compile": "tsc",
"format": "prettier --write \"+(src|test)/**/*.+(ts|js|json)\"",
"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"
}
11 changes: 5 additions & 6 deletions src/args.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import {Arg, ArgDefinition} from './interfaces/parser'
import {dirExists, fileExists, isNotFalsy} from './util'
import {dirExists, fileExists} from './util/fs'
import {Command} from './command'
import {URL} from 'node:url'
import {isNotFalsy} from './util/util'

/**
* Create a custom arg.
Expand Down Expand Up @@ -33,13 +33,12 @@ export function custom<T, P = Record<string, unknown>>(defaults: Partial<Arg<T,
}

export const boolean = custom<boolean>({
parse: async b => Boolean(b) && isNotFalsy(b),
parse: async (b) => Boolean(b) && isNotFalsy(b),
})

export const integer = custom<number, {min?: number; max?: number;}>({
export const integer = custom<number, {min?: number; max?: number}>({
async parse(input, _, opts) {
if (!/^-?\d+$/.test(input))
throw new Error(`Expected an integer but received: ${input}`)
if (!/^-?\d+$/.test(input)) throw new Error(`Expected an integer but received: ${input}`)
const num = Number.parseInt(input, 10)
if (opts.min !== undefined && num < opts.min)
throw new Error(`Expected an integer greater than or equal to ${opts.min} but received: ${input}`)
Expand Down
Loading

0 comments on commit c73fadf

Please sign in to comment.