[GH-ISSUE #5891] [Bug] Reference-source import ignores nested .gitignore files #3569

Closed
opened 2026-10-31 00:41:58 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @shoyann on GitHub (Oct 21, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/5891

Before submitting

  • I searched the open and closed issues for a related report.
  • I removed credentials, tokens, private paths, and sensitive target data.

Area

CLI

Observed behavior

import-reference-source honors the root .gitignore but ignores a .gitignore inside a child directory. In the fixture below, Git ignores both generated files. REA excludes the root-level control file, but hashes packages/widget/generated/stale.js and records its unresolved import. The CLI exits successfully.

Reproduction

Run from a source checkout after npm ci and npm run build:cached. This is the shell reproduction I ran:

set -eu
root=$(mktemp -d)
trap 'rm -rf -- "$root"' EXIT
git init -q "$root"
mkdir -p "$root/packages/widget/generated"
printf 'root-generated.js\n' > "$root/.gitignore"
printf 'export const generated = 1;\n' > "$root/root-generated.js"
printf 'generated/\n' > "$root/packages/widget/.gitignore"
printf 'export const value = 1;\n' > "$root/packages/widget/main.js"
printf 'import "./missing.js";\n' > "$root/packages/widget/generated/stale.js"
git -C "$root" check-ignore -v -- root-generated.js packages/widget/generated/stale.js
node scripts/rea.mjs import-reference-source "$root" --format json --filter-output entries,exclusions,relationships

Expected behavior

packages/widget/generated/ should be excluded by packages/widget/.gitignore, so stale.js and its import should not enter the reference graph. The root-level control should remain excluded.

The CLI documentation says the importer honors the source tree's .gitignore. Git's documented behavior includes rules in child directories, relative to each rule file.

Impact and scope

Observed in this reduced fixture: a generated file is included and contributes an unwanted unresolved dependency. This can affect source trees whose packages keep their own ignore rules. I have not measured the impact on a real project or tested macOS/native Windows.

Reproduced once through the production importer at 5eebe2f, then once through the built CLI at the revision below. Last known good version: NOT_ENOUGH_INFO; no regression range established.

REA version

Source revision c324d31b45fcab77e4ed7320ed60f0bf5a4ba188 (package version 6.7.0).

Runtime and platform

Node.js 24.18.0, npm 11.16.0, Ubuntu 26.04 LTS under WSL2, Linux x86_64. No analysis provider required.

Target and artifact context

A synthetic local Git repository containing a root ignore rule and a package-local ignore rule; no private input files.

Interface

CLI

Earliest failure stage

Capture or observation

Relevant output or evidence

git check-ignore -v reports:

.gitignore:1:root-generated.js    root-generated.js
packages/widget/.gitignore:1:generated/    packages/widget/generated/stale.js

Relevant CLI result excerpt (unrelated entries and fields omitted):

{
  "entries": [
    {
      "path": "packages/widget/generated/stale.js",
      "kind": "file",
      "content_state": "hashed"
    }
  ],
  "exclusions": [
    { "path": ".git", "entry_kind": "directory", "reason": "default-ignored", "pattern": ".git/" },
    { "path": "root-generated.js", "entry_kind": "file", "reason": "project-ignored", "pattern": "root-generated.js" }
  ],
  "relationships": [
    {
      "from_path": "packages/widget/generated/stale.js",
      "to": "packages/widget/generated/missing.js",
      "kind": "imports",
      "resolution": "unresolved",
      "parse_state": "parsed"
    }
  ]
}

Analysis or suspected cause

Source inspection: buildIgnored reads only join(root, ".gitignore"). The resulting matcher is used throughout traversal without loading child-directory policies.

Additional context

This report concerns ignore files inside the selected root. It is separate from the above-root limitation noted in #1770 and the case-sensitivity issue in #5619. No fix is included.

Originally created by @shoyann on GitHub (Oct 21, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/5891 ### Before submitting - [x] I searched the open and closed issues for a related report. - [x] I removed credentials, tokens, private paths, and sensitive target data. ### Area CLI ### Observed behavior `import-reference-source` honors the root `.gitignore` but ignores a `.gitignore` inside a child directory. In the fixture below, Git ignores both generated files. REA excludes the root-level control file, but hashes `packages/widget/generated/stale.js` and records its unresolved import. The CLI exits successfully. ### Reproduction Run from a source checkout after `npm ci` and `npm run build:cached`. This is the shell reproduction I ran: ```bash set -eu root=$(mktemp -d) trap 'rm -rf -- "$root"' EXIT git init -q "$root" mkdir -p "$root/packages/widget/generated" printf 'root-generated.js\n' > "$root/.gitignore" printf 'export const generated = 1;\n' > "$root/root-generated.js" printf 'generated/\n' > "$root/packages/widget/.gitignore" printf 'export const value = 1;\n' > "$root/packages/widget/main.js" printf 'import "./missing.js";\n' > "$root/packages/widget/generated/stale.js" git -C "$root" check-ignore -v -- root-generated.js packages/widget/generated/stale.js node scripts/rea.mjs import-reference-source "$root" --format json --filter-output entries,exclusions,relationships ``` ### Expected behavior `packages/widget/generated/` should be excluded by `packages/widget/.gitignore`, so `stale.js` and its import should not enter the reference graph. The root-level control should remain excluded. The [CLI documentation](https://github.com/morluto/rea/blob/c324d31b45fcab77e4ed7320ed60f0bf5a4ba188/docs/cli.md#L320-L327) says the importer honors the source tree's `.gitignore`. Git's [documented behavior](https://git-scm.com/docs/gitignore#_description) includes rules in child directories, relative to each rule file. ### Impact and scope Observed in this reduced fixture: a generated file is included and contributes an unwanted unresolved dependency. This can affect source trees whose packages keep their own ignore rules. I have not measured the impact on a real project or tested macOS/native Windows. Reproduced once through the production importer at `5eebe2f`, then once through the built CLI at the revision below. Last known good version: NOT_ENOUGH_INFO; no regression range established. ### REA version Source revision `c324d31b45fcab77e4ed7320ed60f0bf5a4ba188` (package version 6.7.0). ### Runtime and platform Node.js 24.18.0, npm 11.16.0, Ubuntu 26.04 LTS under WSL2, Linux x86_64. No analysis provider required. ### Target and artifact context A synthetic local Git repository containing a root ignore rule and a package-local ignore rule; no private input files. ### Interface CLI ### Earliest failure stage Capture or observation ### Relevant output or evidence `git check-ignore -v` reports: ```text .gitignore:1:root-generated.js root-generated.js packages/widget/.gitignore:1:generated/ packages/widget/generated/stale.js ``` Relevant CLI result excerpt (unrelated entries and fields omitted): ```json { "entries": [ { "path": "packages/widget/generated/stale.js", "kind": "file", "content_state": "hashed" } ], "exclusions": [ { "path": ".git", "entry_kind": "directory", "reason": "default-ignored", "pattern": ".git/" }, { "path": "root-generated.js", "entry_kind": "file", "reason": "project-ignored", "pattern": "root-generated.js" } ], "relationships": [ { "from_path": "packages/widget/generated/stale.js", "to": "packages/widget/generated/missing.js", "kind": "imports", "resolution": "unresolved", "parse_state": "parsed" } ] } ``` ### Analysis or suspected cause Source inspection: [`buildIgnored`](https://github.com/morluto/rea/blob/c324d31b45fcab77e4ed7320ed60f0bf5a4ba188/src/application/ReferenceSourceImportPolicy.ts#L103-L179) reads only `join(root, ".gitignore")`. The resulting matcher is used throughout traversal without loading child-directory policies. ### Additional context This report concerns ignore files **inside** the selected root. It is separate from the above-root limitation noted in #1770 and the case-sensitivity issue in #5619. No fix is included.
Author
Owner

@shoyann commented on GitHub (Oct 24, 2026):

Verified the original fixture through the production importer on main at ead9fdcd, which includes 19986406.

Both the root-level generated file and packages/widget/generated/ are excluded, packages/widget/main.js is retained, and stale.js no longer contributes the unwanted missing.js dependency.

Closing as fixed. I've also closed #5927 because its implementation overlaps with the fix on main. Thanks!

<!-- gh-comment-id:6379696146 --> @shoyann commented on GitHub (Oct 24, 2026): Verified the original fixture through the production importer on main at `ead9fdcd`, which includes [19986406](https://github.com/morluto/rea/commit/19986406692be3316434122dcebfd37f267ffa5a). Both the root-level generated file and `packages/widget/generated/` are excluded, `packages/widget/main.js` is retained, and `stale.js` no longer contributes the unwanted `missing.js` dependency. Closing as fixed. I've also closed #5927 because its implementation overlaps with the fix on main. Thanks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#3569
No description provided.