UNPKG

@strapi/strapi

Version:

An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite

75 lines (69 loc) 2.89 kB
'use strict'; var os = require('node:os'); var dependencies = require('./dependencies.js'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var os__default = /*#__PURE__*/_interopDefault(os); /** * Ensures admin peer dependencies are declared (and optionally auto-installed). * * Policy (`installIfMissing`) is decided by the caller — e.g. build vs develop CLI flags. * Checking and installation are command-agnostic. */ const ensureAdminDependencies = async ({ cwd, logger, installIfMissing })=>{ if (process.env.USE_EXPERIMENTAL_DEPENDENCIES === 'true') { logger.warn('You are using experimental dependencies that may not be compatible with Strapi.'); return { didInstall: false }; } // Hash-cache: skip the full check when package.json hasn't changed since // the last successful pass. The cache lives under node_modules so it's // already gitignored and disposable (a `yarn install` wipe re-runs it). const currentHash = await dependencies.hashPackageJson(cwd); if (currentHash) { const cachedHash = await dependencies.readCachedHash(cwd); if (cachedHash === currentHash) { return { didInstall: false }; } } const missing = await dependencies.findUndeclaredAdminPeerDeps(cwd); if (missing.length > 0) { if (installIfMissing) { logger.info('The Strapi admin needs to install the following dependencies:', os__default.default.EOL, missing.map(({ name, wantedVersion })=>` - ${name}@${wantedVersion}`).join(os__default.default.EOL)); await dependencies.installAdminPeerDeps(missing, { cwd, logger }); await dependencies.reexecCurrentCommand(cwd); return { didInstall: true }; } dependencies.reportMissingAdminPeerDeps(logger, missing); throw new dependencies.MissingAdminPeerDepsError(missing); } await dependencies.validateDeclaredAdminPeerDeps(cwd, logger); if (currentHash) { await dependencies.writeCachedHash(cwd, currentHash); } return { didInstall: false }; }; /** * Runs {@link ensureAdminDependencies} and exits the process on failure. * * @returns `true` when the caller should continue, `false` when a re-exec was triggered. */ const handleAdminDependencies = async (options)=>{ try { const { didInstall } = await ensureAdminDependencies(options); return !didInstall; } catch (err) { options.logger.error(err instanceof Error ? err.message : String(err)); process.exit(1); } }; exports.ensureAdminDependencies = ensureAdminDependencies; exports.handleAdminDependencies = handleAdminDependencies; //# sourceMappingURL=ensure-admin-dependencies.js.map