diff --git a/lib/express-handlebars.ts b/lib/express-handlebars.ts index 42298c3b..79b833b7 100644 --- a/lib/express-handlebars.ts +++ b/lib/express-handlebars.ts @@ -311,7 +311,7 @@ export default class ExpressHandlebars { let dir = options.cache && (cache[dirPath] as Promise); if (dir) { - return (await dir).concat(); + return [...await dir]; } const pattern = "**/*" + this.extname; @@ -323,13 +323,14 @@ export default class ExpressHandlebars { dir = cache[dirPath] = glob(pattern, { cwd: dirPath, follow: true, + posix: true, }); // @ts-expect-error FIXME: not sure how to throw error in glob for test coverage if (options._throwTestError) { throw new Error("test"); } - return (await dir).map(d => d.replace(/\\/g, "/")); + return [...await dir]; } catch (err) { delete cache[dirPath]; throw err; diff --git a/package-lock.json b/package-lock.json index f503b71d..3515a70b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "7.0.6", "license": "BSD-3-Clause", "dependencies": { - "glob": "^10.0.0", + "glob": "^10.1.0", "graceful-fs": "^4.2.11", "handlebars": "^4.7.7" }, @@ -4252,14 +4252,14 @@ } }, "node_modules/glob": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.0.0.tgz", - "integrity": "sha512-zmp9ZDC6NpDNLujV2W2n+3lH+BafIVZ4/ct+Yj3BMZTH/+bgm/eVjHzeFLwxJrrIGgjjS2eiQLlpurHsNlEAtQ==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.1.0.tgz", + "integrity": "sha512-daGobsYuT0G4hng24B5LbeLNvwKZYRhWyDl3RvqqAGZjJnCopWWK6PWnAGBY1M/vdA63QE+jddhZcYp+74Bq6Q==", "dependencies": { "fs.realpath": "^1.0.0", "minimatch": "^9.0.0", "minipass": "^5.0.0", - "path-scurry": "^1.6.4" + "path-scurry": "^1.7.0" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -9701,9 +9701,9 @@ "dev": true }, "node_modules/path-scurry": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.6.4.tgz", - "integrity": "sha512-Qp/9IHkdNiXJ3/Kon++At2nVpnhRiPq/aSvQN+H3U1WZbvNRK0RIQK/o4HMqPoXjpuGJUEWpHSs6Mnjxqh3TQg==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.7.0.tgz", + "integrity": "sha512-UkZUeDjczjYRE495+9thsgcVgsaCPkaw80slmfVFgllxY+IO8ubTsOpFVjDPROBqJdHfVPUFRHPBV/WciOVfWg==", "dependencies": { "lru-cache": "^9.0.0", "minipass": "^5.0.0" @@ -14863,14 +14863,14 @@ } }, "glob": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.0.0.tgz", - "integrity": "sha512-zmp9ZDC6NpDNLujV2W2n+3lH+BafIVZ4/ct+Yj3BMZTH/+bgm/eVjHzeFLwxJrrIGgjjS2eiQLlpurHsNlEAtQ==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.1.0.tgz", + "integrity": "sha512-daGobsYuT0G4hng24B5LbeLNvwKZYRhWyDl3RvqqAGZjJnCopWWK6PWnAGBY1M/vdA63QE+jddhZcYp+74Bq6Q==", "requires": { "fs.realpath": "^1.0.0", "minimatch": "^9.0.0", "minipass": "^5.0.0", - "path-scurry": "^1.6.4" + "path-scurry": "^1.7.0" }, "dependencies": { "brace-expansion": { @@ -18725,9 +18725,9 @@ "dev": true }, "path-scurry": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.6.4.tgz", - "integrity": "sha512-Qp/9IHkdNiXJ3/Kon++At2nVpnhRiPq/aSvQN+H3U1WZbvNRK0RIQK/o4HMqPoXjpuGJUEWpHSs6Mnjxqh3TQg==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.7.0.tgz", + "integrity": "sha512-UkZUeDjczjYRE495+9thsgcVgsaCPkaw80slmfVFgllxY+IO8ubTsOpFVjDPROBqJdHfVPUFRHPBV/WciOVfWg==", "requires": { "lru-cache": "^9.0.0", "minipass": "^5.0.0" diff --git a/package.json b/package.json index e3abbc01..b4c1d1df 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "node": ">=v16" }, "dependencies": { - "glob": "^10.0.0", + "glob": "^10.1.0", "graceful-fs": "^4.2.11", "handlebars": "^4.7.7" }, diff --git a/spec/express-handlebars.test.ts b/spec/express-handlebars.test.ts index 9cc7ac01..18677ebd 100644 --- a/spec/express-handlebars.test.ts +++ b/spec/express-handlebars.test.ts @@ -633,17 +633,18 @@ describe("express-handlebars", () => { test("should get from cache", async () => { const exphbs = expressHandlebars.create(); const filePath = fixturePath("test"); - exphbs._fsCache[filePath] = "test"; + exphbs._fsCache[filePath] = Promise.resolve(["test"]); const file = await exphbs["_getDir"](filePath, { cache: true }); - expect(file).toBe("test"); + expect(file).toEqual(["test"]); }); test("should store in cache", async () => { const exphbs = expressHandlebars.create(); const filePath = fixturePath("templates"); expect(exphbs._fsCache[filePath]).toBeUndefined(); - await exphbs["_getDir"](filePath); - expect(exphbs._fsCache[filePath]).toBeDefined(); + const expected = await exphbs["_getDir"](filePath); + expect(exphbs._fsCache[filePath]).toBeInstanceOf(Promise); + expect(await exphbs._fsCache[filePath]).toEqual(expected); }); test("should not store in cache on error", async () => {