refactor(create-sanity): bundle init logic into single file#1011
refactor(create-sanity): bundle init logic into single file#1011
Conversation
|
Claude finished @binoy14's task in 2m 48s —— View job PR Review
Note: The MCP environment gate issue flagged in the previous review ( 1. Auth token exposed in subprocess args (medium)
Fix — pass the token via environment variable instead: await execa(
'sanity',
['dataset', 'import', resolvedTemplate.datasetUrl, '--project-id', projectId, '--dataset', datasetName, '--missing'],
{
cwd: outputPath,
env: {...process.env, SANITY_AUTH_TOKEN: token},
preferLocal: true,
stdio: 'inherit',
},
)2. Changeset summary describes internals (minor)
3.
const settings: {debug?: boolean} = (globalThis as Record<string, unknown>).oclif ?? {}This module is designed to be oclif-free, but it reads |
📦 Bundle Stats —
|
| Metric | Value | vs main (ccda8fd) |
|---|---|---|
| Internal (raw) | 2.1 KB | - |
| Internal (gzip) | 799 B | - |
| Bundled (raw) | 1.54 MB | -9.40 MB, -86.0% |
| Bundled (gzip) | 395.0 KB | -1.67 MB, -81.2% |
| Import time | 867ms | +41ms, +4.9% |
bin:sanity
| Metric | Value | vs main (ccda8fd) |
|---|---|---|
| Internal (raw) | 975 B | - |
| Internal (gzip) | 460 B | - |
| Bundled (raw) | 9.84 MB | - |
| Bundled (gzip) | 1.77 MB | - |
| Import time | 1.97s | -5ms, -0.2% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — @sanity/cli-core
Compared against main (ccda8fd8)
| Metric | Value | vs main (ccda8fd) |
|---|---|---|
| Internal (raw) | 98.0 KB | +4.9 KB, +5.3% |
| Internal (gzip) | 23.3 KB | +1.4 KB, +6.4% |
| Bundled (raw) | 21.63 MB | +35.6 KB, +0.2% |
| Bundled (gzip) | 3.43 MB | +8.6 KB, +0.2% |
| Import time | 808ms | +30ms, +3.9% |
🗺️ View treemap · Artifacts
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
📦 Bundle Stats — create-sanity
Compared against main (ccda8fd8)
| Metric | Value | vs main (ccda8fd) |
|---|---|---|
| Internal (raw) | 2.11 MB | +2.11 MB, +226420.5% |
| Internal (gzip) | 493.3 KB | +492.8 KB, +99536.5% |
| Bundled (raw) | 2.11 MB | +2.11 MB, +220764.4% |
| Bundled (gzip) | 493.3 KB | +492.8 KB, +98177.2% |
| Import time | ❌ --output-path must be specified in unattended mode |
- |
Details
- Import time regressions over 10% are flagged with
⚠️ - Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 02d7b28. Configure here.
| mcpMode = 'skip' | ||
| } else if (flags.yes) { | ||
| mcpMode = 'auto' | ||
| } |
There was a problem hiding this comment.
MCP environment gate removed from shared flag logic
Medium Severity
The old InitCommand.run() skipped MCP setup when getSanityEnv() !== 'production' (i.e., when SANITY_INTERNAL_ENV was set to staging or another non-production value). The new shared flagsToInitOptions drops this environment check entirely. This means sanity init via oclif will now attempt MCP setup in non-production environments where it was previously explicitly disabled. The getSanityEnv import was removed from init.ts but is still used in initHelpers.ts for staging env file writes, so the utility is still available.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 02d7b28. Configure here.
| updateUserProperties() {}, | ||
| } | ||
| return store | ||
| } |
There was a problem hiding this comment.
Duplicate noop telemetry store already exists in cli-core
Low Severity
createNoopTelemetryStore duplicates the existing noopLogger exported from @sanity/cli-core. Since create-sanity already imports from @sanity/cli-core (e.g., isInteractive, CLIError) and the Rollup build resolves these to source, the existing noopLogger could be reused directly instead of maintaining a second noop implementation that may drift out of sync.
Reviewed by Cursor Bugbot for commit 02d7b28. Configure here.
|
This change is part of the following stack: Change managed by git-spice. |
02d7b28 to
dcc9323
Compare
Reapply PR #759 changes onto current main. Replaces the old create-sanity shim with a Rollup-bundled standalone entry point, extracts shared flag definitions, and decouples init from oclif. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dcc9323 to
d705c00
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Restores the staging-env check (from #869) that was lost when the mcpMode logic was extracted into the shared flagsToInitOptions helper. Also updates the create-sanity e2e help-text assertions to match the new "Initialize a new Sanity project" copy. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Coverage Delta
Comparing 24 changed files against main @ Overall Coverage
|


Description
Reapply of #759 onto current
main. The original PR targetedbundled-createand could not be cleanly rebased due to the init refactor in #999 landing on main in the meantime.The goal is to make
npm create sanity@latest(and equivalentyarn/pnpm/buncommands) as fast as possible by minimizing thecreate-sanitybundle size. Previouslycreate-sanitydepended on@sanity/cliat runtime, pulling in oclif and hundreds of transitive dependencies just to runsanity init. This PR bundles only the init logic into a single Rollup-built file, tree-shaking away everything else.Key changes to achieve this:
flags.ts,flagsToInitOptions.ts) as plain objects so both oclif andcreate-sanityuse the same schema withoutcreate-sanityneeding oclif.flagAdapter.tsconverts them back to oclif format for the CLI.CLIError/CLIWarningto@sanity/cli-core/errorsandstdout/warnto@sanity/cli-core/ux, replacing direct imports from@oclif/corein init-reachable code paths.ImportDatasetCommanddynamic import withexecaspawn, removing another oclif dependency from the init flow.rollup.config.tsproduces a single self-contained file forcreate-sanitywith its own arg parser and help formatter.--from-createflag and thefromCreateoption (no longer needed sincecreate-sanitynow runs init directly).What to review
packages/create-sanity/— new bundled entry point, rollup config, parseArgs, help formatter, testspackages/@sanity/cli-core/— new error classes, UX utilities, export changespackages/@sanity/cli/src/commands/init.ts— slimmed down to use shared flag defspackages/@sanity/cli/src/actions/init/— extractedflagsToInitOptions, execa-based dataset importTesting
pnpm test --changed)deploy.app.test.ts(auth mock issue)Note
Medium Risk
Medium risk because it rewires the
sanity initexecution path (flag parsing, error/output handling, and dataset import) and introduces a new Rollup-built standalonecreate-sanitybinary, which could change CLI behavior across environments.Overview
create-sanityis refactored from a thin wrapper around@sanity/cli initinto a standalone, Rollup-bundleddist/index.jsthat runs the sharedinitActiondirectly, with its ownparseArgs-based flag parsing and custom help output.To enable tree-shaking and avoid pulling in oclif,
sanity initflag/arg definitions are extracted into import-free POJOs (flags.ts), conversion logic is centralized inflagsToInitOptions.ts(including--yes/interactive-derived unattended + MCP mode and.envvalidation), and the oclifInitCommandnow adapts those defs via a newflagAdapter.ts.@sanity/cli-coreadds lightweightCLIError/CLIWarningplusuxoutput/error helpers (stdout,warn, formatted printing) and exposes them via a new@sanity/cli-core/errorsexport, while init-reachable code paths switch away from@oclif/coreutilities. Dataset import during init is changed to spawn the localsanity dataset importviaexecaand downgrade failures to warnings instead of hard-failing.Tests and config are updated accordingly (new
create-sanityintegration tests against the bundled output; removal of--from-createbehavior in help; knip ignores/dep hints; new build tooling and lockfile updates).Reviewed by Cursor Bugbot for commit 02d7b28. Bugbot is set up for automated code reviews on this repo. Configure here.