nodejs / nodejs/cjs-module-lexer
Unable to detect exports from bundled webpack output
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 262
- Forks
- 31
- Avg merge
- 9d 2h
- Merged PRs (30d)
- 5
Description
Title is probably inaccurate 😅
I recently added bundling to Jest, and it seems the output makes the lexer not detect exports correctly.
Specifically, it picks up the exports. stuff that is not exported, but not the exports within Object.definedProperty which actually are.
Quickest reproduction I have is to clone Jest, run yarn && yarn build:js then this:
const fs = require('fs');
const {parse} = require('cjs-module-lexer');
const source = fs.readFileSync(require.resolve('jest-watcher'), 'utf8');
console.log(parse(source));
This prints
{
exports: [
'default',
'KEYS',
'printPatternCaret',
'printRestoredPatternCaret'
],
reexports: []
}
Running the parser on the published version (29.7.0) gives this:
{
exports: [
'__esModule',
'BaseWatchPlugin',
'JestHook',
'PatternPrompt',
'Prompt',
'TestWatcher'
],
reexports: [ './constants', './lib/patternModeHelpers' ]
}
The reexports are of course gone as it's bundled, but we're also seeing that the lexer has detected only the resolved re-exports?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Clone the Jest revision linked in the issue, run yarn && yarn build:js, and reproduce the result with the shown cjs-module-lexer parse script. Compare the bundled output with the published package and trace how the lexer handles exports. and Object.defineProperty; done means bundled Jest exports are detected accurately without the false positives.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, webpack
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100