Skip to content

Commit

Permalink
manually join paths instead of using the os sep (#365)
Browse files Browse the repository at this point in the history
* manually join paths instead of using the os sep

* add changelog
  • Loading branch information
bkendall committed Dec 28, 2022
1 parent 35803a3 commit 920e552
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes issue with path resolution on Windows.
7 changes: 4 additions & 3 deletions src/utils/pathutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { join } from "node:path";

const INDEX_FILE = "index.html";

/**
* @param pathname path to check.
* @return the path with "/index.html" appended, if required.
*/
export function asDirectoryIndex(pathname: string): string {
return isDirectoryIndex(pathname) ? pathname : join(pathname, INDEX_FILE);
if (isDirectoryIndex(pathname)) {
return pathname;
}
return normalizeMultiSlashes(`${pathname}/${INDEX_FILE}`);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/unit/providers/fs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("provider: fs", () => {
await fsp(opts)({}, "/index.html")
.then(readStatStream)
.then((body: string) => {
expect(body).to.eq("A\n");
expect(body.trim()).to.eq("A");
});
});

Expand Down Expand Up @@ -86,13 +86,13 @@ describe("provider: fs", () => {
await fsp(opts)({}, "/index.html")
.then(readStatStream)
.then((body: string) => {
expect(body).to.eq("A\n");
expect(body.trim()).to.eq("A");
});

await fsp(opts)({}, "/b.html")
.then(readStatStream)
.then((body: string) => {
expect(body).to.eq("B\n");
expect(body.trim()).to.eq("B");
});
});

Expand Down

0 comments on commit 920e552

Please sign in to comment.