Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit c18c3c6

Browse files
committed
follow, walker: fix types of follow, reduce confusion
1 parent eb03b56 commit c18c3c6

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

lib/follow.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2-
// @ts-ignore
31
import { core, sync, SyncOpts } from 'resolve';
42
import assert from 'assert';
53
import fs from 'fs';
64
import path from 'path';
75
import { toNormalizedRealPath } from './common';
86

7+
import type { PackageJson } from './types';
8+
99
Object.keys(core).forEach((key) => {
1010
// 'resolve' hardcodes the list to host's one, but i need
1111
// to be able to allow 'worker_threads' (target 12) on host 8
@@ -35,10 +35,10 @@ function parentDirectoriesContain(parent: string, directory: string) {
3535
}
3636
}
3737

38-
interface FollowOptions
39-
extends Pick<SyncOpts, 'basedir' | 'extensions' | 'packageFilter'> {
38+
interface FollowOptions extends Pick<SyncOpts, 'basedir' | 'extensions'> {
4039
ignoreFile?: string;
41-
readFile?: (file: string) => void;
40+
catchReadFile?: (file: string) => void;
41+
catchPackageFilter?: (config: PackageJson, base: string, dir: string) => void;
4242
}
4343

4444
export function follow(x: string, opts: FollowOptions) {
@@ -100,15 +100,15 @@ export function follow(x: string, opts: FollowOptions) {
100100
return Buffer.from(`{"main":"${PROOF}"}`);
101101
}
102102

103-
if (opts.readFile) {
104-
opts.readFile(file);
103+
if (opts.catchReadFile) {
104+
opts.catchReadFile(file);
105105
}
106106

107107
return fs.readFileSync(file);
108108
},
109-
packageFilter: (config, base) => {
110-
if (opts.packageFilter) {
111-
opts.packageFilter(config, base);
109+
packageFilter: (config, base, dir) => {
110+
if (opts.catchPackageFilter) {
111+
opts.catchPackageFilter(config, base, dir);
112112
}
113113

114114
return config;

lib/walker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,8 @@ class Walker {
762762
// is not taken in require('./typos')
763763
// in 'normalize-package-data/lib/fixer.js'
764764
extensions: ['.js', '.json', '.node'],
765-
readFile: catchReadFile,
766-
packageFilter: catchPackageFilter,
765+
catchReadFile,
766+
catchPackageFilter,
767767
});
768768
} catch (error) {
769769
failure = error as Error;

0 commit comments

Comments
 (0)