Repository navigation
fix: strip packageManager from generated .faststore/package.json - #3335
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughExports buildFaststorePackageJson and filterAndCopyPackageJson; adds tests ensuring banned fields are removed, name/scripts are set, metadata preserved, and input is immutable. Also switches Vitest coverage provider from v8 to istanbul and updates devDependencies across packages. ChangesFaststore Package JSON Builder
Vitest coverage provider switch
Sequence Diagram(s)sequenceDiagram
participant CLI
participant generate_ts as generate.ts
participant Builder as buildFaststorePackageJson
participant FS as fs-extra
CLI->>generate_ts: call filterAndCopyPackageJson(basePath)
generate_ts->>FS: read core package.json (basePath/package.json)
generate_ts->>Builder: buildFaststorePackageJson(coreManifest)
Builder->>generate_ts: return sanitized manifest (no exports/packageManager, name/scripts set)
generate_ts->>FS: write .faststore/package.json (sanitized manifest)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/diagnostics
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
packages/cli/src/utils/generate.test.ts (1)
156-157: 💤 Low valueConsider stronger typing for mock extraction.
The type assertion is safe but could be avoided with explicit mock typing. However, for test code with optional chaining guards, this is acceptable.
♻️ Optional: Add explicit type to mock setup
You could type the mock in the hoisted setup:
const fsExtraMocked = vi.hoisted(() => ({ copyFileSync: vi.fn(), copySync: vi.fn(), existsSync: vi.fn(), mkdirsSync: vi.fn(), moveSync: vi.fn(), readFileSync: vi.fn(), readdirSync: vi.fn(), removeSync: vi.fn(), writeFileSync: vi.fn(), - writeJsonSync: vi.fn(), + writeJsonSync: vi.fn<[string, Record<string, unknown>, { spaces: number }], void>(), }))Then access without assertion:
- const writtenManifest = fsExtraMocked.writeJsonSync.mock - .calls[0]?.[1] as Record<string, unknown> + const writtenManifest = fsExtraMocked.writeJsonSync.mock.calls[0]?.[1]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/cli/src/utils/generate.test.ts` around lines 156 - 157, The test is using a type assertion to extract the mock call arg into writtenManifest; instead, explicitly type the mocked function in the test setup so the call args are strongly typed and you can read the second arg without a cast. In the hoisted/mock setup replace or augment fsExtraMocked.writeJsonSync with a typed jest mock (e.g., assign fsExtraMocked.writeJsonSync = jest.fn() typed as jest.Mock or jest.MockedFunction<typeof fsExtraMocked.writeJsonSync>), then use that typed mock's .mock.calls[0][1] to get the manifest (no "as Record<string, unknown>" needed) and update the reference to use the typed mock variable instead of fsExtraMocked.writeJsonSync directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/api/vitest.config.ts`:
- Line 7: The vitest config has a typo in the coverage provider value: change
the provider property value from 'instanbul' to 'istanbul' (update the provider:
'instanbul' entry in the exported/vitest config object so Vitest recognizes the
coverage provider correctly).
In `@packages/components/vitest.config.mts`:
- Line 8: The coverage provider value in the Vitest config is misspelled as
'instanbul'; update the provider property in the Vitest configuration (the
provider field used for coverage reporting) to the correct string 'istanbul' so
Vitest recognizes the coverage provider and avoids runtime errors.
In `@packages/core/vitest.config.ts`:
- Line 10: The vitest coverage provider value is misspelled as 'instanbul' in
the config; update the provider entry (the line containing provider:
'instanbul') to the correct string 'istanbul' so Vitest can load the coverage
provider properly.
In `@packages/sdk/vitest.config.mts`:
- Line 7: The vitest coverage provider string is misspelled: change the provider
value from 'instanbul' to 'istanbul' in the vitest config object (the line
setting provider: 'instanbul' in the config); update that literal so the
coverage integration uses '`@vitest/coverage-istanbul`' correctly.
---
Nitpick comments:
In `@packages/cli/src/utils/generate.test.ts`:
- Around line 156-157: The test is using a type assertion to extract the mock
call arg into writtenManifest; instead, explicitly type the mocked function in
the test setup so the call args are strongly typed and you can read the second
arg without a cast. In the hoisted/mock setup replace or augment
fsExtraMocked.writeJsonSync with a typed jest mock (e.g., assign
fsExtraMocked.writeJsonSync = jest.fn() typed as jest.Mock or
jest.MockedFunction<typeof fsExtraMocked.writeJsonSync>), then use that typed
mock's .mock.calls[0][1] to get the manifest (no "as Record<string, unknown>"
needed) and update the reference to use the typed mock variable instead of
fsExtraMocked.writeJsonSync directly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c09eca50-f422-4b4b-b7b6-98363e19fbfb
⛔ Files ignored due to path filters (2)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamland included by nonepnpm-workspace.yamlis excluded by none and included by none
📒 Files selected for processing (11)
packages/api/package.jsonpackages/api/vitest.config.tspackages/cli/package.jsonpackages/cli/src/utils/generate.test.tspackages/cli/vitest.config.tspackages/components/package.jsonpackages/components/vitest.config.mtspackages/core/package.jsonpackages/core/vitest.config.tspackages/sdk/package.jsonpackages/sdk/vitest.config.mts
196bf1e to
389613d
Compare
389613d to
57e4989
Compare

