Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import.meta.resolve support #14930

Merged
merged 11 commits into from
Mar 3, 2024
Merged

import.meta.resolve support #14930

merged 11 commits into from
Mar 3, 2024

Conversation

CheadleCheadle
Copy link
Contributor

@CheadleCheadle CheadleCheadle commented Feb 29, 2024

Summary

Fixes #14923

Jest and libraries support using import { createRequire } from 'node:module';
const require = createRequire(import.meta.url); to resolve relative paths.

This was a useful convention for a while, but now we have import.meta.resolve(…) to express a relative path resolution.

It is supported by all major browsers and all major runtimes.

import.meta.resolve Support: Jest now supports the import.meta.resolve function, allowing users to resolve module specifiers in a manner consistent with the standard JavaScript module system.

Test plan

Successfully resolves paths

Note: This is an initial, primitive implementation and currently supports basic resolution functionality. I am interested in what features such as support for dynamic string values should be incorporated.

foobar

foobarres

Copy link

netlify bot commented Feb 29, 2024

Deploy Preview for jestjs ready!

Name Link
🔨 Latest commit 8178a6a
🔍 Latest deploy log https://app.netlify.com/sites/jestjs/deploys/65e485113b035e0008470821
😎 Deploy Preview https://deploy-preview-14930--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

packages/jest-runtime/src/index.ts Outdated Show resolved Hide resolved
packages/jest-runtime/src/index.ts Outdated Show resolved Hide resolved
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Thanks! could you also add a changelog entry?

e2e/native-esm/__tests__/native-esm.test.js Outdated Show resolved Hide resolved
Copy link
Contributor Author

@CheadleCheadle CheadleCheadle left a comment

Choose a reason for hiding this comment

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

looks good to me!

@SimenB
Copy link
Member

SimenB commented Mar 3, 2024

From reading the docs, it seems

  1. it should actually be synchornous like you first had it - the types are wrong
  2. It should always return a file url (as a string)

I'll fix both 🙂

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

thanks!

@SimenB SimenB merged commit 442c7f6 into jestjs:main Mar 3, 2024
72 of 73 checks passed
Copy link

github-actions bot commented Apr 4, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support import.meta.resolve
2 participants