Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move package managers into a dir #5379

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ injector.require(

injector.requireCommand("setup|*", "./commands/setup");

injector.requirePublic("packageManager", "./package-manager");
injector.requirePublic("npm", "./node-package-manager");
injector.requirePublic("yarn", "./yarn-package-manager");
injector.requirePublic("pnpm", "./pnpm-package-manager");
injector.requirePublic("packageManager", "./package-managers/index");
injector.requirePublic("npm", "./package-managers/npm");
injector.requirePublic("pnpm", "./package-managers/pnpm");
injector.requirePublic("yarn", "./package-managers/yarn");
injector.requireCommand(
"package-manager|*get",
"./commands/package-manager-get"
Expand All @@ -230,7 +230,7 @@ injector.requireCommand(

injector.require(
"packageInstallationManager",
"./package-installation-manager"
"./package-managers/package-installation-manager"
);

injector.require("deviceLogProvider", "./common/mobile/device-log-provider");
Expand Down
4 changes: 1 addition & 3 deletions lib/common/mobile/application-manager-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ export abstract class ApplicationManagerBase
appIdentifier?: string,
buildData?: IBuildData
): Promise<void>;
public abstract uninstallApplication(
appIdentifier: string
): Promise<void>;
public abstract uninstallApplication(appIdentifier: string): Promise<void>;
public abstract startApplication(
appData: Mobile.IApplicationData
): Promise<void>;
Expand Down
4 changes: 1 addition & 3 deletions lib/common/mobile/ios/ios-device-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
}, `ios-debug-socket-${this.deviceInfo.identifier}-${appId}.lock`);
}

protected abstract getDebugSocketCore(
appId: string
): Promise<net.Socket>;
protected abstract getDebugSocketCore(appId: string): Promise<net.Socket>;

protected async attachToDebuggerFoundEvent(
appId: string,
Expand Down
2 changes: 1 addition & 1 deletion lib/common/mobile/ios/simulator/ios-simulator-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class IOSSimulator extends IOSDeviceBase implements Mobile.IiOSDevice {
.catch((e) => this.$logger.error(e));
}, 5e3);

