Isomorphic, fs-agnostic implementation of the Node resolution algorithm.
Implements the following behaviors:
- https://nodejs.org/api/modules.html#modules_all_together
- https://github.com/defunctzombie/package-browser-field-spec
Install library in project:
npm i @file-services/resolve
Then, use the programmatic API:
import { createRequestResolver } from "@file-services/resolve";
import { createMemoryFs } from "@file-services/memory";
const fs = createMemoryFs({
"some-folder": {
"index.js": "some content",
},
});
const resolveRequest = createRequestResolver({ fs });
resolveRequest("/", "./some-folder");
// === '/some-folder/index.js'
MIT