Skip to content

refactor(init): move init logic to action pattern#845

Draft
binoy14 wants to merge 2 commits intomainfrom
bundled-create
Draft

refactor(init): move init logic to action pattern#845
binoy14 wants to merge 2 commits intomainfrom
bundled-create

Conversation

@binoy14
Copy link
Copy Markdown
Contributor

@binoy14 binoy14 commented Mar 30, 2026

refactor(init): move init logic to action pattern (#748)

refactor(init): split init flows into separate functions (#753)

@claude
Copy link
Copy Markdown

claude bot commented Mar 30, 2026

Claude finished @binoy14's task in 5m 9s —— View job


Review

  • Gather context
  • Read changed files
  • Check for changeset
  • Post review

Changeset: Not present. This is a pure refactor with no observable behavioral change to any public CLI API — no changeset required. ✓


initAction.ts:790 — dead schemaUrl field in return type

}> {
  ...
  schemaUrl?: string   // ← never set in any return path
}

getProjectDetails declares schemaUrl?: string in its return type, but none of the function's return paths ever populate it. The destructuring at the call site (initAction.ts:173) doesn't include it either, and it's never forwarded downstream. init.bootstrap-app.test.ts:199 even asserts schemaUrl: undefined (carried from the old code).

This field is dead. Remove it from the return type and the test assertion. Fix this →


initNextJs.ts:127 — fragile string replace on path segments

.replace(':route:', embeddedStudioRouteFilePath.slice(workDir.length).replace('src/', ''))

Plain string .replace('src/', '') only removes the first occurrence. If the workDir itself contains src/ (e.g. /home/user/src/myapp), .slice(workDir.length) strips the prefix correctly, but if the resulting relative path contains multiple src/ segments this would silently strip the wrong one. This is pre-existing code moved unchanged, but worth tracking.


Test changes — exit(0) removal is correct

All three test files (init.bootstrap-app, init.nextjs, init.staging-env) changed from:

expect(error?.oclif?.exit).toBe(0)

to:

if (error) throw error

This is correct. The original code called this.exit(0) after early-return paths (env-only, Next.js), which oclif treats as a thrown error with exit code 0. The refactored action functions simply return instead, which is cleaner and produces no error at all. The test update accurately reflects this.

Copy link
Copy Markdown
Contributor Author

binoy14 commented Mar 30, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

📦 Bundle Stats — @sanity/cli

Compared against main (e9022171) · v6.2.1 (npm)

@sanity/cli

Metric Value vs main (e902217) vs v6.2.1
Internal (raw) 2.1 KB - -
Internal (gzip) 799 B - -
Bundled (raw) 11.06 MB - +9.12 MB, +470.6%
Bundled (gzip) 2.07 MB - +1.60 MB, +335.8%
Import time 844ms +0ms, +0.0% +27ms, +3.3%

bin:sanity

Metric Value vs main (e902217) vs v6.2.1
Internal (raw) 975 B - -
Internal (gzip) 460 B - -
Bundled (raw) 9.83 MB - +9.12 MB, +1286.7%
Bundled (gzip) 1.77 MB - +1.60 MB, +940.0%
Import time NaNs - NaNs, NaN%

🗺️ 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 (e9022171) · v1.2.1 (npm)

Metric Value vs main (e902217) vs v1.2.1
Internal (raw) 92.2 KB - +3.9 KB, +4.4%
Internal (gzip) 21.6 KB - +1.1 KB, +5.5%
Bundled (raw) 21.64 MB - +9.08 MB, +72.3%
Bundled (gzip) 3.43 MB - +1.58 MB, +85.9%
Import time 790ms +3ms, +0.4% +39ms, +5.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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 30, 2026

Coverage Delta

File Statements
packages/@sanity/cli/src/actions/init/bootstrapTemplate.ts 0.0% (±0%)
packages/@sanity/cli/src/actions/init/initAction.ts 94.8% (new)
packages/@sanity/cli/src/actions/init/initApp.ts 96.0% (new)
packages/@sanity/cli/src/actions/init/initError.ts 100.0% (new)
packages/@sanity/cli/src/actions/init/initHelpers.ts 100.0% (new)
packages/@sanity/cli/src/actions/init/initNextJs.ts 86.7% (new)
packages/@sanity/cli/src/actions/init/initStudio.ts 87.0% (new)
packages/@sanity/cli/src/actions/init/scaffoldTemplate.ts 88.0% (new)
packages/@sanity/cli/src/actions/init/types.ts 100.0% (new)
packages/@sanity/cli/src/commands/init.ts 100.0% (+ 7.4%)
packages/@sanity/cli/src/telemetry/init.telemetry.ts 100.0% (±0%)

Comparing 11 changed files against main @ a43cfcca1f919e6d65832432231d8c698b0deda7

Overall Coverage

Metric Coverage
Statements 83.0% (+ 0.0%)
Branches 73.0% (+ 0.0%)
Functions 83.0% (+ 0.1%)
Lines 83.5% (+ 0.0%)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

📦 Bundle Stats — @sanity/cli

Compared against main (a43cfcca)

@sanity/cli

Metric Value vs main (a43cfcc)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 10.95 MB -
Bundled (gzip) 2.06 MB -
Import time 823ms +5ms, +0.6%

bin:sanity

Metric Value vs main (a43cfcc)
Internal (raw) 975 B -
Internal (gzip) 460 B -
Bundled (raw) 9.84 MB -
Bundled (gzip) 1.77 MB -
Import time 1.93s -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 (a43cfcca)

Metric Value vs main (a43cfcc)
Internal (raw) 93.1 KB -
Internal (gzip) 21.9 KB -
Bundled (raw) 21.53 MB -
Bundled (gzip) 3.41 MB -
Import time 781ms -1ms, -0.1%

🗺️ 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 (a43cfcca)

Metric Value vs main (a43cfcc)
Internal (raw) 976 B -
Internal (gzip) 507 B -
Bundled (raw) 50.7 KB -
Bundled (gzip) 12.6 KB -
Import time ❌ ChildProcess denied: node -
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.

@binoy14 binoy14 changed the title refactor(init): move init logic to action pattern (#748) refactor(init): move init logic to action pattern Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Coverage Delta

File Statements
packages/@sanity/cli/src/actions/init/bootstrapTemplate.ts 0.0% (±0%)
packages/@sanity/cli/src/actions/init/initAction.ts 94.8% (new)
packages/@sanity/cli/src/actions/init/initApp.ts 96.0% (new)
packages/@sanity/cli/src/actions/init/initError.ts 100.0% (new)
packages/@sanity/cli/src/actions/init/initHelpers.ts 100.0% (new)
packages/@sanity/cli/src/actions/init/initNextJs.ts 86.7% (new)
packages/@sanity/cli/src/actions/init/initStudio.ts 87.0% (new)
packages/@sanity/cli/src/actions/init/scaffoldTemplate.ts 88.0% (new)
packages/@sanity/cli/src/actions/init/types.ts 100.0% (new)
packages/@sanity/cli/src/commands/init.ts 100.0% (+ 7.4%)
packages/@sanity/cli/src/telemetry/init.telemetry.ts 100.0% (±0%)

Comparing 11 changed files against main @ 7af1594d79003801d6daeadeeb20508d184adb25

Overall Coverage

Metric Coverage
Statements 83.1% (+ 0.0%)
Branches 72.9% (+ 0.0%)
Functions 83.4% (+ 0.1%)
Lines 83.6% (+ 0.0%)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Coverage Delta

File Statements
packages/@sanity/cli/src/actions/init/bootstrapTemplate.ts 0.0% (±0%)
packages/@sanity/cli/src/actions/init/initAction.ts 94.8% (new)
packages/@sanity/cli/src/actions/init/initApp.ts 96.0% (new)
packages/@sanity/cli/src/actions/init/initError.ts 100.0% (new)
packages/@sanity/cli/src/actions/init/initHelpers.ts 100.0% (new)
packages/@sanity/cli/src/actions/init/initNextJs.ts 86.7% (new)
packages/@sanity/cli/src/actions/init/initStudio.ts 87.0% (new)
packages/@sanity/cli/src/actions/init/scaffoldTemplate.ts 88.0% (new)
packages/@sanity/cli/src/actions/init/types.ts 100.0% (new)
packages/@sanity/cli/src/commands/init.ts 100.0% (+ 7.4%)
packages/@sanity/cli/src/telemetry/init.telemetry.ts 100.0% (±0%)

Comparing 11 changed files against main @ ef5ed4565d33b83d67cd66c6b3c335516e5b1132

Overall Coverage

Metric Coverage
Statements 83.1% (+ 0.0%)
Branches 72.9% (+ 0.0%)
Functions 83.4% (+ 0.1%)
Lines 83.6% (+ 0.0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants