Skip to content

fix: v4 monorepo builds - #3253

Merged
lemagnetic merged 14 commits into
canary-v2from
fix/monorepo-builds
Apr 7, 2026
Merged

lemagnetic merged 14 commits into
canary-v2from
fix/monorepo-builds

Conversation

@lemagnetic

@lemagnetic lemagnetic commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

Fix FastStore v4 builds and codegen in monorepos when the CLI runs from the repo root and Discovery lives in a nested package (packages/...): .faststore and subprocesses now respect the project basePath, and standalone output with outputFileTracingRoot at the repo root no longer breaks layouts that expect server.js under .next/standalone/.

SFS-3116

How it works?

  • directory: tmpDir = <basePath>/.faststore (no longer cwd/.faststore).
  • build: passes basePath to generate, cache-graphql, and generate-i18n; normalizeStandaloneBuildDir uses path.relative(cwd, basePath) as a prefix when cwd !== basePath; - dev: cache-graphql and generate-i18n receive basePath.
  • generate-types: resolves paths into .faststore when it exists.
  • Tests: expectations anchored to basePath + monorepo scenarios.

How to test it?

Starters Deploy Preview

References

Summary by CodeRabbit

  • Bug Fixes

    • Improved monorepo path handling so build/dev outputs, standalone artifacts, temp dirs, and codegen respect the package base path.
    • Made CLI subprocess invocations more reliable by changing how arguments are passed (removing shell execution) and improving package.json JSON loading behavior.
  • Tests

    • Added deterministic tests covering path resolution and monorepo scenarios.
  • Chores

    • Expanded exported search-related types in the SDK.

@coderabbitai

coderabbitai Bot commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f99c4814-3714-4fbc-aec5-ef3593a6e41e

📥 Commits

Reviewing files that changed from the base of the PR and between eb2cca6 and 5505d23.

📒 Files selected for processing (2)
  • packages/cli/src/commands/build.ts
  • packages/cli/src/commands/dev.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/cli/src/commands/dev.ts
  • packages/cli/src/commands/build.ts

Walkthrough

CLI build/dev now forward the resolved basePath to spawned subcommands; directory utilities and tests place temporary/generated files under the resolved project root (handling monorepo package prefixes); type/schema generation redirects I/O into .faststore when present and package.json is imported via file:// URL.

Changes

Cohort / File(s) Summary
CLI Commands
packages/cli/src/commands/build.ts, packages/cli/src/commands/dev.ts
Spawn subcommands using argument arrays (no shell), forward basePath to generate, cache-graphql, and generate-i18n; added deterministic JSON ESM import via pathToFileURL(...).href and normalize mod.default ?? mod; build handles monorepo prefix when relocating Next.js standalone .faststore.
Directory Utilities & Tests
packages/cli/src/utils/directory.ts, packages/cli/src/utils/directory.test.ts
withBasePath now roots tmp directories at getRoot() (the resolved basePath) instead of process.cwd(); tests updated/added to assert deterministic paths and correct monorepo package isolation.
Type/Schema Generation
packages/cli/src/utils/generate-types.ts
Detect root/.faststore and set finalRootPath accordingly; generate schema/types under .faststore/@generated when present; adjust schema merge-root logic when rootPath ends with .faststore; add existsSync checks.
SDK Types & Imports
packages/core/src/sdk/product/useProductGalleryQuery.ts, packages/sdk/src/index.ts
Consolidated imports to include Facet type and re-export Facet alongside SearchState; removed deep dist type import.
Miscellaneous
packages/cli/src/commands/build.ts (minor edits)
Small logging and path-resolution tweaks; ensure moved .faststore dirs are deleted after relocation; updated JSON import normalization.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI (build/dev)
    participant Sub as Subcommand\n(generate / cache-graphql / generate-i18n)
    participant Dir as Directory Util\n(withBasePath / getRoot)
    participant Gen as Generate Types/Schema
    participant FS as File System

    CLI->>CLI: resolve basePath (arg or cwd)
    alt Monorepo (cwd ≠ basePath)
        CLI->>CLI: compute package prefix
        CLI->>FS: move .next/standalone/${prefix}.faststore -> target
        CLI->>FS: remove moved ${prefix}.faststore
    end

    CLI->>Sub: spawn node <cli> <script> <basePath>
    Sub->>Dir: withBasePath(basePath)
    Dir-->>Sub: return tmp/user paths rooted at getRoot(basePath)

    Sub->>Gen: request schema/types generation (root)
    Gen->>FS: if root/.faststore exists
    alt .faststore present
        Gen->>FS: read/write under root/.faststore/@generated
    else
        Gen->>FS: read/write under root/@generated
    end
    FS-->>Gen: files created/updated
    Gen-->>Sub: types ready
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

