Skip to content

Commit da64cf8

Browse files
Fix passing relative path for profileDir when extensions are used (#3201)
Installing and loading extensions is based on the `--profileDir` value. In case a relative path is passed, the extensions cannot be loaded as the resolve is not correct. Resolve the full path, so the loading will work correctly.
1 parent c1e2ce7 commit da64cf8

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/services/extensibility-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as constants from "../constants";
44

55
export class ExtensibilityService implements IExtensibilityService {
66
private get pathToExtensions(): string {
7-
return path.join(this.$options.profileDir, "extensions");
7+
return path.join(path.resolve(this.$options.profileDir), "extensions");
88
}
99

1010
private get pathToPackageJson(): string {

test/services/extensibility-service.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ import { Yok } from "../../lib/common/yok";
33
import * as stubs from "../stubs";
44
import { assert } from "chai";
55
import * as constants from "../../lib/constants";
6-
import * as path from "path";
6+
const path = require("path");
7+
const originalResolve = path.resolve;
78

89
describe("extensibilityService", () => {
10+
before(() => {
11+
path.resolve = (p: string) => p;
12+
});
13+
14+
after(() => {
15+
path.resolve = originalResolve;
16+
});
17+
918
const getTestInjector = (): IInjector => {
1019
const testInjector = new Yok();
1120
testInjector.register("fs", {});
@@ -450,7 +459,7 @@ describe("extensibilityService", () => {
450459
const fs: IFileSystem = testInjector.resolve("fs");
451460
fs.exists = (pathToCheck: string): boolean => true;
452461
const npm: INodePackageManager = testInjector.resolve("npm");
453-
npm.uninstall = async (packageName: string, config?: any, path?: string): Promise<any> => {
462+
npm.uninstall = async (packageName: string, config?: any, p?: string): Promise<any> => {
454463
throw new Error(expectedErrorMessage);
455464
};
456465

@@ -469,9 +478,9 @@ describe("extensibilityService", () => {
469478

470479
const npm: INodePackageManager = testInjector.resolve("npm");
471480
const argsPassedToNpmInstall: any = {};
472-
npm.uninstall = async (packageName: string, config?: any, path?: string): Promise<any> => {
481+
npm.uninstall = async (packageName: string, config?: any, p?: string): Promise<any> => {
473482
argsPassedToNpmInstall.packageName = packageName;
474-
argsPassedToNpmInstall.pathToSave = path;
483+
argsPassedToNpmInstall.pathToSave = p;
475484
argsPassedToNpmInstall.config = config;
476485
return [userSpecifiedValue];
477486
};
@@ -523,7 +532,7 @@ describe("extensibilityService", () => {
523532
fs.readDirectory = (dir: string): string[] => [extensionName];
524533

525534
const npm: INodePackageManager = testInjector.resolve("npm");
526-
npm.uninstall = async (packageName: string, config?: any, path?: string): Promise<any> => [extensionName];
535+
npm.uninstall = async (packageName: string, config?: any, p?: string): Promise<any> => [extensionName];
527536

528537
const extensibilityService: IExtensibilityService = testInjector.resolve(ExtensibilityService);
529538
await extensibilityService.uninstallExtension(extensionName);

0 commit comments

Comments
 (0)