What's the purpose of this pull request?
This PR fixes a class of issues where the generated
<store>/.faststore/package.jsonbreaks local dev on consumer stores, depending on the package manager / version manager the developer uses.There are two distinct root causes, both stemming from how
.faststore/package.jsonis generated from@faststore/core's manifest:packageManagerleak (Corepack / Yarn Berry).@faststore/core'spackage.jsondeclares"packageManager": "[email protected]". The CLI'sfilterAndCopyPackageJsononly strippedexports, so this field leaked into.faststore/package.json. Stores running Yarn against.faststore/(viayarn predev,yarn dev-only,yarn build, etc.) trip Corepack / Yarn Berry, which either refuses to run or mangles the field into invalid strings likeyarn@[email protected].Missing
voltapin (Volta resolves the wrong Yarn). Volta determines tool versions by walking up to the nearestpackage.jsonand stops there — it does not keep climbing to inherit a parent'svoltaconfig (that requires an explicitvolta.extends). Since the generated.faststore/package.jsonhad novoltafield, Volta users running anything inside.faststore/(thepredevstep runs withcwd = .faststore) fell back to their global Yarn — typically Yarn Berry (4.x) — instead of the version pinned at the store root. Yarn Berry then errors on the nested manifest:On top of that, this failure was hard to diagnose: the
predeverror message was a copy-paste from the GraphQL codegen step (mentioning GraphQL/TS, which is unrelated), andrunCommandSynconly surfaced the underlying tool output whenDISCOVERY_DEBUG=true, so store devs only ever saw a generic, misleading message.How it works?
Manifest generation (
packages/cli/src/utils/generate.ts)filterAndCopyPackageJsoninto a pure helperbuildFaststorePackageJson(coreManifest, voltaConfig?).packageManagerandexports, renames the package todot-faststore, and merges in the CLI-required scripts.readRootVoltaConfig(rootDir), which reads thevoltafield from the store rootpackage.json(when present) and returnsundefinedotherwise, so stores that don't use Volta are unaffected.filterAndCopyPackageJsonnow resolves the store root viawithBasePath(...).getRoot(), reads itsvoltaconfig, and forwards it to the helper, which injects it into.faststore/package.json. This keeps Volta pinned to the same Node/Yarn the store root declares.Surfacing the real error (
packages/cli/src/utils/runCommandSync.ts)2>&1) is now always shown — not only underDISCOVERY_DEBUG. This means store devs see the actual root cause (e.g. the Yarn Berry message, which itself lists the possible fixes).Clearer
predevmessage (packages/cli/src/commands/dev.ts)Replaces the misleading GraphQL/TS message (duplicated from
generate-graphql.ts) with a concise one that states which step failed and where, deferring details to the now-visible underlying output:Tests
packages/cli/src/utils/generate.test.ts: existing coverage for strippingpackageManager/exports, thedot-faststorerename, scripts merging, metadata preservation and input immutability; plus new cases asserting the storevoltaconfig is propagated when provided and omitted when absent.