Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/late-snails-argue.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"webpack-dev-middleware": major
---

The `getFilenameFromUrl` function now returns an object with the found `filename` (or `undefined` if the file was not found) and throws an error if the URL cannot be processed. Additionally, the object contains the `extra` property with `stats` (file system stats) and `outputFileSystem` (output file system where file was found) properties.
The `getFilenameFromUrl` function is now asynchronous, returning a Promise that resolves to the object with the found `filename` (or `undefined` if the file was not found) or throws an error if the URL cannot be processed. Additionally, the object contains the `extra` property with `stats` (file system stats) and `outputFileSystem` (output file system where file was found) properties.
24 changes: 10 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,20 +460,16 @@ const app = new express();
app.use(instance);

instance.waitUntilValid(() => {
let resolver;

try {
resolved = instance.getFilenameFromUrl("/bundle.js");
} catch (err) {
console.log(`Error: ${err}`);
}

if (!resolved) {
console.log("Not found");
return;
}

console.log(`Filename is ${filename}`);
instance
.getFilenameFromUrl("/bundle.js")
.then(() => {
if (filename) {
console.log(`Filename is ${filename}`);
}
})
.catch((err) => {
console.log(`Error: ${err}`);
});
});
```

Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const noop = () => {};
/** @typedef {import("webpack").Stats} Stats */
/** @typedef {import("webpack").MultiStats} MultiStats */
/** @typedef {import("fs").ReadStream} ReadStream */
/** @typedef {import("./middleware").Extra} Extra */
/** @typedef {import("./middleware").FilenameWithExtra} FilenameWithExtra */

// eslint-disable-next-line jsdoc/reject-any-type
/** @typedef {any} EXPECTED_ANY */
Expand Down Expand Up @@ -126,7 +126,7 @@ const noop = () => {};
/**
* @callback GetFilenameFromUrl
* @param {string} url request URL
* @returns {{ filename: string, extra: Extra } | undefined} a filename with additional information, or `undefined` if nothing is found
* @returns {Promise<FilenameWithExtra | undefined>} a filename with additional information, or `undefined` if nothing is found
*/

/**
Expand Down
Loading
Loading