|
1 | | -// eslint-disable-next-line @typescript-eslint/ban-ts-comment |
2 | | -// @ts-ignore |
3 | 1 | import { core, sync, SyncOpts } from 'resolve'; |
4 | 2 | import assert from 'assert'; |
5 | 3 | import fs from 'fs'; |
6 | 4 | import path from 'path'; |
7 | 5 | import { toNormalizedRealPath } from './common'; |
8 | 6 |
|
| 7 | +import type { PackageJson } from './types'; |
| 8 | + |
9 | 9 | Object.keys(core).forEach((key) => { |
10 | 10 | // 'resolve' hardcodes the list to host's one, but i need |
11 | 11 | // to be able to allow 'worker_threads' (target 12) on host 8 |
@@ -35,10 +35,10 @@ function parentDirectoriesContain(parent: string, directory: string) { |
35 | 35 | } |
36 | 36 | } |
37 | 37 |
|
38 | | -interface FollowOptions |
39 | | - extends Pick<SyncOpts, 'basedir' | 'extensions' | 'packageFilter'> { |
| 38 | +interface FollowOptions extends Pick<SyncOpts, 'basedir' | 'extensions'> { |
40 | 39 | ignoreFile?: string; |
41 | | - readFile?: (file: string) => void; |
| 40 | + catchReadFile?: (file: string) => void; |
| 41 | + catchPackageFilter?: (config: PackageJson, base: string, dir: string) => void; |
42 | 42 | } |
43 | 43 |
|
44 | 44 | export function follow(x: string, opts: FollowOptions) { |
@@ -100,15 +100,15 @@ export function follow(x: string, opts: FollowOptions) { |
100 | 100 | return Buffer.from(`{"main":"${PROOF}"}`); |
101 | 101 | } |
102 | 102 |
|
103 | | - if (opts.readFile) { |
104 | | - opts.readFile(file); |
| 103 | + if (opts.catchReadFile) { |
| 104 | + opts.catchReadFile(file); |
105 | 105 | } |
106 | 106 |
|
107 | 107 | return fs.readFileSync(file); |
108 | 108 | }, |
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); |
112 | 112 | } |
113 | 113 |
|
114 | 114 | return config; |
|
0 commit comments