Skip to content

fix: strip packageManager from generated .faststore/package.json - #3335

Merged
lemagnetic merged 2 commits into
devfrom
fix/cli-strip-package-manager-from-dot-faststore
Jun 1, 2026
Merged

lemagnetic merged 2 commits into
devfrom
fix/cli-strip-package-manager-from-dot-faststore

Conversation

@lemagnetic

@lemagnetic lemagnetic commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

This PR fixes a class of issues where the generated <store>/.faststore/package.json breaks 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.json is generated from @faststore/core's manifest:

  1. packageManager leak (Corepack / Yarn Berry). @faststore/core's package.json declares "packageManager": "[email protected]". The CLI's filterAndCopyPackageJson only stripped exports, so this field leaked into .faststore/package.json. Stores running Yarn against .faststore/ (via yarn predev, yarn dev-only, yarn build, etc.) trip Corepack / Yarn Berry, which either refuses to run or mangles the field into invalid strings like yarn@[email protected].

  2. Missing volta pin (Volta resolves the wrong Yarn). Volta determines tool versions by walking up to the nearest package.json and stops there — it does not keep climbing to inherit a parent's volta config (that requires an explicit volta.extends). Since the generated .faststore/package.json had no volta field, Volta users running anything inside .faststore/ (the predev step runs with cwd = .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:

    Usage Error: The nearest package directory (.../.faststore) doesn't seem to be part of the project declared in ...

On top of that, this failure was hard to diagnose: the predev error message was a copy-paste from the GraphQL codegen step (mentioning GraphQL/TS, which is unrelated), and runCommandSync only surfaced the underlying tool output when DISCOVERY_DEBUG=true, so store devs only ever saw a generic, misleading message.

How it works?

Manifest generation (packages/cli/src/utils/generate.ts)

  • Extracts the filtering logic of filterAndCopyPackageJson into a pure helper buildFaststorePackageJson(coreManifest, voltaConfig?).
  • The helper strips packageManager and exports, renames the package to dot-faststore, and merges in the CLI-required scripts.
  • Adds readRootVoltaConfig(rootDir), which reads the volta field from the store root package.json (when present) and returns undefined otherwise, so stores that don't use Volta are unaffected.
  • filterAndCopyPackageJson now resolves the store root via withBasePath(...).getRoot(), reads its volta config, 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)

  • On failure, the tool's own output (stdout/stderr, already merged via 2>&1) is now always shown — not only under DISCOVERY_DEBUG. This means store devs see the actual root cause (e.g. the Yarn Berry message, which itself lists the possible fixes).

Clearer predev message (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:

    The "predev" step (" predev") failed inside the ".faststore" directory. See the error output below for details.

Tests

  • packages/cli/src/utils/generate.test.ts: existing coverage for stripping packageManager/exports, the dot-faststore rename, scripts merging, metadata preservation and input immutability; plus new cases asserting the store volta config is propagated when provided and omitted when absent.

@lemagnetic
lemagnetic requested a review from a team as a code owner May 20, 2026 00:15
@lemagnetic
lemagnetic requested review from lariciamota and ommeirelles and removed request for a team May 20, 2026 00:15
@lemagnetic lemagnetic added the bug Something isn't working label May 20, 2026
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Exports 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.

Changes

Faststore Package JSON Builder

Layer / File(s) Summary
Builder unit tests
packages/cli/src/utils/generate.test.ts
Test setup, fixture, and unit tests for buildFaststorePackageJson: strips packageManager/exports, renames to dot-faststore, forces CLI scripts (existing or missing), preserves selected metadata, omits absent packageManager, and does not mutate input.
filterAndCopyPackageJson integration test
packages/cli/src/utils/generate.test.ts
Mocks fs-extra to assert reading core package.json and writing the sanitized manifest into .faststore produced by buildFaststorePackageJson(coreManifest), ensuring banned fields are removed.
Builder implementation & integration
packages/cli/src/utils/generate.ts
Adds exported buildFaststorePackageJson(coreManifest) that strips exports/packageManager, sets name to dot-faststore, injects fixed CLI scripts while preserving other fields; refactors and exports filterAndCopyPackageJson.

Vitest coverage provider switch

Layer / File(s) Summary
package.json devDependency updates
packages/*/package.json
Replaces @vitest/coverage-v8 with @vitest/coverage-istanbul in devDependencies for api, cli, components, core, and sdk packages.
Vitest config provider changes
packages/*/vitest.config.*
Updates test.coverage.provider from 'v8' to 'istanbul' across package Vitest configurations and narrows coverage.include globs to specific source file extensions.

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)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ommeirelles
  • lariciamota

Poem

A helper trims what shouldn't stay,
Scripts aligned to light the way,
Tests confirm the manifest's right,
Saved safe into .faststore's night,
Coverage switched and tidy — ship the light. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main change: stripping packageManager from the generated .faststore/package.json, which is the core issue resolved in this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cli-strip-package-manager-from-dot-faststore

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci

codesandbox-ci Bot commented May 20, 2026 •

Copy link
Copy Markdown

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.

@pkg-pr-new

pkg-pr-new Bot commented May 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/cli

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/components

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/core

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/diagnostics

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/lighthouse

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/sdk

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/ui

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

commit: 9009e20

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
packages/cli/src/utils/generate.test.ts (1)

156-157: 💤 Low value

Consider 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

📥 Commits

Reviewing files that changed from the base of the PR and between 38b481e and 015cdb6.

⛔ Files ignored due to path filters (2)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml and included by none
  • pnpm-workspace.yaml is excluded by none and included by none
📒 Files selected for processing (11)
  • packages/api/package.json
  • packages/api/vitest.config.ts
  • packages/cli/package.json
  • packages/cli/src/utils/generate.test.ts
  • packages/cli/vitest.config.ts
  • packages/components/package.json
  • packages/components/vitest.config.mts
  • packages/core/package.json
  • packages/core/vitest.config.ts
  • packages/sdk/package.json
  • packages/sdk/vitest.config.mts

Comment thread packages/api/vitest.config.ts Resolved
Comment thread packages/components/vitest.config.mts Resolved
Comment thread packages/core/vitest.config.ts Resolved
Comment thread packages/sdk/vitest.config.mts Resolved
@lemagnetic
lemagnetic force-pushed the fix/cli-strip-package-manager-from-dot-faststore branch from 196bf1e to 389613d Compare May 20, 2026 17:27
@lemagnetic
lemagnetic force-pushed the fix/cli-strip-package-manager-from-dot-faststore branch from 389613d to 57e4989 Compare May 28, 2026 18:37
@sonar-workflows

Copy link
Copy Markdown

Failed Quality Gate failed

  • 9.50% Coverage on New Code (is less than 80.00%)

Project ID: vtex_faststore_f0a862d5-9557-49f9-8d09-de40caa76622

View in SonarQube

@lemagnetic
lemagnetic merged commit 5a2b793 into dev Jun 1, 2026
8 of 9 checks passed
@lemagnetic
lemagnetic deleted the fix/cli-strip-package-manager-from-dot-faststore branch June 1, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants