import { StorefrontStarter } from './storefront-starters'; import { CliLogLevel, DbType, PackageManager } from './types'; /** * If project only contains files generated by GH, it’s safe. * Also, if project contains remnant error logs from a previous * installation, lets remove them now. * We also special case IJ-based products .idea because it integrates with CRA: * https://github.com/facebook/create-react-app/pull/368#issuecomment-243446094 */ export declare function isSafeToCreateProjectIn(root: string, name: string): boolean; export declare function scaffoldAlreadyExists(root: string, name: string): boolean; export declare function checkNodeVersion(requiredVersion: string, currentVersion?: string): void; export declare function checkThatNpmCanReadCwd(): boolean; /** * Detects the package manager used to invoke this CLI from the * `npm_config_user_agent` env var that npm/yarn/pnpm/bun all set when running a * package's bin. Falls back to npm. This is what lets `bunx @vendure/create` * (and the pnpm/yarn equivalents) install with a package manager that is * actually on the PATH, rather than hard-failing on a missing `npm` (issue #4390). */ export declare function detectPackageManager(userAgent?: string | undefined): PackageManager; /** * Builds the package-manager-specific command and args for installing the given * dependencies (exact versions, optionally as devDependencies). */ export declare function getInstallCommand(packageManager: PackageManager, options: { dependencies: string[]; isDevDependencies?: boolean; logLevel: CliLogLevel; }): { command: string; args: string[]; }; /** * Manager-specific command fragments used to generate package.json scripts, CLI * instructions, Dockerfiles and READMEs that match the package manager the project * was created with. This is the single source of truth for everything that used to * be hard-coded as `npm`. */ export interface PackageManagerInfo { /** The package manager binary, e.g. `npm` | `yarn` | `pnpm` | `bun`. */ name: PackageManager; /** Prefix to run a package.json script, e.g. `npm run` / `pnpm run` / `bun run`. */ runScript: string; /** Prefix to execute a locally-installed bin, e.g. `npx` / `bunx` / `pnpm exec`. */ exec: string; /** Install all deps declared in the manifest, e.g. `npm install` / `pnpm install`. */ install: string; /** Reproducible, lockfile-frozen install for CI & Docker (includes devDependencies). */ ciInstall: string; /** The lockfile this manager writes. */ lockfile: string; /** * Whether the manager reads the package.json `workspaces` field (npm/yarn/bun) or * requires a `pnpm-workspace.yaml` (pnpm). */ usesPackageJsonWorkspaces: boolean; /** Build a command to run a script in a named workspace, e.g. `npm run dev -w server`. */ workspaceScript(workspace: string, script: string): string; } export declare function getPackageManagerInfo(packageManager: PackageManager): PackageManagerInfo; /** * Returns the scripts for the server package.json. These delegate to the `vendure` * CLI's `dev`/`build`/`start` commands, which are package-manager-agnostic. */ export declare function getServerPackageScripts(): Record; /** * Returns the root package.json for the monorepo (`--include-storefront`) layout, with * workspace scripts written in the syntax of the detected package manager. */ export declare function getMonorepoRootPackageJson(name: string, pmInfo: PackageManagerInfo, dbType: DbType): Record; /** * Returns the root package.json for the single-project (non-monorepo) layout. */ export declare function getSingleProjectPackageJson(name: string, pmInfo: PackageManagerInfo, dbType: DbType): Record; /** * Native dependencies whose install/build scripts must run for the scaffolded project to * work — otherwise e.g. better-sqlite3's native binding is never compiled and the server * crashes on startup. npm (v12+), pnpm (v10+), yarn (v4.14+) and bun block dependency * build scripts unless allowlisted, so this list feeds their respective allowlist mechanisms * (`allowScripts`, `onlyBuiltDependencies`, `dependenciesMeta.built`, `trustedDependencies`). * `bcrypt` (core), `sharp` (asset-server-plugin) and `esbuild` (vite) are always present; * SQLite adds `better-sqlite3` and `re2`. `re2` lets core evaluate `regex` list filters in * guaranteed linear time; without its native binding those filters fall back to the built-in * RegExp engine, which is vulnerable to ReDoS on SQLite backends (GHSA-jgm3-qmp2-c4p7). * * This list is derived from the scaffold's transitive native deps; re-check it against * `getDependencies()` whenever Vendure's direct native-dep surface changes. */ export declare function getNativeBuildDependencies(dbType: DbType): string[]; /** * Returns the root package.json fields that allowlist native dependency build scripts for * the given package manager. pnpm gets none: its allowlist lives in pnpm-workspace.yaml * (see `getPnpmWorkspaceYaml()`). */ export declare function getBuildScriptAllowlistFields(pmInfo: PackageManagerInfo, dbType: DbType): Record; /** * Yarn ≥4.14 does not run dependency build scripts unless they are allowlisted via * `dependenciesMeta` in the top-level package.json (`built: true` per package). */ export declare function getYarnDependenciesMeta(dbType: DbType): Record; /** * npm ≥12 does not run dependency install scripts unless they are allowlisted via * `allowScripts` in the top-level package.json. Entries are name-only (not pinned to a * version) so they keep matching as dependencies are upgraded. Older npm versions ignore * the field. */ export declare function getNpmAllowScripts(dbType: DbType): Record; /** * Generates the pnpm-workspace.yaml contents. Since pnpm v11, this file is the only place * pnpm reads its settings from (the package.json `pnpm` field is ignored), and it is also * where build-script permissions live: v10 uses `onlyBuiltDependencies`, v11 replaced it * with `allowBuilds`. Both keys are written so the scaffold works under either version. */ export declare function getPnpmWorkspaceYaml(dbType: DbType, packagesGlobs?: string[]): string; /** * Generates the .yarnrc.yml for yarn-created projects. The scaffold (ts-node registration, * the `vendure` CLI, the dashboard build) resolves packages from a physical node_modules * tree, so Plug'n'Play is disabled. */ export declare function getYarnRcYml(): string; /** * Registers Handlebars helpers that emit package-manager-specific command fragments, * so templates (README, Dockerfile, …) render commands matching the manager in use. */ export declare function registerTemplateHelpers(pmInfo: PackageManagerInfo): void; /** * Install packages via the package manager that invoked the CLI. * Based on the install function from https://github.com/facebook/create-react-app */ export declare function installPackages(options: { dependencies: string[]; isDevDependencies?: boolean; logLevel: CliLogLevel; cwd?: string; packageManager?: PackageManager; }): Promise; export declare function getDependencies(dbType: DbType, vendurePkgVersion?: string, packageManager?: PackageManager): { dependencies: string[]; devDependencies: string[]; }; /** * Checks that the specified DB connection options are working (i.e. a connection can be * established) and that the named database exists. */ export declare function checkDbConnection(options: any, root: string): Promise; export type DockerDaemonStatus = 'running' | 'not-running' | 'not-responding'; /** * Asks the Docker daemon for a response, giving up after `DOCKER_PROBE_TIMEOUT_MS`. * A stopped daemon refuses the connection at once ('not-running'). A daemon whose * processes run but which does not answer makes `docker` hang with no error * ('not-responding'). */ export declare function probeDockerDaemon(): Promise; export declare const DOCKER_NOT_RESPONDING_MESSAGE: string; /** * Check to see if Docker is installed and running. * If it is installed but stopped, attempt to start it. * If it is installed but does not respond, report that without trying to start it: * its processes are already running, so starting it again does nothing. * * Refs: * - https://stackoverflow.com/a/48843074/772859 */ export declare function isDockerAvailable(): Promise<{ result: 'not-found' | DockerDaemonStatus; }>; /** * Sanitizes a project name into a valid Docker Compose project name * (lowercase letters, digits, `-` and `_`, starting with an alphanumeric). * Used as the top-level `name` in the generated docker-compose.yml so that each * created project gets its own Compose project. Without it, Compose derives the * project name from the compose file's directory — which in monorepo mode is * always `apps/server`, so every project would collide on the project "server". * * When sanitization alters the name, a stable suffix derived from the original is * appended: otherwise distinct project names could sanitize to the same value * (e.g. `shop.v1` and `shopv1`) and end up sharing containers and volumes. */ export declare function toComposeProjectName(name: string): string; export declare function startPostgresDatabase(root: string, projectName: string): Promise; /** * Returns `true` if the given TCP port on `127.0.0.1` is already bound, `false` * if the port is free. Rejects on invalid port input or on any socket error * other than `ECONNREFUSED` — surfacing the real error (e.g. `EACCES`, * `EHOSTUNREACH`) to the caller rather than silently treating it as "in use" * and letting a port scan exhaust before reporting a misleading message. */ export declare function isServerPortInUse(port: number): Promise; /** * Checks if the response from a Clack prompt was a cancellation symbol, and if so, * ends the interactive process. */ export declare function checkCancel(value: T | symbol): value is T; export declare function cleanUpDockerResources(name: string): void; /** * Returns a `require` anchored in the generated project rather than in this CLI. * * `yarn dlx` runs the CLI under Plug'n'Play, which resolves each request against the * package that made it. A request from this CLI for a package that only the generated * project declares is rejected. Passing `require.resolve(pkg, { paths })` does not help, * because Plug'n'Play ignores `paths`. Anchoring at the generated project's package.json * makes that project the requesting package, so its node_modules tree is used. * * Loading through this require also keeps the generated project's CommonJS graph on the * CommonJS loader. A dynamic import enters that graph through the ESM loader instead, and * on Node 22 its nested requires fail to link with ERR_VM_MODULE_LINK_FAILURE. */ export declare function createProjectRequire(rootDir: string): NodeJS.Require; export declare function resolvePackageRootDir(packageName: string, rootDir: string): string; /** * Downloads a storefront starter from GitHub and extracts it to the target directory. * Uses the starter's main branch intentionally, so improvements and fixes are available to newly * scaffolded projects without requiring a matching @vendure/create release. */ export declare function downloadAndExtractStorefront(targetDir: string, storefront: StorefrontStarter): Promise; /** * Finds an available port starting from the given port. * Returns the first available port within the specified range. */ export declare function findAvailablePort(startPort: number, range?: number): Promise;