-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: have a single hooks thread for all workers
- Loading branch information
Showing
10 changed files
with
226 additions
and
55 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ const { ModuleWrap, kEvaluating, kEvaluated } = internalBinding('module_wrap'); | |
const { | ||
urlToFilename, | ||
} = require('internal/modules/helpers'); | ||
const { isMainThread } = require('worker_threads'); | ||
let defaultResolve, defaultLoad, defaultLoadSync, importMetaInitializer; | ||
|
||
/** | ||
|
@@ -594,10 +595,11 @@ class CustomizedModuleLoader { | |
*/ | ||
constructor() { | ||
getHooksProxy(); | ||
_hasCustomizations = true; | ||
} | ||
|
||
/** | ||
* Register some loader specifier. | ||
* Register a loader specifier. | ||
* @param {string} originalSpecifier The specified URL path of the loader to | ||
* be registered. | ||
* @param {string} parentURL The parent URL from where the loader will be | ||
|
@@ -608,7 +610,11 @@ class CustomizedModuleLoader { | |
* @returns {{ format: string, url: URL['href'] }} | ||
*/ | ||
register(originalSpecifier, parentURL, data, transferList) { | ||
return hooksProxy.makeSyncRequest('register', transferList, originalSpecifier, parentURL, data); | ||
if (isMainThread) { | ||
// only the main thread has a Hooks instance with worker thread. All other Worker threads | ||
Check warning on line 614 in lib/internal/modules/esm/loader.js GitHub Actions / lint-js-and-md
|
||
// delegate thier hooks to the HooksThread of the main thread. | ||
return hooksProxy.makeSyncRequest('register', transferList, originalSpecifier, parentURL, data); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -617,7 +623,7 @@ class CustomizedModuleLoader { | |
* be resolved. | ||
* @param {string} [parentURL] The URL path of the module's parent. | ||
* @param {ImportAttributes} importAttributes Attributes from the import | ||
* statement or expression. | ||
* statement or exp-ression. | ||
* @returns {{ format: string, url: URL['href'] }} | ||
*/ | ||
resolve(originalSpecifier, parentURL, importAttributes) { | ||
|
@@ -706,6 +712,12 @@ function getHooksProxy() { | |
return hooksProxy; | ||
} | ||
|
||
let _hasCustomizations = false; | ||
function hasCustomizations() { | ||
return _hasCustomizations; | ||
} | ||
|
||
|
||
let cascadedLoader; | ||
|
||
/** | ||
|
@@ -767,6 +779,7 @@ function register(specifier, parentURL = undefined, options) { | |
|
||
module.exports = { | ||
createModuleLoader, | ||
hasCustomizations, | ||
getHooksProxy, | ||
getOrInitializeCascadedLoader, | ||
register, | ||
|
Oops, something went wrong.