-
-
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
fix: add missing module.path
field to modules
#10615
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,8 +83,7 @@ const defaultTransformOptions: InternalModuleOptions = { | |
supportsStaticESM: false, | ||
}; | ||
|
||
type InitialModule = Partial<Module> & | ||
Pick<Module, 'children' | 'exports' | 'filename' | 'id' | 'loaded'>; | ||
type InitialModule = Omit<Module, 'require' | 'parent' | 'paths'>; | ||
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. might consider doing |
||
type ModuleRegistry = Map<string, InitialModule | Module>; | ||
|
||
const OUTSIDE_JEST_VM_RESOLVE_OPTION = Symbol.for( | ||
|
@@ -546,6 +545,7 @@ class Runtime { | |
filename: modulePath, | ||
id: modulePath, | ||
loaded: false, | ||
path: path.dirname(modulePath), | ||
}; | ||
moduleRegistry.set(modulePath, localModule); | ||
|
||
|
@@ -646,6 +646,7 @@ class Runtime { | |
filename: modulePath, | ||
id: modulePath, | ||
loaded: false, | ||
path: path.dirname(modulePath), | ||
}; | ||
|
||
this._loadModule( | ||
|
@@ -981,26 +982,27 @@ class Runtime { | |
return; | ||
} | ||
|
||
const filename = localModule.filename; | ||
const module = localModule as Module; | ||
|
||
const filename = module.filename; | ||
const lastExecutingModulePath = this._currentlyExecutingModulePath; | ||
this._currentlyExecutingModulePath = filename; | ||
const origCurrExecutingManualMock = this._isCurrentlyExecutingManualMock; | ||
this._isCurrentlyExecutingManualMock = filename; | ||
|
||
const dirname = path.dirname(filename); | ||
localModule.children = []; | ||
module.children = []; | ||
|
||
Object.defineProperty(localModule, 'parent', { | ||
Object.defineProperty(module, 'parent', { | ||
enumerable: true, | ||
get() { | ||
const key = from || ''; | ||
return moduleRegistry.get(key) || null; | ||
}, | ||
}); | ||
|
||
localModule.paths = this._resolver.getModulePaths(dirname); | ||
Object.defineProperty(localModule, 'require', { | ||
value: this._createRequireImplementation(localModule, options), | ||
module.paths = this._resolver.getModulePaths(module.path); | ||
Object.defineProperty(module, 'require', { | ||
value: this._createRequireImplementation(module, options), | ||
}); | ||
|
||
const transformedCode = this.transformFile(filename, options); | ||
|
@@ -1053,17 +1055,17 @@ class Runtime { | |
|
||
try { | ||
compiledFunction.call( | ||
localModule.exports, | ||
localModule as NodeModule, // module object | ||
localModule.exports, // module exports | ||
localModule.require as typeof require, // require implementation | ||
dirname, // __dirname | ||
filename, // __filename | ||
module.exports, | ||
module, // module object | ||
module.exports, // module exports | ||
module.require, // require implementation | ||
module.path, // __dirname | ||
module.filename, // __filename | ||
this._environment.global, // global object | ||
...lastArgs.filter(notEmpty), | ||
); | ||
} catch (error) { | ||
this.handleExecutionError(error, localModule); | ||
this.handleExecutionError(error, module); | ||
} | ||
|
||
this._isCurrentlyExecutingManualMock = origCurrExecutingManualMock; | ||
|
@@ -1168,6 +1170,7 @@ class Runtime { | |
filename, | ||
id: filename, | ||
loaded: false, | ||
path: path.dirname(filename), | ||
}); | ||
}; | ||
|
||
|
@@ -1606,7 +1609,7 @@ class Runtime { | |
].filter(notEmpty); | ||
} | ||
|
||
private handleExecutionError(e: Error, module: InitialModule): never { | ||
private handleExecutionError(e: Error, module: Module): never { | ||
const moduleNotFoundError = Resolver.tryCastModuleNotFoundError(e); | ||
if (moduleNotFoundError) { | ||
if (!moduleNotFoundError.requireStack) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
Partial
made this missing not be a type error