firebase-tools 11.15.0 → 11.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -139,12 +139,14 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
139
139
  }
140
140
  const configs = (0, config_1.hostingConfig)(options);
141
141
  let firebaseDefaults = undefined;
142
- if (configs.length === 0)
142
+ if (configs.length === 0) {
143
143
  return;
144
+ }
144
145
  for (const config of configs) {
145
146
  const { source, site, public: publicDir } = config;
146
- if (!source)
147
+ if (!source) {
147
148
  continue;
149
+ }
148
150
  config.rewrites || (config.rewrites = []);
149
151
  config.redirects || (config.redirects = []);
150
152
  config.headers || (config.headers = []);
@@ -152,8 +154,9 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
152
154
  const dist = (0, path_1.join)(projectRoot, ".firebase", site);
153
155
  const hostingDist = (0, path_1.join)(dist, "hosting");
154
156
  const functionsDist = (0, path_1.join)(dist, "functions");
155
- if (publicDir)
157
+ if (publicDir) {
156
158
  throw new Error(`hosting.public and hosting.source cannot both be set in firebase.json`);
159
+ }
157
160
  const getProjectPath = (...args) => (0, path_1.join)(projectRoot, source, ...args);
158
161
  const functionName = `ssr${site.toLowerCase().replace(/-/g, "")}`;
159
162
  const usesFirebaseAdminSdk = !!findDependency("firebase-admin", { cwd: getProjectPath() });
@@ -232,8 +235,9 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
232
235
  if (devModeHandle) {
233
236
  config.public = (0, path_1.relative)(projectRoot, publicDirectory);
234
237
  options.frameworksDevModeHandle = devModeHandle;
235
- if (mayWantBackend && firebaseDefaults)
238
+ if (mayWantBackend && firebaseDefaults) {
236
239
  codegenFunctionsDirectory = codegenDevModeFunctionsDirectory;
240
+ }
237
241
  }
238
242
  else {
239
243
  const { wantsBackend = false, rewrites = [], redirects = [], headers = [], } = (await build(getProjectPath())) || {};
@@ -248,6 +252,7 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
248
252
  if (wantsBackend)
249
253
  codegenFunctionsDirectory = codegenProdModeFunctionsDirectory;
250
254
  }
255
+ config.webFramework = `${framework}${codegenFunctionsDirectory ? "_ssr" : ""}`;
251
256
  if (codegenFunctionsDirectory) {
252
257
  if (firebaseDefaults)
253
258
  firebaseDefaults._authTokenSyncURL = "/__session";
@@ -12,6 +12,7 @@ const prompt_1 = require("../../prompt");
12
12
  const semver_1 = require("semver");
13
13
  const logger_1 = require("../../logger");
14
14
  const error_1 = require("../../error");
15
+ const fsutils_1 = require("../../fsutils");
15
16
  const CLI_COMMAND = (0, path_1.join)("node_modules", ".bin", process.platform === "win32" ? "next.cmd" : "next");
16
17
  exports.name = "Next.js";
17
18
  exports.support = "experimental";
@@ -20,6 +21,10 @@ function getNextVersion(cwd) {
20
21
  var _a;
21
22
  return (_a = (0, __1.findDependency)("next", { cwd, depth: 0, omitDev: false })) === null || _a === void 0 ? void 0 : _a.version;
22
23
  }
24
+ function getReactVersion(cwd) {
25
+ var _a;
26
+ return (_a = (0, __1.findDependency)("react-dom", { cwd, omitDev: false })) === null || _a === void 0 ? void 0 : _a.version;
27
+ }
23
28
  async function discover(dir) {
24
29
  if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
25
30
  return;
@@ -30,6 +35,10 @@ async function discover(dir) {
30
35
  exports.discover = discover;
31
36
  async function build(dir) {
32
37
  const { default: nextBuild } = (0, __1.relativeRequire)(dir, "next/dist/build");
38
+ const reactVersion = getReactVersion(dir);
39
+ if (reactVersion && (0, semver_1.gte)(reactVersion, "18.0.0")) {
40
+ process.env.__NEXT_REACT_ROOT = "true";
41
+ }
33
42
  await nextBuild(dir, null, false, false, true).catch((e) => {
34
43
  console.error(e.message);
35
44
  throw e;
@@ -46,12 +55,19 @@ async function build(dir) {
46
55
  const exportDetailBuffer = exportDetailExists ? await (0, promises_1.readFile)(exportDetailPath) : undefined;
47
56
  const exportDetailJson = exportDetailBuffer && JSON.parse(exportDetailBuffer.toString());
48
57
  if (exportDetailJson === null || exportDetailJson === void 0 ? void 0 : exportDetailJson.success) {
58
+ const appPathRoutesManifestPath = (0, path_1.join)(dir, distDir, "app-path-routes-manifest.json");
59
+ const appPathRoutesManifestJSON = (0, fsutils_1.fileExistsSync)(appPathRoutesManifestPath)
60
+ ? await (0, promises_1.readFile)(appPathRoutesManifestPath).then((it) => JSON.parse(it.toString()))
61
+ : {};
49
62
  const prerenderManifestJSON = await (0, promises_1.readFile)((0, path_1.join)(dir, distDir, "prerender-manifest.json")).then((it) => JSON.parse(it.toString()));
50
63
  const anyDynamicRouteFallbacks = !!Object.values(prerenderManifestJSON.dynamicRoutes || {}).find((it) => it.fallback !== false);
51
64
  const pagesManifestJSON = await (0, promises_1.readFile)((0, path_1.join)(dir, distDir, "server", "pages-manifest.json")).then((it) => JSON.parse(it.toString()));
52
65
  const prerenderedRoutes = Object.keys(prerenderManifestJSON.routes);
53
66
  const dynamicRoutes = Object.keys(prerenderManifestJSON.dynamicRoutes);
54
- const unrenderedPages = Object.keys(pagesManifestJSON).filter((it) => !(["/_app", "/_error", "/_document", "/404"].includes(it) ||
67
+ const unrenderedPages = [
68
+ ...Object.keys(pagesManifestJSON),
69
+ ...Object.values(appPathRoutesManifestJSON),
70
+ ].filter((it) => !(["/_app", "/", "/_error", "/_document", "/404"].includes(it) ||
55
71
  prerenderedRoutes.includes(it) ||
56
72
  dynamicRoutes.includes(it)));
57
73
  if (!anyDynamicRouteFallbacks && unrenderedPages.length === 0) {
@@ -85,7 +101,7 @@ async function init(setup) {
85
101
  message: "What language would you like to use?",
86
102
  choices: ["JavaScript", "TypeScript"],
87
103
  });
88
- (0, child_process_1.execSync)(`npx --yes create-next-app@latest -e hello-world ${setup.hosting.source} ${language === "TypeScript" ? "--ts" : ""}`, { stdio: "inherit" });
104
+ (0, child_process_1.execSync)(`npx --yes create-next-app@latest -e hello-world ${setup.hosting.source} --use-npm ${language === "TypeScript" ? "--ts" : ""}`, { stdio: "inherit" });
89
105
  }
90
106
  exports.init = init;
91
107
  async function ɵcodegenPublicDirectory(sourceDir, destDir) {
@@ -104,20 +120,26 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir) {
104
120
  await (0, fs_extra_1.copy)(publicPath, destDir);
105
121
  }
106
122
  await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, distDir, "static"), (0, path_1.join)(destDir, "_next", "static"));
107
- const serverPagesDir = (0, path_1.join)(sourceDir, distDir, "server", "pages");
108
- await (0, fs_extra_1.copy)(serverPagesDir, destDir, {
109
- filter: async (filename) => {
110
- const status = await (0, promises_1.stat)(filename);
111
- if (status.isDirectory())
112
- return true;
113
- return (0, path_1.extname)(filename) === ".html";
114
- },
115
- });
123
+ for (const file of ["index.html", "404.html", "500.html"]) {
124
+ const pagesPath = (0, path_1.join)(sourceDir, distDir, "server", "pages", file);
125
+ if (await (0, fs_extra_1.pathExists)(pagesPath)) {
126
+ await (0, promises_1.copyFile)(pagesPath, (0, path_1.join)(destDir, file));
127
+ continue;
128
+ }
129
+ const appPath = (0, path_1.join)(sourceDir, distDir, "server", "app", file);
130
+ if (await (0, fs_extra_1.pathExists)(appPath)) {
131
+ await (0, promises_1.copyFile)(appPath, (0, path_1.join)(destDir, file));
132
+ }
133
+ }
116
134
  const prerenderManifestBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, distDir, "prerender-manifest.json"));
117
135
  const prerenderManifest = JSON.parse(prerenderManifestBuffer.toString());
118
- for (const route in prerenderManifest.routes) {
119
- if (prerenderManifest.routes[route]) {
120
- const parts = route
136
+ for (const path in prerenderManifest.routes) {
137
+ if (prerenderManifest.routes[path]) {
138
+ const { initialRevalidateSeconds } = prerenderManifest.routes[path];
139
+ if (initialRevalidateSeconds) {
140
+ continue;
141
+ }
142
+ const parts = path
121
143
  .split("/")
122
144
  .slice(1)
123
145
  .filter((it) => !!it);
@@ -125,10 +147,28 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir) {
125
147
  const dataPath = `${(0, path_1.join)(...partsOrIndex)}.json`;
126
148
  const htmlPath = `${(0, path_1.join)(...partsOrIndex)}.html`;
127
149
  await (0, promises_1.mkdir)((0, path_1.join)(destDir, (0, path_1.dirname)(htmlPath)), { recursive: true });
128
- await (0, promises_1.copyFile)((0, path_1.join)(sourceDir, distDir, "server", "pages", htmlPath), (0, path_1.join)(destDir, htmlPath));
129
- const dataRoute = prerenderManifest.routes[route].dataRoute;
150
+ const pagesHtmlPath = (0, path_1.join)(sourceDir, distDir, "server", "pages", htmlPath);
151
+ if (await (0, fs_extra_1.pathExists)(pagesHtmlPath)) {
152
+ await (0, promises_1.copyFile)(pagesHtmlPath, (0, path_1.join)(destDir, htmlPath));
153
+ }
154
+ else {
155
+ const appHtmlPath = (0, path_1.join)(sourceDir, distDir, "server", "app", htmlPath);
156
+ if (await (0, fs_extra_1.pathExists)(appHtmlPath)) {
157
+ await (0, promises_1.copyFile)(appHtmlPath, (0, path_1.join)(destDir, htmlPath));
158
+ }
159
+ }
160
+ const dataRoute = prerenderManifest.routes[path].dataRoute;
130
161
  await (0, promises_1.mkdir)((0, path_1.join)(destDir, (0, path_1.dirname)(dataRoute)), { recursive: true });
131
- await (0, promises_1.copyFile)((0, path_1.join)(sourceDir, distDir, "server", "pages", dataPath), (0, path_1.join)(destDir, dataRoute));
162
+ const pagesDataPath = (0, path_1.join)(sourceDir, distDir, "server", "pages", dataPath);
163
+ if (await (0, fs_extra_1.pathExists)(pagesDataPath)) {
164
+ await (0, promises_1.copyFile)(pagesDataPath, (0, path_1.join)(destDir, dataRoute));
165
+ }
166
+ else {
167
+ const appDataPath = (0, path_1.join)(sourceDir, distDir, "server", "app", dataPath);
168
+ if (await (0, fs_extra_1.pathExists)(appDataPath)) {
169
+ await (0, promises_1.copyFile)(appDataPath, (0, path_1.join)(destDir, dataRoute));
170
+ }
171
+ }
132
172
  }
133
173
  }
134
174
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.connect = exports.start = exports.stop = void 0;
4
4
  const morgan = require("morgan");
5
- const superstatic_1 = require("superstatic");
5
+ const { server: superstatic } = require("superstatic");
6
6
  const clc = require("colorette");
7
7
  const net_1 = require("net");
8
8
  const detectProjectRoot_1 = require("../detectProjectRoot");
@@ -36,13 +36,13 @@ function startServer(options, config, port, init) {
36
36
  const after = options.frameworksDevModeHandle && {
37
37
  files: options.frameworksDevModeHandle,
38
38
  };
39
- const server = (0, superstatic_1.server)({
39
+ const server = superstatic({
40
40
  debug: false,
41
41
  port: port,
42
- hostname: options.host,
42
+ host: options.host,
43
43
  config: config,
44
44
  compression: true,
45
- cwd: (0, detectProjectRoot_1.detectProjectRoot)(options) || undefined,
45
+ cwd: (0, detectProjectRoot_1.detectProjectRoot)(options),
46
46
  stack: "strict",
47
47
  before: {
48
48
  files: (req, res, next) => {