[PR #590] [MERGED] feat(check): flag __dirname/__filename and suggest ESM path APIs #692

Closed
opened 2026-05-06 13:09:35 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/590
Author: @james-elicx
Created: 3/19/2026
Status: Merged
Merged: 3/19/2026
Merged by: @james-elicx

Base: mainHead: opencode/clever-tiger


📝 Commits (6)

  • a91c990 feat(check): flag __dirname/__filename and suggest ESM path APIs
  • 78be9b1 refactor(check): merge ViewTransition and __dirname scans into one file loop
  • 347ff51 Regex misses __dirname in template expressions.
  • 36058d1 fix(check): expose __dirname inside template expressions to identifier match
  • e6e1948 fix(check): use unsupported status for __dirname/__filename; show files in issues section
  • dee6700 remove files

📊 Changes

2 files changed (+161 additions, -2 deletions)

View changed files

📝 packages/vinext/src/check.ts (+42 -2)
📝 tests/check.test.ts (+119 -0)

📄 Description

Summary

  • Adds `__dirname` / `__filename` detection to `checkConventions` in `vinext check`
  • Reports an `unsupported` compatibility item listing affected files when CJS globals are found in server source (there is no vinext shim for these — they are a hard runtime failure)
  • Uses a single-pass alternation regex to skip string literals, template literals, and comments in one pass — identifiers inside those tokens are never matched, including inside `${...}` template expressions
  • Merges the new scan into the existing ViewTransition file loop so each source file is read only once
  • Fixes `formatReport` to list affected files under each item in the "Issues to address" section

Closes #583

Migration hint shown to users

`__dirname` / `__filename` are CommonJS globals unavailable in ESM — use `fileURLToPath(import.meta.url)` / `dirname(...)`, or `import.meta.dirname` / `import.meta.filename` (Node 22+)

Tests

9 new tests in `tests/check.test.ts` covering:

  • `__dirname` detected in a server file
  • `__filename` detected independently
  • Both globals in one file produce a single check item with `unsupported` status
  • `__dirname` inside a string literal → not flagged
  • `__dirname` inside a comment → not flagged
  • `__dirname` inside a plain template literal (no interpolation) → not flagged
  • `__dirname` inside a template expression `${__dirname}` → flagged
  • ESM reassignment pattern (`const __dirname = dirname(...)`) → no crash
  • Multiple files each listed in `files`
  • Affected file paths appear in the formatted report's "Issues to address" section

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/590 **Author:** [@james-elicx](https://github.com/james-elicx) **Created:** 3/19/2026 **Status:** ✅ Merged **Merged:** 3/19/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `opencode/clever-tiger` --- ### 📝 Commits (6) - [`a91c990`](https://github.com/cloudflare/vinext/commit/a91c9906d285b015e40e1a72e26d711f64636e05) feat(check): flag __dirname/__filename and suggest ESM path APIs - [`78be9b1`](https://github.com/cloudflare/vinext/commit/78be9b196ac707cebe3394d7a040c2d90a81dacf) refactor(check): merge ViewTransition and __dirname scans into one file loop - [`347ff51`](https://github.com/cloudflare/vinext/commit/347ff51204007625c35089ced7c5d5257bb8c70b) Regex misses `__dirname` in template expressions. - [`36058d1`](https://github.com/cloudflare/vinext/commit/36058d107ca7277a5fc12bb0bdc2508e91e32820) fix(check): expose __dirname inside template expressions to identifier match - [`e6e1948`](https://github.com/cloudflare/vinext/commit/e6e1948c6779b549d55b2f60c562336aae09055d) fix(check): use unsupported status for __dirname/__filename; show files in issues section - [`dee6700`](https://github.com/cloudflare/vinext/commit/dee67006c5047ccc9334dc035798aaf19bee8246) remove files ### 📊 Changes **2 files changed** (+161 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/check.ts` (+42 -2) 📝 `tests/check.test.ts` (+119 -0) </details> ### 📄 Description ## Summary - Adds \`__dirname\` / \`__filename\` detection to \`checkConventions\` in \`vinext check\` - Reports an \`unsupported\` compatibility item listing affected files when CJS globals are found in server source (there is no vinext shim for these — they are a hard runtime failure) - Uses a single-pass alternation regex to skip string literals, template literals, and comments in one pass — identifiers inside those tokens are never matched, including inside \`\${...}\` template expressions - Merges the new scan into the existing ViewTransition file loop so each source file is read only once - Fixes \`formatReport\` to list affected files under each item in the "Issues to address" section Closes #583 ## Migration hint shown to users > \`__dirname\` / \`__filename\` are CommonJS globals unavailable in ESM — use \`fileURLToPath(import.meta.url)\` / \`dirname(...)\`, or \`import.meta.dirname\` / \`import.meta.filename\` (Node 22+) ## Tests 9 new tests in \`tests/check.test.ts\` covering: - \`__dirname\` detected in a server file - \`__filename\` detected independently - Both globals in one file produce a single check item with \`unsupported\` status - \`__dirname\` inside a string literal → not flagged - \`__dirname\` inside a comment → not flagged - \`__dirname\` inside a plain template literal (no interpolation) → not flagged - \`__dirname\` inside a template expression \`\${__dirname}\` → flagged - ESM reassignment pattern (\`const __dirname = dirname(...)\`) → no crash - Multiple files each listed in \`files\` - Affected file paths appear in the formatted report's "Issues to address" section --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:09:35 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#692
No description provided.