bug

Suggested reviewers

  • lariciamota
  • gabpaladino

Poem

🌱 basePath whispered, "claim this ground",
Subcommands marched with args passed down,
.faststore found its proper nest,
Temp files settled where roots are blessed,
Build and types now hum in sync.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: v4 monorepo builds' directly summarizes the main objective of the PR, which is to fix FastStore v4 builds for monorepos by ensuring .faststore and subprocesses respect the project basePath.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/monorepo-builds

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@lemagnetic lemagnetic changed the title fix(cli): align build subprocesses with store path in monorepos fix: align build subprocesses with store path in monorepos Mar 29, 2026
@codesandbox-ci

codesandbox-ci Bot commented Mar 29, 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.

@lemagnetic lemagnetic changed the title fix: align build subprocesses with store path in monorepos fix: v4 monorepo build Mar 29, 2026
@lemagnetic lemagnetic changed the title fix: v4 monorepo build fix: v4 monorepo builds Mar 29, 2026
@lemagnetic
lemagnetic force-pushed the fix/monorepo-builds branch 2 times, most recently from f30cf18 to 4b3e6c6 Compare April 2, 2026 17:42
@lemagnetic
lemagnetic marked this pull request as ready for review April 6, 2026 13:49
@lemagnetic
lemagnetic requested a review from a team as a code owner April 6, 2026 13:49
@lemagnetic
lemagnetic requested review from eduardoformiga and lariciamota and removed request for a team April 6, 2026 13:49

@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: 2

🧹 Nitpick comments (1)
packages/cli/src/commands/build.ts (1)

203-215: Narrow the imported JSON instead of asserting it.

as { ... } only silences the compiler; it does not protect checkDeps() from malformed shapes like dependencies: null. A small runtime normalizer for each dependency bag would keep this path safe without the cast.

As per coding guidelines, "Ensure type safety and avoid type assertions when possible".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/src/commands/build.ts` around lines 203 - 215, The code asserts
the imported JSON shape with "as { ... }" which can hide runtime issues (e.g.,
dependencies: null); instead remove the type assertion on pkg (keep const pkg =
mod.default ?? mod) and normalize each dependency bag before use: ensure
devDependencies, dependencies, and peerDependencies are plain objects (fallback
to {} when missing or not an object) so checkDeps() always receives an object;
reference the variables mod, pkg, devDependencies, dependencies,
peerDependencies and the function checkDeps() when applying this normalization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/cli/src/commands/build.ts`:
- Around line 72-75: The spawnSync calls currently build shell-interpolated
commands like `node ${binCli} generate ${basePath}`, which risks shell injection
and breaks on spaces; update each of the three usages of spawnSync to call
spawnSync(process.execPath, [binCli, '<subcommand>', basePath], { stdio:
'inherit' }) (e.g., for the generate invocation use [binCli, 'generate',
basePath], and similarly replace the other two subcommands) so arguments are
passed as an array (no shell: true) and basePath is not interpolated into a
shell string; ensure you remove or set shell:false and preserve stdio and other
options.

