Skip to content

Conversation

teemingc
Copy link
Contributor

@teemingc teemingc commented Sep 25, 2025

Closes sveltejs/svelte.dev#1410
Closes #1662
Closes sveltejs/svelte.dev#1536

📑 Description

This PR swaps out the use of import.meta.env.MODE with esm-env. This makes the library work with environments that don't have import.meta.env.MODE. esm-env is also what SvelteKit uses for dev mode checks.

No test because I've no idea how to remove import.meta.env when importing the module in Vitest.

Status

  • Not Completed
  • Completed

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation and api-check directory as required
  • All the tests and check have passed by running pnpm check && pnpm test:e2e
  • My pull request is based on the latest commit (not the npm version).
  • I have checked the page with https://validator.unl.edu/

ℹ Additional Information

Summary by CodeRabbit

  • Chores
    • Added a runtime dependency to centralize environment detection.
    • Dev-mode warnings/diagnostics now use that external environment flag.
    • No user-facing UI or feature changes are expected; behavior for end users remains the same.

Copy link

vercel bot commented Sep 25, 2025

@teemingc is attempting to deploy a commit to the Themesberg Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

Added the "esm-env" runtime dependency and switched theme deprecation gating to use the exported DEV flag from that package instead of an in-file dev check.

Changes

Cohort / File(s) Summary
Dependencies update
package.json
Added dependency: esm-env ^1.2.2.
Theme utils change
src/lib/theme/themeUtils.ts
Import DEV from esm-env and replace local/dev-mode check with the imported DEV constant in warnThemeDeprecation. Removed previous inline/dev comment and related local dev logic.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant ThemeUtils as ThemeUtils
  participant ESM as esm-env

  Note over ThemeUtils,ESM #d6f5d6: New runtime flag import

  ThemeUtils->>ESM: import { DEV }
  ThemeUtils->>ThemeUtils: call warnThemeDeprecation(...)
  alt DEV === true
    ThemeUtils->>ThemeUtils: emit console warning
  else DEV === false
    ThemeUtils-->>ThemeUtils: no warning emitted
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hopped in the code with a twitchy nose,
Found one little flag where the dev-mode grows.
Pulled in esm-env, gave DEV a wave,
Quietly tidy, no functions to save.
🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning While the PR replaces the runtime environment check with esm-env, it does not address the import resolution errors described in issues #1410 and #1662, which stem from missing theme files in the distributed package rather than the runtime flag check. As a result, the core objectives of ensuring the dist/theme directory is correctly included and importable in playground and REPL environments are unmet. To resolve the linked issues, adjust the build or packaging configuration to include the dist/theme folder and ensure Svelte’s module resolver can locate Theme.svelte, eliminating the import error in cloud-based repls and playgrounds.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change of swapping out import.meta.env.MODE for the esm-env package, which directly reflects the modifications in the code. It is clear, specific, and free of extraneous details, enabling team members to immediately understand the intent of the pull request.
Out of Scope Changes Check ✅ Passed All code changes are confined to replacing the development-mode check and adding the esm-env dependency, which directly relates to removing reliance on import.meta.env.MODE and introduces no unrelated modifications. There are no extraneous changes beyond the stated objectives of this pull request.
Description Check ✅ Passed The pull request description mirrors the repository’s template by listing closed issues, providing a concise summary under the Description heading, indicating the completion status, enumerating the checks, and including an Additional Information section. All required sections are present and properly labeled, ensuring clarity for reviewers.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68a2d5e and ec98f6e.

📒 Files selected for processing (1)
  • src/lib/theme/themeUtils.ts (2 hunks)
🔇 Additional comments (1)
src/lib/theme/themeUtils.ts (1)

4-26: DEV gating via esm-env looks good

Switching to esm-env aligns with SvelteKit’s environment detection and removes the brittle import.meta.env.MODE dependency. Nice improvement.


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99eeb88 and 68a2d5e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json (1 hunks)

"apexcharts": "^5.3.5",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
"esm-env": "^1.2.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

LGTM on adding esm-env; verify usages are updated and add a changeset

Good call moving away from import.meta.env.MODE. Please:

  • Replace all import.meta.env.MODE checks with import { dev } from 'esm-env' (or prod/test as needed).
  • Add a Changeset (patch) noting the fix for REPL/Playground compatibility.

Run this script to confirm there are no lingering import.meta.env usages and that esm-env is actually imported:

Also verify the chosen version is current:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "1) Searching for import.meta.env.MODE"
rg -nP -C2 '\bimport\.meta\.env\.MODE\b' || echo "OK: none found"

echo -e "\n2) Searching for any import.meta.env usage"
rg -nP -C2 '\bimport\.meta\.env\b' || echo "OK: none found"

echo -e "\n3) Confirming esm-env imports exist"
rg -nP -C2 "(?:from|import)\\s+['\"]esm-env['\"]|from\\s+['\"]esm-env['\"]" || echo "WARN: no esm-env imports found"

echo -e "\n4) Check for a pending Changeset"
fd -H -t f '.changeset' -E '.changeset/README.md' | wc -l | awk '{print "changeset files:", $1}'

Length of output: 1020


🌐 Web query:

What is the latest version of the npm package "esm-env"?

💡 Result:

Latest version: 1.2.2. [1][2] (npmjs.com)

Citations:


Replace remaining import.meta.env.MODE usage with esm-env and add a changeset

  • In src/lib/theme/themeUtils.ts (line 6), remove the import.meta.env.MODE check and instead import { dev } from 'esm-env' (use prod/test as appropriate).
  • Create a new Changeset (patch) documenting the REPL/Playground compatibility fix.
🤖 Prompt for AI Agents
In package.json (around line 155) and in src/lib/theme/themeUtils.ts (line 6),
replace the runtime check using import.meta.env.MODE with the esm-env export:
remove any import.meta.env.MODE usage and instead import the appropriate flag
from 'esm-env' (e.g., import { dev } from 'esm-env' — or prod/test if that
matches the intended branch) and use that boolean in the existing conditional
logic; then add a new Changeset (patch) describing the REPL/Playground
compatibility fix (one-line summary and bump type patch) so consumers see the
change.

@shinokada shinokada merged commit 0ff3894 into themesberg:main Sep 25, 2025
1 check failed
@shinokada
Copy link
Collaborator

I still get the following error:

Could not find dist/ in [email protected] (error occurred while trying to resolve .. within npm://$/[email protected]/dist/theme/themeUtils.js)

image

@teemingc
Copy link
Contributor Author

I still get the following error:

Could not find dist/ in [email protected] (error occurred while trying to resolve .. within npm://$/[email protected]/dist/theme/themeUtils.js)
image

You're right. The error still occurs https://svelte.dev/playground/598dd47bf2cd4c728dfcae1573d893c6?version=5.35.4 I'll continue to investigate. Thanks.

We should probably re-open #1662

@teemingc teemingc mentioned this pull request Sep 25, 2025
8 tasks
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.

Svelte REPL problem Playground import issue
2 participants