Skip to content

Commit 49b26df

Browse files
committed
fix: don't force install runtime if it's already installed
1 parent ebdedc1 commit 49b26df

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

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

+25-9
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,16 @@ export class AddPlatformService implements IAddPlatformService {
101101

102102
private async installPackage(
103103
projectDir: string,
104-
pkg: string
104+
packageName: string
105105
): Promise<string> {
106+
const frameworkDir = this.resolveFrameworkDir(projectDir, packageName);
107+
if (frameworkDir && this.$fs.exists(frameworkDir)) {
108+
// don't install if it's already installed
109+
return frameworkDir;
110+
}
111+
106112
const installedPackage = await this.$packageManager.install(
107-
pkg,
113+
packageName,
108114
projectDir,
109115
{
110116
silent: true,
@@ -115,16 +121,26 @@ export class AddPlatformService implements IAddPlatformService {
115121
);
116122

117123
if (!installedPackage.name) {
118-
return "";
124+
return null;
119125
}
120126

121-
const frameworkDir = require
122-
.resolve(`${installedPackage.name}/package.json`, {
123-
paths: [projectDir],
124-
})
125-
.replace("package.json", PROJECT_FRAMEWORK_FOLDER_NAME);
127+
return this.resolveFrameworkDir(projectDir, installedPackage.name);
128+
}
126129

127-
return path.resolve(frameworkDir);
130+
private resolveFrameworkDir(projectDir: string, packageName: string): string {
131+
try {
132+
// strip version info if present <package>@1.2.3 -> <package>
133+
packageName = packageName.replace(/@[\d.]+$/g, "");
134+
const frameworkDir = require
135+
.resolve(`${packageName}/package.json`, {
136+
paths: [projectDir],
137+
})
138+
.replace("package.json", PROJECT_FRAMEWORK_FOLDER_NAME);
139+
140+
return path.resolve(frameworkDir);
141+
} catch (err) {
142+
return null;
143+
}
128144
}
129145

130146
@performanceLog()

0 commit comments

Comments
 (0)