From 23d74c360762b1e8aaaea24988fe2340fdfbddbe Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Mon, 16 Dec 2024 15:20:38 -0300 Subject: [PATCH 1/4] Fix test command to search all spec files The test:node command was not properly recursing over the directories under `tests` leading to some tests being skipped. Change-type: patch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9b61b3b..7b80ebd 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "doc": "typedoc --options ./typedoc.json", "lint": "balena-lint -t tsconfig.dev.json --typescript lib tests scripts", "lint-fix": "balena-lint -t tsconfig.dev.json --typescript --fix lib tests scripts", - "test:node": "mocha -r ts-node/register/transpile-only --reporter spec tests/**/*.spec.ts", + "test:node": "mocha -r ts-node/register/transpile-only --reporter spec \"tests/**/*.spec.ts\"", "test": "npm run build && npm run lint && npm run test:node", "test:fast": "npm run build && npm run test:node", "prepack": "npm run build" From d6439a6932a5b07acc4764f19ec5a6a4a74cc17b Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Mon, 16 Dec 2024 15:55:26 -0300 Subject: [PATCH 2/4] Update typescript to v5 and fix build errors - Fixes a wrong return type on `setFirst` - Fixes a void expression return - Fixes a build error due to bad type inference Change-type: patch --- lib/children-tree.ts | 4 ++++ lib/partials.ts | 20 ++++++++++++++------ lib/types/cuetypes.ts | 2 +- lib/utils.ts | 3 ++- package.json | 4 ++-- scripts/build-types.ts | 4 +++- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/children-tree.ts b/lib/children-tree.ts index 0d0c899..274316d 100644 --- a/lib/children-tree.ts +++ b/lib/children-tree.ts @@ -36,6 +36,10 @@ export const build = (contract: Contract): object => { for (const type of contract.metadata.children.types) { if (contract.metadata.children.byType[type].size === 1) { const hash = setFirst(contract.metadata.children.byType[type]); + if (hash === undefined) { + throw new Error('Error retrieving child'); + } + const child = contract.getChildByHash(hash); if (child === undefined) { throw new Error('Error retrieving child'); diff --git a/lib/partials.ts b/lib/partials.ts index c3a8279..d4e9e40 100644 --- a/lib/partials.ts +++ b/lib/partials.ts @@ -39,7 +39,7 @@ const debug = Debug('partials'); * @type {String} * @private */ -const REFERENCE_DELIMITER: string = '+'; +const REFERENCE_DELIMITER = '+'; /** * @summary Calculate the paths to search for a partial given a contract @@ -112,15 +112,23 @@ export const findPartial = ( range(options.structure.length, 1, -1), (accumulator, slice) => accumulator.concat(invokeMap(products, 'slice', 0, slice)), - [] as string[][], + [] as string[], ); - const fallbackPaths = combinations.reduce( + const fallbackPaths = combinations.reduce< + Array> + >( (accumulator, _, index, collection) => - map([map(collection, first), map(collection, last)], (list) => - take(list, index + 1), + map( + [ + // For some reason typescript does not infer correctly the return + // type of first + map(collection, first), + map(collection, last), + ], + (list) => take(list, index + 1), ).concat(accumulator), - [] as Array>, + [], ); return (products as Array>) diff --git a/lib/types/cuetypes.ts b/lib/types/cuetypes.ts index 76ea480..ad0af12 100644 --- a/lib/types/cuetypes.ts +++ b/lib/types/cuetypes.ts @@ -12,7 +12,7 @@ export interface components { type?: 'meta.blueprint'; layout?: components['schemas']['BlueprintLayout']; skeleton?: { [key: string]: any }; - } & { [key: string]: any }; + }; BlueprintLayout: { [key: string]: any }; Contract: { type: string; diff --git a/lib/utils.ts b/lib/utils.ts index 1237f4a..8cfe3af 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -82,7 +82,8 @@ export const setUnion = (set1: Set, set2: Set): Set => { * console.log(element) * > 'foo' */ -export const setFirst = (set1: Set): T => set1.values().next().value; +export const setFirst = (set1: Set): T | undefined => + set1.values().next().value; /** * @summary Map a set using an iteratee function diff --git a/package.json b/package.json index 7b80ebd..5127b9b 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,8 @@ "openapi-typescript": "^3.2.4", "rimraf": "^3.0.2", "ts-node": "^8.10.1", - "typedoc": "^0.23.28", - "typescript": "^4.9.5" + "typedoc": "^0.27.5", + "typescript": "^5.7.2" }, "engines": { "node": "^20.0.0", diff --git a/scripts/build-types.ts b/scripts/build-types.ts index 5b0fc8c..1ada3a6 100644 --- a/scripts/build-types.ts +++ b/scripts/build-types.ts @@ -32,4 +32,6 @@ const main = async () => { console.log(`Built types to ${output}`); }; -main().catch((err) => console.error(err)); +main().catch((err) => { + console.error(err); +}); From 8ed7a4fbbabac16d36a6c7ed9424b729c8d84fe3 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Mon, 16 Dec 2024 16:13:48 -0300 Subject: [PATCH 3/4] Update Node support to v20 and above Change-type: patch --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5127b9b..565aa6f 100644 --- a/package.json +++ b/package.json @@ -67,8 +67,8 @@ "typescript": "^5.7.2" }, "engines": { - "node": "^20.0.0", - "npm": "^10.0.0" + "node": ">=20.0.0", + "npm": ">=10.0.0" }, "versionist": { "publishedAt": "2024-04-30T23:37:32.408Z" From 19f58ae3c12d5061ae8fe07a4bdf7e7c5dfaa4b4 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Mon, 16 Dec 2024 20:19:20 -0300 Subject: [PATCH 4/4] Switch to promised-handlebars to fix dependencies handlebars-async-helpers had a dependency on handlebars 4.7.6 which has a vulnerability according to `npm audit`. This moves to promised-handlebars, which while it's older, it has almost no dependencies Change-type: patch --- .npmrc | 1 - lib/partials.ts | 4 ++-- package.json | 2 +- ...handlebars-async-helpers.d.ts => promised-handlebars.d.ts} | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) rename typings/{handlebars-async-helpers.d.ts => promised-handlebars.d.ts} (72%) diff --git a/.npmrc b/.npmrc index 4fd15ed..43c97e7 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1 @@ package-lock=false -legacy-peer-deps=true diff --git a/lib/partials.ts b/lib/partials.ts index d4e9e40..f8c3390 100644 --- a/lib/partials.ts +++ b/lib/partials.ts @@ -8,7 +8,7 @@ import Debug from 'debug'; import * as fs from 'fs'; import path from 'path'; import handlebars from 'handlebars'; -import asyncHelpers from 'handlebars-async-helpers'; +import promisedHandlebars from 'promised-handlebars'; import first from 'lodash/first'; import invokeMap from 'lodash/invokeMap'; import join from 'lodash/join'; @@ -30,7 +30,7 @@ import Contract from './contract'; import type { ContractObject } from './types/types'; import { cartesianProductWith, stripExtraBlankLines } from './utils'; -const hb = asyncHelpers(handlebars); +const hb = promisedHandlebars(handlebars); const debug = Debug('partials'); diff --git a/package.json b/package.json index 565aa6f..e25f9c2 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,10 @@ "dependencies": { "debug": "^3.2.6", "handlebars": "^4.7.8", - "handlebars-async-helpers": "^1.0.4", "js-combinatorics": "^0.5.5", "lodash": "^4.17.19", "object-hash": "^1.3.1", + "promised-handlebars": "^2.0.1", "semver": "^5.7.1", "skhema": "^5.3.2" }, diff --git a/typings/handlebars-async-helpers.d.ts b/typings/promised-handlebars.d.ts similarity index 72% rename from typings/handlebars-async-helpers.d.ts rename to typings/promised-handlebars.d.ts index b1d53c8..e2a100e 100644 --- a/typings/handlebars-async-helpers.d.ts +++ b/typings/promised-handlebars.d.ts @@ -1,4 +1,4 @@ -declare module 'handlebars-async-helpers' { +declare module 'promised-handlebars' { import type Handlebars from 'handlebars'; const fn: (hb: typeof Handlebars) => typeof Handlebars;