UNPKG

@storm-stack/core

Version:

A build toolkit and runtime used by Storm Software in TypeScript applications

47 lines (44 loc) 2.61 kB
import { init_esm_shims, __name } from './chunk-QH7NXH7H.js'; import { LogLevelLabel } from '@storm-software/config-tools/types'; import { install } from '@stryke/fs/install'; import { isPackageListed, doesPackageMatch, getPackageListing } from '@stryke/fs/package-fns'; import { hasPackageVersion, getPackageName, getPackageVersion } from '@stryke/string-format/package'; import { isNumber } from '@stryke/type-checks/is-number'; // src/commands/init/install/utilities.ts init_esm_shims(); async function installPackage(context, packageName, dev = false) { const isListed = await isPackageListed(packageName, { cwd: context.options.projectRoot }); if (!isListed) { if (context.options.skipInstalls !== true && !process.env.STORM_STACK_LOCAL) { context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`); const result = await install(packageName, { cwd: context.options.projectRoot, dev }); if (isNumber(result.exitCode) && result.exitCode > 0) { context.log(LogLevelLabel.ERROR, result.stderr); throw new Error(`An error occurred while installing the package "${packageName}"`); } } else { context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`); } } else if (hasPackageVersion(packageName) && !process.env.STORM_STACK_SKIP_VERSION_CHECK) { const isMatching = await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.options.projectRoot); if (!isMatching) { const packageListing = await getPackageListing(getPackageName(packageName), { cwd: context.options.projectRoot }); if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) { context.log(LogLevelLabel.WARN, `The package "${getPackageName(packageName)}" is installed but does not match the expected version ${getPackageVersion(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`); } } } } __name(installPackage, "installPackage"); async function installPackages(context, packages) { return Promise.all(packages.map(async (pkg) => installPackage(context, pkg.name, pkg.dev))); } __name(installPackages, "installPackages"); export { installPackage, installPackages };