Skip to content

New: add loadDependencyFiles utility for scanning files across modules#98

Merged
taylortom merged 2 commits intomasterfrom
copilot/add-load-dependency-files-utility
Feb 25, 2026
Merged

New: add loadDependencyFiles utility for scanning files across modules#98
taylortom merged 2 commits intomasterfrom
copilot/add-load-dependency-files-utility

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

Multiple modules independently implement the same pattern: iterate app.dependencies, glob for files in each module's rootDir, and optionally parse the JSON results. This extracts that into a single shared utility in core.

New

  • loadDependencyFiles(pattern, options) — standalone utility that globs a pattern across all dependency rootDirs, returning results grouped by module name. Supports parse: true for JSON read+parse and a dependencies override for testing or static builds.
import { loadDependencyFiles } from 'adapt-authoring-core'

// Returns { 'adapt-authoring-errors': ['/path/to/errors/foo.json', ...], ... }
const files = await loadDependencyFiles('errors/*.json')

// Returns parsed JSON objects instead of paths
const parsed = await loadDependencyFiles('errors/*.json', { parse: true })

// Override dependency list (e.g. for unit tests or static doc builds)
const parsed = await loadDependencyFiles('errors/*.json', { parse: true, dependencies: customDeps })

Testing

  1. node --test tests/utils-loadDependencyFiles.spec.js
Original prompt

This section details on the original issue you should resolve

<issue_title>New: Add loadDependencyFiles utility for scanning files across modules</issue_title>
<issue_description>## Summary

Multiple modules independently implement the same pattern: iterate app.dependencies, glob for files in each module's rootDir, and optionally parse the JSON results. This should be extracted into a shared utility function in core.

Current duplication

The following modules all implement this pattern separately:

Module Pattern File
ErrorsModule glob('errors/*.json', { cwd: d.rootDir }) adapt-authoring-errors/lib/ErrorsModule.js
LangModule glob('lang/*.json', { cwd: d.rootDir }) adapt-authoring-lang/lib/LangModule.js
JsonSchemaModule glob('schema/*.schema.json', { cwd: d.rootDir }) adapt-authoring-jsonschema/lib/JsonSchemaModule.js
ConfigModule direct read of conf/config.schema.json per dep adapt-authoring-config/lib/ConfigModule.js
Doc plugins various file reads per dep adapt-authoring-docs

Each follows the same shape:

await Promise.all(Object.values(this.app.dependencies).map(async d => {
  const files = await glob('some/pattern', { cwd: d.rootDir, absolute: true })
  await Promise.all(files.map(async f => {
    const contents = JSON.parse(await fs.readFile(f))
    // ...
  }))
}))

Proposed API

A standalone utility function exported from core:

import { loadDependencyFiles } from 'adapt-authoring-core'

// Uses App.instance.dependencies by default, returns file paths grouped by module
const files = await loadDependencyFiles('errors/*.json')

// With JSON parsing — returns parsed content grouped by module
const parsed = await loadDependencyFiles('errors/*.json', { parse: true })

// Override dependencies (for testing or static doc builds)
const parsed = await loadDependencyFiles('errors/*.json', {
  parse: true,
  dependencies: customDeps
})

Key design decisions:

  • Standalone function (not an instance method) for easy unit testing
  • Defaults to App.instance.dependencies when no dependencies option is provided
  • parse option (default false) handles the JSON read-and-parse step that every consumer currently does manually
  • dependencies option allows callers to pass custom dependency lists, which is needed for unit tests and for the docs module's static build (see adapt-security/adapt-authoring-docs)

Motivation

This utility is also a prerequisite for refactoring the docs module to build documentation without a running app instance. The static doc builder needs to perform the same file scanning that runtime modules do, and a shared utility avoids duplicating the logic a sixth time.</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: taylortom <1059083+taylortom@users.noreply.github.com>
Copilot AI changed the title [WIP] Add loadDependencyFiles utility for scanning files across modules New: add loadDependencyFiles utility for scanning files across modules Feb 25, 2026
@taylortom taylortom marked this pull request as ready for review February 25, 2026 23:08
@taylortom taylortom merged commit c4c5743 into master Feb 25, 2026
2 checks passed
@taylortom taylortom deleted the copilot/add-load-dependency-files-utility branch February 25, 2026 23:11
github-actions bot pushed a commit that referenced this pull request Feb 25, 2026
# [2.2.0](v2.1.4...v2.2.0) (2026-02-25)

### New

* add loadDependencyFiles utility for scanning files across modules (#98) ([c4c5743](c4c5743)), closes [#98](#98)
@github-actions
Copy link

🎉 This PR is included in version 2.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New: Add loadDependencyFiles utility for scanning files across modules

2 participants