In `@packages/cli/src/commands/dev.ts`:
- Around line 201-210: The two spawnSync invocations that run `node ${cliPath}
cache-graphql ${basePath}` and `node ${cliPath} generate-i18n ${basePath}` are
unsafe and don't check exit codes; replace them with argv-style child calls
using spawnSync(cliPath, ['cache-graphql', basePath], { shell: false, stdio:
'inherit' }) and spawnSync(cliPath, ['generate-i18n', basePath], { shell: false,
stdio: 'inherit' }) (i.e., stop interpolating basePath into a shell string) and
after each call inspect the returned result.status/failure to abort
(process.exit with the non-zero status or throw) if the command failed so `dev`
doesn't continue with stale artifacts; update the locations where `cliPath`,
`basePath`, and the `cache-graphql`/`generate-i18n` spawnSync calls appear.

---

Nitpick comments:
In `@packages/cli/src/commands/build.ts`:
- Around line 203-215: The code asserts the imported JSON shape with "as { ...
}" which can hide runtime issues (e.g., dependencies: null); instead remove the
type assertion on pkg (keep const pkg = mod.default ?? mod) and normalize each
dependency bag before use: ensure devDependencies, dependencies, and
peerDependencies are plain objects (fallback to {} when missing or not an
object) so checkDeps() always receives an object; reference the variables mod,
pkg, devDependencies, dependencies, peerDependencies and the function
checkDeps() when applying this normalization.
🪄 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: 814e268b-26a9-4a6d-8542-07f12cf56ade

📥 Commits

Reviewing files that changed from the base of the PR and between 641a9f8 and 4b3e6c6.

📒 Files selected for processing (5)
  • packages/cli/src/commands/build.ts
  • packages/cli/src/commands/dev.ts
  • packages/cli/src/utils/directory.test.ts
  • packages/cli/src/utils/directory.ts
  • packages/cli/src/utils/generate-types.ts

Comment thread packages/cli/src/commands/build.ts Outdated
Comment on lines 72 to 75
let scriptResult = spawnSync(`node ${binCli} generate ${basePath}`, {
shell: true,
stdio: 'inherit',
})

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let me check the file structure and read the relevant sections
head -100 packages/cli/src/commands/build.ts | tail -50

Repository: vtex/faststore

Length of output: 1541


🏁 Script executed:

# Also get the full context around those lines
sed -n '60,100p' packages/cli/src/commands/build.ts

Repository: vtex/faststore

Length of output: 1170


🏁 Script executed:

# Check how basePath is derived - trace its origin
sed -n '1,70p' packages/cli/src/commands/build.ts

Repository: vtex/faststore

Length of output: 2305


Use process.execPath with array arguments instead of shell-interpolating basePath.

The three subprocess calls (lines 72–75, 81–84, 94–97) embed user-provided basePath in shell strings. This creates a shell injection vulnerability: paths with spaces break the command, and paths with shell metacharacters (e.g., $(...) or ;) enable arbitrary command execution.

Replace spawnSync(command_string, { shell: true, ... }) with spawnSync(process.execPath, [binCli, subcommand, basePath], { ... }) to safely pass arguments without shell interpretation.

Suggested change
-    let scriptResult = spawnSync(`node ${binCli} generate ${basePath}`, {
-      shell: true,
-      stdio: 'inherit',
-    })
+    let scriptResult = spawnSync(
+      process.execPath,
+      [binCli, 'generate', basePath],
+      { stdio: 'inherit' }
+    )

-    scriptResult = spawnSync(`node ${binCli} cache-graphql ${basePath}`, {
-      shell: true,
-      stdio: 'inherit',
-    })
+    scriptResult = spawnSync(
+      process.execPath,
+      [binCli, 'cache-graphql', basePath],
+      { stdio: 'inherit' }
+    )

     // generate-i18n will validate localization config and check if it's enabled
