* This class covers the base machinery of module loading. There are two types of loader hooks: * 1. Asynchronous loader hooks, which are run in a separate loader hook worker thread. * This is configured in #asyncLoaderHooks. * 2. Synchronous loader hooks, which are run in-thread. This is share
| 136 | * stored in the cross-module syncResolveHooks and syncLoadHooks arrays. |
| 137 | */ |
| 138 | class ModuleLoader { |
| 139 | /** |
| 140 | * The conditions for resolving packages if `--conditions` is not used. |
| 141 | */ |
| 142 | #defaultConditions = getDefaultConditions(); |
| 143 | |
| 144 | /** |
| 145 | * Registry of resolved specifiers |
| 146 | */ |
| 147 | #resolveCache = new ResolveCache(); |
| 148 | |
| 149 | /** |
| 150 | * Registry of loaded modules, akin to `require.cache` |
| 151 | */ |
| 152 | loadCache = new LoadCache(); |
| 153 | |
| 154 | /** |
| 155 | * @see {AsyncLoaderHooks.isForAsyncLoaderHookWorker} |
| 156 | * Shortcut to this.#asyncLoaderHooks.isForAsyncLoaderHookWorker. |
| 157 | */ |
| 158 | isForAsyncLoaderHookWorker = false; |
| 159 | |
| 160 | /** |
| 161 | * Asynchronous loader hooks to pass requests to. |
| 162 | * |
| 163 | * Note that this value _MUST_ be set with `#setAsyncLoaderHooks` |
| 164 | * because it needs to copy `#asyncLoaderHooks.isForAsyncLoaderHookWorker` |
| 165 | * to this property. |
| 166 | * TODO(joyeecheung): this was a legacy of the previous setup of import.meta.resolve |
| 167 | * configuration; put this information in the environment directly instead. |
| 168 | * |
| 169 | * When the ModuleLoader is created on a loader hook thread, this is |
| 170 | * {@link AsyncLoaderHooksOnLoaderHookWorker}, and its methods directly call out |
| 171 | * to loader methods. Otherwise, this is {@link AsyncLoaderHooksProxiedToLoaderHookWorker}, |
| 172 | * and its methods post messages to the loader thread and possibly block on it. |
| 173 | * @see {ModuleLoader.#setAsyncLoaderHooks} |
| 174 | * @type {AsyncLoaderHooks} |
| 175 | */ |
| 176 | #asyncLoaderHooks; |
| 177 | |
| 178 | constructor(asyncLoaderHooks) { |
| 179 | this.#setAsyncLoaderHooks(asyncLoaderHooks); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Change the currently activate async loader hooks for this module |
| 184 | * loader to be the provided `AsyncLoaderHooks`. |
| 185 | * |
| 186 | * If present, this class customizes its core functionality to the |
| 187 | * `AsyncLoaderHooks` object, including registration, loading, and resolving. |
| 188 | * There are some responsibilities that this class _always_ takes |
| 189 | * care of, like validating outputs, so that the AsyncLoaderHooks object |
| 190 | * does not have to do so. |
| 191 | * |
| 192 | * Calling this function alters how modules are loaded and should be |
| 193 | * invoked with care. |
| 194 | * @param {AsyncLoaderHooks} asyncLoaderHooks |
| 195 | */ |
nothing calls this directly
no test coverage detected
searching dependent graphs…