Skip to content

chore: change env filename used by generate-i18n and improve error message - #3222

Merged
lariciamota merged 2 commits into
feat/multilanguagefrom
chore/change-env-filename
Feb 25, 2026
Merged

lariciamota merged 2 commits into
feat/multilanguagefrom
chore/change-env-filename

Conversation

@lariciamota

@lariciamota lariciamota commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

The generate-i18n CLI command was loading credentials from .env instead of vtex.env, which is the FastStore-specific environment file. Additionally, the error message shown when credentials are missing was too vague, not telling developers where to look or what to do next.

How to test it?

Running node packages/cli/bin/run generate-i18n ./packages/core, test with and without the variables on vtex.env.

Or through a test account, running the build command:

Screenshot 2026-02-25 at 10 07 40

Starters Deploy Preview

PR: https://github.com/vtex-sites/brandless.store/pull/148
Even without the vtex.env it worked on production since those variables were set in Webops Settings:
Screenshot 2026-02-25 at 10 08 35

References

Summary by CodeRabbit

  • Bug Fixes
    • Improved credentials validation for the i18n command with clearer error messaging and earlier checks to fail fast.
    • Environment file loading now occurs conditionally at runtime, improving detection and configuration behavior.

@lariciamota lariciamota self-assigned this Feb 24, 2026
@lariciamota lariciamota added the enhancement New feature or request label Feb 24, 2026
@lariciamota
lariciamota marked this pull request as ready for review February 24, 2026 14:00
@lariciamota
lariciamota requested a review from a team as a code owner February 24, 2026 14:00
@lariciamota
lariciamota requested review from gabpaladino and renatamottam and removed request for a team February 24, 2026 14:00
@coderabbitai

coderabbitai Bot commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

The generate-i18n CLI now loads vtex.env at runtime (when present) and validates VTEX credentials (VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY, FS_DISCOVERY_APP_TOKEN) early in the command flow, before initializing FastStore SDK; module-level dotenv/config extraction was removed.

Changes

Cohort / File(s) Summary
Environment & Credentials Handling
packages/cli/src/commands/generate-i18n.ts
Removed module-scope dotenv.config and global credential extraction. Added runtime existsSync check and conditional dotenv.config() to load vtex.env; moved credential presence validation earlier with immediate error-and-exit on missing VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY, or FS_DISCOVERY_APP_TOKEN; retained passing validated creds to FastStore SDK initialization.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI (generate-i18n)
  participant FS as FileSystem
  participant Dotenv as Dotenv.loader
  participant Validator as Credentials Validator
  participant SDK as FastStoreSDK

  CLI->>FS: check for vtex.env (existsSync)
  alt vtex.env exists
    CLI->>Dotenv: dotenv.config(vtex.env)
    Dotenv-->>CLI: populate process.env
  end
  CLI->>Validator: read VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY, FS_DISCOVERY_APP_TOKEN
  Validator-->>CLI: valid? / error
  alt valid
    CLI->>SDK: initialize with validated creds
    SDK-->>CLI: ready
  else invalid
    CLI-->>CLI: log error + exit
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

Secrets fetched at runtime’s door,
dotenv whispers, then checks the core,
Credentials screened before SDK wakes,
Safe starts now — no fragile breaks. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: switching the environment file from .env to vtex.env and improving the error message for missing credentials.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/change-env-filename

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.

@codesandbox-ci

codesandbox-ci Bot commented Feb 24, 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.

@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

