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

feat: final v3 features #779

Merged
merged 62 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
66a69ea
feat: add charAliases
mdonnalley Sep 6, 2023
b525246
feat: add Flags.option
mdonnalley Sep 6, 2023
292b4b1
fix: undo default options
mdonnalley Sep 6, 2023
d64d915
fix: allow bin/dev.js to auto-transpile ESM plugin
mdonnalley Sep 7, 2023
f6291f2
chore: update execute examples
mdonnalley Sep 7, 2023
f25c4cb
fix: update tsnode skip logic
mdonnalley Sep 7, 2023
d3446a2
chore: test debugging
mdonnalley Sep 7, 2023
f02bce2
fix: ts-node skip logic
mdonnalley Sep 7, 2023
ef1319f
fix: ts-node skip logic
mdonnalley Sep 7, 2023
a28e277
feat: cache relativePath and isESM in manifest
mdonnalley Sep 7, 2023
3273513
fix: calculate id permutations at runtime to support backwards compat…
mdonnalley Sep 7, 2023
15f8177
perf: avoid findLegacyRoot for linked plugins
mdonnalley Sep 7, 2023
4f1a889
chore: remove env var
mdonnalley Sep 7, 2023
e2f37ce
fix: improve perf metrics
mdonnalley Sep 8, 2023
2618f14
perf: improve perf debug output
mdonnalley Sep 8, 2023
13115a6
perf: more debug improvements
mdonnalley Sep 8, 2023
15b8f75
test: compilation errors
mdonnalley Sep 8, 2023
eaec901
fix: make relativePath OS safe
mdonnalley Sep 11, 2023
a89267e
test: use sf esm branch
mdonnalley Sep 11, 2023
7882ce7
perf: give full hook path
mdonnalley Sep 11, 2023
3efa804
chore: test debugging
mdonnalley Sep 11, 2023
0c607e5
chore: test debugging
mdonnalley Sep 11, 2023
7e9505f
chore: test debugging
mdonnalley Sep 11, 2023
e6d5b35
test: set shell for e2e tests
mdonnalley Sep 12, 2023
70f07e4
fix: flag types respect defaults
mdonnalley Sep 12, 2023
0fdc986
feat: node protocol
mdonnalley Sep 14, 2023
cac1dbd
test: move windows sf integration tests into separate job
mdonnalley Sep 15, 2023
d05c513
test: update assertion on plugins install test
mdonnalley Sep 15, 2023
c8d1c61
test: use correct file path
mdonnalley Sep 18, 2023
f13e29c
test: use -Force
mdonnalley Sep 18, 2023
540fc32
test: use bash shell
mdonnalley Sep 18, 2023
160e6c2
test: clean up
mdonnalley Sep 18, 2023
6fcd2a6
test: remove shell option
mdonnalley Sep 18, 2023
86d0ded
test: oclif/config, core v1, and core v2 interop tests
mdonnalley Sep 18, 2023
970d04b
chore: drop node 16
mdonnalley Sep 18, 2023
7a03f8f
test: remove lts/-1
mdonnalley Sep 18, 2023
3f8c63e
chore: code review
mdonnalley Sep 19, 2023
9b949fb
chore: add pre core migration guide
mdonnalley Sep 19, 2023
49b7315
refactor: break up ModuleLoader
mdonnalley Sep 19, 2023
c00d998
chore: remove unicorn/consistent-function-scoping
mdonnalley Sep 19, 2023
a75e37c
chore: remove unicorn/no-missing-imports
mdonnalley Sep 19, 2023
836d7e7
chore: remove @typescript-eslint/no-empty-function
mdonnalley Sep 19, 2023
037e224
chore: remove ban-ts-comment and ban-ts-ignore
mdonnalley Sep 19, 2023
9e9b677
chore: add sort-import rule
mdonnalley Sep 19, 2023
023fe3d
fix: throw error if non-multiple flag provided more than once
mdonnalley Sep 19, 2023
9d66bc9
test: mutliples of non-multiple flag test
mdonnalley Sep 19, 2023
6c2145c
test: ut for charAliases (#791)
mshanemc Sep 19, 2023
8cb414b
test: duplicate aliases tests
mdonnalley Sep 19, 2023
0f65a1c
test: extend timeout
mdonnalley Sep 19, 2023
efbafd9
test: split windows esm-cjs tests
mdonnalley Sep 19, 2023
c579b4f
test: parallelize linux interop tests too
mdonnalley Sep 19, 2023
c62f427
test: typo
mdonnalley Sep 19, 2023
be392d0
test: use right executor
mdonnalley Sep 19, 2023
a4887b5
test: use right executor for clean up
mdonnalley Sep 20, 2023
11b3ed4
chore: update eslint libs (#792)
mdonnalley Sep 21, 2023
1c9104b
chore: replaceAll
mdonnalley Sep 21, 2023
d5fc535
fix: error exit codes
mdonnalley Sep 21, 2023
4ff3245
fix: use es2021
mdonnalley Sep 21, 2023
f83d639
feat: use ES2022
mdonnalley Sep 21, 2023
24fcc62
fix: use ES2021 again
mdonnalley Sep 21, 2023
748fe7c
test: incorporate flags and args in esm-cjs tests
mdonnalley Sep 21, 2023
91665b1
test: use correct expected values
mdonnalley Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
],
"rules": {
"unicorn/prefer-module": "off",
"unicorn/prefer-node-protocol": "off",
"unicorn/import-style": "off",
"unicorn/consistent-function-scoping": "off",
"unicorn/no-array-reduce": "off",
Expand Down
56 changes: 46 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ jobs:
needs: linux-unit-tests
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
node_version: [lts/-1, lts/*, latest]
os: [ubuntu-latest, windows-latest]
node_version: [lts/*, latest]
exclude:
- os: windows-latest
node_version: lts/*
- os: windows-latest
node_version: lts/-1
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -34,18 +32,56 @@ jobs:
cache: yarn
- run: yarn install --network-timeout 600000
- run: yarn build
- run: yarn test:e2e
- if: runner.os == 'Windows'
run: yarn mocha --forbid-only "test/**/*.e2e.ts" --exclude "test/integration/sf.e2e.ts" --parallel --timeout 1200000
- if: runner.os == 'Linux'
run: yarn test:e2e
windows-sf-e2e:
# For whatever reason the windows-latest runner doesn't like it when you shell yarn commands in the sf repo
# which is an integral part of the setup for the tests. Instead, we replicate the setup here.
needs: linux-unit-tests
strategy:
fail-fast: false
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: latest
cache: yarn
- run: yarn install --network-timeout 600000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and elsewhere, prefer https://github.com/salesforcecli/github-workflows/blob/main/.github/actions/yarnInstallWithRetries/action.yml

use it like - uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main

- run: yarn build
- run: yarn link
- run: New-Item -Path D:\a -Name "e2e" -ItemType "directory"
- run: New-Item -Path D:\a\e2e -Name "sf.e2e.ts" -ItemType "directory"
- run: |
git clone https://github.com/salesforcecli/cli.git --branch mdonnalley/esm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is your branch required just temporarily?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. The sf integration tests fail since there are breaking changes. I have a note to switch this back to main once salesforcecli/cli#1094 is merged

cd cli

$Json = Get-Content package.json | ConvertFrom-Json
$Json.dependencies | Add-Member -Force -MemberType NoteProperty -Name "@oclif/core" -Value "file:D:\a\core\core"
$Json.resolutions | Add-Member -MemberType NoteProperty -Name "@oclif/core" -Value "D:\a\core\core"
$Json | ConvertTo-Json -Depth 9 | Out-File package.json

yarn install --network-timeout 600000
yarn link @oclif/core
yarn build
working-directory: D:\a\e2e\sf.e2e.ts
- run: yarn mocha --forbid-only "test/integration/sf.e2e.ts" --parallel --timeout 1200000
env:
OCLIF_CORE_E2E_SKIP_SETUP: true
OCLIF_CORE_E2E_TEST_DIR: D:\a\e2e
DEBUG: e2e:*

esm-cjs-interop:
needs: linux-unit-tests
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
node_version: [lts/-1, lts/*, latest]
os: [ubuntu-latest, windows-latest]
node_version: [lts/*, latest]
exclude:
- os: windows-latest
node_version: lts/*
- os: windows-latest
node_version: lts/-1
fail-fast: false
runs-on: ${{ matrix.os }}
timeout-minutes: 60
Expand All @@ -64,7 +100,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest"]
os: [ubuntu-latest, windows-latest]
externalProjectGitUrl:
- https://github.com/salesforcecli/plugin-auth
- https://github.com/salesforcecli/plugin-data
Expand Down
35 changes: 35 additions & 0 deletions guides/V3_MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Migrating to @oclif/core@V3
- [`noCacheDefault` flag property replaces `isWritingManifest`](#nocachedefault-flag-property-replaces-iswritingmanifest)
- [Features 🎉](#features-)
- [Cache Flexible taxonomy Command Permutations](#cache-flexible-taxonomy-command-permutations)
- [charAliases Flag Property](#charaliases-flag-property)
- [Flags.option](#flagsoption)


## BREAKING CHANGES ❗
Expand Down Expand Up @@ -114,3 +116,36 @@ export const mySensitiveFlag = Flags.string({
### Cache Flexible taxonomy Command Permutations

The command permutations for flexible taxonomy are now cached in the oclif.manifest.json allowing for quicker startup times.

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

```typescript
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,

```typescript
export default class MyCommand extends Command {
static flags = {
name: Flags.option({
options: ['foo', 'bar'] as const,
})(),
}
}
```
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@types/nock": "^11.1.0",
"@types/node": "^16",
"@types/node-notifier": "^8.0.2",
"@types/proxyquire": "^1.3.28",
"@types/shelljs": "^0.8.12",
"@types/slice-ansi": "^4.0.0",
"@types/strip-ansi": "^5.2.1",
Expand All @@ -72,15 +71,14 @@
"husky": "6",
"mocha": "^10.2.0",
"nock": "^13.3.0",
"proxyquire": "^2.1.3",
"shelljs": "^0.8.5",
"shx": "^0.3.4",
"sinon": "^11.1.2",
"tsd": "^0.25.0",
"typescript": "^4.9.5"
},
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"files": [
"/lib",
Expand Down
2 changes: 1 addition & 1 deletion src/args.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {URL} from 'url'
import {URL} from 'node:url'
import {Arg, ArgDefinition} from './interfaces/parser'
import {Command} from './command'
import {dirExists, fileExists, isNotFalsy} from './util'
Expand Down
2 changes: 1 addition & 1 deletion src/cli-ux/action/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {inspect} from 'util'
import {inspect} from 'node:util'
import {castArray} from '../../util'
import {stderr, stdout} from '../stream'

Expand Down
8 changes: 4 additions & 4 deletions src/cli-ux/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Errors from '../errors'
import * as util from 'util'
import {format as utilFormat} from 'node:util'
import * as chalk from 'chalk'
import {ActionBase} from './action/base'
import {config, Config} from './config'
Expand Down Expand Up @@ -71,18 +71,18 @@ export class ux {

public static trace(format: string, ...args: string[]): void {
if (this.config.outputLevel === 'trace') {
stdout.write(util.format(format, ...args) + '\n')
stdout.write(utilFormat(format, ...args) + '\n')
}
}

public static debug(format: string, ...args: string[]): void {
if (['trace', 'debug'].includes(this.config.outputLevel)) {
stdout.write(util.format(format, ...args) + '\n')
stdout.write(utilFormat(format, ...args) + '\n')
}
}

public static info(format: string, ...args: string[]): void {
stdout.write(util.format(format, ...args) + '\n')
stdout.write(utilFormat(format, ...args) + '\n')
}

public static log(format?: string, ...args: string[]): void {
Expand Down
6 changes: 3 additions & 3 deletions src/cli-ux/styled/object.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as chalk from 'chalk'
import * as util from 'util'
import {inspect} from 'node:util'

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export default function styledObject(obj: any, keys?: string[]): string {
Expand All @@ -10,11 +10,11 @@ export default function styledObject(obj: any, keys?: string[]): string {
if (typeof obj === 'string' || typeof obj === 'number') return obj
if (typeof obj === 'object') {
return Object.keys(obj)
.map(k => k + ': ' + util.inspect(obj[k]))
.map(k => k + ': ' + inspect(obj[k]))
.join(', ')
}

return util.inspect(obj)
return inspect(obj)
}

const logKeyValue = (key: string, value: any): string => {
Expand Down
2 changes: 1 addition & 1 deletion src/cli-ux/styled/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {stdtermwidth} from '../../screen'
import * as chalk from 'chalk'
import {capitalize, sumBy} from '../../util'
import {safeDump} from 'js-yaml'
import {inspect} from 'util'
import {inspect} from 'node:util'
import {stdout} from '../stream'

const sw = require('string-width')
Expand Down
20 changes: 11 additions & 9 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {fileURLToPath} from 'url'
import {fileURLToPath} from 'node:url'
import * as chalk from 'chalk'
import {format, inspect} from 'util'
import {format, inspect} from 'node:util'
import {ux} from './cli-ux'
import {Config} from './config'
import * as Errors from './errors'
import {PrettyPrintableError} from './errors'
import * as Parser from './parser'
import {
BooleanFlagProps,
CompletableFlag,
Deprecation,
Arg as IArg,
ArgInput,
ArgOutput,
ArgProps,
BooleanFlagProps,
Deprecation,
Flag as IFlag,
FlagInput,
FlagOutput,
Input,
ArgProps,
OptionFlagProps,
ParserOutput,
ArgOutput,
} from './interfaces/parser'
import {formatCommandDeprecationWarning, formatFlagDeprecationWarning, toConfiguredId, normalizeArgv} from './help/util'
import {Plugin} from './interfaces/plugin'
Expand Down Expand Up @@ -315,7 +315,7 @@ export abstract class Command {
}

const deprecateAliases = flagDef?.deprecateAliases
const aliases = (flagDef?.aliases ?? []).map(a => a.length === 1 ? `-${a}` : `--${a}`)
const aliases = ([...flagDef?.aliases ?? [], ...flagDef?.charAliases ?? []]).map(a => a.length === 1 ? `-${a}` : `--${a}`)
if (deprecateAliases && aliases.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to put, for example, c in both aliases and charAliases such that they'd get the warning multiple times (and we should Set-dedupe them?)

also, rather than iterating all these aliases, should we exit early if !deprecateAliases and then compute the aliases and check length?

const foundAliases = aliases.filter(alias => this.argv.some(a => a.startsWith(alias)))
for (const alias of foundAliases) {
Expand Down Expand Up @@ -435,9 +435,11 @@ export namespace Command {
hasDynamicHelp?: boolean;
permutations?: string[]
aliasPermutations?: string[];
isESM?: boolean;
relativePath?: string[];
}

export type Flag = CompletableFlag<any>
export type Flag = IFlag<any>

export namespace Flag {
export type Cached = Omit<Flag, 'parse' | 'input'> & (BooleanFlagProps | OptionFlagProps)
Expand Down
Loading
Loading