Skip to content

Commit

Permalink
cfg(Firebase): fix Firebase local serving (serve or emulators:start)
Browse files Browse the repository at this point in the history
Due to a [breaking change][1] in Node.js v22, `superstatic`, the local
server used by Firebase `serve` and `emulators:start` commands throws an
error. See, also, [firebase/superstatic#468 (comment)][2] for details.

Apply a local patch to fix the issue, by accessing a property that is
defined on the `Stat` instance and thus will be available. We currently
do not need or use Firebase local serving, but I figured out the fix,
so... ¯\\\_(ツ)_/¯

[1]: nodejs/node#50908
[2]: firebase/superstatic#468 (comment)
  • Loading branch information
gkalpak committed Jun 13, 2024
1 parent ff41fdc commit 483423f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jasmine": "^4.1.3",
"firebase-tools": "^13.10.2",
"firebase-tools": "^13.11.2",
"hint": "^7.1.12",
"jasmine-core": "^5.1.2",
"karma": "^6.4.3",
Expand Down
20 changes: 20 additions & 0 deletions patches/superstatic+9.0.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/node_modules/superstatic/lib/providers/fs.js b/node_modules/superstatic/lib/providers/fs.js
index 414d9fc..1975cd5 100644
--- a/node_modules/superstatic/lib/providers/fs.js
+++ b/node_modules/superstatic/lib/providers/fs.js
@@ -86,7 +86,14 @@ module.exports = function provider(options) {
try {
const stat = await multiStat(fullPathnames);
return {
- modified: stat.mtime.getTime(),
+ /*
+ * [LOCAL-PATCH]
+ * With Node.js v22, `mtime` is undefined, due to it being initially defined on `Stat.prototype`, which
+ * means that the spread operator in `multiStat()` will not propagate it.
+ * See, also, https://github.com/firebase/superstatic/issues/468#issuecomment-2166883064.
+ */
+ //modified: stat.mtime.getTime(),
+ modified: Math.round(Number(stat.mtimeMs)),
size: stat.size,
etag: await fetchEtag(stat.pathname, stat),
stream: fs.createReadStream(stat.pathname),

0 comments on commit 483423f

Please sign in to comment.