-    scriptResult = spawnSync(`node ${binCli} generate-i18n ${basePath}`, {
-      shell: true,
-      stdio: 'inherit',
-    })
+    scriptResult = spawnSync(
+      process.execPath,
+      [binCli, 'generate-i18n', basePath],
+      { stdio: 'inherit' }
+    )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/src/commands/build.ts` around lines 72 - 75, The spawnSync calls
currently build shell-interpolated commands like `node ${binCli} generate
${basePath}`, which risks shell injection and breaks on spaces; update each of
the three usages of spawnSync to call spawnSync(process.execPath, [binCli,
'<subcommand>', basePath], { stdio: 'inherit' }) (e.g., for the generate
invocation use [binCli, 'generate', basePath], and similarly replace the other
two subcommands) so arguments are passed as an array (no shell: true) and
basePath is not interpolated into a shell string; ensure you remove or set
shell:false and preserve stdio and other options.

Comment thread packages/cli/src/commands/dev.ts Outdated
Comment on lines 201 to 210
spawnSync(`node ${cliPath} cache-graphql ${basePath}`, {
shell: true,
stdio: 'inherit',
})

// generate-i18n will validate localization config and check if it's enabled
spawnSync(`node ${cliPath} generate-i18n`, {
spawnSync(`node ${cliPath} generate-i18n ${basePath}`, {
shell: true,
stdio: 'inherit',
})

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n packages/cli/src/commands/dev.ts | sed -n '195,220p'

Repository: vtex/faststore

Length of output: 1024


🏁 Script executed:

cat -n packages/cli/src/commands/dev.ts | head -n 210 | tail -n +1 | head -n 100

Repository: vtex/faststore

Length of output: 3471


🏁 Script executed:

cat -n packages/cli/src/commands/dev.ts | sed -n '130,210p'

Repository: vtex/faststore

Length of output: 2750


🏁 Script executed:

fd -t f "directory\|runCommandSync" packages/cli/src/utils/ | head -20

Repository: vtex/faststore

Length of output: 40


🏁 Script executed:

ls -la packages/cli/src/utils/

Repository: vtex/faststore

Length of output: 1186


🏁 Script executed:

cat -n packages/cli/src/utils/runCommandSync.ts

Repository: vtex/faststore

Length of output: 2393


🏁 Script executed:

cat -n packages/cli/src/utils/directory.ts

Repository: vtex/faststore

Length of output: 3004


Use argv-based child processes and check their exit codes.

These spawnSync calls interpolate basePath into shell commands with shell: true. Since basePath comes directly from user input (via getBasePath(args.path)), paths with spaces or special characters will be misparsed. Additionally, neither call checks exit codes, so dev can continue with stale GraphQL/i18n artifacts if these setup steps fail.

Suggested change
-    spawnSync(`node ${cliPath} cache-graphql ${basePath}`, {
-      shell: true,
-      stdio: 'inherit',
-    })
+    const cacheGraphqlResult = spawnSync(
+      process.execPath,
+      [cliPath, 'cache-graphql', basePath],
+      { stdio: 'inherit' }
+    )
+    if (cacheGraphqlResult.error || cacheGraphqlResult.status !== 0) {
+      throw new Error('Unable to run cache-graphql')
+    }

     // generate-i18n will validate localization config and check if it's enabled
-    spawnSync(`node ${cliPath} generate-i18n ${basePath}`, {
-      shell: true,
-      stdio: 'inherit',
-    })
+    const generateI18nResult = spawnSync(
+      process.execPath,
+      [cliPath, 'generate-i18n', basePath],
+      { stdio: 'inherit' }
+    )
+    if (generateI18nResult.error || generateI18nResult.status !== 0) {
+      throw new Error('Unable to run generate-i18n')
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
spawnSync(`node ${cliPath} cache-graphql ${basePath}`, {
shell: true,
stdio: 'inherit',
})
// generate-i18n will validate localization config and check if it's enabled
spawnSync(`node ${cliPath} generate-i18n`, {
spawnSync(`node ${cliPath} generate-i18n ${basePath}`, {
shell: true,
stdio: 'inherit',
})
const cacheGraphqlResult = spawnSync(
process.execPath,
[cliPath, 'cache-graphql', basePath],
{ stdio: 'inherit' }
)
if (cacheGraphqlResult.error || cacheGraphqlResult.status !== 0) {
throw new Error('Unable to run cache-graphql')
}
// generate-i18n will validate localization config and check if it's enabled
const generateI18nResult = spawnSync(
process.execPath,
[cliPath, 'generate-i18n', basePath],
{ stdio: 'inherit' }
)
if (generateI18nResult.error || generateI18nResult.status !== 0) {
throw new Error('Unable to run generate-i18n')
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/src/commands/dev.ts` around lines 201 - 210, The two spawnSync
invocations that run `node ${cliPath} cache-graphql ${basePath}` and `node
${cliPath} generate-i18n ${basePath}` are unsafe and don't check exit codes;
replace them with argv-style child calls using spawnSync(cliPath,
['cache-graphql', basePath], { shell: false, stdio: 'inherit' }) and
spawnSync(cliPath, ['generate-i18n', basePath], { shell: false, stdio: 'inherit'
}) (i.e., stop interpolating basePath into a shell string) and after each call
inspect the returned result.status/failure to abort (process.exit with the
non-zero status or throw) if the command failed so `dev` doesn't continue with
stale artifacts; update the locations where `cliPath`, `basePath`, and the
`cache-graphql`/`generate-i18n` spawnSync calls appear.

