Skip to content

SDK operations

Programmatic entry points for @i18nprune/core. Each runXxx function mirrors a CLI command’s engine logic; hosts supply runtime adapters and optional hooks for progress, prompts, and filesystem access.

Mental model

text
resolveContext({ projectRoot, adapters })  →  CoreContext
runXxx(ctx, options, hostHooks?)           →  { payload, issues, … }
  • Core owns deterministic analysis, locale IO plans, and typed results.
  • CLI / your host owns envelopes, exit codes, human stderr, and adapter construction.
  • Tier A — read / analyze only (safe in browser and edge bundles).
  • Tier B — may write locale files or mutate project state (expect Node or a backend you operate).

See Runtime-neutral SDK host model (ADR 011) and Runtime overview.

Host setup (Node)

ts
import { resolveContext, runValidate } from '@i18nprune/core';
import { createNodeRuntimeAdapters } from '@i18nprune/core/runtime/node';

const ctx = await resolveContext({
  projectRoot: process.cwd(),
  adapters: createNodeRuntimeAdapters(),
});

const result = await runValidate(ctx, {});
// result.payload · result.issues

Web and edge adapters: @i18nprune/core/runtime/web, @i18nprune/core/runtime/edge.

Runnable scripts: SDK examples.

Operations index

OperationCore entryTierExampleCLI --json
validaterunValidateAyes
doctorrunDoctorAdoctoryes
missingrunMissingBmissingyes
syncrunSyncBsyncyes
cleanuprunCleanupByes
qualityrunQualityAqualityyes
reviewrunReviewAreviewyes
generaterunGenerateBgenerateyes
translate (provider)runTranslateBtranslatevia generate path
reportrunReportAyes (dual JSON)
share uploadrunShareAyes
share listrunShareListAshare listyes
share viewrunShareViewAyes
share deleterunShareDeleteAyes
locales listrunLocalesListA/Byes
locales dynamicrunDynamicAyes
locales deletedeleteLocaleFilesByes
initrunInitBpartial / host-specific
patchingrunPatchingBCLI-first today
project readinessrunProjectReadinessAused by doctor / CI presets

CLI envelope wrappers (import from CLI, not core)

These commands assemble the CliJsonEnvelope in the CLI package even though core owns most payloads:

CLI commandNotes
validate --jsonCore runValidate; CLI adds envelope + exit code
languages --jsonLocale catalog envelope
config --jsonResolved config snapshot
providers --jsonTranslation provider list

SDK integrators should call the matching runXxx in core when one exists, or spawn the CLI for envelope-only commands.

Return shape (sketch)

Most runXxx results follow:

ts
type RunResult = {
  payload: /* command-specific JSON data */;
  issues: Issue[];  // stable codes: i18nprune.*
  ok?: boolean;       // some ops expose explicitly
};

Long-running ops (runGenerate, runTranslate) accept host hooks for run.progress.* events. Progress UX is host-owned; semantics stay in core. See generate.

Async / IO-heavy: runGenerate, runReport, runShare, runSync, runMissing, runCleanup, runInit.

Exports and subpaths

Install:

bash
npm i @i18nprune/core

Root barrel (@i18nprune/core)

Primary runXxx exports, analysis helpers (resolveProjectAnalysis, scanProjectLiteralKeyUsage), share/report builders, translator utilities, and shared types.

Published subpaths

SubpathUse for
@i18nprune/coreDefault — runXxx, context, analysis
@i18nprune/core/configdefineConfig, I18nPruneConfig
@i18nprune/core/runtime/nodecreateNodeRuntimeAdapters
@i18nprune/core/runtime/webcreateWebRuntimeAdapters
@i18nprune/core/runtime/edgecreateEdgeRuntimeAdapters
@i18nprune/core/validateValidate-only graph (smaller bundle)
@i18nprune/core/syncSync-only graph
@i18nprune/core/missingMissing-only graph
@i18nprune/core/cleanupCleanup-only graph
@i18nprune/core/qualityQuality-only graph
@i18nprune/core/generateGenerate / translate graph
@i18nprune/core/initInit scaffolding
@i18nprune/core/localesLocale list / dynamic helpers
@i18nprune/core/sharedShared constants and helpers
@i18nprune/core/typesType-only imports
@i18nprune/core/report-schemaReport document Zod schema

Type namespaces on the root barrel (e.g. keySites, extractor, share) mirror core modules for tree-shaking-friendly imports.

Configuration types and defineConfig: Configuration.

JSON contract parity

CLI --json envelopes use stable issues[].code values and meta.apiVersion (envelope contract, currently "1" — independent of npm semver). See JSON output.

Known extraction limits

Static analysis is heuristic, not full TypeScript semantics. Patterns such as const { t } = useTranslation() (hook destructuring) may not resolve today. See Regex and static-analysis limits and the unsolved inventory.