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: revert exports changes #776

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ See the [v3 migration guide](./guides/V3_MIGRATION.md) for an overview of breaki
CLI UX
=====

The [ux README](./src/ux/README.md) contains detailed usage examples of using the `ux` export.
The [ux README](./src/cli-ux/README.md) contains detailed usage examples of using the `ux` export.

Usage
=====
Expand Down
3 changes: 3 additions & 0 deletions flush.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const flush: () => Promise<void>

export = flush
1 change: 1 addition & 0 deletions flush.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/cli-ux/flush').flush
26 changes: 0 additions & 26 deletions guides/V3_MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Migrating to @oclif/core@V3
- [`handle`](#handle)
- [`noCacheDefault` flag property replaces `isWritingManifest`](#nocachedefault-flag-property-replaces-iswritingmanifest)
- [Features 🎉](#features-)
- [Exports](#exports)
- [Cache Flexible taxonomy Command Permutations](#cache-flexible-taxonomy-command-permutations)


Expand Down Expand Up @@ -112,31 +111,6 @@ export const mySensitiveFlag = Flags.string({

## Features 🎉

### Exports
The `exports` property in the package.json are now used for exporting a few individual pieces of functionality.

The main export should continue to work as it did in v2:

```typescript
import {handle, flush} from '@oclif/core'
```

But you can now import individual modules if desired:

```typescript
import handle from '@oclif/core/handle'
import flush from '@oclif/core/flush'
```

These are the exports that are available:
`@oclif/core/execute`
`@oclif/core/flush`
`@oclif/core/handle`
`@oclif/core/run`
`@oclif/core/settings`

**You will need to set moduleResolution to Node16 in your tsconfig.json to use this feature.**

### Cache Flexible taxonomy Command Permutations

The command permutations for flexible taxonomy are now cached in the oclif.manifest.json allowing for quicker startup times.
1 change: 1 addition & 0 deletions handle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = async error => require('./lib/errors/handle').handle(error)
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,17 @@
"node": ">=16.0.0"
},
"files": [
"/lib"
"/lib",
"/flush.js",
"/flush.d.ts",
"/handle.js"
],
"homepage": "https://github.com/oclif/core",
"keywords": [
"oclif"
],
"license": "MIT",
"main": "./lib/index.js",
"exports": {
".": "./lib/index.js",
"./execute": "./lib/execute.js",
"./flush": "./lib/ux/flush.js",
"./handle": "./lib/errors/handle.js",
"./run": "./lib/main.js",
"./settings": "./lib/settings.js"
},
"repository": "oclif/core",
"oclif": {
"bin": "oclif",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ux/flush.ts → src/cli-ux/flush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ async function _flush() {
return p
}

export default async function flush(ms = 10_000): Promise<void> {
export async function flush(ms = 10_000): Promise<void> {
await timeout(_flush(), ms)
}
File renamed without changes.
19 changes: 9 additions & 10 deletions src/ux/index.ts → src/cli-ux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import {ExitError} from './exit'
import {IPromptOptions} from './prompt'
import * as styled from './styled'
import {Table} from './styled'
export * from './styled/table'
import * as uxPrompt from './prompt'
import uxWait from './wait'
import {stdout} from './stream'
import * as _flush from './flush'
import {flush as _flush} from './flush'

const hyperlinker = require('hyperlinker')

export default class ux {
export class ux {
public static config: Config = config

public static get prompt(): typeof uxPrompt.prompt {
Expand Down Expand Up @@ -110,7 +109,7 @@ export default class ux {
}

public static async flush(ms = 10_000): Promise<void> {
await _flush.default(ms)
await _flush(ms)
}
}

Expand Down Expand Up @@ -139,33 +138,33 @@ const warn = Errors.warn

export {
action,
ActionBase,
annotation,
anykey,
config,
Config,
confirm,
debug,
done,
error,
exit,
ExitError,
flush,
info,
IPromptOptions,
log,
progress,
prompt,
styledHeader,
styledJSON,
styledObject,
table,
Table,
trace,
tree,
url,
wait,
warn,
ActionBase,
config,
Config,
ExitError,
IPromptOptions,
Table,
}

const uxProcessExitHandler = async () => {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/ux/prompt.ts → src/cli-ux/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ async function _prompt(name: string, inputOptions: Partial<IPromptOptions> = {})
...inputOptions,
}
const passwordPrompt = require('password-prompt')

switch (options.type) {
case 'normal':
return normal(options)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ux/styled/json.ts → src/cli-ux/styled/json.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as chalk from 'chalk'

import ux from '../index'
import {ux} from '../index'

export default function styledJSON(obj: unknown): void {
const json = JSON.stringify(obj, null, 2)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {fileURLToPath} from 'url'
import * as chalk from 'chalk'
import {format, inspect} from 'util'
import ux from './ux'
import {ux} from './cli-ux'
import {Config} from './config'
import * as Errors from './errors'
import {PrettyPrintableError} from './errors'
Expand All @@ -27,7 +27,7 @@ import {CommandError} from './interfaces/errors'
import {boolean} from './flags'
import {requireJson} from './util'
import {PJSON} from './interfaces'
import {stdout, stderr} from './ux/stream'
import {stdout, stderr} from './cli-ux/stream'

const pjson = requireJson<PJSON>(__dirname, '..', 'package.json')

Expand Down
4 changes: 2 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import ModuleLoader from '../module-loader'
import {getHelpFlagAdditions} from '../help'
import {Command} from '../command'
import {CompletableOptionFlag, Arg} from '../interfaces/parser'
import {stdout} from '../ux/stream'
import {stdout} from '../cli-ux/stream'
import Performance from '../performance'
import settings from '../settings'
import {settings} from '../settings'
import {userInfo as osUserInfo} from 'node:os'
import {sep} from 'node:path'
import PluginLoader from './plugin-loader'
Expand Down
2 changes: 1 addition & 1 deletion src/config/ts-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path'
import * as TSNode from 'ts-node'

import {TSConfig, Plugin} from '../interfaces'
import settings from '../settings'
import {settings} from '../settings'
import {isProd} from '../util'
import {Debug} from './util'
import {Config} from './config'
Expand Down
2 changes: 1 addition & 1 deletion src/errors/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import settings from '../settings'
import {settings} from '../settings'
import {Logger} from './logger'

function displayWarnings() {
Expand Down
2 changes: 1 addition & 1 deletion src/errors/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import clean = require('clean-stack')
import {CLIError} from './errors/cli'
import {OclifError, PrettyPrintableError} from '../interfaces'

export default async function handle(err: Error & Partial<PrettyPrintableError> & Partial<OclifError> & {skipOclifErrorHandling?: boolean}): Promise<void> {
export async function handle(err: Error & Partial<PrettyPrintableError> & Partial<OclifError> & {skipOclifErrorHandling?: boolean}): Promise<void> {
try {
if (!err) err = new CLIError('no error?')
if (err.message === 'SIGINT') process.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {default as handle} from './handle'
export {handle} from './handle'
export {ExitError} from './errors/exit'
export {ModuleLoadError} from './errors/module-load'
export {CLIError} from './errors/cli'
Expand Down
6 changes: 3 additions & 3 deletions src/execute.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import settings from './settings'
import flush from './ux/flush'
import handle from './errors/handle'
import {settings} from './settings'
import {flush} from './cli-ux/flush'
import {handle} from './errors/handle'
import run from './main'
import * as Interfaces from './interfaces'

Expand Down
2 changes: 1 addition & 1 deletion src/help/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {formatCommandDeprecationWarning, getHelpFlagAdditions, standardizeIDFrom
import {HelpFormatter} from './formatter'
import {toCached} from '../config/config'
import {Command} from '../command'
import {stdout} from '../ux/stream'
import {stdout} from '../cli-ux/stream'
export {CommandHelp} from './command'
export {standardizeIDFromArgv, loadHelpClass, getHelpFlagAdditions, normalizeArgv} from './util'

Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Command} from './command'
import run from './main'
import execute from './execute'
import handle from './errors/handle'
import {handle} from './errors/handle'
import {Config, Plugin, tsPath, toCached} from './config'
import * as Interfaces from './interfaces'
import * as Errors from './errors'
Expand All @@ -11,12 +11,12 @@ import {CommandHelp, HelpBase, Help, loadHelpClass} from './help'
import {toStandardizedId, toConfiguredId} from './help/util'
import * as Parser from './parser'
import {Hook} from './interfaces/hooks'
import settings, {Settings} from './settings'
import {settings, Settings} from './settings'
import {HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable} from './help/formatter'
import * as ux from './ux'
import {stderr, stdout} from './ux/stream'
import * as ux from './cli-ux'
import {stderr, stdout} from './cli-ux/stream'
import Performance from './performance'
import flush from './ux/flush'
import {flush} from './cli-ux/flush'

export {
Args,
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as Interfaces from './interfaces'
import {URL} from 'url'
import {Config} from './config'
import {getHelpFlagAdditions, loadHelpClass, normalizeArgv} from './help'
import {stdout} from './ux/stream'
import {stdout} from './cli-ux/stream'
import Performance from './performance'

const debug = require('debug')('oclif:main')
Expand Down
2 changes: 1 addition & 1 deletion src/parser/errors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CLIError} from '../errors'

import {flagUsages} from './help'
import {renderList} from '../ux/list'
import {renderList} from '../cli-ux/list'
import * as chalk from 'chalk'
import {OptionFlag, Flag} from '../interfaces'
import {uniq} from '../config/util'
Expand Down
2 changes: 1 addition & 1 deletion src/performance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PerformanceObserver, performance} from 'perf_hooks'
import settings from './settings'
import {settings} from './settings'

type Details = Record<string, string | boolean | number | string[]>
type PerfResult = {
Expand Down
4 changes: 2 additions & 2 deletions src/screen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {stdout, stderr} from './ux/stream'
import settings from './settings'
import {stdout, stderr} from './cli-ux/stream'
import {settings} from './settings'

function termwidth(stream: any): number {
if (!stream.isTTY) {
Expand Down
3 changes: 1 addition & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ export type Settings = {
// Set global.oclif to the new object if it wasn't set before
if (!(global as any).oclif) (global as any).oclif = {}

const settings: Settings = (global as any).oclif as Settings
export default settings
export const settings: Settings = (global as any).oclif as Settings
2 changes: 1 addition & 1 deletion test/cli-ux/export.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ux, {Table, IPromptOptions, Config, ActionBase, ExitError} from '../../src/ux'
import {ux, Table, IPromptOptions, Config, ActionBase, ExitError} from '../../src/cli-ux'
import {expect} from 'chai'

type MyColumns = Record<string, unknown>
Expand Down
2 changes: 1 addition & 1 deletion test/cli-ux/fancy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {expect, fancy as base, FancyTypes} from 'fancy-test'
import {rm} from 'node:fs/promises'
import {join} from 'node:path'

import ux from '../../src/ux'
import {ux} from '../../src/cli-ux'

export {
expect,
Expand Down
2 changes: 1 addition & 1 deletion test/cli-ux/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ux from '../../src/ux'
import {ux} from '../../src/cli-ux'

import {expect, fancy} from './fancy'
const hyperlinker = require('hyperlinker')
Expand Down
2 changes: 1 addition & 1 deletion test/cli-ux/prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as chai from 'chai'

const expect = chai.expect

import ux from '../../src/ux'
import {ux} from '../../src/cli-ux'

import {fancy} from './fancy'

Expand Down
2 changes: 1 addition & 1 deletion test/cli-ux/styled/header.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {expect} from 'chai'

import {stdout} from '../../../src'
import {stub, SinonStub} from 'sinon'
import ux from '../../../src/ux'
import {ux} from '../../../src/cli-ux'

describe('styled/header', () => {
let writeStub: SinonStub
Expand Down
2 changes: 1 addition & 1 deletion test/cli-ux/styled/object.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, fancy} from 'fancy-test'

import ux from '../../../src/ux'
import {ux} from '../../../src/cli-ux'

describe('styled/object', () => {
fancy
Expand Down
2 changes: 1 addition & 1 deletion test/cli-ux/styled/progress.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect, fancy} from 'fancy-test'
import ux from '../../../src/ux'
import {ux} from '../../../src/cli-ux'

describe('progress', () => {
// single bar
Expand Down
2 changes: 1 addition & 1 deletion test/cli-ux/styled/table.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect, fancy} from 'fancy-test'
import ux from '../../../src/ux'
import {ux} from '../../../src/cli-ux'

describe('styled/table', () => {
describe('null/undefined handling', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/cli-ux/styled/table.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, fancy} from 'fancy-test'

import ux from '../../../src/ux'
import {ux} from '../../../src/cli-ux'
import * as screen from '../../../src/screen'

/* eslint-disable camelcase */
Expand Down
2 changes: 1 addition & 1 deletion test/cli-ux/styled/tree.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, fancy} from 'fancy-test'

import ux from '../../../src/ux'
import {ux} from '../../../src/cli-ux'

describe('styled/tree', () => {
fancy
Expand Down
Loading