// the internal retry-mechanism of getDebuggerPort will ensure the above
// the internal retry-mechanism of getDebuggerPort will ensure the above
// interval has a chance to execute multiple times
const port = await super.getDebuggerPort(appId).finally(() => {
clearInterval(postNotificationRetryInterval);
Expand Down
6 changes: 4 additions & 2 deletions lib/common/services/hooks-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,10 @@ export class HooksService implements IHooksService {

private getCustomHooksByName(hookName: string): IHook[] {
const hooks: IHook[] = [];
const customHooks: INsConfigHooks[] =
this.$projectConfigService.getValue("hooks", []);
const customHooks: INsConfigHooks[] = this.$projectConfigService.getValue(
"hooks",
[]
);

for (const cHook of customHooks) {
if (cHook.type === hookName) {
Expand Down
4 changes: 2 additions & 2 deletions lib/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as helpers from "./common/helpers";
import * as yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import * as yargs from "yargs";
import { hideBin } from "yargs/helpers";
import * as _ from "lodash";
import {
IDictionary,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { isInteractive } from "./common/helpers";
import { isInteractive } from "../common/helpers";
import {
INodePackageManager,
INodePackageManagerInstallOptions,
INpmInstallResultInfo,
INpmsResult,
INpmPackageNameParts,
} from "./declarations";
} from "../declarations";
import {
IDictionary,
IChildProcess,
IFileSystem,
IHostInfo,
} from "./common/declarations";
} from "../common/declarations";

export abstract class BasePackageManager implements INodePackageManager {
public abstract install(
Expand Down
75 changes: 75 additions & 0 deletions lib/package-managers/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// This is a WIP declaration file and it is not being used yet

interface IPackageJSON {
name?: string;
version?: string;
dependencies?: any;
devDependencies?: any;

[key: string]: any;
}

interface IPackageInfo {
name: string;
version: string;
}

/**
* A package identifier can be any of the following:
* - <package name>
* - <package name>@<version>
* - <package name>@<version range>
* - <package name>@<tag>
* - <git repo url>
* - <tarball url>
* - <tarball file>
* - <folder>
*/
type IPackageIdentifier = string;

interface IPackageManagerOptions {
projectPath?: string;
}
interface IPackageManagerAddOptions extends IPackageManagerOptions {
version?: string;
exact?: boolean;
scripts?: boolean;

// these 3 are shared with the remove options, however
// they are duplicated as they don't quite make sense
// to be added to IPackageManagerOptions as they are
// specific to add and remove operations
save?: boolean;
dev?: boolean;
optional?: boolean;
}
interface IPackageManagerRemoveOptions extends IPackageManagerOptions {
save?: boolean;
dev?: boolean;
optional?: boolean;
}

interface IPackageManager {
add(
packageIdentifier: IPackageIdentifier,
options?: IPackageManagerAddOptions
): Promise<IPackageInfo>;
install(
packageIdentifier: IPackageIdentifier,
options?: IPackageManagerAddOptions
): Promise<IPackageInfo>;

remove(
packageIdentifier: IPackageIdentifier,
options?: IPackageManagerRemoveOptions
): Promise<IPackageInfo>;
uninstall(
packageIdentifier: IPackageIdentifier,
options?: IPackageManagerRemoveOptions
): Promise<IPackageInfo>;

getInstalledPackage(
packageIdentifier: IPackageIdentifier
): Promise<IPackageInfo>;
getPackageJson(packageIdentifier: IPackageIdentifier): Promise<IPackageJSON>;
}
18 changes: 11 additions & 7 deletions lib/package-manager.ts → lib/package-managers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cache, exported, invokeInit } from "./common/decorators";
import { performanceLog } from "./common/decorators";
import { PackageManagers } from "./constants";
import { cache, exported, invokeInit } from "../common/decorators";
import { performanceLog } from "../common/decorators";
import { PackageManagers } from "../constants";
import {
IPackageManager,
INodePackageManager,
Expand All @@ -9,14 +9,14 @@ import {
INpmInstallResultInfo,
INpmsResult,
INpmPackageNameParts,
} from "./declarations";
} from "../declarations";
import {
IErrors,
IUserSettingsService,
IDictionary,
} from "./common/declarations";
import { injector } from "./common/yok";
import { IProjectConfigService } from "./definitions/project";
} from "../common/declarations";
import { injector } from "../common/yok";
import { IProjectConfigService } from "../definitions/project";
export class PackageManager implements IPackageManager {
private packageManager: INodePackageManager;
private _packageManagerName: string;
Expand Down Expand Up @@ -174,4 +174,8 @@ export class PackageManager implements IPackageManager {
}
}

// export { NPM } from './npm'
// export { PNPM } from './pnpm'
// export { Yarn } from './yarn'

injector.register("packageManager", PackageManager);
14 changes: 7 additions & 7 deletions lib/node-package-manager.ts → lib/package-managers/npm.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { join, relative } from "path";
import { BasePackageManager } from "./base-package-manager";
import { exported, cache } from "./common/decorators";
import { CACACHE_DIRECTORY_NAME } from "./constants";
import { exported, cache } from "../common/decorators";
import { CACACHE_DIRECTORY_NAME } from "../constants";
import * as _ from "lodash";
import {
INodePackageManagerInstallOptions,
INpmInstallResultInfo,
INpmsResult,
} from "./declarations";
} from "../declarations";
import {
IChildProcess,
IErrors,
IFileSystem,
IHostInfo,
Server,
} from "./common/declarations";
import { injector } from "./common/yok";
} from "../common/declarations";
import { injector } from "../common/yok";

export class NodePackageManager extends BasePackageManager {
export class NPM extends BasePackageManager {
constructor(
$childProcess: IChildProcess,
private $errors: IErrors,
Expand Down Expand Up @@ -172,4 +172,4 @@ export class NodePackageManager extends BasePackageManager {
}
}

injector.register("npm", NodePackageManager);
injector.register("npm", NPM);
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as path from "path";
import * as constants from "./constants";
import * as constants from "../constants";
import {
INpmInstallOptions,
INpmInstallResultInfo,
IPackageInstallationManager,
IPackageManager,
IStaticConfig,
} from "./declarations";
import { IProjectDataService } from "./definitions/project";
} from "../declarations";
import { IProjectDataService } from "../definitions/project";
import {
IChildProcess,
IDictionary,
IFileSystem,
ISettingsService,
} from "./common/declarations";
import { injector } from "./common/yok";
} from "../common/declarations";
import { injector } from "../common/yok";

const semver = require("semver");

Expand Down
14 changes: 7 additions & 7 deletions lib/pnpm-package-manager.ts → lib/package-managers/pnpm.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import * as path from "path";
import * as _ from "lodash";
import { BasePackageManager } from "./base-package-manager";
import { exported } from "./common/decorators";
import { CACACHE_DIRECTORY_NAME } from "./constants";
import { exported } from "../common/decorators";
import { CACACHE_DIRECTORY_NAME } from "../constants";
import {
INodePackageManagerInstallOptions,
INpmInstallResultInfo,
INpmsResult,
} from "./declarations";
} from "../declarations";
import {
IChildProcess,
IErrors,
IFileSystem,
IHostInfo,
Server,
IDictionary,
} from "./common/declarations";
import { injector } from "./common/yok";
} from "../common/declarations";
import { injector } from "../common/yok";

export class PnpmPackageManager extends BasePackageManager {
export class PNPM extends BasePackageManager {
constructor(
$childProcess: IChildProcess,
private $errors: IErrors,
Expand Down Expand Up @@ -149,4 +149,4 @@ export class PnpmPackageManager extends BasePackageManager {
}
}

injector.register("pnpm", PnpmPackageManager);
injector.register("pnpm", PNPM);
12 changes: 6 additions & 6 deletions lib/yarn-package-manager.ts → lib/package-managers/yarn.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import * as path from "path";
import * as _ from "lodash";
import { BasePackageManager } from "./base-package-manager";
import { exported } from "./common/decorators";
import { exported } from "../common/decorators";
import {
INodePackageManagerInstallOptions,
INpmInstallResultInfo,
INpmsResult,
} from "./declarations";
} from "../declarations";
import {
IChildProcess,
IErrors,
IFileSystem,
IHostInfo,
Server,
IDictionary,
} from "./common/declarations";
import { injector } from "./common/yok";
} from "../common/declarations";
import { injector } from "../common/yok";

export class YarnPackageManager extends BasePackageManager {
export class Yarn extends BasePackageManager {
constructor(
$childProcess: IChildProcess,
private $errors: IErrors,
Expand Down Expand Up @@ -147,4 +147,4 @@ export class YarnPackageManager extends BasePackageManager {
}
}

injector.register("yarn", YarnPackageManager);
injector.register("yarn", Yarn);
3 changes: 2 additions & 1 deletion lib/tools/node-modules/node-modules-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
projectData,
}: IPrepareNodeModulesData): Promise<void> {
let dependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(
projectData.projectDir, projectData.ignoredDependencies
projectData.projectDir,
projectData.ignoredDependencies
);
dependencies = await platformData.platformProjectService.beforePrepareAllPlugins(
projectData,
Expand Down
Loading