-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 #5485
Changes from all commits
88d8f5c
b11f76e
91a3f40
b3a6a26
7965fac
044ab23
faa7f08
f03f004
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["env"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. All rights reserved. | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
import { connect } from 'react-redux'; | ||
import Contents from '../sample'; | ||
|
||
describe('module field resolution', () => { | ||
it('should return the correct file exports', () => { | ||
expect(typeof connect).toBe('function'); | ||
expect(Contents).toBe('👏'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"devDependencies": { | ||
"babel-preset-env": "*", | ||
"jest": "*" | ||
}, | ||
"jest": { | ||
"module": true | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"react-redux": "^5.0.6", | ||
"redux": "^3.7.2" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. All rights reserved. | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
export default '👏'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"main": "wrong.js", | ||
"module": "correct.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. All rights reserved. | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
module.exports = '😒'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,7 +177,7 @@ export default class ScriptTransformer { | |
} | ||
} | ||
|
||
transformSource(filepath: Path, content: string, instrument: boolean) { | ||
transformSource(filepath: Path, content: string, instrument: boolean, isRequiredByModuleField: boolean) { | ||
const filename = this._getRealPath(filepath); | ||
const transform = this._getTransformer(filename); | ||
const cacheFilePath = this._getFileCachePath(filename, content, instrument); | ||
|
@@ -214,7 +214,7 @@ export default class ScriptTransformer { | |
map: null, | ||
}; | ||
|
||
if (transform && shouldCallTransform) { | ||
if (isRequiredByModuleField || (transform && shouldCallTransform)) { | ||
const processed = transform.process(content, filename, this._config, { | ||
instrument, | ||
returnSourceString: false, | ||
|
@@ -283,16 +283,21 @@ export default class ScriptTransformer { | |
let mapCoverage = false; | ||
|
||
const willTransform = | ||
!isInternalModule && | ||
!isCoreModule && | ||
(shouldTransform(filename, this._config) || instrument); | ||
options.isRequiredByModuleField || | ||
( | ||
!isInternalModule && | ||
!isCoreModule && | ||
(shouldTransform(filename, this._config) || instrument) | ||
); | ||
|
||
try { | ||
if (willTransform) { | ||
const transformedSource = this.transformSource( | ||
filename, | ||
content, | ||
instrument, | ||
options.isRequiredByModuleField, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Twice within the same file or same code path? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same code path. |
||
!!(options && options.mapCoverage), | ||
); | ||
|
||
wrappedCode = wrap(transformedSource.code); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly I reverted to keeping a local CACHE singleton here, if you have any ideas, please let me know as well!