firebase-tools 11.29.0 → 11.30.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.
- package/lib/commands/database-import.js +2 -2
- package/lib/commands/hosting-channel-deploy.js +3 -0
- package/lib/database/import.js +113 -18
- package/lib/deploy/extensions/secrets.js +2 -2
- package/lib/deploy/functions/ensure.js +7 -1
- package/lib/deploy/functions/release/fabricator.js +2 -0
- package/lib/deploy/functions/runtimes/discovery/index.js +1 -1
- package/lib/deploy/functions/runtimes/index.js +11 -3
- package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +3 -3
- package/lib/deploy/functions/runtimes/python/index.js +41 -13
- package/lib/deploy/hosting/convertConfig.js +8 -4
- package/lib/deploy/hosting/prepare.js +115 -2
- package/lib/deploy/index.js +24 -8
- package/lib/emulator/adminSdkConfig.js +8 -0
- package/lib/emulator/controller.js +7 -9
- package/lib/emulator/download.js +3 -12
- package/lib/emulator/downloadableEmulators.js +5 -5
- package/lib/emulator/functionsEmulator.js +57 -7
- package/lib/emulator/functionsEmulatorRuntime.js +4 -1
- package/lib/emulator/functionsEmulatorShared.js +1 -0
- package/lib/emulator/functionsRuntimeWorker.js +12 -4
- package/lib/experiments.js +20 -7
- package/lib/extensions/extensionsHelper.js +2 -2
- package/lib/frameworks/angular/index.js +13 -13
- package/lib/frameworks/astro/index.js +3 -4
- package/lib/frameworks/constants.js +42 -0
- package/lib/frameworks/express/index.js +3 -2
- package/lib/frameworks/flutter/index.js +39 -0
- package/lib/frameworks/flutter/utils.js +11 -0
- package/lib/frameworks/index.js +58 -131
- package/lib/frameworks/interfaces.js +2 -0
- package/lib/frameworks/next/constants.js +2 -1
- package/lib/frameworks/next/index.js +124 -87
- package/lib/frameworks/next/utils.js +71 -6
- package/lib/frameworks/nuxt/index.js +4 -5
- package/lib/frameworks/nuxt/utils.js +2 -2
- package/lib/frameworks/nuxt2/index.js +5 -5
- package/lib/frameworks/utils.js +101 -1
- package/lib/frameworks/vite/index.js +5 -6
- package/lib/functions/ensureTargeted.js +4 -4
- package/lib/functions/python.js +12 -5
- package/lib/gcp/resourceManager.js +1 -0
- package/lib/hosting/config.js +4 -8
- package/lib/init/features/functions/index.js +4 -7
- package/lib/init/features/hosting/github.js +7 -2
- package/lib/init/features/hosting/index.js +3 -2
- package/lib/serve/index.js +2 -1
- package/lib/unzip.js +126 -0
- package/npm-shrinkwrap.json +6 -287
- package/package.json +1 -2
- package/schema/firebase-config.json +1 -1
- package/templates/init/functions/python/requirements.txt +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDevModeHandle = exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.init = exports.build = exports.discover = exports.type = exports.support = exports.name = void 0;
|
|
3
|
+
exports.getDevModeHandle = exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.init = exports.build = exports.discover = exports.docsUrl = exports.type = exports.support = exports.name = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const cross_spawn_1 = require("cross-spawn");
|
|
6
6
|
const promises_1 = require("fs/promises");
|
|
@@ -14,27 +14,27 @@ const stream_chain_1 = require("stream-chain");
|
|
|
14
14
|
const stream_json_1 = require("stream-json");
|
|
15
15
|
const Pick_1 = require("stream-json/filters/Pick");
|
|
16
16
|
const StreamObject_1 = require("stream-json/streamers/StreamObject");
|
|
17
|
-
const
|
|
17
|
+
const fsutils_1 = require("../../fsutils");
|
|
18
18
|
const prompt_1 = require("../../prompt");
|
|
19
19
|
const error_1 = require("../../error");
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const constants_1 = require("./constants");
|
|
20
|
+
const constants_1 = require("../constants");
|
|
21
|
+
const utils_1 = require("../utils");
|
|
22
|
+
const utils_2 = require("./utils");
|
|
23
|
+
const constants_2 = require("./constants");
|
|
25
24
|
const DEFAULT_BUILD_SCRIPT = ["next build"];
|
|
26
25
|
const PUBLIC_DIR = "public";
|
|
27
26
|
exports.name = "Next.js";
|
|
28
|
-
exports.support = "
|
|
27
|
+
exports.support = "preview";
|
|
29
28
|
exports.type = 2;
|
|
29
|
+
exports.docsUrl = "https://firebase.google.com/docs/hosting/frameworks/nextjs";
|
|
30
30
|
const DEFAULT_NUMBER_OF_REASONS_TO_LIST = 5;
|
|
31
31
|
function getNextVersion(cwd) {
|
|
32
32
|
var _a;
|
|
33
|
-
return (_a = (0,
|
|
33
|
+
return (_a = (0, utils_1.findDependency)("next", { cwd, depth: 0, omitDev: false })) === null || _a === void 0 ? void 0 : _a.version;
|
|
34
34
|
}
|
|
35
35
|
function getReactVersion(cwd) {
|
|
36
36
|
var _a;
|
|
37
|
-
return (_a = (0,
|
|
37
|
+
return (_a = (0, utils_1.findDependency)("react-dom", { cwd, omitDev: false })) === null || _a === void 0 ? void 0 : _a.version;
|
|
38
38
|
}
|
|
39
39
|
async function discover(dir) {
|
|
40
40
|
if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
|
|
@@ -46,8 +46,8 @@ async function discover(dir) {
|
|
|
46
46
|
exports.discover = discover;
|
|
47
47
|
async function build(dir) {
|
|
48
48
|
var _a, _b;
|
|
49
|
-
const { default: nextBuild } = (0,
|
|
50
|
-
await (0,
|
|
49
|
+
const { default: nextBuild } = (0, utils_1.relativeRequire)(dir, "next/dist/build");
|
|
50
|
+
await (0, utils_1.warnIfCustomBuildScript)(dir, exports.name, DEFAULT_BUILD_SCRIPT);
|
|
51
51
|
const reactVersion = getReactVersion(dir);
|
|
52
52
|
if (reactVersion && (0, semver_1.gte)(reactVersion, "18.0.0")) {
|
|
53
53
|
process.env.__NEXT_REACT_ROOT = "true";
|
|
@@ -56,88 +56,97 @@ async function build(dir) {
|
|
|
56
56
|
console.error(e.message);
|
|
57
57
|
throw e;
|
|
58
58
|
});
|
|
59
|
-
const reasonsForBackend =
|
|
59
|
+
const reasonsForBackend = new Set();
|
|
60
60
|
const { distDir, trailingSlash } = await getConfig(dir);
|
|
61
|
-
if (await (0,
|
|
62
|
-
reasonsForBackend.
|
|
61
|
+
if (await (0, utils_2.isUsingMiddleware)((0, path_1.join)(dir, distDir), false)) {
|
|
62
|
+
reasonsForBackend.add("middleware");
|
|
63
63
|
}
|
|
64
|
-
if (await (0,
|
|
65
|
-
reasonsForBackend.
|
|
64
|
+
if (await (0, utils_2.isUsingImageOptimization)((0, path_1.join)(dir, distDir))) {
|
|
65
|
+
reasonsForBackend.add(`Image Optimization`);
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
reasonsForBackend.push("app directory (unstable)");
|
|
69
|
-
}
|
|
70
|
-
const prerenderManifest = await (0, utils_2.readJSON)((0, path_1.join)(dir, distDir, constants_1.PRERENDER_MANIFEST));
|
|
67
|
+
const prerenderManifest = await (0, utils_1.readJSON)((0, path_1.join)(dir, distDir, constants_2.PRERENDER_MANIFEST));
|
|
71
68
|
const dynamicRoutesWithFallback = Object.entries(prerenderManifest.dynamicRoutes || {}).filter(([, it]) => it.fallback !== false);
|
|
72
69
|
if (dynamicRoutesWithFallback.length > 0) {
|
|
73
70
|
for (const [key] of dynamicRoutesWithFallback) {
|
|
74
|
-
reasonsForBackend.
|
|
71
|
+
reasonsForBackend.add(`use of fallback ${key}`);
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
const routesWithRevalidate = Object.entries(prerenderManifest.routes).filter(([, it]) => it.initialRevalidateSeconds);
|
|
78
75
|
if (routesWithRevalidate.length > 0) {
|
|
79
|
-
for (const [
|
|
80
|
-
reasonsForBackend.
|
|
76
|
+
for (const [, { srcRoute }] of routesWithRevalidate) {
|
|
77
|
+
reasonsForBackend.add(`use of revalidate ${srcRoute}`);
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
|
-
const pagesManifestJSON = await (0,
|
|
80
|
+
const pagesManifestJSON = await (0, utils_1.readJSON)((0, path_1.join)(dir, distDir, "server", constants_2.PAGES_MANIFEST));
|
|
84
81
|
const prerenderedRoutes = Object.keys(prerenderManifest.routes);
|
|
85
82
|
const dynamicRoutes = Object.keys(prerenderManifest.dynamicRoutes);
|
|
86
|
-
const unrenderedPages =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (unrenderedPages.length > 0) {
|
|
90
|
-
for (const key of unrenderedPages) {
|
|
91
|
-
reasonsForBackend.push(`non-static route ${key}`);
|
|
92
|
-
}
|
|
83
|
+
const unrenderedPages = (0, utils_2.getNonStaticRoutes)(pagesManifestJSON, prerenderedRoutes, dynamicRoutes);
|
|
84
|
+
for (const key of unrenderedPages) {
|
|
85
|
+
reasonsForBackend.add(`non-static route ${key}`);
|
|
93
86
|
}
|
|
94
|
-
const manifest = await (0,
|
|
87
|
+
const manifest = await (0, utils_1.readJSON)((0, path_1.join)(dir, distDir, constants_2.ROUTES_MANIFEST));
|
|
95
88
|
const { headers: nextJsHeaders = [], redirects: nextJsRedirects = [], rewrites: nextJsRewrites = [], } = manifest;
|
|
96
|
-
const isEveryHeaderSupported = nextJsHeaders.every(
|
|
89
|
+
const isEveryHeaderSupported = nextJsHeaders.every(utils_2.isHeaderSupportedByHosting);
|
|
97
90
|
if (!isEveryHeaderSupported) {
|
|
98
|
-
reasonsForBackend.
|
|
91
|
+
reasonsForBackend.add("advanced headers");
|
|
99
92
|
}
|
|
100
|
-
const headers = nextJsHeaders
|
|
101
|
-
|
|
93
|
+
const headers = nextJsHeaders
|
|
94
|
+
.filter(utils_2.isHeaderSupportedByHosting)
|
|
95
|
+
.map(({ source, headers }) => ({
|
|
96
|
+
source: (0, utils_2.cleanEscapedChars)(source),
|
|
102
97
|
headers,
|
|
103
98
|
}));
|
|
99
|
+
const [appPathsManifest, appPathRoutesManifest] = await Promise.all([
|
|
100
|
+
(0, utils_1.readJSON)((0, path_1.join)(dir, distDir, "server", constants_2.APP_PATHS_MANIFEST)).catch(() => undefined),
|
|
101
|
+
(0, utils_1.readJSON)((0, path_1.join)(dir, distDir, constants_2.APP_PATH_ROUTES_MANIFEST)).catch(() => undefined),
|
|
102
|
+
]);
|
|
103
|
+
if (appPathRoutesManifest) {
|
|
104
|
+
const headersFromMetaFiles = await (0, utils_2.getHeadersFromMetaFiles)(dir, distDir, appPathRoutesManifest);
|
|
105
|
+
headers.push(...headersFromMetaFiles);
|
|
106
|
+
if (appPathsManifest) {
|
|
107
|
+
const unrenderedServerComponents = (0, utils_2.getNonStaticServerComponents)(appPathsManifest, appPathRoutesManifest, prerenderedRoutes, dynamicRoutes);
|
|
108
|
+
for (const key of unrenderedServerComponents) {
|
|
109
|
+
reasonsForBackend.add(`non-static component ${key}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
104
113
|
const isEveryRedirectSupported = nextJsRedirects
|
|
105
114
|
.filter((it) => !it.internal)
|
|
106
|
-
.every(
|
|
115
|
+
.every(utils_2.isRedirectSupportedByHosting);
|
|
107
116
|
if (!isEveryRedirectSupported) {
|
|
108
|
-
reasonsForBackend.
|
|
117
|
+
reasonsForBackend.add("advanced redirects");
|
|
109
118
|
}
|
|
110
119
|
const redirects = nextJsRedirects
|
|
111
|
-
.filter(
|
|
120
|
+
.filter(utils_2.isRedirectSupportedByHosting)
|
|
112
121
|
.map(({ source, destination, statusCode: type }) => ({
|
|
113
|
-
source: (0,
|
|
122
|
+
source: (0, utils_2.cleanEscapedChars)(source),
|
|
114
123
|
destination,
|
|
115
124
|
type,
|
|
116
125
|
}));
|
|
117
|
-
const nextJsRewritesToUse = (0,
|
|
126
|
+
const nextJsRewritesToUse = (0, utils_2.getNextjsRewritesToUse)(nextJsRewrites);
|
|
118
127
|
if (!Array.isArray(nextJsRewrites) &&
|
|
119
128
|
(((_a = nextJsRewrites.afterFiles) === null || _a === void 0 ? void 0 : _a.length) || ((_b = nextJsRewrites.fallback) === null || _b === void 0 ? void 0 : _b.length))) {
|
|
120
|
-
reasonsForBackend.
|
|
129
|
+
reasonsForBackend.add("advanced rewrites");
|
|
121
130
|
}
|
|
122
|
-
const isEveryRewriteSupported = nextJsRewritesToUse.every(
|
|
131
|
+
const isEveryRewriteSupported = nextJsRewritesToUse.every(utils_2.isRewriteSupportedByHosting);
|
|
123
132
|
if (!isEveryRewriteSupported) {
|
|
124
|
-
reasonsForBackend.
|
|
133
|
+
reasonsForBackend.add("advanced rewrites");
|
|
125
134
|
}
|
|
126
135
|
const rewrites = nextJsRewritesToUse
|
|
127
|
-
.filter(
|
|
136
|
+
.filter(utils_2.isRewriteSupportedByHosting)
|
|
128
137
|
.map(({ source, destination }) => ({
|
|
129
|
-
source: (0,
|
|
138
|
+
source: (0, utils_2.cleanEscapedChars)(source),
|
|
130
139
|
destination,
|
|
131
140
|
}));
|
|
132
|
-
const wantsBackend = reasonsForBackend.
|
|
141
|
+
const wantsBackend = reasonsForBackend.size > 0;
|
|
133
142
|
if (wantsBackend) {
|
|
134
143
|
const numberOfReasonsToList = process.env.DEBUG ? Infinity : DEFAULT_NUMBER_OF_REASONS_TO_LIST;
|
|
135
144
|
console.log("Building a Cloud Function to run this application. This is needed due to:");
|
|
136
|
-
for (const reason of reasonsForBackend.slice(0, numberOfReasonsToList)) {
|
|
145
|
+
for (const reason of Array.from(reasonsForBackend).slice(0, numberOfReasonsToList)) {
|
|
137
146
|
console.log(` • ${reason}`);
|
|
138
147
|
}
|
|
139
|
-
if (reasonsForBackend.
|
|
140
|
-
console.log(` • and ${reasonsForBackend.
|
|
148
|
+
if (reasonsForBackend.size > numberOfReasonsToList) {
|
|
149
|
+
console.log(` • and ${reasonsForBackend.size - numberOfReasonsToList} other reasons, use --debug to see more`);
|
|
141
150
|
}
|
|
142
151
|
console.log("");
|
|
143
152
|
}
|
|
@@ -173,24 +182,24 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir) {
|
|
|
173
182
|
await (0, promises_1.copyFile)(appPath, (0, path_1.join)(destDir, file));
|
|
174
183
|
}
|
|
175
184
|
}
|
|
176
|
-
const [middlewareManifest, prerenderManifest, routesManifest] = await Promise.all([
|
|
177
|
-
(0,
|
|
178
|
-
(0,
|
|
179
|
-
(0,
|
|
185
|
+
const [middlewareManifest, prerenderManifest, routesManifest, pagesManifest, appPathRoutesManifest,] = await Promise.all([
|
|
186
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, "server", constants_2.MIDDLEWARE_MANIFEST)),
|
|
187
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, constants_2.PRERENDER_MANIFEST)),
|
|
188
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, constants_2.ROUTES_MANIFEST)),
|
|
189
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, "server", constants_2.PAGES_MANIFEST)),
|
|
190
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, constants_2.APP_PATH_ROUTES_MANIFEST)).catch(() => ({})),
|
|
180
191
|
]);
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
.flat()
|
|
184
|
-
.map((it) => new RegExp(it.regexp));
|
|
192
|
+
const appPathRoutesEntries = Object.entries(appPathRoutesManifest);
|
|
193
|
+
const middlewareMatcherRegexes = (0, utils_2.getMiddlewareMatcherRegexes)(middlewareManifest);
|
|
185
194
|
const { redirects = [], rewrites = [], headers = [] } = routesManifest;
|
|
186
|
-
const rewritesRegexesNotSupportedByHosting = (0,
|
|
187
|
-
.filter((rewrite) => !(0,
|
|
195
|
+
const rewritesRegexesNotSupportedByHosting = (0, utils_2.getNextjsRewritesToUse)(rewrites)
|
|
196
|
+
.filter((rewrite) => !(0, utils_2.isRewriteSupportedByHosting)(rewrite))
|
|
188
197
|
.map((rewrite) => new RegExp(rewrite.regex));
|
|
189
198
|
const redirectsRegexesNotSupportedByHosting = redirects
|
|
190
|
-
.filter((redirect) => !(0,
|
|
199
|
+
.filter((redirect) => !(0, utils_2.isRedirectSupportedByHosting)(redirect))
|
|
191
200
|
.map((redirect) => new RegExp(redirect.regex));
|
|
192
201
|
const headersRegexesNotSupportedByHosting = headers
|
|
193
|
-
.filter((header) => !(0,
|
|
202
|
+
.filter((header) => !(0, utils_2.isHeaderSupportedByHosting)(header))
|
|
194
203
|
.map((header) => new RegExp(header.regex));
|
|
195
204
|
const pathsUsingsFeaturesNotSupportedByHosting = [
|
|
196
205
|
...middlewareMatcherRegexes,
|
|
@@ -198,41 +207,66 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir) {
|
|
|
198
207
|
...redirectsRegexesNotSupportedByHosting,
|
|
199
208
|
...headersRegexesNotSupportedByHosting,
|
|
200
209
|
];
|
|
201
|
-
|
|
210
|
+
const pagesManifestLikePrerender = Object.fromEntries(Object.entries(pagesManifest)
|
|
211
|
+
.filter(([, srcRoute]) => srcRoute.endsWith(".html"))
|
|
212
|
+
.map(([path]) => {
|
|
213
|
+
return [path, { srcRoute: null, initialRevalidateSeconds: false, dataRoute: "" }];
|
|
214
|
+
}));
|
|
215
|
+
const routesToCopy = Object.assign(Object.assign({}, prerenderManifest.routes), pagesManifestLikePrerender);
|
|
216
|
+
await Promise.all(Object.entries(routesToCopy).map(async ([path, route]) => {
|
|
217
|
+
var _a;
|
|
202
218
|
if (route.initialRevalidateSeconds ||
|
|
203
219
|
pathsUsingsFeaturesNotSupportedByHosting.some((it) => path.match(it))) {
|
|
204
|
-
|
|
220
|
+
return;
|
|
205
221
|
}
|
|
206
|
-
const
|
|
207
|
-
const contentDist = (0, path_1.join)(sourceDir, distDir, "server",
|
|
222
|
+
const appPathRoute = route.srcRoute && ((_a = appPathRoutesEntries.find(([, it]) => it === route.srcRoute)) === null || _a === void 0 ? void 0 : _a[0]);
|
|
223
|
+
const contentDist = (0, path_1.join)(sourceDir, distDir, "server", appPathRoute ? "app" : "pages");
|
|
208
224
|
const parts = path.split("/").filter((it) => !!it);
|
|
209
225
|
const partsOrIndex = parts.length > 0 ? parts : ["index"];
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
await (0, promises_1.mkdir)((0, path_1.join)(destDir, (0, path_1.dirname)(route.dataRoute)), { recursive: true });
|
|
216
|
-
await (0, promises_1.copyFile)((0, path_1.join)(contentDist, dataPath), (0, path_1.join)(destDir, route.dataRoute));
|
|
226
|
+
let sourcePath = (0, path_1.join)(contentDist, ...partsOrIndex);
|
|
227
|
+
let destPath = (0, path_1.join)(destDir, ...partsOrIndex);
|
|
228
|
+
if (!(0, fsutils_1.fileExistsSync)(sourcePath) && (0, fsutils_1.fileExistsSync)(`${sourcePath}.html`)) {
|
|
229
|
+
sourcePath += ".html";
|
|
230
|
+
destPath += ".html";
|
|
217
231
|
}
|
|
218
|
-
|
|
232
|
+
else if (appPathRoute && (0, path_1.basename)(appPathRoute) === "route" && (0, fsutils_1.dirExistsSync)(sourcePath)) {
|
|
233
|
+
sourcePath += ".body";
|
|
234
|
+
}
|
|
235
|
+
if (!(0, fs_extra_1.pathExistsSync)(sourcePath)) {
|
|
236
|
+
console.error(`Cannot find ${path} in your compiled Next.js application.`);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(destPath), { recursive: true });
|
|
240
|
+
await (0, promises_1.copyFile)(sourcePath, destPath);
|
|
241
|
+
if (route.dataRoute && !appPathRoute) {
|
|
242
|
+
const dataSourcePath = `${(0, path_1.join)(...partsOrIndex)}.json`;
|
|
243
|
+
const dataDestPath = (0, path_1.join)(destDir, route.dataRoute);
|
|
244
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(dataDestPath), { recursive: true });
|
|
245
|
+
await (0, promises_1.copyFile)((0, path_1.join)(contentDist, dataSourcePath), dataDestPath);
|
|
246
|
+
}
|
|
247
|
+
}));
|
|
219
248
|
}
|
|
220
249
|
exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
|
|
250
|
+
const BUNDLE_NEXT_CONFIG_TIMEOUT = 10000;
|
|
221
251
|
async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
222
252
|
const { distDir } = await getConfig(sourceDir);
|
|
223
|
-
const packageJson = await (0,
|
|
253
|
+
const packageJson = await (0, utils_1.readJSON)((0, path_1.join)(sourceDir, "package.json"));
|
|
224
254
|
if ((0, fs_1.existsSync)((0, path_1.join)(sourceDir, "next.config.js"))) {
|
|
225
255
|
try {
|
|
226
256
|
const productionDeps = await new Promise((resolve) => {
|
|
227
257
|
const dependencies = [];
|
|
258
|
+
const npmLs = (0, cross_spawn_1.spawn)("npm", ["ls", "--omit=dev", "--all", "--json=true"], {
|
|
259
|
+
cwd: sourceDir,
|
|
260
|
+
timeout: constants_1.NPM_COMMAND_TIMEOUT_MILLIES,
|
|
261
|
+
});
|
|
228
262
|
const pipeline = (0, stream_chain_1.chain)([
|
|
229
|
-
|
|
263
|
+
npmLs.stdout,
|
|
230
264
|
(0, stream_json_1.parser)({ packValues: false, packKeys: true, streamValues: false }),
|
|
231
265
|
(0, Pick_1.pick)({ filter: "dependencies" }),
|
|
232
266
|
(0, StreamObject_1.streamObject)(),
|
|
233
267
|
({ key, value }) => [
|
|
234
268
|
key,
|
|
235
|
-
...(0,
|
|
269
|
+
...(0, utils_2.allDependencyNames)(value),
|
|
236
270
|
],
|
|
237
271
|
]);
|
|
238
272
|
pipeline.on("data", (it) => dependencies.push(it));
|
|
@@ -242,9 +276,10 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
242
276
|
});
|
|
243
277
|
const esbuildArgs = productionDeps
|
|
244
278
|
.map((it) => `--external:${it}`)
|
|
245
|
-
.concat("--bundle", "--platform=node", `--target=node${
|
|
279
|
+
.concat("--bundle", "--platform=node", `--target=node${constants_1.NODE_VERSION}`, `--outdir=${destDir}`, "--log-level=error");
|
|
246
280
|
const bundle = (0, cross_spawn_1.sync)("npx", ["--yes", "esbuild", "next.config.js", ...esbuildArgs], {
|
|
247
281
|
cwd: sourceDir,
|
|
282
|
+
timeout: BUNDLE_NEXT_CONFIG_TIMEOUT,
|
|
248
283
|
});
|
|
249
284
|
if (bundle.status) {
|
|
250
285
|
throw new error_1.FirebaseError(bundle.stderr.toString());
|
|
@@ -252,7 +287,7 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
252
287
|
}
|
|
253
288
|
catch (e) {
|
|
254
289
|
console.warn("Unable to bundle next.config.js for use in Cloud Functions, proceeding with deploy but problems may be enountered.");
|
|
255
|
-
console.error(e.message);
|
|
290
|
+
console.error(e.message || e);
|
|
256
291
|
(0, fs_extra_1.copy)((0, path_1.join)(sourceDir, "next.config.js"), (0, path_1.join)(destDir, "next.config.js"));
|
|
257
292
|
}
|
|
258
293
|
}
|
|
@@ -260,8 +295,8 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
260
295
|
await (0, promises_1.mkdir)((0, path_1.join)(destDir, "public"));
|
|
261
296
|
await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, "public"), (0, path_1.join)(destDir, "public"));
|
|
262
297
|
}
|
|
263
|
-
if (!(await (0,
|
|
264
|
-
((0,
|
|
298
|
+
if (!(await (0, utils_2.hasUnoptimizedImage)(sourceDir, distDir)) &&
|
|
299
|
+
((0, utils_2.usesAppDirRouter)(sourceDir) || (await (0, utils_2.usesNextImage)(sourceDir, distDir)))) {
|
|
265
300
|
packageJson.dependencies["sharp"] = "latest";
|
|
266
301
|
}
|
|
267
302
|
await (0, fs_extra_1.mkdirp)((0, path_1.join)(destDir, distDir));
|
|
@@ -271,11 +306,13 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
271
306
|
exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
|
|
272
307
|
async function getDevModeHandle(dir, hostingEmulatorInfo) {
|
|
273
308
|
if (!hostingEmulatorInfo) {
|
|
274
|
-
if (await (0,
|
|
309
|
+
if (await (0, utils_2.isUsingMiddleware)(dir, true)) {
|
|
275
310
|
throw new error_1.FirebaseError(`${clc.bold("firebase serve")} does not support Next.js Middleware. Please use ${clc.bold("firebase emulators:start")} instead.`);
|
|
276
311
|
}
|
|
277
312
|
}
|
|
278
|
-
|
|
313
|
+
let next = (0, utils_1.relativeRequire)(dir, "next");
|
|
314
|
+
if ("default" in next)
|
|
315
|
+
next = next.default;
|
|
279
316
|
const nextApp = next({
|
|
280
317
|
dev: true,
|
|
281
318
|
dir,
|
|
@@ -284,7 +321,7 @@ async function getDevModeHandle(dir, hostingEmulatorInfo) {
|
|
|
284
321
|
});
|
|
285
322
|
const handler = nextApp.getRequestHandler();
|
|
286
323
|
await nextApp.prepare();
|
|
287
|
-
return (0,
|
|
324
|
+
return (0, utils_1.simpleProxy)(async (req, res) => {
|
|
288
325
|
const parsedUrl = (0, url_1.parse)(req.url, true);
|
|
289
326
|
await handler(req, res, parsedUrl);
|
|
290
327
|
});
|
|
@@ -298,8 +335,8 @@ async function getConfig(dir) {
|
|
|
298
335
|
if (!version)
|
|
299
336
|
throw new Error("Unable to find the next dep, try NPM installing?");
|
|
300
337
|
if ((0, semver_1.gte)(version, "12.0.0")) {
|
|
301
|
-
const { default: loadConfig } = (0,
|
|
302
|
-
const { PHASE_PRODUCTION_BUILD } = (0,
|
|
338
|
+
const { default: loadConfig } = (0, utils_1.relativeRequire)(dir, "next/dist/server/config");
|
|
339
|
+
const { PHASE_PRODUCTION_BUILD } = (0, utils_1.relativeRequire)(dir, "next/constants");
|
|
303
340
|
config = await loadConfig(PHASE_PRODUCTION_BUILD, dir, null);
|
|
304
341
|
}
|
|
305
342
|
else {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.allDependencyNames = exports.isUsingAppDirectory = exports.isUsingImageOptimization = exports.isUsingMiddleware = exports.hasUnoptimizedImage = exports.usesNextImage = exports.usesAppDirRouter = exports.getNextjsRewritesToUse = exports.isHeaderSupportedByHosting = exports.isRedirectSupportedByHosting = exports.isRewriteSupportedByHosting = exports.cleanEscapedChars = exports.pathHasRegex = void 0;
|
|
3
|
+
exports.getBuildId = exports.getHeadersFromMetaFiles = exports.getNonStaticServerComponents = exports.getNonStaticRoutes = exports.getMiddlewareMatcherRegexes = exports.allDependencyNames = exports.isUsingAppDirectory = exports.isUsingImageOptimization = exports.isUsingMiddleware = exports.hasUnoptimizedImage = exports.usesNextImage = exports.usesAppDirRouter = exports.getNextjsRewritesToUse = exports.isHeaderSupportedByHosting = exports.isRedirectSupportedByHosting = exports.isRewriteSupportedByHosting = exports.cleanEscapedChars = exports.pathHasRegex = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const fs_extra_1 = require("fs-extra");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const utils_1 = require("../utils");
|
|
8
8
|
const constants_1 = require("./constants");
|
|
9
9
|
const fsutils_1 = require("../../fsutils");
|
|
10
|
+
const promises_1 = require("fs/promises");
|
|
10
11
|
function pathHasRegex(path) {
|
|
11
12
|
return /(?<!\\)\(/.test(path);
|
|
12
13
|
}
|
|
@@ -67,13 +68,15 @@ async function isUsingMiddleware(dir, isDevMode) {
|
|
|
67
68
|
}
|
|
68
69
|
exports.isUsingMiddleware = isUsingMiddleware;
|
|
69
70
|
async function isUsingImageOptimization(dir) {
|
|
70
|
-
|
|
71
|
+
let { isNextImageImported } = await (0, utils_1.readJSON)((0, path_1.join)(dir, constants_1.EXPORT_MARKER));
|
|
72
|
+
if (!isNextImageImported && isUsingAppDirectory(dir)) {
|
|
73
|
+
isNextImageImported = (await (0, promises_1.readFile)((0, path_1.join)(dir, "server", "client-reference-manifest.js")))
|
|
74
|
+
.toString()
|
|
75
|
+
.includes("node_modules/next/dist/client/image.js");
|
|
76
|
+
}
|
|
71
77
|
if (isNextImageImported) {
|
|
72
78
|
const imagesManifest = await (0, utils_1.readJSON)((0, path_1.join)(dir, constants_1.IMAGES_MANIFEST));
|
|
73
|
-
|
|
74
|
-
if (usingImageOptimization) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
79
|
+
return !imagesManifest.images.unoptimized;
|
|
77
80
|
}
|
|
78
81
|
return false;
|
|
79
82
|
}
|
|
@@ -90,3 +93,65 @@ function allDependencyNames(mod) {
|
|
|
90
93
|
return dependencyNames;
|
|
91
94
|
}
|
|
92
95
|
exports.allDependencyNames = allDependencyNames;
|
|
96
|
+
function getMiddlewareMatcherRegexes(middlewareManifest) {
|
|
97
|
+
const middlewareObjectValues = Object.values(middlewareManifest.middleware);
|
|
98
|
+
let middlewareMatchers;
|
|
99
|
+
if (middlewareManifest.version === 1) {
|
|
100
|
+
middlewareMatchers = middlewareObjectValues.map((page) => ({ regexp: page.regexp }));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
middlewareMatchers = middlewareObjectValues
|
|
104
|
+
.map((page) => page.matchers)
|
|
105
|
+
.flat();
|
|
106
|
+
}
|
|
107
|
+
return middlewareMatchers.map((matcher) => new RegExp(matcher.regexp));
|
|
108
|
+
}
|
|
109
|
+
exports.getMiddlewareMatcherRegexes = getMiddlewareMatcherRegexes;
|
|
110
|
+
function getNonStaticRoutes(pagesManifestJSON, prerenderedRoutes, dynamicRoutes) {
|
|
111
|
+
const nonStaticRoutes = Object.entries(pagesManifestJSON)
|
|
112
|
+
.filter(([it, src]) => !((0, path_1.extname)(src) !== ".js" ||
|
|
113
|
+
["/_app", "/_error", "/_document"].includes(it) ||
|
|
114
|
+
prerenderedRoutes.includes(it) ||
|
|
115
|
+
dynamicRoutes.includes(it)))
|
|
116
|
+
.map(([it]) => it);
|
|
117
|
+
return nonStaticRoutes;
|
|
118
|
+
}
|
|
119
|
+
exports.getNonStaticRoutes = getNonStaticRoutes;
|
|
120
|
+
function getNonStaticServerComponents(appPathsManifest, appPathRoutesManifest, prerenderedRoutes, dynamicRoutes) {
|
|
121
|
+
const nonStaticServerComponents = Object.entries(appPathsManifest)
|
|
122
|
+
.filter(([it, src]) => {
|
|
123
|
+
if ((0, path_1.extname)(src) !== ".js")
|
|
124
|
+
return;
|
|
125
|
+
const path = appPathRoutesManifest[it];
|
|
126
|
+
return !(prerenderedRoutes.includes(path) || dynamicRoutes.includes(path));
|
|
127
|
+
})
|
|
128
|
+
.map(([it]) => it);
|
|
129
|
+
return nonStaticServerComponents;
|
|
130
|
+
}
|
|
131
|
+
exports.getNonStaticServerComponents = getNonStaticServerComponents;
|
|
132
|
+
async function getHeadersFromMetaFiles(sourceDir, distDir, appPathRoutesManifest) {
|
|
133
|
+
const headers = [];
|
|
134
|
+
await Promise.all(Object.entries(appPathRoutesManifest).map(async ([key, source]) => {
|
|
135
|
+
if ((0, path_1.basename)(key) !== "route")
|
|
136
|
+
return;
|
|
137
|
+
const parts = source.split("/").filter((it) => !!it);
|
|
138
|
+
const partsOrIndex = parts.length > 0 ? parts : ["index"];
|
|
139
|
+
const routePath = (0, path_1.join)(sourceDir, distDir, "server", "app", ...partsOrIndex);
|
|
140
|
+
const metadataPath = `${routePath}.meta`;
|
|
141
|
+
if ((0, fsutils_1.dirExistsSync)(routePath) && (0, fsutils_1.fileExistsSync)(metadataPath)) {
|
|
142
|
+
const meta = await (0, utils_1.readJSON)(metadataPath);
|
|
143
|
+
if (meta.headers)
|
|
144
|
+
headers.push({
|
|
145
|
+
source,
|
|
146
|
+
headers: Object.entries(meta.headers).map(([key, value]) => ({ key, value })),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}));
|
|
150
|
+
return headers;
|
|
151
|
+
}
|
|
152
|
+
exports.getHeadersFromMetaFiles = getHeadersFromMetaFiles;
|
|
153
|
+
async function getBuildId(distDir) {
|
|
154
|
+
const buildId = await (0, promises_1.readFile)((0, path_1.join)(distDir, "BUILD_ID"));
|
|
155
|
+
return buildId.toString();
|
|
156
|
+
}
|
|
157
|
+
exports.getBuildId = getBuildId;
|
|
@@ -6,7 +6,6 @@ const promises_1 = require("fs/promises");
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const semver_1 = require("semver");
|
|
8
8
|
const cross_spawn_1 = require("cross-spawn");
|
|
9
|
-
const __1 = require("..");
|
|
10
9
|
const utils_1 = require("../utils");
|
|
11
10
|
const utils_2 = require("./utils");
|
|
12
11
|
exports.name = "Nuxt";
|
|
@@ -28,7 +27,7 @@ async function discover(dir) {
|
|
|
28
27
|
}
|
|
29
28
|
exports.discover = discover;
|
|
30
29
|
async function build(root) {
|
|
31
|
-
const { buildNuxt } = await (0,
|
|
30
|
+
const { buildNuxt } = await (0, utils_1.relativeRequire)(root, "@nuxt/kit");
|
|
32
31
|
const nuxtApp = await getNuxt3App(root);
|
|
33
32
|
await (0, utils_1.warnIfCustomBuildScript)(root, exports.name, DEFAULT_BUILD_SCRIPT);
|
|
34
33
|
await buildNuxt(nuxtApp);
|
|
@@ -36,7 +35,7 @@ async function build(root) {
|
|
|
36
35
|
}
|
|
37
36
|
exports.build = build;
|
|
38
37
|
async function getNuxt3App(cwd) {
|
|
39
|
-
const { loadNuxt } = await (0,
|
|
38
|
+
const { loadNuxt } = await (0, utils_1.relativeRequire)(cwd, "@nuxt/kit");
|
|
40
39
|
return await loadNuxt({
|
|
41
40
|
cwd,
|
|
42
41
|
overrides: {
|
|
@@ -60,7 +59,7 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
60
59
|
exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
|
|
61
60
|
async function getDevModeHandle(cwd) {
|
|
62
61
|
const host = new Promise((resolve) => {
|
|
63
|
-
const cli = (0,
|
|
62
|
+
const cli = (0, utils_1.getNodeModuleBin)("nuxt", cwd);
|
|
64
63
|
const serve = (0, cross_spawn_1.spawn)(cli, ["dev"], { cwd: cwd });
|
|
65
64
|
serve.stdout.on("data", (data) => {
|
|
66
65
|
process.stdout.write(data);
|
|
@@ -76,7 +75,7 @@ async function getDevModeHandle(cwd) {
|
|
|
76
75
|
}
|
|
77
76
|
exports.getDevModeHandle = getDevModeHandle;
|
|
78
77
|
async function getConfig(dir) {
|
|
79
|
-
const { loadNuxtConfig } = await (0,
|
|
78
|
+
const { loadNuxtConfig } = await (0, utils_1.relativeRequire)(dir, "@nuxt/kit");
|
|
80
79
|
return await loadNuxtConfig(dir);
|
|
81
80
|
}
|
|
82
81
|
exports.getConfig = getConfig;
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.nuxtConfigFilesExist = exports.getNuxtVersion = void 0;
|
|
4
4
|
const fs_extra_1 = require("fs-extra");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
7
|
function getNuxtVersion(cwd) {
|
|
8
8
|
var _a;
|
|
9
|
-
return (_a = (0,
|
|
9
|
+
return (_a = (0, utils_1.findDependency)("nuxt", {
|
|
10
10
|
cwd,
|
|
11
11
|
depth: 0,
|
|
12
12
|
omitDev: false,
|
|
@@ -5,16 +5,16 @@ const fs_extra_1 = require("fs-extra");
|
|
|
5
5
|
const promises_1 = require("fs/promises");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const semver_1 = require("semver");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const utils_2 = require("../nuxt/utils");
|
|
10
10
|
exports.name = "Nuxt";
|
|
11
11
|
exports.support = "experimental";
|
|
12
12
|
exports.type = 2;
|
|
13
13
|
async function discover(dir) {
|
|
14
14
|
if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
|
|
15
15
|
return;
|
|
16
|
-
const nuxtVersion = (0,
|
|
17
|
-
const anyConfigFileExists = await (0,
|
|
16
|
+
const nuxtVersion = (0, utils_2.getNuxtVersion)(dir);
|
|
17
|
+
const anyConfigFileExists = await (0, utils_2.nuxtConfigFilesExist)(dir);
|
|
18
18
|
if (!anyConfigFileExists && !nuxtVersion)
|
|
19
19
|
return;
|
|
20
20
|
if (nuxtVersion && (0, semver_1.lt)(nuxtVersion, "3.0.0-0"))
|
|
@@ -22,7 +22,7 @@ async function discover(dir) {
|
|
|
22
22
|
}
|
|
23
23
|
exports.discover = discover;
|
|
24
24
|
async function getNuxtApp(cwd) {
|
|
25
|
-
return await (0,
|
|
25
|
+
return await (0, utils_1.relativeRequire)(cwd, "nuxt/dist/nuxt.js");
|
|
26
26
|
}
|
|
27
27
|
async function build(root) {
|
|
28
28
|
const nuxt = await getNuxtApp(root);
|