diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 1b567971..8b23c911 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -42,7 +42,6 @@ "fast-boot2": "^1.1.0", "fast-levenshtein": "^3.0.0", "filenamify": "^4.3.0", - "get-stdin": "^8.0.0", "glob": "^7.2.0", "global-agent": "^2.2.0", "global-tunnel-ng": "^2.1.1", @@ -9402,17 +9401,6 @@ "node": ">=4" } }, - "node_modules/get-stdin": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", - "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", diff --git a/package.json b/package.json index 55e90fbb..09d49994 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "helpClass": "./build/help", "topicSeparator": " ", "hooks": { - "prerun": "./build/hooks/prerun/track", + "prerun": "./build/hooks/prerun", "command_not_found": "./build/hooks/command-not-found/suggest" }, "additionalHelpFlags": [ @@ -221,7 +221,6 @@ "fast-boot2": "^1.1.0", "fast-levenshtein": "^3.0.0", "filenamify": "^4.3.0", - "get-stdin": "^8.0.0", "glob": "^7.2.0", "global-agent": "^2.2.0", "global-tunnel-ng": "^2.1.1", diff --git a/src/app.ts b/src/app.ts index 87003b5e..e2c4f17d 100644 --- a/src/app.ts +++ b/src/app.ts @@ -153,7 +153,7 @@ async function oclifRun(command: string[], options: AppOptions) { } })(!options.noFlush); - const { trackPromise } = await import('./hooks/prerun/track'); + const { trackPromise } = await import('./hooks/prerun'); await Promise.all([trackPromise, deprecationPromise, runPromise]); } diff --git a/src/command.ts b/src/command.ts deleted file mode 100644 index 4c5d66bd..00000000 --- a/src/command.ts +++ /dev/null @@ -1,170 +0,0 @@ -/** - * @license - * Copyright 2020 Balena Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Command } from '@oclif/core'; -import { - InsufficientPrivilegesError, - NotAvailableInOfflineModeError, -} from './errors'; -import { stripIndent } from './utils/lazy'; - -export default abstract class BalenaCommand extends Command { - /** - * When set to true, command will be listed in `help`, - * otherwise listed in `help --verbose` with secondary commands. - */ - public static primary = false; - - /** - * Require elevated privileges to run. - * When set to true, command will exit with an error - * if executed without root on Mac/Linux - * or if executed by non-Administrator on Windows. - */ - public static root = false; - - /** - * Require authentication to run. - * When set to true, command will exit with an error - * if user is not already logged in. - */ - public static authenticated = false; - - /** - * Require an internet connection to run. - * When set to true, command will exit with an error - * if user is running in offline mode (BALENARC_OFFLINE_MODE). - */ - public static offlineCompatible = false; - - /** - * Accept piped input. - * When set to true, command will read from stdin during init - * and make contents available on member `stdin`. - */ - public static readStdin = false; - - public stdin: string; - - /** - * Throw InsufficientPrivilegesError if not root on Mac/Linux - * or non-Administrator on Windows. - * - * Called automatically if `root=true`. - * Can be called explicitly by command implementation, if e.g.: - * - check should only be done conditionally - * - other code needs to execute before check - */ - protected static async checkElevatedPrivileges() { - const isElevated = await (await import('is-elevated'))(); - if (!isElevated) { - throw new InsufficientPrivilegesError( - 'You need root/admin privileges to run this command', - ); - } - } - - /** - * Throw NotLoggedInError if not logged in. - * - * Called automatically if `authenticated=true`. - * Can be called explicitly by command implementation, if e.g.: - * - check should only be done conditionally - * - other code needs to execute before check - * - * Note, currently public to allow use outside of derived commands - * (as some command implementations require this. Can be made protected - * if this changes). - * - * @throws {NotLoggedInError} - */ - public static async checkLoggedIn() { - await (await import('./utils/patterns')).checkLoggedIn(); - } - - /** - * Throw NotLoggedInError if not logged in when condition true. - * - * @param {boolean} doCheck - will check if true. - * @throws {NotLoggedInError} - */ - public static async checkLoggedInIf(doCheck: boolean) { - if (doCheck) { - await this.checkLoggedIn(); - } - } - - /** - * Throw NotAvailableInOfflineModeError if in offline mode. - * - * Called automatically if `onlineOnly=true`. - * Can be called explicitly by command implementation, if e.g.: - * - check should only be done conditionally - * - other code needs to execute before check - * - * Note, currently public to allow use outside of derived commands - * (as some command implementations require this. Can be made protected - * if this changes). - * - * @throws {NotAvailableInOfflineModeError} - */ - public static checkNotUsingOfflineMode() { - if (process.env.BALENARC_OFFLINE_MODE) { - throw new NotAvailableInOfflineModeError(stripIndent` - This command requires an internet connection, and cannot be used in offline mode. - To leave offline mode, unset the BALENARC_OFFLINE_MODE environment variable. - `); - } - } - - /** - * Read stdin contents and make available to command. - * - * This approach could be improved in the future to automatically set argument - * values from stdin based in configuration, minimising command implementation. - */ - protected async getStdin() { - this.stdin = await (await import('get-stdin'))(); - } - - /** - * Get a logger instance. - */ - protected static async getLogger() { - return (await import('./utils/logger')).getLogger(); - } - - protected async init() { - const ctr = this.constructor as typeof BalenaCommand; - - if (ctr.root) { - await BalenaCommand.checkElevatedPrivileges(); - } - - if (ctr.authenticated) { - await BalenaCommand.checkLoggedIn(); - } - - if (!ctr.offlineCompatible) { - BalenaCommand.checkNotUsingOfflineMode(); - } - - if (ctr.readStdin) { - await this.getStdin(); - } - } -} diff --git a/src/commands/api-key/generate.ts b/src/commands/api-key/generate.ts index 58cd0608..e869358d 100644 --- a/src/commands/api-key/generate.ts +++ b/src/commands/api-key/generate.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/api-key/revoke.ts b/src/commands/api-key/revoke.ts index 2b158e7a..a8c4756b 100644 --- a/src/commands/api-key/revoke.ts +++ b/src/commands/api-key/revoke.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/api-keys/index.ts b/src/commands/api-keys/index.ts index 498ceaf6..560c83fb 100644 --- a/src/commands/api-keys/index.ts +++ b/src/commands/api-keys/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/app/create.ts b/src/commands/app/create.ts index 5f333a92..c6f4a21c 100644 --- a/src/commands/app/create.ts +++ b/src/commands/app/create.ts @@ -15,9 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; - -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { stripIndent } from '../../utils/lazy'; diff --git a/src/commands/block/create.ts b/src/commands/block/create.ts index 47ce1959..dc2768c7 100644 --- a/src/commands/block/create.ts +++ b/src/commands/block/create.ts @@ -15,9 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; - -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { stripIndent } from '../../utils/lazy'; diff --git a/src/commands/build/index.ts b/src/commands/build/index.ts index 08db04af..fd0c9940 100644 --- a/src/commands/build/index.ts +++ b/src/commands/build/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args, Flags } from '@oclif/core'; -import Command from '../../command'; +import { Args, Flags, Command } from '@oclif/core'; import { getBalenaSdk } from '../../utils/lazy'; import * as cf from '../../utils/common-flags'; import * as compose from '../../utils/compose'; @@ -106,13 +105,16 @@ ${dockerignoreHelp} public async run() { const { args: params, flags: options } = await this.parse(BuildCmd); - await Command.checkLoggedInIf(!!options.fleet); + const Logger = await import('../../utils/logger'); + const { checkLoggedInIf } = await import('../../utils/patterns'); + + await checkLoggedInIf(!!options.fleet); (await import('events')).defaultMaxListeners = 1000; const sdk = getBalenaSdk(); - const logger = await Command.getLogger(); + const logger = Logger.getLogger(); logger.logDebug('Parsing input...'); // `build` accepts `source` as a parameter, but compose expects it as an option diff --git a/src/commands/config/generate.ts b/src/commands/config/generate.ts index 25f7d7cd..7bb6b4a6 100644 --- a/src/commands/config/generate.ts +++ b/src/commands/config/generate.ts @@ -15,9 +15,8 @@ * limitations under the License. */ -import { Flags } from '@oclif/core'; +import { Flags, Command } from '@oclif/core'; import type { Interfaces } from '@oclif/core'; -import Command from '../../command'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getCliForm, stripIndent } from '../../utils/lazy'; import { diff --git a/src/commands/config/inject.ts b/src/commands/config/inject.ts index 9640776e..f34e71d0 100644 --- a/src/commands/config/inject.ts +++ b/src/commands/config/inject.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/config/read.ts b/src/commands/config/read.ts index 32fdf9ee..d32b511d 100644 --- a/src/commands/config/read.ts +++ b/src/commands/config/read.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/config/reconfigure.ts b/src/commands/config/reconfigure.ts index d00e7005..24003f8e 100644 --- a/src/commands/config/reconfigure.ts +++ b/src/commands/config/reconfigure.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/config/write.ts b/src/commands/config/write.ts index 8147169f..34cd3b8b 100644 --- a/src/commands/config/write.ts +++ b/src/commands/config/write.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/deploy/index.ts b/src/commands/deploy/index.ts index cf00b220..1e87ad74 100644 --- a/src/commands/deploy/index.ts +++ b/src/commands/deploy/index.ts @@ -15,10 +15,8 @@ * limitations under the License. */ -import { Args, Flags } from '@oclif/core'; +import { Args, Flags, Command } from '@oclif/core'; import type { ImageDescriptor } from '@balena/compose/dist/parse'; - -import Command from '../../command'; import { ExpectedError } from '../../errors'; import { getBalenaSdk, getChalk, stripIndent } from '../../utils/lazy'; import { @@ -155,7 +153,9 @@ ${dockerignoreHelp} (await import('events')).defaultMaxListeners = 1000; - const logger = await Command.getLogger(); + const Logger = await import('../../utils/logger'); + + const logger = Logger.getLogger(); logger.logDebug('Parsing input...'); const { fleet, image } = params; diff --git a/src/commands/device/deactivate.ts b/src/commands/device/deactivate.ts index 52c9ff8c..e8e50611 100644 --- a/src/commands/device/deactivate.ts +++ b/src/commands/device/deactivate.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/identify.ts b/src/commands/device/identify.ts index 93b7e74d..57bef0af 100644 --- a/src/commands/device/identify.ts +++ b/src/commands/device/identify.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { ExpectedError } from '../../errors'; diff --git a/src/commands/device/index.ts b/src/commands/device/index.ts index a9428c64..86e2c0a0 100644 --- a/src/commands/device/index.ts +++ b/src/commands/device/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { expandForAppName } from '../../utils/helpers'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/init.ts b/src/commands/device/init.ts index 41edcb04..c48f4559 100644 --- a/src/commands/device/init.ts +++ b/src/commands/device/init.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { applicationIdInfo } from '../../utils/messages'; @@ -117,8 +116,9 @@ export default class DeviceInitCmd extends Command { tmp.setGracefulCleanup(); const { downloadOSImage } = await import('../../utils/cloud'); const { getApplication } = await import('../../utils/sdk'); + const Logger = await import('../../utils/logger'); - const logger = await Command.getLogger(); + const logger = Logger.getLogger(); const balena = getBalenaSdk(); // Get application and diff --git a/src/commands/device/list.ts b/src/commands/device/list.ts index 66592a65..ce492a0a 100644 --- a/src/commands/device/list.ts +++ b/src/commands/device/list.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { expandForAppName } from '../../utils/helpers'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/local-mode.ts b/src/commands/device/local-mode.ts index aa7be85a..e26ae15d 100644 --- a/src/commands/device/local-mode.ts +++ b/src/commands/device/local-mode.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/move.ts b/src/commands/device/move.ts index 59fbd63f..93393b32 100644 --- a/src/commands/device/move.ts +++ b/src/commands/device/move.ts @@ -15,14 +15,13 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; +import { Args, Command } from '@oclif/core'; import type { BalenaSDK, Device, PineOptions, PineTypedResult, } from 'balena-sdk'; -import Command from '../../command'; import * as cf from '../../utils/common-flags'; import { ExpectedError } from '../../errors'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/os-update.ts b/src/commands/device/os-update.ts index e335d151..665c5d87 100644 --- a/src/commands/device/os-update.ts +++ b/src/commands/device/os-update.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; import type { Device } from 'balena-sdk'; diff --git a/src/commands/device/pin.ts b/src/commands/device/pin.ts index e27b294b..9e4382c4 100644 --- a/src/commands/device/pin.ts +++ b/src/commands/device/pin.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { getExpandedProp } from '../../utils/pine'; diff --git a/src/commands/device/public-url.ts b/src/commands/device/public-url.ts index 91fd9314..c1ff9bb5 100644 --- a/src/commands/device/public-url.ts +++ b/src/commands/device/public-url.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/purge.ts b/src/commands/device/purge.ts index 7c548406..00bd54d0 100644 --- a/src/commands/device/purge.ts +++ b/src/commands/device/purge.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/reboot.ts b/src/commands/device/reboot.ts index 1c4e5231..2a7e0e90 100644 --- a/src/commands/device/reboot.ts +++ b/src/commands/device/reboot.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/register.ts b/src/commands/device/register.ts index 6bfe5829..de756408 100644 --- a/src/commands/device/register.ts +++ b/src/commands/device/register.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import * as ca from '../../utils/common-args'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/rename.ts b/src/commands/device/rename.ts index 9f0b12cf..0f56b8d4 100644 --- a/src/commands/device/rename.ts +++ b/src/commands/device/rename.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; diff --git a/src/commands/device/restart.ts b/src/commands/device/restart.ts index b5fb5eef..92d1d90d 100644 --- a/src/commands/device/restart.ts +++ b/src/commands/device/restart.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; import type { diff --git a/src/commands/device/rm.ts b/src/commands/device/rm.ts index e7cb221d..1ce7434d 100644 --- a/src/commands/device/rm.ts +++ b/src/commands/device/rm.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/device/shutdown.ts b/src/commands/device/shutdown.ts index 8b9eeef6..79b1974e 100644 --- a/src/commands/device/shutdown.ts +++ b/src/commands/device/shutdown.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { ExpectedError } from '../../errors'; diff --git a/src/commands/device/start-service.ts b/src/commands/device/start-service.ts index 27c80727..5749c2a2 100644 --- a/src/commands/device/start-service.ts +++ b/src/commands/device/start-service.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; import type { BalenaSDK } from 'balena-sdk'; diff --git a/src/commands/device/stop-service.ts b/src/commands/device/stop-service.ts index e7900b6a..652d1ec4 100644 --- a/src/commands/device/stop-service.ts +++ b/src/commands/device/stop-service.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; import type { BalenaSDK } from 'balena-sdk'; diff --git a/src/commands/device/track-fleet.ts b/src/commands/device/track-fleet.ts index e5f35a32..cbf976b2 100644 --- a/src/commands/device/track-fleet.ts +++ b/src/commands/device/track-fleet.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/devices/supported.ts b/src/commands/devices/supported.ts index 9a96f427..964d5b35 100644 --- a/src/commands/devices/supported.ts +++ b/src/commands/devices/supported.ts @@ -14,11 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Flags } from '@oclif/core'; +import { Flags, Command } from '@oclif/core'; import type * as BalenaSdk from 'balena-sdk'; import * as _ from 'lodash'; -import Command from '../../command'; - import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/env/add.ts b/src/commands/env/add.ts index fc99a309..8c6fccba 100644 --- a/src/commands/env/add.ts +++ b/src/commands/env/add.ts @@ -15,9 +15,8 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; +import { Args, Command } from '@oclif/core'; import type * as BalenaSdk from 'balena-sdk'; -import Command from '../../command'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; @@ -111,7 +110,9 @@ export default class EnvAddCmd extends Command { ); } - await Command.checkLoggedIn(); + const { checkLoggedIn } = await import('../../utils/patterns'); + + await checkLoggedIn(); if (params.value == null) { params.value = process.env[params.name]; diff --git a/src/commands/env/rename.ts b/src/commands/env/rename.ts index 11ae1ea0..dcdd59f4 100644 --- a/src/commands/env/rename.ts +++ b/src/commands/env/rename.ts @@ -14,9 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; - +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import * as ec from '../../utils/env-common'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; @@ -63,7 +61,9 @@ export default class EnvRenameCmd extends Command { public async run() { const { args: params, flags: opt } = await this.parse(EnvRenameCmd); - await Command.checkLoggedIn(); + const { checkLoggedIn } = await import('../../utils/patterns'); + + await checkLoggedIn(); await getBalenaSdk().pine.patch({ resource: ec.getVarResourceName(opt.config, opt.device, opt.service), diff --git a/src/commands/env/rm.ts b/src/commands/env/rm.ts index 39538d55..afe03928 100644 --- a/src/commands/env/rm.ts +++ b/src/commands/env/rm.ts @@ -15,9 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; - +import { Flags, Args, Command } from '@oclif/core'; import * as ec from '../../utils/env-common'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { parseAsInteger } from '../../utils/validation'; @@ -67,7 +65,9 @@ export default class EnvRmCmd extends Command { public async run() { const { args: params, flags: opt } = await this.parse(EnvRmCmd); - await Command.checkLoggedIn(); + const { checkLoggedIn } = await import('../../utils/patterns'); + + await checkLoggedIn(); const { confirm } = await import('../../utils/patterns'); await confirm( diff --git a/src/commands/envs/index.ts b/src/commands/envs/index.ts index 553189d3..6d0802f1 100644 --- a/src/commands/envs/index.ts +++ b/src/commands/envs/index.ts @@ -14,11 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Flags } from '@oclif/core'; +import { Flags, Command } from '@oclif/core'; import type { Interfaces } from '@oclif/core'; import type * as SDK from 'balena-sdk'; import * as _ from 'lodash'; -import Command from '../../command'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; @@ -113,7 +112,9 @@ export default class EnvsCmd extends Command { const variables: EnvironmentVariableInfo[] = []; - await Command.checkLoggedIn(); + const { checkLoggedIn } = await import('../../utils/patterns'); + + await checkLoggedIn(); if (!options.fleet && !options.device) { throw new ExpectedError('Missing --fleet or --device option'); diff --git a/src/commands/fleet/create.ts b/src/commands/fleet/create.ts index 46e958ad..da773dec 100644 --- a/src/commands/fleet/create.ts +++ b/src/commands/fleet/create.ts @@ -15,9 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; - -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { stripIndent } from '../../utils/lazy'; diff --git a/src/commands/fleet/index.ts b/src/commands/fleet/index.ts index 7c382550..ebba3444 100644 --- a/src/commands/fleet/index.ts +++ b/src/commands/fleet/index.ts @@ -15,9 +15,7 @@ * limitations under the License. */ -import { Flags } from '@oclif/core'; - -import Command from '../../command'; +import { Flags, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import * as ca from '../../utils/common-args'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/fleet/pin.ts b/src/commands/fleet/pin.ts index bcbfdc8a..3d6df74d 100644 --- a/src/commands/fleet/pin.ts +++ b/src/commands/fleet/pin.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { getExpandedProp } from '../../utils/pine'; diff --git a/src/commands/fleet/purge.ts b/src/commands/fleet/purge.ts index 386d0aab..a6601ff1 100644 --- a/src/commands/fleet/purge.ts +++ b/src/commands/fleet/purge.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import * as ca from '../../utils/common-args'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/fleet/rename.ts b/src/commands/fleet/rename.ts index a2b09196..cd99434c 100644 --- a/src/commands/fleet/rename.ts +++ b/src/commands/fleet/rename.ts @@ -15,9 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; - -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import * as ca from '../../utils/common-args'; import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; diff --git a/src/commands/fleet/restart.ts b/src/commands/fleet/restart.ts index 83d560c6..e81067b0 100644 --- a/src/commands/fleet/restart.ts +++ b/src/commands/fleet/restart.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import * as ca from '../../utils/common-args'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/fleet/rm.ts b/src/commands/fleet/rm.ts index e81168b2..c115f67f 100644 --- a/src/commands/fleet/rm.ts +++ b/src/commands/fleet/rm.ts @@ -15,11 +15,11 @@ * limitations under the License. */ -import Command from '../../command'; import * as cf from '../../utils/common-flags'; import * as ca from '../../utils/common-args'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { applicationIdInfo } from '../../utils/messages'; +import { Command } from '@oclif/core'; export default class FleetRmCmd extends Command { public static description = stripIndent` diff --git a/src/commands/fleet/track-latest.ts b/src/commands/fleet/track-latest.ts index 75fee330..588592ee 100644 --- a/src/commands/fleet/track-latest.ts +++ b/src/commands/fleet/track-latest.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/fleets/index.ts b/src/commands/fleets/index.ts index 91b2fba6..c895a956 100644 --- a/src/commands/fleets/index.ts +++ b/src/commands/fleets/index.ts @@ -16,10 +16,9 @@ */ import type * as BalenaSdk from 'balena-sdk'; - -import Command from '../../command'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; +import { Command } from '@oclif/core'; interface ExtendedApplication extends ApplicationWithDeviceTypeSlug { device_count: number; diff --git a/src/commands/internal/osinit.ts b/src/commands/internal/osinit.ts index dfc9bc9a..4a420ae8 100644 --- a/src/commands/internal/osinit.ts +++ b/src/commands/internal/osinit.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import { stripIndent } from '../../utils/lazy'; // 'Internal' commands are called during the execution of other commands. diff --git a/src/commands/join/index.ts b/src/commands/join/index.ts index af09affc..2e3ccc7f 100644 --- a/src/commands/join/index.ts +++ b/src/commands/join/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args, Flags } from '@oclif/core'; -import Command from '../../command'; +import { Args, Flags, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { applicationIdInfo } from '../../utils/messages'; @@ -77,7 +76,8 @@ export default class JoinCmd extends Command { const promote = await import('../../utils/promote'); const sdk = getBalenaSdk(); - const logger = await Command.getLogger(); + const Logger = await import('../../utils/logger'); + const logger = Logger.getLogger(); return promote.join( logger, sdk, diff --git a/src/commands/key/add.ts b/src/commands/key/add.ts index 24e4d4fb..51e075d4 100644 --- a/src/commands/key/add.ts +++ b/src/commands/key/add.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; @@ -67,8 +66,6 @@ export default class KeyAddCmd extends Command { public static authenticated = true; - public static readStdin = true; - public async run() { const { args: params } = await this.parse(KeyAddCmd); @@ -76,8 +73,6 @@ export default class KeyAddCmd extends Command { if (params.path != null) { const { readFile } = (await import('fs')).promises; key = await readFile(params.path, 'utf8'); - } else if (this.stdin.length > 0) { - key = this.stdin; } else { throw new ExpectedError('No public key file or path provided.'); } diff --git a/src/commands/key/index.ts b/src/commands/key/index.ts index fa343133..ebe90ef2 100644 --- a/src/commands/key/index.ts +++ b/src/commands/key/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; import { parseAsInteger } from '../../utils/validation'; diff --git a/src/commands/key/rm.ts b/src/commands/key/rm.ts index aecad823..b6f31712 100644 --- a/src/commands/key/rm.ts +++ b/src/commands/key/rm.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { parseAsInteger } from '../../utils/validation'; diff --git a/src/commands/keys/index.ts b/src/commands/keys/index.ts index af77abfb..800aa6ff 100644 --- a/src/commands/keys/index.ts +++ b/src/commands/keys/index.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/leave/index.ts b/src/commands/leave/index.ts index a94d9a77..9ff81399 100644 --- a/src/commands/leave/index.ts +++ b/src/commands/leave/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { stripIndent } from '../../utils/lazy'; import { parseAsLocalHostnameOrIp } from '../../utils/validation'; @@ -61,7 +60,8 @@ export default class LeaveCmd extends Command { const { args: params } = await this.parse(LeaveCmd); const promote = await import('../../utils/promote'); - const logger = await Command.getLogger(); + const Logger = await import('../../utils/logger'); + const logger = Logger.getLogger(); return promote.leave(logger, params.deviceIpOrHostname); } } diff --git a/src/commands/local/configure.ts b/src/commands/local/configure.ts index 0aace8f2..7e72fb60 100644 --- a/src/commands/local/configure.ts +++ b/src/commands/local/configure.ts @@ -15,9 +15,8 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; +import { Args, Command } from '@oclif/core'; import { promisify } from 'util'; -import Command from '../../command'; import * as cf from '../../utils/common-flags'; import { stripIndent } from '../../utils/lazy'; diff --git a/src/commands/local/flash.ts b/src/commands/local/flash.ts index 1e6b137d..592e0993 100644 --- a/src/commands/local/flash.ts +++ b/src/commands/local/flash.ts @@ -15,9 +15,8 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; +import { Args, Command } from '@oclif/core'; import type { BlockDevice } from 'etcher-sdk/build/source-destination'; -import Command from '../../command'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getChalk, getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/login/index.ts b/src/commands/login/index.ts index 653836c5..7fb7de77 100644 --- a/src/commands/login/index.ts +++ b/src/commands/login/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; import { ExpectedError } from '../../errors'; diff --git a/src/commands/logout/index.ts b/src/commands/logout/index.ts index ff14cb9c..313db52f 100644 --- a/src/commands/logout/index.ts +++ b/src/commands/logout/index.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; export default class LogoutCmd extends Command { diff --git a/src/commands/logs/index.ts b/src/commands/logs/index.ts index 7a6f9056..8c3cbf22 100644 --- a/src/commands/logs/index.ts +++ b/src/commands/logs/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import type { LogMessage } from 'balena-sdk'; @@ -151,8 +150,9 @@ export default class LogsCmd extends Command { maxAttempts: 1 + (options['max-retry'] ?? MAX_RETRY), }); } else { + const { checkLoggedIn } = await import('../../utils/patterns'); // Logs from cloud - await Command.checkLoggedIn(); + await checkLoggedIn(); if (options.tail) { const logStream = await balena.logs.subscribe(params.device, { count: 100, diff --git a/src/commands/notes/index.ts b/src/commands/notes/index.ts index 6cf6de27..d27654ca 100644 --- a/src/commands/notes/index.ts +++ b/src/commands/notes/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; @@ -53,14 +52,10 @@ export default class NoteCmd extends Command { public static authenticated = true; - public static readStdin = true; - public async run() { const { args: params, flags: options } = await this.parse(NoteCmd); - params.note = params.note || this.stdin; - - if (params.note.length === 0) { + if (params.note?.length === 0) { throw new ExpectedError('Missing note content'); } @@ -73,6 +68,6 @@ export default class NoteCmd extends Command { const balena = getBalenaSdk(); - return balena.models.device.setNote(options.device, params.note); + return balena.models.device.setNote(options.device, params.note ?? ''); } } diff --git a/src/commands/orgs/index.ts b/src/commands/orgs/index.ts index 62ec99cf..bd210d5b 100644 --- a/src/commands/orgs/index.ts +++ b/src/commands/orgs/index.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/os/build-config.ts b/src/commands/os/build-config.ts index 0e88a58d..caac821a 100644 --- a/src/commands/os/build-config.ts +++ b/src/commands/os/build-config.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getCliForm, stripIndent } from '../../utils/lazy'; import * as _ from 'lodash'; diff --git a/src/commands/os/configure.ts b/src/commands/os/configure.ts index 1fd978cb..cb9669ef 100644 --- a/src/commands/os/configure.ts +++ b/src/commands/os/configure.ts @@ -15,12 +15,11 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; +import { Flags, Args, Command } from '@oclif/core'; import type { Interfaces } from '@oclif/core'; import type * as BalenaSdk from 'balena-sdk'; import { promisify } from 'util'; import * as _ from 'lodash'; -import Command from '../../command'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; @@ -319,7 +318,9 @@ async function validateOptions(options: FlagsDef) { ); } - await Command.checkLoggedIn(); + const { checkLoggedIn } = await import('../../utils/patterns'); + + await checkLoggedIn(); } /** diff --git a/src/commands/os/download.ts b/src/commands/os/download.ts index 9c902cca..122d479d 100644 --- a/src/commands/os/download.ts +++ b/src/commands/os/download.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { stripIndent } from '../../utils/lazy'; @@ -90,7 +89,8 @@ export default class OsDownloadCmd extends Command { const { isESR } = await import('../../utils/image-manager'); if (options.version === 'menu-esr' || isESR(options.version)) { try { - await OsDownloadCmd.checkLoggedIn(); + const { checkLoggedIn } = await import('../../utils/patterns'); + await checkLoggedIn(); } catch (e) { const { ExpectedError, NotLoggedInError } = await import( '../../errors' diff --git a/src/commands/os/initialize.ts b/src/commands/os/initialize.ts index 8e815e59..76c5063f 100644 --- a/src/commands/os/initialize.ts +++ b/src/commands/os/initialize.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getCliForm, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/os/versions.ts b/src/commands/os/versions.ts index 7b813b78..60ec4936 100644 --- a/src/commands/os/versions.ts +++ b/src/commands/os/versions.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { stripIndent } from '../../utils/lazy'; diff --git a/src/commands/preload/index.ts b/src/commands/preload/index.ts index 74d27ac8..cad1c732 100644 --- a/src/commands/preload/index.ts +++ b/src/commands/preload/index.ts @@ -15,7 +15,6 @@ * limitations under the License. */ -import Command from '../../command'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { @@ -27,8 +26,7 @@ import { import { applicationIdInfo } from '../../utils/messages'; import { dockerConnectionCliFlags } from '../../utils/docker'; import { parseAsInteger } from '../../utils/validation'; - -import { Flags, Args } from '@oclif/core'; +import { Flags, Args, Command } from '@oclif/core'; import * as _ from 'lodash'; import type { Application, diff --git a/src/commands/push/index.ts b/src/commands/push/index.ts index a1a10521..520c2511 100644 --- a/src/commands/push/index.ts +++ b/src/commands/push/index.ts @@ -15,9 +15,8 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; +import { Flags, Args, Command } from '@oclif/core'; import type { Interfaces } from '@oclif/core'; -import Command from '../../command'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { dockerignoreHelp, registrySecretsHelp } from '../../utils/messages'; @@ -227,7 +226,9 @@ export default class PushCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(PushCmd); - const logger = await Command.getLogger(); + const Logger = await import('../../utils/logger'); + + const logger = Logger.getLogger(); logger.logDebug(`Using build source directory: ${options.source} `); const sdk = getBalenaSdk(); @@ -294,7 +295,9 @@ export default class PushCmd extends Command { options['release-tag'] ?? [], ); - await Command.checkLoggedIn(); + const { checkLoggedIn } = await import('../../utils/patterns'); + + await checkLoggedIn(); const [token, baseUrl] = await Promise.all([ sdk.auth.getToken(), sdk.settings.get('balenaUrl'), diff --git a/src/commands/release/finalize.ts b/src/commands/release/finalize.ts index bcae1b6b..e1f6c229 100644 --- a/src/commands/release/finalize.ts +++ b/src/commands/release/finalize.ts @@ -15,8 +15,8 @@ * limitations under the License. */ +import { Command } from '@oclif/core'; import { commitOrIdArg } from '.'; -import Command from '../../command'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/release/index.ts b/src/commands/release/index.ts index 9f0a6960..1b9db22e 100644 --- a/src/commands/release/index.ts +++ b/src/commands/release/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args, type Interfaces } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, type Interfaces, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; import type * as BalenaSdk from 'balena-sdk'; diff --git a/src/commands/release/invalidate.ts b/src/commands/release/invalidate.ts index b4c68070..26cfee60 100644 --- a/src/commands/release/invalidate.ts +++ b/src/commands/release/invalidate.ts @@ -15,8 +15,8 @@ * limitations under the License. */ +import { Command } from '@oclif/core'; import { commitOrIdArg } from '.'; -import Command from '../../command'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/release/validate.ts b/src/commands/release/validate.ts index eca3ce68..83c269da 100644 --- a/src/commands/release/validate.ts +++ b/src/commands/release/validate.ts @@ -15,8 +15,8 @@ * limitations under the License. */ +import { Command } from '@oclif/core'; import { commitOrIdArg } from '.'; -import Command from '../../command'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/releases/index.ts b/src/commands/releases/index.ts index c5510113..09d049e5 100644 --- a/src/commands/releases/index.ts +++ b/src/commands/releases/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; import { applicationNameNote } from '../../utils/messages'; diff --git a/src/commands/scan/index.ts b/src/commands/scan/index.ts index dbe68a14..ec170e3c 100644 --- a/src/commands/scan/index.ts +++ b/src/commands/scan/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getCliUx, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/settings/index.ts b/src/commands/settings/index.ts index 71d3d116..f5ca58f0 100644 --- a/src/commands/settings/index.ts +++ b/src/commands/settings/index.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/ssh/index.ts b/src/commands/ssh/index.ts index f44e2ee6..9c990da5 100644 --- a/src/commands/ssh/index.ts +++ b/src/commands/ssh/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { @@ -121,15 +120,19 @@ export default class SshCmd extends Command { // Remote connection const { getProxyConfig } = await import('../../utils/helpers'); - const { getOnlineTargetDeviceUuid } = await import('../../utils/patterns'); + const { + getOnlineTargetDeviceUuid, + checkLoggedIn, + checkNotUsingOfflineMode, + } = await import('../../utils/patterns'); const sdk = getBalenaSdk(); const proxyConfig = getProxyConfig(); const useProxy = !!proxyConfig && !options.noproxy; // this will be a tunnelled SSH connection... - await Command.checkNotUsingOfflineMode(); - await Command.checkLoggedIn(); + await checkNotUsingOfflineMode(); + await checkLoggedIn(); const deviceUuid = await getOnlineTargetDeviceUuid( sdk, params.fleetOrDevice, diff --git a/src/commands/support/index.ts b/src/commands/support/index.ts index 58550cb2..50d4e420 100644 --- a/src/commands/support/index.ts +++ b/src/commands/support/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/tag/rm.ts b/src/commands/tag/rm.ts index b3cf0aa7..3c1585cc 100644 --- a/src/commands/tag/rm.ts +++ b/src/commands/tag/rm.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { applicationIdInfo } from '../../utils/messages'; diff --git a/src/commands/tag/set.ts b/src/commands/tag/set.ts index 306e90de..60575a32 100644 --- a/src/commands/tag/set.ts +++ b/src/commands/tag/set.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Args } from '@oclif/core'; -import Command from '../../command'; +import { Args, Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, stripIndent } from '../../utils/lazy'; import { applicationIdInfo } from '../../utils/messages'; diff --git a/src/commands/tags/index.ts b/src/commands/tags/index.ts index cb13e7cc..79b90229 100644 --- a/src/commands/tags/index.ts +++ b/src/commands/tags/index.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import { ExpectedError } from '../../errors'; import * as cf from '../../utils/common-flags'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; diff --git a/src/commands/tunnel/index.ts b/src/commands/tunnel/index.ts index 299943a7..fe8556e8 100644 --- a/src/commands/tunnel/index.ts +++ b/src/commands/tunnel/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Args, Command } from '@oclif/core'; import { NoPortsDefinedError, InvalidPortMappingError, @@ -94,7 +93,9 @@ export default class TunnelCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(TunnelCmd); - const logger = await Command.getLogger(); + const Logger = await import('../../utils/logger'); + + const logger = Logger.getLogger(); const sdk = getBalenaSdk(); const logConnection = ( diff --git a/src/commands/util/available-drives.ts b/src/commands/util/available-drives.ts index 705e157e..3de865cf 100644 --- a/src/commands/util/available-drives.ts +++ b/src/commands/util/available-drives.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import * as cf from '../../utils/common-flags'; import { stripIndent, getChalk, getVisuals } from '../../utils/lazy'; diff --git a/src/commands/version/index.ts b/src/commands/version/index.ts index 9e1c3c86..c7f5919c 100644 --- a/src/commands/version/index.ts +++ b/src/commands/version/index.ts @@ -15,8 +15,7 @@ * limitations under the License. */ -import { Flags } from '@oclif/core'; -import Command from '../../command'; +import { Flags, Command } from '@oclif/core'; import { stripIndent } from '../../utils/lazy'; export interface JsonVersions { diff --git a/src/commands/whoami/index.ts b/src/commands/whoami/index.ts index 7c01b0f2..19ff60e5 100644 --- a/src/commands/whoami/index.ts +++ b/src/commands/whoami/index.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import Command from '../../command'; +import { Command } from '@oclif/core'; import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; export default class WhoamiCmd extends Command { diff --git a/src/hooks/prerun.ts b/src/hooks/prerun.ts new file mode 100644 index 00000000..3e3e1d47 --- /dev/null +++ b/src/hooks/prerun.ts @@ -0,0 +1,119 @@ +/** + * @license + * Copyright 2020 Balena Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + type Hook, + type Command, + // ux +} from '@oclif/core'; +import { InsufficientPrivilegesError } from '../errors'; +import { checkLoggedIn, checkNotUsingOfflineMode } from '../utils/patterns'; + +let trackResolve: (result: Promise<any>) => void; + +// note: trackPromise is subject to a Bluebird.timeout, defined in events.ts +export const trackPromise = new Promise((resolve) => { + trackResolve = resolve; +}); + +/** + * Throw InsufficientPrivilegesError if not root on Mac/Linux + * or non-Administrator on Windows. + * + * Called automatically if `root=true`. + * Can be called explicitly by command implementation, if e.g.: + * - check should only be done conditionally + * - other code needs to execute before check + */ +const checkElevatedPrivileges = async () => { + const isElevated = await (await import('is-elevated'))(); + if (!isElevated) { + throw new InsufficientPrivilegesError( + 'You need root/admin privileges to run this command', + ); + } +}; + +/** + * Require elevated privileges to run. + * When set to true, command will exit with an error + * if executed without root on Mac/Linux + * or if executed by non-Administrator on Windows. + */ +const DEFAULT_ROOT = false; + +/** + * Require authentication to run. + * When set to true, command will exit with an error + * if user is not already logged in. + */ +const DEFAULT_AUTHENTICATED = false; + +/** + * Require an internet connection to run. + * When set to true, command will exit with an error + * if user is running in offline mode (BALENARC_OFFLINE_MODE). + */ +const DEFAULT_OFFLINE_COMPATIBLE = false; + +/** + * This is an oclif 'prerun' hook. This hook runs after the command line is + * parsed by oclif, but before the command's run() function is called. + * See: https://oclif.io/docs/hooks + * + * This hook is used to track CLI command signatures (usage analytics). + * A command signature is something like "env add NAME [VALUE]". That's + * literally so: 'NAME' and 'VALUE' are NOT replaced with actual values. + */ + +const hook: Hook<'prerun'> = async function (options) { + try { + if ( + (options.Command as Command.Class & { root: boolean }).root ?? + DEFAULT_ROOT + ) { + await checkElevatedPrivileges(); + } + + if ( + (options.Command as Command.Class & { authenticated: boolean }) + .authenticated ?? + DEFAULT_AUTHENTICATED + ) { + await checkLoggedIn(); + } + + if ( + !( + (options.Command as Command.Class & { offlineCompatible: boolean }) + .offlineCompatible ?? DEFAULT_OFFLINE_COMPATIBLE + ) + ) { + await checkNotUsingOfflineMode(); + } + } catch (error) { + this.error(error); + } + const events = await import('../events'); + const cmd = options.Command.id; + + // Intentionally do not await for the track promise here, in order to + // run the command tracking and the command itself in parallel. + trackResolve(events.trackCommand(cmd)); +}; + +export default hook; diff --git a/src/hooks/prerun/track.ts b/src/hooks/prerun/track.ts deleted file mode 100644 index 24152a1b..00000000 --- a/src/hooks/prerun/track.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @license - * Copyright 2019-2020 Balena Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import type { Hook } from '@oclif/core'; - -let trackResolve: (result: Promise<any>) => void; - -// note: trackPromise is subject to a Bluebird.timeout, defined in events.ts -export const trackPromise = new Promise((resolve) => { - trackResolve = resolve; -}); - -/** - * This is an oclif 'prerun' hook. This hook runs after the command line is - * parsed by oclif, but before the command's run() function is called. - * See: https://oclif.io/docs/hooks - * - * This hook is used to track CLI command signatures (usage analytics). - * A command signature is something like "env add NAME [VALUE]". That's - * literally so: 'NAME' and 'VALUE' are NOT replaced with actual values. - */ -const hook: Hook<'prerun'> = async function (options) { - const events = await import('../../events'); - const cmd = options.Command.id; - - // Intentionally do not await for the track promise here, in order to - // run the command tracking and the command itself in parallel. - trackResolve(events.trackCommand(cmd)); -}; - -export default hook; diff --git a/src/utils/patterns.ts b/src/utils/patterns.ts index ebae0aa6..6dcbc516 100644 --- a/src/utils/patterns.ts +++ b/src/utils/patterns.ts @@ -24,7 +24,12 @@ import type { PineTypedResult, } from 'balena-sdk'; -import { instanceOf, NotLoggedInError, ExpectedError } from '../errors'; +import { + instanceOf, + NotLoggedInError, + ExpectedError, + NotAvailableInOfflineModeError, +} from '../errors'; import { getBalenaSdk, getVisuals, stripIndent, getCliForm } from './lazy'; import validation = require('./validation'); import { delay } from './helpers'; @@ -89,6 +94,41 @@ export async function checkLoggedIn(): Promise<void> { } } +/** + * Throw NotLoggedInError if not logged in when condition true. + * + * @param {boolean} doCheck - will check if true. + * @throws {NotLoggedInError} + */ +export const checkLoggedInIf = async (doCheck: boolean) => { + if (doCheck) { + await checkLoggedIn(); + } +}; + +/** + * Throw NotAvailableInOfflineModeError if in offline mode. + * + * Called automatically if `onlineOnly=true`. + * Can be called explicitly by command implementation, if e.g.: + * - check should only be done conditionally + * - other code needs to execute before check + * + * Note, currently public to allow use outside of derived commands + * (as some command implementations require this. Can be made protected + * if this changes). + * + * @throws {NotAvailableInOfflineModeError} + */ +export const checkNotUsingOfflineMode = async () => { + if (process.env.BALENARC_OFFLINE_MODE) { + throw new NotAvailableInOfflineModeError(stripIndent` + This command requires an internet connection, and cannot be used in offline mode. + To leave offline mode, unset the BALENARC_OFFLINE_MODE environment variable. + `); + } +}; + export function askLoginType() { return getCliForm().ask<'web' | 'credentials' | 'token' | 'register'>({ message: 'How would you like to login?', diff --git a/tests/test-data/pkg/expected-warnings-darwin-arm64.txt b/tests/test-data/pkg/expected-warnings-darwin-arm64.txt index 960b23f8..cc9ad867 100644 --- a/tests/test-data/pkg/expected-warnings-darwin-arm64.txt +++ b/tests/test-data/pkg/expected-warnings-darwin-arm64.txt @@ -4,9 +4,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/app.js -> Warning Entry 'main' not found in %1 - %1: node_modules/@oclif/core/package.json - %2: build/command.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/help.js @@ -55,6 +52,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/config/inject.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/config/read.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/config/reconfigure.js @@ -76,6 +76,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/init.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/device/list.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/local-mode.js @@ -145,12 +148,24 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/pin.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/purge.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/rename.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/restart.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/rm.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/track-latest.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleets/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/internal/osinit.js @@ -166,6 +181,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/key/rm.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/keys/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/leave/index.js @@ -178,12 +196,18 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/login/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/logout/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/logs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/notes/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/orgs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/os/build-config.js @@ -205,15 +229,27 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/push/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/finalize.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/release/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/invalidate.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/validate.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/releases/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/scan/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/settings/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/ssh/index.js @@ -226,12 +262,21 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/tag/set.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/tags/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/tunnel/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/util/available-drives.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/version/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/whoami/index.js > Warning Cannot include file %1 into executable. The file must be distributed with executable as %2. %1: node_modules/open/xdg-open diff --git a/tests/test-data/pkg/expected-warnings-darwin-x64.txt b/tests/test-data/pkg/expected-warnings-darwin-x64.txt index bab73f1c..fee5b5d2 100644 --- a/tests/test-data/pkg/expected-warnings-darwin-x64.txt +++ b/tests/test-data/pkg/expected-warnings-darwin-x64.txt @@ -4,9 +4,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/app.js -> Warning Entry 'main' not found in %1 - %1: node_modules/@oclif/core/package.json - %2: build/command.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/help.js @@ -55,6 +52,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/config/inject.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/config/read.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/config/reconfigure.js @@ -76,6 +76,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/init.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/device/list.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/local-mode.js @@ -145,12 +148,24 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/pin.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/purge.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/rename.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/restart.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/rm.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/track-latest.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleets/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/internal/osinit.js @@ -166,6 +181,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/key/rm.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/keys/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/leave/index.js @@ -178,12 +196,18 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/login/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/logout/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/logs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/notes/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/orgs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/os/build-config.js @@ -205,15 +229,27 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/push/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/finalize.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/release/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/invalidate.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/validate.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/releases/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/scan/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/settings/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/ssh/index.js @@ -226,12 +262,21 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/tag/set.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/tags/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/tunnel/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/util/available-drives.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/version/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/whoami/index.js > Warning Cannot include file %1 into executable. The file must be distributed with executable as %2. %1: node_modules/open/xdg-open diff --git a/tests/test-data/pkg/expected-warnings-linux-arm64.txt b/tests/test-data/pkg/expected-warnings-linux-arm64.txt index 67d1f968..cc9ad867 100644 --- a/tests/test-data/pkg/expected-warnings-linux-arm64.txt +++ b/tests/test-data/pkg/expected-warnings-linux-arm64.txt @@ -4,9 +4,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/app.js -> Warning Entry 'main' not found in %1 - %1: node_modules/@oclif/core/package.json - %2: build/command.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/help.js @@ -55,6 +52,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/config/inject.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/config/read.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/config/reconfigure.js @@ -76,6 +76,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/init.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/device/list.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/local-mode.js @@ -145,12 +148,24 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/pin.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/purge.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/rename.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/restart.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/rm.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/track-latest.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleets/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/internal/osinit.js @@ -166,6 +181,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/key/rm.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/keys/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/leave/index.js @@ -178,12 +196,18 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/login/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/logout/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/logs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/notes/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/orgs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/os/build-config.js @@ -205,15 +229,27 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/push/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/finalize.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/release/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/invalidate.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/validate.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/releases/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/scan/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/settings/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/ssh/index.js @@ -226,12 +262,21 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/tag/set.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/tags/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/tunnel/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/util/available-drives.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/version/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/whoami/index.js > Warning Cannot include file %1 into executable. The file must be distributed with executable as %2. %1: node_modules/open/xdg-open @@ -332,4 +377,4 @@ > Warning Failed to make bytecode node20-arm64 for file node_modules/@isaacs/cliui/node_modules/strip-ansi/index.js > Warning Failed to make bytecode node20-arm64 for file node_modules/@isaacs/cliui/node_modules/wrap-ansi/index.js > Warning Failed to make bytecode node20-arm64 for file node_modules/@isaacs/cliui/node_modules/ansi-regex/index.js -> Warning Failed to make bytecode node20-arm64 for file node_modules/@isaacs/cliui/node_modules/ansi-styles/index.js +> Warning Failed to make bytecode node20-arm64 for file node_modules/@isaacs/cliui/node_modules/ansi-styles/index.js \ No newline at end of file diff --git a/tests/test-data/pkg/expected-warnings-linux-x64.txt b/tests/test-data/pkg/expected-warnings-linux-x64.txt index fe0b5c76..fee5b5d2 100644 --- a/tests/test-data/pkg/expected-warnings-linux-x64.txt +++ b/tests/test-data/pkg/expected-warnings-linux-x64.txt @@ -4,9 +4,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/app.js -> Warning Entry 'main' not found in %1 - %1: node_modules/@oclif/core/package.json - %2: build/command.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/help.js @@ -55,6 +52,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/config/inject.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/config/read.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/config/reconfigure.js @@ -76,6 +76,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/init.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/device/list.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/device/local-mode.js @@ -145,12 +148,24 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/pin.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/purge.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/rename.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/restart.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleet/rm.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/fleet/track-latest.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/fleets/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/internal/osinit.js @@ -166,6 +181,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/key/rm.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/keys/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/leave/index.js @@ -178,12 +196,18 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/login/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/logout/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/logs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/notes/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/orgs/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/os/build-config.js @@ -205,15 +229,27 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/push/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/finalize.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/release/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/invalidate.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/release/validate.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/releases/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/scan/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/settings/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/ssh/index.js @@ -226,12 +262,21 @@ > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/tag/set.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/tags/index.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/tunnel/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/util/available-drives.js > Warning Entry 'main' not found in %1 %1: node_modules/@oclif/core/package.json %2: build/commands/version/index.js +> Warning Entry 'main' not found in %1 + %1: node_modules/@oclif/core/package.json + %2: build/commands/whoami/index.js > Warning Cannot include file %1 into executable. The file must be distributed with executable as %2. %1: node_modules/open/xdg-open @@ -332,4 +377,4 @@ > Warning Failed to make bytecode node20-x64 for file node_modules/@isaacs/cliui/node_modules/strip-ansi/index.js > Warning Failed to make bytecode node20-x64 for file node_modules/@isaacs/cliui/node_modules/wrap-ansi/index.js > Warning Failed to make bytecode node20-x64 for file node_modules/@isaacs/cliui/node_modules/ansi-regex/index.js -> Warning Failed to make bytecode node20-x64 for file node_modules/@isaacs/cliui/node_modules/ansi-styles/index.js +> Warning Failed to make bytecode node20-x64 for file node_modules/@isaacs/cliui/node_modules/ansi-styles/index.js \ No newline at end of file diff --git a/tests/test-data/pkg/expected-warnings-win32-x64.txt b/tests/test-data/pkg/expected-warnings-win32-x64.txt index 6804a059..ed6eba29 100644 --- a/tests/test-data/pkg/expected-warnings-win32-x64.txt +++ b/tests/test-data/pkg/expected-warnings-win32-x64.txt @@ -4,9 +4,6 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\app.js -> Warning Entry 'main' not found in %1 - %1: node_modules\@oclif\core\package.json - %2: build\command.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\help.js @@ -55,6 +52,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\config\inject.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\config\read.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\config\reconfigure.js @@ -76,6 +76,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\device\init.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\device\list.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\device\local-mode.js @@ -145,12 +148,24 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\fleet\pin.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\fleet\purge.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\fleet\rename.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\fleet\restart.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\fleet\rm.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\fleet\track-latest.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\fleets\index.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\internal\osinit.js @@ -166,6 +181,9 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\key\rm.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\keys\index.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\leave\index.js @@ -178,12 +196,18 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\login\index.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\logout\index.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\logs\index.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\notes\index.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\orgs\index.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\os\build-config.js @@ -205,15 +229,27 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\push\index.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\release\finalize.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\release\index.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\release\invalidate.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\release\validate.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\releases\index.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\scan\index.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\settings\index.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\ssh\index.js @@ -226,12 +262,21 @@ > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\tag\set.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\tags\index.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\tunnel\index.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\util\available-drives.js > Warning Entry 'main' not found in %1 %1: node_modules\@oclif\core\package.json %2: build\commands\version\index.js +> Warning Entry 'main' not found in %1 + %1: node_modules\@oclif\core\package.json + %2: build\commands\whoami\index.js > Warning Cannot include file %1 into executable. The file must be distributed with executable as %2. %1: node_modules\open\xdg-open