`find.up` does not include the `stop` directory

#9 · closed · 1 comments

View on GitHub ↗

mrginglymus

As discovered in https://github.com/storybookjs/storybook/pull/31338, which is attempting to replace `find-up` with `empathic`. There are two issues with the behaviour: 1. it's a different behaviour to competing libraries that makes migration more difficult - at the very least this needs prominently documenting that `stop` is exclusive, not inclusive. 2. I find it an unintuitive api. This is definitely a personal opinion, but I'm sure I'm not alone. I would expect that ```js find.up('package.json', { stop: '~' }) ``` would search for the first `package.json` found between `cwd` and `~` _inclusive_. When I'm constructing my call, I'm far more likely to know the last place I want to look, rather than the parent of the last place I want to look. As an related bit of fun: ```js find.up('dev'); // finds `/dev` find.up('dev', { stop: '/' }); // doesn't ``` which means if I have a (unknown) dir that is the last place I want to look for a file, I can't just do ```js find.up('dev', { stop: path.dirname(stop) }); ``` it has to be ```js find.up('dev', { stop: stop === '/' ? undefined : path.dirname(stop) }); ```

Comments

lukeed

It’s documented here: https://github.com/lukeed/empathic/blob/0dc2c39e1fdd6b5a833bd240634e86af9cc4f9ce/src/walk.ts#L18 I can cut a new release that replaces `options.stop` with an `options.last`, which defaults to “/“ To me, stop means stop. So it’s actually very unintuitive to me that “stopAt” actually means “stop after”