diff --git a/automation/build-bin.ts b/automation/build-bin.ts index b3eb474ed6..7d7e7601fe 100644 --- a/automation/build-bin.ts +++ b/automation/build-bin.ts @@ -32,19 +32,14 @@ import { promisify } from 'util'; import { notarize } from '@electron/notarize'; import { stripIndent } from '../lib/utils/lazy'; -import { - diffLines, - loadPackageJson, - ROOT, - StdOutTap, - whichSpawn, -} from './utils'; +import { diffLines, ROOT, StdOutTap, whichSpawn } from './utils'; import { filterCliOutputForTests, monochrome } from '../tests/helpers'; const execFileAsync = promisify(execFile); const execAsync = promisify(exec); -export const packageJSON = loadPackageJson(); +import pjson from '../package.json' with { type: 'json' }; +export const packageJSON = pjson; export const version = 'v' + packageJSON.version; const arch = process.arch; @@ -172,7 +167,11 @@ async function execPkg(...args: any[]) { throw err; } outTap.untap(); - await diffPkgOutput(outTap.allBuf.join('')); + try { + await diffPkgOutput(outTap.allBuf.join('')); + } catch (err) { + console.error('diff on pkg warnings', err); + } } /** diff --git a/automation/capitanodoc/capitanodoc.ts b/automation/capitanodoc/capitanodoc.ts index 6e9840d96b..7c0e09f1e4 100644 --- a/automation/capitanodoc/capitanodoc.ts +++ b/automation/capitanodoc/capitanodoc.ts @@ -16,7 +16,7 @@ */ import * as path from 'path'; -import { MarkdownFileParser } from './utils'; +import { MarkdownFileParser } from './utils.js'; import { GlobSync } from 'glob'; /** @@ -82,13 +82,13 @@ const commandHeadings: { [key: string]: string } = { }; // Fetch all available commands -const allCommandsPaths = new GlobSync('build/commands/**/*.js', { - ignore: 'build/commands/internal/**', +const allCommandsPaths = new GlobSync('build/lib/commands/**/*.js', { + ignore: 'build/lib/commands/internal/**', }).found; // Throw error if any commands found outside of command directories const illegalCommandPaths = allCommandsPaths.filter((commandPath: string) => - /^build\/commands\/[^/]+\.js$/.test(commandPath), + /^build\/lib\/commands\/[^/]+\.js$/.test(commandPath), ); if (illegalCommandPaths.length !== 0) { diff --git a/automation/capitanodoc/index.ts b/automation/capitanodoc/index.ts index 58701e96af..f10b40594d 100644 --- a/automation/capitanodoc/index.ts +++ b/automation/capitanodoc/index.ts @@ -15,10 +15,10 @@ * limitations under the License. */ import * as path from 'path'; -import { getCapitanoDoc } from './capitanodoc'; -import type { Category, Document, OclifCommand } from './doc-types'; -import * as markdown from './markdown'; -import { stripIndent } from '../../lib/utils/lazy'; +import { getCapitanoDoc } from './capitanodoc.js'; +import type { Category, Document, OclifCommand } from './doc-types.js'; +import * as markdown from './markdown.js'; +import { stripIndent } from '../../lib/utils/lazy.js'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); diff --git a/automation/capitanodoc/markdown.ts b/automation/capitanodoc/markdown.ts index ada7531d59..94cc4609a5 100644 --- a/automation/capitanodoc/markdown.ts +++ b/automation/capitanodoc/markdown.ts @@ -15,7 +15,7 @@ * limitations under the License. */ import { Parser } from '@oclif/core'; -import * as ent from 'ent'; +import ent from 'ent'; import _ from 'lodash'; import { getManualSortCompareFunction } from '../../lib/utils/helpers'; diff --git a/automation/capitanodoc/utils.ts b/automation/capitanodoc/utils.ts index 8108d263af..e9c0e88635 100644 --- a/automation/capitanodoc/utils.ts +++ b/automation/capitanodoc/utils.ts @@ -15,8 +15,6 @@ * limitations under the License. */ -import type { OptionDefinition } from 'capitano'; -import * as ent from 'ent'; import * as fs from 'fs'; import * as readline from 'readline'; @@ -32,24 +30,6 @@ export function getOptionSignature(signature: string) { return `${getOptionPrefix(signature)}${signature}`; } -export function parseCapitanoOption(option: OptionDefinition): string { - let result = getOptionSignature(option.signature); - - if (Array.isArray(option.alias)) { - for (const alias of option.alias) { - result += `, ${getOptionSignature(alias)}`; - } - } else if (typeof option.alias === 'string') { - result += `, ${getOptionSignature(option.alias)}`; - } - - if (option.parameter) { - result += ` <${option.parameter}>`; - } - - return ent.encode(result); -} - export class MarkdownFileParser { constructor(public mdFilePath: string) {} diff --git a/automation/utils.ts b/automation/utils.ts index 28891e3d7e..c9919eaa14 100644 --- a/automation/utils.ts +++ b/automation/utils.ts @@ -83,10 +83,6 @@ export function diffLines(str1: string, str2: string): string { return diffStr; } -export function loadPackageJson() { - return require(path.join(ROOT, 'package.json')); -} - /** * Error handling wrapper around the npm `which` package: * "Like the unix which utility. Finds the first instance of a specified diff --git a/bin/dev.js b/bin/dev.js index 880d22eba0..75525e5185 100755 --- a/bin/dev.js +++ b/bin/dev.js @@ -64,27 +64,27 @@ process.on('SIGINT', function () { }); // Modify package.json oclif paths from build/ -> lib/, or vice versa -// function modifyOclifPaths(revert) { -// const packageJsonPath = path.join(rootDir, 'package.json'); +function modifyOclifPaths(revert) { + const packageJsonPath = path.join(rootDir, 'package.json'); -// const packageJson = fs.readFileSync(packageJsonPath, 'utf8'); -// const packageObj = JSON.parse(packageJson); + const packageJson = fs.readFileSync(packageJsonPath, 'utf8'); + const packageObj = JSON.parse(packageJson); -// if (!packageObj.oclif) { -// return; -// } + if (!packageObj.oclif) { + return; + } -// let oclifSectionText = JSON.stringify(packageObj.oclif); -// if (!revert) { -// oclifSectionText = oclifSectionText.replace(/\/build\//g, '/lib/'); -// } else { -// oclifSectionText = oclifSectionText.replace(/\/lib\//g, '/build/'); -// } + let oclifSectionText = JSON.stringify(packageObj.oclif); + if (!revert) { + oclifSectionText = oclifSectionText.replace(/\/build\/lib\//g, '/lib/'); + } else { + oclifSectionText = oclifSectionText.replace(/\/lib\//g, '/build/lib/'); + } -// packageObj.oclif = JSON.parse(oclifSectionText); -// fs.writeFileSync( -// packageJsonPath, -// `${JSON.stringify(packageObj, null, 2)}\n`, -// 'utf8', -// ); -// } + packageObj.oclif = JSON.parse(oclifSectionText); + fs.writeFileSync( + packageJsonPath, + `${JSON.stringify(packageObj, null, 2)}\n`, + 'utf8', + ); +} diff --git a/lib/auth/server.ts b/lib/auth/server.ts index 4c3ab85370..0660368f7e 100644 --- a/lib/auth/server.ts +++ b/lib/auth/server.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import * as bodyParser from 'body-parser'; +import bodyParser from 'body-parser'; import { EventEmitter } from 'events'; import express from 'express'; import type { Socket } from 'net'; diff --git a/lib/commands/version/index.ts b/lib/commands/version/index.ts index b0cbb89e99..423b5c15db 100644 --- a/lib/commands/version/index.ts +++ b/lib/commands/version/index.ts @@ -72,7 +72,9 @@ export default class VersionCmd extends Command { public async run() { const { flags: options } = await this.parse(VersionCmd); const versions: JsonVersions = { - 'balena-cli': (await import('../../../package.json')).default.version, + 'balena-cli': ( + await import('../../../package.json', { with: { type: 'json' } }) + ).default.version, 'Node.js': process.version && process.version.startsWith('v') ? process.version.slice(1) diff --git a/lib/help.ts b/lib/help.ts index 4b94dcbbec..124cc1a6bd 100644 --- a/lib/help.ts +++ b/lib/help.ts @@ -147,7 +147,9 @@ See: https://git.io/JRHUW#deprecation-policy`, ]; globalOps[0][0] = globalOps[0][0].padEnd(usageLength); - const { deprecationPolicyNote, reachingOut } = await import('./utils/messages.js'); + const { deprecationPolicyNote, reachingOut } = await import( + './utils/messages.js' + ); return [ bold('USAGE'), diff --git a/package.json b/package.json index e6a27c087a..ffe0847639 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "build": "npm run build:src && npm run catch-uncommitted", "build:t": "npm run lint && npm run build:fast && npm run build:test", "build:src": "npm run lint && npm run build:fast && npm run build:test && npm run build:doc && npm run build:completion", - "build:pages": "mkdirp ./build/auth/pages/&& inline-source --compress ./lib/auth/pages/error.ejs ./build/auth/pages/error.ejs && inline-source --compress ./lib/auth/pages/success.ejs ./build/auth/pages/success.ejs", + "build:pages": "mkdirp ./build/lib/auth/pages/&& inline-source --compress ./lib/auth/pages/error.ejs ./build/lib/auth/pages/error.ejs && inline-source --compress ./lib/auth/pages/success.ejs ./build/lib/auth/pages/success.ejs", "build:fast": "npm run build:pages && tsc && npx oclif manifest", "build:test": "tsc -P ./tsconfig.dev.json --noEmit", "build:doc": "ts-node --transpile-only automation/capitanodoc/index.ts > docs/balena-cli.md", diff --git a/tsconfig.json b/tsconfig.json index 5e8d449a37..98ea96c68f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,7 @@ "removeComments": true, "sourceMap": true, "skipLibCheck": true, + "esModuleInterop": true, "resolveJsonModule": true, "typeRoots": [ "./node_modules/@types",