@kongyo2/ts-comment-scanner 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/run.ts CHANGED
@@ -5,6 +5,7 @@ import { parseArgs, UsageError, type CliOptions, type DirectiveMode } from "./ar
5
5
  import {
6
6
  collectFiles,
7
7
  encodeFileText,
8
+ foldPathCase,
8
9
  isJsxFile,
9
10
  mapLimit,
10
11
  readFileText,
@@ -53,8 +54,11 @@ General:
53
54
  -v, --version Print the version number
54
55
 
55
56
  Paths default to the current directory. Directories are scanned recursively,
56
- skipping node_modules and .git. Removal keeps directives and license headers
57
- unless explicitly requested, so builds and linters keep working.
57
+ skipping node_modules and .git. Ignore globs without a slash match file names,
58
+ and a trailing slash (dist/) restricts a glob to directories. JavaScript files
59
+ (.js, .jsx, .mjs, .cjs) added with --ext are parsed with JSX enabled. Removal
60
+ keeps directives and license headers unless explicitly requested, so builds
61
+ and linters keep working.
58
62
 
59
63
  --diff narrows any scan or removal to files changed in git: a single revision
60
64
  compares the working tree against it (HEAD covers all uncommitted work,
@@ -142,31 +146,27 @@ async function collectTargets(options: CliOptions, collectOptions: CollectOption
142
146
  // alias may point at the changed file), and either spelling names the same
143
147
  // content. Broken links (a symlink re-pointed at nothing) only match by
144
148
  // their reported spelling.
149
+ // Paths are folded the way the platform compares them: git reports the case
150
+ // a file was tracked with, so on Windows `Foo.ts` must stay in scope when
151
+ // the scan found it as `foo.ts`.
145
152
  const changed = new Set<string>();
146
153
  for (const path of await changedFiles(options.diff, anchor)) {
147
- changed.add(caseFold(path));
154
+ changed.add(foldPathCase(path));
148
155
  const real = tryRealpath(path);
149
- if (real !== undefined) changed.add(caseFold(real));
156
+ if (real !== undefined) changed.add(foldPathCase(real));
150
157
  }
151
158
  // Realpath only the directory part first: spellings through symlinked
152
159
  // directories then compare equal while a tracked symlink still matches the
153
- // path git reports it at; the fully dereferenced path is the fallback.
160
+ // path git reports it at; the fully dereferenced path is the fallback. A
161
+ // directory that vanished since the walk is compared as spelled.
154
162
  return files.filter((file) => {
155
- if (changed.has(caseFold(join(realpathSync.native(dirname(file)), basename(file))))) return true;
163
+ const directory = tryRealpath(dirname(file)) ?? dirname(file);
164
+ if (changed.has(foldPathCase(join(directory, basename(file))))) return true;
156
165
  const real = tryRealpath(file);
157
- return real !== undefined && changed.has(caseFold(real));
166
+ return real !== undefined && changed.has(foldPathCase(real));
158
167
  });
159
168
  }
160
169
 
161
- /**
162
- * Windows paths are case-insensitive, but git reports the case a file was
163
- * tracked with; folding both sides keeps `Foo.ts` in the --diff scope when
164
- * the scan found it as `foo.ts`.
165
- */
166
- function caseFold(path: string): string {
167
- return process.platform === "win32" ? path.toLowerCase() : path;
168
- }
169
-
170
170
  /**
171
171
  * Native realpath — changedFiles resolves the repository root with the
172
172
  * (native) promises realpath, and on Windows only the native calls expand