Skip to content

Commit ed947c0

Browse files
committed
refactor(definitions): make the legacy service interfaces contract aliases
Each of the twelve interfaces becomes 'interface IFoo extends Foo {}', so a service has one declaration instead of two that can drift, and the existing 'implements IFoo' clause enforces the contract at the implementation site. Four methods on Mobile.IDevicesService and two on IProjectDataService were public, exported through the require('nativescript') surface and asserted by its test, yet declared nowhere; they are now on both the interface and the contract. These declarations were previously invisible to the compiler under skipLibCheck. Moving them into .ts files puts them under type checking, which is what surfaced the parameter initializers that are illegal in a declaration file.
1 parent 7079d1a commit ed947c0

8 files changed

Lines changed: 40 additions & 713 deletions

File tree

lib/common/declarations.d.ts

Lines changed: 10 additions & 394 deletions
Large diffs are not rendered by default.

lib/common/definitions/logger.d.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Layout, LoggingEvent, Configuration, Level } from "log4js";
22
import { EventEmitter } from "events";
33
import { LoggerLevel } from "../../constants";
44
import { IDictionary } from "../declarations";
5+
import type { Logger } from "../../contracts/logger";
56

67
declare global {
78
interface IAppenderOptions extends IDictionary<any> {
@@ -14,28 +15,13 @@ declare global {
1415
appenderOptions?: IAppenderOptions;
1516
}
1617

17-
interface ILogger {
18-
initialize(opts?: ILoggerOptions): void;
19-
initializeCliLogger(opts?: ILoggerOptions): void;
20-
getLevel(): string;
21-
fatal(formatStr?: any, ...args: any[]): void;
22-
error(formatStr?: any, ...args: any[]): void;
23-
warn(formatStr?: any, ...args: any[]): void;
24-
info(formatStr?: any, ...args: any[]): void;
25-
debug(formatStr?: any, ...args: any[]): void;
26-
trace(formatStr?: any, ...args: any[]): void;
27-
printMarkdown(...args: any[]): void;
28-
prepare(item: any): string;
29-
isVerbose(): boolean;
30-
clearScreen(): void;
31-
}
18+
interface ILogger extends Logger {}
3219

3320
interface Log4JSAppenderConfiguration extends Configuration {
3421
layout: Layout;
3522
}
3623

37-
interface Log4JSEmitAppenderConfiguration
38-
extends Log4JSAppenderConfiguration {
24+
interface Log4JSEmitAppenderConfiguration extends Log4JSAppenderConfiguration {
3925
emitter: EventEmitter;
4026
}
4127
}

lib/common/definitions/mobile.d.ts

Lines changed: 2 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
IHasEmulatorOption,
1212
IDisposable,
1313
} from "../declarations";
14+
import type { DevicesService } from "../../contracts/devices-service";
1415

1516
declare global {
1617
export module Mobile {
@@ -587,107 +588,7 @@ declare global {
587588
[platform: string]: string;
588589
}
589590

590-
interface IDevicesService extends NodeJS.EventEmitter, IPlatform {
591-
hasDevices: boolean;
592-
deviceCount: number;
593-
594-
execute<T>(
595-
action: (device: Mobile.IDevice) => Promise<T>,
596-
canExecute?: (dev: Mobile.IDevice) => boolean,
597-
options?: { allowNoDevices?: boolean },
598-
): Promise<IDeviceActionResult<T>[]>;
599-
600-
/**
601-
* Initializes DevicesService, so after that device operations could be executed.
602-
* @param {IDevicesServicesInitializationOptions} data Defines the options which will be used for whole devicesService.
603-
* @return {Promise<void>}
604-
*/
605-
initialize(data?: IDevicesServicesInitializationOptions): Promise<void>;
606-
607-
/**
608-
* Add an IDeviceDiscovery instance which will from now on report devices. The instance should implement IDeviceDiscovery and raise "deviceFound" and "deviceLost" events.
609-
* @param {IDeviceDiscovery} deviceDiscovery Instance, implementing IDeviceDiscovery and raising raise "deviceFound" and "deviceLost" events.
610-
* @return {void}
611-
*/
612-
addDeviceDiscovery(deviceDiscovery: IDeviceDiscovery): void;
613-
getDevices(): Mobile.IDeviceInfo[];
614-
615-
/**
616-
* Gets device instance by specified identifier or number.
617-
* @param {string} deviceOption The specified device identifier or number.
618-
* @returns {Promise<Mobile.IDevice>} Instance of IDevice.
619-
*/
620-
getDevice(deviceOption: string): Promise<Mobile.IDevice>;
621-
getDevicesForPlatform(platform: string): Mobile.IDevice[];
622-
getDeviceInstances(): Mobile.IDevice[];
623-
getDeviceByDeviceOption(): Mobile.IDevice;
624-
isAndroidDevice(device: Mobile.IDevice): boolean;
625-
isiOSDevice(device: Mobile.IDevice): boolean;
626-
isiOSSimulator(device: Mobile.IDevice): boolean;
627-
isOnlyiOSSimultorRunning(): boolean;
628-
isAppInstalledOnDevices(
629-
deviceIdentifiers: string[],
630-
appIdentifier: string,
631-
framework: string,
632-
projectDir: string,
633-
): Promise<IAppInstalledInfo>[];
634-
setLogLevel(logLevel: string, deviceIdentifier?: string): void;
635-
deployOnDevices(
636-
deviceIdentifiers: string[],
637-
packageFile: string,
638-
packageName: string,
639-
framework: string,
640-
projectDir: string,
641-
): Promise<void>[];
642-
getDeviceByIdentifier(identifier: string): Mobile.IDevice;
643-
mapAbstractToTcpPort(
644-
deviceIdentifier: string,
645-
appIdentifier: string,
646-
framework: string,
647-
): Promise<string>;
648-
getDebuggableApps(
649-
deviceIdentifiers: string[],
650-
): Promise<Mobile.IDeviceApplicationInformation[]>[];
651-
getDebuggableViews(
652-
deviceIdentifier: string,
653-
appIdentifier: string,
654-
): Promise<Mobile.IDebugWebViewInfo[]>;
655-
656-
/**
657-
* Returns all applications installed on the specified device.
658-
* @param {string} deviceIdentifer The identifier of the device for which to get installed applications.
659-
* @returns {Promise<string[]>} Array of all application identifiers of the apps installed on device.
660-
*/
661-
getInstalledApplications(deviceIdentifier: string): Promise<string[]>;
662-
663-
/**
664-
* Returns all available iOS and/or Android emulators.
665-
* @param options The options that can be passed to filter the result.
666-
* @returns {Promise<Mobile.IListEmulatorsOutput>} Dictionary with the following format: { ios: { devices: Mobile.IDeviceInfo[], errors: string[] }, android: { devices: Mobile.IDeviceInfo[], errors: string[]}}.
667-
*/
668-
getEmulatorImages(
669-
options?: Mobile.IListEmulatorsOptions,
670-
): Promise<Mobile.IListEmulatorsOutput>;
671-
672-
/**
673-
* Starts an emulator by provided options.
674-
* @param options
675-
* @returns {Promise<string[]>} - Returns array of errors.
676-
*/
677-
startEmulator(options?: IStartEmulatorOptions): Promise<string[]>;
678-
679-
/**
680-
* Returns a single device based on the specified options. If more than one devices are matching,
681-
* prompts the user for a manual choice or returns the first one for non interactive terminals.
682-
*/
683-
pickSingleDevice(
684-
options: IPickSingleDeviceOptions,
685-
): Promise<Mobile.IDevice>;
686-
687-
getPlatformsFromDeviceDescriptors(
688-
deviceDescriptors: ILiveSyncDeviceDescriptor[],
689-
): string[];
690-
}
591+
interface IDevicesService extends DevicesService {}
691592

692593
interface IPickSingleDeviceOptions {
693594
/**

lib/declarations.d.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "./common/declarations";
2020
import { IExtensionData } from "./common/definitions/extensibility";
2121
import { IApplePortalUserDetail } from "./services/apple-portal/definitions";
22+
import type { PackageManager } from "./contracts/package-manager";
2223

2324
interface INodePackageManager {
2425
/**
@@ -108,21 +109,7 @@ interface INodePackageManager {
108109
getCachePath(): Promise<string>;
109110
}
110111

111-
interface IPackageManager extends INodePackageManager {
112-
/**
113-
* Gets the name of the package manager used for the current process.
114-
* It can be read from the user settings or by passing -- option.
115-
*/
116-
getPackageManagerName(): Promise<string>;
117-
118-
/**
119-
* Gets the version corresponding to the tag for the package
120-
* @param {string} packageName The name of the package.
121-
* @param {string} tag The tag which we need the version of.
122-
* @returns {string} The version corresponding to the tag
123-
*/
124-
getTagVersion(packageName: string, tag: string): Promise<string>;
125-
}
112+
interface IPackageManager extends PackageManager {}
126113

127114
interface IPerformanceService {
128115
// Will process the data based on the command options (--performance flag and user-reporting setting)

lib/definitions/project.d.ts

Lines changed: 4 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
} from "../common/declarations";
1919
import { SupportedConfigValues } from "../tools/config-manipulation/config-transformer";
2020
import * as constants from "../constants";
21+
import type { ProjectData } from "../contracts/project-data";
22+
import type { ProjectDataService } from "../contracts/project-data-service";
2123

2224
interface IProjectName {
2325
/**
@@ -209,165 +211,9 @@ interface INsConfig {
209211
buildPath?: string;
210212
}
211213

212-
interface IProjectData extends ICreateProjectData {
213-
platformsDir: string;
214-
projectFilePath: string;
215-
projectId: string;
216-
projectIdentifiers?: Mobile.IProjectIdentifier;
217-
dependencies: any;
218-
ignoredDependencies?: string[];
219-
devDependencies: IStringDictionary;
220-
appDirectoryPath: string;
221-
appResourcesDirectoryPath: string;
222-
projectType: string;
223-
packageJsonData: any;
224-
nsConfig: INsConfig;
225-
androidManifestPath: string;
226-
appGradlePath: string;
227-
gradleFilesDirectoryPath: string;
228-
infoPlistPath: string;
229-
buildXcconfigPath: string;
230-
podfilePath: string;
231-
initialized?: boolean;
232-
/**
233-
* Defines if the project is a code sharing one.
234-
* Value is true when project has nativescript.config and it has `shared: true` in it.
235-
*/
236-
isShared: boolean;
237-
/**
238-
* Specifies the bundler used to build the application.
239-
*
240-
* - `"webpack"`: Uses Webpack for traditional bundling.
241-
* - `"rspack"`: Uses Rspack for fast bundling.
242-
* - `"vite"`: Uses Vite for fast bundling.
243-
*
244-
* @default "webpack"
245-
*/
246-
bundler: BundlerType;
247-
/**
248-
* @deprecated Use bundlerConfigPath
249-
* Defines the path to the configuration file passed to webpack process.
250-
* By default this is the webpack.config.js at the root of the application.
251-
* The value can be changed by setting `webpackConfigPath` in nativescript.config.
252-
*/
253-
webpackConfigPath: string;
254-
/**
255-
* Defines the path to the bundler configuration file passed to the compiler.
256-
* The value can be changed by setting `bundlerConfigPath` in nativescript.config.
257-
*/
258-
bundlerConfigPath: string;
259-
projectName: string;
260-
261-
/**
262-
* Initializes project data with the given project directory. If none supplied defaults to --path option or cwd.
263-
* @param {string} projectDir Project root directory.
264-
* @returns {void}
265-
*/
266-
initializeProjectData(projectDir?: string): void;
267-
initializeProjectDataFromContent(
268-
packageJsonContent: string,
269-
projectDir?: string,
270-
): void;
271-
getAppDirectoryPath(projectDir?: string): string;
272-
getAppDirectoryRelativePath(): string;
273-
getAppResourcesDirectoryPath(projectDir?: string): string;
274-
getAppResourcesRelativeDirectoryPath(): string;
275-
}
276-
277-
interface IProjectDataService {
278-
/**
279-
* Returns a value from `nativescript` key in project's package.json.
280-
* @param {string} projectDir The project directory - the place where the root package.json is located.
281-
* @param {string} propertyName The name of the property to be checked in `nativescript` key.
282-
* @returns {any} The value of the property.
283-
*/
284-
getNSValue(projectDir: string, propertyName: string): any;
285-
286-
/**
287-
* Sets a value in the `nativescript` key in a project's package.json.
288-
* @param {string} projectDir The project directory - the place where the root package.json is located.
289-
* @param {string} key Key to be added to `nativescript` key in project's package.json.
290-
* @param {any} value Value of the key to be added to `nativescript` key in project's package.json.
291-
* @returns {void}
292-
*/
293-
setNSValue(projectDir: string, key: string, value: any): void;
294-
295-
/**
296-
* Removes a property from `nativescript` key in project's package.json.
297-
* @param {string} projectDir The project directory - the place where the root package.json is located.
298-
* @param {string} propertyName The name of the property to be removed from `nativescript` key.
299-
* @returns {void}
300-
*/
301-
removeNSProperty(projectDir: string, propertyName: string): void;
302-
303-
/**
304-
* Removes a property from `nativescript.config`.
305-
* @param {string} projectDir The project directory - the place where the `nativescript.config` is located.
306-
* @param {string} propertyName The name of the property to be removed.
307-
* @returns {void}
308-
*/
309-
removeNSConfigProperty(projectDir: string, propertyName: string): void;
214+
interface IProjectData extends ProjectData {}
310215

311-
/**
312-
* Removes dependency from package.json
313-
* @param {string} projectDir The project directory - the place where the root package.json is located.
314-
* @param {string} dependencyName Name of the dependency that has to be removed.
315-
* @returns {void}
316-
*/
317-
removeDependency(projectDir: string, dependencyName: string): void;
318-
319-
getProjectData(projectDir?: string): IProjectData;
320-
321-
/**
322-
* Gives information about the whole assets structure for both iOS and Android.
323-
* For each of the platforms, the returned object will contain icons, splashBackgrounds, splashCenterImages and splashImages (only for iOS).
324-
* @param {IProjectDir} opts Object with a single property - projectDir. This is the root directory where NativeScript project is located.
325-
* @returns {Promise<IAssetsStructure>} An object describing the current asset structure.
326-
*/
327-
getAssetsStructure(opts: IProjectDir): Promise<IAssetsStructure>;
328-
329-
/**
330-
* Gives information about the whole assets structure for iOS.
331-
* The returned object will contain icons, splashBackgrounds, splashCenterImages and splashImages.
332-
* @param {IProjectDir} opts Object with a single property - projectDir. This is the root directory where NativeScript project is located.
333-
* @returns {Promise<IAssetGroup>} An object describing the current asset structure for iOS.
334-
*/
335-
getIOSAssetsStructure(opts: IProjectDir): Promise<IAssetGroup>;
336-
337-
/**
338-
* Gives information about the whole assets structure for Android.
339-
* The returned object will contain icons, splashBackgrounds and splashCenterImages.
340-
* @param {IProjectDir} opts Object with a single property - projectDir. This is the root directory where NativeScript project is located.
341-
* @returns {Promise<IAssetGroup>} An object describing the current asset structure for Android.
342-
*/
343-
getAndroidAssetsStructure(opts: IProjectDir): Promise<IAssetGroup>;
344-
345-
/**
346-
* Returns array with paths to all `.js` or `.ts` files in application's app directory.
347-
* @param {string} projectDir Path to application.
348-
* @returns {string[]} Array of paths to `.js` or `.ts` files.
349-
*/
350-
getAppExecutableFiles(projectDir: string): string[];
351-
352-
/**
353-
* Returns package details for runtime, respecting the nativescript key for legacy projects
354-
* @param {string} projectDir Path to application.
355-
* @param {string} platform Platform key
356-
*/
357-
getRuntimePackage(
358-
projectDir: string,
359-
platform: SupportedPlatform,
360-
): IBasePluginData;
361-
362-
/**
363-
* Returns a value from `nativescript` key in project's package.json.
364-
* @param {string} jsonData The project directory - the place where the root package.json is located.
365-
* @param {string} propertyName The name of the property to be checked in `nativescript` key.
366-
* @returns {any} The value of the property.
367-
* @deprecated no longer used - will be removed in 8.0.
368-
*/
369-
getNSValueFromContent(jsonData: Object, propertyName: string): any;
370-
}
216+
interface IProjectDataService extends ProjectDataService {}
371217

372218
interface IProjectCleanupService {
373219
/**

lib/definitions/prompter.d.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
1-
import {
2-
IPrompterOptions,
3-
IAllowEmpty,
4-
IDisposable,
5-
IPrompterQuestion,
6-
} from "../common/declarations";
1+
import type { Prompter } from "../contracts/prompter";
72

83
declare global {
9-
interface IPrompter extends IDisposable {
10-
get(schemas: IPrompterQuestion[]): Promise<any>;
11-
getPassword(prompt: string, options?: IAllowEmpty): Promise<string>;
12-
getString(prompt: string, options?: IPrompterOptions): Promise<string>;
13-
promptForChoice(
14-
promptMessage: string,
15-
choices:
16-
| string[]
17-
| { title: string; description?: string; value?: string }[],
18-
multiple: boolean = false,
19-
options: any = {}
20-
): Promise<string>;
21-
promptForDetailedChoice(
22-
promptMessage: string,
23-
choices: { key: string; description: string }[]
24-
): Promise<string>;
25-
confirm(prompt: string, defaultAction?: () => boolean): Promise<boolean>;
26-
}
4+
interface IPrompter extends Prompter {}
275
}

0 commit comments

Comments
 (0)