Skip to content

Commit a04bc4c

Browse files
docs: add resolvePromise examples for Resolver and ResolverFactory (#555)
1 parent f9f6d57 commit a04bc4c

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,16 @@ const resolver = ResolverFactory.createResolver({
131131
extensions: [".js", ".json"],
132132
});
133133

134+
// callback
134135
resolver.resolve({}, __dirname, "./utils", {}, (err, file) => {
135136
// ...
136137
});
138+
139+
// sync (requires a sync fileSystem)
140+
const fileSync = resolver.resolveSync({}, __dirname, "./utils");
141+
142+
// promise
143+
const filePromise = await resolver.resolvePromise({}, __dirname, "./utils", {});
137144
```
138145

139146
#### `CachedInputFileSystem(fileSystem, duration)`
@@ -199,6 +206,8 @@ const context = {};
199206
const lookupStartPath = "/Users/webpack/some/root/dir";
200207
const request = "./path/to-look-up.js";
201208
const resolveContext = {};
209+
210+
// callback
202211
myResolver.resolve(
203212
context,
204213
lookupStartPath,
@@ -208,6 +217,22 @@ myResolver.resolve(
208217
// Do something with the path
209218
},
210219
);
220+
221+
// promise
222+
try {
223+
const filepath = await myResolver.resolvePromise(
224+
context,
225+
lookupStartPath,
226+
request,
227+
resolveContext,
228+
);
229+
// Do something with the path
230+
} catch (err) {
231+
// handle resolve failure
232+
}
233+
234+
// sync (requires a sync fileSystem, e.g. the default Node.js one)
235+
const filepath = myResolver.resolveSync(context, lookupStartPath, request);
211236
```
212237

213238
#### Resolver Options

0 commit comments

Comments
 (0)