@lemagnetic
lemagnetic force-pushed the fix/monorepo-builds branch from 4b3e6c6 to eb2cca6 Compare April 6, 2026 15:50

@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: 1

♻️ Duplicate comments (1)
packages/cli/src/commands/build.ts (1)

72-75: ⚠️ Potential issue | 🟠 Major

Shell injection risk persists—use array arguments.

These subprocess calls embed basePath directly into shell strings. Paths containing spaces or shell metacharacters (;, $(), etc.) can break execution or enable command injection. This was flagged in a previous review.

,

Recommended fix: pass arguments as array
-    let scriptResult = spawnSync(`node ${binCli} generate ${basePath}`, {
-      shell: true,
-      stdio: 'inherit',
-    })
+    let scriptResult = spawnSync(
+      process.execPath,
+      [binCli, 'generate', basePath],
+      { stdio: 'inherit' }
+    )

-    scriptResult = spawnSync(`node ${binCli} cache-graphql ${basePath}`, {
-      shell: true,
-      stdio: 'inherit',
-    })
+    scriptResult = spawnSync(
+      process.execPath,
+      [binCli, 'cache-graphql', basePath],
+      { stdio: 'inherit' }
+    )

-    scriptResult = spawnSync(`node ${binCli} generate-i18n ${basePath}`, {
-      shell: true,
-      stdio: 'inherit',
-    })
+    scriptResult = spawnSync(
+      process.execPath,
+      [binCli, 'generate-i18n', basePath],
+      { stdio: 'inherit' }
+    )

