firebase-tools 11.29.1 → 12.0.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/api.js +4 -2
- package/lib/commands/database-import.js +2 -2
- package/lib/commands/ext-configure.js +2 -1
- package/lib/commands/ext-dev-deprecate.js +24 -20
- package/lib/commands/ext-dev-list.js +12 -11
- package/lib/commands/ext-dev-publish.js +13 -47
- package/lib/commands/ext-dev-register.js +8 -5
- package/lib/commands/ext-dev-undeprecate.js +4 -4
- package/lib/commands/ext-dev-upload.js +88 -0
- package/lib/commands/ext-dev-usage.js +3 -3
- package/lib/commands/ext-install.js +5 -10
- package/lib/commands/ext-uninstall.js +0 -1
- package/lib/commands/ext-update.js +4 -10
- package/lib/commands/hosting-channel-deploy.js +3 -0
- package/lib/commands/index.js +9 -19
- package/lib/database/import.js +113 -18
- package/lib/deploy/extensions/planner.js +13 -7
- package/lib/deploy/extensions/prepare.js +16 -32
- 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 +64 -6
- 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/emulator/storage/rules/config.js +17 -7
- package/lib/experiments.js +22 -8
- package/lib/extensions/extensionsApi.js +24 -151
- package/lib/extensions/extensionsHelper.js +283 -146
- package/lib/extensions/manifest.js +1 -8
- package/lib/extensions/publisherApi.js +215 -0
- package/lib/extensions/refs.js +1 -1
- package/lib/extensions/resolveSource.js +1 -18
- package/lib/extensions/tos.js +78 -0
- package/lib/extensions/warnings.js +21 -41
- package/lib/frameworks/angular/index.js +74 -192
- package/lib/frameworks/angular/interfaces.js +2 -0
- package/lib/frameworks/angular/utils.js +274 -0
- package/lib/frameworks/astro/index.js +3 -4
- package/lib/frameworks/constants.js +45 -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 +104 -145
- package/lib/frameworks/interfaces.js +2 -0
- package/lib/frameworks/next/constants.js +2 -1
- package/lib/frameworks/next/index.js +197 -114
- package/lib/frameworks/next/utils.js +97 -15
- 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 +108 -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/api.js +32 -1
- 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/package.json +2 -3
- package/schema/firebase-config.json +1 -1
- package/templates/extensions/POSTINSTALL.md +2 -2
- package/templates/extensions/PREINSTALL.md +1 -1
- package/templates/extensions/extension.yaml +10 -6
- package/templates/extensions/javascript/WELCOME.md +1 -1
- package/templates/extensions/typescript/WELCOME.md +1 -1
- package/templates/extensions/typescript/index.ts +1 -1
- package/templates/init/functions/javascript/index.js +16 -6
- package/templates/init/functions/javascript/package.lint.json +4 -4
- package/templates/init/functions/javascript/package.nolint.json +4 -4
- package/templates/init/functions/python/requirements.txt +1 -1
- package/templates/init/functions/typescript/index.ts +16 -6
- package/templates/init/functions/typescript/package.lint.json +4 -4
- package/templates/init/functions/typescript/package.nolint.json +4 -4
- package/lib/commands/ext-dev-emulators-exec.js +0 -27
- package/lib/commands/ext-dev-emulators-start.js +0 -24
- package/lib/commands/ext-dev-extension-delete.js +0 -45
- package/lib/commands/ext-dev-unpublish.js +0 -49
- package/lib/commands/ext-sources-create.js +0 -24
- package/lib/extensions/askUserForConsent.js +0 -33
- package/npm-shrinkwrap.json +0 -12649
|
@@ -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,28 @@ 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 utils_1 = require("
|
|
21
|
-
const utils_2 = require("
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
20
|
+
const utils_1 = require("../utils");
|
|
21
|
+
const utils_2 = require("./utils");
|
|
22
|
+
const constants_1 = require("../constants");
|
|
23
|
+
const constants_2 = require("./constants");
|
|
24
|
+
const api_1 = require("../../hosting/api");
|
|
25
25
|
const DEFAULT_BUILD_SCRIPT = ["next build"];
|
|
26
26
|
const PUBLIC_DIR = "public";
|
|
27
27
|
exports.name = "Next.js";
|
|
28
|
-
exports.support = "
|
|
28
|
+
exports.support = "preview";
|
|
29
29
|
exports.type = 2;
|
|
30
|
+
exports.docsUrl = "https://firebase.google.com/docs/hosting/frameworks/nextjs";
|
|
30
31
|
const DEFAULT_NUMBER_OF_REASONS_TO_LIST = 5;
|
|
31
32
|
function getNextVersion(cwd) {
|
|
32
33
|
var _a;
|
|
33
|
-
return (_a = (0,
|
|
34
|
+
return (_a = (0, utils_1.findDependency)("next", { cwd, depth: 0, omitDev: false })) === null || _a === void 0 ? void 0 : _a.version;
|
|
34
35
|
}
|
|
35
36
|
function getReactVersion(cwd) {
|
|
36
37
|
var _a;
|
|
37
|
-
return (_a = (0,
|
|
38
|
+
return (_a = (0, utils_1.findDependency)("react-dom", { cwd, omitDev: false })) === null || _a === void 0 ? void 0 : _a.version;
|
|
38
39
|
}
|
|
39
40
|
async function discover(dir) {
|
|
40
41
|
if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
|
|
@@ -46,8 +47,8 @@ async function discover(dir) {
|
|
|
46
47
|
exports.discover = discover;
|
|
47
48
|
async function build(dir) {
|
|
48
49
|
var _a, _b;
|
|
49
|
-
const { default: nextBuild } = (0,
|
|
50
|
-
await (0,
|
|
50
|
+
const { default: nextBuild } = (0, utils_1.relativeRequire)(dir, "next/dist/build");
|
|
51
|
+
await (0, utils_1.warnIfCustomBuildScript)(dir, exports.name, DEFAULT_BUILD_SCRIPT);
|
|
51
52
|
const reactVersion = getReactVersion(dir);
|
|
52
53
|
if (reactVersion && (0, semver_1.gte)(reactVersion, "18.0.0")) {
|
|
53
54
|
process.env.__NEXT_REACT_ROOT = "true";
|
|
@@ -56,92 +57,112 @@ async function build(dir) {
|
|
|
56
57
|
console.error(e.message);
|
|
57
58
|
throw e;
|
|
58
59
|
});
|
|
59
|
-
const reasonsForBackend =
|
|
60
|
-
const { distDir, trailingSlash } = await getConfig(dir);
|
|
61
|
-
if (await (0,
|
|
62
|
-
reasonsForBackend.
|
|
60
|
+
const reasonsForBackend = new Set();
|
|
61
|
+
const { distDir, trailingSlash, basePath } = await getConfig(dir);
|
|
62
|
+
if (await (0, utils_2.isUsingMiddleware)((0, path_1.join)(dir, distDir), false)) {
|
|
63
|
+
reasonsForBackend.add("middleware");
|
|
63
64
|
}
|
|
64
|
-
if (await (0,
|
|
65
|
-
reasonsForBackend.
|
|
65
|
+
if (await (0, utils_2.isUsingImageOptimization)((0, path_1.join)(dir, distDir))) {
|
|
66
|
+
reasonsForBackend.add(`Image Optimization`);
|
|
66
67
|
}
|
|
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));
|
|
68
|
+
const prerenderManifest = await (0, utils_1.readJSON)((0, path_1.join)(dir, distDir, constants_2.PRERENDER_MANIFEST));
|
|
71
69
|
const dynamicRoutesWithFallback = Object.entries(prerenderManifest.dynamicRoutes || {}).filter(([, it]) => it.fallback !== false);
|
|
72
70
|
if (dynamicRoutesWithFallback.length > 0) {
|
|
73
71
|
for (const [key] of dynamicRoutesWithFallback) {
|
|
74
|
-
reasonsForBackend.
|
|
72
|
+
reasonsForBackend.add(`use of fallback ${key}`);
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
const routesWithRevalidate = Object.entries(prerenderManifest.routes).filter(([, it]) => it.initialRevalidateSeconds);
|
|
78
76
|
if (routesWithRevalidate.length > 0) {
|
|
79
|
-
for (const [
|
|
80
|
-
reasonsForBackend.
|
|
77
|
+
for (const [, { srcRoute }] of routesWithRevalidate) {
|
|
78
|
+
reasonsForBackend.add(`use of revalidate ${srcRoute}`);
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
|
-
const pagesManifestJSON = await (0,
|
|
81
|
+
const pagesManifestJSON = await (0, utils_1.readJSON)((0, path_1.join)(dir, distDir, "server", constants_2.PAGES_MANIFEST));
|
|
84
82
|
const prerenderedRoutes = Object.keys(prerenderManifest.routes);
|
|
85
83
|
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
|
-
}
|
|
84
|
+
const unrenderedPages = (0, utils_2.getNonStaticRoutes)(pagesManifestJSON, prerenderedRoutes, dynamicRoutes);
|
|
85
|
+
for (const key of unrenderedPages) {
|
|
86
|
+
reasonsForBackend.add(`non-static route ${key}`);
|
|
93
87
|
}
|
|
94
|
-
const manifest = await (0,
|
|
95
|
-
const { headers: nextJsHeaders = [], redirects: nextJsRedirects = [], rewrites: nextJsRewrites = [], } = manifest;
|
|
96
|
-
const isEveryHeaderSupported = nextJsHeaders.every(
|
|
88
|
+
const manifest = await (0, utils_1.readJSON)((0, path_1.join)(dir, distDir, constants_2.ROUTES_MANIFEST));
|
|
89
|
+
const { headers: nextJsHeaders = [], redirects: nextJsRedirects = [], rewrites: nextJsRewrites = [], i18n: nextjsI18n, } = manifest;
|
|
90
|
+
const isEveryHeaderSupported = nextJsHeaders.map(utils_2.cleanI18n).every(utils_2.isHeaderSupportedByHosting);
|
|
97
91
|
if (!isEveryHeaderSupported) {
|
|
98
|
-
reasonsForBackend.
|
|
92
|
+
reasonsForBackend.add("advanced headers");
|
|
99
93
|
}
|
|
100
|
-
const headers = nextJsHeaders
|
|
101
|
-
|
|
94
|
+
const headers = nextJsHeaders
|
|
95
|
+
.map(utils_2.cleanI18n)
|
|
96
|
+
.filter(utils_2.isHeaderSupportedByHosting)
|
|
97
|
+
.map(({ source, headers }) => ({
|
|
98
|
+
source: (0, utils_2.cleanEscapedChars)(source),
|
|
102
99
|
headers,
|
|
103
100
|
}));
|
|
101
|
+
const [appPathsManifest, appPathRoutesManifest] = await Promise.all([
|
|
102
|
+
(0, utils_1.readJSON)((0, path_1.join)(dir, distDir, "server", constants_2.APP_PATHS_MANIFEST)).catch(() => undefined),
|
|
103
|
+
(0, utils_1.readJSON)((0, path_1.join)(dir, distDir, constants_2.APP_PATH_ROUTES_MANIFEST)).catch(() => undefined),
|
|
104
|
+
]);
|
|
105
|
+
if (appPathRoutesManifest) {
|
|
106
|
+
const headersFromMetaFiles = await (0, utils_2.getHeadersFromMetaFiles)(dir, distDir, basePath, appPathRoutesManifest);
|
|
107
|
+
headers.push(...headersFromMetaFiles);
|
|
108
|
+
if (appPathsManifest) {
|
|
109
|
+
const unrenderedServerComponents = (0, utils_2.getNonStaticServerComponents)(appPathsManifest, appPathRoutesManifest, prerenderedRoutes, dynamicRoutes);
|
|
110
|
+
for (const key of unrenderedServerComponents) {
|
|
111
|
+
reasonsForBackend.add(`non-static component ${key}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
104
115
|
const isEveryRedirectSupported = nextJsRedirects
|
|
105
116
|
.filter((it) => !it.internal)
|
|
106
|
-
.every(
|
|
117
|
+
.every(utils_2.isRedirectSupportedByHosting);
|
|
107
118
|
if (!isEveryRedirectSupported) {
|
|
108
|
-
reasonsForBackend.
|
|
119
|
+
reasonsForBackend.add("advanced redirects");
|
|
109
120
|
}
|
|
110
121
|
const redirects = nextJsRedirects
|
|
111
|
-
.
|
|
122
|
+
.map(utils_2.cleanI18n)
|
|
123
|
+
.filter(utils_2.isRedirectSupportedByHosting)
|
|
112
124
|
.map(({ source, destination, statusCode: type }) => ({
|
|
113
|
-
source: (0,
|
|
125
|
+
source: (0, utils_2.cleanEscapedChars)(source),
|
|
114
126
|
destination,
|
|
115
127
|
type,
|
|
116
128
|
}));
|
|
117
|
-
const nextJsRewritesToUse = (0,
|
|
129
|
+
const nextJsRewritesToUse = (0, utils_2.getNextjsRewritesToUse)(nextJsRewrites);
|
|
118
130
|
if (!Array.isArray(nextJsRewrites) &&
|
|
119
131
|
(((_a = nextJsRewrites.afterFiles) === null || _a === void 0 ? void 0 : _a.length) || ((_b = nextJsRewrites.fallback) === null || _b === void 0 ? void 0 : _b.length))) {
|
|
120
|
-
reasonsForBackend.
|
|
132
|
+
reasonsForBackend.add("advanced rewrites");
|
|
121
133
|
}
|
|
122
|
-
const isEveryRewriteSupported = nextJsRewritesToUse.every(
|
|
134
|
+
const isEveryRewriteSupported = nextJsRewritesToUse.every(utils_2.isRewriteSupportedByHosting);
|
|
123
135
|
if (!isEveryRewriteSupported) {
|
|
124
|
-
reasonsForBackend.
|
|
136
|
+
reasonsForBackend.add("advanced rewrites");
|
|
125
137
|
}
|
|
126
138
|
const rewrites = nextJsRewritesToUse
|
|
127
|
-
.filter(
|
|
139
|
+
.filter(utils_2.isRewriteSupportedByHosting)
|
|
140
|
+
.map(utils_2.cleanI18n)
|
|
128
141
|
.map(({ source, destination }) => ({
|
|
129
|
-
source: (0,
|
|
142
|
+
source: (0, utils_2.cleanEscapedChars)(source),
|
|
130
143
|
destination,
|
|
131
144
|
}));
|
|
132
|
-
const wantsBackend = reasonsForBackend.
|
|
145
|
+
const wantsBackend = reasonsForBackend.size > 0;
|
|
133
146
|
if (wantsBackend) {
|
|
134
147
|
const numberOfReasonsToList = process.env.DEBUG ? Infinity : DEFAULT_NUMBER_OF_REASONS_TO_LIST;
|
|
135
148
|
console.log("Building a Cloud Function to run this application. This is needed due to:");
|
|
136
|
-
for (const reason of reasonsForBackend.slice(0, numberOfReasonsToList)) {
|
|
149
|
+
for (const reason of Array.from(reasonsForBackend).slice(0, numberOfReasonsToList)) {
|
|
137
150
|
console.log(` • ${reason}`);
|
|
138
151
|
}
|
|
139
|
-
if (reasonsForBackend.
|
|
140
|
-
console.log(` • and ${reasonsForBackend.
|
|
152
|
+
if (reasonsForBackend.size > numberOfReasonsToList) {
|
|
153
|
+
console.log(` • and ${reasonsForBackend.size - numberOfReasonsToList} other reasons, use --debug to see more`);
|
|
141
154
|
}
|
|
142
155
|
console.log("");
|
|
143
156
|
}
|
|
144
|
-
|
|
157
|
+
const i18n = !!nextjsI18n;
|
|
158
|
+
return {
|
|
159
|
+
wantsBackend,
|
|
160
|
+
headers,
|
|
161
|
+
redirects,
|
|
162
|
+
rewrites,
|
|
163
|
+
trailingSlash,
|
|
164
|
+
i18n,
|
|
165
|
+
};
|
|
145
166
|
}
|
|
146
167
|
exports.build = build;
|
|
147
168
|
async function init(setup, config) {
|
|
@@ -154,43 +175,41 @@ async function init(setup, config) {
|
|
|
154
175
|
(0, child_process_1.execSync)(`npx --yes create-next-app@latest -e hello-world ${setup.hosting.source} --use-npm ${language === "TypeScript" ? "--ts" : "--js"}`, { stdio: "inherit", cwd: config.projectDir });
|
|
155
176
|
}
|
|
156
177
|
exports.init = init;
|
|
157
|
-
async function ɵcodegenPublicDirectory(sourceDir, destDir) {
|
|
158
|
-
const { distDir } = await getConfig(sourceDir);
|
|
178
|
+
async function ɵcodegenPublicDirectory(sourceDir, destDir, context) {
|
|
179
|
+
const { distDir, i18n, basePath } = await getConfig(sourceDir);
|
|
180
|
+
let matchingI18nDomain = undefined;
|
|
181
|
+
if (i18n === null || i18n === void 0 ? void 0 : i18n.domains) {
|
|
182
|
+
const siteDomains = await (0, api_1.getAllSiteDomains)(context.project, context.site);
|
|
183
|
+
matchingI18nDomain = i18n.domains.find(({ domain }) => siteDomains.includes(domain));
|
|
184
|
+
}
|
|
185
|
+
const singleLocaleDomain = !i18n || ((matchingI18nDomain || i18n).locales || []).length <= 1;
|
|
159
186
|
const publicPath = (0, path_1.join)(sourceDir, "public");
|
|
160
|
-
await (0, promises_1.mkdir)((0, path_1.join)(destDir, "_next", "static"), { recursive: true });
|
|
187
|
+
await (0, promises_1.mkdir)((0, path_1.join)(destDir, basePath, "_next", "static"), { recursive: true });
|
|
161
188
|
if (await (0, fs_extra_1.pathExists)(publicPath)) {
|
|
162
|
-
await (0, fs_extra_1.copy)(publicPath, destDir);
|
|
163
|
-
}
|
|
164
|
-
await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, distDir, "static"), (0, path_1.join)(destDir, "_next", "static"));
|
|
165
|
-
for (const file of ["index.html", "404.html", "500.html"]) {
|
|
166
|
-
const pagesPath = (0, path_1.join)(sourceDir, distDir, "server", "pages", file);
|
|
167
|
-
if (await (0, fs_extra_1.pathExists)(pagesPath)) {
|
|
168
|
-
await (0, promises_1.copyFile)(pagesPath, (0, path_1.join)(destDir, file));
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
const appPath = (0, path_1.join)(sourceDir, distDir, "server", "app", file);
|
|
172
|
-
if (await (0, fs_extra_1.pathExists)(appPath)) {
|
|
173
|
-
await (0, promises_1.copyFile)(appPath, (0, path_1.join)(destDir, file));
|
|
174
|
-
}
|
|
189
|
+
await (0, fs_extra_1.copy)(publicPath, (0, path_1.join)(destDir, basePath));
|
|
175
190
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
(0,
|
|
179
|
-
(0,
|
|
191
|
+
await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, distDir, "static"), (0, path_1.join)(destDir, basePath, "_next", "static"));
|
|
192
|
+
const [middlewareManifest, prerenderManifest, routesManifest, pagesManifest, appPathRoutesManifest,] = await Promise.all([
|
|
193
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, "server", constants_2.MIDDLEWARE_MANIFEST)),
|
|
194
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, constants_2.PRERENDER_MANIFEST)),
|
|
195
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, constants_2.ROUTES_MANIFEST)),
|
|
196
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, "server", constants_2.PAGES_MANIFEST)),
|
|
197
|
+
(0, utils_1.readJSON)((0, path_1.join)(sourceDir, distDir, constants_2.APP_PATH_ROUTES_MANIFEST)).catch(() => ({})),
|
|
180
198
|
]);
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
.flat()
|
|
184
|
-
.map((it) => new RegExp(it.regexp));
|
|
199
|
+
const appPathRoutesEntries = Object.entries(appPathRoutesManifest);
|
|
200
|
+
const middlewareMatcherRegexes = (0, utils_2.getMiddlewareMatcherRegexes)(middlewareManifest);
|
|
185
201
|
const { redirects = [], rewrites = [], headers = [] } = routesManifest;
|
|
186
|
-
const rewritesRegexesNotSupportedByHosting = (0,
|
|
187
|
-
.filter((rewrite) => !(0,
|
|
202
|
+
const rewritesRegexesNotSupportedByHosting = (0, utils_2.getNextjsRewritesToUse)(rewrites)
|
|
203
|
+
.filter((rewrite) => !(0, utils_2.isRewriteSupportedByHosting)(rewrite))
|
|
204
|
+
.map(utils_2.cleanI18n)
|
|
188
205
|
.map((rewrite) => new RegExp(rewrite.regex));
|
|
189
206
|
const redirectsRegexesNotSupportedByHosting = redirects
|
|
190
|
-
.filter((
|
|
207
|
+
.filter((it) => !it.internal)
|
|
208
|
+
.filter((redirect) => !(0, utils_2.isRedirectSupportedByHosting)(redirect))
|
|
209
|
+
.map(utils_2.cleanI18n)
|
|
191
210
|
.map((redirect) => new RegExp(redirect.regex));
|
|
192
211
|
const headersRegexesNotSupportedByHosting = headers
|
|
193
|
-
.filter((header) => !(0,
|
|
212
|
+
.filter((header) => !(0, utils_2.isHeaderSupportedByHosting)(header))
|
|
194
213
|
.map((header) => new RegExp(header.regex));
|
|
195
214
|
const pathsUsingsFeaturesNotSupportedByHosting = [
|
|
196
215
|
...middlewareMatcherRegexes,
|
|
@@ -198,41 +217,100 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir) {
|
|
|
198
217
|
...redirectsRegexesNotSupportedByHosting,
|
|
199
218
|
...headersRegexesNotSupportedByHosting,
|
|
200
219
|
];
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
220
|
+
const pagesManifestLikePrerender = Object.fromEntries(Object.entries(pagesManifest)
|
|
221
|
+
.filter(([, srcRoute]) => srcRoute.endsWith(".html"))
|
|
222
|
+
.map(([path]) => {
|
|
223
|
+
return [path, { srcRoute: null, initialRevalidateSeconds: false, dataRoute: "" }];
|
|
224
|
+
}));
|
|
225
|
+
const routesToCopy = Object.assign(Object.assign({}, prerenderManifest.routes), pagesManifestLikePrerender);
|
|
226
|
+
await Promise.all(Object.entries(routesToCopy).map(async ([path, route]) => {
|
|
227
|
+
var _a, _b;
|
|
228
|
+
if (route.initialRevalidateSeconds) {
|
|
229
|
+
if (process.env.DEBUG)
|
|
230
|
+
console.log(`skipping ${path} due to revalidate`);
|
|
231
|
+
return;
|
|
205
232
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const htmlPath = `${(0, path_1.join)(...partsOrIndex)}.html`;
|
|
211
|
-
await (0, promises_1.mkdir)((0, path_1.join)(destDir, (0, path_1.dirname)(htmlPath)), { recursive: true });
|
|
212
|
-
await (0, promises_1.copyFile)((0, path_1.join)(contentDist, htmlPath), (0, path_1.join)(destDir, htmlPath));
|
|
213
|
-
if (!isReactServerComponent) {
|
|
214
|
-
const dataPath = `${(0, path_1.join)(...partsOrIndex)}.json`;
|
|
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));
|
|
233
|
+
if (pathsUsingsFeaturesNotSupportedByHosting.some((it) => path.match(it))) {
|
|
234
|
+
if (process.env.DEBUG)
|
|
235
|
+
console.log(`skipping ${path} due to it matching an unsupported rewrite/redirect/header or middlware`);
|
|
236
|
+
return;
|
|
217
237
|
}
|
|
218
|
-
|
|
238
|
+
const appPathRoute = route.srcRoute && ((_a = appPathRoutesEntries.find(([, it]) => it === route.srcRoute)) === null || _a === void 0 ? void 0 : _a[0]);
|
|
239
|
+
const contentDist = (0, path_1.join)(sourceDir, distDir, "server", appPathRoute ? "app" : "pages");
|
|
240
|
+
const sourceParts = path.split("/").filter((it) => !!it);
|
|
241
|
+
const locale = (i18n === null || i18n === void 0 ? void 0 : i18n.locales.includes(sourceParts[0])) ? sourceParts[0] : undefined;
|
|
242
|
+
const includeOnThisDomain = !locale ||
|
|
243
|
+
!matchingI18nDomain ||
|
|
244
|
+
matchingI18nDomain.defaultLocale === locale ||
|
|
245
|
+
!matchingI18nDomain.locales ||
|
|
246
|
+
matchingI18nDomain.locales.includes(locale);
|
|
247
|
+
if (!includeOnThisDomain) {
|
|
248
|
+
if (process.env.DEBUG)
|
|
249
|
+
console.log(`skipping ${path} since it is for a locale not deployed on this domain`);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const sourcePartsOrIndex = sourceParts.length > 0 ? sourceParts : ["index"];
|
|
253
|
+
const destParts = sourceParts.slice(locale ? 1 : 0);
|
|
254
|
+
const destPartsOrIndex = destParts.length > 0 ? destParts : ["index"];
|
|
255
|
+
const isDefaultLocale = !locale || ((_b = (matchingI18nDomain || i18n)) === null || _b === void 0 ? void 0 : _b.defaultLocale) === locale;
|
|
256
|
+
let sourcePath = (0, path_1.join)(contentDist, ...sourcePartsOrIndex);
|
|
257
|
+
let localizedDestPath = !singleLocaleDomain &&
|
|
258
|
+
locale &&
|
|
259
|
+
(0, path_1.join)(destDir, constants_1.I18N_ROOT, locale, basePath, ...destPartsOrIndex);
|
|
260
|
+
let defaultDestPath = isDefaultLocale && (0, path_1.join)(destDir, basePath, ...destPartsOrIndex);
|
|
261
|
+
if (!(0, fsutils_1.fileExistsSync)(sourcePath) && (0, fsutils_1.fileExistsSync)(`${sourcePath}.html`)) {
|
|
262
|
+
sourcePath += ".html";
|
|
263
|
+
if (localizedDestPath)
|
|
264
|
+
localizedDestPath += ".html";
|
|
265
|
+
if (defaultDestPath)
|
|
266
|
+
defaultDestPath += ".html";
|
|
267
|
+
}
|
|
268
|
+
else if (appPathRoute &&
|
|
269
|
+
(0, path_1.basename)(appPathRoute) === "route" &&
|
|
270
|
+
(0, fsutils_1.fileExistsSync)(`${sourcePath}.body`)) {
|
|
271
|
+
sourcePath += ".body";
|
|
272
|
+
}
|
|
273
|
+
else if (!(0, fs_extra_1.pathExistsSync)(sourcePath)) {
|
|
274
|
+
console.error(`Cannot find ${path} in your compiled Next.js application.`);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (localizedDestPath) {
|
|
278
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(localizedDestPath), { recursive: true });
|
|
279
|
+
await (0, promises_1.copyFile)(sourcePath, localizedDestPath);
|
|
280
|
+
}
|
|
281
|
+
if (defaultDestPath) {
|
|
282
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(defaultDestPath), { recursive: true });
|
|
283
|
+
await (0, promises_1.copyFile)(sourcePath, defaultDestPath);
|
|
284
|
+
}
|
|
285
|
+
if (route.dataRoute && !appPathRoute) {
|
|
286
|
+
const dataSourcePath = `${(0, path_1.join)(...sourcePartsOrIndex)}.json`;
|
|
287
|
+
const dataDestPath = (0, path_1.join)(destDir, basePath, route.dataRoute);
|
|
288
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(dataDestPath), { recursive: true });
|
|
289
|
+
await (0, promises_1.copyFile)((0, path_1.join)(contentDist, dataSourcePath), dataDestPath);
|
|
290
|
+
}
|
|
291
|
+
}));
|
|
219
292
|
}
|
|
220
293
|
exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
|
|
294
|
+
const BUNDLE_NEXT_CONFIG_TIMEOUT = 10000;
|
|
221
295
|
async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
222
|
-
const { distDir } = await getConfig(sourceDir);
|
|
223
|
-
const packageJson = await (0,
|
|
296
|
+
const { distDir, basePath } = await getConfig(sourceDir);
|
|
297
|
+
const packageJson = await (0, utils_1.readJSON)((0, path_1.join)(sourceDir, "package.json"));
|
|
224
298
|
if ((0, fs_1.existsSync)((0, path_1.join)(sourceDir, "next.config.js"))) {
|
|
225
299
|
try {
|
|
226
300
|
const productionDeps = await new Promise((resolve) => {
|
|
227
301
|
const dependencies = [];
|
|
302
|
+
const npmLs = (0, cross_spawn_1.spawn)("npm", ["ls", "--omit=dev", "--all", "--json=true"], {
|
|
303
|
+
cwd: sourceDir,
|
|
304
|
+
timeout: constants_1.NPM_COMMAND_TIMEOUT_MILLIES,
|
|
305
|
+
});
|
|
228
306
|
const pipeline = (0, stream_chain_1.chain)([
|
|
229
|
-
|
|
307
|
+
npmLs.stdout,
|
|
230
308
|
(0, stream_json_1.parser)({ packValues: false, packKeys: true, streamValues: false }),
|
|
231
309
|
(0, Pick_1.pick)({ filter: "dependencies" }),
|
|
232
310
|
(0, StreamObject_1.streamObject)(),
|
|
233
311
|
({ key, value }) => [
|
|
234
312
|
key,
|
|
235
|
-
...(0,
|
|
313
|
+
...(0, utils_2.allDependencyNames)(value),
|
|
236
314
|
],
|
|
237
315
|
]);
|
|
238
316
|
pipeline.on("data", (it) => dependencies.push(it));
|
|
@@ -242,9 +320,10 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
242
320
|
});
|
|
243
321
|
const esbuildArgs = productionDeps
|
|
244
322
|
.map((it) => `--external:${it}`)
|
|
245
|
-
.concat("--bundle", "--platform=node", `--target=node${
|
|
323
|
+
.concat("--bundle", "--platform=node", `--target=node${constants_1.NODE_VERSION}`, `--outdir=${destDir}`, "--log-level=error");
|
|
246
324
|
const bundle = (0, cross_spawn_1.sync)("npx", ["--yes", "esbuild", "next.config.js", ...esbuildArgs], {
|
|
247
325
|
cwd: sourceDir,
|
|
326
|
+
timeout: BUNDLE_NEXT_CONFIG_TIMEOUT,
|
|
248
327
|
});
|
|
249
328
|
if (bundle.status) {
|
|
250
329
|
throw new error_1.FirebaseError(bundle.stderr.toString());
|
|
@@ -252,7 +331,7 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
252
331
|
}
|
|
253
332
|
catch (e) {
|
|
254
333
|
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);
|
|
334
|
+
console.error(e.message || e);
|
|
256
335
|
(0, fs_extra_1.copy)((0, path_1.join)(sourceDir, "next.config.js"), (0, path_1.join)(destDir, "next.config.js"));
|
|
257
336
|
}
|
|
258
337
|
}
|
|
@@ -260,22 +339,24 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
260
339
|
await (0, promises_1.mkdir)((0, path_1.join)(destDir, "public"));
|
|
261
340
|
await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, "public"), (0, path_1.join)(destDir, "public"));
|
|
262
341
|
}
|
|
263
|
-
if (!(await (0,
|
|
264
|
-
((0,
|
|
265
|
-
packageJson.dependencies["sharp"] =
|
|
342
|
+
if (!(await (0, utils_2.hasUnoptimizedImage)(sourceDir, distDir)) &&
|
|
343
|
+
((0, utils_2.usesAppDirRouter)(sourceDir) || (await (0, utils_2.usesNextImage)(sourceDir, distDir)))) {
|
|
344
|
+
packageJson.dependencies["sharp"] = constants_1.SHARP_VERSION;
|
|
266
345
|
}
|
|
267
346
|
await (0, fs_extra_1.mkdirp)((0, path_1.join)(destDir, distDir));
|
|
268
347
|
await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, distDir), (0, path_1.join)(destDir, distDir));
|
|
269
|
-
return { packageJson, frameworksEntry: "next.js" };
|
|
348
|
+
return { packageJson, frameworksEntry: "next.js", basePath };
|
|
270
349
|
}
|
|
271
350
|
exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
|
|
272
351
|
async function getDevModeHandle(dir, hostingEmulatorInfo) {
|
|
273
352
|
if (!hostingEmulatorInfo) {
|
|
274
|
-
if (await (0,
|
|
353
|
+
if (await (0, utils_2.isUsingMiddleware)(dir, true)) {
|
|
275
354
|
throw new error_1.FirebaseError(`${clc.bold("firebase serve")} does not support Next.js Middleware. Please use ${clc.bold("firebase emulators:start")} instead.`);
|
|
276
355
|
}
|
|
277
356
|
}
|
|
278
|
-
|
|
357
|
+
let next = (0, utils_1.relativeRequire)(dir, "next");
|
|
358
|
+
if ("default" in next)
|
|
359
|
+
next = next.default;
|
|
279
360
|
const nextApp = next({
|
|
280
361
|
dev: true,
|
|
281
362
|
dir,
|
|
@@ -284,7 +365,7 @@ async function getDevModeHandle(dir, hostingEmulatorInfo) {
|
|
|
284
365
|
});
|
|
285
366
|
const handler = nextApp.getRequestHandler();
|
|
286
367
|
await nextApp.prepare();
|
|
287
|
-
return (0,
|
|
368
|
+
return (0, utils_1.simpleProxy)(async (req, res) => {
|
|
288
369
|
const parsedUrl = (0, url_1.parse)(req.url, true);
|
|
289
370
|
await handler(req, res, parsedUrl);
|
|
290
371
|
});
|
|
@@ -292,14 +373,15 @@ async function getDevModeHandle(dir, hostingEmulatorInfo) {
|
|
|
292
373
|
exports.getDevModeHandle = getDevModeHandle;
|
|
293
374
|
async function getConfig(dir) {
|
|
294
375
|
var _a;
|
|
376
|
+
var _b;
|
|
295
377
|
let config = {};
|
|
296
378
|
if ((0, fs_1.existsSync)((0, path_1.join)(dir, "next.config.js"))) {
|
|
297
379
|
const version = getNextVersion(dir);
|
|
298
380
|
if (!version)
|
|
299
381
|
throw new Error("Unable to find the next dep, try NPM installing?");
|
|
300
382
|
if ((0, semver_1.gte)(version, "12.0.0")) {
|
|
301
|
-
const { default: loadConfig } = (0,
|
|
302
|
-
const { PHASE_PRODUCTION_BUILD } = (0,
|
|
383
|
+
const { default: loadConfig } = (0, utils_1.relativeRequire)(dir, "next/dist/server/config");
|
|
384
|
+
const { PHASE_PRODUCTION_BUILD } = (0, utils_1.relativeRequire)(dir, "next/constants");
|
|
303
385
|
config = await loadConfig(PHASE_PRODUCTION_BUILD, dir, null);
|
|
304
386
|
}
|
|
305
387
|
else {
|
|
@@ -311,5 +393,6 @@ async function getConfig(dir) {
|
|
|
311
393
|
}
|
|
312
394
|
}
|
|
313
395
|
}
|
|
314
|
-
|
|
396
|
+
(0, utils_1.validateLocales)((_b = config.i18n) === null || _b === void 0 ? void 0 : _b.locales);
|
|
397
|
+
return Object.assign({ distDir: ".next", trailingSlash: false, basePath: "/" }, config);
|
|
315
398
|
}
|
|
@@ -1,38 +1,56 @@
|
|
|
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.
|
|
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.cleanI18n = exports.cleanCustomRouteI18n = exports.cleanEscapedChars = exports.I18N_SOURCE = 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
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
exports.pathHasRegex = pathHasRegex;
|
|
10
|
+
const promises_1 = require("fs/promises");
|
|
11
|
+
exports.I18N_SOURCE = /\/:nextInternalLocale(\([^\)]+\))?/;
|
|
14
12
|
function cleanEscapedChars(path) {
|
|
15
13
|
return path.replace(/\\([(){}:+?*])/g, (a, b) => b);
|
|
16
14
|
}
|
|
17
15
|
exports.cleanEscapedChars = cleanEscapedChars;
|
|
16
|
+
function cleanCustomRouteI18n(path) {
|
|
17
|
+
return path.replace(exports.I18N_SOURCE, "");
|
|
18
|
+
}
|
|
19
|
+
exports.cleanCustomRouteI18n = cleanCustomRouteI18n;
|
|
20
|
+
function cleanI18n(it) {
|
|
21
|
+
const [, localesRegex] = it.source.match(exports.I18N_SOURCE) || [undefined, undefined];
|
|
22
|
+
const source = localesRegex ? cleanCustomRouteI18n(it.source) : it.source;
|
|
23
|
+
const destination = "destination" in it && localesRegex ? cleanCustomRouteI18n(it.destination) : it.destination;
|
|
24
|
+
const regex = "regex" in it && localesRegex ? it.regex.replace(`(?:/${localesRegex})`, "") : it.regex;
|
|
25
|
+
return Object.assign(Object.assign({}, it), { source,
|
|
26
|
+
destination,
|
|
27
|
+
regex });
|
|
28
|
+
}
|
|
29
|
+
exports.cleanI18n = cleanI18n;
|
|
18
30
|
function isRewriteSupportedByHosting(rewrite) {
|
|
19
|
-
return !("has" in rewrite ||
|
|
31
|
+
return !("has" in rewrite ||
|
|
32
|
+
"missing" in rewrite ||
|
|
33
|
+
(0, utils_1.isUrl)(rewrite.destination) ||
|
|
34
|
+
rewrite.destination.includes("?"));
|
|
20
35
|
}
|
|
21
36
|
exports.isRewriteSupportedByHosting = isRewriteSupportedByHosting;
|
|
22
37
|
function isRedirectSupportedByHosting(redirect) {
|
|
23
|
-
return !("has" in redirect ||
|
|
38
|
+
return !("has" in redirect ||
|
|
39
|
+
"missing" in redirect ||
|
|
40
|
+
"internal" in redirect ||
|
|
41
|
+
redirect.destination.includes("?"));
|
|
24
42
|
}
|
|
25
43
|
exports.isRedirectSupportedByHosting = isRedirectSupportedByHosting;
|
|
26
44
|
function isHeaderSupportedByHosting(header) {
|
|
27
|
-
return !("has" in header ||
|
|
45
|
+
return !("has" in header || "missing" in header);
|
|
28
46
|
}
|
|
29
47
|
exports.isHeaderSupportedByHosting = isHeaderSupportedByHosting;
|
|
30
48
|
function getNextjsRewritesToUse(nextJsRewrites) {
|
|
31
49
|
if (Array.isArray(nextJsRewrites)) {
|
|
32
|
-
return nextJsRewrites;
|
|
50
|
+
return nextJsRewrites.map(cleanI18n);
|
|
33
51
|
}
|
|
34
52
|
if (nextJsRewrites === null || nextJsRewrites === void 0 ? void 0 : nextJsRewrites.beforeFiles) {
|
|
35
|
-
return nextJsRewrites.beforeFiles;
|
|
53
|
+
return nextJsRewrites.beforeFiles.map(cleanI18n);
|
|
36
54
|
}
|
|
37
55
|
return [];
|
|
38
56
|
}
|
|
@@ -67,13 +85,15 @@ async function isUsingMiddleware(dir, isDevMode) {
|
|
|
67
85
|
}
|
|
68
86
|
exports.isUsingMiddleware = isUsingMiddleware;
|
|
69
87
|
async function isUsingImageOptimization(dir) {
|
|
70
|
-
|
|
88
|
+
let { isNextImageImported } = await (0, utils_1.readJSON)((0, path_1.join)(dir, constants_1.EXPORT_MARKER));
|
|
89
|
+
if (!isNextImageImported && isUsingAppDirectory(dir)) {
|
|
90
|
+
isNextImageImported = (await (0, promises_1.readFile)((0, path_1.join)(dir, "server", "client-reference-manifest.js")))
|
|
91
|
+
.toString()
|
|
92
|
+
.includes("node_modules/next/dist/client/image.js");
|
|
93
|
+
}
|
|
71
94
|
if (isNextImageImported) {
|
|
72
95
|
const imagesManifest = await (0, utils_1.readJSON)((0, path_1.join)(dir, constants_1.IMAGES_MANIFEST));
|
|
73
|
-
|
|
74
|
-
if (usingImageOptimization) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
96
|
+
return !imagesManifest.images.unoptimized;
|
|
77
97
|
}
|
|
78
98
|
return false;
|
|
79
99
|
}
|
|
@@ -90,3 +110,65 @@ function allDependencyNames(mod) {
|
|
|
90
110
|
return dependencyNames;
|
|
91
111
|
}
|
|
92
112
|
exports.allDependencyNames = allDependencyNames;
|
|
113
|
+
function getMiddlewareMatcherRegexes(middlewareManifest) {
|
|
114
|
+
const middlewareObjectValues = Object.values(middlewareManifest.middleware);
|
|
115
|
+
let middlewareMatchers;
|
|
116
|
+
if (middlewareManifest.version === 1) {
|
|
117
|
+
middlewareMatchers = middlewareObjectValues.map((page) => ({ regexp: page.regexp }));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
middlewareMatchers = middlewareObjectValues
|
|
121
|
+
.map((page) => page.matchers)
|
|
122
|
+
.flat();
|
|
123
|
+
}
|
|
124
|
+
return middlewareMatchers.map((matcher) => new RegExp(matcher.regexp));
|
|
125
|
+
}
|
|
126
|
+
exports.getMiddlewareMatcherRegexes = getMiddlewareMatcherRegexes;
|
|
127
|
+
function getNonStaticRoutes(pagesManifestJSON, prerenderedRoutes, dynamicRoutes) {
|
|
128
|
+
const nonStaticRoutes = Object.entries(pagesManifestJSON)
|
|
129
|
+
.filter(([it, src]) => !((0, path_1.extname)(src) !== ".js" ||
|
|
130
|
+
["/_app", "/_error", "/_document"].includes(it) ||
|
|
131
|
+
prerenderedRoutes.includes(it) ||
|
|
132
|
+
dynamicRoutes.includes(it)))
|
|
133
|
+
.map(([it]) => it);
|
|
134
|
+
return nonStaticRoutes;
|
|
135
|
+
}
|
|
136
|
+
exports.getNonStaticRoutes = getNonStaticRoutes;
|
|
137
|
+
function getNonStaticServerComponents(appPathsManifest, appPathRoutesManifest, prerenderedRoutes, dynamicRoutes) {
|
|
138
|
+
const nonStaticServerComponents = Object.entries(appPathsManifest)
|
|
139
|
+
.filter(([it, src]) => {
|
|
140
|
+
if ((0, path_1.extname)(src) !== ".js")
|
|
141
|
+
return;
|
|
142
|
+
const path = appPathRoutesManifest[it];
|
|
143
|
+
return !(prerenderedRoutes.includes(path) || dynamicRoutes.includes(path));
|
|
144
|
+
})
|
|
145
|
+
.map(([it]) => it);
|
|
146
|
+
return nonStaticServerComponents;
|
|
147
|
+
}
|
|
148
|
+
exports.getNonStaticServerComponents = getNonStaticServerComponents;
|
|
149
|
+
async function getHeadersFromMetaFiles(sourceDir, distDir, basePath, appPathRoutesManifest) {
|
|
150
|
+
const headers = [];
|
|
151
|
+
await Promise.all(Object.entries(appPathRoutesManifest).map(async ([key, source]) => {
|
|
152
|
+
if ((0, path_1.basename)(key) !== "route")
|
|
153
|
+
return;
|
|
154
|
+
const parts = source.split("/").filter((it) => !!it);
|
|
155
|
+
const partsOrIndex = parts.length > 0 ? parts : ["index"];
|
|
156
|
+
const routePath = (0, path_1.join)(sourceDir, distDir, "server", "app", ...partsOrIndex);
|
|
157
|
+
const metadataPath = `${routePath}.meta`;
|
|
158
|
+
if ((0, fsutils_1.dirExistsSync)(routePath) && (0, fsutils_1.fileExistsSync)(metadataPath)) {
|
|
159
|
+
const meta = await (0, utils_1.readJSON)(metadataPath);
|
|
160
|
+
if (meta.headers)
|
|
161
|
+
headers.push({
|
|
162
|
+
source: path_1.posix.join(basePath, source),
|
|
163
|
+
headers: Object.entries(meta.headers).map(([key, value]) => ({ key, value })),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}));
|
|
167
|
+
return headers;
|
|
168
|
+
}
|
|
169
|
+
exports.getHeadersFromMetaFiles = getHeadersFromMetaFiles;
|
|
170
|
+
async function getBuildId(distDir) {
|
|
171
|
+
const buildId = await (0, promises_1.readFile)((0, path_1.join)(distDir, "BUILD_ID"));
|
|
172
|
+
return buildId.toString();
|
|
173
|
+
}
|
|
174
|
+
exports.getBuildId = getBuildId;
|