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

Add support for the "module" package.json field #2704

Closed
wants to merge 4 commits into from

Conversation

quantizor
Copy link
Contributor

This is used in modern es module codebases to designate the entry point for code that makes use of import/export instead of commonjs. Jest doesn't need to care about whether or not that destination code is actually an ES module, just that the path gets resolved 🙃

Closes #2702

@jest-bot
Copy link
Contributor

jest-bot commented Jan 26, 2017

Warnings
⚠️ Please ensure that @flow is enabled on: examples/module-field/sample/correct.js and examples/module-field/sample/wrong.js

Generated by 🚫 dangerJS

@codecov-io
Copy link

codecov-io commented Jan 26, 2017

Codecov Report

Merging #2704 into master will decrease coverage by -0.08%.

@@            Coverage Diff             @@
##           master    #2704      +/-   ##
==========================================
- Coverage   67.51%   67.43%   -0.08%     
==========================================
  Files         142      142              
  Lines        5094     5101       +7     
==========================================
+ Hits         3439     3440       +1     
- Misses       1655     1661       +6
Impacted Files Coverage Δ
packages/jest-config/src/validConfig.js 100% <ø> (ø)
packages/jest-config/src/defaults.js 100% <ø> (ø)
packages/jest-runtime/src/index.js 85.02% <ø> (ø)
packages/jest-config/src/normalize.js 85.51% <ø> (ø)
packages/jest-resolve/src/index.js 0% <ø> (ø)
packages/jest-cli/src/watch.js 74.13% <ø> (-1.76%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 204e46c...8f9514a. Read the comment docs.

@quantizor
Copy link
Contributor Author

I added a test 🤷‍♂️

@quantizor
Copy link
Contributor Author

@cpojer could you review? :)

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Could you also add a brief explanation in docs about this and why is it helpful?
I'd also ask for a little patience, because we're focusing on rolling out new release.

path,
{
basedir: options.basedir,
extensions: options.extensions,
moduleDirectory: options.moduleDirectory,
packageFilter: options.module ? packageJson => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit, Jest uses this style:

condition 
  ? truth 
  : false

@quantizor
Copy link
Contributor Author

quantizor commented Feb 2, 2017

@thymikee All set. I'd love to get this in the next release if possible... it helps greatly when working on lerna codebases so you don't have to prebuild every package before running tests on packages with deps on other packages.

@quantizor
Copy link
Contributor Author

Rebased

@cpojer
Copy link
Member

cpojer commented Feb 10, 2017

Hey @yaycmyk. Thanks for your PR. Can you go into more detail where this is used and how this is a standard?

We are planning on releasing Jest 19 next week but I'm afraid if you want to get this in, I'd ask you to make a breaking change to Jest to make sure we aren't adding more options. I would be happy to support this feature and the browser resolution feature if they are merged into one config, like this:

packageResolution: ['module', 'browser']

This would prefer the "module" field over the "browser" field or the default. This will also enable things like react-native support, this way:

packageResolution: ['react-native', 'module']

What do you think?

@quantizor
Copy link
Contributor Author

quantizor commented Feb 10, 2017

Oh I'm totally into that, sure. I'll make that change by Sunday. See followup comment.

@quantizor
Copy link
Contributor Author

quantizor commented Feb 10, 2017

@cpojer one wrinkle here: browser is actually a different data structure. "main" and "module" are a single file path, whereas browser is an object of paths/module names pointing to other paths.

For example:

{
  "browser": {
    "build/foo.js": "build/foo.umd.js"
  },
  "main": "build/foo.js",
  "module": "foo.js"
}

I suppose I could write a resolver that handles both cases, but it would require more extensive changes.

Evan Scott added 4 commits February 25, 2017 12:06
I tested the regex thoroughly, so I think it's just a matter of
usage. Regex.test() has some weird semantics if its run over the
same string twice... so switched to match() instead.
This is used in modern es module codebases to designate the entry
point for code that makes use of import/export instead of commonjs.
It's used by a lot more bundlers than Browserify, so I removed
that specification.
@quantizor
Copy link
Contributor Author

This PR has been largely ignored, so I'm just going to close it.

@quantizor quantizor closed this Mar 18, 2017
@SimenB
Copy link
Member

SimenB commented Oct 21, 2017

@probablyup if you're still up for it, I'd love to have this land. Mind reopening and rebasing?

@GioSensation
Copy link

@probablyup Any update on this? Will you reopen the PR?

@quantizor
Copy link
Contributor Author

quantizor commented Jan 30, 2018 via email

@SimenB
Copy link
Member

SimenB commented Feb 7, 2018

For those following along: #5485

@github-actions
Copy link

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 May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support the "module" package.json field
8 participants