Skip to content

Commit f741205

Browse files
committed
fix(core): fix pkg install vesion mismatch
1 parent e7d2d60 commit f741205

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

packages/framework-core/src/plugin-manager/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,16 @@ export default class PluginManager {
6060
*/
6161
async init(id?: string) {
6262
try {
63-
await spawnPromise("npm ls", ["--depth=0"], {
64-
cwd: this.pluginRegistry,
65-
});
63+
await this.pluginInstallPromise;
64+
this.context.logger.debug(
65+
"插件版本信息",
66+
JSON.parse(
67+
(await spawnPromise("npm ls", ["--depth=0", "--json"], {
68+
cwd: this.pluginRegistry,
69+
stdio: "pipe",
70+
})) as string
71+
)
72+
);
6673
} catch (e) {
6774
this.context.logger.debug(e);
6875
}
@@ -265,11 +272,9 @@ export default class PluginManager {
265272
const packageInfo = this.plugins.reduce((prev, curr) => {
266273
let version = "latest";
267274

268-
// 官方插件的版本,跟内核版本小版本相同
275+
// 官方插件的版本,跟内核版本相同
269276
if (curr.name.match(/^@cloudbase/)) {
270-
version =
271-
"~" +
272-
(corePackageInfo as any).version.split(".").splice(0, 2).join(".");
277+
version = (corePackageInfo as any).version;
273278
} else {
274279
// 其他插件,取最新版本
275280
version = "latest";

packages/framework-core/src/plugin-manager/pkg-install.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function install(
1313
// 支持node8
1414
return spawnPromise("npm", [...args, ...packageList, ...npmOptions], {
1515
cwd: options?.cwd || process.cwd(),
16+
stdio: undefined,
1617
});
1718
}
1819

packages/framework-core/src/utils/spawn.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export async function spawnPromise(
1717
options
1818
)
1919
);
20+
let stdout = "";
21+
cm.stdout.on("data", (data) => {
22+
stdout += data;
23+
});
2024
cm.on("error", reject);
21-
cm.on("close", (code) => (code === 0 ? resolve() : reject(code)));
25+
cm.on("close", (code) => (code === 0 ? resolve(stdout) : reject(code)));
2226
});
2327
}

0 commit comments

Comments
 (0)