HarperFast / HarperFast/harper

jsResource: files in subdirectories are never loaded when listed as literal paths in config.yaml

Open
#2,121 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
89
Forks
10
Avg merge
2d 6h
Merged PRs (30d)
200

Description

## Bug

When `jsResource.files` lists a file located in a subdirectory using a **literal path** (e.g. `routes/index.js`), the file is silently ignored and the resource is never registered.

## Root Cause

`picomatch.scan('routes/index.js').base` returns `'routes/index.js'` (the full literal path, because there are no glob characters). This becomes the sole entry in `allowedBases` for that pattern.

The `ignored` function in `EntryHandler.ts` filters chokidar events:

```js
normalizedBases.every((base) => !normalizedPath.startsWith(base))
```

When chokidar visits the **`routes/`** directory node during its initial scan, no `allowedBases` entry starts with `/path/to/routes` (the bases only have the full file path `/path/to/routes/index.js`), so the directory is marked ignored. Chokidar never descends into it, and `routes/index.js` is never seen.

The fix should add a reverse check — "any base starts with this path" — to allow traversal into parent directories:

```js
normalizedBases.every((base) =>
!normalizedPath.startsWith(base) &&
!base.startsWith(normalizedPath + '/') // allow traversal into parent dirs
)
```

## Reproduction

```yaml
# config.yaml
jsResource:
files:
- resources.js
- routes/index.js # ← file in subdirectory, literal path
```

`GET /GetAll` returns 404. No error is logged.

## Workaround

Use a glob pattern so the `base` resolves to the directory level:

```yaml
jsResource:
files:
- resources.js
- routes/** # ← glob; scan().base = 'routes', directory not ignored
```

## Affected version

Harper 5.1.0

— Claude

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.