Compare commits
1 Commits
ec2b0fb96e
...
ecb9bbd3e8
| Author | SHA1 | Date |
|---|---|---|
|
|
ecb9bbd3e8 |
|
|
@ -4,14 +4,28 @@ const fs = require('./fs-native');
|
|||
const { CLIUtils } = require('./cli-utils');
|
||||
const { ExternalModuleManager } = require('./modules/external-manager');
|
||||
const { resolveModuleVersion } = require('./modules/version-resolver');
|
||||
const { Manifest } = require('./core/manifest');
|
||||
const prompts = require('./prompts');
|
||||
|
||||
/**
|
||||
* Read a module version from the freshest local metadata available.
|
||||
* @param {string} moduleCode - Module code (e.g., 'core', 'bmm', 'cis')
|
||||
* @param {string|null} npmPackage - npm package name for live version lookup
|
||||
* @returns {string} Version string or empty string
|
||||
*/
|
||||
async function getModuleVersion(moduleCode) {
|
||||
async function getModuleVersion(moduleCode, npmPackage = null) {
|
||||
if (npmPackage) {
|
||||
try {
|
||||
const manifest = new Manifest();
|
||||
const npmVersion = await manifest.fetchNpmVersion(npmPackage);
|
||||
if (npmVersion) {
|
||||
return npmVersion;
|
||||
}
|
||||
} catch {
|
||||
// Fall back to local metadata when npm is unreachable.
|
||||
}
|
||||
}
|
||||
|
||||
const versionInfo = await resolveModuleVersion(moduleCode);
|
||||
return versionInfo.version || '';
|
||||
}
|
||||
|
|
@ -611,9 +625,9 @@ class UI {
|
|||
const initialValues = [];
|
||||
const lockedValues = ['core'];
|
||||
|
||||
const buildModuleEntry = async (code, name, description, isDefault) => {
|
||||
const buildModuleEntry = async (code, name, description, isDefault, npmPackage = null) => {
|
||||
const isInstalled = installedModuleIds.has(code);
|
||||
const version = await getModuleVersion(code);
|
||||
const version = await getModuleVersion(code, npmPackage);
|
||||
const label = version ? `${name} (v${version})` : name;
|
||||
return {
|
||||
label,
|
||||
|
|
@ -628,7 +642,7 @@ class UI {
|
|||
for (const mod of builtInModules) {
|
||||
const code = mod.id;
|
||||
builtInCodes.add(code);
|
||||
const entry = await buildModuleEntry(code, mod.name, mod.description, mod.defaultSelected);
|
||||
const entry = await buildModuleEntry(code, mod.name, mod.description, mod.defaultSelected, mod.npmPackage || null);
|
||||
allOptions.push({ label: entry.label, value: entry.value, hint: entry.hint });
|
||||
if (entry.selected) {
|
||||
initialValues.push(code);
|
||||
|
|
@ -638,7 +652,7 @@ class UI {
|
|||
// Add external registry modules (skip built-in duplicates)
|
||||
for (const mod of registryModules) {
|
||||
if (mod.builtIn || builtInCodes.has(mod.code)) continue;
|
||||
const entry = await buildModuleEntry(mod.code, mod.name, mod.description, mod.defaultSelected);
|
||||
const entry = await buildModuleEntry(mod.code, mod.name, mod.description, mod.defaultSelected, mod.npmPackage || null);
|
||||
allOptions.push({ label: entry.label, value: entry.value, hint: entry.hint });
|
||||
if (entry.selected) {
|
||||
initialValues.push(mod.code);
|
||||
|
|
|
|||
Loading…
Reference in New Issue