Skip to content

Commit 00b53f5

Browse files
committed
fix: platform add should not return null paths
1 parent 49b26df commit 00b53f5

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

lib/services/platform/add-platform-service.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { IPackageManager } from "../../declarations";
1818
export class AddPlatformService implements IAddPlatformService {
1919
constructor(
2020
private $fs: IFileSystem,
21+
private $logger: ILogger,
2122
// private $pacoteService: IPacoteService,
2223
// private $projectDataService: IProjectDataService,
2324
private $packageManager: IPackageManager,
@@ -121,10 +122,10 @@ export class AddPlatformService implements IAddPlatformService {
121122
);
122123

123124
if (!installedPackage.name) {
124-
return null;
125+
return "";
125126
}
126127

127-
return this.resolveFrameworkDir(projectDir, installedPackage.name);
128+
return this.resolveFrameworkDir(projectDir, installedPackage.name) || "";
128129
}
129130

130131
private resolveFrameworkDir(projectDir: string, packageName: string): string {
@@ -137,10 +138,15 @@ export class AddPlatformService implements IAddPlatformService {
137138
})
138139
.replace("package.json", PROJECT_FRAMEWORK_FOLDER_NAME);
139140

140-
return path.resolve(frameworkDir);
141+
if (frameworkDir) {
142+
return path.resolve(frameworkDir);
143+
}
141144
} catch (err) {
142-
return null;
145+
this.$logger.trace(
146+
`Couldn't resolve installed framework. Continuing with install...`
147+
);
143148
}
149+
return null;
144150
}
145151

146152
@performanceLog()

test/services/platform/add-platform-service.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
InjectorStub,
3-
TempServiceStub,
4-
PackageInstallationManagerStub,
5-
} from "../../stubs";
1+
import * as stubs from "../../stubs";
62
import { AddPlatformService } from "../../../lib/services/platform/add-platform-service";
73
import { assert } from "chai";
84
import * as _ from "lodash";
@@ -13,7 +9,7 @@ import { IInjector } from "../../../lib/common/definitions/yok";
139
const nativePrepare: INativePrepare = null;
1410

1511
function createTestInjector() {
16-
const injector = new InjectorStub();
12+
const injector = new stubs.InjectorStub();
1713
injector.register("pacoteService", {
1814
extractPackage: async (name: string) => ({}),
1915
});
@@ -25,12 +21,12 @@ function createTestInjector() {
2521
};
2622
},
2723
});
28-
injector.register("packageManager", PackageInstallationManagerStub);
24+
injector.register("packageManager", stubs.NodePackageManagerStub);
2925
injector.register("addPlatformService", AddPlatformService);
3026
injector.register("analyticsService", {
3127
trackEventActionInGoogleAnalytics: () => ({}),
3228
});
33-
injector.register("tempService", TempServiceStub);
29+
injector.register("tempService", stubs.TempServiceStub);
3430

3531
const fs = injector.resolve("fs");
3632
fs.exists = () => false;

test/stubs.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ export class NodePackageManagerStub implements INodePackageManager {
443443
pathToSave: string,
444444
config: INodePackageManagerInstallOptions
445445
): Promise<INpmInstallResultInfo> {
446-
return null;
446+
return {
447+
name: packageName,
448+
version: "latest",
449+
};
447450
}
448451

449452
public async uninstall(

0 commit comments

Comments
 (0)