Skip to content

feat(config): cli.packageManager override support #5596

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

Merged
merged 2 commits into from
Oct 20, 2021
Merged
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
2 changes: 1 addition & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ interface IProjectConfigService {
* Get value for a given config key path
* @param key the property key path
*/
getValue(key: string): any;
getValue(key: string, defaultValue?: any): any;
/**
* Set value for a given config key path
* @param key the property key path
Expand Down
23 changes: 22 additions & 1 deletion lib/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
IDictionary,
} 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 All @@ -27,7 +28,8 @@ export class PackageManager implements IPackageManager {
private $yarn: INodePackageManager,
private $pnpm: INodePackageManager,
private $logger: ILogger,
private $userSettingsService: IUserSettingsService
private $userSettingsService: IUserSettingsService,
private $projectConfigService: IProjectConfigService
) {}

@cache()
Expand Down Expand Up @@ -140,6 +142,25 @@ export class PackageManager implements IPackageManager {
);
}

try {
const configPm = this.$projectConfigService.getValue(
"cli.packageManager"
);

if (configPm) {
this.$logger.trace(
`Determined packageManager to use from user config is: ${configPm}`
);
pm = configPm;
}
} catch (err) {
// ignore error, but log info
this.$logger.trace(
"Tried to read cli.packageManager from project config and failed. Error is: ",
err
);
}

if (pm === PackageManagers.yarn || this.$options.yarn) {
this._packageManagerName = PackageManagers.yarn;
return this.$yarn;
Expand Down
2 changes: 2 additions & 0 deletions test/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
ProjectDataStub,
TempServiceStub,
ProjectDataServiceStub,
ProjectConfigServiceStub,
} from "./stubs";
import { xcode } from "../lib/node/xcode";
import temp = require("temp");
Expand Down Expand Up @@ -172,6 +173,7 @@ function createTestInjector(
getSettingValue: async (settingName: string): Promise<void> => undefined,
});
testInjector.register("packageManager", PackageManager);
testInjector.register("projectConfigService", ProjectConfigServiceStub);
testInjector.register("npm", NodePackageManager);
testInjector.register("yarn", YarnPackageManager);
testInjector.register("xcconfigService", XcconfigService);
Expand Down
3 changes: 2 additions & 1 deletion test/package-installation-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as yok from "../lib/common/yok";
import ChildProcessLib = require("../lib/common/child-process");
import { SettingsService } from "../lib/common/test/unit-tests/stubs";
import { ProjectDataService } from "../lib/services/project-data-service";
import { ProjectDataStub } from "./stubs";
import { ProjectConfigServiceStub, ProjectDataStub } from "./stubs";
import { IInjector } from "../lib/common/definitions/yok";
import * as _ from "lodash";
import { IDictionary } from "../lib/common/declarations";
Expand Down Expand Up @@ -48,6 +48,7 @@ function createTestInjector(): IInjector {
testInjector.register("yarn", YarnLib.YarnPackageManager);
testInjector.register("pnpm", PnpmLib.PnpmPackageManager);
testInjector.register("packageManager", PackageManagerLib.PackageManager);
testInjector.register("projectConfigService", ProjectConfigServiceStub);
testInjector.register(
"packageInstallationManager",
PackageInstallationManagerLib.PackageInstallationManager
Expand Down
4 changes: 4 additions & 0 deletions test/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ function createTestInjector() {
getSettingValue: async (settingName: string): Promise<void> => undefined,
});
testInjector.register("packageManager", PackageManager);
testInjector.register(
"projectConfigService",
stubs.PackageInstallationManagerStub
);
testInjector.register("npm", NodePackageManager);
testInjector.register("yarn", YarnPackageManager);
testInjector.register("pnpm", PnpmPackageManager);
Expand Down
4 changes: 4 additions & 0 deletions test/services/extensibility-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ describe("extensibilityService", () => {
testInjector.register("hostInfo", HostInfo);
testInjector.register("httpClient", {});
testInjector.register("packageManager", PackageManager);
testInjector.register(
"projectConfigService",
stubs.ProjectConfigServiceStub
);
testInjector.register("options", {});
testInjector.register("pacoteService", {
manifest: async (
Expand Down