* Resolves dependencies. * @param {InputFileSystem} fs file system * @param {ContextModuleOptions} options options * @param {ResolveDependenciesCallback} callback callback function * @returns {void}
(fs, options, callback)
| 316 | * @returns {void} |
| 317 | */ |
| 318 | resolveDependencies(fs, options, callback) { |
| 319 | const cmf = this; |
| 320 | const { |
| 321 | resource, |
| 322 | resourceQuery, |
| 323 | resourceFragment, |
| 324 | recursive, |
| 325 | regExp, |
| 326 | include, |
| 327 | exclude, |
| 328 | referencedExports, |
| 329 | category, |
| 330 | typePrefix, |
| 331 | attributes |
| 332 | } = options; |
| 333 | if (!regExp || !resource) return callback(null, []); |
| 334 | |
| 335 | /** |
| 336 | * Adds directory checked. |
| 337 | * @param {string} ctx context |
| 338 | * @param {string} directory directory |
| 339 | * @param {Set<string>} visited visited |
| 340 | * @param {ResolveDependenciesCallback} callback callback |
| 341 | */ |
| 342 | const addDirectoryChecked = (ctx, directory, visited, callback) => { |
| 343 | /** @type {NonNullable<InputFileSystem["realpath"]>} */ |
| 344 | (fs.realpath)(directory, (err, _realPath) => { |
| 345 | if (err) return callback(err); |
| 346 | const realPath = /** @type {string} */ (_realPath); |
| 347 | if (visited.has(realPath)) return callback(null, []); |
| 348 | /** @type {Set<string> | undefined} */ |
| 349 | let recursionStack; |
| 350 | addDirectory( |
| 351 | ctx, |
| 352 | directory, |
| 353 | (_, dir, callback) => { |
| 354 | if (recursionStack === undefined) { |
| 355 | recursionStack = new Set(visited); |
| 356 | recursionStack.add(realPath); |
| 357 | } |
| 358 | addDirectoryChecked(ctx, dir, recursionStack, callback); |
| 359 | }, |
| 360 | callback |
| 361 | ); |
| 362 | }); |
| 363 | }; |
| 364 | |
| 365 | /** |
| 366 | * Adds the provided ctx to the context module factory. |
| 367 | * @param {string} ctx context |
| 368 | * @param {string} directory directory |
| 369 | * @param {(context: string, subResource: string, callback: () => void) => void} addSubDirectory addSubDirectoryFn |
| 370 | * @param {ResolveDependenciesCallback} callback callback |
| 371 | * @returns {void} |
| 372 | */ |
| 373 | const addDirectory = (ctx, directory, addSubDirectory, callback) => { |
| 374 | fs.readdir(directory, (err, files) => { |
| 375 | if (err) return callback(err); |
no test coverage detected