diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 92% rename from .eslintrc.js rename to .eslintrc.cjs index 67c2bfb8..ba52386e 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 2034d395..abe2ec6b 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 76fc8f81..b3eb474e 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 93a7f5b3..6e9840d9 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 75e79272..58701e96 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 c0e2dc80..ada7531d 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 9ad65dc4..0a514d4c 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 cddf82f6..2e7ce68c 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 5395d02e..fb8f61e4 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 f8fc0273..3d2cfd8c 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 d895d35e..539409ed 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 5b9f5ef5..28891e3d 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 ceaf47c4..880d22eb 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 6a27aff0..8d48b887 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 732ffb83..d7939aff 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 98065ea5..b8154181 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 7c48867c..16f1001b 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 c24388fd..4c3ab853 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 7956b55b..f2935f0a 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 83c8c445..9580457f 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 c9213b67..86265d26 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 27475f39..d12d8d1f 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 d0ceb50f..ac3ef301 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 1e888504..60baabc8 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 e6dd7b56..9372bff1 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 0bcef8eb..43249017 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 b5a7210a..d8c81652 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 a9034e0d..05a267ab 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 9830e5a6..3acd906d 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 8dd9a2b1..7e1d6b4e 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 dd922da1..3d008855 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 e11e72fa..db2b6094 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 c22d2653..2537e913 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 7766a088..62bcae49 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 3dc318ca..b4c2d640 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 2a4b45c1..073169df 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 1d048baf..66b5a487 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 bff8f949..8d32b69f 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 c7883ae0..b4ba86aa 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 51f582bf..6a855143 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 51326070..8879e084 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 a40d00e6..d2752292 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 daef864b..04a92610 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 6a366267..72b05bf8 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 be6c38f4..7d58f1e5 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 8b71c101..ecbac949 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 9f7e8206..21b7e5eb 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 7da13ade..3c6f36c4 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 460f5e3f..60027fd3 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 1ae793ff..9260c543 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 edb164ef..b0935b24 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 70991a3a..9509a611 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 93305a41..4f984db9 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 77c58fc5..bf6a6a57 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 6f9a3b99..6058ae96 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 1af607eb..64343e2a 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 d0719d81..11c37eab 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 a4f11a2a..5026df92 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 81849e88..4bb5a160 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 2b9f6cc1..5b38130b 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 4ecbd85c..9efaa7af 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 f8569aa1..793f285d 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 6d22b657..b67b014e 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 25dab03f..e47240ab 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 e05a9365..ec8d579e 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 fe649c18..fff856fb 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 9bc184b0..73d3a450 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 a61efb1e..4c0d7f3c 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 797c251b..3c6b528b 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 895e7451..ecffb5fc 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 f9523efe..a63dc519 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 ca81f366..18d99381 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 d30cf2ce..8db65dd3 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 220d1288..6f2b84b4 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 c0293605..f36e68d2 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 fb140488..49289f58 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 5ea45963..654ebf28 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 5b8b49ce..d05c1286 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 fb3e38fc..e8e38b6f 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 28deb7f9..357acfbe 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 fe5c8323..685f2063 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 01a8b638..81bcea76 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 66664b81..0c9e0088 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 ca574483..801b67c0 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 79cd8049..f7b7f45b 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 6966d1ad..92df481d 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 6560c263..e8703380 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 2ddb422e..8d3008e7 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 a73a8d31..72bec99c 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 f9f3f9b2..f13f8433 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 85ce4b45..239412df 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 72ef9e0b..659a2bec 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 181ef3c5..0bf15f63 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 f54c4db0..5ac3311f 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 c469d90d..5f9dccdf 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 22030c13..6303990d 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 1eaaa6fc..f1e09cb9 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 77d9bec7..8c854f4e 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 a7a7cbc5..79d8bd1b 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 bac32073..4f5503f0 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 ac71d201..8705dd77 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 1fa1c2e2..b0cbb89e 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 adc81acd..c1e8af5a 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 c55f74cc..ccf99736 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 90e365dd..492b5d12 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 fef266bf..2f08a075 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 fd2718f9..1eaba086 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 24097f7b..65281aca 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 ae0e5132..f99ddec8 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 39796bc5..4b94dcbb 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 834dc003..952bde9f 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 35161fb6..5fefe6d5 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 74ae562e..23d5c77d 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 21e7ee61..17ad7ad2 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 536f11a2..591b54df 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 74ae9baa..040541eb 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 0941ed43..9c90ae1d 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 5543115e..297b69c1 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 21eabf09..fd2395db 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 3275c726..a8691a26 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 074e9cf2..cbc596cd 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 62f2b67b..c3135a9b 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 9c5e64ae..2890c984 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 5455a803..5f3668a4 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 667b31fe..b428b7bf 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 2786600c..c3e65907 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 3138a2bd..283e2690 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 25e1c309..abd719e5 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 58b414c1..45270005 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 96654572..0389ebd7 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 2d015c6b..ec76fcdd 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 f29cd68a..e32a8eb8 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 a9be2275..69e279f3 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 c6d0a984..3303dba9 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 7aa69314..22c9309b 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 3bf8fd5b..6be48aeb 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 ceac7501..c7889e5d 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 18e6a1f3..c627a432 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 e7f8165d..0ba4bead 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 c4147f5e..cbc1a10f 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 ed54254f..53c586db 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 1887fc9f..885fccee 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 3e8527d9..0170193e 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 23f51e88..bb94abc2 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 3e8953dd..c1e6b679 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 7c786956..6b647dd0 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 aa2f6602..906aafd4 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 918acc92..4b336dfc 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 891ec39b..4e66142d 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 739b3803..931f18d4 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 af7cafe6..679e4163 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 ec2bdd89..e6a27c08 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 6a399d1b..ed0ec9ee 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 3184edd9..01bbd739 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 d8537524..451063ef 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 5c429299..645cc548 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 5a2c4c24..2d33be6d 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 20b912dd..b37ecc54 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 fd701da5..e419f6f1 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 0d50f9d2..9fa1e756 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 ffed6304..63b89f72 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 b21dab20..f08de767 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 2b2ce10c..c328317d 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 d160e93d..c98d2dd5 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 0d149f5e..ffade237 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 b842ccce..a1a49732 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 5baf2fe0..249cd2bc 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 fd498c3f..235fac90 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 cdf582a6..3a5dd579 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 f335e82f..5e8d449a 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",