Skip to content

Commit

Permalink
dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuss committed Jul 7, 2024
1 parent dd19581 commit 5ded25c
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 281 deletions.
31 changes: 14 additions & 17 deletions cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
#!/usr/bin/env node

// Disables (node:64080) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
process.emitWarning = () => {};
(async () => {
process.emitWarning = () => {};

// import { Console } from 'console';
import { ErrorWithReturnCode } from '../src/errors';
import { Command } from '../src/command';
import { Console } from 'console';
import { isHeadless } from '../src/ui';
const { ErrorWithReturnCode } = await import('../src/errors');
const { Command } = await import('../src/command');
const { Console } = await import('console');
const { isHeadless } = await import('../src/ui');

export const outputStream = isHeadless() ? process.stderr : process.stdout;
export const customConsole = new Console(outputStream, process.stderr);
const customConsole = new Console(isHeadless() ? process.stderr : process.stdout, process.stderr);

console.log = customConsole.log;
console.info = customConsole.info;
console.warn = customConsole.warn;
console.error = customConsole.error;
console.debug = customConsole.debug;
console.clear = customConsole.clear;
console.trace = customConsole.trace;
console.log = customConsole.log;
console.info = customConsole.info;
console.warn = customConsole.warn;
console.error = customConsole.error;
console.debug = customConsole.debug;
console.clear = customConsole.clear;
console.trace = customConsole.trace;

(async () => {
const command = new Command(process.argv);
try {
await command.run(process.argv);
Expand Down
486 changes: 243 additions & 243 deletions dist/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/index.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@types/node": "16",
"@types/qrcode-terminal": "^0.12.0",
"@types/which": "^2.0.1",
"@types/yargs": "^17.0.7",
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"axios": "^0.27.2",
Expand All @@ -86,6 +86,6 @@
"source-map": "^0.7.3",
"ts-node": "^10.4.0",
"typescript": "^4.5.4",
"yargs": "^17.3.0"
"yargs": "^17.7.2"
}
}
}
8 changes: 4 additions & 4 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { hideBin } from 'yargs/helpers';
import yargs from 'yargs';
import axios from 'axios';
import { AssumeCommand } from './commands/assume';
// import { InitCommand } from './commands/init';
Expand All @@ -16,14 +15,14 @@ import { version } from '../package.json';
import { ApiHelper } from './helpers/apiHelper';
import { NOT_LOGGED_IN } from './messages';
import { ErrorWithReturnCode, RETURN_CODE_NOT_LOGGED_IN } from './errors';
import { outputStream } from '../cli';
import { BottomBar } from './ui';
import { BottomBar, isHeadless } from './ui';

process.addListener('SIGINT', () => {
console.log('Exiting!');
process.exit(0);
});

const outputStream = isHeadless() ? process.stderr : process.stdout;
export const ui = new BottomBar(outputStream);

export const prompt = <T extends inquirer.Answers>(
Expand Down Expand Up @@ -67,7 +66,8 @@ export class Command {
}

public async run(argv: string[]): Promise<void> {
const ya = yargs
const yargs = (await import('yargs')).default;
const ya = yargs()
.scriptName(this.messagesHelper.processName)
.command({
command: 'identity',
Expand Down
34 changes: 24 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1263,10 +1263,10 @@
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.1.tgz#3b9ce2489919d9e4fea439b76916abc34b2df129"
integrity sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==

"@types/yargs@^17.0.7":
version "17.0.7"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.7.tgz#44a484c634761da4391477515a98772b82b5060f"
integrity sha512-OvLKmpKdea1aWtqHv9bxVVcMoT6syAeK+198dfETIFkAevYRGwqh4H+KFxfjUETZuUuE5sQCAFwdOdoHUdo8eg==
"@types/yargs@^17.0.32":
version "17.0.32"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.32.tgz#030774723a2f7faafebf645f4e5a48371dca6229"
integrity sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==
dependencies:
"@types/yargs-parser" "*"

Expand Down Expand Up @@ -1613,6 +1613,15 @@ cliui@^7.0.2:
strip-ansi "^6.0.0"
wrap-ansi "^7.0.0"

cliui@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa"
integrity sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==
dependencies:
string-width "^4.2.0"
strip-ansi "^6.0.1"
wrap-ansi "^7.0.0"

clone@^1.0.2:
version "1.0.4"
resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e"
Expand Down Expand Up @@ -3440,6 +3449,11 @@ yargs-parser@^21.0.0:
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.0.tgz#a485d3966be4317426dd56bdb6a30131b281dc55"
integrity sha512-z9kApYUOCwoeZ78rfRYYWdiU/iNL6mwwYlkkZfJoyMR1xps+NEBX5X7XmRpxkZHhXJ6+Ey00IwKxBBSW9FIjyA==

yargs-parser@^21.1.1:
version "21.1.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35"
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==

yargs@^17.2.1:
version "17.3.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.3.0.tgz#295c4ffd0eef148ef3e48f7a2e0f58d0e4f26b1c"
Expand All @@ -3453,18 +3467,18 @@ yargs@^17.2.1:
y18n "^5.0.5"
yargs-parser "^21.0.0"

yargs@^17.3.0:
version "17.3.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.3.1.tgz#da56b28f32e2fd45aefb402ed9c26f42be4c07b9"
integrity sha512-WUANQeVgjLbNsEmGk20f+nlHgOqzRFpiGWVaBrYGYIGANIIu3lWjoyi0fNlFmJkvfhCZ6BXINe7/W2O2bV4iaA==
yargs@^17.7.2:
version "17.7.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269"
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==
dependencies:
cliui "^7.0.2"
cliui "^8.0.1"
escalade "^3.1.1"
get-caller-file "^2.0.5"
require-directory "^2.1.1"
string-width "^4.2.3"
y18n "^5.0.5"
yargs-parser "^21.0.0"
yargs-parser "^21.1.1"

[email protected]:
version "3.1.1"
Expand Down

0 comments on commit 5ded25c

Please sign in to comment.