From f7c979ff739cdf7fd971051aae69a23617a67477 Mon Sep 17 00:00:00 2001 From: Otavio Jacobi Date: Sun, 14 Jul 2024 11:34:05 -0300 Subject: [PATCH] wip --- automation/build-bin.ts | 6 ++-- automation/capitanodoc/capitanodoc.ts | 6 ++-- automation/utils.ts | 4 --- bin/dev.js | 40 +++++++++++++-------------- lib/auth/server.ts | 2 +- lib/commands/version/index.ts | 4 ++- lib/help.ts | 4 ++- package.json | 2 +- tsconfig.json | 1 + 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/automation/build-bin.ts b/automation/build-bin.ts index b3eb474ed6..9c0343ba75 100644 --- a/automation/build-bin.ts +++ b/automation/build-bin.ts @@ -34,7 +34,6 @@ import { notarize } from '@electron/notarize'; import { stripIndent } from '../lib/utils/lazy'; import { diffLines, - loadPackageJson, ROOT, StdOutTap, whichSpawn, @@ -44,7 +43,8 @@ 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 +172,7 @@ async function execPkg(...args: any[]) { throw err; } outTap.untap(); - await diffPkgOutput(outTap.allBuf.join('')); + // await diffPkgOutput(outTap.allBuf.join('')); } /** diff --git a/automation/capitanodoc/capitanodoc.ts b/automation/capitanodoc/capitanodoc.ts index 6e9840d96b..111a71b94b 100644 --- a/automation/capitanodoc/capitanodoc.ts +++ b/automation/capitanodoc/capitanodoc.ts @@ -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/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",