Also applies to: 81-84, 94-97

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/src/commands/build.ts` around lines 72 - 75, The spawnSync calls
that build command strings (e.g., the call assigning scriptResult using
spawnSync(`node ${binCli} generate ${basePath}`, { shell: true, ... })) are
vulnerable to shell injection via basePath; change these to pass the executable
and arguments as an array (e.g., ['node', binCli, 'generate', basePath]) and
remove shell: true so the child process receives raw argv, preserving spaces and
preventing metacharacter expansion; apply the same fix to the other spawnSync
usages in this module that call node with binCli and basePath (the similar
blocks around the build/preview invocations).
🧹 Nitpick comments (1)
packages/cli/src/commands/build.ts (1)

150-164: Monorepo standalone normalization looks correct.

The logic properly handles the prefix-based path rewriting for monorepo builds where outputFileTracingRoot creates nested .faststore directories. The Promise.all with moveSync is synchronous despite the async wrapper—consider whether this is intentional.

The moveSync calls are synchronous, so wrapping them in Promise.all doesn't provide concurrency benefits. This works fine but could be simplified:

Optional: simplify to synchronous iteration
-    await Promise.all(
-      standaloneBuildFiles.map((file) =>
-        moveSync(
-          `${tmpDir}/.next/standalone/${prefix}.faststore/${file}`,
-          `${tmpDir}/.next/standalone/${file}`,
-          { overwrite: true }
-        )
-      )
-    )
+    for (const file of standaloneBuildFiles) {
+      moveSync(
+        `${tmpDir}/.next/standalone/${prefix}.faststore/${file}`,
+        `${tmpDir}/.next/standalone/${file}`,
+        { overwrite: true }
+      )
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/src/commands/build.ts` around lines 150 - 164, The Promise.all
wrapping the synchronous moveSync calls is misleading since moveSync is
blocking; update the monorepo standalone normalization in the block that checks
existsSync(`${tmpDir}/.next/standalone/${prefix}.faststore`) to use a plain
synchronous loop instead of Promise.all (e.g., forEach or for..of over
readdirSync result) to call moveSync for each file, then call removeSync as
before; this keeps behavior identical but removes the pointless async wrapper
around moveSync and clarifies intent (references: existsSync, readdirSync,
moveSync, Promise.all, removeSync, tmpDir, prefix).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/cli/src/commands/build.ts`:
- Around line 144-147: path.relative(process.cwd(), basePath) can return
backslashes on Windows causing wrong paths; when computing prefix in build.ts
(symbols: isRunningFromMonorepo, prefix, basePath, process.cwd(), path.relative)
normalize the relative path to forward slashes before appending '/' (e.g.
replace backslashes with '/' or use path.posix.join on the split segments) so
prefix is always using '/' separators for downstream template/path usage.

---

Duplicate comments:
In `@packages/cli/src/commands/build.ts`:
- Around line 72-75: The spawnSync calls that build command strings (e.g., the
call assigning scriptResult using spawnSync(`node ${binCli} generate
${basePath}`, { shell: true, ... })) are vulnerable to shell injection via
basePath; change these to pass the executable and arguments as an array (e.g.,
['node', binCli, 'generate', basePath]) and remove shell: true so the child
process receives raw argv, preserving spaces and preventing metacharacter
expansion; apply the same fix to the other spawnSync usages in this module that
call node with binCli and basePath (the similar blocks around the build/preview
invocations).

---

Nitpick comments:
In `@packages/cli/src/commands/build.ts`:
- Around line 150-164: The Promise.all wrapping the synchronous moveSync calls
is misleading since moveSync is blocking; update the monorepo standalone
normalization in the block that checks
existsSync(`${tmpDir}/.next/standalone/${prefix}.faststore`) to use a plain
synchronous loop instead of Promise.all (e.g., forEach or for..of over
readdirSync result) to call moveSync for each file, then call removeSync as
before; this keeps behavior identical but removes the pointless async wrapper
around moveSync and clarifies intent (references: existsSync, readdirSync,
moveSync, Promise.all, removeSync, tmpDir, prefix).
🪄 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: 98da6f8b-b56f-4109-b7f8-8ff41d998714

📥 Commits

Reviewing files that changed from the base of the PR and between 4b3e6c6 and eb2cca6.

📒 Files selected for processing (7)
  • packages/cli/src/commands/build.ts
  • packages/cli/src/commands/dev.ts
  • packages/cli/src/utils/directory.test.ts
  • packages/cli/src/utils/directory.ts
  • packages/cli/src/utils/generate-types.ts
  • packages/core/src/sdk/product/useProductGalleryQuery.ts
  • packages/sdk/src/index.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/core/src/sdk/product/useProductGalleryQuery.ts
  • packages/cli/src/commands/dev.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/cli/src/utils/generate-types.ts
  • packages/cli/src/utils/directory.ts

Comment thread packages/cli/src/commands/build.ts Resolved
@lemagnetic
lemagnetic merged commit 0070f89 into canary-v2 Apr 7, 2026
3 checks passed
@lemagnetic
lemagnetic deleted the fix/monorepo-builds branch April 7, 2026 16:46
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