From f7cb010aef57453d760e1108b85b0711a9d2d4c2 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 24 Jul 2026 09:50:32 +0200 Subject: [PATCH] feat!: Migrate the package to ESM --- lib/index.ts | 4 +- lib/logger.ts | 2 +- lib/simctl.ts | 56 ++++++++++++++-------------- lib/subcommands/addmedia.ts | 2 +- lib/subcommands/appinfo.ts | 6 +-- lib/subcommands/boot.ts | 4 +- lib/subcommands/bootstatus.ts | 6 +-- lib/subcommands/create.ts | 8 ++-- lib/subcommands/delete.ts | 2 +- lib/subcommands/erase.ts | 2 +- lib/subcommands/get_app_container.ts | 2 +- lib/subcommands/getenv.ts | 2 +- lib/subcommands/install.ts | 2 +- lib/subcommands/io.ts | 2 +- lib/subcommands/keychain.ts | 4 +- lib/subcommands/launch.ts | 2 +- lib/subcommands/list.ts | 8 ++-- lib/subcommands/location.ts | 2 +- lib/subcommands/openurl.ts | 2 +- lib/subcommands/pbcopy.ts | 2 +- lib/subcommands/pbpaste.ts | 2 +- lib/subcommands/privacy.ts | 2 +- lib/subcommands/push.ts | 2 +- lib/subcommands/shutdown.ts | 4 +- lib/subcommands/spawn.ts | 2 +- lib/subcommands/terminate.ts | 2 +- lib/subcommands/ui.ts | 2 +- lib/subcommands/uninstall.ts | 2 +- package.json | 14 +++++-- test/e2e/simctl-e2e.spec.ts | 2 +- test/unit/simctl.spec.ts | 5 ++- tsconfig.json | 4 +- 32 files changed, 87 insertions(+), 76 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index cf516a4..06df6a4 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,4 @@ -import {Simctl} from './simctl'; +import {Simctl} from './simctl.js'; export type { SimctlOpts, DeviceInfo, @@ -7,7 +7,7 @@ export type { CertOptions, XCRun, AppInfo, -} from './types'; +} from './types.js'; export {Simctl}; export default Simctl; diff --git a/lib/logger.ts b/lib/logger.ts index 905394a..2451f83 100644 --- a/lib/logger.ts +++ b/lib/logger.ts @@ -1,4 +1,4 @@ -import appiumLogger from '@appium/logger'; +import {log as appiumLogger} from '@appium/logger'; export const LOG_PREFIX = 'simctl'; diff --git a/lib/simctl.ts b/lib/simctl.ts index 98cd6ea..41f91a2 100644 --- a/lib/simctl.ts +++ b/lib/simctl.ts @@ -1,33 +1,33 @@ import which from 'which'; -import {log, LOG_PREFIX} from './logger'; -import {DEFAULT_EXEC_TIMEOUT, getXcrunBinary} from './helpers'; +import {log, LOG_PREFIX} from './logger.js'; +import {DEFAULT_EXEC_TIMEOUT, getXcrunBinary} from './helpers.js'; import {exec as tpExec, SubProcess} from 'teen_process'; -import * as addmediaCommands from './subcommands/addmedia'; -import * as appinfoCommands from './subcommands/appinfo'; -import * as bootCommands from './subcommands/boot'; -import * as bootstatusCommands from './subcommands/bootstatus'; -import * as createCommands from './subcommands/create'; -import * as deleteCommands from './subcommands/delete'; -import * as eraseCommands from './subcommands/erase'; -import * as getappcontainerCommands from './subcommands/get_app_container'; -import * as installCommands from './subcommands/install'; -import * as ioCommands from './subcommands/io'; -import * as keychainCommands from './subcommands/keychain'; -import * as launchCommands from './subcommands/launch'; -import * as listCommands from './subcommands/list'; -import * as openurlCommands from './subcommands/openurl'; -import * as pbcopyCommands from './subcommands/pbcopy'; -import * as pbpasteCommands from './subcommands/pbpaste'; -import * as privacyCommands from './subcommands/privacy'; -import * as pushCommands from './subcommands/push'; -import * as envCommands from './subcommands/getenv'; -import * as shutdownCommands from './subcommands/shutdown'; -import * as spawnCommands from './subcommands/spawn'; -import * as terminateCommands from './subcommands/terminate'; -import * as uiCommands from './subcommands/ui'; -import * as uninstallCommands from './subcommands/uninstall'; -import * as locationCommands from './subcommands/location'; -import type {XCRun, ExecOpts, SimctlOpts, ExecResult} from './types'; +import * as addmediaCommands from './subcommands/addmedia.js'; +import * as appinfoCommands from './subcommands/appinfo.js'; +import * as bootCommands from './subcommands/boot.js'; +import * as bootstatusCommands from './subcommands/bootstatus.js'; +import * as createCommands from './subcommands/create.js'; +import * as deleteCommands from './subcommands/delete.js'; +import * as eraseCommands from './subcommands/erase.js'; +import * as getappcontainerCommands from './subcommands/get_app_container.js'; +import * as installCommands from './subcommands/install.js'; +import * as ioCommands from './subcommands/io.js'; +import * as keychainCommands from './subcommands/keychain.js'; +import * as launchCommands from './subcommands/launch.js'; +import * as listCommands from './subcommands/list.js'; +import * as openurlCommands from './subcommands/openurl.js'; +import * as pbcopyCommands from './subcommands/pbcopy.js'; +import * as pbpasteCommands from './subcommands/pbpaste.js'; +import * as privacyCommands from './subcommands/privacy.js'; +import * as pushCommands from './subcommands/push.js'; +import * as envCommands from './subcommands/getenv.js'; +import * as shutdownCommands from './subcommands/shutdown.js'; +import * as spawnCommands from './subcommands/spawn.js'; +import * as terminateCommands from './subcommands/terminate.js'; +import * as uiCommands from './subcommands/ui.js'; +import * as uninstallCommands from './subcommands/uninstall.js'; +import * as locationCommands from './subcommands/location.js'; +import type {XCRun, ExecOpts, SimctlOpts, ExecResult} from './types.js'; const SIMCTL_ENV_PREFIX = 'SIMCTL_CHILD_'; diff --git a/lib/subcommands/addmedia.ts b/lib/subcommands/addmedia.ts index e8f73c4..a7da796 100644 --- a/lib/subcommands/addmedia.ts +++ b/lib/subcommands/addmedia.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; import type {TeenProcessExecResult} from 'teen_process'; /** diff --git a/lib/subcommands/appinfo.ts b/lib/subcommands/appinfo.ts index 1024c06..1cb89da 100644 --- a/lib/subcommands/appinfo.ts +++ b/lib/subcommands/appinfo.ts @@ -1,6 +1,6 @@ -import type {Simctl} from '../simctl'; -import type {AppInfo} from '../types'; -import {convertPlistToJson} from '../helpers'; +import type {Simctl} from '../simctl.js'; +import type {AppInfo} from '../types.js'; +import {convertPlistToJson} from '../helpers.js'; /** * Get information about an app installed on the simulator diff --git a/lib/subcommands/boot.ts b/lib/subcommands/boot.ts index 5561665..c2dfc0c 100644 --- a/lib/subcommands/boot.ts +++ b/lib/subcommands/boot.ts @@ -1,5 +1,5 @@ -import {log, LOG_PREFIX} from '../logger'; -import type {Simctl} from '../simctl'; +import {log, LOG_PREFIX} from '../logger.js'; +import type {Simctl} from '../simctl.js'; /** * Boot the particular Simulator if it is not running. diff --git a/lib/subcommands/bootstatus.ts b/lib/subcommands/bootstatus.ts index bff1435..a4a3957 100644 --- a/lib/subcommands/bootstatus.ts +++ b/lib/subcommands/bootstatus.ts @@ -1,7 +1,7 @@ -import {log, LOG_PREFIX} from '../logger'; +import {log, LOG_PREFIX} from '../logger.js'; import {waitForCondition} from 'asyncbox'; -import type {Simctl} from '../simctl'; -import type {BootMonitorOptions} from '../types'; +import type {Simctl} from '../simctl.js'; +import type {BootMonitorOptions} from '../types.js'; import type {SubProcess} from 'teen_process'; /** diff --git a/lib/subcommands/create.ts b/lib/subcommands/create.ts index e828a60..b54a7de 100644 --- a/lib/subcommands/create.ts +++ b/lib/subcommands/create.ts @@ -1,8 +1,8 @@ -import {log, LOG_PREFIX} from '../logger'; +import {log, LOG_PREFIX} from '../logger.js'; import {retryInterval} from 'asyncbox'; -import {SIM_RUNTIME_NAME, normalizeVersion} from '../helpers'; -import type {Simctl} from '../simctl'; -import type {SimCreationOpts} from '../types'; +import {SIM_RUNTIME_NAME, normalizeVersion} from '../helpers.js'; +import type {Simctl} from '../simctl.js'; +import type {SimCreationOpts} from '../types.js'; const SIM_RUNTIME_NAME_SUFFIX_IOS = 'iOS'; const DEFAULT_CREATE_SIMULATOR_TIMEOUT = 10000; diff --git a/lib/subcommands/delete.ts b/lib/subcommands/delete.ts index ad116b0..bc7ede4 100644 --- a/lib/subcommands/delete.ts +++ b/lib/subcommands/delete.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Delete the particular Simulator from available devices list. diff --git a/lib/subcommands/erase.ts b/lib/subcommands/erase.ts index 672607e..2a62e51 100644 --- a/lib/subcommands/erase.ts +++ b/lib/subcommands/erase.ts @@ -1,5 +1,5 @@ import {retryInterval} from 'asyncbox'; -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Reset the content and settings of the particular Simulator. diff --git a/lib/subcommands/get_app_container.ts b/lib/subcommands/get_app_container.ts index d0ebd5b..079c48f 100644 --- a/lib/subcommands/get_app_container.ts +++ b/lib/subcommands/get_app_container.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Get the full path to the particular application container diff --git a/lib/subcommands/getenv.ts b/lib/subcommands/getenv.ts index 42a49bc..7a7dc45 100644 --- a/lib/subcommands/getenv.ts +++ b/lib/subcommands/getenv.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Retrieves the value of a Simulator environment variable diff --git a/lib/subcommands/install.ts b/lib/subcommands/install.ts index a4adf28..b32aca9 100644 --- a/lib/subcommands/install.ts +++ b/lib/subcommands/install.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Install the particular application package on Simulator. diff --git a/lib/subcommands/io.ts b/lib/subcommands/io.ts index 0eed3dc..7afeed9 100644 --- a/lib/subcommands/io.ts +++ b/lib/subcommands/io.ts @@ -3,7 +3,7 @@ import {randomUUID} from 'node:crypto'; import path from 'node:path'; import os from 'node:os'; import fs from 'node:fs/promises'; -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Gets base64 screenshot for device diff --git a/lib/subcommands/keychain.ts b/lib/subcommands/keychain.ts index 63645a3..ed7ba85 100644 --- a/lib/subcommands/keychain.ts +++ b/lib/subcommands/keychain.ts @@ -3,8 +3,8 @@ import fs from 'node:fs/promises'; import {randomUUID} from 'node:crypto'; import path from 'node:path'; import {rimraf} from 'rimraf'; -import type {Simctl} from '../simctl'; -import type {CertOptions} from '../types'; +import type {Simctl} from '../simctl.js'; +import type {CertOptions} from '../types.js'; /** * Adds the given certificate to the Trusted Root Store on the simulator diff --git a/lib/subcommands/launch.ts b/lib/subcommands/launch.ts index 5a0bd6b..e9d516a 100644 --- a/lib/subcommands/launch.ts +++ b/lib/subcommands/launch.ts @@ -1,5 +1,5 @@ import {retryInterval} from 'asyncbox'; -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Execute the particular application package on Simulator. diff --git a/lib/subcommands/list.ts b/lib/subcommands/list.ts index baeb6cb..de07888 100644 --- a/lib/subcommands/list.ts +++ b/lib/subcommands/list.ts @@ -1,7 +1,7 @@ -import {SIM_RUNTIME_NAME, normalizeVersion} from '../helpers'; -import {log, LOG_PREFIX} from '../logger'; -import type {Simctl} from '../simctl'; -import type {DeviceInfo} from '../types'; +import {SIM_RUNTIME_NAME, normalizeVersion} from '../helpers.js'; +import {log, LOG_PREFIX} from '../logger.js'; +import type {Simctl} from '../simctl.js'; +import type {DeviceInfo} from '../types.js'; /** * Parse the list of existing Simulator devices to represent diff --git a/lib/subcommands/location.ts b/lib/subcommands/location.ts index 2bf30b3..a42600f 100644 --- a/lib/subcommands/location.ts +++ b/lib/subcommands/location.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Set the Simulator location to a specific latitude and longitude. diff --git a/lib/subcommands/openurl.ts b/lib/subcommands/openurl.ts index 8734ecc..a3c99b2 100644 --- a/lib/subcommands/openurl.ts +++ b/lib/subcommands/openurl.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; import type {TeenProcessExecResult} from 'teen_process'; /** diff --git a/lib/subcommands/pbcopy.ts b/lib/subcommands/pbcopy.ts index 29f1aed..da4a6c9 100644 --- a/lib/subcommands/pbcopy.ts +++ b/lib/subcommands/pbcopy.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; import type {SubProcess} from 'teen_process'; /** diff --git a/lib/subcommands/pbpaste.ts b/lib/subcommands/pbpaste.ts index 5e890c8..8e35232 100644 --- a/lib/subcommands/pbpaste.ts +++ b/lib/subcommands/pbpaste.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Get the content of Simulator pasteboard. diff --git a/lib/subcommands/privacy.ts b/lib/subcommands/privacy.ts index 7526b2b..6628c5c 100644 --- a/lib/subcommands/privacy.ts +++ b/lib/subcommands/privacy.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Grants the given permission on the app with the given bundle identifier diff --git a/lib/subcommands/push.ts b/lib/subcommands/push.ts index 2dca196..ed98efe 100644 --- a/lib/subcommands/push.ts +++ b/lib/subcommands/push.ts @@ -3,7 +3,7 @@ import {randomUUID} from 'node:crypto'; import path from 'node:path'; import os from 'node:os'; import fs from 'node:fs/promises'; -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Send a simulated push notification diff --git a/lib/subcommands/shutdown.ts b/lib/subcommands/shutdown.ts index 2b8b8a1..f1de73b 100644 --- a/lib/subcommands/shutdown.ts +++ b/lib/subcommands/shutdown.ts @@ -1,5 +1,5 @@ -import {log, LOG_PREFIX} from '../logger'; -import type {Simctl} from '../simctl'; +import {log, LOG_PREFIX} from '../logger.js'; +import type {Simctl} from '../simctl.js'; /** * Shutdown the given Simulator if it is running. diff --git a/lib/subcommands/spawn.ts b/lib/subcommands/spawn.ts index 8aeb75b..0457d5f 100644 --- a/lib/subcommands/spawn.ts +++ b/lib/subcommands/spawn.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; import type {TeenProcessExecResult, SubProcess} from 'teen_process'; /** diff --git a/lib/subcommands/terminate.ts b/lib/subcommands/terminate.ts index 5537f91..c347b52 100644 --- a/lib/subcommands/terminate.ts +++ b/lib/subcommands/terminate.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Terminate the given running application on Simulator. diff --git a/lib/subcommands/ui.ts b/lib/subcommands/ui.ts index 4e329ac..e45a062 100644 --- a/lib/subcommands/ui.ts +++ b/lib/subcommands/ui.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Retrieves the current UI appearance value from the given simulator diff --git a/lib/subcommands/uninstall.ts b/lib/subcommands/uninstall.ts index edb1929..3028414 100644 --- a/lib/subcommands/uninstall.ts +++ b/lib/subcommands/uninstall.ts @@ -1,4 +1,4 @@ -import type {Simctl} from '../simctl'; +import type {Simctl} from '../simctl.js'; /** * Remove the particular application package from Simulator. diff --git a/package.json b/package.json index d7c6329..985a62d 100644 --- a/package.json +++ b/package.json @@ -48,8 +48,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, @@ -77,5 +77,13 @@ "sinon": "^22.0.0", "typescript": "^6.0.2" }, - "types": "./build/lib/index.d.ts" + "types": "./build/lib/index.d.ts", + "type": "module", + "exports": { + ".": { + "types": "./build/lib/index.d.ts", + "import": "./build/lib/index.js" + }, + "./package.json": "./package.json" + } } diff --git a/test/e2e/simctl-e2e.spec.ts b/test/e2e/simctl-e2e.spec.ts index fe53f37..e773f9f 100644 --- a/test/e2e/simctl-e2e.spec.ts +++ b/test/e2e/simctl-e2e.spec.ts @@ -1,4 +1,4 @@ -import {Simctl} from '../../lib/simctl'; +import {Simctl} from '../../lib/simctl.js'; import {rimraf} from 'rimraf'; import {randomUUID} from 'node:crypto'; import path from 'node:path'; diff --git a/test/unit/simctl.spec.ts b/test/unit/simctl.spec.ts index 71762be..245abb5 100644 --- a/test/unit/simctl.spec.ts +++ b/test/unit/simctl.spec.ts @@ -1,9 +1,10 @@ import sinon from 'sinon'; import fs from 'node:fs'; import path from 'node:path'; +import {fileURLToPath} from 'node:url'; import {expect, use} from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {Simctl} from '../../lib/simctl'; +import {Simctl} from '../../lib/simctl.js'; import {describe, it, beforeEach, afterEach, after} from 'node:test'; use(chaiAsPromised); @@ -321,7 +322,7 @@ describe('simctl', function () { }); function getModuleRootSync(): string { - let currentDir = path.dirname(path.resolve(__filename)); + let currentDir = path.dirname(fileURLToPath(import.meta.url)); let isAtFsRoot = false; while (!isAtFsRoot) { const manifestPath = path.join(currentDir, 'package.json'); diff --git a/tsconfig.json b/tsconfig.json index f1aed4a..36b96b7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,9 @@ "esModuleInterop": true, "outDir": "build", "types": ["node"], - "strict": true + "strict": true, + "module": "NodeNext", + "moduleResolution": "NodeNext" }, "include": [ "lib",