🤖 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/generate-i18n.ts`:
- Around line 84-103: The command currently logs and returns when VTEX
credentials are missing (vars VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY,
FS_DISCOVERY_APP_TOKEN) which may exit with code 0 and doesn’t narrow types for
SDK init; replace the boolean hasCredentials check with a direct guard that
reads the three env vars into consts (VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY,
FS_DISCOVERY_APP_TOKEN), log the existing message via logger.error (using
vtexEnvPath/dotenv.config as needed), then immediately call process.exit(1) to
return a non-zero status so the process fails loudly and the three consts can be
used as definitely-assigned (non-null) values when initializing the SDK.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5da1a3c and 94a0a49.

📒 Files selected for processing (1)
  • packages/cli/src/commands/generate-i18n.ts

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

♻️ Duplicate comments (1)
packages/cli/src/commands/generate-i18n.ts (1)

89-93: Use a direct credential guard to preserve TypeScript narrowing.

Line 91-94 still uses hasCredentials; this pattern doesn’t narrow VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY, and FS_DISCOVERY_APP_TOKEN as strongly as a direct if (!A || !B || !C) guard.

Suggested minimal refactor (no behavior change)
     const { VTEX_ACCOUNT, FS_DISCOVERY_APP_KEY, FS_DISCOVERY_APP_TOKEN } =
       process.env
-    const hasCredentials =
-      VTEX_ACCOUNT && FS_DISCOVERY_APP_KEY && FS_DISCOVERY_APP_TOKEN
-
-    if (!hasCredentials) {
+    if (!VTEX_ACCOUNT || !FS_DISCOVERY_APP_KEY || !FS_DISCOVERY_APP_TOKEN) {
       logger.error(`${chalk.red('[Error]')} - Missing VTEX credentials.\n
       ${chalk.cyan('Required Action:')}\n
       Check your FastStore WebOps Settings page - to work in production, it should contain the following variables: ${chalk.cyan('VTEX_ACCOUNT')}, ${chalk.cyan('FS_DISCOVERY_APP_KEY')}, ${chalk.cyan('FS_DISCOVERY_APP_TOKEN')}.\n
       If running locally, please check your ${chalk.bold('vtex.env')} file, it should also contain those variables.
       `)

       process.exit(1)
     }
In TypeScript control-flow analysis, does `const ok = a && b && c; if (!ok) return;` narrow `a`, `b`, and `c` to non-undefined for subsequent lines?

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/generate-i18n.ts` around lines 89 - 93, Replace the
intermediate boolean `hasCredentials` guard with a direct conditional check so
TypeScript properly narrows `VTEX_ACCOUNT`, `FS_DISCOVERY_APP_KEY`, and
`FS_DISCOVERY_APP_TOKEN`; specifically, after extracting those env vars (the
consts named `VTEX_ACCOUNT`, `FS_DISCOVERY_APP_KEY`, `FS_DISCOVERY_APP_TOKEN`)
change the flow to `if (!VTEX_ACCOUNT || !FS_DISCOVERY_APP_KEY ||
!FS_DISCOVERY_APP_TOKEN) return` (or the equivalent early-return guard) and
remove `hasCredentials` so subsequent code can rely on narrowed, non-undefined
types.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/cli/src/commands/generate-i18n.ts`:
- Around line 89-93: Replace the intermediate boolean `hasCredentials` guard
with a direct conditional check so TypeScript properly narrows `VTEX_ACCOUNT`,
`FS_DISCOVERY_APP_KEY`, and `FS_DISCOVERY_APP_TOKEN`; specifically, after
extracting those env vars (the consts named `VTEX_ACCOUNT`,
`FS_DISCOVERY_APP_KEY`, `FS_DISCOVERY_APP_TOKEN`) change the flow to `if
(!VTEX_ACCOUNT || !FS_DISCOVERY_APP_KEY || !FS_DISCOVERY_APP_TOKEN) return` (or
the equivalent early-return guard) and remove `hasCredentials` so subsequent
code can rely on narrowed, non-undefined types.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94a0a49 and fb03d6a.

📒 Files selected for processing (1)
  • packages/cli/src/commands/generate-i18n.ts

@lemagnetic lemagnetic 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.

nice

@lariciamota
lariciamota merged commit 75d6bbc into feat/multilanguage Feb 25, 2026
4 checks passed
@lariciamota
lariciamota deleted the chore/change-env-filename branch February 25, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants