From 524e0ace99fe3d2393d62a0535b807e54cb90123 Mon Sep 17 00:00:00 2001 From: Dief Bell Date: Wed, 28 May 2025 17:56:24 +0100 Subject: [PATCH 1/9] Bumped version of `which`, bumped `cmake-ts`'s version --- package.json | 2 +- pnpm-lock.yaml | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2f115bb..9b37022 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cmake-ts", - "version": "1.0.2", + "version": "1.0.3", "description": "cmake-js rewrite in typescript to support advanced build configurations", "main": "build/lib.js", "module": "build/lib.mjs", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9d90523..30227fc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -132,8 +132,8 @@ importers: specifier: 3.1.1 version: 3.1.1(@types/debug@4.1.12)(@types/node@22.14.0)(@vitest/ui@3.1.1)(terser@5.39.0)(yaml@2.7.0) which: - specifier: ^2 - version: 2.0.2 + specifier: ^3.0.1 + version: 3.0.1 packages: @@ -3318,6 +3318,11 @@ packages: engines: {node: '>= 8'} hasBin: true + which@3.0.1: + resolution: {integrity: sha512-XA1b62dzQzLfaEOSQFTCOd5KFf/1VSzZo7/7TUjnya6u0vGGKzU96UQBZTAThCb2j4/xjBAyii1OhRLJEivHvg==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + hasBin: true + which@5.0.0: resolution: {integrity: sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ==} engines: {node: ^18.17.0 || >=20.5.0} @@ -7039,6 +7044,10 @@ snapshots: dependencies: isexe: 2.0.0 + which@3.0.1: + dependencies: + isexe: 2.0.0 + which@5.0.0: dependencies: isexe: 3.1.1 From 59002f4db4a25560697a947b2c4bb5028892d53d Mon Sep 17 00:00:00 2001 From: Dief Bell Date: Wed, 28 May 2025 18:03:59 +0100 Subject: [PATCH 2/9] Added minimum Node version engine requirement --- package.json | 3 +++ pnpm-lock.yaml | 13 ++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 9b37022..64b8366 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "description": "cmake-js rewrite in typescript to support advanced build configurations", "main": "build/lib.js", "module": "build/lib.mjs", + "engines": { + "node": ">= 18" + }, "exports": { ".": { "require": "./build/lib.js", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 30227fc..9d90523 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -132,8 +132,8 @@ importers: specifier: 3.1.1 version: 3.1.1(@types/debug@4.1.12)(@types/node@22.14.0)(@vitest/ui@3.1.1)(terser@5.39.0)(yaml@2.7.0) which: - specifier: ^3.0.1 - version: 3.0.1 + specifier: ^2 + version: 2.0.2 packages: @@ -3318,11 +3318,6 @@ packages: engines: {node: '>= 8'} hasBin: true - which@3.0.1: - resolution: {integrity: sha512-XA1b62dzQzLfaEOSQFTCOd5KFf/1VSzZo7/7TUjnya6u0vGGKzU96UQBZTAThCb2j4/xjBAyii1OhRLJEivHvg==} - engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} - hasBin: true - which@5.0.0: resolution: {integrity: sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ==} engines: {node: ^18.17.0 || >=20.5.0} @@ -7044,10 +7039,6 @@ snapshots: dependencies: isexe: 2.0.0 - which@3.0.1: - dependencies: - isexe: 2.0.0 - which@5.0.0: dependencies: isexe: 3.1.1 From 2a35885ecabaa87c2d012a4fb10332b765d94298 Mon Sep 17 00:00:00 2001 From: Dief Bell Date: Wed, 28 May 2025 18:11:36 +0100 Subject: [PATCH 3/9] Upgraded which version, idk how it ended up not being in the PR --- package.json | 72 ++++++++++++++++++++++++++++++++------------------ pnpm-lock.yaml | 13 +++++++-- 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 64b8366..695cf4a 100644 --- a/package.json +++ b/package.json @@ -69,14 +69,30 @@ "test": "cross-env NODE_OPTIONS=--enable-source-maps pnpx vitest --watch false", "coverage": "cross-env NODE_OPTIONS=--enable-source-maps pnpx vitest --coverage --watch false" }, - "files": ["build/**/*", "src/**/*", "./*.mts", "./tsconfig.json"], + "files": [ + "build/**/*", + "src/**/*", + "./*.mts", + "./tsconfig.json" + ], "repository": { "type": "git", "url": "git+https://github.com/EmbeddedEnterprises/cmake-ts.git" }, - "keywords": ["cmake", "nan", "node", "native", "addon", "build", "cmake-js"], + "keywords": [ + "cmake", + "nan", + "node", + "native", + "addon", + "build", + "cmake-js" + ], "author": "Amin Yahyaabadi ", - "contributors": ["Amin Yahyaabadi ", "Martin Koppehel "], + "contributors": [ + "Amin Yahyaabadi ", + "Martin Koppehel " + ], "license": "MIT", "bugs": { "url": "https://github.com/EmbeddedEnterprises/cmake-ts/issues" @@ -84,51 +100,55 @@ "homepage": "https://github.com/EmbeddedEnterprises/cmake-ts#readme", "devDependencies": { "@babel/core": "7.26.10", + "@biomejs/biome": "1.9.4", "@types/babel__core": "7.20.5", + "@types/escape-quotes": "1.0.0", "@types/fs-extra": "11.0.4", + "@types/memoizee": "0.4.7", "@types/node": "22.14.0", "@types/resolve": "1.20.6", "@types/semver": "7.7.0", "@types/tar": "6.1.13", "@types/url-join": "4.0.3", "@types/which": "3.0.4", - "@types/escape-quotes": "1.0.0", "@upleveled/babel-plugin-remove-node-prefix": "1.0.5", - "@types/memoizee": "0.4.7", - "turbo": "2.5.0", + "@vitest/coverage-v8": "3.1.1", + "@vitest/ui": "3.1.1", + "ci-info": "4.2.0", + "commander": "^13.1.0", "cross-env": "7.0.3", + "escape-quotes": "^1.0.2", "eslint": "^8", "eslint-config-atomic": "1.22.1", - "npm-run-all2": "7.0.2", - "rollup-plugin-visualizer": "5.14.0", - "shx": "0.4.0", - "typescript": "5.8.3", - "vite": "6.2.7", - "vitest": "3.1.1", - "vite-plugin-babel": "1.3.0", - "@vitest/coverage-v8": "3.1.1", - "@vitest/ui": "3.1.1", - "@biomejs/biome": "1.9.4", - "prettier": "3.5.3", - "prettier-config-atomic": "4.0.0", "execa": "9.5.2", - "ci-info": "4.2.0", "fast-glob": "3.3.3", "fs-extra": "^10", + "memoizee": "0.4.17", + "msvc-dev-cmd": "github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd", + "node-downloader-helper": "^2.1.9", + "npm-run-all2": "7.0.2", + "prettier": "3.5.3", + "prettier-config-atomic": "4.0.0", "resolve": "^1.22.10", + "rollup-plugin-visualizer": "5.14.0", "semver": "^7.7.1", + "shx": "0.4.0", "tar": "^6", + "turbo": "2.5.0", + "typescript": "5.8.3", "url-join": "^4.0.1", - "which": "^2", - "node-downloader-helper": "^2.1.9", - "escape-quotes": "^1.0.2", - "commander": "^13.1.0", - "msvc-dev-cmd": "github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd", - "memoizee": "0.4.17" + "vite": "6.2.7", + "vite-plugin-babel": "1.3.0", + "vitest": "3.1.1", + "which": "^3.0.1" }, "packageManager": "pnpm@10.8.0", "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/package.json", "pnpm": { - "onlyBuiltDependencies": ["@biomejs/biome", "core-js", "esbuild"] + "onlyBuiltDependencies": [ + "@biomejs/biome", + "core-js", + "esbuild" + ] } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9d90523..30227fc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -132,8 +132,8 @@ importers: specifier: 3.1.1 version: 3.1.1(@types/debug@4.1.12)(@types/node@22.14.0)(@vitest/ui@3.1.1)(terser@5.39.0)(yaml@2.7.0) which: - specifier: ^2 - version: 2.0.2 + specifier: ^3.0.1 + version: 3.0.1 packages: @@ -3318,6 +3318,11 @@ packages: engines: {node: '>= 8'} hasBin: true + which@3.0.1: + resolution: {integrity: sha512-XA1b62dzQzLfaEOSQFTCOd5KFf/1VSzZo7/7TUjnya6u0vGGKzU96UQBZTAThCb2j4/xjBAyii1OhRLJEivHvg==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + hasBin: true + which@5.0.0: resolution: {integrity: sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ==} engines: {node: ^18.17.0 || >=20.5.0} @@ -7039,6 +7044,10 @@ snapshots: dependencies: isexe: 2.0.0 + which@3.0.1: + dependencies: + isexe: 2.0.0 + which@5.0.0: dependencies: isexe: 3.1.1 From 06b096e314f15ff6411972022c285f5e16251f33 Mon Sep 17 00:00:00 2001 From: Dief Bell Date: Wed, 28 May 2025 18:13:58 +0100 Subject: [PATCH 4/9] Undid pnpm's reformat --- package.json | 72 +++++++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index 695cf4a..5f20c4d 100644 --- a/package.json +++ b/package.json @@ -69,30 +69,14 @@ "test": "cross-env NODE_OPTIONS=--enable-source-maps pnpx vitest --watch false", "coverage": "cross-env NODE_OPTIONS=--enable-source-maps pnpx vitest --coverage --watch false" }, - "files": [ - "build/**/*", - "src/**/*", - "./*.mts", - "./tsconfig.json" - ], + "files": ["build/**/*", "src/**/*", "./*.mts", "./tsconfig.json"], "repository": { "type": "git", "url": "git+https://github.com/EmbeddedEnterprises/cmake-ts.git" }, - "keywords": [ - "cmake", - "nan", - "node", - "native", - "addon", - "build", - "cmake-js" - ], + "keywords": ["cmake", "nan", "node", "native", "addon", "build", "cmake-js"], "author": "Amin Yahyaabadi ", - "contributors": [ - "Amin Yahyaabadi ", - "Martin Koppehel " - ], + "contributors": ["Amin Yahyaabadi ", "Martin Koppehel "], "license": "MIT", "bugs": { "url": "https://github.com/EmbeddedEnterprises/cmake-ts/issues" @@ -100,55 +84,51 @@ "homepage": "https://github.com/EmbeddedEnterprises/cmake-ts#readme", "devDependencies": { "@babel/core": "7.26.10", - "@biomejs/biome": "1.9.4", "@types/babel__core": "7.20.5", - "@types/escape-quotes": "1.0.0", "@types/fs-extra": "11.0.4", - "@types/memoizee": "0.4.7", "@types/node": "22.14.0", "@types/resolve": "1.20.6", "@types/semver": "7.7.0", "@types/tar": "6.1.13", "@types/url-join": "4.0.3", "@types/which": "3.0.4", + "@types/escape-quotes": "1.0.0", "@upleveled/babel-plugin-remove-node-prefix": "1.0.5", - "@vitest/coverage-v8": "3.1.1", - "@vitest/ui": "3.1.1", - "ci-info": "4.2.0", - "commander": "^13.1.0", + "@types/memoizee": "0.4.7", + "turbo": "2.5.0", "cross-env": "7.0.3", - "escape-quotes": "^1.0.2", "eslint": "^8", "eslint-config-atomic": "1.22.1", - "execa": "9.5.2", - "fast-glob": "3.3.3", - "fs-extra": "^10", - "memoizee": "0.4.17", - "msvc-dev-cmd": "github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd", - "node-downloader-helper": "^2.1.9", "npm-run-all2": "7.0.2", + "rollup-plugin-visualizer": "5.14.0", + "shx": "0.4.0", + "typescript": "5.8.3", + "vite": "6.2.7", + "vitest": "3.1.1", + "vite-plugin-babel": "1.3.0", + "@vitest/coverage-v8": "3.1.1", + "@vitest/ui": "3.1.1", + "@biomejs/biome": "1.9.4", "prettier": "3.5.3", "prettier-config-atomic": "4.0.0", + "execa": "9.5.2", + "ci-info": "4.2.0", + "fast-glob": "3.3.3", + "fs-extra": "^10", "resolve": "^1.22.10", - "rollup-plugin-visualizer": "5.14.0", "semver": "^7.7.1", - "shx": "0.4.0", "tar": "^6", - "turbo": "2.5.0", - "typescript": "5.8.3", "url-join": "^4.0.1", - "vite": "6.2.7", - "vite-plugin-babel": "1.3.0", - "vitest": "3.1.1", - "which": "^3.0.1" + "which": "3.0.1", + "node-downloader-helper": "^2.1.9", + "escape-quotes": "^1.0.2", + "commander": "^13.1.0", + "msvc-dev-cmd": "github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd", + "memoizee": "0.4.17" }, "packageManager": "pnpm@10.8.0", "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/package.json", "pnpm": { - "onlyBuiltDependencies": [ - "@biomejs/biome", - "core-js", - "esbuild" - ] + "onlyBuiltDependencies": ["@biomejs/biome", "core-js", "esbuild"] } } From 3329751bb728723793d6c8c1301f5dee139c7b16 Mon Sep 17 00:00:00 2001 From: Dief Bell Date: Wed, 28 May 2025 18:15:35 +0100 Subject: [PATCH 5/9] Updated lockfile --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 30227fc..16d67aa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -132,7 +132,7 @@ importers: specifier: 3.1.1 version: 3.1.1(@types/debug@4.1.12)(@types/node@22.14.0)(@vitest/ui@3.1.1)(terser@5.39.0)(yaml@2.7.0) which: - specifier: ^3.0.1 + specifier: 3.0.1 version: 3.0.1 packages: From 6c51e2c15ce87ae85f3cd6f26e548b4523564bb8 Mon Sep 17 00:00:00 2001 From: Dief Bell Date: Wed, 1 Apr 2026 14:40:42 +0100 Subject: [PATCH 6/9] Reverted `which` to version 2, manually handling `which` throwing --- package.json | 75 +++++++++++++++++++++++++++------------------ pnpm-lock.yaml | 13 ++------ src/config.ts | 4 +-- src/generator.ts | 4 +-- src/whichNoThrow.ts | 15 +++++++++ 5 files changed, 67 insertions(+), 44 deletions(-) create mode 100644 src/whichNoThrow.ts diff --git a/package.json b/package.json index 5f20c4d..fe7936d 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,6 @@ "description": "cmake-js rewrite in typescript to support advanced build configurations", "main": "build/lib.js", "module": "build/lib.mjs", - "engines": { - "node": ">= 18" - }, "exports": { ".": { "require": "./build/lib.js", @@ -69,14 +66,30 @@ "test": "cross-env NODE_OPTIONS=--enable-source-maps pnpx vitest --watch false", "coverage": "cross-env NODE_OPTIONS=--enable-source-maps pnpx vitest --coverage --watch false" }, - "files": ["build/**/*", "src/**/*", "./*.mts", "./tsconfig.json"], + "files": [ + "build/**/*", + "src/**/*", + "./*.mts", + "./tsconfig.json" + ], "repository": { "type": "git", "url": "git+https://github.com/EmbeddedEnterprises/cmake-ts.git" }, - "keywords": ["cmake", "nan", "node", "native", "addon", "build", "cmake-js"], + "keywords": [ + "cmake", + "nan", + "node", + "native", + "addon", + "build", + "cmake-js" + ], "author": "Amin Yahyaabadi ", - "contributors": ["Amin Yahyaabadi ", "Martin Koppehel "], + "contributors": [ + "Amin Yahyaabadi ", + "Martin Koppehel " + ], "license": "MIT", "bugs": { "url": "https://github.com/EmbeddedEnterprises/cmake-ts/issues" @@ -84,51 +97,55 @@ "homepage": "https://github.com/EmbeddedEnterprises/cmake-ts#readme", "devDependencies": { "@babel/core": "7.26.10", + "@biomejs/biome": "1.9.4", "@types/babel__core": "7.20.5", + "@types/escape-quotes": "1.0.0", "@types/fs-extra": "11.0.4", + "@types/memoizee": "0.4.7", "@types/node": "22.14.0", "@types/resolve": "1.20.6", "@types/semver": "7.7.0", "@types/tar": "6.1.13", "@types/url-join": "4.0.3", "@types/which": "3.0.4", - "@types/escape-quotes": "1.0.0", "@upleveled/babel-plugin-remove-node-prefix": "1.0.5", - "@types/memoizee": "0.4.7", - "turbo": "2.5.0", + "@vitest/coverage-v8": "3.1.1", + "@vitest/ui": "3.1.1", + "ci-info": "4.2.0", + "commander": "^13.1.0", "cross-env": "7.0.3", + "escape-quotes": "^1.0.2", "eslint": "^8", "eslint-config-atomic": "1.22.1", - "npm-run-all2": "7.0.2", - "rollup-plugin-visualizer": "5.14.0", - "shx": "0.4.0", - "typescript": "5.8.3", - "vite": "6.2.7", - "vitest": "3.1.1", - "vite-plugin-babel": "1.3.0", - "@vitest/coverage-v8": "3.1.1", - "@vitest/ui": "3.1.1", - "@biomejs/biome": "1.9.4", - "prettier": "3.5.3", - "prettier-config-atomic": "4.0.0", "execa": "9.5.2", - "ci-info": "4.2.0", "fast-glob": "3.3.3", "fs-extra": "^10", + "memoizee": "0.4.17", + "msvc-dev-cmd": "github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd", + "node-downloader-helper": "^2.1.9", + "npm-run-all2": "7.0.2", + "prettier": "3.5.3", + "prettier-config-atomic": "4.0.0", "resolve": "^1.22.10", + "rollup-plugin-visualizer": "5.14.0", "semver": "^7.7.1", + "shx": "0.4.0", "tar": "^6", + "turbo": "2.5.0", + "typescript": "5.8.3", "url-join": "^4.0.1", - "which": "3.0.1", - "node-downloader-helper": "^2.1.9", - "escape-quotes": "^1.0.2", - "commander": "^13.1.0", - "msvc-dev-cmd": "github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd", - "memoizee": "0.4.17" + "vite": "6.2.7", + "vite-plugin-babel": "1.3.0", + "vitest": "3.1.1", + "which": "^2" }, "packageManager": "pnpm@10.8.0", "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/package.json", "pnpm": { - "onlyBuiltDependencies": ["@biomejs/biome", "core-js", "esbuild"] + "onlyBuiltDependencies": [ + "@biomejs/biome", + "core-js", + "esbuild" + ] } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 16d67aa..9d90523 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -132,8 +132,8 @@ importers: specifier: 3.1.1 version: 3.1.1(@types/debug@4.1.12)(@types/node@22.14.0)(@vitest/ui@3.1.1)(terser@5.39.0)(yaml@2.7.0) which: - specifier: 3.0.1 - version: 3.0.1 + specifier: ^2 + version: 2.0.2 packages: @@ -3318,11 +3318,6 @@ packages: engines: {node: '>= 8'} hasBin: true - which@3.0.1: - resolution: {integrity: sha512-XA1b62dzQzLfaEOSQFTCOd5KFf/1VSzZo7/7TUjnya6u0vGGKzU96UQBZTAThCb2j4/xjBAyii1OhRLJEivHvg==} - engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} - hasBin: true - which@5.0.0: resolution: {integrity: sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ==} engines: {node: ^18.17.0 || >=20.5.0} @@ -7044,10 +7039,6 @@ snapshots: dependencies: isexe: 2.0.0 - which@3.0.1: - dependencies: - isexe: 2.0.0 - which@5.0.0: dependencies: isexe: 3.1.1 diff --git a/src/config.ts b/src/config.ts index f14cd62..2f7d565 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,8 +1,8 @@ import { readJson } from "fs-extra" -import which from "which" import type { BuildCommandOptions, BuildConfiguration, BuildConfigurations, Options } from "./config-types.d" import { getCmakeGenerator } from "./generator.js" import { logger } from "./lib.js" +import { whichNoThrow } from "./whichNoThrow.js" export async function parseBuildConfigs( opts: Options, @@ -97,7 +97,7 @@ export async function getBuildConfig( config.additionalDefines ??= globalConfig.additionalDefines ?? [] - config.cmakeToUse ??= globalConfig.cmakeToUse ?? (await which("cmake", { nothrow: true })) ?? "cmake" + config.cmakeToUse ??= globalConfig.cmakeToUse ?? (await whichNoThrow("cmake", { nothrow: true })) ?? "cmake" const { generator, generatorFlags, binary } = await getCmakeGenerator(config.cmakeToUse, config.os, config.arch) config.generatorToUse ??= globalConfig.generatorToUse ?? generator diff --git a/src/generator.ts b/src/generator.ts index e6a6477..9f4c6f8 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -1,8 +1,8 @@ import memoizee from "memoizee" -import which from "which" import { getCMakeArchitecture } from "./argumentBuilder.js" import { execCapture } from "./utils/exec.js" import { logger } from "./utils/logger.js" +import { whichNoThrow } from "./whichNoThrow.js" export const getCmakeGenerator = memoizee( async ( @@ -15,7 +15,7 @@ export const getCmakeGenerator = memoizee( binary?: string }> => { // use ninja if available - const ninja = await which("ninja", { nothrow: true }) + const ninja = await whichNoThrow("ninja"); if (ninja !== null) { logger.debug(`Using generator: Ninja for ${os} ${arch}`) return { diff --git a/src/whichNoThrow.ts b/src/whichNoThrow.ts new file mode 100644 index 0000000..3644f25 --- /dev/null +++ b/src/whichNoThrow.ts @@ -0,0 +1,15 @@ +import which from "which"; + +/** + * Wraps `which` to return `null` instead of throwing an error if the command is not found, + * matching the v3 behaviour if `nothrow: true` option is used. + * + * `@types/which@2.0.2` still show this `nothrow` parameter, even though it's not respected in v2. + */ +export const whichNoThrow = async (cmd: string, options?: which.Options): Promise> | null> => { + try { + return await which(cmd, options); + } catch { + return null; + } +}; From ddcf84c762934f7e7d9ff2e42c43a563eda2836a Mon Sep 17 00:00:00 2001 From: Dief Bell Date: Wed, 1 Apr 2026 16:44:02 +0100 Subject: [PATCH 7/9] Corrected logging for generator and generator flags --- src/config.ts | 4 ++++ src/generator.ts | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/config.ts b/src/config.ts index 2f7d565..2faee49 100644 --- a/src/config.ts +++ b/src/config.ts @@ -100,8 +100,12 @@ export async function getBuildConfig( config.cmakeToUse ??= globalConfig.cmakeToUse ?? (await whichNoThrow("cmake", { nothrow: true })) ?? "cmake" const { generator, generatorFlags, binary } = await getCmakeGenerator(config.cmakeToUse, config.os, config.arch) + // If this build configuration specifies a generator, use that. + // If not, use the globally defined generator. + // If that isn't found, use the detected generator from getCmakeGenerator. config.generatorToUse ??= globalConfig.generatorToUse ?? generator config.generatorFlags ??= globalConfig.generatorFlags ?? generatorFlags + logger.debug(`Using generator: ${ config.generatorToUse} ${config.generatorFlags} for ${config.os} ${config.arch}`) config.generatorBinary ??= globalConfig.generatorBinary ?? binary return config as BuildConfiguration diff --git a/src/generator.ts b/src/generator.ts index 9f4c6f8..cb2e650 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -17,7 +17,7 @@ export const getCmakeGenerator = memoizee( // use ninja if available const ninja = await whichNoThrow("ninja"); if (ninja !== null) { - logger.debug(`Using generator: Ninja for ${os} ${arch}`) + logger.debug(`Found generator: Ninja for ${os} ${arch}`) return { generator: "Ninja", binary: ninja, @@ -54,7 +54,7 @@ export const getCmakeGenerator = memoizee( const generator = useArchSwitch ? parsedGenerator : `${parsedGenerator}${archString}` const generatorFlags = useArchSwitch ? ["-A", getCMakeArchitecture(arch, os)] : undefined - logger.debug(`Using generator: ${generator} ${generatorFlags} for ${os} ${arch}`) + logger.debug(`Found generator: ${generator} ${generatorFlags} for ${os} ${arch}`) return { generator, generatorFlags, @@ -68,7 +68,7 @@ export const getCmakeGenerator = memoizee( } // use native generator - logger.debug(`Using generator: native for ${os} ${arch}`) + logger.debug(`Found generator: native for ${os} ${arch}`) return { generator: "native", binary: undefined, From f122639d92680c267c16b6d6f342cb16806897ed Mon Sep 17 00:00:00 2001 From: Dief Bell Date: Thu, 2 Apr 2026 10:11:33 +0100 Subject: [PATCH 8/9] Corrected architecture arg map for msvc Unsure if this breaks cmake/ninja on Windows --- src/argumentBuilder.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/argumentBuilder.ts b/src/argumentBuilder.ts index 1d5beff..e29e21a 100644 --- a/src/argumentBuilder.ts +++ b/src/argumentBuilder.ts @@ -157,9 +157,9 @@ export function getCMakeArchitecture(arch: NodeJS.Architecture, os: NodeJS.Platf const cmakeArchMap: Record> = { win32: { - arm64: "arm64", - x64: "AMD64", - ia32: "X86", + arm64: "ARM64", + x64: "x64", + ia32: "Win32", }, darwin: { arm64: "arm64", From 5823edbee24a1180c6f6f70b31bc38bd1e52e756 Mon Sep 17 00:00:00 2001 From: Dief Bell Date: Thu, 2 Apr 2026 10:54:49 +0100 Subject: [PATCH 9/9] Documented `generatorToUse` and `generatorFlags` --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index cee138b..cd0466e 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,8 @@ Configuration is done entirely via `package.json`. You can specify multiple buil "name": "win-x64", // name for named-configs mode "os": "win32", // win32, linux and darwin are supported "arch": "x64", // x64, x86 should work + "generatorToUse": "Visual Studio 15 2017", // optional CMake generator override for this configuration + "generatorFlags": ["-A", "x64"], // optional extra flags passed to the generator "runtime": "electron", // node or electron "runtimeVersion": "4.0.1", // Version of the runtime which it is built "toolchainFile": "/windows.cmake", // CMake Toolchain file to use for crosscompiling @@ -177,6 +179,8 @@ Configuration is done entirely via `package.json`. You can specify multiple buil } // more build configurations ... ], "targetDirectory": "build", // where to build your project + "generatorToUse": "Ninja", // optional default CMake generator for all configurations + "generatorFlags": ["-A", "ARM64"], // optional default generator flags for all configurations "buildType": "Release", // Debug or Release build, most likely set it to Release "projectName": "addon" // The name of your CMake project. "globalCMakeOptions": [{ // this might be omitted of no further options should be passed to CMake