Skip to content

Fix for issue #4807: Include JSON file relative imports in dashboard dev mode compilation#4808

Open
StefanOrzu wants to merge 2 commits into
vendurehq:masterfrom
StefanOrzu:dashboard-vite-json-import-fix
Open

Fix for issue #4807: Include JSON file relative imports in dashboard dev mode compilation#4808
StefanOrzu wants to merge 2 commits into
vendurehq:masterfrom
StefanOrzu:dashboard-vite-json-import-fix

Conversation

@StefanOrzu

@StefanOrzu StefanOrzu commented Jun 6, 2026

Copy link
Copy Markdown

Description

Added the inclusion of JSON files when transpiling vendure-config.ts and its imports during the dashboard app compilation phase. Collected JSON files aren't transpiled per se - they're just passed through as-is.

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

… vite-config.ts includes a custom plugin that imports a JSON file from a relative path.
@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vendure-storybook Ready Ready Preview, Comment Jun 14, 2026 7:53pm

Request Review

@vendure-ci-automation-bot

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Worried about impact? Review this PR in Change Stack to explore blast radius before you approve or request changes.

Review Change Stack

📝 Walkthrough

Walkthrough

This PR modifies the TypeScript compilation utility in the dashboard's Vite configuration to support JSON files. The change expands the source file filter to recognize .json files as valid source inputs, then adds conditional logic in the per-file transpilation loop to emit JSON content directly without passing it through the TypeScript transpiler. Other file types (.ts, .tsx, .js, .jsx) continue to use the standard transpilation pipeline.

🚥 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 PR title clearly and specifically describes the main change: including JSON files in dashboard dev mode compilation, which directly aligns with the code changes in compiler.ts.
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 The PR description covers the main change (JSON file inclusion in transpilation) and completes required checklist items, though it lacks a 'Breaking changes' section from the template.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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

🧹 Nitpick comments (1)
packages/dashboard/vite/utils/compiler.ts (1)

261-267: ⚡ Quick win

Skip AST parsing for JSON files to improve performance and avoid edge cases.

After expanding the filter to include .json files (line 261), the function proceeds to parse JSON content as a TypeScript AST (line 267) and search for import/export declarations. Since JSON files cannot contain import or export statements, this parsing step is unnecessary overhead.

Skipping AST parsing for JSON files will improve performance and eliminate potential edge cases if non-standard JSON (e.g., with comments) is encountered.

⚡ Proposed optimization
     if (visited.has(resolved)) return;
     visited.add(resolved);
 
+    // JSON files have no imports to follow - skip AST parsing
+    if (resolved.endsWith('.json')) return;
+
     const content = await fs.readFile(resolved, 'utf-8');
     const sf = ts.createSourceFile(resolved, content, ts.ScriptTarget.Latest, true);
🤖 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/dashboard/vite/utils/compiler.ts` around lines 261 - 267, The code
currently treats .json files like code and calls ts.createSourceFile on them
(see resolved, content, sf), which is unnecessary and slow; update the logic so
that after resolving and reading the file (resolved, content) you skip AST
parsing for JSON files — e.g., detect /\.json$/ on resolved (or content) and
return early before calling ts.createSourceFile/searching for import/export
declarations — leaving other extensions (ts/tsx/js/jsx) unchanged.
🤖 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.

Nitpick comments:
In `@packages/dashboard/vite/utils/compiler.ts`:
- Around line 261-267: The code currently treats .json files like code and calls
ts.createSourceFile on them (see resolved, content, sf), which is unnecessary
and slow; update the logic so that after resolving and reading the file
(resolved, content) you skip AST parsing for JSON files — e.g., detect /\.json$/
on resolved (or content) and return early before calling
ts.createSourceFile/searching for import/export declarations — leaving other
extensions (ts/tsx/js/jsx) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4dd59b3a-2682-4aff-84b3-ab61fcff0a74

📥 Commits

Reviewing files that changed from the base of the PR and between 8a8f8b9 and efe13f3.

📒 Files selected for processing (1)
  • packages/dashboard/vite/utils/compiler.ts

@michaelbromley

Copy link
Copy Markdown
Member

Hi, can you provide some information about the use-case that this PR is addressing? Thanks!

@StefanOrzu

StefanOrzu commented Jun 14, 2026

Copy link
Copy Markdown
Author

Hi, can you provide some information about the use-case that this PR is addressing? Thanks!

I have a couple of custom plugins in my project (one for connecting to Google Sheets to upload some order data in a sheet, and one for connecting to a shipping service to get quotes for shipments), and I'm instantiating each of these plugins with some configuration objects. These objects contain information like client ids, api keys, etc, which can vary based on deployment.

In my case, the simplest approach is to simply import these config objects fom json files which I can populate during the Docker build based on the target environment. I can do this via readFileSync, but this adds extra burden of manually copying each of these json files into the dist directory after building the Vendure project, and also introduces type unsafety when parsing the configs.

I think it's much more handy to be able to do import myConfig from './my-config.json';, which automatically pulls the file into dist at compile time, and makes the code typesafe when passing myConfig to a init(config: MyConfig) method.

@michaelbromley

Copy link
Copy Markdown
Member

Hi @StefanOrzu thanks for the explanation.

Can you add a test to this?

The suite is fixture-driven (vite/tests/*.spec.ts), so a fixtures-json-import/ with a config that imports a ./config.json + an assertion that the JSON lands in the output dir is straightforward and mirrors every other scenario. Should be a merge requirement given how cheap it is.

Also, you need to sign the CLA as per this comment before the PR can be merged. Cheers!

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