Skip to content

♻️ Replace fileURLToPath patterns with import.meta.*#6437

Merged
dubzzz merged 8 commits into
mainfrom
copilot/fix-convoluted-file-paths
Jan 15, 2026
Merged

♻️ Replace fileURLToPath patterns with import.meta.*#6437
dubzzz merged 8 commits into
mainfrom
copilot/fix-convoluted-file-paths

Conversation

Copilot AI commented Jan 8, 2026

Copy link
Copy Markdown
Contributor
  • Verify Node.js version compatibility
  • Replace fileURLToPath(new URL('.', import.meta.url)) with import.meta.dirname in code files
  • Replace fileURLToPath(import.meta.url) with import.meta.filename in code files
  • Inline import.meta.dirname and import.meta.filename directly instead of using intermediate variables
  • Update documentation to use modern syntax for ES modules
  • Keep CommonJS examples using __filename (not available as import.meta.* in CJS)
  • Update JSDoc comments in source code
  • Remove unnecessary imports of fileURLToPath and url modules
  • Position @ts-expect-error --module must be higher comments on the line before path.join for better readability
  • Run tests to ensure changes work correctly
  • Run lint and build to ensure no issues
  • Address all code review feedback
  • Ensure documentation accurately reflects ES module vs CommonJS patterns
Original prompt

I may have some places in the code or the doc that want to achieve fileName or dirname but do it with a convoluted syntax. could you fix them using these shorter syntaxes:

CommonJS ESM Equivalent Minimum Node.js Version
__filename import.meta.filename v20.11.0 / v21.2.0
__dirname import.meta.dirname v20.11.0 / v21.2.0
require.main import.meta.main v22.18.0 / v24.2.0
require.resolve import.meta.resolve v12.16.2+


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@changeset-bot

changeset-bot Bot commented Jan 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f42b277

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI changed the title [WIP] Fix convoluted syntax for fileName and dirname ♻️ Replace fileURLToPath patterns with import.meta.filename/dirname Jan 8, 2026
Copilot AI requested a review from dubzzz January 8, 2026 23:19
Comment thread packages/ava/test/main.spec.ts
Copilot AI requested a review from dubzzz January 9, 2026 07:47
@dubzzz

dubzzz commented Jan 15, 2026

Copy link
Copy Markdown
Owner

@copilot make sure you have not missed any place inclkuding doc files

@dubzzz
dubzzz marked this pull request as ready for review January 15, 2026 16:42
@dubzzz dubzzz changed the title ♻️ Replace fileURLToPath patterns with import.meta.filename/dirname ♻️ Replace fileURLToPath patterns with import.meta.<name> Jan 15, 2026
@dubzzz dubzzz changed the title ♻️ Replace fileURLToPath patterns with import.meta.<name> ♻️ Replace fileURLToPath patterns with import.meta.* Jan 15, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jan 15, 2026

Copy link
Copy Markdown
@fast-check/ava

npm i https://pkg.pr.new/@fast-check/ava@6437

@fast-check/expect-type

npm i https://pkg.pr.new/@fast-check/expect-type@6437

fast-check

npm i https://pkg.pr.new/fast-check@6437

@fast-check/jest

npm i https://pkg.pr.new/@fast-check/jest@6437

@fast-check/packaged

npm i https://pkg.pr.new/@fast-check/packaged@6437

@fast-check/poisoning

npm i https://pkg.pr.new/@fast-check/poisoning@6437

@fast-check/vitest

npm i https://pkg.pr.new/@fast-check/vitest@6437

@fast-check/worker

npm i https://pkg.pr.new/@fast-check/worker@6437

commit: f42b277

@github-actions

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot make sure you have not missed any place inclkuding doc files

Verified all files including documentation. No places were missed:

✅ All ES module code files use inlined import.meta.dirname and import.meta.filename
✅ All CommonJS files correctly use __dirname and __filename
✅ Documentation (README.md files, ecosystem.md) shows correct patterns for both ESM and CJS
✅ No intermediate variables remain (const __dirname = ...)
✅ No old fileURLToPath(new URL(...)) patterns found
✅ No unnecessary url module imports

The only remaining uses of new URL(import.meta.url) are correct - they're for API calls like propertyFor() and init() which expect URL objects, not file paths.

Copilot AI requested a review from dubzzz January 15, 2026 16:46
// @ts-expect-error --module must be higher
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const avaPackageRoot = path.join(__dirname, '..');
const avaPackageRoot = path.join(import.meta.dirname, '..');

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot add back the expect error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added back the @ts-expect-error --module must be higher comments to all test files that had them before (ava, jest, vitest, packaged). (1d7ee1e)

Copilot AI requested a review from dubzzz January 15, 2026 22:35
declare const jestExpect: typeof _jestExpect;

// @ts-expect-error --module must be higher
const generatedTestsDirectoryName = '.test-artifacts';

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot move expect error on the line right before import.meta

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved the @ts-expect-error comments to be right before import.meta.dirname on all affected files (ava, jest, vitest, packaged). (9755265)

Comment thread packages/ava/test/main.spec.ts Outdated
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const avaPackageRoot = path.join(__dirname, '..');
const avaPackageRoot = path.join(
// @ts-expect-error --module must be higher

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot move expect on the line before path join so that the display would be nicer with join and import staying together on the same line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved the @ts-expect-error comment to the line before path.join so that path.join(import.meta.dirname, ...) stays on one line for better readability. (f42b277)

@dubzzz
dubzzz enabled auto-merge (squash) January 15, 2026 22:48
@github-actions

Copy link
Copy Markdown
Contributor

@dubzzz
dubzzz merged commit 8f9025b into main Jan 15, 2026
45 checks passed
@dubzzz
dubzzz deleted the copilot/fix-convoluted-file-paths branch January 15, 2026 22:57
@codecov

codecov Bot commented Jan 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.84%. Comparing base (4a27525) to head (f42b277).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6437   +/-   ##
=======================================
  Coverage   94.84%   94.84%           
=======================================
  Files         207      207           
  Lines        5567     5567           
  Branches     1456     1456           
=======================================
  Hits         5280     5280           
  Misses        274      274           
  Partials       13       13           
Flag Coverage Δ
tests 94.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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