From 5e5b3a26356acbc3bba5b1ef76f0990d2f760531 Mon Sep 17 00:00:00 2001 From: Otavio Jacobi Date: Fri, 12 Jul 2024 22:25:40 -0300 Subject: [PATCH 1/3] WIP module node16 for ESM change-type: patch --- automation/build-bin.ts | 12 ++++----- automation/utils.ts | 2 +- lib/app.ts | 23 ++++++++-------- lib/auth/index.ts | 4 +-- lib/auth/server.ts | 2 +- lib/command.ts | 10 ++++--- lib/commands/api-keys/index.ts | 2 +- lib/commands/app/create.ts | 2 +- lib/commands/block/create.ts | 2 +- lib/commands/build/index.ts | 23 +++++++++++----- lib/commands/config/generate.ts | 18 ++++++------- lib/commands/config/inject.ts | 2 +- lib/commands/config/read.ts | 2 +- lib/commands/config/reconfigure.ts | 6 ++--- lib/commands/config/write.ts | 2 +- lib/commands/deploy/index.ts | 8 +++--- lib/commands/device/deactivate.ts | 2 +- lib/commands/device/index.ts | 2 +- lib/commands/device/init.ts | 8 +++--- lib/commands/device/move.ts | 4 +-- lib/commands/device/os-update.ts | 6 +++-- lib/commands/device/register.ts | 2 +- lib/commands/device/restart.ts | 6 ++--- lib/commands/device/rm.ts | 2 +- lib/commands/device/start-service.ts | 4 +-- lib/commands/device/stop-service.ts | 4 +-- lib/commands/devices/index.ts | 4 +-- lib/commands/env/add.ts | 4 +-- lib/commands/env/rm.ts | 2 +- lib/commands/envs/index.ts | 6 ++--- lib/commands/fleet/create.ts | 2 +- lib/commands/fleet/index.ts | 4 +-- lib/commands/fleet/purge.ts | 2 +- lib/commands/fleet/rename.ts | 8 +++--- lib/commands/fleet/restart.ts | 2 +- lib/commands/fleet/rm.ts | 4 +-- lib/commands/internal/osinit.ts | 2 +- lib/commands/join/index.ts | 2 +- lib/commands/key/rm.ts | 2 +- lib/commands/leave/index.ts | 2 +- lib/commands/local/configure.ts | 4 +-- lib/commands/local/flash.ts | 2 +- lib/commands/login/index.ts | 10 +++---- lib/commands/logs/index.ts | 12 ++++----- lib/commands/orgs/index.ts | 2 +- lib/commands/os/build-config.ts | 4 +-- lib/commands/os/configure.ts | 16 ++++++------ lib/commands/os/download.ts | 4 +-- lib/commands/os/initialize.ts | 8 +++--- lib/commands/os/versions.ts | 4 +-- lib/commands/preload/index.ts | 15 ++++++----- lib/commands/push/index.ts | 14 +++++----- lib/commands/releases/index.ts | 2 +- lib/commands/scan/index.ts | 4 +-- lib/commands/ssh/index.ts | 16 +++++++----- lib/commands/support/index.ts | 2 +- lib/commands/tag/rm.ts | 6 ++--- lib/commands/tag/set.ts | 6 ++--- lib/commands/tags/index.ts | 4 +-- lib/commands/tunnel/index.ts | 6 +++-- lib/commands/version/index.ts | 2 +- lib/deprecation.ts | 4 +-- lib/events.ts | 4 +-- lib/fast-boot.ts | 2 +- lib/help.ts | 2 +- lib/hooks/prerun/track.ts | 2 +- lib/preparser.ts | 4 +-- lib/utils/application-create.ts | 4 +-- lib/utils/bootstrap.ts | 2 +- lib/utils/cloud.ts | 2 +- lib/utils/compose.ts | 12 +++------ lib/utils/compose_ts.ts | 39 +++++++++++++++------------- lib/utils/config.ts | 8 +++--- lib/utils/device/api.ts | 2 +- lib/utils/device/deploy.ts | 6 ++--- lib/utils/device/live.ts | 4 +-- lib/utils/device/logs.ts | 4 +-- lib/utils/discover.ts | 2 +- lib/utils/docker.ts | 2 +- lib/utils/helpers.ts | 8 +++--- lib/utils/ignore.ts | 2 +- lib/utils/patterns.ts | 12 +++++---- lib/utils/promote.ts | 10 +++---- lib/utils/qemu.ts | 2 +- lib/utils/remote-build.ts | 2 +- lib/utils/sdk.ts | 4 +-- lib/utils/ssh.ts | 8 +++--- lib/utils/sudo.ts | 4 +-- lib/utils/umount.ts | 12 ++++----- lib/utils/update.ts | 2 +- lib/utils/which.ts | 4 +-- tests/auth/utils.spec.ts | 2 +- tests/commands/build.spec.ts | 2 +- tests/commands/ssh.spec.ts | 4 +-- tests/helpers.ts | 8 +++--- tests/nock/nock-mock.ts | 2 +- tests/utils/device/live.spec.ts | 4 +-- tests/utils/qemu.spec.ts | 2 +- tests/utils/update.spec.ts | 2 +- tsconfig.json | 4 +-- 100 files changed, 290 insertions(+), 264 deletions(-) diff --git a/automation/build-bin.ts b/automation/build-bin.ts index 520f5f394b..76fc8f81c7 100644 --- a/automation/build-bin.ts +++ b/automation/build-bin.ts @@ -18,15 +18,15 @@ import type { JsonVersions } from '../lib/commands/version/index'; import { run as oclifRun } from '@oclif/core'; -import * as archiver from 'archiver'; -import * as Bluebird from 'bluebird'; +import archiver from 'archiver'; +import Bluebird from 'bluebird'; import { exec, execFile } from 'child_process'; import * as filehound from 'filehound'; import type { Stats } from 'fs'; import * as fs from 'fs-extra'; -import * as klaw from 'klaw'; +import klaw from 'klaw'; import * as path from 'path'; -import * as rimraf from 'rimraf'; +import rimraf from 'rimraf'; import * as semver from 'semver'; import { promisify } from 'util'; import { notarize } from '@electron/notarize'; @@ -87,7 +87,7 @@ export const finalReleaseAssets: { [platform: string]: string[] } = { * Throw an error if the diff is not empty. */ async function diffPkgOutput(pkgOut: string) { - const { monochrome } = await import('../tests/helpers'); + const { monochrome } = await import('../tests/helpers.js'); const relSavedPath = path.join( 'tests', 'test-data', @@ -263,7 +263,7 @@ async function testPkg() { 'version', '-j', ]); - const { filterCliOutputForTests } = await import('../tests/helpers'); + const { filterCliOutputForTests } = await import('../tests/helpers.js'); const filtered = filterCliOutputForTests({ err: stderr.split(/\r?\n/), out: stdout.split(/\r?\n/), diff --git a/automation/utils.ts b/automation/utils.ts index 77c97b2b8c..5b9f5ef537 100644 --- a/automation/utils.ts +++ b/automation/utils.ts @@ -97,7 +97,7 @@ export function loadPackageJson() { * @returns The program's full path, e.g. 'C:\WINDOWS\System32\OpenSSH\ssh.EXE' */ export async function which(program: string): Promise { - const whichMod = await import('which'); + const { default: whichMod } = await import('which'); let programPath: string; try { programPath = await whichMod(program); diff --git a/lib/app.ts b/lib/app.ts index 8b9359ea44..98065ea561 100644 --- a/lib/app.ts +++ b/lib/app.ts @@ -31,7 +31,7 @@ import { run as mainRun, settings } from '@oclif/core'; * @see https://docs.sentry.io/error-reporting/quickstart/?platform=node */ export const setupSentry = onceAsync(async () => { - const config = await import('./config'); + const config = await import('./config.js'); const Sentry = await import('@sentry/node'); Sentry.init({ autoSessionTracking: false, @@ -51,7 +51,7 @@ export const setupSentry = onceAsync(async () => { async function checkNodeVersion() { const validNodeVersions = packageJSON.engines.node; if (!(await import('semver')).satisfies(process.version, validNodeVersions)) { - const { getNodeEngineVersionWarn } = await import('./utils/messages'); + const { getNodeEngineVersionWarn } = await import('./utils/messages.js'); console.warn(getNodeEngineVersionWarn(process.version, validNodeVersions)); } } @@ -89,13 +89,13 @@ async function init() { const settings = new CliSettings(); // Proxy setup should be done early on, before loading balena-sdk - await (await import('./utils/proxy')).setupGlobalHttpProxy(settings); + await (await import('./utils/proxy.js')).setupGlobalHttpProxy(settings); setupBalenaSdkSharedOptions(settings); // check for CLI updates once a day if (!process.env.BALENARC_OFFLINE_MODE) { - (await import('./utils/update')).notify(); + (await import('./utils/update.js')).notify(); } } @@ -106,7 +106,7 @@ async function oclifRun(command: string[], options: AppOptions) { if (unsupportedFlag || process.env.BALENARC_UNSUPPORTED) { deprecationPromise = Promise.resolve(); } else { - const { DeprecationChecker } = await import('./deprecation'); + const { DeprecationChecker } = await import('./deprecation.js'); const deprecationChecker = new DeprecationChecker(packageJSON.version); // warnAndAbortIfDeprecated uses previously cached data only await deprecationChecker.warnAndAbortIfDeprecated(); @@ -137,7 +137,8 @@ async function oclifRun(command: string[], options: AppOptions) { } } if (shouldFlush) { - await import('@oclif/core/flush'); + const { default: flush } = await import('@oclif/core/flush.js'); + await flush(); } // TODO: figure out why we need to call fast-boot stop() here, in // addition to calling it in the main `run()` function in this file. @@ -148,11 +149,11 @@ async function oclifRun(command: string[], options: AppOptions) { // the try/catch block above, execution does not get past the // Promise.all() call below, but I don't understand why. if (isEEXIT) { - (await import('./fast-boot')).stop(); + (await import('./fast-boot.js')).stop(); } })(!options.noFlush); - const { trackPromise } = await import('./hooks/prerun/track'); + const { trackPromise } = await import('./hooks/prerun/track.js'); await Promise.all([trackPromise, deprecationPromise, runPromise]); } @@ -161,7 +162,7 @@ async function oclifRun(command: string[], options: AppOptions) { export async function run(cliArgs = process.argv, options: AppOptions) { try { const { setOfflineModeEnvVars, normalizeEnvVars, pkgExec } = await import( - './utils/bootstrap' + './utils/bootstrap.js' ); setOfflineModeEnvVars(); normalizeEnvVars(); @@ -180,10 +181,10 @@ export async function run(cliArgs = process.argv, options: AppOptions) { const args = await preparseArgs(cliArgs); await oclifRun(args, options); } catch (err) { - await (await import('./errors')).handleError(err); + await (await import('./errors.js')).handleError(err); } finally { try { - (await import('./fast-boot')).stop(); + (await import('./fast-boot.js')).stop(); } catch (e) { if (process.env.DEBUG) { console.error(`[debug] Stopping fast-boot: ${e}`); diff --git a/lib/auth/index.ts b/lib/auth/index.ts index 2089eaada2..7c48867ccf 100644 --- a/lib/auth/index.ts +++ b/lib/auth/index.ts @@ -42,7 +42,7 @@ import { LoginServer } from './server'; * console.log("My session token is: #{sessionToken}") */ export async function login({ host = '127.0.0.1', port = 0 }) { - const utils = await import('./utils'); + const utils = await import('./utils.js'); const loginServer = new LoginServer(); const { @@ -55,7 +55,7 @@ export async function login({ host = '127.0.0.1', port = 0 }) { const loginUrl = await utils.getDashboardLoginURL(callbackUrl); console.info(`Opening web browser for URL:\n${loginUrl}`); - const open = await import('open'); + const { default: open } = await import('open'); await open(loginUrl, { wait: false }); const balena = getBalenaSdk(); diff --git a/lib/auth/server.ts b/lib/auth/server.ts index df7880d4ee..c24388fd14 100644 --- a/lib/auth/server.ts +++ b/lib/auth/server.ts @@ -16,7 +16,7 @@ limitations under the License. import * as bodyParser from 'body-parser'; import { EventEmitter } from 'events'; -import * as express from 'express'; +import express from 'express'; import type { Socket } from 'net'; import * as path from 'path'; diff --git a/lib/command.ts b/lib/command.ts index 1b260a3587..83c8c44512 100644 --- a/lib/command.ts +++ b/lib/command.ts @@ -71,7 +71,7 @@ export default abstract class BalenaCommand extends Command { * - other code needs to execute before check */ protected static async checkElevatedPrivileges() { - const isElevated = await (await import('is-elevated'))(); + const isElevated = await (await import('is-elevated')).default(); if (!isElevated) { throw new InsufficientPrivilegesError( 'You need root/admin privileges to run this command', @@ -94,7 +94,7 @@ export default abstract class BalenaCommand extends Command { * @throws {NotLoggedInError} */ public static async checkLoggedIn() { - await (await import('./utils/patterns')).checkLoggedIn(); + await (await import('./utils/patterns.js')).checkLoggedIn(); } /** @@ -139,14 +139,16 @@ export default abstract class BalenaCommand extends Command { * values from stdin based in configuration, minimising command implementation. */ protected async getStdin() { - this.stdin = await (await import('get-stdin'))(); + const { default: getStdin } = await import('get-stdin'); + this.stdin = await getStdin(); } /** * Get a logger instance. */ protected static async getLogger() { - return (await import('./utils/logger')).getLogger(); + const { default: logger } = await import('./utils/logger.js'); + return logger.getLogger(); } protected async init() { diff --git a/lib/commands/api-keys/index.ts b/lib/commands/api-keys/index.ts index cadf144e08..d0ceb50f52 100644 --- a/lib/commands/api-keys/index.ts +++ b/lib/commands/api-keys/index.ts @@ -46,7 +46,7 @@ export default class ApiKeysCmd extends Command { public async run() { const { flags: options } = await this.parse(ApiKeysCmd); - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); const actorId = options.fleet ? ( await getApplication(getBalenaSdk(), options.fleet, { diff --git a/lib/commands/app/create.ts b/lib/commands/app/create.ts index 5d82e33c71..1e888504c4 100644 --- a/lib/commands/app/create.ts +++ b/lib/commands/app/create.ts @@ -77,7 +77,7 @@ export default class AppCreateCmd extends Command { const { args: params, flags: options } = await this.parse(AppCreateCmd); await ( - await import('../../utils/application-create') + await import('../../utils/application-create.js') ).applicationCreateBase('app', options, params); } } diff --git a/lib/commands/block/create.ts b/lib/commands/block/create.ts index efb5ced7ba..e6dd7b56cd 100644 --- a/lib/commands/block/create.ts +++ b/lib/commands/block/create.ts @@ -77,7 +77,7 @@ export default class BlockCreateCmd extends Command { const { args: params, flags: options } = await this.parse(BlockCreateCmd); await ( - await import('../../utils/application-create') + await import('../../utils/application-create.js') ).applicationCreateBase('block', options, params); } } diff --git a/lib/commands/build/index.ts b/lib/commands/build/index.ts index 906f348984..0bcef8ebe6 100644 --- a/lib/commands/build/index.ts +++ b/lib/commands/build/index.ts @@ -36,6 +36,7 @@ import type { ComposeCliFlags, ComposeOpts } from '../../utils/compose-types'; import { buildProject, composeCliFlags } from '../../utils/compose_ts'; import type { BuildOpts, DockerCliFlags } from '../../utils/docker'; import { dockerCliFlags } from '../../utils/docker'; +import type Dockerode from 'dockerode'; // TODO: For this special one we can't use Interfaces.InferredFlags/InferredArgs // because of the 'registry-secrets' type which is defined in the actual code @@ -157,14 +158,16 @@ ${dockerignoreHelp} (opts.fleet == null && (opts.arch == null || opts.deviceType == null)) || (opts.fleet != null && (opts.arch != null || opts.deviceType != null)) ) { - const { ExpectedError } = await import('../../errors'); + const { ExpectedError } = await import('../../errors.js'); throw new ExpectedError( 'You must specify either a fleet (-f), or the device type (-d) and optionally the architecture (-A)', ); } // Validate project directory - const { validateProjectDirectory } = await import('../../utils/compose_ts'); + const { validateProjectDirectory } = await import( + '../../utils/compose_ts.js' + ); const { dockerfilePath, registrySecrets } = await validateProjectDirectory( sdk, { @@ -197,7 +200,7 @@ ${dockerignoreHelp} )) as PineTypedResult ).is_of__cpu_architecture[0].slug; } catch (err) { - const { ExpectedError } = await import('../../errors'); + const { ExpectedError } = await import('../../errors.js'); if (err instanceof sdk.errors.BalenaInvalidDeviceType) { let message = err.message; if (!(await sdk.auth.isLoggedIn())) { @@ -214,7 +217,7 @@ ${dockerignoreHelp} protected async getAppAndResolveArch(opts: FlagsDef) { if (opts.fleet) { - const { getAppWithArch } = await import('../../utils/helpers'); + const { getAppWithArch } = await import('../../utils/helpers.js'); const app = await getAppWithArch(opts.fleet); opts.arch = app.arch; opts.deviceType = app.is_for__device_type[0].slug; @@ -222,8 +225,14 @@ ${dockerignoreHelp} } } - protected async prepareBuild(options: FlagsDef) { - const { getDocker, generateBuildOpts } = await import('../../utils/docker'); + protected async prepareBuild(options: FlagsDef): Promise<{ + docker: Dockerode; + buildOpts: BuildOpts; + composeOpts: ComposeOpts; + }> { + const { getDocker, generateBuildOpts } = await import( + '../../utils/docker.js' + ); const [docker, buildOpts, composeOpts] = await Promise.all([ getDocker(options), generateBuildOpts(options), @@ -261,7 +270,7 @@ ${dockerignoreHelp} buildOpts: BuildOpts; }, ) { - const { loadProject } = await import('../../utils/compose_ts'); + const { loadProject } = await import('../../utils/compose_ts.js'); const project = await loadProject( logger, diff --git a/lib/commands/config/generate.ts b/lib/commands/config/generate.ts index 2788b3c63a..b5a7210a8a 100644 --- a/lib/commands/config/generate.ts +++ b/lib/commands/config/generate.ts @@ -126,7 +126,7 @@ export default class ConfigGenerateCmd extends Command { public static authenticated = true; public async getApplication(balena: BalenaSDK, fleet: string) { - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); return await getApplication(balena, fleet, { $select: 'slug', $expand: { @@ -152,7 +152,7 @@ export default class ConfigGenerateCmd extends Command { $expand: { is_of__device_type: { $select: 'slug' } }, }); if (!rawDevice.belongs_to__application) { - const { ExpectedError } = await import('../../errors'); + const { ExpectedError } = await import('../../errors.js'); throw new ExpectedError(stripIndent` Device ${options.device} does not appear to belong to an accessible fleet. Try with a different device, or use '--fleet' instead of '--device'.`); @@ -171,14 +171,14 @@ export default class ConfigGenerateCmd extends Command { // Check compatibility if application and deviceType provided if (options.fleet && options.deviceType) { - const helpers = await import('../../utils/helpers'); + const helpers = await import('../../utils/helpers.js'); if ( !(await helpers.areDeviceTypesCompatible( resourceDeviceType, deviceType, )) ) { - const { ExpectedError } = await import('../../errors'); + const { ExpectedError } = await import('../../errors.js'); throw new ExpectedError( `Device type ${options.deviceType} is incompatible with fleet ${options.fleet}`, ); @@ -189,7 +189,7 @@ export default class ConfigGenerateCmd extends Command { await balena.models.config.getDeviceTypeManifestBySlug(deviceType); const { validateSecureBootOptionAndWarn } = await import( - '../../utils/config' + '../../utils/config.js' ); await validateSecureBootOptionAndWarn( options.secureBoot, @@ -211,7 +211,7 @@ export default class ConfigGenerateCmd extends Command { // Generate config const { generateDeviceConfig, generateApplicationConfig } = await import( - '../../utils/config' + '../../utils/config.js' ); let config; @@ -250,7 +250,7 @@ export default class ConfigGenerateCmd extends Command { protected async validateOptions( options: Interfaces.InferredFlags, ) { - const { ExpectedError } = await import('../../errors'); + const { ExpectedError } = await import('../../errors.js'); if (options.device == null && options.fleet == null) { throw new ExpectedError(this.missingDeviceOrAppMessage); @@ -259,9 +259,9 @@ export default class ConfigGenerateCmd extends Command { if (!options.fleet && options.deviceType) { throw new ExpectedError(this.deviceTypeNotAllowedMessage); } - const { normalizeOsVersion } = await import('../../utils/normalization'); + const { normalizeOsVersion } = await import('../../utils/normalization.js'); options.version = normalizeOsVersion(options.version); - const { validateDevOptionAndWarn } = await import('../../utils/config'); + const { validateDevOptionAndWarn } = await import('../../utils/config.js'); await validateDevOptionAndWarn(options.dev, options.version); } } diff --git a/lib/commands/config/inject.ts b/lib/commands/config/inject.ts index 6e344f702b..a9034e0dcf 100644 --- a/lib/commands/config/inject.ts +++ b/lib/commands/config/inject.ts @@ -56,7 +56,7 @@ export default class ConfigInjectCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(ConfigInjectCmd); - const { safeUmount } = await import('../../utils/umount'); + const { safeUmount } = await import('../../utils/umount.js'); const drive = options.drive || (await getVisuals().drive('Select the device/OS drive')); diff --git a/lib/commands/config/read.ts b/lib/commands/config/read.ts index 333fea8746..9830e5a6a5 100644 --- a/lib/commands/config/read.ts +++ b/lib/commands/config/read.ts @@ -50,7 +50,7 @@ export default class ConfigReadCmd extends Command { public async run() { const { flags: options } = await this.parse(ConfigReadCmd); - const { safeUmount } = await import('../../utils/umount'); + const { safeUmount } = await import('../../utils/umount.js'); const drive = options.drive || (await getVisuals().drive('Select the device drive')); diff --git a/lib/commands/config/reconfigure.ts b/lib/commands/config/reconfigure.ts index be9ab466cc..8dd9a2b1ef 100644 --- a/lib/commands/config/reconfigure.ts +++ b/lib/commands/config/reconfigure.ts @@ -59,7 +59,7 @@ export default class ConfigReconfigureCmd extends Command { public async run() { const { flags: options } = await this.parse(ConfigReconfigureCmd); - const { safeUmount } = await import('../../utils/umount'); + const { safeUmount } = await import('../../utils/umount.js'); const drive = options.drive || (await getVisuals().drive('Select the device drive')); @@ -70,7 +70,7 @@ export default class ConfigReconfigureCmd extends Command { await safeUmount(drive); if (!uuid) { - const { ExpectedError } = await import('../../errors'); + const { ExpectedError } = await import('../../errors.js'); throw new ExpectedError( `Error: UUID not found in 'config.json' file for '${drive}'`, ); @@ -84,7 +84,7 @@ export default class ConfigReconfigureCmd extends Command { configureCommand.push('--advanced'); } - const { runCommand } = await import('../../utils/helpers'); + const { runCommand } = await import('../../utils/helpers.js'); await runCommand(configureCommand); console.info('Done'); diff --git a/lib/commands/config/write.ts b/lib/commands/config/write.ts index e1323f5f15..dd922da161 100644 --- a/lib/commands/config/write.ts +++ b/lib/commands/config/write.ts @@ -61,7 +61,7 @@ export default class ConfigWriteCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(ConfigWriteCmd); - const { denyMount, safeUmount } = await import('../../utils/umount'); + const { denyMount, safeUmount } = await import('../../utils/umount.js'); const drive = options.drive || (await getVisuals().drive('Select the device drive')); diff --git a/lib/commands/deploy/index.ts b/lib/commands/deploy/index.ts index 1fa0232c42..e11e72fa2f 100644 --- a/lib/commands/deploy/index.ts +++ b/lib/commands/deploy/index.ts @@ -175,7 +175,7 @@ ${dockerignoreHelp} const sdk = getBalenaSdk(); const { getRegistrySecrets, validateProjectDirectory } = await import( - '../../utils/compose_ts' + '../../utils/compose_ts.js' ); const { releaseTagKeys, releaseTagValues } = parseReleaseTagKeysAndValues( @@ -199,10 +199,10 @@ ${dockerignoreHelp} (options as FlagsDef)['registry-secrets'] = registrySecrets; } - const helpers = await import('../../utils/helpers'); + const helpers = await import('../../utils/helpers.js'); const app = await helpers.getAppWithArch(fleet); - const dockerUtils = await import('../../utils/docker'); + const dockerUtils = await import('../../utils/docker.js'); const [docker, buildOpts, composeOpts] = await Promise.all([ dockerUtils.getDocker(options), dockerUtils.generateBuildOpts(options as FlagsDef), @@ -250,7 +250,7 @@ ${dockerignoreHelp} const doodles = await import('resin-doodles'); const sdk = getBalenaSdk(); const { deployProject: $deployProject, loadProject } = await import( - '../../utils/compose_ts' + '../../utils/compose_ts.js' ); const appType = opts.app.application_type[0]; diff --git a/lib/commands/device/deactivate.ts b/lib/commands/device/deactivate.ts index 43afcc8ec4..c22d2653a9 100644 --- a/lib/commands/device/deactivate.ts +++ b/lib/commands/device/deactivate.ts @@ -55,7 +55,7 @@ export default class DeviceDeactivateCmd extends Command { await this.parse(DeviceDeactivateCmd); const balena = getBalenaSdk(); - const patterns = await import('../../utils/patterns'); + const patterns = await import('../../utils/patterns.js'); const uuid = params.uuid; const deactivationWarning = ` diff --git a/lib/commands/device/index.ts b/lib/commands/device/index.ts index 71dbef74e5..3dc318caa8 100644 --- a/lib/commands/device/index.ts +++ b/lib/commands/device/index.ts @@ -122,7 +122,7 @@ export default class DeviceCmd extends Command { )) as ExtendedDevice; if (options.view) { - const open = await import('open'); + const { default: open } = await import('open'); const dashboardUrl = balena.models.device.getDashboardUrl(device.uuid); await open(dashboardUrl, { wait: false }); return; diff --git a/lib/commands/device/init.ts b/lib/commands/device/init.ts index 3fc45e4bc8..2a4b45c1c4 100644 --- a/lib/commands/device/init.ts +++ b/lib/commands/device/init.ts @@ -113,12 +113,12 @@ export default class DeviceInitCmd extends Command { // Imports const { promisify } = await import('util'); - const rimraf = promisify(await import('rimraf')); + const rimraf = promisify((await import('rimraf')).default); const tmp = await import('tmp'); const tmpNameAsync = promisify(tmp.tmpName); tmp.setGracefulCleanup(); - const { downloadOSImage } = await import('../../utils/cloud'); - const { getApplication } = await import('../../utils/sdk'); + const { downloadOSImage } = await import('../../utils/cloud.js'); + const { getApplication } = await import('../../utils/sdk.js'); const logger = await Command.getLogger(); const balena = getBalenaSdk(); @@ -133,7 +133,7 @@ export default class DeviceInitCmd extends Command { }, }, }) - : await (await import('../../utils/patterns')).selectApplication(); + : await (await import('../../utils/patterns.js')).selectApplication(); // Register new device const deviceUuid = balena.models.device.generateUniqueKey(); diff --git a/lib/commands/device/move.ts b/lib/commands/device/move.ts index 20e4c9afa9..bff8f949d3 100644 --- a/lib/commands/device/move.ts +++ b/lib/commands/device/move.ts @@ -101,7 +101,7 @@ export default class DeviceMoveCmd extends Command { const devices = await this.getDevices(balena, deviceUuids); // Disambiguate application - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); // Get destination application const application = options.fleet @@ -151,7 +151,7 @@ export default class DeviceMoveCmd extends Command { }) .map((deviceType) => deviceType.id); - const patterns = await import('../../utils/patterns'); + const patterns = await import('../../utils/patterns.js'); try { const application = await patterns.selectApplication( { diff --git a/lib/commands/device/os-update.ts b/lib/commands/device/os-update.ts index bb5b3226ab..c7883ae049 100644 --- a/lib/commands/device/os-update.ts +++ b/lib/commands/device/os-update.ts @@ -122,7 +122,9 @@ export default class DeviceOsUpdateCmd extends Command { // Get target OS version let targetOsVersion = options.version; if (targetOsVersion != null) { - const { normalizeOsVersion } = await import('../../utils/normalization'); + const { normalizeOsVersion } = await import( + '../../utils/normalization.js' + ); targetOsVersion = normalizeOsVersion(targetOsVersion); if (!hupVersionInfo.versions.includes(targetOsVersion)) { throw new ExpectedError( @@ -143,7 +145,7 @@ export default class DeviceOsUpdateCmd extends Command { }); } - const patterns = await import('../../utils/patterns'); + const patterns = await import('../../utils/patterns.js'); // Confirm and start update await patterns.confirm( options.yes || false, diff --git a/lib/commands/device/register.ts b/lib/commands/device/register.ts index 7a9d10b517..6a366267e2 100644 --- a/lib/commands/device/register.ts +++ b/lib/commands/device/register.ts @@ -64,7 +64,7 @@ export default class DeviceRegisterCmd extends Command { const { args: params, flags: options } = await this.parse(DeviceRegisterCmd); - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); const balena = getBalenaSdk(); diff --git a/lib/commands/device/restart.ts b/lib/commands/device/restart.ts index 71f35f7b3c..8b71c10123 100644 --- a/lib/commands/device/restart.ts +++ b/lib/commands/device/restart.ts @@ -94,8 +94,8 @@ export default class DeviceRestartCmd extends Command { deviceUuid: string, serviceNames: string[], ) { - const { ExpectedError, instanceOf } = await import('../../errors'); - const { getExpandedProp } = await import('../../utils/pine'); + const { ExpectedError, instanceOf } = await import('../../errors.js'); + const { getExpandedProp } = await import('../../utils/pine.js'); // Get device let device: DeviceWithServiceDetails; @@ -161,7 +161,7 @@ export default class DeviceRestartCmd extends Command { // Note: device.restartApplication throws `BalenaDeviceNotFound: Device not found` if device not online. // Need to use device.get first to distinguish between non-existant and offline devices. // Remove this workaround when SDK issue resolved: https://github.com/balena-io/balena-sdk/issues/649 - const { instanceOf, ExpectedError } = await import('../../errors'); + const { instanceOf, ExpectedError } = await import('../../errors.js'); try { const device = await balena.models.device.get(deviceUuid); if (!device.is_online) { diff --git a/lib/commands/device/rm.ts b/lib/commands/device/rm.ts index 6f3cc48291..9f7e820630 100644 --- a/lib/commands/device/rm.ts +++ b/lib/commands/device/rm.ts @@ -56,7 +56,7 @@ export default class DeviceRmCmd extends Command { const { args: params, flags: options } = await this.parse(DeviceRmCmd); const balena = getBalenaSdk(); - const patterns = await import('../../utils/patterns'); + const patterns = await import('../../utils/patterns.js'); // Confirm const uuids = params.uuid.split(','); diff --git a/lib/commands/device/start-service.ts b/lib/commands/device/start-service.ts index 4637f22115..460f5e3f67 100644 --- a/lib/commands/device/start-service.ts +++ b/lib/commands/device/start-service.ts @@ -78,8 +78,8 @@ export default class DeviceStartServiceCmd extends Command { deviceUuid: string, serviceNames: string[], ) { - const { ExpectedError } = await import('../../errors'); - const { getExpandedProp } = await import('../../utils/pine'); + const { ExpectedError } = await import('../../errors.js'); + const { getExpandedProp } = await import('../../utils/pine.js'); // Get device const device = await balena.models.device.getWithServiceDetails( diff --git a/lib/commands/device/stop-service.ts b/lib/commands/device/stop-service.ts index b7aa53dc78..1ae793ff5b 100644 --- a/lib/commands/device/stop-service.ts +++ b/lib/commands/device/stop-service.ts @@ -78,8 +78,8 @@ export default class DeviceStopServiceCmd extends Command { deviceUuid: string, serviceNames: string[], ) { - const { ExpectedError } = await import('../../errors'); - const { getExpandedProp } = await import('../../utils/pine'); + const { ExpectedError } = await import('../../errors.js'); + const { getExpandedProp } = await import('../../utils/pine.js'); // Get device const device = await balena.models.device.getWithServiceDetails( diff --git a/lib/commands/devices/index.ts b/lib/commands/devices/index.ts index e7196c42bf..70991a3a00 100644 --- a/lib/commands/devices/index.ts +++ b/lib/commands/devices/index.ts @@ -78,7 +78,7 @@ export default class DevicesCmd extends Command { const devices = ( await (async () => { if (options.fleet != null) { - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); const application = await getApplication(balena, options.fleet, { $select: 'slug', $expand: { @@ -115,7 +115,7 @@ export default class DevicesCmd extends Command { ]; if (options.json) { - const { pickAndRename } = await import('../../utils/helpers'); + const { pickAndRename } = await import('../../utils/helpers.js'); const mapped = devices.map((device) => pickAndRename(device, fields)); console.log(JSON.stringify(mapped, null, 4)); } else { diff --git a/lib/commands/env/add.ts b/lib/commands/env/add.ts index 479e03c476..77c58fc56c 100644 --- a/lib/commands/env/add.ts +++ b/lib/commands/env/add.ts @@ -185,7 +185,7 @@ async function resolveFleetSlugs( fleetOption: string, ) { const fleetSlugs: string[] = []; - const { getFleetSlug } = await import('../../utils/sdk'); + const { getFleetSlug } = await import('../../utils/sdk.js'); for (const appNameOrSlug of fleetOption.split(',')) { try { fleetSlugs.push(await getFleetSlug(balena, appNameOrSlug)); @@ -222,7 +222,7 @@ async function setServiceVars( } } } else if (options.device) { - const { getDeviceAndAppFromUUID } = await import('../../utils/cloud'); + const { getDeviceAndAppFromUUID } = await import('../../utils/cloud.js'); for (const uuid of options.device.split(',')) { let device; let app; diff --git a/lib/commands/env/rm.ts b/lib/commands/env/rm.ts index d3589001de..1af607eb16 100644 --- a/lib/commands/env/rm.ts +++ b/lib/commands/env/rm.ts @@ -71,7 +71,7 @@ export default class EnvRmCmd extends Command { await Command.checkLoggedIn(); - const { confirm } = await import('../../utils/patterns'); + const { confirm } = await import('../../utils/patterns.js'); await confirm( opt.yes || false, 'Are you sure you want to delete the environment variable?', diff --git a/lib/commands/envs/index.ts b/lib/commands/envs/index.ts index 310d9cca6a..d0719d812a 100644 --- a/lib/commands/envs/index.ts +++ b/lib/commands/envs/index.ts @@ -125,14 +125,14 @@ export default class EnvsCmd extends Command { let fleetSlug: string | undefined = options.fleet ? await ( - await import('../../utils/sdk') + await import('../../utils/sdk.js') ).getFleetSlug(balena, options.fleet) : undefined; let fullUUID: string | undefined; // as oppposed to the short, 7-char UUID if (options.device) { const { getDeviceAndMaybeAppFromUUID } = await import( - '../../utils/cloud' + '../../utils/cloud.js' ); const [device, app] = await getDeviceAndMaybeAppFromUUID( balena, @@ -186,7 +186,7 @@ export default class EnvsCmd extends Command { } if (options.json) { - const { pickAndRename } = await import('../../utils/helpers'); + const { pickAndRename } = await import('../../utils/helpers.js'); const mapped = varArray.map((o) => pickAndRename(o, fields)); this.log(JSON.stringify(mapped, null, 4)); } else { diff --git a/lib/commands/fleet/create.ts b/lib/commands/fleet/create.ts index 2d10c2214d..a4f11a2ad7 100644 --- a/lib/commands/fleet/create.ts +++ b/lib/commands/fleet/create.ts @@ -77,7 +77,7 @@ export default class FleetCreateCmd extends Command { const { args: params, flags: options } = await this.parse(FleetCreateCmd); await ( - await import('../../utils/application-create') + await import('../../utils/application-create.js') ).applicationCreateBase('fleet', options, params); } } diff --git a/lib/commands/fleet/index.ts b/lib/commands/fleet/index.ts index b59c135a7d..81849e88e1 100644 --- a/lib/commands/fleet/index.ts +++ b/lib/commands/fleet/index.ts @@ -58,7 +58,7 @@ export default class FleetCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(FleetCmd); - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); const balena = getBalenaSdk(); @@ -70,7 +70,7 @@ export default class FleetCmd extends Command { }); if (options.view) { - const open = await import('open'); + const { default: open } = await import('open'); const dashboardUrl = balena.models.application.getDashboardUrl( application.id, ); diff --git a/lib/commands/fleet/purge.ts b/lib/commands/fleet/purge.ts index 5456ea0af3..4ecbd85cdb 100644 --- a/lib/commands/fleet/purge.ts +++ b/lib/commands/fleet/purge.ts @@ -51,7 +51,7 @@ export default class FleetPurgeCmd extends Command { public async run() { const { args: params } = await this.parse(FleetPurgeCmd); - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); const balena = getBalenaSdk(); diff --git a/lib/commands/fleet/rename.ts b/lib/commands/fleet/rename.ts index 9214d2e659..f8569aa1a2 100644 --- a/lib/commands/fleet/rename.ts +++ b/lib/commands/fleet/rename.ts @@ -59,13 +59,15 @@ export default class FleetRenameCmd extends Command { public async run() { const { args: params } = await this.parse(FleetRenameCmd); - const { validateApplicationName } = await import('../../utils/validation'); - const { ExpectedError } = await import('../../errors'); + const { validateApplicationName } = await import( + '../../utils/validation.js' + ); + const { ExpectedError } = await import('../../errors.js'); const balena = getBalenaSdk(); // Disambiguate target application (if params.params is a number, it could either be an ID or a numerical name) - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); const application = await getApplication(balena, params.fleet, { $select: ['id', 'app_name', 'slug'], $expand: { diff --git a/lib/commands/fleet/restart.ts b/lib/commands/fleet/restart.ts index f9a8c4b6ec..6d22b6573b 100644 --- a/lib/commands/fleet/restart.ts +++ b/lib/commands/fleet/restart.ts @@ -50,7 +50,7 @@ export default class FleetRestartCmd extends Command { public async run() { const { args: params } = await this.parse(FleetRestartCmd); - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); const balena = getBalenaSdk(); diff --git a/lib/commands/fleet/rm.ts b/lib/commands/fleet/rm.ts index e75d1c04d3..25dab03fce 100644 --- a/lib/commands/fleet/rm.ts +++ b/lib/commands/fleet/rm.ts @@ -54,8 +54,8 @@ export default class FleetRmCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(FleetRmCmd); - const { confirm } = await import('../../utils/patterns'); - const { getApplication } = await import('../../utils/sdk'); + const { confirm } = await import('../../utils/patterns.js'); + const { getApplication } = await import('../../utils/sdk.js'); const balena = getBalenaSdk(); // Confirm diff --git a/lib/commands/internal/osinit.ts b/lib/commands/internal/osinit.ts index 8bc1299283..9bc184b0f0 100644 --- a/lib/commands/internal/osinit.ts +++ b/lib/commands/internal/osinit.ts @@ -63,7 +63,7 @@ export default class OsinitCmd extends Command { const config = JSON.parse(params.config); const { getManifest, osProgressHandler } = await import( - '../../utils/helpers' + '../../utils/helpers.js' ); const manifest = await getManifest(params.image, params.type); diff --git a/lib/commands/join/index.ts b/lib/commands/join/index.ts index 152381b35e..a61efb1ee0 100644 --- a/lib/commands/join/index.ts +++ b/lib/commands/join/index.ts @@ -78,7 +78,7 @@ export default class JoinCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(JoinCmd); - const promote = await import('../../utils/promote'); + const promote = await import('../../utils/promote.js'); const sdk = getBalenaSdk(); const logger = await Command.getLogger(); return promote.join( diff --git a/lib/commands/key/rm.ts b/lib/commands/key/rm.ts index 5e0ad100f8..f9523efebc 100644 --- a/lib/commands/key/rm.ts +++ b/lib/commands/key/rm.ts @@ -52,7 +52,7 @@ export default class KeyRmCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(KeyRmCmd); - const patterns = await import('../../utils/patterns'); + const patterns = await import('../../utils/patterns.js'); await patterns.confirm( options.yes ?? false, diff --git a/lib/commands/leave/index.ts b/lib/commands/leave/index.ts index 2365d00758..d30cf2ce18 100644 --- a/lib/commands/leave/index.ts +++ b/lib/commands/leave/index.ts @@ -62,7 +62,7 @@ export default class LeaveCmd extends Command { public async run() { const { args: params } = await this.parse(LeaveCmd); - const promote = await import('../../utils/promote'); + const promote = await import('../../utils/promote.js'); const logger = await Command.getLogger(); return promote.leave(logger, params.deviceIpOrHostname); } diff --git a/lib/commands/local/configure.ts b/lib/commands/local/configure.ts index 53aa170d56..220d128847 100644 --- a/lib/commands/local/configure.ts +++ b/lib/commands/local/configure.ts @@ -53,8 +53,8 @@ export default class LocalConfigureCmd extends Command { const { args: params } = await this.parse(LocalConfigureCmd); const reconfix = await import('reconfix'); - const { denyMount, safeUmount } = await import('../../utils/umount'); - const Logger = await import('../../utils/logger'); + const { denyMount, safeUmount } = await import('../../utils/umount.js'); + const { default: Logger } = await import('../../utils/logger.js'); const logger = Logger.getLogger(); diff --git a/lib/commands/local/flash.ts b/lib/commands/local/flash.ts index e230171809..c0293605cb 100644 --- a/lib/commands/local/flash.ts +++ b/lib/commands/local/flash.ts @@ -79,7 +79,7 @@ export default class LocalFlashCmd extends Command { const drive = await this.getDrive(options); - const { confirm } = await import('../../utils/patterns'); + const { confirm } = await import('../../utils/patterns.js'); await confirm( options.yes, 'This will erase the selected drive. Are you sure?', diff --git a/lib/commands/login/index.ts b/lib/commands/login/index.ts index 70d6c1c6a5..fb14048813 100644 --- a/lib/commands/login/index.ts +++ b/lib/commands/login/index.ts @@ -123,7 +123,7 @@ export default class LoginCmd extends Command { const { flags: options, args: params } = await this.parse(LoginCmd); const balena = getBalenaSdk(); - const messages = await import('../../utils/messages'); + const messages = await import('../../utils/messages.js'); const balenaUrl = await balena.settings.get('balenaUrl'); // Consolidate user/email options @@ -202,20 +202,20 @@ ${messages.reachingOut}`); } // Credentials else if (loginOptions.credentials) { - const patterns = await import('../../utils/patterns'); + const patterns = await import('../../utils/patterns.js'); return patterns.authenticate(loginOptions); } // Web else if (loginOptions.web) { - const auth = await import('../../auth'); + const auth = await import('../../auth/index.js'); await auth.login({ port: loginOptions.port }); return; } else { - const patterns = await import('../../utils/patterns'); + const patterns = await import('../../utils/patterns.js'); // User had not selected login preference, prompt interactively const loginType = await patterns.askLoginType(); if (loginType === 'register') { - const open = await import('open'); + const { default: open } = await import('open'); const signupUrl = `https://dashboard.${balenaUrl}/signup`; await open(signupUrl, { wait: false }); throw new ExpectedError(`Please sign up at ${signupUrl}`); diff --git a/lib/commands/logs/index.ts b/lib/commands/logs/index.ts index 1ca17e72b0..5b8b49cea2 100644 --- a/lib/commands/logs/index.ts +++ b/lib/commands/logs/index.ts @@ -96,14 +96,14 @@ export default class LogsCmd extends Command { const { args: params, flags: options } = await this.parse(LogsCmd); const balena = getBalenaSdk(); - const { serviceIdToName } = await import('../../utils/cloud'); + const { serviceIdToName } = await import('../../utils/cloud.js'); const { connectAndDisplayDeviceLogs, displayLogObject } = await import( - '../../utils/device/logs' + '../../utils/device/logs.js' ); const { validateIPAddress, validateDotLocalUrl } = await import( - '../../utils/validation' + '../../utils/validation.js' ); - const Logger = await import('../../utils/logger'); + const { default: Logger } = await import('../../utils/logger.js'); const logger = Logger.getLogger(); @@ -132,13 +132,13 @@ export default class LogsCmd extends Command { validateDotLocalUrl(params.device) ) { // Logs from local device - const { DeviceAPI } = await import('../../utils/device/api'); + const { DeviceAPI } = await import('../../utils/device/api.js'); const deviceApi = new DeviceAPI(logger, params.device); logger.logDebug('Checking we can access device'); try { await deviceApi.ping(); } catch (e) { - const { ExpectedError } = await import('../../errors'); + const { ExpectedError } = await import('../../errors.js'); throw new ExpectedError( `Cannot access device at address ${params.device}. Device may not be in local mode.`, ); diff --git a/lib/commands/orgs/index.ts b/lib/commands/orgs/index.ts index f50604f808..28deb7f98e 100644 --- a/lib/commands/orgs/index.ts +++ b/lib/commands/orgs/index.ts @@ -38,7 +38,7 @@ export default class OrgsCmd extends Command { public async run() { await this.parse(OrgsCmd); - const { getOwnOrganizations } = await import('../../utils/sdk'); + const { getOwnOrganizations } = await import('../../utils/sdk.js'); // Get organizations const organizations = await getOwnOrganizations(getBalenaSdk(), { diff --git a/lib/commands/os/build-config.ts b/lib/commands/os/build-config.ts index 0b6d954a90..fe5c8323db 100644 --- a/lib/commands/os/build-config.ts +++ b/lib/commands/os/build-config.ts @@ -82,7 +82,7 @@ export default class OsBuildConfigCmd extends Command { async buildConfig(image: string, deviceTypeSlug: string, advanced: boolean) { advanced = advanced || false; - const { getManifest } = await import('../../utils/helpers'); + const { getManifest } = await import('../../utils/helpers.js'); const deviceTypeManifest = await getManifest(image, deviceTypeSlug); return this.buildConfigForDeviceType(deviceTypeManifest, advanced); @@ -103,7 +103,7 @@ export default class OsBuildConfigCmd extends Command { }); if (advancedGroup != null) { - const { getGroupDefaults } = await import('../../utils/helpers'); + const { getGroupDefaults } = await import('../../utils/helpers.js'); override = getGroupDefaults(advancedGroup); } } diff --git a/lib/commands/os/configure.ts b/lib/commands/os/configure.ts index d25f8ce24b..01a8b63899 100644 --- a/lib/commands/os/configure.ts +++ b/lib/commands/os/configure.ts @@ -170,10 +170,10 @@ export default class OsConfigureCmd extends Command { const devInit = await import('balena-device-init'); const { promises: fs } = await import('fs'); const { generateDeviceConfig, generateApplicationConfig } = await import( - '../../utils/config' + '../../utils/config.js' ); - const helpers = await import('../../utils/helpers'); - const { getApplication } = await import('../../utils/sdk'); + const helpers = await import('../../utils/helpers.js'); + const { getApplication } = await import('../../utils/sdk.js'); let app: ApplicationWithDeviceTypeSlug | undefined; let device; @@ -211,7 +211,7 @@ export default class OsConfigureCmd extends Command { configJson = JSON.parse(rawConfig); } - const { normalizeOsVersion } = await import('../../utils/normalization'); + const { normalizeOsVersion } = await import('../../utils/normalization.js'); const osVersion = normalizeOsVersion( options.version || (await getOsVersionFromImage( @@ -221,11 +221,11 @@ export default class OsConfigureCmd extends Command { )), ); - const { validateDevOptionAndWarn } = await import('../../utils/config'); + const { validateDevOptionAndWarn } = await import('../../utils/config.js'); await validateDevOptionAndWarn(options.dev, osVersion); const { validateSecureBootOptionAndWarn } = await import( - '../../utils/config' + '../../utils/config.js' ); await validateSecureBootOptionAndWarn( options.secureBoot, @@ -363,7 +363,7 @@ async function checkDeviceTypeCompatibility( }, ) { if (options['device-type']) { - const helpers = await import('../../utils/helpers'); + const helpers = await import('../../utils/helpers.js'); if ( !(await helpers.areDeviceTypesCompatible( app.is_for__device_type[0].slug, @@ -417,7 +417,7 @@ async function askQuestionsForDeviceType( isGroup: true, }); if (!_.isEmpty(advancedGroup)) { - const helpers = await import('../../utils/helpers'); + const helpers = await import('../../utils/helpers.js'); answerSources.push(helpers.getGroupDefaults(advancedGroup)); } } diff --git a/lib/commands/os/download.ts b/lib/commands/os/download.ts index e7ef1bdab6..66664b8152 100644 --- a/lib/commands/os/download.ts +++ b/lib/commands/os/download.ts @@ -95,7 +95,7 @@ export default class OsDownloadCmd extends Command { await OsDownloadCmd.checkLoggedIn(); } catch (e) { const { ExpectedError, NotLoggedInError } = await import( - '../../errors' + '../../errors.js' ); if (e instanceof NotLoggedInError) { throw new ExpectedError(stripIndent` @@ -107,7 +107,7 @@ export default class OsDownloadCmd extends Command { } } - const { downloadOSImage } = await import('../../utils/cloud'); + const { downloadOSImage } = await import('../../utils/cloud.js'); try { await downloadOSImage(params.type, options.output, options.version); diff --git a/lib/commands/os/initialize.ts b/lib/commands/os/initialize.ts index 322c1ab8dc..ca574483ce 100644 --- a/lib/commands/os/initialize.ts +++ b/lib/commands/os/initialize.ts @@ -62,7 +62,7 @@ export default class OsInitializeCmd extends Command { public async run() { const { args: params, flags: options } = await this.parse(OsInitializeCmd); - const { getManifest, sudo } = await import('../../utils/helpers'); + const { getManifest, sudo } = await import('../../utils/helpers.js'); console.info(`Initializing device ${INIT_WARNING_MESSAGE}`); @@ -75,13 +75,13 @@ export default class OsInitializeCmd extends Command { }); if (answers.drive != null) { - const { confirm } = await import('../../utils/patterns'); + const { confirm } = await import('../../utils/patterns.js'); await confirm( options.yes, `This will erase ${answers.drive}. Are you sure?`, `Going to erase ${answers.drive}.`, ); - const { safeUmount } = await import('../../utils/umount'); + const { safeUmount } = await import('../../utils/umount.js'); await safeUmount(answers.drive); } @@ -94,7 +94,7 @@ export default class OsInitializeCmd extends Command { ]); if (answers.drive != null) { - const { safeUmount } = await import('../../utils/umount'); + const { safeUmount } = await import('../../utils/umount.js'); await safeUmount(answers.drive); console.info(`You can safely remove ${answers.drive} now`); } diff --git a/lib/commands/os/versions.ts b/lib/commands/os/versions.ts index 9ba22a6b8d..79cd80497b 100644 --- a/lib/commands/os/versions.ts +++ b/lib/commands/os/versions.ts @@ -58,7 +58,7 @@ export default class OsVersionsCmd extends Command { const { args: params, flags: options } = await this.parse(OsVersionsCmd); if (options['include-draft']) { - const { warnify } = await import('../../utils/messages'); + const { warnify } = await import('../../utils/messages.js'); console.error( warnify(stripIndent` Using pre-release balenaOS versions is only supported for OS updates @@ -68,7 +68,7 @@ export default class OsVersionsCmd extends Command { } const { formatOsVersion, getOsVersions } = await import( - '../../utils/cloud' + '../../utils/cloud.js' ); const vs = await getOsVersions( params.type, diff --git a/lib/commands/preload/index.ts b/lib/commands/preload/index.ts index 7df4fc4605..6966d1ad5c 100644 --- a/lib/commands/preload/index.ts +++ b/lib/commands/preload/index.ts @@ -39,6 +39,7 @@ import type { Release, } from 'balena-sdk'; import type { Preloader } from 'balena-preload'; +import type { EventEmitter } from 'events'; export default class PreloadCmd extends Command { public static description = stripIndent` @@ -145,10 +146,10 @@ Can be repeated to add multiple certificates.\ const { args: params, flags: options } = await this.parse(PreloadCmd); const balena = getBalenaSdk(); - const balenaPreload = await import('balena-preload'); + const { default: balenaPreload } = await import('balena-preload'); const visuals = getVisuals(); - const nodeCleanup = await import('node-cleanup'); - const { instanceOf } = await import('../../errors'); + const { default: nodeCleanup } = await import('node-cleanup'); + const { instanceOf } = await import('../../errors.js'); // Check image file exists try { @@ -172,7 +173,7 @@ Can be repeated to add multiple certificates.\ // Load app here, and use app slug from hereon const fleetSlug: string | undefined = options.fleet ? await ( - await import('../../utils/sdk') + await import('../../utils/sdk.js') ).getFleetSlug(balena, options.fleet) : undefined; @@ -229,7 +230,7 @@ Can be repeated to add multiple certificates.\ } // Get a configured dockerode instance - const dockerUtils = await import('../../utils/docker'); + const dockerUtils = await import('../../utils/docker.js'); const docker = await dockerUtils.getDocker(options); const preloader = new balenaPreload.Preloader( undefined, @@ -243,7 +244,7 @@ Can be repeated to add multiple certificates.\ pinDevice ?? false, certificates, additionalSpace, - ); + ) as Preloader & EventEmitter; let gotSignal = false; @@ -481,7 +482,7 @@ Would you like to disable automatic updates for this fleet now?\ } async getAppWithReleases(balenaSdk: BalenaSDK, slug: string) { - const { getApplication } = await import('../../utils/sdk'); + const { getApplication } = await import('../../utils/sdk.js'); return await getApplication(balenaSdk, slug, { $expand: this.applicationExpandOptions, diff --git a/lib/commands/push/index.ts b/lib/commands/push/index.ts index 7693f7c430..6560c26394 100644 --- a/lib/commands/push/index.ts +++ b/lib/commands/push/index.ts @@ -233,7 +233,9 @@ export default class PushCmd extends Command { logger.logDebug(`Using build source directory: ${options.source} `); const sdk = getBalenaSdk(); - const { validateProjectDirectory } = await import('../../utils/compose_ts'); + const { validateProjectDirectory } = await import( + '../../utils/compose_ts.js' + ); const { dockerfilePath, registrySecrets } = await validateProjectDirectory( sdk, { @@ -276,8 +278,8 @@ export default class PushCmd extends Command { dockerfilePath: string, registrySecrets: RegistrySecrets, ) { - const remote = await import('../../utils/remote-build'); - const { getApplication } = await import('../../utils/sdk'); + const remote = await import('../../utils/remote-build.js'); + const { getApplication } = await import('../../utils/sdk.js'); // Check for invalid options const localOnlyOptions: Array = [ @@ -356,7 +358,7 @@ export default class PushCmd extends Command { 'is only valid when pushing to a fleet', ); - const deviceDeploy = await import('../../utils/device/deploy'); + const deviceDeploy = await import('../../utils/device/deploy.js'); try { await deviceDeploy.deployToDevice({ @@ -376,7 +378,7 @@ export default class PushCmd extends Command { convertEol: !options['noconvert-eol'], }); } catch (e) { - const { BuildError } = await import('../../utils/device/errors'); + const { BuildError } = await import('../../utils/device/errors.js'); if (instanceOf(e, BuildError)) { throw new ExpectedError(e.toString()); } else { @@ -387,7 +389,7 @@ export default class PushCmd extends Command { protected async getBuildTarget(appOrDevice: string): Promise { const { validateLocalHostnameOrIp } = await import( - '../../utils/validation' + '../../utils/validation.js' ); return validateLocalHostnameOrIp(appOrDevice) diff --git a/lib/commands/releases/index.ts b/lib/commands/releases/index.ts index 49bf3897ab..72ef9e0b95 100644 --- a/lib/commands/releases/index.ts +++ b/lib/commands/releases/index.ts @@ -67,7 +67,7 @@ export default class ReleasesCmd extends Command { ]; const balena = getBalenaSdk(); - const { getFleetSlug } = await import('../../utils/sdk'); + const { getFleetSlug } = await import('../../utils/sdk.js'); const releases = await balena.models.release.getAllByApplication( await getFleetSlug(balena, params.fleet), diff --git a/lib/commands/scan/index.ts b/lib/commands/scan/index.ts index fd6fdcc22e..181ef3c57d 100644 --- a/lib/commands/scan/index.ts +++ b/lib/commands/scan/index.ts @@ -65,10 +65,10 @@ export default class ScanCmd extends Command { public async run() { const _ = await import('lodash'); const { discoverLocalBalenaOsDevices } = await import( - '../../utils/discover' + '../../utils/discover.js' ); const prettyjson = await import('prettyjson'); - const dockerUtils = await import('../../utils/docker'); + const dockerUtils = await import('../../utils/docker.js'); const dockerPort = 2375; const dockerTimeout = 2000; diff --git a/lib/commands/ssh/index.ts b/lib/commands/ssh/index.ts index 477736ffd0..c469d90d28 100644 --- a/lib/commands/ssh/index.ts +++ b/lib/commands/ssh/index.ts @@ -111,7 +111,9 @@ export default class SshCmd extends Command { // Local connection if (validateLocalHostnameOrIp(params.fleetOrDevice)) { - const { performLocalDeviceSSH } = await import('../../utils/device/ssh'); + const { performLocalDeviceSSH } = await import( + '../../utils/device/ssh.js' + ); return await performLocalDeviceSSH({ hostname: params.fleetOrDevice, port: options.port || 'local', @@ -122,8 +124,10 @@ export default class SshCmd extends Command { } // Remote connection - const { getProxyConfig } = await import('../../utils/helpers'); - const { getOnlineTargetDeviceUuid } = await import('../../utils/patterns'); + const { getProxyConfig } = await import('../../utils/helpers.js'); + const { getOnlineTargetDeviceUuid } = await import( + '../../utils/patterns.js' + ); const sdk = getBalenaSdk(); const proxyConfig = getProxyConfig(); @@ -137,7 +141,7 @@ export default class SshCmd extends Command { params.fleetOrDevice, ); - const { which } = await import('../../utils/which'); + const { which } = await import('../../utils/which.js'); const [whichProxytunnel, { username }, proxyUrl] = await Promise.all([ useProxy ? which('proxytunnel', false) : undefined, @@ -189,7 +193,7 @@ export default class SshCmd extends Command { let containerId: string | undefined; if (params.service != null) { const { getContainerIdForService } = await import( - '../../utils/device/ssh' + '../../utils/device/ssh.js' ); containerId = await getContainerIdForService({ deviceUuid, @@ -207,7 +211,7 @@ export default class SshCmd extends Command { } else { accessCommand = `host ${deviceUuid}`; } - const { runRemoteCommand } = await import('../../utils/ssh'); + const { runRemoteCommand } = await import('../../utils/ssh.js'); await runRemoteCommand({ cmd: accessCommand, hostname: `ssh.${proxyUrl}`, diff --git a/lib/commands/support/index.ts b/lib/commands/support/index.ts index 84af6f4cef..22030c13c2 100644 --- a/lib/commands/support/index.ts +++ b/lib/commands/support/index.ts @@ -116,7 +116,7 @@ export default class SupportCmd extends Command { ux.action.stop(); } - const { getFleetSlug } = await import('../../utils/sdk'); + const { getFleetSlug } = await import('../../utils/sdk.js'); // Process applications for (const appName of appNames) { diff --git a/lib/commands/tag/rm.ts b/lib/commands/tag/rm.ts index 057418f4c2..1eaaa6fc7f 100644 --- a/lib/commands/tag/rm.ts +++ b/lib/commands/tag/rm.ts @@ -72,12 +72,12 @@ export default class TagRmCmd extends Command { // Check user has specified one of application/device/release if (!options.fleet && !options.device && !options.release) { - const { ExpectedError } = await import('../../errors'); + const { ExpectedError } = await import('../../errors.js'); throw new ExpectedError(TagRmCmd.missingResourceMessage); } if (options.fleet) { - const { getFleetSlug } = await import('../../utils/sdk'); + const { getFleetSlug } = await import('../../utils/sdk.js'); return balena.models.application.tags.remove( await getFleetSlug(balena, options.fleet), params.tagKey, @@ -88,7 +88,7 @@ export default class TagRmCmd extends Command { } if (options.release) { const { disambiguateReleaseParam } = await import( - '../../utils/normalization' + '../../utils/normalization.js' ); const releaseParam = await disambiguateReleaseParam( balena, diff --git a/lib/commands/tag/set.ts b/lib/commands/tag/set.ts index d77e419083..77d9bec761 100644 --- a/lib/commands/tag/set.ts +++ b/lib/commands/tag/set.ts @@ -85,14 +85,14 @@ export default class TagSetCmd extends Command { // Check user has specified one of application/device/release if (!options.fleet && !options.device && !options.release) { - const { ExpectedError } = await import('../../errors'); + const { ExpectedError } = await import('../../errors.js'); throw new ExpectedError(TagSetCmd.missingResourceMessage); } params.value ??= ''; if (options.fleet) { - const { getFleetSlug } = await import('../../utils/sdk'); + const { getFleetSlug } = await import('../../utils/sdk.js'); return balena.models.application.tags.set( await getFleetSlug(balena, options.fleet), params.tagKey, @@ -108,7 +108,7 @@ export default class TagSetCmd extends Command { } if (options.release) { const { disambiguateReleaseParam } = await import( - '../../utils/normalization' + '../../utils/normalization.js' ); const releaseParam = await disambiguateReleaseParam( balena, diff --git a/lib/commands/tags/index.ts b/lib/commands/tags/index.ts index 9653c396b7..a7a7cbc5c8 100644 --- a/lib/commands/tags/index.ts +++ b/lib/commands/tags/index.ts @@ -71,7 +71,7 @@ export default class TagsCmd extends Command { let tags; if (options.fleet) { - const { getFleetSlug } = await import('../../utils/sdk'); + const { getFleetSlug } = await import('../../utils/sdk.js'); tags = await balena.models.application.tags.getAllByApplication( await getFleetSlug(balena, options.fleet), ); @@ -81,7 +81,7 @@ export default class TagsCmd extends Command { } if (options.release) { const { disambiguateReleaseParam } = await import( - '../../utils/normalization' + '../../utils/normalization.js' ); const releaseParam = await disambiguateReleaseParam( balena, diff --git a/lib/commands/tunnel/index.ts b/lib/commands/tunnel/index.ts index 91be2fe603..bac32073a4 100644 --- a/lib/commands/tunnel/index.ts +++ b/lib/commands/tunnel/index.ts @@ -122,7 +122,9 @@ export default class TunnelCmd extends Command { } // Ascertain device uuid - const { getOnlineTargetDeviceUuid } = await import('../../utils/patterns'); + const { getOnlineTargetDeviceUuid } = await import( + '../../utils/patterns.js' + ); const uuid = await getOnlineTargetDeviceUuid(sdk, params.deviceOrFleet); logger.logInfo(`Opening a tunnel to ${uuid}...`); @@ -134,7 +136,7 @@ export default class TunnelCmd extends Command { .map(async ({ localPort, localAddress, remotePort }) => { try { const { tunnelConnectionToDevice } = await import( - '../../utils/tunnel' + '../../utils/tunnel.js' ); const handler = await tunnelConnectionToDevice(uuid, remotePort, sdk); diff --git a/lib/commands/version/index.ts b/lib/commands/version/index.ts index 9c59a8cc19..1fa1c2e27d 100644 --- a/lib/commands/version/index.ts +++ b/lib/commands/version/index.ts @@ -72,7 +72,7 @@ export default class VersionCmd extends Command { public async run() { const { flags: options } = await this.parse(VersionCmd); const versions: JsonVersions = { - 'balena-cli': (await import('../../../package.json')).version, + 'balena-cli': (await import('../../../package.json')).default.version, 'Node.js': process.version && process.version.startsWith('v') ? process.version.slice(1) diff --git a/lib/deprecation.ts b/lib/deprecation.ts index 7a8762bb29..c55f74cc2f 100644 --- a/lib/deprecation.ts +++ b/lib/deprecation.ts @@ -102,7 +102,7 @@ export class DeprecationChecker { protected async fetchPublishedTimestampForVersion( version: string, ): Promise { - const { default: got } = await import('got'); + const { default: got } = (await import('got')).default; const url = this.getNpmUrl(version); let response: import('got').Response> | undefined; try { @@ -198,7 +198,7 @@ or release date not available`); const nextMajorDate = new Date(nextMajorDateStr).getTime(); const daysElapsed = Math.trunc((this.now - nextMajorDate) / this.msInDay); if (daysElapsed > this.expiryDays) { - const { ExpectedError } = await import('./errors'); + const { ExpectedError } = await import('./errors.js'); throw new ExpectedError(this.getExpiryMsg(daysElapsed)); } else if (daysElapsed > this.deprecationDays && process.stderr.isTTY) { console.error(this.getDeprecationMsg(daysElapsed)); diff --git a/lib/events.ts b/lib/events.ts index fd0f74f6a2..fef266bfbc 100644 --- a/lib/events.ts +++ b/lib/events.ts @@ -44,7 +44,7 @@ export async function trackCommand(commandSignature: string) { scope.setExtra('command', commandSignature); }); } - const { getCachedUsername } = await import('./utils/bootstrap'); + const { getCachedUsername } = await import('./utils/bootstrap.js'); let username: string | undefined; try { username = (await getCachedUsername())?.username; @@ -79,7 +79,7 @@ const TIMEOUT = 4000; * Make the event tracking HTTPS request to balenaCloud's '/mixpanel' endpoint. */ async function sendEvent(balenaUrl: string, event: string, username?: string) { - const { default: got } = await import('got'); + const { default: got } = (await import('got')).default; const trackData = { api_key: 'balena-main', events: [ diff --git a/lib/fast-boot.ts b/lib/fast-boot.ts index d66dd499cd..fd2718f915 100644 --- a/lib/fast-boot.ts +++ b/lib/fast-boot.ts @@ -74,7 +74,7 @@ async function $start() { stat(path.join(root, 'npm-shrinkwrap.json'), { bigint: true }), ]); // Include timestamps to account for dev-time changes to node_modules - const cacheKiller = `${pJson.version}-${pStat.mtimeMs}-${nStat.mtimeMs}`; + const cacheKiller = `${pJson.default.version}-${pStat.mtimeMs}-${nStat.mtimeMs}`; require('fast-boot2').start({ cacheFile, cacheKiller, diff --git a/lib/help.ts b/lib/help.ts index e9644fee21..39796bc537 100644 --- a/lib/help.ts +++ b/lib/help.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import { Help } from '@oclif/core'; -import * as indent from 'indent-string'; +import indent from 'indent-string'; import { getChalk } from './utils/lazy'; // Partially overrides standard implementation of help plugin diff --git a/lib/hooks/prerun/track.ts b/lib/hooks/prerun/track.ts index c57061aa02..434ff534a2 100644 --- a/lib/hooks/prerun/track.ts +++ b/lib/hooks/prerun/track.ts @@ -33,7 +33,7 @@ export const trackPromise = new Promise((resolve) => { * literally so: 'NAME' and 'VALUE' are NOT replaced with actual values. */ const hook: Hook<'prerun'> = async function (options) { - const events = await import('../../events'); + const events = await import('../../events.js'); const usage: string | string[] | undefined = options.Command.usage; const cmdSignature = usage == null ? '*' : typeof usage === 'string' ? usage : usage.join(' '); diff --git a/lib/preparser.ts b/lib/preparser.ts index b09418a86c..35161fb627 100644 --- a/lib/preparser.ts +++ b/lib/preparser.ts @@ -68,7 +68,7 @@ export async function preparseArgs(argv: string[]): Promise { process.env.BLUEBIRD_LONG_STACK_TRACES = '1'; } - const Logger = await import('./utils/logger'); + const Logger = await import('./utils/logger.js'); Logger.command = cmdSlice[0]; let args = cmdSlice; @@ -157,7 +157,7 @@ Please use "balena ${alternative}" instead.`); // Check if this is a space separated 'topic command' style command subcommand (e.g. `end add`) // by comparing with oclif style colon-separated subcommand list (e.g. `env:add`) export async function isSubcommand(args: string[]) { - const { getCommandIdsFromManifest } = await import('./utils/oclif-utils'); + const { getCommandIdsFromManifest } = await import('./utils/oclif-utils.js'); const commandIds = await getCommandIdsFromManifest(); return commandIds.includes(`${args[0] || ''}:${args[1] || ''}`); } diff --git a/lib/utils/application-create.ts b/lib/utils/application-create.ts index 072b561cde..74ae562ec9 100644 --- a/lib/utils/application-create.ts +++ b/lib/utils/application-create.ts @@ -18,12 +18,12 @@ export async function applicationCreateBase( ) { // Ascertain device type const deviceType = - options.type || (await (await import('./patterns')).selectDeviceType()); + options.type || (await (await import('./patterns.js')).selectDeviceType()); // Ascertain organization const organization = options.organization?.toLowerCase() || - (await (await import('./patterns')).getAndSelectOrganization()); + (await (await import('./patterns.js')).getAndSelectOrganization()); // Create application try { diff --git a/lib/utils/bootstrap.ts b/lib/utils/bootstrap.ts index bcf5c5876e..21e7ee6163 100644 --- a/lib/utils/bootstrap.ts +++ b/lib/utils/bootstrap.ts @@ -139,7 +139,7 @@ export async function getCachedUsername(): Promise { return cachedUsername; } const [{ getBalenaSdk }, { getStorage }, settings] = await Promise.all([ - import('./lazy'), + import('./lazy.js'), import('balena-settings-storage'), import('balena-settings-client'), ]); diff --git a/lib/utils/cloud.ts b/lib/utils/cloud.ts index 1546441ded..536f11a201 100644 --- a/lib/utils/cloud.ts +++ b/lib/utils/cloud.ts @@ -206,7 +206,7 @@ async function resolveOSVersion( false, ); } - const { normalizeOsVersion } = await import('./normalization'); + const { normalizeOsVersion } = await import('./normalization.js'); version = normalizeOsVersion(version); return version; } diff --git a/lib/utils/compose.ts b/lib/utils/compose.ts index a9f8d09c29..5543115e8d 100644 --- a/lib/utils/compose.ts +++ b/lib/utils/compose.ts @@ -479,10 +479,8 @@ export class BuildProgressUI implements Renderer { } _renderStatus(end = false) { - const moment = require('moment') as typeof import('moment'); - ( - require('moment-duration-format') as typeof import('moment-duration-format') - )(moment); + const moment = require('moment'); + require('moment-duration-format')(moment); this._tty.clearLine(); this._tty.write(this._prefix); @@ -577,10 +575,8 @@ export class BuildProgressInline implements Renderer { } end(summary?: Dictionary) { - const moment = require('moment') as typeof import('moment'); - ( - require('moment-duration-format') as typeof import('moment-duration-format') - )(moment); + const moment = require('moment'); + require('moment-duration-format')(moment); if (this._ended) { return; diff --git a/lib/utils/compose_ts.ts b/lib/utils/compose_ts.ts index 8cb9ae5b1c..21eabf099d 100644 --- a/lib/utils/compose_ts.ts +++ b/lib/utils/compose_ts.ts @@ -117,7 +117,7 @@ export async function loadProject( imageTag?: string, ): Promise { const compose = await import('@balena/compose/dist/parse'); - const { createProject } = await import('./compose'); + const { createProject } = await import('./compose.js'); let composeName: string; let composeStr: string; @@ -265,7 +265,7 @@ export async function buildProject( const renderer = await startRenderer({ imageDescriptors, ...opts }); let buildSummaryByService: Dictionary | undefined; try { - const { awaitInterruptibleTask } = await import('./helpers'); + const { awaitInterruptibleTask } = await import('./helpers.js'); const [images, summaryMsgByService] = await awaitInterruptibleTask( $buildProject, imageDescriptors, @@ -330,7 +330,7 @@ async function $buildProject( logger.logDebug('Prepared tasks; building...'); - const { BALENA_ENGINE_TMP_PATH } = await import('../config'); + const { BALENA_ENGINE_TMP_PATH } = await import('../config.js'); const builder = await import('@balena/compose/dist/multibuild'); const builtImages = await builder.performBuilds( @@ -358,13 +358,14 @@ async function startRenderer({ }): Promise { let renderer: Renderer; if (inlineLogs) { - renderer = new (await import('./compose')).BuildProgressInline( + renderer = new (await import('./compose.js')).BuildProgressInline( logger.streams['build'], imageDescriptors, ); } else { - const tty = (await import('./tty'))(process.stdout); - renderer = new (await import('./compose')).BuildProgressUI( + const { default: $tty } = await import('./tty.js'); + const tty = $tty(process.stdout); + renderer = new (await import('./compose.js')).BuildProgressUI( tty, imageDescriptors, ); @@ -388,7 +389,7 @@ async function installQemuIfNeeded({ logger: Logger; projectPath: string; }): Promise { - const qemu = await import('./qemu'); + const qemu = await import('./qemu.js'); const needsQemu = await qemu.installQemuIfNeeded( emulated, logger, @@ -471,7 +472,7 @@ async function qemuTransposeBuildStream({ dockerfilePath?: string; projectPath: string; }): Promise { - const qemu = await import('./qemu'); + const qemu = await import('./qemu.js'); const binPath = qemu.qemuPathInContext( path.join(projectPath, task.context ?? ''), ); @@ -681,7 +682,7 @@ export async function getServiceDirsFromComposition( sourceDir: string, composition?: Composition, ): Promise> { - const { createProject } = await import('./compose'); + const { createProject } = await import('./compose.js'); const serviceDirs: Dictionary = {}; if (!composition) { const [, composeStr] = await resolveProject( @@ -757,7 +758,7 @@ export async function tarDirectory( preFinalizeCallback, }: TarDirectoryOptions, ): Promise { - const { filterFilesWithDockerignore } = await import('./ignore'); + const { filterFilesWithDockerignore } = await import('./ignore.js'); const { toPosixPath } = (await import('@balena/compose/dist/multibuild')) .PathUtils; @@ -891,7 +892,7 @@ export async function checkBuildSecretsRequirements( ) { const [metaObj, metaFilename] = await loadBuildMetatada(sourceDir); if (metaObj && !_.isEmpty(metaObj['build-secrets'])) { - const dockerUtils = await import('./docker'); + const dockerUtils = await import('./docker.js'); const isBalenaEngine = await dockerUtils.isBalenaEngine(docker); if (!isBalenaEngine) { throw new ExpectedError(stripIndent` @@ -1222,7 +1223,7 @@ async function getTokenForPreviousRepos( taggedImages: TaggedImage[], ): Promise { logger.logDebug('Authorizing push...'); - const { authorizePush, getPreviousRepos } = await import('./compose'); + const { authorizePush, getPreviousRepos } = await import('./compose.js'); const sdk = getBalenaSdk(); const previousRepos = await getPreviousRepos(sdk, logger, appId); @@ -1246,9 +1247,10 @@ async function pushAndUpdateServiceImages( ) => Promise, ) { const { DockerProgress } = await import('docker-progress'); - const { retry } = await import('./helpers'); - const { pushProgressRenderer } = await import('./compose'); - const tty = (await import('./tty'))(process.stdout); + const { retry } = await import('./helpers.js'); + const { pushProgressRenderer } = await import('./compose.js'); + const { default: $tty } = await import('./tty.js'); + const tty = $tty(process.stdout); const opts = { authconfig: { registrytoken: token } }; const progress = new DockerProgress({ docker }); const renderer = pushProgressRenderer( @@ -1361,8 +1363,9 @@ export async function deployProject( isDraft: boolean, ): Promise { const releaseMod = await import('@balena/compose/dist/release'); - const { createRelease, tagServiceImages } = await import('./compose'); - const tty = (await import('./tty'))(process.stdout); + const { createRelease, tagServiceImages } = await import('./compose.js'); + const { default: $tty } = await import('./tty.js'); + const tty = $tty(process.stdout); const prefix = getChalk().cyan('[Info]') + ' '; const spinner = createSpinner(); @@ -1397,7 +1400,7 @@ export async function deployProject( logger.logDebug('Tagging images...'); const taggedImages = await tagServiceImages(docker, images, serviceImages); try { - const { awaitInterruptibleTask } = await import('./helpers'); + const { awaitInterruptibleTask } = await import('./helpers.js'); // awaitInterruptibleTask throws SIGINTError on CTRL-C, // causing the release status to be set to 'failed' await awaitInterruptibleTask(async () => { diff --git a/lib/utils/config.ts b/lib/utils/config.ts index 5194822525..3275c726b8 100644 --- a/lib/utils/config.ts +++ b/lib/utils/config.ts @@ -161,13 +161,13 @@ export async function validateDevOptionAndWarn( return; } if (version && /\bprod\b/.test(version)) { - const { ExpectedError } = await import('../errors'); + const { ExpectedError } = await import('../errors.js'); throw new ExpectedError( `Error: The '--dev' option conflicts with production balenaOS version '${version}'`, ); } if (!logger) { - const Logger = await import('./logger'); + const { default: Logger } = await import('./logger.js'); logger = Logger.getLogger(); } logger.logInfo(stripIndent` @@ -192,7 +192,7 @@ export async function validateSecureBootOptionAndWarn( if (!secureBoot) { return; } - const { ExpectedError } = await import('../errors'); + const { ExpectedError } = await import('../errors.js'); if (!version) { throw new ExpectedError(`Error: No version provided`); } @@ -215,7 +215,7 @@ export async function validateSecureBootOptionAndWarn( }) ) { if (!logger) { - const Logger = await import('./logger'); + const { default: Logger } = await import('./logger.js'); logger = Logger.getLogger(); } logger.logInfo(stripIndent` diff --git a/lib/utils/device/api.ts b/lib/utils/device/api.ts index 7687ed255f..62f2b67b24 100644 --- a/lib/utils/device/api.ts +++ b/lib/utils/device/api.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import * as _ from 'lodash'; -import * as request from 'request'; +import request from 'request'; import type * as Stream from 'stream'; import { retry } from '../helpers'; diff --git a/lib/utils/device/deploy.ts b/lib/utils/device/deploy.ts index 018467e825..9c5e64ae55 100644 --- a/lib/utils/device/deploy.ts +++ b/lib/utils/device/deploy.ts @@ -16,7 +16,7 @@ */ import * as semver from 'balena-semver'; -import * as Docker from 'dockerode'; +import Docker from 'dockerode'; import * as _ from 'lodash'; import type { Composition } from '@balena/compose/dist/parse'; import type { @@ -215,7 +215,7 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise { imageIds = {}; } - const { awaitInterruptibleTask } = await import('../helpers'); + const { awaitInterruptibleTask } = await import('../helpers.js'); const buildTasks = await awaitInterruptibleTask( performBuilds, project.composition, @@ -295,7 +295,7 @@ async function streamDeviceLogs( return; } globalLogger.logInfo('Streaming device logs...'); - const { connectAndDisplayDeviceLogs } = await import('./logs'); + const { connectAndDisplayDeviceLogs } = await import('./logs.js'); return connectAndDisplayDeviceLogs({ deviceApi, logger: globalLogger, diff --git a/lib/utils/device/live.ts b/lib/utils/device/live.ts index 817581273e..667b31fe6e 100644 --- a/lib/utils/device/live.ts +++ b/lib/utils/device/live.ts @@ -108,8 +108,8 @@ export class LivepushManager { this.logger.logLivepush('Device state settled'); // Prepare dockerignore data for file watcher - const { getDockerignoreByService } = await import('../ignore'); - const { getServiceDirsFromComposition } = await import('../compose_ts'); + const { getDockerignoreByService } = await import('../ignore.js'); + const { getServiceDirsFromComposition } = await import('../compose_ts.js'); const rootContext = path.resolve(this.buildContext); const serviceDirsByService = await getServiceDirsFromComposition( this.deployOpts.source, diff --git a/lib/utils/device/logs.ts b/lib/utils/device/logs.ts index 267ba1f4c1..2786600c0d 100644 --- a/lib/utils/device/logs.ts +++ b/lib/utils/device/logs.ts @@ -62,7 +62,7 @@ async function displayDeviceLogs( system: boolean, filterServices?: string[], ): Promise { - const { addSIGINTHandler } = await import('../helpers'); + const { addSIGINTHandler } = await import('../helpers.js'); const { parse: ndjsonParse } = await import('ndjson'); let gotSignal = false; const handleSignal = () => { @@ -125,7 +125,7 @@ export async function connectAndDisplayDeviceLogs({ return displayDeviceLogs(logStream, logger, system, filterServices); } - const { retry } = await import('../../utils/helpers'); + const { retry } = await import('../../utils/helpers.js'); try { await retry({ func: connectAndDisplay, diff --git a/lib/utils/discover.ts b/lib/utils/discover.ts index 7694558256..25e1c30973 100644 --- a/lib/utils/discover.ts +++ b/lib/utils/discover.ts @@ -21,7 +21,7 @@ export async function discoverLocalBalenaOsDevices( ): Promise { const services = await new Promise((resolve) => { const bonjour = new Bonjour({}, async (err: string | Error) => { - await (await import('../errors')).handleError(err); + await (await import('../errors.js')).handleError(err); }); const resinSshServices: Service[] = []; const browser = bonjour.find(avahiBalenaSshConfig, (service) => diff --git a/lib/utils/docker.ts b/lib/utils/docker.ts index f93ecf0367..58b414c137 100644 --- a/lib/utils/docker.ts +++ b/lib/utils/docker.ts @@ -186,7 +186,7 @@ export async function getDocker( export async function createClient( opts: dockerode.DockerOptions, ): Promise { - const Docker = await import('dockerode'); + const { default: Docker } = await import('dockerode'); return new Docker(opts); } diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index 8d040383f6..f29cd68a85 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -77,7 +77,7 @@ export async function sudo( isCLIcmd, }: { stderr?: NodeJS.WritableStream; msg?: string; isCLIcmd?: boolean } = {}, ) { - const { executeWithPrivileges } = await import('./sudo'); + const { executeWithPrivileges } = await import('./sudo.js'); if (process.platform !== 'win32') { console.log( @@ -115,7 +115,7 @@ export async function getManifest( manifest.slug !== deviceType && manifest.slug !== (await sdk.models.deviceType.get(deviceType)).slug ) { - const { ExpectedError } = await import('../errors'); + const { ExpectedError } = await import('../errors.js'); throw new ExpectedError( `The device type of the provided OS image ${manifest.slug}, does not match the expected device type ${deviceType}`, ); @@ -182,7 +182,7 @@ export async function osProgressHandler(step: InitializeEmitter) { } export async function getAppWithArch(applicationName: string) { - const { getApplication } = await import('./sdk'); + const { getApplication } = await import('./sdk.js'); const balena = getBalenaSdk(); const app = await getApplication(balena, applicationName, { $expand: { @@ -239,7 +239,7 @@ export async function retry({ backoffScaler?: number; maxSingleDelayMs?: number; }): Promise { - const { SIGINTError } = await import('../errors'); + const { SIGINTError } = await import('../errors.js'); let delayMs = initialDelayMs; for (let count = 0; count < maxAttempts - 1; count++) { const lastAttemptMs = Date.now(); diff --git a/lib/utils/ignore.ts b/lib/utils/ignore.ts index dcc8d5a3a9..a9be22752f 100644 --- a/lib/utils/ignore.ts +++ b/lib/utils/ignore.ts @@ -104,7 +104,7 @@ export async function getDockerIgnoreInstance( ): Promise { const dockerIgnoreStr = await readDockerIgnoreFile(directory); const $dockerIgnore = (await import('@balena/dockerignore')).default; - const ig = $dockerIgnore({ ignorecase: false }); + const ig = $dockerIgnore.default({ ignorecase: false }); ig.add(['**/.git']); if (dockerIgnoreStr) { diff --git a/lib/utils/patterns.ts b/lib/utils/patterns.ts index ebae0aa630..18e6a1f332 100644 --- a/lib/utils/patterns.ts +++ b/lib/utils/patterns.ts @@ -28,8 +28,9 @@ import { instanceOf, NotLoggedInError, ExpectedError } from '../errors'; import { getBalenaSdk, getVisuals, stripIndent, getCliForm } from './lazy'; import validation = require('./validation'); import { delay } from './helpers'; +import type Bluebird from 'bluebird'; -export function authenticate(options: object): Promise { +export function authenticate(options: object): Bluebird { const balena = getBalenaSdk(); return getCliForm() .run( @@ -229,7 +230,7 @@ export async function selectOrganization( } export async function getAndSelectOrganization() { - const { getOwnOrganizations } = await import('./sdk'); + const { getOwnOrganizations } = await import('./sdk.js'); const organizations = await getOwnOrganizations(getBalenaSdk(), { $select: ['name', 'handle'], }); @@ -304,7 +305,8 @@ export async function getOnlineTargetDeviceUuid( sdk: BalenaSDK, fleetOrDevice: string, ) { - const logger = (await import('../utils/logger')).getLogger(); + const { default: Logger } = await import('../utils/logger.js'); + const logger = Logger.getLogger(); // If looks like UUID, probably device if (validation.validateUuid(fleetOrDevice)) { @@ -337,7 +339,7 @@ export async function getOnlineTargetDeviceUuid( const application = await (async () => { try { logger.logDebug(`Fetching fleet ${fleetOrDevice}`); - const { getApplication } = await import('./sdk'); + const { getApplication } = await import('./sdk.js'); return await getApplication(sdk, fleetOrDevice, { $select: ['id', 'slug'], $expand: { @@ -382,7 +384,7 @@ export async function getOnlineTargetDeviceUuid( export function selectFromList( message: string, choices: Array, -): Promise { +): Bluebird { return getCliForm().ask({ message, type: 'list', diff --git a/lib/utils/promote.ts b/lib/utils/promote.ts index 805dc259ea..e7f8165d4f 100644 --- a/lib/utils/promote.ts +++ b/lib/utils/promote.ts @@ -167,7 +167,7 @@ const dockerPort = 2375; const dockerTimeout = 2000; async function selectLocalBalenaOsDevice(timeout = 4000): Promise { - const { discoverLocalBalenaOsDevices } = await import('../utils/discover'); + const { discoverLocalBalenaOsDevices } = await import('../utils/discover.js'); const { SpinnerPromise } = getVisuals(); const devices = await new SpinnerPromise({ promise: discoverLocalBalenaOsDevices(timeout), @@ -176,7 +176,7 @@ async function selectLocalBalenaOsDevice(timeout = 4000): Promise { }); const responsiveDevices: typeof devices = []; - const Docker = await import('dockerode'); + const { default: Docker } = await import('dockerode'); await Promise.all( devices.map(async function (device) { const address = device?.address; @@ -231,7 +231,7 @@ async function selectAppFromList( applications: ApplicationWithDeviceTypeSlug[], ): Promise { const _ = await import('lodash'); - const { selectFromList } = await import('../utils/patterns'); + const { selectFromList } = await import('../utils/patterns.js'); // Present a list to the user which shows the fully qualified fleet // name (user/fleetname) and allows them to select. @@ -384,7 +384,7 @@ async function createApplication( deviceType: string, name?: string, ): Promise { - const validation = await import('./validation'); + const validation = await import('./validation.js'); let username: string; try { @@ -447,7 +447,7 @@ async function generateApplicationConfig( appUpdatePollInterval?: number; }, ) { - const { generateApplicationConfig: configGen } = await import('./config'); + const { generateApplicationConfig: configGen } = await import('./config.js'); const manifest = await sdk.models.config.getDeviceTypeManifestBySlug( app.is_for__device_type[0].slug, diff --git a/lib/utils/qemu.ts b/lib/utils/qemu.ts index a9e379dc5b..ed54254f0c 100644 --- a/lib/utils/qemu.ts +++ b/lib/utils/qemu.ts @@ -94,7 +94,7 @@ async function installQemu(arch: string, qemuPath: string) { const urlVersion = encodeURIComponent(QEMU_VERSION); const qemuUrl = `https://github.com/balena-io/qemu/releases/download/${urlVersion}/${urlFile}`; - const request = await import('request'); + const { default: request } = await import('request'); const fs = await import('fs'); const zlib = await import('zlib'); const tar = await import('tar-stream'); diff --git a/lib/utils/remote-build.ts b/lib/utils/remote-build.ts index 353b653d51..1887fc9f3d 100644 --- a/lib/utils/remote-build.ts +++ b/lib/utils/remote-build.ts @@ -126,7 +126,7 @@ export async function startRemoteBuild( } }; - const { addSIGINTHandler } = await import('./helpers'); + const { addSIGINTHandler } = await import('./helpers.js'); addSIGINTHandler(sigintHandler); try { diff --git a/lib/utils/sdk.ts b/lib/utils/sdk.ts index 0df612df2f..4e95833fc0 100644 --- a/lib/utils/sdk.ts +++ b/lib/utils/sdk.ts @@ -42,7 +42,7 @@ export async function getApplication( nameOrSlugOrId: string | number, options?: PineOptions, ): Promise { - const { looksLikeFleetSlug } = await import('./validation'); + const { looksLikeFleetSlug } = await import('./validation.js'); const whoamiResult = await sdk.auth.whoami(); const isDeviceActor = whoamiResult?.actorType === 'device'; @@ -97,7 +97,7 @@ export async function getFleetSlug( sdk: BalenaSDK, nameOrSlug: string, ): Promise { - const { looksLikeFleetSlug } = await import('./validation'); + const { looksLikeFleetSlug } = await import('./validation.js'); if (!looksLikeFleetSlug(nameOrSlug)) { // Not a slug: must be an app name. // TODO: revisit this logic when we add support for fleet UUIDs. diff --git a/lib/utils/ssh.ts b/lib/utils/ssh.ts index 6613b2cf1d..3e8527d9d6 100644 --- a/lib/utils/ssh.ts +++ b/lib/utils/ssh.ts @@ -127,7 +127,7 @@ export async function runRemoteCommand({ } else { ignoreStdin = false; } - const { which } = await import('./which'); + const { which } = await import('./which.js'); const program = await which('ssh'); const args = sshArgsForRemoteCommand({ cmd, @@ -140,7 +140,7 @@ export async function runRemoteCommand({ }); if (process.env.DEBUG) { - const logger = (await import('./logger')).getLogger(); + const logger = (await import('./logger.js')).default.getLogger(); logger.logDebug(`Executing [${program},${args}]`); } @@ -296,11 +296,11 @@ export const findBestUsernameForDevice = _.memoize( if (await isRootUserGood(hostname, port)) { username = 'root'; } else { - const { getCachedUsername } = await import('./bootstrap'); + const { getCachedUsername } = await import('./bootstrap.js'); username = (await getCachedUsername())?.username; } if (!username) { - const { stripIndent } = await import('./lazy'); + const { stripIndent } = await import('./lazy.js'); throw new ExpectedError(stripIndent` SSH authentication failed for 'root@${hostname}'. Please login with 'balena login' for alternative authentication.`); diff --git a/lib/utils/sudo.ts b/lib/utils/sudo.ts index 603b89af87..3e8953dd3f 100644 --- a/lib/utils/sudo.ts +++ b/lib/utils/sudo.ts @@ -43,8 +43,8 @@ export async function executeWithPrivileges( isCLIcmd = true, ): Promise { // whether the CLI is already running with admin / super user privileges - const isElevated = await (await import('is-elevated'))(); - const { shellEscape } = await import('./helpers'); + const isElevated = await (await import('is-elevated')).default(); + const { shellEscape } = await import('./helpers.js'); const opts: SpawnOptions = { env: process.env, stdio: ['inherit', 'inherit', stderr ? 'pipe' : 'inherit'], diff --git a/lib/utils/umount.ts b/lib/utils/umount.ts index 335a953690..37ab045eb5 100644 --- a/lib/utils/umount.ts +++ b/lib/utils/umount.ts @@ -39,7 +39,7 @@ export async function umount(device: string): Promise { if (process.platform === 'win32') { return; } - const { sanitizePath, whichBin } = await import('./which'); + const { sanitizePath, whichBin } = await import('./which.js'); // sanitize user's input (regular expression attacks ?) device = sanitizePath(device); const cmd: string[] = []; @@ -48,7 +48,7 @@ export async function umount(device: string): Promise { cmd.push('/usr/sbin/diskutil', 'unmountDisk', 'force', device); } else { // Linux - const glob = promisify(await import('glob')); + const glob = promisify((await import('glob')).default); // '?*' expands a base device path like '/dev/sdb' to an array of paths // like '/dev/sdb1', '/dev/sdb2', ..., '/dev/sdb11', ... (partitions) // that exist for balenaOS images and are needed as arguments to 'umount' @@ -75,7 +75,7 @@ export async function umount(device: string): Promise { } return; } - const { ExpectedError } = await import('../errors'); + const { ExpectedError } = await import('../errors.js'); throw new ExpectedError(msg.join('\n')); } } @@ -92,7 +92,7 @@ export async function isMounted(device: string): Promise { if (!device) { return false; } - const { whichBin } = await import('./which'); + const { whichBin } = await import('./which.js'); const mountCmd = await whichBin('mount'); let stdout = ''; let stderr = ''; @@ -101,7 +101,7 @@ export async function isMounted(device: string): Promise { stdout = proc.stdout; stderr = proc.stderr; } catch (err) { - const { ExpectedError } = await import('../errors'); + const { ExpectedError } = await import('../errors.js'); throw new ExpectedError( `Error executing "${mountCmd}":\n${stderr}\n${err.message}`, ); @@ -131,7 +131,7 @@ export async function denyMount( handler: () => any, opts: { autoMountOnSuccess?: boolean; executablePath?: string } = {}, ) { - const denymount = promisify(await import('denymount')); + const denymount = promisify((await import('denymount')).default); if (process.pkg) { // when running in a standalone pkg install, the 'denymount' // executable is placed on the same folder as process.execPath diff --git a/lib/utils/update.ts b/lib/utils/update.ts index caf1ca2e73..918acc9263 100644 --- a/lib/utils/update.ts +++ b/lib/utils/update.ts @@ -15,7 +15,7 @@ limitations under the License. */ import isRoot = require('is-root'); -import * as UpdateNotifier from 'update-notifier'; +import UpdateNotifier from 'update-notifier'; import packageJSON = require('../../package.json'); diff --git a/lib/utils/which.ts b/lib/utils/which.ts index d35b72bb10..af7cafe607 100644 --- a/lib/utils/which.ts +++ b/lib/utils/which.ts @@ -76,14 +76,14 @@ export async function which( program: string, rejectOnMissing = true, ): Promise { - const whichMod = await import('which'); + const { default: whichMod } = await import('which'); let programPath: string; try { programPath = await whichMod(program); } catch (err) { if (err.code === 'ENOENT') { if (rejectOnMissing) { - const { ExpectedError } = await import('../errors'); + const { ExpectedError } = await import('../errors.js'); throw new ExpectedError( `'${program}' program not found. Is it installed?`, ); diff --git a/tests/auth/utils.spec.ts b/tests/auth/utils.spec.ts index ad1e8285e9..793ff4985b 100644 --- a/tests/auth/utils.spec.ts +++ b/tests/auth/utils.spec.ts @@ -1,4 +1,4 @@ -import * as Bluebird from 'bluebird'; +import Bluebird from 'bluebird'; import { expect } from 'chai'; import rewire = require('rewire'); import * as sinon from 'sinon'; diff --git a/tests/commands/build.spec.ts b/tests/commands/build.spec.ts index d402f551ae..3184edd9d0 100644 --- a/tests/commands/build.spec.ts +++ b/tests/commands/build.spec.ts @@ -17,7 +17,7 @@ import { expect } from 'chai'; import * as _ from 'lodash'; -import * as mock from 'mock-require'; +import mock from 'mock-require'; import { promises as fs } from 'fs'; import * as path from 'path'; diff --git a/tests/commands/ssh.spec.ts b/tests/commands/ssh.spec.ts index 4e67b7e484..22f7e8e946 100644 --- a/tests/commands/ssh.spec.ts +++ b/tests/commands/ssh.spec.ts @@ -16,7 +16,7 @@ */ import { expect } from 'chai'; -import mock = require('mock-require'); +import mock from 'mock-require'; import type { Server } from 'net'; import { createServer } from 'net'; @@ -149,7 +149,7 @@ describe('balena ssh', function () { /** Check whether the 'ssh' tool (executable) exists in the PATH */ async function checkSsh(): Promise { - const { which } = await import('../../build/utils/which'); + const { which } = await import('../../build/utils/which.js'); const sshPath = await which('ssh', false); if ((sshPath || '').includes('\\Windows\\System32\\OpenSSH\\ssh')) { // don't use Windows' built-in ssh tool for these test cases diff --git a/tests/helpers.ts b/tests/helpers.ts index dddf112e55..fd701da570 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -90,8 +90,8 @@ export function filterCliOutputForTests({ * @param cmd Command to execute, e.g. `push myApp` (without 'balena' prefix) */ async function runCommandInProcess(cmd: string): Promise { - const balenaCLI = await import('../build/app'); - const intercept = await import('intercept-stdout'); + const balenaCLI = await import('../build/app.js'); + const { default: intercept } = await import('intercept-stdout'); const preArgs = [process.argv[0], path.join(process.cwd(), 'bin', 'balena')]; @@ -236,7 +236,7 @@ export async function runCommand(cmd: string): Promise { } catch { throw new Error(`Standalone executable not found: "${standalonePath}"`); } - const proxy = await import('./nock/proxy-server'); + const proxy = await import('./nock/proxy-server.js'); const [proxyPort] = await proxy.createProxyServerOnce(); return runCommandInSubprocess(cmd, proxyPort); } else { @@ -353,7 +353,7 @@ export function deepJsonParse(data: any): any { export async function switchSentry( enabled: boolean | undefined, ): Promise { - const balenaCLI = await import('../build/app'); + const balenaCLI = await import('../build/app.js'); const sentryOpts = (await balenaCLI.setupSentry()).getClient()?.getOptions(); if (sentryOpts) { const sentryStatus = sentryOpts.enabled; diff --git a/tests/nock/nock-mock.ts b/tests/nock/nock-mock.ts index 04ce0d6dca..2b2ce10c57 100644 --- a/tests/nock/nock-mock.ts +++ b/tests/nock/nock-mock.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as nock from 'nock'; +import nock from 'nock'; import * as fs from 'fs'; export interface ScopeOpts { diff --git a/tests/utils/device/live.spec.ts b/tests/utils/device/live.spec.ts index 844c01d245..5baf2fe039 100644 --- a/tests/utils/device/live.spec.ts +++ b/tests/utils/device/live.spec.ts @@ -83,10 +83,10 @@ describeSS('LivepushManager::setupFilesystemWatcher', function () { changedPathHandler: (serviceName: string, changedPath: string) => void, ): Promise> { const { getServiceDirsFromComposition } = await import( - '../../../build/utils/compose_ts' + '../../../build/utils/compose_ts.js' ); const { getDockerignoreByService } = await import( - '../../../build/utils/ignore' + '../../../build/utils/ignore.js' ); const rootContext = path.resolve(projectPath); diff --git a/tests/utils/qemu.spec.ts b/tests/utils/qemu.spec.ts index fc38de3c74..87d1b8b4bf 100644 --- a/tests/utils/qemu.spec.ts +++ b/tests/utils/qemu.spec.ts @@ -22,7 +22,7 @@ describe('@balena/compose/multibuild consistency', function () { const { QEMU_BIN_NAME: MQEMU_BIN_NAME } = await import( '@balena/compose/dist/multibuild' ); - const { QEMU_BIN_NAME } = await import('../../build/utils/qemu'); + const { QEMU_BIN_NAME } = await import('../../build/utils/qemu.js'); expect(QEMU_BIN_NAME).to.equal(MQEMU_BIN_NAME); }); }); diff --git a/tests/utils/update.spec.ts b/tests/utils/update.spec.ts index c726b3b335..f9813da4b2 100644 --- a/tests/utils/update.spec.ts +++ b/tests/utils/update.spec.ts @@ -16,7 +16,7 @@ */ import { expect } from 'chai'; -import * as stripIndent from 'common-tags/lib/stripIndent'; +import stripIndent from 'common-tags/lib/stripIndent'; import { getNotifierMessage } from '../../build/utils/update'; diff --git a/tsconfig.json b/tsconfig.json index bfe183cbf4..f335e82f13 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "declaration": true, - "module": "commonjs", - "target": "es2018", + "module": "Node16", + "target": "es2022", "outDir": "build", "strict": true, "strictPropertyInitialization": false, From 6059f60bbd1a7722678d78822b612ec3c1cfc20a Mon Sep 17 00:00:00 2001 From: Otavio Jacobi Date: Sun, 14 Jul 2024 10:55:10 -0300 Subject: [PATCH 2/3] does not work --- .eslintrc.js => .eslintrc.cjs | 1 - .mocharc-standalone.js | 2 +- automation/build-bin.ts | 11 ++--- automation/capitanodoc/capitanodoc.ts | 2 +- automation/capitanodoc/index.ts | 2 + automation/capitanodoc/markdown.ts | 2 +- automation/check-doc.ts | 4 +- automation/check-npm-version.js | 2 +- automation/deploy-bin.ts | 16 +++---- automation/run.ts | 4 +- automation/update-module.ts | 5 ++- automation/utils.ts | 4 +- bin/dev.js | 61 ++++++++++++++------------ bin/run.js | 13 +++--- completion/generate-completion.js | 14 +++--- lib/app.ts | 16 ++++--- lib/auth/index.ts | 4 +- lib/auth/server.ts | 6 +-- lib/auth/utils.ts | 2 +- lib/command.ts | 10 ++--- lib/commands/api-key/generate.ts | 8 ++-- lib/commands/api-key/revoke.ts | 6 +-- lib/commands/api-keys/index.ts | 6 +-- lib/commands/app/create.ts | 6 +-- lib/commands/block/create.ts | 6 +-- lib/commands/build/index.ts | 23 +++++----- lib/commands/config/generate.ts | 8 ++-- lib/commands/config/inject.ts | 6 +-- lib/commands/config/read.ts | 6 +-- lib/commands/config/reconfigure.ts | 6 +-- lib/commands/config/write.ts | 8 ++-- lib/commands/deploy/index.ts | 32 ++++++++------ lib/commands/device/deactivate.ts | 6 +-- lib/commands/device/identify.ts | 8 ++-- lib/commands/device/index.ts | 10 ++--- lib/commands/device/init.ts | 10 ++--- lib/commands/device/local-mode.ts | 6 +-- lib/commands/device/move.ts | 10 ++--- lib/commands/device/os-update.ts | 8 ++-- lib/commands/device/pin.ts | 8 ++-- lib/commands/device/public-url.ts | 8 ++-- lib/commands/device/purge.ts | 6 +-- lib/commands/device/reboot.ts | 6 +-- lib/commands/device/register.ts | 10 ++--- lib/commands/device/rename.ts | 6 +-- lib/commands/device/restart.ts | 6 +-- lib/commands/device/rm.ts | 6 +-- lib/commands/device/shutdown.ts | 8 ++-- lib/commands/device/start-service.ts | 6 +-- lib/commands/device/stop-service.ts | 6 +-- lib/commands/device/track-fleet.ts | 6 +-- lib/commands/devices/index.ts | 10 ++--- lib/commands/devices/supported.ts | 10 ++--- lib/commands/env/add.ts | 10 ++--- lib/commands/env/rename.ts | 10 ++--- lib/commands/env/rm.ts | 8 ++-- lib/commands/envs/index.ts | 12 ++--- lib/commands/fleet/create.ts | 6 +-- lib/commands/fleet/index.ts | 10 ++--- lib/commands/fleet/pin.ts | 8 ++-- lib/commands/fleet/purge.ts | 10 ++--- lib/commands/fleet/rename.ts | 10 ++--- lib/commands/fleet/restart.ts | 10 ++--- lib/commands/fleet/rm.ts | 10 ++--- lib/commands/fleet/track-latest.ts | 6 +-- lib/commands/fleets/index.ts | 6 +-- lib/commands/internal/osinit.ts | 6 +-- lib/commands/join/index.ts | 10 ++--- lib/commands/key/add.ts | 8 ++-- lib/commands/key/index.ts | 8 ++-- lib/commands/key/rm.ts | 8 ++-- lib/commands/keys/index.ts | 6 +-- lib/commands/leave/index.ts | 8 ++-- lib/commands/local/configure.ts | 6 +-- lib/commands/local/flash.ts | 8 ++-- lib/commands/login/index.ts | 8 ++-- lib/commands/logout/index.ts | 4 +- lib/commands/logs/index.ts | 7 ++- lib/commands/notes/index.ts | 8 ++-- lib/commands/orgs/index.ts | 6 +-- lib/commands/os/build-config.ts | 8 ++-- lib/commands/os/configure.ts | 16 +++---- lib/commands/os/download.ts | 6 +-- lib/commands/os/initialize.ts | 6 +-- lib/commands/os/versions.ts | 6 +-- lib/commands/preload/index.ts | 16 +++---- lib/commands/push/index.ts | 14 +++--- lib/commands/release/finalize.ts | 8 ++-- lib/commands/release/index.ts | 12 ++--- lib/commands/release/invalidate.ts | 8 ++-- lib/commands/release/validate.ts | 8 ++-- lib/commands/releases/index.ts | 10 ++--- lib/commands/scan/index.ts | 6 +-- lib/commands/settings/index.ts | 6 +-- lib/commands/ssh/index.ts | 8 ++-- lib/commands/support/index.ts | 10 ++--- lib/commands/tag/rm.ts | 8 ++-- lib/commands/tag/set.ts | 8 ++-- lib/commands/tags/index.ts | 10 ++--- lib/commands/tunnel/index.ts | 10 ++--- lib/commands/util/available-drives.ts | 6 +-- lib/commands/version/index.ts | 4 +- lib/commands/whoami/index.ts | 4 +- lib/deprecation.ts | 4 +- lib/errors.ts | 8 ++-- lib/events.ts | 4 +- lib/fast-boot.ts | 4 +- lib/framework/index.ts | 2 +- lib/framework/output.ts | 2 +- lib/help.ts | 9 ++-- lib/hooks/command-not-found/suggest.ts | 2 +- lib/preparser.ts | 6 +-- lib/utils/application-create.ts | 4 +- lib/utils/bootstrap.ts | 2 + lib/utils/cloud.ts | 6 +-- lib/utils/common-args.ts | 2 +- lib/utils/common-flags.ts | 4 +- lib/utils/compose.ts | 24 +++++----- lib/utils/compose_ts.ts | 54 ++++++++++++----------- lib/utils/config.ts | 6 +-- lib/utils/deploy-legacy.ts | 15 ++++--- lib/utils/device/api.ts | 8 ++-- lib/utils/device/deploy.ts | 22 +++++----- lib/utils/device/errors.ts | 4 +- lib/utils/device/live.ts | 22 +++++----- lib/utils/device/logs.ts | 10 ++--- lib/utils/device/ssh.ts | 8 ++-- lib/utils/discover.ts | 2 +- lib/utils/docker.ts | 6 ++- lib/utils/env-common.ts | 4 +- lib/utils/eol-conversion.ts | 2 +- lib/utils/helpers.ts | 13 +++--- lib/utils/ignore.ts | 4 +- lib/utils/lazy.ts | 2 + lib/utils/logger.ts | 4 +- lib/utils/normalization.ts | 2 +- lib/utils/oclif-utils.ts | 4 +- lib/utils/patterns.ts | 12 ++--- lib/utils/promote.ts | 10 ++--- lib/utils/proxy.ts | 2 +- lib/utils/qemu.ts | 20 +++++---- lib/utils/remote-build.ts | 10 +++-- lib/utils/ssh.ts | 4 +- lib/utils/streams.ts | 4 +- lib/utils/sudo.ts | 7 ++- lib/utils/tty.ts | 4 +- lib/utils/tunnel.ts | 2 +- lib/utils/update.ts | 7 +-- lib/utils/validation.ts | 2 +- lib/utils/version.ts | 7 ++- lib/utils/which.ts | 2 + package.json | 15 ++++--- tests/auth/server.spec.ts | 2 +- tests/commands/build.spec.ts | 10 +++-- tests/commands/deploy.spec.ts | 4 +- tests/commands/env/envs.spec.ts | 5 ++- tests/commands/push.spec.ts | 2 +- tests/docker-build.ts | 18 +++++--- tests/helpers.ts | 22 ++++++---- tests/nock/balena-api-mock.ts | 4 +- tests/nock/builder-mock.ts | 2 +- tests/nock/docker-mock.ts | 2 +- tests/nock/nock-mock.ts | 3 +- tests/nock/proxy-server.ts | 3 +- tests/nock/supervisor-mock.ts | 2 +- tests/projects.ts | 4 +- tests/utils/device/live.spec.ts | 4 +- tests/utils/docker.spec.ts | 2 +- tests/utils/tarDirectory.spec.ts | 2 +- tsconfig.json | 4 +- 170 files changed, 709 insertions(+), 646 deletions(-) rename .eslintrc.js => .eslintrc.cjs (92%) diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 92% rename from .eslintrc.js rename to .eslintrc.cjs index 67c2bfb833..ba52386e2e 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -9,7 +9,6 @@ module.exports = { // to avoid the `warning Forbidden non-null assertion @typescript-eslint/no-non-null-assertion` '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-shadow': 'off', - '@typescript-eslint/no-var-requires': 'off', 'no-restricted-imports': [ 'error', { diff --git a/.mocharc-standalone.js b/.mocharc-standalone.js index 2034d395ea..abe2ec6b8f 100644 --- a/.mocharc-standalone.js +++ b/.mocharc-standalone.js @@ -1,4 +1,4 @@ -const commonConfig = require('./.mocharc.js'); +import commonConfig from './.mocharc.js'; module.exports = { ...commonConfig, diff --git a/automation/build-bin.ts b/automation/build-bin.ts index 76fc8f81c7..b3eb474ed6 100644 --- a/automation/build-bin.ts +++ b/automation/build-bin.ts @@ -21,7 +21,7 @@ import { run as oclifRun } from '@oclif/core'; import archiver from 'archiver'; import Bluebird from 'bluebird'; import { exec, execFile } from 'child_process'; -import * as filehound from 'filehound'; +import filehound from 'filehound'; import type { Stats } from 'fs'; import * as fs from 'fs-extra'; import klaw from 'klaw'; @@ -31,7 +31,7 @@ import * as semver from 'semver'; import { promisify } from 'util'; import { notarize } from '@electron/notarize'; -import { stripIndent } from '../build/utils/lazy'; +import { stripIndent } from '../lib/utils/lazy'; import { diffLines, loadPackageJson, @@ -39,6 +39,7 @@ import { StdOutTap, whichSpawn, } from './utils'; +import { filterCliOutputForTests, monochrome } from '../tests/helpers'; const execFileAsync = promisify(execFile); const execAsync = promisify(exec); @@ -87,7 +88,6 @@ export const finalReleaseAssets: { [platform: string]: string[] } = { * Throw an error if the diff is not empty. */ async function diffPkgOutput(pkgOut: string) { - const { monochrome } = await import('../tests/helpers.js'); const relSavedPath = path.join( 'tests', 'test-data', @@ -263,7 +263,6 @@ async function testPkg() { 'version', '-j', ]); - const { filterCliOutputForTests } = await import('../tests/helpers.js'); const filtered = filterCliOutputForTests({ err: stderr.split(/\r?\n/), out: stdout.split(/\r?\n/), @@ -570,6 +569,8 @@ export async function testShrinkwrap(): Promise { console.error(`[debug] platform=${process.platform}`); } if (process.platform !== 'win32') { - await whichSpawn(path.resolve(__dirname, 'test-lock-deduplicated.sh')); + await whichSpawn( + path.resolve(import.meta.dirname, 'test-lock-deduplicated.sh'), + ); } } diff --git a/automation/capitanodoc/capitanodoc.ts b/automation/capitanodoc/capitanodoc.ts index 93a7f5b3ec..6e9840d96b 100644 --- a/automation/capitanodoc/capitanodoc.ts +++ b/automation/capitanodoc/capitanodoc.ts @@ -144,7 +144,7 @@ capitanoDoc.categories.forEach((category) => { * for the documentation web page. */ export async function getCapitanoDoc(): Promise { - const readmePath = path.join(__dirname, '..', '..', 'README.md'); + const readmePath = path.join(import.meta.dirname, '..', '..', 'README.md'); const mdParser = new MarkdownFileParser(readmePath); const sections: string[] = await Promise.all([ mdParser.getSectionOfTitle('About').then((sectionLines: string) => { diff --git a/automation/capitanodoc/index.ts b/automation/capitanodoc/index.ts index 75e792726b..58701e96af 100644 --- a/automation/capitanodoc/index.ts +++ b/automation/capitanodoc/index.ts @@ -19,6 +19,8 @@ import { getCapitanoDoc } from './capitanodoc'; import type { Category, Document, OclifCommand } from './doc-types'; import * as markdown from './markdown'; import { stripIndent } from '../../lib/utils/lazy'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); /** * Generates the markdown document (as a string) for the CLI documentation diff --git a/automation/capitanodoc/markdown.ts b/automation/capitanodoc/markdown.ts index c0e2dc804e..ada7531d59 100644 --- a/automation/capitanodoc/markdown.ts +++ b/automation/capitanodoc/markdown.ts @@ -16,7 +16,7 @@ */ import { Parser } from '@oclif/core'; import * as ent from 'ent'; -import * as _ from 'lodash'; +import _ from 'lodash'; import { getManualSortCompareFunction } from '../../lib/utils/helpers'; import { capitanoizeOclifUsage } from '../../lib/utils/oclif-utils'; diff --git a/automation/check-doc.ts b/automation/check-doc.ts index 9ad65dc416..0a514d4c1b 100644 --- a/automation/check-doc.ts +++ b/automation/check-doc.ts @@ -17,12 +17,12 @@ // eslint-disable-next-line no-restricted-imports import { stripIndent } from 'common-tags'; -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; import * as path from 'path'; import { simpleGit } from 'simple-git'; -const ROOT = path.normalize(path.join(__dirname, '..')); +const ROOT = path.normalize(path.join(import.meta.dirname, '..')); /** * Compare the timestamp of balena-cli.md with the timestamp of staged files, diff --git a/automation/check-npm-version.js b/automation/check-npm-version.js index cddf82f670..2e7ce68c1a 100644 --- a/automation/check-npm-version.js +++ b/automation/check-npm-version.js @@ -1,5 +1,6 @@ #!/usr/bin/env node 'use strict'; +import { execSync } from 'child_process'; /** * Check that semver v1 is greater than or equal to semver v2. @@ -36,7 +37,6 @@ function semverGte(v1, v2) { } function checkNpmVersion() { - const execSync = require('child_process').execSync; const npmVersion = execSync('npm --version').toString().trim(); const requiredVersion = '6.9.0'; if (!semverGte(npmVersion, requiredVersion)) { diff --git a/automation/deploy-bin.ts b/automation/deploy-bin.ts index 5395d02ec3..fb8f61e4d8 100644 --- a/automation/deploy-bin.ts +++ b/automation/deploy-bin.ts @@ -15,20 +15,17 @@ * limitations under the License. */ -import * as _ from 'lodash'; +import _ from 'lodash'; import * as semver from 'semver'; +import { Octokit as OctokitLib } from '@octokit/rest'; +import OctoKitPluginThrottling from '@octokit/plugin-throttling'; +import parse from 'parse-link-header'; const { GITHUB_TOKEN } = process.env; /** Return a cached Octokit instance, creating a new one as needed. */ const getOctokit = _.once(function () { - const Octokit = ( - require('@octokit/rest') as typeof import('@octokit/rest') - ).Octokit.plugin( - ( - require('@octokit/plugin-throttling') as typeof import('@octokit/plugin-throttling') - ).throttling, - ); + const Octokit = OctokitLib.plugin(OctoKitPluginThrottling.throttling); return new Octokit({ auth: GITHUB_TOKEN, throttle: { @@ -73,8 +70,7 @@ function getPageNumbers( if (!response.headers.link) { return res; } - const parse = - require('parse-link-header') as typeof import('parse-link-header'); + const parsed = parse(response.headers.link); if (parsed == null) { throw new Error(`Failed to parse link header: '${response.headers.link}'`); diff --git a/automation/run.ts b/automation/run.ts index f8fc02731a..3d2cfd8c7d 100644 --- a/automation/run.ts +++ b/automation/run.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as _ from 'lodash'; +import _ from 'lodash'; import { buildOclifInstaller, @@ -24,7 +24,7 @@ import { signFilesForNotarization, testShrinkwrap, } from './build-bin'; -import { updateDescriptionOfReleasesAffectedByIssue1359 } from './deploy-bin'; +import { updateDescriptionOfReleasesAffectedByIssue1359 } from './deploy-bin.js'; // DEBUG set to falsy for negative values else is truthy process.env.DEBUG = ['0', 'no', 'false', '', undefined].includes( diff --git a/automation/update-module.ts b/automation/update-module.ts index d895d35ebf..539409edab 100644 --- a/automation/update-module.ts +++ b/automation/update-module.ts @@ -54,7 +54,10 @@ interface Upstream { const getUpstreams = async () => { const fs = await import('fs'); - const repoYaml = fs.readFileSync(__dirname + '/../repo.yml', 'utf8'); + const repoYaml = fs.readFileSync( + import.meta.dirname + '/../repo.yml', + 'utf8', + ); const yaml = await import('js-yaml'); const { upstream } = yaml.load(repoYaml) as { diff --git a/automation/utils.ts b/automation/utils.ts index 5b9f5ef537..28891e3d7e 100644 --- a/automation/utils.ts +++ b/automation/utils.ts @@ -17,8 +17,9 @@ import { spawn } from 'child_process'; import * as path from 'path'; +import { diffTrimmedLines } from 'diff'; -export const ROOT = path.join(__dirname, '..'); +export const ROOT = path.join(import.meta.dirname, '..'); /** Tap and buffer this process' stdout and stderr */ export class StdOutTap { @@ -64,7 +65,6 @@ export class StdOutTap { * https://www.npmjs.com/package/diff */ export function diffLines(str1: string, str2: string): string { - const { diffTrimmedLines } = require('diff'); const diffObjs = diffTrimmedLines(str1, str2); const prefix = (chunk: string, char: string) => chunk diff --git a/bin/dev.js b/bin/dev.js index ceaf47c418..880d22eba0 100755 --- a/bin/dev.js +++ b/bin/dev.js @@ -1,4 +1,4 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning // **************************************************************************** // THIS IS FOR DEV PURPOSES ONLY AND WILL NOT BE PART OF THE PUBLISHED PACKAGE @@ -25,8 +25,9 @@ process.env.UV_THREADPOOL_SIZE = '64'; // is to use `balena-dev` without `fast-boot`. See also notes in // `CONTRIBUTING.md`. -const path = require('path'); -const rootDir = path.join(__dirname, '..'); +import * as path from 'path'; +import * as fs from 'fs'; +const rootDir = path.join(import.meta.dirname, '..'); // Allow balena-dev to work with oclif by temporarily // pointing oclif config options to lib/ instead of build/ @@ -46,42 +47,44 @@ process.on('SIGINT', function () { }); // Set the desired es version for downstream modules that support it -require('@balena/es-version').set('es2018'); +(await import('@balena/es-version')).set('es2018'); // Note: before ts-node v6.0.0, 'transpile-only' (no type checking) was the // default option. We upgraded ts-node and found that adding 'transpile-only' // was necessary to avoid a mysterious 'null' error message. On the plus side, // it is supposed to run faster. We still benefit from type checking when // running 'npm run build'. -require('ts-node').register({ - project: path.join(rootDir, 'tsconfig.json'), - transpileOnly: true, +// (await import('ts-node')).register({ +// project: path.join(rootDir, 'tsconfig.json'), +// transpileOnly: true, +// }); +(await import('../lib/app.js')).run(undefined, { + dir: import.meta.url, + development: true, }); -require('../lib/app').run(undefined, { dir: __dirname, development: true }); // Modify package.json oclif paths from build/ -> lib/, or vice versa -function modifyOclifPaths(revert) { - const fs = require('fs'); - const packageJsonPath = path.join(rootDir, 'package.json'); +// function modifyOclifPaths(revert) { +// const packageJsonPath = path.join(rootDir, 'package.json'); - const packageJson = fs.readFileSync(packageJsonPath, 'utf8'); - const packageObj = JSON.parse(packageJson); +// const packageJson = fs.readFileSync(packageJsonPath, 'utf8'); +// const packageObj = JSON.parse(packageJson); - if (!packageObj.oclif) { - return; - } +// if (!packageObj.oclif) { +// return; +// } - let oclifSectionText = JSON.stringify(packageObj.oclif); - if (!revert) { - oclifSectionText = oclifSectionText.replace(/\/build\//g, '/lib/'); - } else { - oclifSectionText = oclifSectionText.replace(/\/lib\//g, '/build/'); - } +// let oclifSectionText = JSON.stringify(packageObj.oclif); +// if (!revert) { +// oclifSectionText = oclifSectionText.replace(/\/build\//g, '/lib/'); +// } else { +// oclifSectionText = oclifSectionText.replace(/\/lib\//g, '/build/'); +// } - packageObj.oclif = JSON.parse(oclifSectionText); - fs.writeFileSync( - packageJsonPath, - `${JSON.stringify(packageObj, null, 2)}\n`, - 'utf8', - ); -} +// packageObj.oclif = JSON.parse(oclifSectionText); +// fs.writeFileSync( +// packageJsonPath, +// `${JSON.stringify(packageObj, null, 2)}\n`, +// 'utf8', +// ); +// } diff --git a/bin/run.js b/bin/run.js index 6a27aff0f3..8d48b88788 100755 --- a/bin/run.js +++ b/bin/run.js @@ -1,21 +1,20 @@ -#!/usr/bin/env node +#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning // We boost the threadpool size as ext2fs can deadlock with some // operations otherwise, if the pool runs out. process.env.UV_THREADPOOL_SIZE = '64'; -// Disable oclif registering ts-node -process.env.OCLIF_TS_NODE = 0; - async function run() { // Use fast-boot to cache require lookups, speeding up startup - await require('../build/fast-boot').start(); + await (await import('../build/lib/fast-boot.js')).start(); // Set the desired es version for downstream modules that support it - require('@balena/es-version').set('es2018'); + (await import('@balena/es-version')).set('es2018'); // Run the CLI - await require('../build/app').run(undefined, { dir: __dirname }); + await ( + await import('../build/lib/app.js') + ).run(undefined, { dir: import.meta.url }); } run(); diff --git a/completion/generate-completion.js b/completion/generate-completion.js index 732ffb8398..d7939affed 100644 --- a/completion/generate-completion.js +++ b/completion/generate-completion.js @@ -15,9 +15,9 @@ * limitations under the License. */ -const path = require('path'); -const rootDir = path.join(__dirname, '..'); -const fs = require('fs'); +import path from 'path'; +const rootDir = path.join(import.meta.dirname, '..'); +import fs from 'fs'; const manifestFile = 'oclif.manifest.json'; commandsFilePath = path.join(rootDir, manifestFile); @@ -47,8 +47,8 @@ for (const key of Object.keys(commandsJson.commands).sort()) { const mainCommandsStr = mainCommands.join(' '); // GENERATE BASH COMPLETION FILE -bashFilePathIn = path.join(__dirname, '/templates/bash.template'); -bashFilePathOut = path.join(__dirname, 'balena-completion.bash'); +bashFilePathIn = path.join(import.meta.dirname, '/templates/bash.template'); +bashFilePathOut = path.join(import.meta.dirname, 'balena-completion.bash'); try { fs.unlinkSync(bashFilePathOut); @@ -109,8 +109,8 @@ fs.readFile(bashFilePathIn, 'utf8', function (err, data) { }); // GENERATE ZSH COMPLETION FILE -zshFilePathIn = path.join(__dirname, '/templates/zsh.template'); -zshFilePathOut = path.join(__dirname, '_balena'); +zshFilePathIn = path.join(import.meta.dirname, '/templates/zsh.template'); +zshFilePathOut = path.join(import.meta.dirname, '_balena'); try { fs.unlinkSync(zshFilePathOut); diff --git a/lib/app.ts b/lib/app.ts index 98065ea561..b81541810f 100644 --- a/lib/app.ts +++ b/lib/app.ts @@ -15,17 +15,20 @@ * limitations under the License. */ -import * as packageJSON from '../package.json'; -import type { AppOptions } from './preparser'; +import packageJSON from '../package.json' with { type: 'json' }; +import type { AppOptions } from './preparser.js'; import { checkDeletedCommand, preparseArgs, unsupportedFlag, -} from './preparser'; -import { CliSettings } from './utils/bootstrap'; -import { onceAsync } from './utils/lazy'; +} from './preparser.js'; +import { CliSettings } from './utils/bootstrap.js'; +import { onceAsync } from './utils/lazy.js'; import { run as mainRun, settings } from '@oclif/core'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); + /** * Sentry.io setup * @see https://docs.sentry.io/error-reporting/quickstart/?platform=node @@ -164,6 +167,7 @@ export async function run(cliArgs = process.argv, options: AppOptions) { const { setOfflineModeEnvVars, normalizeEnvVars, pkgExec } = await import( './utils/bootstrap.js' ); + setOfflineModeEnvVars(); normalizeEnvVars(); @@ -176,7 +180,7 @@ export async function run(cliArgs = process.argv, options: AppOptions) { await init(); // Look for commands that have been removed and if so, exit with a notice - checkDeletedCommand(cliArgs.slice(2)); + await checkDeletedCommand(cliArgs.slice(2)); const args = await preparseArgs(cliArgs); await oclifRun(args, options); diff --git a/lib/auth/index.ts b/lib/auth/index.ts index 7c48867ccf..16f1001b65 100644 --- a/lib/auth/index.ts +++ b/lib/auth/index.ts @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { getBalenaSdk } from '../utils/lazy'; -import { LoginServer } from './server'; +import { getBalenaSdk } from '../utils/lazy.js'; +import { LoginServer } from './server.js'; /** * @module auth diff --git a/lib/auth/server.ts b/lib/auth/server.ts index c24388fd14..4c3ab85370 100644 --- a/lib/auth/server.ts +++ b/lib/auth/server.ts @@ -20,8 +20,8 @@ import express from 'express'; import type { Socket } from 'net'; import * as path from 'path'; -import * as utils from './utils'; -import { ExpectedError } from '../errors'; +import * as utils from './utils.js'; +import { ExpectedError } from '../errors.js'; export class LoginServer extends EventEmitter { protected expressApp: express.Express; @@ -56,7 +56,7 @@ export class LoginServer extends EventEmitter { ); app.set('view engine', 'ejs'); - app.set('views', path.join(__dirname, 'pages')); + app.set('views', path.join(import.meta.dirname, 'pages')); this.server = await new Promise((resolve, reject) => { const callback = (err: Error) => { diff --git a/lib/auth/utils.ts b/lib/auth/utils.ts index 7956b55b98..f2935f0a16 100644 --- a/lib/auth/utils.ts +++ b/lib/auth/utils.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { getBalenaSdk } from '../utils/lazy'; +import { getBalenaSdk } from '../utils/lazy.js'; /** * Get dashboard CLI login URL diff --git a/lib/command.ts b/lib/command.ts index 83c8c44512..9580457f5d 100644 --- a/lib/command.ts +++ b/lib/command.ts @@ -19,9 +19,9 @@ import { Command } from '@oclif/core'; import { InsufficientPrivilegesError, NotAvailableInOfflineModeError, -} from './errors'; -import { stripIndent } from './utils/lazy'; -import * as output from './framework/output'; +} from './errors.js'; +import { stripIndent } from './utils/lazy.js'; +import * as output from './framework/output.js'; export default abstract class BalenaCommand extends Command { /** @@ -147,8 +147,8 @@ export default abstract class BalenaCommand extends Command { * Get a logger instance. */ protected static async getLogger() { - const { default: logger } = await import('./utils/logger.js'); - return logger.getLogger(); + const { default: Logger } = await import('./utils/logger.js'); + return Logger.getLogger(); } protected async init() { diff --git a/lib/commands/api-key/generate.ts b/lib/commands/api-key/generate.ts index c9213b673b..86265d26f8 100644 --- a/lib/commands/api-key/generate.ts +++ b/lib/commands/api-key/generate.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import { ExpectedError } from '../../errors'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class GenerateCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/api-key/revoke.ts b/lib/commands/api-key/revoke.ts index 27475f39ef..d12d8d1f2a 100644 --- a/lib/commands/api-key/revoke.ts +++ b/lib/commands/api-key/revoke.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class RevokeCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/api-keys/index.ts b/lib/commands/api-keys/index.ts index d0ceb50f52..ac3ef301f6 100644 --- a/lib/commands/api-keys/index.ts +++ b/lib/commands/api-keys/index.ts @@ -16,9 +16,9 @@ */ import { Flags } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; export default class ApiKeysCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/app/create.ts b/lib/commands/app/create.ts index 1e888504c4..60baabc8ae 100644 --- a/lib/commands/app/create.ts +++ b/lib/commands/app/create.ts @@ -17,9 +17,9 @@ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { stripIndent } from '../../utils/lazy.js'; export default class AppCreateCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/block/create.ts b/lib/commands/block/create.ts index e6dd7b56cd..9372bff101 100644 --- a/lib/commands/block/create.ts +++ b/lib/commands/block/create.ts @@ -17,9 +17,9 @@ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { stripIndent } from '../../utils/lazy.js'; export default class BlockCreateCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/build/index.ts b/lib/commands/build/index.ts index 0bcef8ebe6..432490175c 100644 --- a/lib/commands/build/index.ts +++ b/lib/commands/build/index.ts @@ -16,10 +16,10 @@ */ import { Args, Flags } from '@oclif/core'; -import Command from '../../command'; -import { getBalenaSdk } from '../../utils/lazy'; -import * as cf from '../../utils/common-flags'; -import * as compose from '../../utils/compose'; +import Command from '../../command.js'; +import { getBalenaSdk } from '../../utils/lazy.js'; +import * as cf from '../../utils/common-flags.js'; +import * as compose from '../../utils/compose.js'; import type { ApplicationType, BalenaSDK, @@ -31,11 +31,14 @@ import { buildArgDeprecation, dockerignoreHelp, registrySecretsHelp, -} from '../../utils/messages'; -import type { ComposeCliFlags, ComposeOpts } from '../../utils/compose-types'; -import { buildProject, composeCliFlags } from '../../utils/compose_ts'; -import type { BuildOpts, DockerCliFlags } from '../../utils/docker'; -import { dockerCliFlags } from '../../utils/docker'; +} from '../../utils/messages.js'; +import type { + ComposeCliFlags, + ComposeOpts, +} from '../../utils/compose-types.js'; +import { buildProject, composeCliFlags } from '../../utils/compose_ts.js'; +import type { BuildOpts, DockerCliFlags } from '../../utils/docker.js'; +import { dockerCliFlags } from '../../utils/docker.js'; import type Dockerode from 'dockerode'; // TODO: For this special one we can't use Interfaces.InferredFlags/InferredArgs @@ -260,7 +263,7 @@ ${dockerignoreHelp} */ protected async buildProject( docker: import('dockerode'), - logger: import('../../utils/logger'), + logger: import('../../utils/logger.js').default, composeOpts: ComposeOpts, opts: { appType?: Pick; diff --git a/lib/commands/config/generate.ts b/lib/commands/config/generate.ts index b5a7210a8a..d8c816528f 100644 --- a/lib/commands/config/generate.ts +++ b/lib/commands/config/generate.ts @@ -17,14 +17,14 @@ import { Flags } 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 Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getCliForm, stripIndent } from '../../utils/lazy.js'; import { applicationIdInfo, devModeInfo, secureBootInfo, -} from '../../utils/messages'; +} from '../../utils/messages.js'; import type { BalenaSDK, PineDeferred } from 'balena-sdk'; export default class ConfigGenerateCmd extends Command { diff --git a/lib/commands/config/inject.ts b/lib/commands/config/inject.ts index a9034e0dcf..05a267ab3e 100644 --- a/lib/commands/config/inject.ts +++ b/lib/commands/config/inject.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getVisuals, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getVisuals, stripIndent } from '../../utils/lazy.js'; export default class ConfigInjectCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/config/read.ts b/lib/commands/config/read.ts index 9830e5a6a5..3acd906d85 100644 --- a/lib/commands/config/read.ts +++ b/lib/commands/config/read.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getVisuals, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getVisuals, stripIndent } from '../../utils/lazy.js'; export default class ConfigReadCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/config/reconfigure.ts b/lib/commands/config/reconfigure.ts index 8dd9a2b1ef..7e1d6b4ed9 100644 --- a/lib/commands/config/reconfigure.ts +++ b/lib/commands/config/reconfigure.ts @@ -16,9 +16,9 @@ */ import { Flags } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getVisuals, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getVisuals, stripIndent } from '../../utils/lazy.js'; export default class ConfigReconfigureCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/config/write.ts b/lib/commands/config/write.ts index dd922da161..3d008855b5 100644 --- a/lib/commands/config/write.ts +++ b/lib/commands/config/write.ts @@ -16,9 +16,11 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getVisuals, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getVisuals, stripIndent } from '../../utils/lazy.js'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); export default class ConfigWriteCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/deploy/index.ts b/lib/commands/deploy/index.ts index e11e72fa2f..db2b60948f 100644 --- a/lib/commands/deploy/index.ts +++ b/lib/commands/deploy/index.ts @@ -16,34 +16,36 @@ */ import { Args, Flags } from '@oclif/core'; -import type { ImageDescriptor } from '@balena/compose/dist/parse'; +import type { parse } from '@balena/compose'; -import Command from '../../command'; -import { ExpectedError } from '../../errors'; -import { getBalenaSdk, getChalk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import { getBalenaSdk, getChalk, stripIndent } from '../../utils/lazy.js'; import { dockerignoreHelp, registrySecretsHelp, buildArgDeprecation, -} from '../../utils/messages'; -import * as ca from '../../utils/common-args'; -import * as compose from '../../utils/compose'; +} from '../../utils/messages.js'; +import * as ca from '../../utils/common-args.js'; +import * as compose from '../../utils/compose.js'; import type { BuiltImage, ComposeCliFlags, ComposeOpts, Release as ComposeReleaseInfo, -} from '../../utils/compose-types'; -import type { BuildOpts, DockerCliFlags } from '../../utils/docker'; +} from '../../utils/compose-types.js'; +import type { BuildOpts, DockerCliFlags } from '../../utils/docker.js'; import { applyReleaseTagKeysAndValues, buildProject, composeCliFlags, isBuildConfig, parseReleaseTagKeysAndValues, -} from '../../utils/compose_ts'; -import { dockerCliFlags } from '../../utils/docker'; +} from '../../utils/compose_ts.js'; +import { dockerCliFlags } from '../../utils/docker.js'; import type { ApplicationType, DeviceType, Release } from 'balena-sdk'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); interface ApplicationWithArch { id: number; @@ -232,7 +234,7 @@ ${dockerignoreHelp} async deployProject( docker: import('dockerode'), - logger: import('../../utils/logger'), + logger: import('../../utils/logger.js').default, composeOpts: ComposeOpts, opts: { app: ApplicationWithArch; // the application instance to deploy to @@ -270,7 +272,7 @@ ${dockerignoreHelp} // find which services use images that already exist locally let servicesToSkip: string[] = await Promise.all( - project.descriptors.map(async function (d: ImageDescriptor) { + project.descriptors.map(async function (d: parse.ImageDescriptor) { // unconditionally build (or pull) if explicitly requested if (opts.shouldPerformBuild) { return ''; @@ -320,8 +322,9 @@ ${dockerignoreHelp} }); builtImagesByService = _.keyBy(builtImages, 'serviceName'); } + const images: BuiltImage[] = project.descriptors.map( - (d) => + (d: parse.ImageDescriptor) => builtImagesByService[d.serviceName] ?? { serviceName: d.serviceName, name: (isBuildConfig(d.image) ? d.image.tag : d.image) || '', @@ -364,6 +367,7 @@ ${dockerignoreHelp} $select: ['commit'], }); } else { + // @ts-expect-error CHECK ESM release = await $deployProject( docker, sdk, diff --git a/lib/commands/device/deactivate.ts b/lib/commands/device/deactivate.ts index c22d2653a9..2537e91313 100644 --- a/lib/commands/device/deactivate.ts +++ b/lib/commands/device/deactivate.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class DeviceDeactivateCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/identify.ts b/lib/commands/device/identify.ts index 7766a088e6..62bcae4930 100644 --- a/lib/commands/device/identify.ts +++ b/lib/commands/device/identify.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { ExpectedError } from '../../errors'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { ExpectedError } from '../../errors.js'; export default class DeviceIdentifyCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/index.ts b/lib/commands/device/index.ts index 3dc318caa8..b4c2d6409f 100644 --- a/lib/commands/device/index.ts +++ b/lib/commands/device/index.ts @@ -16,11 +16,11 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { expandForAppName } from '../../utils/helpers'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; -import { jsonInfo } from '../../utils/messages'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { expandForAppName } from '../../utils/helpers.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; +import { jsonInfo } from '../../utils/messages.js'; import type { Application, Release } from 'balena-sdk'; diff --git a/lib/commands/device/init.ts b/lib/commands/device/init.ts index 2a4b45c1c4..073169dfad 100644 --- a/lib/commands/device/init.ts +++ b/lib/commands/device/init.ts @@ -16,11 +16,11 @@ */ import { Flags } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { applicationIdInfo } from '../../utils/messages'; -import { runCommand } from '../../utils/helpers'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; +import { runCommand } from '../../utils/helpers.js'; interface FlagsDef { fleet?: string; diff --git a/lib/commands/device/local-mode.ts b/lib/commands/device/local-mode.ts index 1d048baf9e..66b5a487c6 100644 --- a/lib/commands/device/local-mode.ts +++ b/lib/commands/device/local-mode.ts @@ -16,9 +16,9 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class DeviceLocalModeCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/move.ts b/lib/commands/device/move.ts index bff8f949d3..8d32b69f03 100644 --- a/lib/commands/device/move.ts +++ b/lib/commands/device/move.ts @@ -22,11 +22,11 @@ import type { 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'; -import { applicationIdInfo } from '../../utils/messages'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { ExpectedError } from '../../errors.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class DeviceMoveCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/os-update.ts b/lib/commands/device/os-update.ts index c7883ae049..b4ba86aaa0 100644 --- a/lib/commands/device/os-update.ts +++ b/lib/commands/device/os-update.ts @@ -16,11 +16,11 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js'; import type { Device } from 'balena-sdk'; -import { ExpectedError } from '../../errors'; +import { ExpectedError } from '../../errors.js'; export default class DeviceOsUpdateCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/pin.ts b/lib/commands/device/pin.ts index 51f582bfaa..6a855143cc 100644 --- a/lib/commands/device/pin.ts +++ b/lib/commands/device/pin.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { getExpandedProp } from '../../utils/pine'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { getExpandedProp } from '../../utils/pine.js'; export default class DevicePinCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/public-url.ts b/lib/commands/device/public-url.ts index 5132607048..8879e084b0 100644 --- a/lib/commands/device/public-url.ts +++ b/lib/commands/device/public-url.ts @@ -16,10 +16,10 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import { ExpectedError } from '../../errors'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class DevicePublicUrlCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/purge.ts b/lib/commands/device/purge.ts index a40d00e6c2..d2752292a7 100644 --- a/lib/commands/device/purge.ts +++ b/lib/commands/device/purge.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js'; export default class DevicePurgeCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/reboot.ts b/lib/commands/device/reboot.ts index daef864bae..04a92610d1 100644 --- a/lib/commands/device/reboot.ts +++ b/lib/commands/device/reboot.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class DeviceRebootCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/register.ts b/lib/commands/device/register.ts index 6a366267e2..72b05bf86c 100644 --- a/lib/commands/device/register.ts +++ b/lib/commands/device/register.ts @@ -16,11 +16,11 @@ */ import { Flags } from '@oclif/core'; -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 '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import * as ca from '../../utils/common-args.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class DeviceRegisterCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/rename.ts b/lib/commands/device/rename.ts index be6c38f42c..7d58f1e54d 100644 --- a/lib/commands/device/rename.ts +++ b/lib/commands/device/rename.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js'; export default class DeviceRenameCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/restart.ts b/lib/commands/device/restart.ts index 8b71c10123..ecbac949f1 100644 --- a/lib/commands/device/restart.ts +++ b/lib/commands/device/restart.ts @@ -16,9 +16,9 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js'; import type { BalenaSDK, DeviceWithServiceDetails, diff --git a/lib/commands/device/rm.ts b/lib/commands/device/rm.ts index 9f7e820630..21b7e5eb8d 100644 --- a/lib/commands/device/rm.ts +++ b/lib/commands/device/rm.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class DeviceRmCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/shutdown.ts b/lib/commands/device/shutdown.ts index 7da13adefc..3c6f36c475 100644 --- a/lib/commands/device/shutdown.ts +++ b/lib/commands/device/shutdown.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { ExpectedError } from '../../errors'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { ExpectedError } from '../../errors.js'; export default class DeviceShutdownCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/device/start-service.ts b/lib/commands/device/start-service.ts index 460f5e3f67..60027fd300 100644 --- a/lib/commands/device/start-service.ts +++ b/lib/commands/device/start-service.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js'; import type { BalenaSDK } from 'balena-sdk'; export default class DeviceStartServiceCmd extends Command { diff --git a/lib/commands/device/stop-service.ts b/lib/commands/device/stop-service.ts index 1ae793ff5b..9260c543db 100644 --- a/lib/commands/device/stop-service.ts +++ b/lib/commands/device/stop-service.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js'; import type { BalenaSDK } from 'balena-sdk'; export default class DeviceStopServiceCmd extends Command { diff --git a/lib/commands/device/track-fleet.ts b/lib/commands/device/track-fleet.ts index edb164ef22..b0935b2429 100644 --- a/lib/commands/device/track-fleet.ts +++ b/lib/commands/device/track-fleet.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class DeviceTrackFleetCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/devices/index.ts b/lib/commands/devices/index.ts index 70991a3a00..9509a61103 100644 --- a/lib/commands/devices/index.ts +++ b/lib/commands/devices/index.ts @@ -15,11 +15,11 @@ * limitations under the License. */ -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { expandForAppName } from '../../utils/helpers'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; -import { applicationIdInfo, jsonInfo } from '../../utils/messages'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { expandForAppName } from '../../utils/helpers.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo, jsonInfo } from '../../utils/messages.js'; import type { Device, PineOptions } from 'balena-sdk'; diff --git a/lib/commands/devices/supported.ts b/lib/commands/devices/supported.ts index 93305a41b1..4f984db9dd 100644 --- a/lib/commands/devices/supported.ts +++ b/lib/commands/devices/supported.ts @@ -16,12 +16,12 @@ */ import { Flags } from '@oclif/core'; import type * as BalenaSdk from 'balena-sdk'; -import * as _ from 'lodash'; -import Command from '../../command'; +import _ from 'lodash'; +import Command from '../../command.js'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; -import { CommandHelp } from '../../utils/oclif-utils'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; +import { CommandHelp } from '../../utils/oclif-utils.js'; export default class DevicesSupportedCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/env/add.ts b/lib/commands/env/add.ts index 77c58fc56c..bf6a6a5766 100644 --- a/lib/commands/env/add.ts +++ b/lib/commands/env/add.ts @@ -17,11 +17,11 @@ import { Args } 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'; -import { applicationIdInfo } from '../../utils/messages'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; interface FlagsDef { fleet?: string; diff --git a/lib/commands/env/rename.ts b/lib/commands/env/rename.ts index 6f9a3b992c..6058ae96c5 100644 --- a/lib/commands/env/rename.ts +++ b/lib/commands/env/rename.ts @@ -15,12 +15,12 @@ * limitations under the License. */ import { Args } from '@oclif/core'; -import Command from '../../command'; +import Command from '../../command.js'; -import * as cf from '../../utils/common-flags'; -import * as ec from '../../utils/env-common'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { parseAsInteger } from '../../utils/validation'; +import * as cf from '../../utils/common-flags.js'; +import * as ec from '../../utils/env-common.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { parseAsInteger } from '../../utils/validation.js'; export default class EnvRenameCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/env/rm.ts b/lib/commands/env/rm.ts index 1af607eb16..64343e2a9b 100644 --- a/lib/commands/env/rm.ts +++ b/lib/commands/env/rm.ts @@ -16,11 +16,11 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import Command from '../../command.js'; -import * as ec from '../../utils/env-common'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { parseAsInteger } from '../../utils/validation'; +import * as ec from '../../utils/env-common.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { parseAsInteger } from '../../utils/validation.js'; export default class EnvRmCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/envs/index.ts b/lib/commands/envs/index.ts index d0719d812a..11c37eabd4 100644 --- a/lib/commands/envs/index.ts +++ b/lib/commands/envs/index.ts @@ -17,12 +17,12 @@ import { Flags } 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'; -import { applicationIdInfo } from '../../utils/messages'; +import _ from 'lodash'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; type FlagsDef = Interfaces.InferredFlags; diff --git a/lib/commands/fleet/create.ts b/lib/commands/fleet/create.ts index a4f11a2ad7..5026df920f 100644 --- a/lib/commands/fleet/create.ts +++ b/lib/commands/fleet/create.ts @@ -17,9 +17,9 @@ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { stripIndent } from '../../utils/lazy.js'; export default class FleetCreateCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/fleet/index.ts b/lib/commands/fleet/index.ts index 81849e88e1..4bb5a160ab 100644 --- a/lib/commands/fleet/index.ts +++ b/lib/commands/fleet/index.ts @@ -17,11 +17,11 @@ import { Flags } from '@oclif/core'; -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 '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import * as ca from '../../utils/common-args.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class FleetCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/fleet/pin.ts b/lib/commands/fleet/pin.ts index 2b9f6cc17b..5b38130b58 100644 --- a/lib/commands/fleet/pin.ts +++ b/lib/commands/fleet/pin.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { getExpandedProp } from '../../utils/pine'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { getExpandedProp } from '../../utils/pine.js'; export default class FleetPinCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/fleet/purge.ts b/lib/commands/fleet/purge.ts index 4ecbd85cdb..9efaa7af74 100644 --- a/lib/commands/fleet/purge.ts +++ b/lib/commands/fleet/purge.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 '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import * as ca from '../../utils/common-args.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class FleetPurgeCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/fleet/rename.ts b/lib/commands/fleet/rename.ts index f8569aa1a2..793f285da9 100644 --- a/lib/commands/fleet/rename.ts +++ b/lib/commands/fleet/rename.ts @@ -17,11 +17,11 @@ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import * as ca from '../../utils/common-args'; -import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; -import { applicationIdInfo } from '../../utils/messages'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import * as ca from '../../utils/common-args.js'; +import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class FleetRenameCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/fleet/restart.ts b/lib/commands/fleet/restart.ts index 6d22b6573b..b67b014edf 100644 --- a/lib/commands/fleet/restart.ts +++ b/lib/commands/fleet/restart.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 '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import * as ca from '../../utils/common-args.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class FleetRestartCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/fleet/rm.ts b/lib/commands/fleet/rm.ts index 25dab03fce..e47240ab60 100644 --- a/lib/commands/fleet/rm.ts +++ b/lib/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 '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import * as ca from '../../utils/common-args.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class FleetRmCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/fleet/track-latest.ts b/lib/commands/fleet/track-latest.ts index e05a9365e3..ec8d579ebe 100644 --- a/lib/commands/fleet/track-latest.ts +++ b/lib/commands/fleet/track-latest.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class FleetTrackLatestCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/fleets/index.ts b/lib/commands/fleets/index.ts index fe649c186b..fff856fb9d 100644 --- a/lib/commands/fleets/index.ts +++ b/lib/commands/fleets/index.ts @@ -17,9 +17,9 @@ import type * as BalenaSdk from 'balena-sdk'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; interface ExtendedApplication extends ApplicationWithDeviceTypeSlug { device_count: number; diff --git a/lib/commands/internal/osinit.ts b/lib/commands/internal/osinit.ts index 9bc184b0f0..73d3a450fb 100644 --- a/lib/commands/internal/osinit.ts +++ b/lib/commands/internal/osinit.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import { stripIndent } from '../../utils/lazy'; -import { CommandHelp } from '../../utils/oclif-utils'; +import Command from '../../command.js'; +import { stripIndent } from '../../utils/lazy.js'; +import { CommandHelp } from '../../utils/oclif-utils.js'; // 'Internal' commands are called during the execution of other commands. // `osinit` is called during `os initialize` diff --git a/lib/commands/join/index.ts b/lib/commands/join/index.ts index a61efb1ee0..4c0d7f3c90 100644 --- a/lib/commands/join/index.ts +++ b/lib/commands/join/index.ts @@ -16,11 +16,11 @@ */ import { Args, Flags } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { applicationIdInfo } from '../../utils/messages'; -import { parseAsLocalHostnameOrIp } from '../../utils/validation'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; +import { parseAsLocalHostnameOrIp } from '../../utils/validation.js'; export default class JoinCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/key/add.ts b/lib/commands/key/add.ts index 797c251b13..3c6b528b44 100644 --- a/lib/commands/key/add.ts +++ b/lib/commands/key/add.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import { ExpectedError } from '../../errors'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class KeyAddCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/key/index.ts b/lib/commands/key/index.ts index 895e745159..ecffb5fc3c 100644 --- a/lib/commands/key/index.ts +++ b/lib/commands/key/index.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; -import { parseAsInteger } from '../../utils/validation'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; +import { parseAsInteger } from '../../utils/validation.js'; export default class KeyCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/key/rm.ts b/lib/commands/key/rm.ts index f9523efebc..a63dc51990 100644 --- a/lib/commands/key/rm.ts +++ b/lib/commands/key/rm.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { parseAsInteger } from '../../utils/validation'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { parseAsInteger } from '../../utils/validation.js'; export default class KeyRmCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/keys/index.ts b/lib/commands/keys/index.ts index ca81f366cd..18d99381c4 100644 --- a/lib/commands/keys/index.ts +++ b/lib/commands/keys/index.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; export default class KeysCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/leave/index.ts b/lib/commands/leave/index.ts index d30cf2ce18..8db65dd32d 100644 --- a/lib/commands/leave/index.ts +++ b/lib/commands/leave/index.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { stripIndent } from '../../utils/lazy'; -import { parseAsLocalHostnameOrIp } from '../../utils/validation'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { stripIndent } from '../../utils/lazy.js'; +import { parseAsLocalHostnameOrIp } from '../../utils/validation.js'; export default class LeaveCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/local/configure.ts b/lib/commands/local/configure.ts index 220d128847..6f2b84b476 100644 --- a/lib/commands/local/configure.ts +++ b/lib/commands/local/configure.ts @@ -17,9 +17,9 @@ import { Args } from '@oclif/core'; import { promisify } from 'util'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { stripIndent } from '../../utils/lazy.js'; export default class LocalConfigureCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/local/flash.ts b/lib/commands/local/flash.ts index c0293605cb..f36e68d2ca 100644 --- a/lib/commands/local/flash.ts +++ b/lib/commands/local/flash.ts @@ -17,10 +17,10 @@ import { Args } 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'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getChalk, getVisuals, stripIndent } from '../../utils/lazy.js'; export default class LocalFlashCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/login/index.ts b/lib/commands/login/index.ts index fb14048813..49289f58ed 100644 --- a/lib/commands/login/index.ts +++ b/lib/commands/login/index.ts @@ -16,10 +16,10 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy'; -import { ExpectedError } from '../../errors'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js'; +import { ExpectedError } from '../../errors.js'; import type { WhoamiResult } from 'balena-sdk'; interface FlagsDef { diff --git a/lib/commands/logout/index.ts b/lib/commands/logout/index.ts index 5ea4596350..654ebf28ee 100644 --- a/lib/commands/logout/index.ts +++ b/lib/commands/logout/index.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import Command from '../../command'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class LogoutCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/logs/index.ts b/lib/commands/logs/index.ts index 5b8b49cea2..d05c1286c4 100644 --- a/lib/commands/logs/index.ts +++ b/lib/commands/logs/index.ts @@ -16,9 +16,9 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; import type { LogMessage } from 'balena-sdk'; const MAX_RETRY = 1000; @@ -104,7 +104,6 @@ export default class LogsCmd extends Command { '../../utils/validation.js' ); const { default: Logger } = await import('../../utils/logger.js'); - const logger = Logger.getLogger(); const displayCloudLog = async (line: LogMessage) => { diff --git a/lib/commands/notes/index.ts b/lib/commands/notes/index.ts index fb3e38fc87..e8e38b6f89 100644 --- a/lib/commands/notes/index.ts +++ b/lib/commands/notes/index.ts @@ -16,10 +16,10 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import { ExpectedError } from '../../errors'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class NoteCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/orgs/index.ts b/lib/commands/orgs/index.ts index 28deb7f98e..357acfbe8b 100644 --- a/lib/commands/orgs/index.ts +++ b/lib/commands/orgs/index.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; export default class OrgsCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/os/build-config.ts b/lib/commands/os/build-config.ts index fe5c8323db..685f2063e8 100644 --- a/lib/commands/os/build-config.ts +++ b/lib/commands/os/build-config.ts @@ -16,10 +16,10 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getCliForm, stripIndent } from '../../utils/lazy'; -import * as _ from 'lodash'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getCliForm, stripIndent } from '../../utils/lazy.js'; +import _ from 'lodash'; import type { DeviceTypeJson } from 'balena-sdk'; export default class OsBuildConfigCmd extends Command { diff --git a/lib/commands/os/configure.ts b/lib/commands/os/configure.ts index 01a8b63899..81bcea7690 100644 --- a/lib/commands/os/configure.ts +++ b/lib/commands/os/configure.ts @@ -19,16 +19,16 @@ import { Flags, Args } 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'; +import _ from 'lodash'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent, getCliForm } from '../../utils/lazy.js'; import { applicationIdInfo, devModeInfo, secureBootInfo, -} from '../../utils/messages'; +} from '../../utils/messages.js'; const CONNECTIONS_FOLDER = '/system-connections'; @@ -205,7 +205,7 @@ export default class OsConfigureCmd extends Command { deviceTypeSlug, ); - let configJson: import('../../utils/config').ImgConfig | undefined; + let configJson: import('../../utils/config.js').ImgConfig | undefined; if (options.config) { const rawConfig = await fs.readFile(options.config, 'utf8'); configJson = JSON.parse(rawConfig); @@ -394,7 +394,7 @@ async function checkDeviceTypeCompatibility( async function askQuestionsForDeviceType( deviceType: BalenaSdk.DeviceTypeJson.DeviceType, options: FlagsDef, - configJson?: import('../../utils/config').ImgConfig, + configJson?: import('../../utils/config.js').ImgConfig, ): Promise { const answerSources: any[] = [ { diff --git a/lib/commands/os/download.ts b/lib/commands/os/download.ts index 66664b8152..0c9e008830 100644 --- a/lib/commands/os/download.ts +++ b/lib/commands/os/download.ts @@ -16,9 +16,9 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { stripIndent } from '../../utils/lazy.js'; export default class OsDownloadCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/os/initialize.ts b/lib/commands/os/initialize.ts index ca574483ce..801b67c0f7 100644 --- a/lib/commands/os/initialize.ts +++ b/lib/commands/os/initialize.ts @@ -16,9 +16,9 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getCliForm, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getCliForm, stripIndent } from '../../utils/lazy.js'; const INIT_WARNING_MESSAGE = ` diff --git a/lib/commands/os/versions.ts b/lib/commands/os/versions.ts index 79cd80497b..f7b7f45bb2 100644 --- a/lib/commands/os/versions.ts +++ b/lib/commands/os/versions.ts @@ -16,9 +16,9 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { stripIndent } from '../../utils/lazy.js'; export default class OsVersionsCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/preload/index.ts b/lib/commands/preload/index.ts index 6966d1ad5c..92df481dcf 100644 --- a/lib/commands/preload/index.ts +++ b/lib/commands/preload/index.ts @@ -15,21 +15,21 @@ * limitations under the License. */ -import Command from '../../command'; -import { ExpectedError } from '../../errors'; -import * as cf from '../../utils/common-flags'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; import { getBalenaSdk, getCliForm, getVisuals, stripIndent, -} from '../../utils/lazy'; -import { applicationIdInfo } from '../../utils/messages'; -import { dockerConnectionCliFlags } from '../../utils/docker'; -import { parseAsInteger } from '../../utils/validation'; +} from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; +import { dockerConnectionCliFlags } from '../../utils/docker.js'; +import { parseAsInteger } from '../../utils/validation.js'; import { Flags, Args } from '@oclif/core'; -import * as _ from 'lodash'; +import _ from 'lodash'; import type { Application, BalenaSDK, diff --git a/lib/commands/push/index.ts b/lib/commands/push/index.ts index 6560c26394..e8703380c0 100644 --- a/lib/commands/push/index.ts +++ b/lib/commands/push/index.ts @@ -17,18 +17,18 @@ import { Flags, Args } 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'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { dockerignoreHelp, registrySecretsHelp } from '../../utils/messages.js'; import type { BalenaSDK } from 'balena-sdk'; -import { ExpectedError, instanceOf } from '../../errors'; +import { ExpectedError, instanceOf } from '../../errors.js'; import type { RegistrySecrets } from '@balena/compose/dist/multibuild'; -import { lowercaseIfSlug } from '../../utils/normalization'; +import { lowercaseIfSlug } from '../../utils/normalization.js'; import { applyReleaseTagKeysAndValues, parseReleaseTagKeysAndValues, -} from '../../utils/compose_ts'; +} from '../../utils/compose_ts.js'; enum BuildTarget { Cloud, diff --git a/lib/commands/release/finalize.ts b/lib/commands/release/finalize.ts index 2ddb422ef2..8d3008e70b 100644 --- a/lib/commands/release/finalize.ts +++ b/lib/commands/release/finalize.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import { commitOrIdArg } from '.'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import { commitOrIdArg } from './index.js'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class ReleaseFinalizeCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/release/index.ts b/lib/commands/release/index.ts index a73a8d31df..72bec99c09 100644 --- a/lib/commands/release/index.ts +++ b/lib/commands/release/index.ts @@ -16,13 +16,13 @@ */ import { Flags, Args, type Interfaces } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; import type * as BalenaSdk from 'balena-sdk'; -import jsyaml = require('js-yaml'); -import { tryAsInteger } from '../../utils/validation'; -import { jsonInfo } from '../../utils/messages'; +import jsyaml from 'js-yaml'; +import { tryAsInteger } from '../../utils/validation.js'; +import { jsonInfo } from '../../utils/messages.js'; export const commitOrIdArg = Args.custom({ parse: async (commitOrId: string) => tryAsInteger(commitOrId), diff --git a/lib/commands/release/invalidate.ts b/lib/commands/release/invalidate.ts index f9f3f9b22b..f13f8433d5 100644 --- a/lib/commands/release/invalidate.ts +++ b/lib/commands/release/invalidate.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import { commitOrIdArg } from '.'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import { commitOrIdArg } from './index.js'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class ReleaseInvalidateCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/release/validate.ts b/lib/commands/release/validate.ts index 85ce4b4572..239412dfeb 100644 --- a/lib/commands/release/validate.ts +++ b/lib/commands/release/validate.ts @@ -15,10 +15,10 @@ * limitations under the License. */ -import { commitOrIdArg } from '.'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import { commitOrIdArg } from './index.js'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class ReleaseValidateCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/releases/index.ts b/lib/commands/releases/index.ts index 72ef9e0b95..659a2bec78 100644 --- a/lib/commands/releases/index.ts +++ b/lib/commands/releases/index.ts @@ -16,12 +16,12 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; -import { applicationNameNote } from '../../utils/messages'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; +import { applicationNameNote } from '../../utils/messages.js'; import type * as BalenaSdk from 'balena-sdk'; -import { jsonInfo } from '../../utils/messages'; +import { jsonInfo } from '../../utils/messages.js'; export default class ReleasesCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/scan/index.ts b/lib/commands/scan/index.ts index 181ef3c57d..0bf15f6372 100644 --- a/lib/commands/scan/index.ts +++ b/lib/commands/scan/index.ts @@ -16,9 +16,9 @@ */ import { Flags } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getCliUx, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getCliUx, stripIndent } from '../../utils/lazy.js'; export default class ScanCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/settings/index.ts b/lib/commands/settings/index.ts index f54c4db078..5ac3311f3e 100644 --- a/lib/commands/settings/index.ts +++ b/lib/commands/settings/index.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; export default class SettingsCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/ssh/index.ts b/lib/commands/ssh/index.ts index c469d90d28..5f9dccdf46 100644 --- a/lib/commands/ssh/index.ts +++ b/lib/commands/ssh/index.ts @@ -16,13 +16,13 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; import { parseAsInteger, validateLocalHostnameOrIp, -} from '../../utils/validation'; +} from '../../utils/validation.js'; export default class SshCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/support/index.ts b/lib/commands/support/index.ts index 22030c13c2..6303990d36 100644 --- a/lib/commands/support/index.ts +++ b/lib/commands/support/index.ts @@ -16,11 +16,11 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; -import { ExpectedError } from '../../errors'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy'; -import { applicationIdInfo } from '../../utils/messages'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getCliUx, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class SupportCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/tag/rm.ts b/lib/commands/tag/rm.ts index 1eaaa6fc7f..f1e09cb9a7 100644 --- a/lib/commands/tag/rm.ts +++ b/lib/commands/tag/rm.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { applicationIdInfo } from '../../utils/messages'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class TagRmCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/tag/set.ts b/lib/commands/tag/set.ts index 77d9bec761..8c854f4e68 100644 --- a/lib/commands/tag/set.ts +++ b/lib/commands/tag/set.ts @@ -16,10 +16,10 @@ */ import { Args } from '@oclif/core'; -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { applicationIdInfo } from '../../utils/messages'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class TagSetCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/tags/index.ts b/lib/commands/tags/index.ts index a7a7cbc5c8..79d8bd1bec 100644 --- a/lib/commands/tags/index.ts +++ b/lib/commands/tags/index.ts @@ -15,11 +15,11 @@ * limitations under the License. */ -import Command from '../../command'; -import { ExpectedError } from '../../errors'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; -import { applicationIdInfo } from '../../utils/messages'; +import Command from '../../command.js'; +import { ExpectedError } from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; +import { applicationIdInfo } from '../../utils/messages.js'; export default class TagsCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/tunnel/index.ts b/lib/commands/tunnel/index.ts index bac32073a4..4f5503f096 100644 --- a/lib/commands/tunnel/index.ts +++ b/lib/commands/tunnel/index.ts @@ -16,15 +16,15 @@ */ import { Flags, Args } from '@oclif/core'; -import Command from '../../command'; +import Command from '../../command.js'; import { NoPortsDefinedError, InvalidPortMappingError, ExpectedError, -} from '../../errors'; -import * as cf from '../../utils/common-flags'; -import { getBalenaSdk, stripIndent } from '../../utils/lazy'; -import { lowercaseIfSlug } from '../../utils/normalization'; +} from '../../errors.js'; +import * as cf from '../../utils/common-flags.js'; +import { getBalenaSdk, stripIndent } from '../../utils/lazy.js'; +import { lowercaseIfSlug } from '../../utils/normalization.js'; import type { Server, Socket } from 'net'; diff --git a/lib/commands/util/available-drives.ts b/lib/commands/util/available-drives.ts index ac71d201d9..8705dd7760 100644 --- a/lib/commands/util/available-drives.ts +++ b/lib/commands/util/available-drives.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import Command from '../../command'; -import * as cf from '../../utils/common-flags'; -import { stripIndent, getChalk, getVisuals } from '../../utils/lazy'; +import Command from '../../command.js'; +import * as cf from '../../utils/common-flags.js'; +import { stripIndent, getChalk, getVisuals } from '../../utils/lazy.js'; export default class UtilAvailableDrivesCmd extends Command { public static description = stripIndent` diff --git a/lib/commands/version/index.ts b/lib/commands/version/index.ts index 1fa1c2e27d..b0cbb89e99 100644 --- a/lib/commands/version/index.ts +++ b/lib/commands/version/index.ts @@ -16,8 +16,8 @@ */ import { Flags } from '@oclif/core'; -import Command from '../../command'; -import { stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import { stripIndent } from '../../utils/lazy.js'; export interface JsonVersions { 'balena-cli': string; diff --git a/lib/commands/whoami/index.ts b/lib/commands/whoami/index.ts index adc81acdf6..c1e8af5a1e 100644 --- a/lib/commands/whoami/index.ts +++ b/lib/commands/whoami/index.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import Command from '../../command'; -import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy'; +import Command from '../../command.js'; +import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy.js'; export default class WhoamiCmd extends Command { public static description = stripIndent` diff --git a/lib/deprecation.ts b/lib/deprecation.ts index c55f74cc2f..ccf997361b 100644 --- a/lib/deprecation.ts +++ b/lib/deprecation.ts @@ -16,6 +16,8 @@ */ import type { BalenaSettingsStorage } from 'balena-settings-storage'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); export interface ReleaseTimestampsByVersion { [version: string]: string; // e.g. { '12.0.0': '2021-06-16T12:54:52.000Z' } @@ -208,7 +210,7 @@ or release date not available`); /** Separate function for the benefit of code testing */ getDeprecationMsg(daysElapsed: number) { const { warnify } = - require('./utils/messages') as typeof import('./utils/messages'); + require('./utils/messages') as typeof import('./utils/messages.js'); return warnify(`\ CLI version ${this.nextMajorVersion} was released ${daysElapsed} days ago: please upgrade. This version of the balena CLI (${this.currentVersion}) will exit with an error diff --git a/lib/errors.ts b/lib/errors.ts index 90e365dddc..492b5d129a 100644 --- a/lib/errors.ts +++ b/lib/errors.ts @@ -15,12 +15,12 @@ limitations under the License. */ import type { BalenaError } from 'balena-errors'; -import * as _ from 'lodash'; +import _ from 'lodash'; import * as os from 'os'; import { TypedError } from 'typed-error'; -import { getChalk, stripIndent } from './utils/lazy'; -import { getHelp } from './utils/messages'; -import { CliSettings } from './utils/bootstrap'; +import { getChalk, stripIndent } from './utils/lazy.js'; +import { getHelp } from './utils/messages.js'; +import { CliSettings } from './utils/bootstrap.js'; export class ExpectedError extends TypedError { public code?: string; diff --git a/lib/events.ts b/lib/events.ts index fef266bfbc..2f08a07599 100644 --- a/lib/events.ts +++ b/lib/events.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import * as packageJSON from '../package.json'; -import { stripIndent } from './utils/lazy'; +import packageJSON from '../package.json' with { type: 'json' }; +import { stripIndent } from './utils/lazy.js'; /** * Track balena CLI usage events (product improvement analytics). diff --git a/lib/fast-boot.ts b/lib/fast-boot.ts index fd2718f915..1eaba08637 100644 --- a/lib/fast-boot.ts +++ b/lib/fast-boot.ts @@ -26,6 +26,8 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); const stat = process.pkg ? fs.statSync : fs.promises.stat; @@ -66,7 +68,7 @@ async function $start() { // such as `/usr[/local]/lib/balena-cli`, while being executed by // a regular user account. const cacheFile = path.join(dataDir, 'cli-module-cache.json'); - const root = path.join(__dirname, '..'); + const root = path.join(import.meta.dirname, '..'); const [, pJson, pStat, nStat] = await Promise.all([ ensureCanWrite(dataDir, cacheFile), import('../package.json'), diff --git a/lib/framework/index.ts b/lib/framework/index.ts index 24097f7bf0..65281acaaf 100644 --- a/lib/framework/index.ts +++ b/lib/framework/index.ts @@ -14,6 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -import type { DataOutputOptions, DataSetOutputOptions } from './output'; +import type { DataOutputOptions, DataSetOutputOptions } from './output.js'; export { DataOutputOptions, DataSetOutputOptions }; diff --git a/lib/framework/output.ts b/lib/framework/output.ts index ae0e5132ac..f99ddec840 100644 --- a/lib/framework/output.ts +++ b/lib/framework/output.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { getCliUx, getChalk } from '../utils/lazy'; +import { getCliUx, getChalk } from '../utils/lazy.js'; export interface DataOutputOptions { fields?: string; diff --git a/lib/help.ts b/lib/help.ts index 39796bc537..4b94dcbbec 100644 --- a/lib/help.ts +++ b/lib/help.ts @@ -16,7 +16,7 @@ */ import { Help } from '@oclif/core'; import indent from 'indent-string'; -import { getChalk } from './utils/lazy'; +import { getChalk } from './utils/lazy.js'; // Partially overrides standard implementation of help plugin // https://github.com/oclif/plugin-help/blob/master/src/index.ts @@ -44,7 +44,7 @@ export default class BalenaHelp extends Help { const subject = getHelpSubject(argv); if (!subject) { const verbose = argv.includes('-v') || argv.includes('--verbose'); - console.log(this.getCustomRootHelp(verbose)); + console.log(await this.getCustomRootHelp(verbose)); return; } @@ -83,7 +83,7 @@ export default class BalenaHelp extends Help { console.log(`command ${chalk.cyan.bold(subject)} not found`); } - getCustomRootHelp(showAllCommands: boolean): string { + async getCustomRootHelp(showAllCommands: boolean): Promise { const { bold, cyan } = getChalk(); let commands = this.config.commands; @@ -147,8 +147,7 @@ See: https://git.io/JRHUW#deprecation-policy`, ]; globalOps[0][0] = globalOps[0][0].padEnd(usageLength); - const { deprecationPolicyNote, reachingOut } = - require('./utils/messages') as typeof import('./utils/messages'); + const { deprecationPolicyNote, reachingOut } = await import('./utils/messages.js'); return [ bold('USAGE'), diff --git a/lib/hooks/command-not-found/suggest.ts b/lib/hooks/command-not-found/suggest.ts index 834dc00305..952bde9f5a 100644 --- a/lib/hooks/command-not-found/suggest.ts +++ b/lib/hooks/command-not-found/suggest.ts @@ -16,7 +16,7 @@ */ import type { Hook, Interfaces } from '@oclif/core'; -import { getChalk } from '../../utils/lazy'; +import { getChalk } from '../../utils/lazy.js'; /* A modified version of the command-not-found plugin logic, diff --git a/lib/preparser.ts b/lib/preparser.ts index 35161fb627..5fefe6d5ee 100644 --- a/lib/preparser.ts +++ b/lib/preparser.ts @@ -68,7 +68,7 @@ export async function preparseArgs(argv: string[]): Promise { process.env.BLUEBIRD_LONG_STACK_TRACES = '1'; } - const Logger = await import('./utils/logger.js'); + const { default: Logger } = await import('./utils/logger.js'); Logger.command = cmdSlice[0]; let args = cmdSlice; @@ -104,8 +104,8 @@ function extractBooleanFlag(argv: string[], flag: string): boolean { * Check whether the command line refers to a command that has been deprecated * and removed and, if so, exit with an informative error message. */ -export function checkDeletedCommand(argvSlice: string[]): void { - const { ExpectedError } = require('./errors') as typeof import('./errors'); +export async function checkDeletedCommand(argvSlice: string[]): Promise { + const { ExpectedError } = await import('./errors.js'); if (argvSlice[0] === 'help') { argvSlice = argvSlice.slice(1); diff --git a/lib/utils/application-create.ts b/lib/utils/application-create.ts index 74ae562ec9..23d5c77dcc 100644 --- a/lib/utils/application-create.ts +++ b/lib/utils/application-create.ts @@ -1,5 +1,5 @@ -import { ExpectedError } from '../errors'; -import { getBalenaSdk } from './lazy'; +import { ExpectedError } from '../errors.js'; +import { getBalenaSdk } from './lazy.js'; export interface FlagsDef { organization?: string; diff --git a/lib/utils/bootstrap.ts b/lib/utils/bootstrap.ts index 21e7ee6163..17ad7ad24c 100644 --- a/lib/utils/bootstrap.ts +++ b/lib/utils/bootstrap.ts @@ -21,6 +21,8 @@ * can be used very early on during CLI startup, before anything else * like Sentry error reporting, preparser, oclif parser and the like. */ +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); export class CliSettings { public readonly settings: any; diff --git a/lib/utils/cloud.ts b/lib/utils/cloud.ts index 536f11a201..591b54dfd7 100644 --- a/lib/utils/cloud.ts +++ b/lib/utils/cloud.ts @@ -16,10 +16,10 @@ */ import type * as SDK from 'balena-sdk'; -import * as _ from 'lodash'; -import { getBalenaSdk, getCliForm, getVisuals, stripIndent } from './lazy'; +import _ from 'lodash'; +import { getBalenaSdk, getCliForm, getVisuals, stripIndent } from './lazy.js'; -import { ExpectedError } from '../errors'; +import { ExpectedError } from '../errors.js'; export const serviceIdToName = _.memoize( async ( diff --git a/lib/utils/common-args.ts b/lib/utils/common-args.ts index 74ae9baa2e..040541eb60 100644 --- a/lib/utils/common-args.ts +++ b/lib/utils/common-args.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import { Args } from '@oclif/core'; -import { lowercaseIfSlug } from './normalization'; +import { lowercaseIfSlug } from './normalization.js'; export const fleetRequired = Args.string({ description: 'fleet name or slug (preferred)', diff --git a/lib/utils/common-flags.ts b/lib/utils/common-flags.ts index 0941ed4321..9c90ae1d0e 100644 --- a/lib/utils/common-flags.ts +++ b/lib/utils/common-flags.ts @@ -16,8 +16,8 @@ */ import { Flags } from '@oclif/core'; -import { stripIndent } from './lazy'; -import { lowercaseIfSlug } from './normalization'; +import { stripIndent } from './lazy.js'; +import { lowercaseIfSlug } from './normalization.js'; export const fleet = Flags.string({ char: 'f', diff --git a/lib/utils/compose.ts b/lib/utils/compose.ts index 5543115e8d..297b69c1fe 100644 --- a/lib/utils/compose.ts +++ b/lib/utils/compose.ts @@ -15,9 +15,9 @@ * limitations under the License. */ -import type { Renderer } from './compose_ts'; +import type { Renderer } from './compose_ts.js'; import type * as SDK from 'balena-sdk'; -import type Dockerode = require('dockerode'); +import type Dockerode from 'dockerode'; import * as path from 'path'; import type { Composition, ImageDescriptor } from '@balena/compose/dist/parse'; import type { RetryParametersObj } from 'pinejs-client-core'; @@ -27,10 +27,12 @@ import type { ComposeProject, Release, TaggedImage, -} from './compose-types'; -import { getChalk } from './lazy'; -import Logger = require('./logger'); +} from './compose-types.js'; +import { getChalk } from './lazy.js'; +import type Logger from './logger.js'; import type { ProgressCallback } from 'docker-progress'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); export function generateOpts(options: { source?: string; @@ -82,7 +84,7 @@ export function createProject( descr.image.tag == null ) { const { makeImageName } = - require('./compose_ts') as typeof import('./compose_ts'); + require('./compose_ts') as typeof import('./compose_ts.js'); descr.image.tag = makeImageName(projectName, descr.serviceName, imageTag); } return descr; @@ -318,7 +320,7 @@ const renderProgressBar = function (percentage: number, stepCount: number) { }; export const pushProgressRenderer = function ( - tty: ReturnType, + tty: ReturnType, prefix: string, ): ProgressCallback & { end: () => void } { const fn: ProgressCallback & { end: () => void } = function (e) { @@ -352,14 +354,14 @@ export class BuildProgressUI implements Renderer { private _spinner; private _runloop: | undefined - | ReturnType; + | ReturnType; // these are to handle window wrapping private _maxLineWidth: undefined | number; private _lineWidths: number[] = []; constructor( - tty: ReturnType, + tty: ReturnType, descriptors: ImageDescriptor[], ) { this._handleEvent = this._handleEvent.bind(this); @@ -400,7 +402,7 @@ export class BuildProgressUI implements Renderer { this._ended = false; this._cancelled = false; this._spinner = ( - require('./compose_ts') as typeof import('./compose_ts') + require('./compose_ts') as typeof import('./compose_ts.js') ).createSpinner(); this.streams = streams; @@ -419,7 +421,7 @@ export class BuildProgressUI implements Renderer { this.streams[service].write({ status: 'Preparing...' }); }); this._runloop = ( - require('./compose_ts') as typeof import('./compose_ts') + require('./compose_ts') as typeof import('./compose_ts.js') ).createRunLoop(this._display); this._startTime = Date.now(); } diff --git a/lib/utils/compose_ts.ts b/lib/utils/compose_ts.ts index 21eabf099d..fd2395dbf8 100644 --- a/lib/utils/compose_ts.ts +++ b/lib/utils/compose_ts.ts @@ -20,7 +20,7 @@ import type { TransposeOptions } from '@balena/compose/dist/emulate'; import type * as Dockerode from 'dockerode'; import { promises as fs } from 'fs'; import jsyaml = require('js-yaml'); -import * as _ from 'lodash'; +import _ from 'lodash'; import * as path from 'path'; import type { BuildConfig, @@ -31,18 +31,26 @@ import type * as MultiBuild from '@balena/compose/dist/multibuild'; import * as semver from 'semver'; import type { Duplex, Readable } from 'stream'; import type { Pack } from 'tar-stream'; -import { ExpectedError } from '../errors'; +import { ExpectedError } from '../errors.js'; import type { BuiltImage, ComposeOpts, ComposeProject, TaggedImage, TarDirectoryOptions, -} from './compose-types'; -import type { DeviceInfo } from './device/api'; -import { getBalenaSdk, getChalk, stripIndent } from './lazy'; -import Logger = require('./logger'); -import { exists } from './which'; +} from './compose-types.js'; +import type { DeviceInfo } from './device/api.js'; +import { getBalenaSdk, getChalk, stripIndent } from './lazy.js'; +import Logger from './logger.js'; +import { exists } from './which.js'; + +// TODO: fix typings on balena-model +import type { + ImageModel, + ReleaseModel, +} from '@balena/compose/dist/release/models.js'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); const allowedContractTypes = ['sw.application', 'sw.block']; @@ -249,7 +257,7 @@ export interface BuildProjectOpts { arch: string; deviceType: string; emulated: boolean; - buildOpts: import('./docker').BuildOpts; + buildOpts: import('./docker.js').BuildOpts; inlineLogs?: boolean; convertEol: boolean; dockerfilePath?: string; @@ -363,8 +371,7 @@ async function startRenderer({ imageDescriptors, ); } else { - const { default: $tty } = await import('./tty.js'); - const tty = $tty(process.stdout); + const tty = (await import('./tty.js')).default(process.stdout); renderer = new (await import('./compose.js')).BuildProgressUI( tty, imageDescriptors, @@ -432,7 +439,7 @@ function setTaskAttributes({ projectName, }: { tasks: BuildTaskPlus[]; - buildOpts: import('./docker').BuildOpts; + buildOpts: import('./docker.js').BuildOpts; imageDescriptorsByServiceName: Dictionary; projectName: string; }) { @@ -801,17 +808,17 @@ export async function tarDirectory( * @param multiDockerignore Whether --multi-dockerignore (-m) was provided */ function printDockerignoreWarn( - dockerignoreFiles: Array, + dockerignoreFiles: Array, serviceDirsByService: Dictionary, multiDockerignore: boolean, ) { - let rootDockerignore: import('./ignore').FileStats | undefined; + let rootDockerignore: import('./ignore.js').FileStats | undefined; const logger = Logger.getLogger(); const relPrefix = '.' + path.sep; const serviceDirs = Object.values(serviceDirsByService || {}); // compute a list of unused .dockerignore files const unusedFiles = dockerignoreFiles.filter( - (dockerignoreStats: import('./ignore').FileStats) => { + (dockerignoreStats: import('./ignore.js').FileStats) => { let dirname = path.dirname(dockerignoreStats.relPath); dirname = dirname.startsWith(relPrefix) ? dirname.slice(2) : dirname; const isProjectRootDir = !dirname || dirname === '.'; @@ -874,7 +881,7 @@ function printDockerignoreWarn( } } if (msg.length) { - const { warnify } = require('./messages') as typeof import('./messages'); + const { warnify } = require('./messages') as typeof import('./messages.js'); logFunc.call(logger, ' \n' + warnify(msg.join('\n'), '')); } } @@ -1241,16 +1248,12 @@ async function pushAndUpdateServiceImages( docker: Dockerode, token: string, images: TaggedImage[], - afterEach: ( - serviceImage: import('@balena/compose/dist/release/models').ImageModel, - props: object, - ) => Promise, + afterEach: (serviceImage: ImageModel, props: object) => Promise, ) { const { DockerProgress } = await import('docker-progress'); const { retry } = await import('./helpers.js'); const { pushProgressRenderer } = await import('./compose.js'); - const { default: $tty } = await import('./tty.js'); - const tty = $tty(process.stdout); + const tty = (await import('./tty.js')).default(process.stdout); const opts = { authconfig: { registrytoken: token } }; const progress = new DockerProgress({ docker }); const renderer = pushProgressRenderer( @@ -1333,7 +1336,7 @@ async function pushServiceImages( token: string, skipLogUpload: boolean, ): Promise { - const releaseMod = await import('@balena/compose/dist/release'); + const releaseMod = (await import('@balena/compose')).release; logger.logInfo('Pushing images to registry...'); await pushAndUpdateServiceImages( docker, @@ -1361,11 +1364,10 @@ export async function deployProject( skipLogUpload: boolean, projectPath: string, isDraft: boolean, -): Promise { +): Promise { const releaseMod = await import('@balena/compose/dist/release'); const { createRelease, tagServiceImages } = await import('./compose.js'); - const { default: $tty } = await import('./tty.js'); - const tty = $tty(process.stdout); + const tty = (await import('./tty.js')).default(process.stdout); const prefix = getChalk().cyan('[Info]') + ' '; const spinner = createSpinner(); @@ -1447,7 +1449,7 @@ export function createSpinner() { } async function runSpinner( - tty: ReturnType, + tty: ReturnType, spinner: () => string, msg: string, fn: () => Promise, diff --git a/lib/utils/config.ts b/lib/utils/config.ts index 3275c726b8..a8691a268f 100644 --- a/lib/utils/config.ts +++ b/lib/utils/config.ts @@ -15,7 +15,7 @@ limitations under the License. */ import type * as BalenaSdk from 'balena-sdk'; import * as semver from 'balena-semver'; -import { getBalenaSdk, stripIndent } from './lazy'; +import { getBalenaSdk, stripIndent } from './lazy.js'; export interface ImgConfig { applicationName: string; @@ -155,7 +155,7 @@ export function generateDeviceConfig( export async function validateDevOptionAndWarn( dev?: boolean, version?: string, - logger?: import('./logger'), + logger?: import('./logger.js').default, ) { if (!dev) { return; @@ -187,7 +187,7 @@ export async function validateSecureBootOptionAndWarn( secureBoot: boolean, slug: string, version: string, - logger?: import('./logger'), + logger?: import('./logger.js').default, ) { if (!secureBoot) { return; diff --git a/lib/utils/deploy-legacy.ts b/lib/utils/deploy-legacy.ts index 074e9cf246..cbc596cd8f 100644 --- a/lib/utils/deploy-legacy.ts +++ b/lib/utils/deploy-legacy.ts @@ -15,11 +15,13 @@ * limitations under the License. */ -import { getVisuals } from './lazy'; +import { getVisuals } from './lazy.js'; import { promisify } from 'util'; -import type * as Dockerode from 'dockerode'; -import type Logger = require('./logger'); +import type Dockerode from 'dockerode'; +import type Logger from './logger.js'; import type { Request } from 'request'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); const getBuilderPushEndpoint = function ( baseUrl: string, @@ -47,17 +49,16 @@ const getBuilderLogPushEndpoint = function ( * @param {string} imageId * @param {string} bufferFile */ -const bufferImage = function ( +const bufferImage = async function ( docker: Dockerode, imageId: string, bufferFile: string, ): Promise { - const streamUtils = require('./streams') as typeof import('./streams'); - + const streamUtils = await import('./streams.js'); const image = docker.getImage(imageId); const sizePromise = image.inspect().then((img) => img.Size); - return Promise.all([image.get(), sizePromise]).then( + return await Promise.all([image.get(), sizePromise]).then( ([imageStream, imageSize]) => streamUtils .buffer(imageStream, bufferFile) diff --git a/lib/utils/device/api.ts b/lib/utils/device/api.ts index 62f2b67b24..c3135a9b34 100644 --- a/lib/utils/device/api.ts +++ b/lib/utils/device/api.ts @@ -14,13 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as _ from 'lodash'; +import _ from 'lodash'; import request from 'request'; import type * as Stream from 'stream'; -import { retry } from '../helpers'; -import Logger = require('../logger'); -import * as ApiErrors from './errors'; +import { retry } from '../helpers.js'; +import type Logger from '../logger.js'; +import * as ApiErrors from './errors.js'; export interface DeviceResponse { [key: string]: any; diff --git a/lib/utils/device/deploy.ts b/lib/utils/device/deploy.ts index 9c5e64ae55..2890c984a2 100644 --- a/lib/utils/device/deploy.ts +++ b/lib/utils/device/deploy.ts @@ -17,7 +17,7 @@ import * as semver from 'balena-semver'; import Docker from 'dockerode'; -import * as _ from 'lodash'; +import _ from 'lodash'; import type { Composition } from '@balena/compose/dist/parse'; import type { BuildTask, @@ -27,22 +27,22 @@ import type { import { getAuthConfigObj } from '@balena/compose/dist/multibuild'; import type { Readable } from 'stream'; -import { BALENA_ENGINE_TMP_PATH } from '../../config'; -import { ExpectedError } from '../../errors'; +import { BALENA_ENGINE_TMP_PATH } from '../../config.js'; +import { ExpectedError } from '../../errors.js'; import { checkBuildSecretsRequirements, loadProject, makeBuildTasks, tarDirectory, makeImageName, -} from '../compose_ts'; -import Logger = require('../logger'); -import type { DeviceInfo } from './api'; -import { DeviceAPI } from './api'; -import * as LocalPushErrors from './errors'; -import LivepushManager from './live'; -import { displayBuildLog } from './logs'; -import { stripIndent } from '../lazy'; +} from '../compose_ts.js'; +import Logger from '../logger.js'; +import type { DeviceInfo } from './api.js'; +import { DeviceAPI } from './api.js'; +import * as LocalPushErrors from './errors.js'; +import LivepushManager from './live.js'; +import { displayBuildLog } from './logs.js'; +import { stripIndent } from '../lazy.js'; const LOCAL_APPNAME = 'localapp'; const LOCAL_RELEASEHASH = '10ca12e1ea5e'; diff --git a/lib/utils/device/errors.ts b/lib/utils/device/errors.ts index 5455a803bf..5f3668a435 100644 --- a/lib/utils/device/errors.ts +++ b/lib/utils/device/errors.ts @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as _ from 'lodash'; +import _ from 'lodash'; -import { ExpectedError } from '../../errors'; +import { ExpectedError } from '../../errors.js'; export interface BuildFailure { error: Error; diff --git a/lib/utils/device/live.ts b/lib/utils/device/live.ts index 667b31fe6e..b428b7bf4f 100644 --- a/lib/utils/device/live.ts +++ b/lib/utils/device/live.ts @@ -18,23 +18,23 @@ import * as chokidar from 'chokidar'; import type * as Dockerode from 'dockerode'; import * as fs from 'fs'; -import Livepush, { ContainerNotRunningError } from 'livepush'; -import * as _ from 'lodash'; +import { Livepush, ContainerNotRunningError } from 'livepush'; +import _ from 'lodash'; import * as path from 'path'; import type { Composition } from '@balena/compose/dist/parse'; import type { BuildTask } from '@balena/compose/dist/multibuild'; -import { instanceOf } from '../../errors'; -import Logger = require('../logger'); +import { instanceOf } from '../../errors.js'; +import type Logger from '../logger.js'; import { Dockerfile } from 'livepush'; -import type DeviceAPI from './api'; -import type { DeviceInfo, Status } from './api'; -import type { DeviceDeployOptions } from './deploy'; -import { generateTargetState, rebuildSingleTask } from './deploy'; -import { BuildError } from './errors'; -import { getServiceColourFn } from './logs'; -import { delay } from '../helpers'; +import type DeviceAPI from './api.js'; +import type { DeviceInfo, Status } from './api.js'; +import type { DeviceDeployOptions } from './deploy.js'; +import { generateTargetState, rebuildSingleTask } from './deploy.js'; +import { BuildError } from './errors.js'; +import { getServiceColourFn } from './logs.js'; +import { delay } from '../helpers.js'; // How often do we want to check the device state // engine has settled (delay in ms) diff --git a/lib/utils/device/logs.ts b/lib/utils/device/logs.ts index 2786600c0d..c3e6590711 100644 --- a/lib/utils/device/logs.ts +++ b/lib/utils/device/logs.ts @@ -15,12 +15,12 @@ * limitations under the License. */ import ColorHash = require('color-hash'); -import * as _ from 'lodash'; +import _ from 'lodash'; import type { Readable } from 'stream'; -import { getChalk } from '../lazy'; -import Logger = require('../logger'); -import { ExpectedError, SIGINTError } from '../../errors'; +import { getChalk } from '../lazy.js'; +import type Logger from '../logger.js'; +import { ExpectedError, SIGINTError } from '../../errors.js'; class DeviceConnectionLostError extends ExpectedError { public static defaultMsg = 'Connection to device lost'; @@ -113,7 +113,7 @@ export async function connectAndDisplayDeviceLogs({ filterServices, maxAttempts = 3, }: { - deviceApi: import('./api').DeviceAPI; + deviceApi: import('./api.js').DeviceAPI; logger: Logger; system: boolean; filterServices?: string[]; diff --git a/lib/utils/device/ssh.ts b/lib/utils/device/ssh.ts index 3138a2bd14..283e2690f6 100644 --- a/lib/utils/device/ssh.ts +++ b/lib/utils/device/ssh.ts @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { ExpectedError } from '../../errors'; -import { stripIndent } from '../lazy'; +import { ExpectedError } from '../../errors.js'; +import { stripIndent } from '../lazy.js'; -import type { SshRemoteCommandOpts } from '../ssh'; +import type { SshRemoteCommandOpts } from '../ssh.js'; import { findBestUsernameForDevice, getRemoteCommandOutput, runRemoteCommand, -} from '../ssh'; +} from '../ssh.js'; export interface DeviceSSHOpts extends SshRemoteCommandOpts { forceTTY?: boolean; diff --git a/lib/utils/discover.ts b/lib/utils/discover.ts index 25e1c30973..abd719e5a6 100644 --- a/lib/utils/discover.ts +++ b/lib/utils/discover.ts @@ -1,4 +1,4 @@ -import Bonjour from 'bonjour-service'; +import { Bonjour } from 'bonjour-service'; import type { Service } from 'bonjour-service'; interface LocalBalenaOsDevice { diff --git a/lib/utils/docker.ts b/lib/utils/docker.ts index 58b414c137..45270005b2 100644 --- a/lib/utils/docker.ts +++ b/lib/utils/docker.ts @@ -18,8 +18,10 @@ import type * as dockerode from 'dockerode'; import { Flags } from '@oclif/core'; -import { ExpectedError } from '../errors'; -import { parseAsInteger } from './validation'; +import { ExpectedError } from '../errors.js'; +import { parseAsInteger } from './validation.js'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); interface BalenaEngineVersion extends dockerode.DockerVersion { Engine?: string; diff --git a/lib/utils/env-common.ts b/lib/utils/env-common.ts index 966545727e..0389ebd749 100644 --- a/lib/utils/env-common.ts +++ b/lib/utils/env-common.ts @@ -16,9 +16,9 @@ */ import { Flags } from '@oclif/core'; -import { stripIndent } from './lazy'; +import { stripIndent } from './lazy.js'; -import { ExpectedError } from '../errors'; +import { ExpectedError } from '../errors.js'; export const booleanConfig = Flags.boolean({ char: 'c', diff --git a/lib/utils/eol-conversion.ts b/lib/utils/eol-conversion.ts index 2d015c6b10..ec76fcdd93 100644 --- a/lib/utils/eol-conversion.ts +++ b/lib/utils/eol-conversion.ts @@ -16,7 +16,7 @@ */ import { promises as fs } from 'fs'; -import Logger = require('./logger'); +import Logger from './logger.js'; const globalLogger = Logger.getLogger(); diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index f29cd68a85..e32a8eb8ae 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -17,10 +17,12 @@ limitations under the License. import type { InitializeEmitter, OperationState } from 'balena-device-init'; import type * as BalenaSdk from 'balena-sdk'; -import * as _ from 'lodash'; +import _ from 'lodash'; import { promisify } from 'util'; -import { getBalenaSdk, getChalk, getVisuals } from './lazy'; +import { getBalenaSdk, getChalk, getVisuals } from './lazy.js'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); export function getGroupDefaults(group: { options: Array<{ name: string; default: string | number }>; @@ -90,8 +92,7 @@ export async function sudo( } export async function runCommand(commandArgs: string[]): Promise { - const { isSubcommand } = - require('../preparser') as typeof import('../preparser'); + const { isSubcommand } = await import('../preparser.js'); if (await isSubcommand(commandArgs)) { commandArgs = [ commandArgs[0] + ':' + commandArgs[1], @@ -99,7 +100,7 @@ export async function runCommand(commandArgs: string[]): Promise { ]; } - const { run } = require('@oclif/core') as typeof import('@oclif/core'); + const { run } = await import('@oclif/core'); return run(commandArgs) as Promise; } @@ -486,7 +487,7 @@ export async function awaitInterruptibleTask< const sigintPromise = new Promise((_resolve, reject) => { sigintHandler = () => { const { SIGINTError } = - require('../errors') as typeof import('../errors'); + require('../errors.js') as typeof import('../errors.js'); reject(new SIGINTError('Task aborted on SIGINT signal')); }; addSIGINTHandler(sigintHandler); diff --git a/lib/utils/ignore.ts b/lib/utils/ignore.ts index a9be22752f..69e279f334 100644 --- a/lib/utils/ignore.ts +++ b/lib/utils/ignore.ts @@ -14,14 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as _ from 'lodash'; +import _ from 'lodash'; import type { Stats } from 'fs'; import { promises as fs } from 'fs'; import * as path from 'path'; import type { Ignore } from '@balena/dockerignore'; -import { ExpectedError } from '../errors'; +import { ExpectedError } from '../errors.js'; export interface FileStats { filePath: string; diff --git a/lib/utils/lazy.ts b/lib/utils/lazy.ts index c6d0a98450..3303dba954 100644 --- a/lib/utils/lazy.ts +++ b/lib/utils/lazy.ts @@ -21,6 +21,8 @@ import type { Chalk } from 'chalk'; import type * as visuals from 'resin-cli-visuals'; import type * as CliForm from 'resin-cli-form'; import type { ux } from '@oclif/core'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); // Equivalent of _.once but avoiding the need to import lodash for lazy deps const once = (fn: () => T) => { diff --git a/lib/utils/logger.ts b/lib/utils/logger.ts index 7aa69314f1..22c9309b3f 100644 --- a/lib/utils/logger.ts +++ b/lib/utils/logger.ts @@ -17,7 +17,7 @@ import _ = require('lodash'); import { EOL as eol } from 'os'; import { StreamLogger } from 'resin-stream-logger'; -import { getChalk } from './lazy'; +import { getChalk } from './lazy.js'; enum Level { BUILD = 'build', @@ -175,4 +175,4 @@ class Logger { } } -export = Logger; +export default Logger; diff --git a/lib/utils/normalization.ts b/lib/utils/normalization.ts index 3bf8fd5b66..6be48aebc4 100644 --- a/lib/utils/normalization.ts +++ b/lib/utils/normalization.ts @@ -16,7 +16,7 @@ */ import type { BalenaSDK } from 'balena-sdk'; -import { ExpectedError } from '../errors'; +import { ExpectedError } from '../errors.js'; /** * Takes a string which may represent one of: diff --git a/lib/utils/oclif-utils.ts b/lib/utils/oclif-utils.ts index ceac7501c3..c7889e5da1 100644 --- a/lib/utils/oclif-utils.ts +++ b/lib/utils/oclif-utils.ts @@ -52,7 +52,9 @@ export function capitanoizeOclifUsage( } export async function getCommandsFromManifest() { - const manifest = require('../../oclif.manifest.json'); + const { default: manifest } = await import('../../oclif.manifest.json', { + with: { type: 'json' }, + }); if (manifest.commands == null) { throw new Error('Commands section not found in manifest.'); diff --git a/lib/utils/patterns.ts b/lib/utils/patterns.ts index 18e6a1f332..c627a4323c 100644 --- a/lib/utils/patterns.ts +++ b/lib/utils/patterns.ts @@ -24,10 +24,10 @@ import type { PineTypedResult, } from 'balena-sdk'; -import { instanceOf, NotLoggedInError, ExpectedError } from '../errors'; -import { getBalenaSdk, getVisuals, stripIndent, getCliForm } from './lazy'; -import validation = require('./validation'); -import { delay } from './helpers'; +import { instanceOf, NotLoggedInError, ExpectedError } from '../errors.js'; +import { getBalenaSdk, getVisuals, stripIndent, getCliForm } from './lazy.js'; +import * as validation from './validation.js'; +import { delay } from './helpers.js'; import type Bluebird from 'bluebird'; export function authenticate(options: object): Bluebird { @@ -305,8 +305,8 @@ export async function getOnlineTargetDeviceUuid( sdk: BalenaSDK, fleetOrDevice: string, ) { - const { default: Logger } = await import('../utils/logger.js'); - const logger = Logger.getLogger(); + const Logger = await import('../utils/logger.js'); + const logger = Logger.default.getLogger(); // If looks like UUID, probably device if (validation.validateUuid(fleetOrDevice)) { diff --git a/lib/utils/promote.ts b/lib/utils/promote.ts index e7f8165d4f..0ba4bead07 100644 --- a/lib/utils/promote.ts +++ b/lib/utils/promote.ts @@ -16,11 +16,11 @@ */ import type * as BalenaSdk from 'balena-sdk'; -import { ExpectedError, printErrorMessage } from '../errors'; -import { getVisuals, stripIndent, getCliForm } from './lazy'; -import Logger = require('./logger'); -import { confirm } from './patterns'; -import { getLocalDeviceCmdStdout, getDeviceOsRelease } from './ssh'; +import { ExpectedError, printErrorMessage } from '../errors.js'; +import { getVisuals, stripIndent, getCliForm } from './lazy.js'; +import type Logger from './logger.js'; +import { confirm } from './patterns.js'; +import { getLocalDeviceCmdStdout, getDeviceOsRelease } from './ssh.js'; const MIN_BALENAOS_VERSION = 'v2.14.0'; diff --git a/lib/utils/proxy.ts b/lib/utils/proxy.ts index c4147f5e65..cbc1a10fb7 100644 --- a/lib/utils/proxy.ts +++ b/lib/utils/proxy.ts @@ -18,7 +18,7 @@ import type { Options as GlobalTunnelNgConfig } from 'global-tunnel-ng'; export type { GlobalTunnelNgConfig }; -import type { CliSettings } from './bootstrap'; +import type { CliSettings } from './bootstrap.js'; type ProxyConfig = string | GlobalTunnelNgConfig; diff --git a/lib/utils/qemu.ts b/lib/utils/qemu.ts index ed54254f0c..53c586db29 100644 --- a/lib/utils/qemu.ts +++ b/lib/utils/qemu.ts @@ -17,9 +17,11 @@ import type * as Dockerode from 'dockerode'; -import { ExpectedError } from '../errors'; -import { getBalenaSdk, stripIndent } from './lazy'; -import Logger = require('./logger'); +import { ExpectedError } from '../errors.js'; +import { getBalenaSdk, stripIndent } from './lazy.js'; +import type Logger from './logger.js'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); export const QEMU_VERSION = 'v7.0.0+balena1'; export const QEMU_BIN_NAME = 'qemu-execve'; @@ -31,9 +33,9 @@ export function qemuPathInContext(context: string) { return path.relative(context, binPath); } -export function copyQemu(context: string, arch: string) { - const path = require('path') as typeof import('path'); - const fs = require('fs') as typeof import('fs'); +export async function copyQemu(context: string, arch: string) { + const path = await import('path'); + const fs = await import('fs'); // Create a hidden directory in the build context, containing qemu const binDir = path.join(context, '.balena'); const binPath = path.join(binDir, QEMU_BIN_NAME); @@ -65,11 +67,11 @@ export function copyQemu(context: string, arch: string) { .then(() => path.relative(context, binPath)); } -export const getQemuPath = function (balenaArch: string) { +export const getQemuPath = async function (balenaArch: string) { const qemuArch = balenaArchToQemuArch(balenaArch); const balena = getBalenaSdk(); - const path = require('path') as typeof import('path'); - const { promises: fs } = require('fs') as typeof import('fs'); + const path = await import('path'); + const { promises: fs } = await import('fs'); return balena.settings.get('binDirectory').then((binDir) => fs diff --git a/lib/utils/remote-build.ts b/lib/utils/remote-build.ts index 1887fc9f3d..885fccee9b 100644 --- a/lib/utils/remote-build.ts +++ b/lib/utils/remote-build.ts @@ -22,10 +22,12 @@ import type * as Stream from 'stream'; import streamToPromise = require('stream-to-promise'); import type { Pack } from 'tar-stream'; -import { ExpectedError, SIGINTError } from '../errors'; -import { tarDirectory } from './compose_ts'; -import { getVisuals, stripIndent } from './lazy'; -import Logger = require('./logger'); +import { ExpectedError, SIGINTError } from '../errors.js'; +import { tarDirectory } from './compose_ts.js'; +import { getVisuals, stripIndent } from './lazy.js'; +import Logger from './logger.js'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); const globalLogger = Logger.getLogger(); diff --git a/lib/utils/ssh.ts b/lib/utils/ssh.ts index 3e8527d9d6..0170193e93 100644 --- a/lib/utils/ssh.ts +++ b/lib/utils/ssh.ts @@ -16,9 +16,9 @@ */ import type { StdioOptions } from 'child_process'; import { spawn } from 'child_process'; -import * as _ from 'lodash'; +import _ from 'lodash'; -import { ExpectedError } from '../errors'; +import { ExpectedError } from '../errors.js'; export class SshPermissionDeniedError extends ExpectedError {} diff --git a/lib/utils/streams.ts b/lib/utils/streams.ts index 23f51e88c4..bb94abc246 100644 --- a/lib/utils/streams.ts +++ b/lib/utils/streams.ts @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import fs = require('fs'); +import fs from 'fs'; -export function buffer( +export async function buffer( stream: NodeJS.ReadableStream, bufferFile: string, ): Promise { diff --git a/lib/utils/sudo.ts b/lib/utils/sudo.ts index 3e8953dd3f..c1e6b6792b 100644 --- a/lib/utils/sudo.ts +++ b/lib/utils/sudo.ts @@ -17,7 +17,7 @@ import type { ChildProcess, SpawnOptions } from 'child_process'; import { spawn } from 'child_process'; -import { stripIndent } from './lazy'; +import { stripIndent } from './lazy.js'; /** * Execute a child process with admin / superuser privileges, prompting the user for @@ -116,5 +116,10 @@ async function windosuExec( `; throw new Error(msg); } + + const { + default: { createRequire }, + } = await import('node:module'); + const require = createRequire(import.meta.url); return require('windosu').exec(escapedArgs.join(' ')); } diff --git a/lib/utils/tty.ts b/lib/utils/tty.ts index 7c786956b1..6b647dd0b9 100644 --- a/lib/utils/tty.ts +++ b/lib/utils/tty.ts @@ -14,7 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); const windowSize: { width?: number; height?: number } = {}; const updateWindowSize = () => { @@ -25,7 +27,7 @@ const updateWindowSize = () => { process.stdout.on('resize', updateWindowSize); -export = (stream: NodeJS.WriteStream = process.stdout) => { +export default (stream: NodeJS.WriteStream = process.stdout) => { // make sure we get initial metrics updateWindowSize(); diff --git a/lib/utils/tunnel.ts b/lib/utils/tunnel.ts index aa2f660202..906aafd40d 100644 --- a/lib/utils/tunnel.ts +++ b/lib/utils/tunnel.ts @@ -17,7 +17,7 @@ import type { BalenaSDK } from 'balena-sdk'; import type { Socket } from 'net'; import * as tls from 'tls'; import { TypedError } from 'typed-error'; -import { ExpectedError } from '../errors'; +import { ExpectedError } from '../errors.js'; const PROXY_CONNECT_TIMEOUT_MS = 10000; diff --git a/lib/utils/update.ts b/lib/utils/update.ts index 918acc9263..4b336dfc85 100644 --- a/lib/utils/update.ts +++ b/lib/utils/update.ts @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -import isRoot = require('is-root'); +import isRoot from 'is-root'; import UpdateNotifier from 'update-notifier'; - -import packageJSON = require('../../package.json'); +import packageJSON from '../../package.json' with { type: 'json' }; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); // Check for an update at most once a day. 1 day granularity should be // enough, rather than every run. Note because we show the information diff --git a/lib/utils/validation.ts b/lib/utils/validation.ts index 891ec39bd2..4e66142d53 100644 --- a/lib/utils/validation.ts +++ b/lib/utils/validation.ts @@ -15,7 +15,7 @@ limitations under the License. */ import validEmail = require('@resin.io/valid-email'); -import { ExpectedError } from '../errors'; +import { ExpectedError } from '../errors.js'; const APPNAME_REGEX = new RegExp(/^[a-zA-Z0-9_-]+$/); // An regex to detect an IP address, from https://www.regular-expressions.info/ip.html diff --git a/lib/utils/version.ts b/lib/utils/version.ts index 739b3803bf..931f18d499 100644 --- a/lib/utils/version.ts +++ b/lib/utils/version.ts @@ -16,8 +16,11 @@ */ import * as semver from 'semver'; -import { version } from '../../package.json'; +import packageJson from '../../package.json' with { type: 'json' }; export function isVersionGTE(v: string): boolean { - return semver.gte(process.env.BALENA_CLI_VERSION_OVERRIDE || version, v); + return semver.gte( + process.env.BALENA_CLI_VERSION_OVERRIDE || packageJson.version, + v, + ); } diff --git a/lib/utils/which.ts b/lib/utils/which.ts index af7cafe607..679e416346 100644 --- a/lib/utils/which.ts +++ b/lib/utils/which.ts @@ -17,6 +17,8 @@ import { promises as fs, constants } from 'fs'; import * as path from 'path'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); export const { F_OK, R_OK, W_OK, X_OK } = constants; diff --git a/package.json b/package.json index ec2bdd899c..e6a27c087a 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "name": "balena-cli", "version": "18.2.31", "description": "The official balena Command Line Interface", - "main": "./build/app.js", + "main": "./build/lib/app.js", "homepage": "https://github.com/balena-io/balena-cli", "repository": { "type": "git", "url": "git@github.com:balena-io/balena-cli.git" }, + "type": "module", "preferGlobal": true, "files": [ "bin/.fast-boot.json", @@ -32,7 +33,7 @@ "node_modules/@balena/compose/dist/parse/schemas/*.json" ], "assets": [ - "build/auth/pages/*.ejs", + "build/lib/auth/pages/*.ejs", "node_modules/balena-sdk/node_modules/balena-pine/**/*", "node_modules/balena-pine/**/*", "node_modules/pinejs-client-core/**/*", @@ -91,7 +92,7 @@ "author": "Balena Inc. (https://balena.io/)", "license": "Apache-2.0", "engines": { - "node": "^20.6.0" + "node": "^20.11.0" }, "husky": { "hooks": { @@ -100,12 +101,12 @@ }, "oclif": { "bin": "balena", - "commands": "./build/commands", - "helpClass": "./build/help", + "commands": "./build/lib/commands", + "helpClass": "./build/lib/help", "topicSeparator": " ", "hooks": { - "prerun": "./build/hooks/prerun/track", - "command_not_found": "./build/hooks/command-not-found/suggest" + "prerun": "./build/lib/hooks/prerun/track", + "command_not_found": "./build/lib/hooks/command-not-found/suggest" }, "additionalHelpFlags": [ "help" diff --git a/tests/auth/server.spec.ts b/tests/auth/server.spec.ts index 6a399d1b51..ed0ec9eebc 100644 --- a/tests/auth/server.spec.ts +++ b/tests/auth/server.spec.ts @@ -33,7 +33,7 @@ const { expect } = chai; async function getPage(name: string): Promise { const pagePath = path.join( - __dirname, + import.meta.dirname, '..', '..', 'build', diff --git a/tests/commands/build.spec.ts b/tests/commands/build.spec.ts index 3184edd9d0..01bbd739d0 100644 --- a/tests/commands/build.spec.ts +++ b/tests/commands/build.spec.ts @@ -16,12 +16,12 @@ */ import { expect } from 'chai'; -import * as _ from 'lodash'; +import _ from 'lodash'; import mock from 'mock-require'; import { promises as fs } from 'fs'; import * as path from 'path'; -import { stripIndent } from '../../build/utils/lazy'; +import { stripIndent } from '../../lib/utils/lazy'; import { BalenaAPIMock } from '../nock/balena-api-mock'; import { expectStreamNoCRLF, testDockerBuildStream } from '../docker-build'; import { DockerMock, dockerResponsePath } from '../nock/docker-mock'; @@ -35,8 +35,10 @@ import { getDockerignoreWarn2, getDockerignoreWarn3, } from '../projects'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); -const repoPath = path.normalize(path.join(__dirname, '..', '..')); +const repoPath = path.normalize(path.join(import.meta.dirname, '..', '..')); const projectsPath = path.join(repoPath, 'tests', 'test-data', 'projects'); const commonResponseLines: { [key: string]: string[] } = { @@ -258,7 +260,7 @@ describe('balena build', function () { const deviceType = 'raspberry-pi'; const fsModPath = 'fs'; const fsMod = await import(fsModPath); - const qemuModPath = '../../build/utils/qemu'; + const qemuModPath = '../../build/utils/qemu.js'; const qemuMod = require(qemuModPath); const qemuBinPath = await qemuMod.getQemuPath(arch); try { diff --git a/tests/commands/deploy.spec.ts b/tests/commands/deploy.spec.ts index d85375246d..451063ef72 100644 --- a/tests/commands/deploy.spec.ts +++ b/tests/commands/deploy.spec.ts @@ -19,7 +19,7 @@ import { intVar } from '@balena/env-parsing'; import type { Request as ReleaseRequest } from '@balena/compose/dist/release'; import { expect } from 'chai'; import { promises as fs } from 'fs'; -import * as _ from 'lodash'; +import _ from 'lodash'; import type * as nock from 'nock'; import * as path from 'path'; import * as sinon from 'sinon'; @@ -34,7 +34,7 @@ import type { } from '../projects'; import { getDockerignoreWarn1, getDockerignoreWarn3 } from '../projects'; -const repoPath = path.normalize(path.join(__dirname, '..', '..')); +const repoPath = path.normalize(path.join(import.meta.dirname, '..', '..')); const projectsPath = path.join(repoPath, 'tests', 'test-data', 'projects'); const commonResponseLines = { diff --git a/tests/commands/env/envs.spec.ts b/tests/commands/env/envs.spec.ts index 5c42929916..645cc5481e 100644 --- a/tests/commands/env/envs.spec.ts +++ b/tests/commands/env/envs.spec.ts @@ -16,7 +16,8 @@ */ import { expect } from 'chai'; -import { stripIndent } from '../../../build/utils/lazy'; +import { stripIndent } from '../../../lib/utils/lazy'; +import { randomBytes } from 'crypto'; import { BalenaAPIMock } from '../../nock/balena-api-mock'; import { runCommand } from '../../helpers'; @@ -32,7 +33,7 @@ describe('balena envs', function () { api.expectGetWhoAmI({ optional: true, persist: true }); api.expectGetMixpanel({ optional: true }); // Random device UUID used to frustrate _.memoize() in utils/cloud.ts - fullUUID = require('crypto').randomBytes(16).toString('hex'); + fullUUID = randomBytes(16).toString('hex'); shortUUID = fullUUID.substring(0, 7); }); diff --git a/tests/commands/push.spec.ts b/tests/commands/push.spec.ts index 5a2c4c2498..2d33be6d96 100644 --- a/tests/commands/push.spec.ts +++ b/tests/commands/push.spec.ts @@ -33,7 +33,7 @@ import { setupDockerignoreTestData, } from '../projects'; -const repoPath = path.normalize(path.join(__dirname, '..', '..')); +const repoPath = path.normalize(path.join(import.meta.dirname, '..', '..')); const projectsPath = path.join(repoPath, 'tests', 'test-data', 'projects'); const itNoWin = process.platform === 'win32' ? it.skip : it; diff --git a/tests/docker-build.ts b/tests/docker-build.ts index 20b912dd90..b37ecc54d8 100644 --- a/tests/docker-build.ts +++ b/tests/docker-build.ts @@ -16,19 +16,19 @@ */ import { expect } from 'chai'; -import * as _ from 'lodash'; +import _ from 'lodash'; import { promises as fs } from 'fs'; import * as path from 'path'; import { PathUtils } from '@balena/compose/dist/multibuild'; -import rewire = require('rewire'); +import rewire from 'rewire'; import * as sinon from 'sinon'; import { Readable } from 'stream'; import * as tar from 'tar-stream'; import { streamToBuffer } from 'tar-utils'; import { URL } from 'url'; -import { makeImageName } from '../build/utils/compose_ts'; -import { stripIndent } from '../build/utils/lazy'; +import { makeImageName } from '../lib/utils/compose_ts'; +import { stripIndent } from '../lib/utils/lazy'; import type { BuilderMock } from './nock/builder-mock'; import type { DockerMock } from './nock/docker-mock'; import { @@ -101,8 +101,7 @@ export async function inspectTarStream( try { expect($expected).to.deep.equal(found); } catch (e) { - const { diff } = - require('deep-object-diff') as typeof import('deep-object-diff'); + const { diff } = await import('deep-object-diff'); const diffStr = JSON.stringify( diff($expected, found), (_k, v) => (v === undefined ? 'undefined' : v), @@ -126,7 +125,12 @@ async function defaultTestStream( } if (header.name === '.balena/registry-secrets.json') { expectedContents = await fs.readFile( - path.join(__dirname, 'test-data', 'projects', 'registry-secrets.json'), + path.join( + import.meta.dirname, + 'test-data', + 'projects', + 'registry-secrets.json', + ), ); } const [buf, buf2] = await Promise.all([ diff --git a/tests/helpers.ts b/tests/helpers.ts index fd701da570..e419f6f1d0 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -15,13 +15,20 @@ * limitations under the License. */ -import * as _ from 'lodash'; +import _ from 'lodash'; import * as path from 'path'; -import * as packageJSON from '../package.json'; +import packageJSON from '../package.json' with { type: 'json' }; +import { getNodeEngineVersionWarn } from '../lib/utils/messages.js'; +import { warnify } from '../lib/utils/messages.js'; const balenaExe = process.platform === 'win32' ? 'balena.exe' : 'balena'; -const standalonePath = path.resolve(__dirname, '..', 'build-bin', balenaExe); +const standalonePath = path.resolve( + import.meta.dirname, + '..', + 'build-bin', + balenaExe, +); export interface TestOutput { err: string[]; // stderr @@ -41,7 +48,6 @@ function matchesNodeEngineVersionWarn(msg: string) { .map((l) => l.trim()) .filter((l) => l); - const { getNodeEngineVersionWarn } = require('../build/utils/messages'); let nodeEngineWarn: string = getNodeEngineVersionWarn( 'x.y.z', packageJSON.engines.node, @@ -90,7 +96,7 @@ export function filterCliOutputForTests({ * @param cmd Command to execute, e.g. `push myApp` (without 'balena' prefix) */ async function runCommandInProcess(cmd: string): Promise { - const balenaCLI = await import('../build/app.js'); + const balenaCLI = await import('../lib/app.js'); const { default: intercept } = await import('intercept-stdout'); const preArgs = [process.argv[0], path.join(process.cwd(), 'bin', 'balena')]; @@ -112,7 +118,7 @@ async function runCommandInProcess(cmd: string): Promise { try { await balenaCLI.run(preArgs.concat(cmd.split(' ').filter((c) => c)), { - dir: path.resolve(__dirname, '..'), + dir: path.resolve(import.meta.dirname, '..'), noFlush: true, }); } finally { @@ -179,8 +185,6 @@ async function runCommandInSubprocess( const msg = ` Error (possibly expected) executing child CLI process "${standalonePath}" ${$error}`; - const { warnify } = - require('../build/utils/messages') as typeof import('../build/utils/messages'); console.error(warnify(msg, '[debug] ')); } resolve(); @@ -353,7 +357,7 @@ export function deepJsonParse(data: any): any { export async function switchSentry( enabled: boolean | undefined, ): Promise { - const balenaCLI = await import('../build/app.js'); + const balenaCLI = await import('../lib/app.js'); const sentryOpts = (await balenaCLI.setupSentry()).getClient()?.getOptions(); if (sentryOpts) { const sentryStatus = sentryOpts.enabled; diff --git a/tests/nock/balena-api-mock.ts b/tests/nock/balena-api-mock.ts index 0d50f9d25a..9fa1e7560f 100644 --- a/tests/nock/balena-api-mock.ts +++ b/tests/nock/balena-api-mock.ts @@ -15,14 +15,14 @@ * limitations under the License. */ -import * as _ from 'lodash'; +import _ from 'lodash'; import * as path from 'path'; import type { ScopeOpts } from './nock-mock'; import { NockMock } from './nock-mock'; export const apiResponsePath = path.normalize( - path.join(__dirname, '..', 'test-data', 'api-response'), + path.join(import.meta.dirname, '..', 'test-data', 'api-response'), ); const jHeader = { 'Content-Type': 'application/json' }; diff --git a/tests/nock/builder-mock.ts b/tests/nock/builder-mock.ts index ffed63047c..63b89f7230 100644 --- a/tests/nock/builder-mock.ts +++ b/tests/nock/builder-mock.ts @@ -22,7 +22,7 @@ import * as zlib from 'zlib'; import { NockMock } from './nock-mock'; export const builderResponsePath = path.normalize( - path.join(__dirname, '..', 'test-data', 'builder-response'), + path.join(import.meta.dirname, '..', 'test-data', 'builder-response'), ); export class BuilderMock extends NockMock { diff --git a/tests/nock/docker-mock.ts b/tests/nock/docker-mock.ts index b21dab2003..f08de76742 100644 --- a/tests/nock/docker-mock.ts +++ b/tests/nock/docker-mock.ts @@ -22,7 +22,7 @@ import type { ScopeOpts } from './nock-mock'; import { NockMock } from './nock-mock'; export const dockerResponsePath = path.normalize( - path.join(__dirname, '..', 'test-data', 'docker-response'), + path.join(import.meta.dirname, '..', 'test-data', 'docker-response'), ); export class DockerMock extends NockMock { diff --git a/tests/nock/nock-mock.ts b/tests/nock/nock-mock.ts index 2b2ce10c57..c328317d3e 100644 --- a/tests/nock/nock-mock.ts +++ b/tests/nock/nock-mock.ts @@ -17,6 +17,7 @@ import nock from 'nock'; import * as fs from 'fs'; +import { interceptorServerPort } from './proxy-server'; export interface ScopeOpts { optional?: boolean; @@ -170,8 +171,6 @@ export class NockMock { } protected handleUnexpectedRequest(req: any) { - const { interceptorServerPort } = - require('./proxy-server') as typeof import('./proxy-server'); const o = req.options || {}; const u = o.uri || {}; const method = req.method; diff --git a/tests/nock/proxy-server.ts b/tests/nock/proxy-server.ts index d160e93d91..c98d2dd55d 100644 --- a/tests/nock/proxy-server.ts +++ b/tests/nock/proxy-server.ts @@ -55,6 +55,7 @@ */ import * as http from 'http'; +import httpProxy from 'http-proxy'; const proxyServers: http.Server[] = []; @@ -81,8 +82,6 @@ export async function createProxyServerOnce(): Promise<[number, number]> { } async function createProxyServer(): Promise<[number, number]> { - const httpProxy = require('http-proxy') as typeof import('http-proxy'); - const interceptorPort = await createInterceptorServer(); const proxy = httpProxy.createProxyServer(); diff --git a/tests/nock/supervisor-mock.ts b/tests/nock/supervisor-mock.ts index 0d149f5ed9..ffade23729 100644 --- a/tests/nock/supervisor-mock.ts +++ b/tests/nock/supervisor-mock.ts @@ -21,7 +21,7 @@ import type { ScopeOpts } from './nock-mock'; import { NockMock } from './nock-mock'; export const dockerResponsePath = path.normalize( - path.join(__dirname, '..', 'test-data', 'docker-response'), + path.join(import.meta.dirname, '..', 'test-data', 'docker-response'), ); export class SupervisorMock extends NockMock { diff --git a/tests/projects.ts b/tests/projects.ts index b842ccce00..a1a4973247 100644 --- a/tests/projects.ts +++ b/tests/projects.ts @@ -38,7 +38,7 @@ export interface ExpectedTarStreamFilesByService { [service: string]: ExpectedTarStreamFiles; } -export const repoPath = path.normalize(path.join(__dirname, '..')); +export const repoPath = path.normalize(path.join(import.meta.dirname, '..')); export const projectsPath = path.join( repoPath, 'tests', @@ -58,7 +58,7 @@ export async function exists(fPath: string) { export async function setupDockerignoreTestData({ cleanup = false } = {}) { const { copy, remove } = await import('fs-extra'); const dockerignoreProjDir = path.join( - __dirname, + import.meta.dirname, 'test-data', 'projects', 'no-docker-compose', diff --git a/tests/utils/device/live.spec.ts b/tests/utils/device/live.spec.ts index 5baf2fe039..249cd2bc4a 100644 --- a/tests/utils/device/live.spec.ts +++ b/tests/utils/device/live.spec.ts @@ -28,7 +28,9 @@ import { setupDockerignoreTestData } from '../../projects'; const delay = promisify(setTimeout); const FS_WATCH_DURATION_MS = 500; -const repoPath = path.normalize(path.join(__dirname, '..', '..', '..')); +const repoPath = path.normalize( + path.join(import.meta.dirname, '..', '..', '..'), +); const projectsPath = path.join(repoPath, 'tests', 'test-data', 'projects'); interface ByService { diff --git a/tests/utils/docker.spec.ts b/tests/utils/docker.spec.ts index fd498c3fc0..235fac909d 100644 --- a/tests/utils/docker.spec.ts +++ b/tests/utils/docker.spec.ts @@ -122,7 +122,7 @@ describe('generateConnectOpts() function', function () { it('should use the HTTPS protocol when ca/cert/key are used', async () => { const path = await import('path'); const aFile = path.join( - __dirname, + import.meta.dirname, '../test-data/projects/no-docker-compose/dockerignore1/a.txt', ); const cliFlags: DockerConnectionCliFlags = { diff --git a/tests/utils/tarDirectory.spec.ts b/tests/utils/tarDirectory.spec.ts index cdf582a654..3a5dd57956 100644 --- a/tests/utils/tarDirectory.spec.ts +++ b/tests/utils/tarDirectory.spec.ts @@ -22,7 +22,7 @@ import * as tar from 'tar-stream'; import { tarDirectory } from '../../build/utils/compose_ts'; import { setupDockerignoreTestData } from '../projects'; -const repoPath = path.normalize(path.join(__dirname, '..', '..')); +const repoPath = path.normalize(path.join(import.meta.dirname, '..', '..')); const projectsPath = path.join(repoPath, 'tests', 'test-data', 'projects'); interface TarFiles { diff --git a/tsconfig.json b/tsconfig.json index f335e82f13..5e8d449a37 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,8 @@ { "compilerOptions": { "declaration": true, - "module": "Node16", + "module": "NodeNext", + "moduleResolution": "NodeNext", "target": "es2022", "outDir": "build", "strict": true, @@ -13,6 +14,7 @@ "removeComments": true, "sourceMap": true, "skipLibCheck": true, + "resolveJsonModule": true, "typeRoots": [ "./node_modules/@types", "./node_modules/etcher-sdk/typings", From 7d6bd6642033f90f3c1636fcaa6306ac4b1a9609 Mon Sep 17 00:00:00 2001 From: Otavio Jacobi Date: Sun, 14 Jul 2024 11:34:05 -0300 Subject: [PATCH 3/3] wip --- automation/build-bin.ts | 17 ++++++------ automation/capitanodoc/capitanodoc.ts | 8 +++--- automation/capitanodoc/index.ts | 8 +++--- automation/capitanodoc/markdown.ts | 2 +- automation/capitanodoc/utils.ts | 20 -------------- automation/utils.ts | 4 --- bin/dev.js | 40 +++++++++++++-------------- lib/auth/server.ts | 2 +- lib/commands/version/index.ts | 4 ++- lib/help.ts | 4 ++- package.json | 2 +- tsconfig.json | 1 + 12 files changed, 46 insertions(+), 66 deletions(-) diff --git a/automation/build-bin.ts b/automation/build-bin.ts index b3eb474ed6..7d7e7601fe 100644 --- a/automation/build-bin.ts +++ b/automation/build-bin.ts @@ -32,19 +32,14 @@ import { promisify } from 'util'; import { notarize } from '@electron/notarize'; import { stripIndent } from '../lib/utils/lazy'; -import { - diffLines, - loadPackageJson, - ROOT, - StdOutTap, - whichSpawn, -} from './utils'; +import { diffLines, ROOT, StdOutTap, whichSpawn } from './utils'; import { filterCliOutputForTests, monochrome } from '../tests/helpers'; const execFileAsync = promisify(execFile); const execAsync = promisify(exec); -export const packageJSON = loadPackageJson(); +import pjson from '../package.json' with { type: 'json' }; +export const packageJSON = pjson; export const version = 'v' + packageJSON.version; const arch = process.arch; @@ -172,7 +167,11 @@ async function execPkg(...args: any[]) { throw err; } outTap.untap(); - await diffPkgOutput(outTap.allBuf.join('')); + try { + await diffPkgOutput(outTap.allBuf.join('')); + } catch (err) { + console.error('diff on pkg warnings', err); + } } /** diff --git a/automation/capitanodoc/capitanodoc.ts b/automation/capitanodoc/capitanodoc.ts index 6e9840d96b..7c0e09f1e4 100644 --- a/automation/capitanodoc/capitanodoc.ts +++ b/automation/capitanodoc/capitanodoc.ts @@ -16,7 +16,7 @@ */ import * as path from 'path'; -import { MarkdownFileParser } from './utils'; +import { MarkdownFileParser } from './utils.js'; import { GlobSync } from 'glob'; /** @@ -82,13 +82,13 @@ const commandHeadings: { [key: string]: string } = { }; // Fetch all available commands -const allCommandsPaths = new GlobSync('build/commands/**/*.js', { - ignore: 'build/commands/internal/**', +const allCommandsPaths = new GlobSync('build/lib/commands/**/*.js', { + ignore: 'build/lib/commands/internal/**', }).found; // Throw error if any commands found outside of command directories const illegalCommandPaths = allCommandsPaths.filter((commandPath: string) => - /^build\/commands\/[^/]+\.js$/.test(commandPath), + /^build\/lib\/commands\/[^/]+\.js$/.test(commandPath), ); if (illegalCommandPaths.length !== 0) { diff --git a/automation/capitanodoc/index.ts b/automation/capitanodoc/index.ts index 58701e96af..f10b40594d 100644 --- a/automation/capitanodoc/index.ts +++ b/automation/capitanodoc/index.ts @@ -15,10 +15,10 @@ * limitations under the License. */ import * as path from 'path'; -import { getCapitanoDoc } from './capitanodoc'; -import type { Category, Document, OclifCommand } from './doc-types'; -import * as markdown from './markdown'; -import { stripIndent } from '../../lib/utils/lazy'; +import { getCapitanoDoc } from './capitanodoc.js'; +import type { Category, Document, OclifCommand } from './doc-types.js'; +import * as markdown from './markdown.js'; +import { stripIndent } from '../../lib/utils/lazy.js'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); diff --git a/automation/capitanodoc/markdown.ts b/automation/capitanodoc/markdown.ts index ada7531d59..94cc4609a5 100644 --- a/automation/capitanodoc/markdown.ts +++ b/automation/capitanodoc/markdown.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import { Parser } from '@oclif/core'; -import * as ent from 'ent'; +import ent from 'ent'; import _ from 'lodash'; import { getManualSortCompareFunction } from '../../lib/utils/helpers'; diff --git a/automation/capitanodoc/utils.ts b/automation/capitanodoc/utils.ts index 8108d263af..e9c0e88635 100644 --- a/automation/capitanodoc/utils.ts +++ b/automation/capitanodoc/utils.ts @@ -15,8 +15,6 @@ * limitations under the License. */ -import type { OptionDefinition } from 'capitano'; -import * as ent from 'ent'; import * as fs from 'fs'; import * as readline from 'readline'; @@ -32,24 +30,6 @@ export function getOptionSignature(signature: string) { return `${getOptionPrefix(signature)}${signature}`; } -export function parseCapitanoOption(option: OptionDefinition): string { - let result = getOptionSignature(option.signature); - - if (Array.isArray(option.alias)) { - for (const alias of option.alias) { - result += `, ${getOptionSignature(alias)}`; - } - } else if (typeof option.alias === 'string') { - result += `, ${getOptionSignature(option.alias)}`; - } - - if (option.parameter) { - result += ` <${option.parameter}>`; - } - - return ent.encode(result); -} - export class MarkdownFileParser { constructor(public mdFilePath: string) {} diff --git a/automation/utils.ts b/automation/utils.ts index 28891e3d7e..c9919eaa14 100644 --- a/automation/utils.ts +++ b/automation/utils.ts @@ -83,10 +83,6 @@ export function diffLines(str1: string, str2: string): string { return diffStr; } -export function loadPackageJson() { - return require(path.join(ROOT, 'package.json')); -} - /** * Error handling wrapper around the npm `which` package: * "Like the unix which utility. Finds the first instance of a specified diff --git a/bin/dev.js b/bin/dev.js index 880d22eba0..75525e5185 100755 --- a/bin/dev.js +++ b/bin/dev.js @@ -64,27 +64,27 @@ process.on('SIGINT', function () { }); // Modify package.json oclif paths from build/ -> lib/, or vice versa -// function modifyOclifPaths(revert) { -// const packageJsonPath = path.join(rootDir, 'package.json'); +function modifyOclifPaths(revert) { + const packageJsonPath = path.join(rootDir, 'package.json'); -// const packageJson = fs.readFileSync(packageJsonPath, 'utf8'); -// const packageObj = JSON.parse(packageJson); + const packageJson = fs.readFileSync(packageJsonPath, 'utf8'); + const packageObj = JSON.parse(packageJson); -// if (!packageObj.oclif) { -// return; -// } + if (!packageObj.oclif) { + return; + } -// let oclifSectionText = JSON.stringify(packageObj.oclif); -// if (!revert) { -// oclifSectionText = oclifSectionText.replace(/\/build\//g, '/lib/'); -// } else { -// oclifSectionText = oclifSectionText.replace(/\/lib\//g, '/build/'); -// } + let oclifSectionText = JSON.stringify(packageObj.oclif); + if (!revert) { + oclifSectionText = oclifSectionText.replace(/\/build\/lib\//g, '/lib/'); + } else { + oclifSectionText = oclifSectionText.replace(/\/lib\//g, '/build/lib/'); + } -// packageObj.oclif = JSON.parse(oclifSectionText); -// fs.writeFileSync( -// packageJsonPath, -// `${JSON.stringify(packageObj, null, 2)}\n`, -// 'utf8', -// ); -// } + packageObj.oclif = JSON.parse(oclifSectionText); + fs.writeFileSync( + packageJsonPath, + `${JSON.stringify(packageObj, null, 2)}\n`, + 'utf8', + ); +} diff --git a/lib/auth/server.ts b/lib/auth/server.ts index 4c3ab85370..0660368f7e 100644 --- a/lib/auth/server.ts +++ b/lib/auth/server.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import * as bodyParser from 'body-parser'; +import bodyParser from 'body-parser'; import { EventEmitter } from 'events'; import express from 'express'; import type { Socket } from 'net'; diff --git a/lib/commands/version/index.ts b/lib/commands/version/index.ts index b0cbb89e99..423b5c15db 100644 --- a/lib/commands/version/index.ts +++ b/lib/commands/version/index.ts @@ -72,7 +72,9 @@ export default class VersionCmd extends Command { public async run() { const { flags: options } = await this.parse(VersionCmd); const versions: JsonVersions = { - 'balena-cli': (await import('../../../package.json')).default.version, + 'balena-cli': ( + await import('../../../package.json', { with: { type: 'json' } }) + ).default.version, 'Node.js': process.version && process.version.startsWith('v') ? process.version.slice(1) diff --git a/lib/help.ts b/lib/help.ts index 4b94dcbbec..124cc1a6bd 100644 --- a/lib/help.ts +++ b/lib/help.ts @@ -147,7 +147,9 @@ See: https://git.io/JRHUW#deprecation-policy`, ]; globalOps[0][0] = globalOps[0][0].padEnd(usageLength); - const { deprecationPolicyNote, reachingOut } = await import('./utils/messages.js'); + const { deprecationPolicyNote, reachingOut } = await import( + './utils/messages.js' + ); return [ bold('USAGE'), diff --git a/package.json b/package.json index e6a27c087a..ffe0847639 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "build": "npm run build:src && npm run catch-uncommitted", "build:t": "npm run lint && npm run build:fast && npm run build:test", "build:src": "npm run lint && npm run build:fast && npm run build:test && npm run build:doc && npm run build:completion", - "build:pages": "mkdirp ./build/auth/pages/&& inline-source --compress ./lib/auth/pages/error.ejs ./build/auth/pages/error.ejs && inline-source --compress ./lib/auth/pages/success.ejs ./build/auth/pages/success.ejs", + "build:pages": "mkdirp ./build/lib/auth/pages/&& inline-source --compress ./lib/auth/pages/error.ejs ./build/lib/auth/pages/error.ejs && inline-source --compress ./lib/auth/pages/success.ejs ./build/lib/auth/pages/success.ejs", "build:fast": "npm run build:pages && tsc && npx oclif manifest", "build:test": "tsc -P ./tsconfig.dev.json --noEmit", "build:doc": "ts-node --transpile-only automation/capitanodoc/index.ts > docs/balena-cli.md", diff --git a/tsconfig.json b/tsconfig.json index 5e8d449a37..98ea96c68f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,7 @@ "removeComments": true, "sourceMap": true, "skipLibCheck": true, + "esModuleInterop": true, "resolveJsonModule": true, "typeRoots": [ "./node_modules/@types",