From f1f67e3d2a14695cf53e642c0694285c0d4d8141 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 24 Jul 2026 10:06:17 +0200 Subject: [PATCH 1/2] feat!: Migrate the package to ESM --- lib/index.ts | 4 ++-- lib/xcode.ts | 6 +++--- package.json | 12 ++++++++++-- test/e2e/xcode.spec.ts | 2 +- test/unit/index.spec.ts | 2 +- tsconfig.json | 4 +++- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 5e064ac..af4d328 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,5 +1,5 @@ // transpile:main -import {getPath, getVersion, getMaxIOSSDK, getMaxTVOSSDK, getClangVersion} from './xcode'; +import {getPath, getVersion, getMaxIOSSDK, getMaxTVOSSDK, getClangVersion} from './xcode.js'; const xcode = { getPath, @@ -12,4 +12,4 @@ const xcode = { export {getPath, getVersion, getMaxIOSSDK, getMaxTVOSSDK, getClangVersion}; export default xcode; -export type {XcodeVersion} from './types'; +export type {XcodeVersion} from './types.js'; diff --git a/lib/xcode.ts b/lib/xcode.ts index b724d92..665e2f9 100644 --- a/lib/xcode.ts +++ b/lib/xcode.ts @@ -3,8 +3,8 @@ import path from 'node:path'; import {retry} from 'asyncbox'; import {exec} from 'teen_process'; import * as semver from 'semver'; -import {runXcrunCommand, findAppPaths, XCRUN_TIMEOUT, readXcodePlist} from './helpers'; -import type {XcodeVersion} from './types'; +import {runXcrunCommand, findAppPaths, XCRUN_TIMEOUT, readXcodePlist} from './helpers.js'; +import type {XcodeVersion} from './types.js'; const DEFAULT_NUMBER_OF_RETRIES = 2; const XCODE_BUNDLE_ID = 'com.apple.dt.Xcode'; @@ -44,7 +44,7 @@ export async function getPathFromXcodeSelect(timeout: number = XCRUN_TIMEOUT): P const msg = `Cannot determine the path to Xcode by running 'xcode-select -p' command. ` + `Original error: ${stderr || message}`; - throw new Error(msg); + throw new Error(msg, {cause: e}); } // trim and remove trailing slash const developerRoot = String(stdout).replace(/\/$/, '').trim(); diff --git a/package.json b/package.json index 1d762e3..42e8bd2 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,8 @@ "format": "prettier -w ./lib ./test", "format:check": "prettier --check ./lib ./test", "prepare": "npm run build", - "test": "node --test --test-timeout=60000 \"./build/test/unit/**/*.spec.js\"", - "e2e-test": "node --test --test-force-exit --test-concurrency=1 --test-timeout=300000 \"./build/test/e2e/**/*.spec.js\"" + "test": "node --enable-source-maps --test --test-timeout=60000 \"./build/test/unit/**/*.spec.js\"", + "e2e-test": "node --enable-source-maps --test --test-force-exit --test-concurrency=1 --test-timeout=300000 \"./build/test/e2e/**/*.spec.js\"" }, "prettier": { "bracketSpacing": false, @@ -63,5 +63,13 @@ "prettier": "^3.9.3", "semantic-release": "^25.0.2", "typescript": "^6.0.2" + }, + "type": "module", + "exports": { + ".": { + "types": "./build/lib/index.d.ts", + "import": "./build/lib/index.js" + }, + "./package.json": "./package.json" } } diff --git a/test/e2e/xcode.spec.ts b/test/e2e/xcode.spec.ts index e11930d..5075ffe 100644 --- a/test/e2e/xcode.spec.ts +++ b/test/e2e/xcode.spec.ts @@ -1,6 +1,6 @@ import {fs, util} from '@appium/support'; import assert from 'node:assert/strict'; -import * as xcode from '../../lib/xcode'; +import * as xcode from '../../lib/xcode.js'; import {describe, it} from 'node:test'; // on slow machines and busy CI systems these can be slow and flakey diff --git a/test/unit/index.spec.ts b/test/unit/index.spec.ts index 4766378..1dc4354 100644 --- a/test/unit/index.spec.ts +++ b/test/unit/index.spec.ts @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import xcode from '../../lib/index'; +import xcode from '../../lib/index.js'; import {describe, it} from 'node:test'; describe('index', function () { diff --git a/tsconfig.json b/tsconfig.json index 906ef91..7d12b32 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,9 @@ "outDir": "build", "types": ["node"], "checkJs": true, - "strict": true + "strict": true, + "module": "NodeNext", + "moduleResolution": "NodeNext" }, "include": [ "lib", From 6001c7993b4d9097fe43ab201ceefdd6ab0a92e2 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 24 Jul 2026 10:07:23 +0200 Subject: [PATCH 2/2] moar --- lib/index.ts | 1 - lib/types.ts | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/index.ts b/lib/index.ts index af4d328..bbbacbd 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,3 @@ -// transpile:main import {getPath, getVersion, getMaxIOSSDK, getMaxTVOSSDK, getClangVersion} from './xcode.js'; const xcode = { diff --git a/lib/types.ts b/lib/types.ts index acbd386..6f44927 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -1,8 +1,14 @@ export interface XcodeVersion { + /** The Xcode version as a string, e.g. '10.0' or '10.0.1' */ versionString: string; + /** The Xcode version as a float, e.g. 10.0 or 10.1 */ versionFloat: number; + /** The major version number, e.g. 10 */ major: number; + /** The minor version number, e.g. 1 */ minor: number; + /** The patch version number, if present in the version string */ patch?: number; + /** Returns {@link versionString} */ toString(): string; }