firebase-tools 12.0.1 → 12.2.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/deploy/functions/functionsDeployHelper.js +8 -1
- package/lib/deploy/functions/release/fabricator.js +3 -1
- package/lib/deploy/functions/runtimes/index.js +2 -0
- package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +1 -0
- package/lib/deploy/functions/runtimes/python/index.js +1 -1
- package/lib/emulator/downloadableEmulators.js +3 -3
- package/lib/emulator/functionsEmulator.js +6 -1
- package/lib/frameworks/angular/index.js +47 -13
- package/lib/frameworks/angular/utils.js +124 -75
- package/lib/frameworks/astro/index.js +1 -1
- package/lib/frameworks/constants.js +10 -2
- package/lib/frameworks/express/index.js +4 -4
- package/lib/frameworks/flutter/constants.js +72 -0
- package/lib/frameworks/flutter/index.js +22 -3
- package/lib/frameworks/flutter/utils.js +2 -2
- package/lib/frameworks/frameworks.js +29 -0
- package/lib/frameworks/index.js +27 -24
- package/lib/frameworks/next/index.js +3 -3
- package/lib/frameworks/nuxt/index.js +33 -22
- package/lib/frameworks/nuxt2/index.js +55 -62
- package/lib/frameworks/utils.js +30 -2
- package/lib/frameworks/vite/index.js +1 -0
- package/lib/gcp/cloudfunctionsv2.js +26 -16
- package/package.json +1 -1
- package/schema/firebase-config.json +4 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ɵcodegenPublicDirectory = exports.build = exports.discover = exports.support = exports.type = exports.name = void 0;
|
|
3
|
+
exports.ɵcodegenPublicDirectory = exports.build = exports.init = exports.discover = exports.support = exports.type = exports.name = void 0;
|
|
4
4
|
const cross_spawn_1 = require("cross-spawn");
|
|
5
5
|
const fs_extra_1 = require("fs-extra");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -8,7 +8,8 @@ const js_yaml_1 = require("js-yaml");
|
|
|
8
8
|
const promises_1 = require("fs/promises");
|
|
9
9
|
const error_1 = require("../../error");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
|
-
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
exports.name = "Flutter Web";
|
|
12
13
|
exports.type = 3;
|
|
13
14
|
exports.support = "experimental";
|
|
14
15
|
async function discover(dir) {
|
|
@@ -25,10 +26,28 @@ async function discover(dir) {
|
|
|
25
26
|
return { mayWantBackend: false, publicDirectory: (0, path_1.join)(dir, "web") };
|
|
26
27
|
}
|
|
27
28
|
exports.discover = discover;
|
|
29
|
+
function init(setup, config) {
|
|
30
|
+
(0, utils_1.assertFlutterCliExists)();
|
|
31
|
+
const projectName = constants_1.DART_RESERVED_WORDS.includes(setup.projectId)
|
|
32
|
+
? constants_1.FALLBACK_PROJECT_NAME
|
|
33
|
+
: setup.projectId.replaceAll("-", "_");
|
|
34
|
+
const result = (0, cross_spawn_1.sync)("flutter", [
|
|
35
|
+
"create",
|
|
36
|
+
"--template=app",
|
|
37
|
+
`--project-name=${projectName}`,
|
|
38
|
+
"--overwrite",
|
|
39
|
+
"--platforms=web",
|
|
40
|
+
setup.hosting.source,
|
|
41
|
+
], { stdio: "inherit", cwd: config.projectDir });
|
|
42
|
+
if (result.status !== 0)
|
|
43
|
+
throw new error_1.FirebaseError("We were not able to create your flutter app, create the application yourself https://docs.flutter.dev/get-started/test-drive?tab=terminal before trying again.");
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
}
|
|
46
|
+
exports.init = init;
|
|
28
47
|
function build(cwd) {
|
|
29
48
|
(0, utils_1.assertFlutterCliExists)();
|
|
30
49
|
const build = (0, cross_spawn_1.sync)("flutter", ["build", "web"], { cwd, stdio: "inherit" });
|
|
31
|
-
if (build.status)
|
|
50
|
+
if (build.status !== 0)
|
|
32
51
|
throw new error_1.FirebaseError("Unable to build your Flutter app");
|
|
33
52
|
return Promise.resolve({ wantsBackend: false });
|
|
34
53
|
}
|
|
@@ -5,7 +5,7 @@ const cross_spawn_1 = require("cross-spawn");
|
|
|
5
5
|
const error_1 = require("../../error");
|
|
6
6
|
function assertFlutterCliExists() {
|
|
7
7
|
const process = (0, cross_spawn_1.sync)("flutter", ["--version"], { stdio: "ignore" });
|
|
8
|
-
if (process.status)
|
|
9
|
-
throw new error_1.FirebaseError("Flutter CLI not found.");
|
|
8
|
+
if (process.status !== 0)
|
|
9
|
+
throw new error_1.FirebaseError("Flutter CLI not found, follow the instructions here https://docs.flutter.dev/get-started/install before trying again.");
|
|
10
10
|
}
|
|
11
11
|
exports.assertFlutterCliExists = assertFlutterCliExists;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebFrameworks = void 0;
|
|
4
|
+
const angular = require("./angular");
|
|
5
|
+
const astro = require("./astro");
|
|
6
|
+
const express = require("./express");
|
|
7
|
+
const lit = require("./lit");
|
|
8
|
+
const next = require("./next");
|
|
9
|
+
const nuxt = require("./nuxt");
|
|
10
|
+
const nuxt2 = require("./nuxt2");
|
|
11
|
+
const preact = require("./preact");
|
|
12
|
+
const svelte = require("./svelte");
|
|
13
|
+
const svelekit = require("./sveltekit");
|
|
14
|
+
const react = require("./react");
|
|
15
|
+
const vite = require("./vite");
|
|
16
|
+
exports.WebFrameworks = {
|
|
17
|
+
angular,
|
|
18
|
+
astro,
|
|
19
|
+
express,
|
|
20
|
+
lit,
|
|
21
|
+
next,
|
|
22
|
+
nuxt,
|
|
23
|
+
nuxt2,
|
|
24
|
+
preact,
|
|
25
|
+
svelte,
|
|
26
|
+
svelekit,
|
|
27
|
+
react,
|
|
28
|
+
vite,
|
|
29
|
+
};
|
package/lib/frameworks/index.js
CHANGED
|
@@ -60,14 +60,14 @@ async function discover(dir, warn = true) {
|
|
|
60
60
|
}
|
|
61
61
|
exports.discover = discover;
|
|
62
62
|
const BUILD_MEMO = new Map();
|
|
63
|
-
function memoizeBuild(dir, build, deps) {
|
|
63
|
+
function memoizeBuild(dir, build, deps, target) {
|
|
64
64
|
const key = [dir, ...deps];
|
|
65
65
|
for (const existingKey of BUILD_MEMO.keys()) {
|
|
66
66
|
if ((0, util_1.isDeepStrictEqual)(existingKey, key)) {
|
|
67
67
|
return BUILD_MEMO.get(existingKey);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
const value = build(dir);
|
|
70
|
+
const value = build(dir, target);
|
|
71
71
|
BUILD_MEMO.set(key, value);
|
|
72
72
|
return value;
|
|
73
73
|
}
|
|
@@ -188,14 +188,17 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
|
|
|
188
188
|
throw new error_1.FirebaseError((0, utils_1.frameworksCallToAction)("Unable to detect the web framework in use, check firebase-debug.log for more info."));
|
|
189
189
|
}
|
|
190
190
|
const { framework, mayWantBackend, publicDirectory } = results;
|
|
191
|
-
const { build, ɵcodegenPublicDirectory, ɵcodegenFunctionsDirectory: codegenProdModeFunctionsDirectory, getDevModeHandle, name, support, docsUrl, } = constants_2.WebFrameworks[framework];
|
|
191
|
+
const { build, ɵcodegenPublicDirectory, ɵcodegenFunctionsDirectory: codegenProdModeFunctionsDirectory, getDevModeHandle, name, support, docsUrl, getValidBuildTargets = constants_2.GET_DEFAULT_BUILD_TARGETS, shouldUseDevModeHandle = constants_2.DEFAULT_SHOULD_USE_DEV_MODE_HANDLE, } = constants_2.WebFrameworks[framework];
|
|
192
192
|
console.log(`\n${(0, utils_1.frameworksCallToAction)(constants_2.SupportLevelWarnings[support](name), docsUrl, " ")}\n`);
|
|
193
|
-
const isDevMode = context._name === "serve" || context._name === "emulators:start";
|
|
194
193
|
const hostingEmulatorInfo = emulators.find((e) => e.name === types_1.Emulators.HOSTING);
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
const buildTargetPurpose = context._name === "deploy" ? "deploy" : context._name === "emulators:exec" ? "test" : "serve";
|
|
195
|
+
const validBuildTargets = await getValidBuildTargets(buildTargetPurpose, getProjectPath());
|
|
196
|
+
const frameworksBuildTarget = (0, utils_1.getFrameworksBuildTarget)(buildTargetPurpose, validBuildTargets);
|
|
197
|
+
const useDevModeHandle = await shouldUseDevModeHandle(frameworksBuildTarget, getProjectPath());
|
|
198
198
|
let codegenFunctionsDirectory;
|
|
199
|
+
const devModeHandle = useDevModeHandle &&
|
|
200
|
+
getDevModeHandle &&
|
|
201
|
+
(await getDevModeHandle(getProjectPath(), frameworksBuildTarget, hostingEmulatorInfo));
|
|
199
202
|
if (devModeHandle) {
|
|
200
203
|
config.public = (0, path_1.relative)(projectRoot, publicDirectory);
|
|
201
204
|
options.frameworksDevModeHandle = devModeHandle;
|
|
@@ -204,7 +207,8 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
|
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
209
|
else {
|
|
207
|
-
const
|
|
210
|
+
const buildResult = await memoizeBuild(getProjectPath(), build, [firebaseDefaults, frameworksBuildTarget], frameworksBuildTarget);
|
|
211
|
+
const { wantsBackend = false, rewrites = [], redirects = [], headers = [], trailingSlash, i18n = false, } = buildResult || {};
|
|
208
212
|
config.rewrites.push(...rewrites);
|
|
209
213
|
config.redirects.push(...redirects);
|
|
210
214
|
config.headers.push(...headers);
|
|
@@ -214,7 +218,7 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
|
|
|
214
218
|
if (await (0, fs_extra_1.pathExists)(hostingDist))
|
|
215
219
|
await (0, promises_1.rm)(hostingDist, { recursive: true });
|
|
216
220
|
await (0, fs_extra_1.mkdirp)(hostingDist);
|
|
217
|
-
await ɵcodegenPublicDirectory(getProjectPath(), hostingDist, {
|
|
221
|
+
await ɵcodegenPublicDirectory(getProjectPath(), hostingDist, frameworksBuildTarget, {
|
|
218
222
|
project,
|
|
219
223
|
site,
|
|
220
224
|
});
|
|
@@ -269,15 +273,18 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
|
|
|
269
273
|
else {
|
|
270
274
|
await (0, fs_extra_1.mkdirp)(functionsDist);
|
|
271
275
|
}
|
|
272
|
-
const { packageJson, bootstrapScript, frameworksEntry = framework, baseUrl = "", dotEnv = {}, } = await codegenFunctionsDirectory(getProjectPath(), functionsDist);
|
|
273
|
-
config.rewrites
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
276
|
+
const { packageJson, bootstrapScript, frameworksEntry = framework, baseUrl = "", dotEnv = {}, rewriteSource = path_1.posix.join(baseUrl, "**"), } = await codegenFunctionsDirectory(getProjectPath(), functionsDist, frameworksBuildTarget);
|
|
277
|
+
config.rewrites = [
|
|
278
|
+
{
|
|
279
|
+
source: rewriteSource,
|
|
280
|
+
function: {
|
|
281
|
+
functionId,
|
|
282
|
+
region: ssrRegion,
|
|
283
|
+
pinTag: experiments.isEnabled("pintags"),
|
|
284
|
+
},
|
|
279
285
|
},
|
|
280
|
-
|
|
286
|
+
...config.rewrites,
|
|
287
|
+
];
|
|
281
288
|
process.env.__FIREBASE_FRAMEWORKS_ENTRY__ = frameworksEntry;
|
|
282
289
|
packageJson.main = "server.js";
|
|
283
290
|
packageJson.dependencies || (packageJson.dependencies = {});
|
|
@@ -311,8 +318,8 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
|
|
|
311
318
|
const result = (0, cross_spawn_1.sync)("npm", ["pack", (0, path_1.relative)(functionsDist, path), "--json=true"], {
|
|
312
319
|
cwd: functionsDist,
|
|
313
320
|
});
|
|
314
|
-
if (result.status)
|
|
315
|
-
throw new
|
|
321
|
+
if (result.status !== 0)
|
|
322
|
+
throw new error_1.FirebaseError(`Error running \`npm pack\` at ${path}`);
|
|
316
323
|
const { filename } = JSON.parse(result.stdout.toString())[0];
|
|
317
324
|
packageJson.dependencies[name] = `file:${filename}`;
|
|
318
325
|
}
|
|
@@ -368,10 +375,6 @@ ${firebaseDefaults ? `__FIREBASE_DEFAULTS__=${JSON.stringify(firebaseDefaults)}\
|
|
|
368
375
|
if (await (0, fs_extra_1.pathExists)(functionsDist)) {
|
|
369
376
|
await (0, promises_1.rm)(functionsDist, { recursive: true });
|
|
370
377
|
}
|
|
371
|
-
config.rewrites.push({
|
|
372
|
-
source: "**",
|
|
373
|
-
destination: "/index.html",
|
|
374
|
-
});
|
|
375
378
|
}
|
|
376
379
|
if (firebaseDefaults) {
|
|
377
380
|
const encodedDefaults = Buffer.from(JSON.stringify(firebaseDefaults)).toString("base64url");
|
|
@@ -379,7 +382,7 @@ ${firebaseDefaults ? `__FIREBASE_DEFAULTS__=${JSON.stringify(firebaseDefaults)}\
|
|
|
379
382
|
const sameSite = "Strict";
|
|
380
383
|
const path = `/`;
|
|
381
384
|
config.headers.push({
|
|
382
|
-
source: "**/*.
|
|
385
|
+
source: "**/*.[jt]s",
|
|
383
386
|
headers: [
|
|
384
387
|
{
|
|
385
388
|
key: "Set-Cookie",
|
|
@@ -175,7 +175,7 @@ async function init(setup, config) {
|
|
|
175
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 });
|
|
176
176
|
}
|
|
177
177
|
exports.init = init;
|
|
178
|
-
async function ɵcodegenPublicDirectory(sourceDir, destDir, context) {
|
|
178
|
+
async function ɵcodegenPublicDirectory(sourceDir, destDir, _, context) {
|
|
179
179
|
const { distDir, i18n, basePath } = await getConfig(sourceDir);
|
|
180
180
|
let matchingI18nDomain = undefined;
|
|
181
181
|
if (i18n === null || i18n === void 0 ? void 0 : i18n.domains) {
|
|
@@ -325,7 +325,7 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
325
325
|
cwd: sourceDir,
|
|
326
326
|
timeout: BUNDLE_NEXT_CONFIG_TIMEOUT,
|
|
327
327
|
});
|
|
328
|
-
if (bundle.status) {
|
|
328
|
+
if (bundle.status !== 0) {
|
|
329
329
|
throw new error_1.FirebaseError(bundle.stderr.toString());
|
|
330
330
|
}
|
|
331
331
|
}
|
|
@@ -348,7 +348,7 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
|
|
|
348
348
|
return { packageJson, frameworksEntry: "next.js", basePath };
|
|
349
349
|
}
|
|
350
350
|
exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
|
|
351
|
-
async function getDevModeHandle(dir, hostingEmulatorInfo) {
|
|
351
|
+
async function getDevModeHandle(dir, _, hostingEmulatorInfo) {
|
|
352
352
|
if (!hostingEmulatorInfo) {
|
|
353
353
|
if (await (0, utils_2.isUsingMiddleware)(dir, true)) {
|
|
354
354
|
throw new error_1.FirebaseError(`${clc.bold("firebase serve")} does not support Next.js Middleware. Please use ${clc.bold("firebase emulators:start")} instead.`);
|
|
@@ -12,6 +12,7 @@ exports.name = "Nuxt";
|
|
|
12
12
|
exports.support = "experimental";
|
|
13
13
|
exports.type = 4;
|
|
14
14
|
const utils_3 = require("./utils");
|
|
15
|
+
const error_1 = require("../../error");
|
|
15
16
|
const DEFAULT_BUILD_SCRIPT = ["nuxt build", "nuxi build"];
|
|
16
17
|
async function discover(dir) {
|
|
17
18
|
if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
|
|
@@ -22,39 +23,49 @@ async function discover(dir) {
|
|
|
22
23
|
return;
|
|
23
24
|
if (nuxtVersion && (0, semver_1.lt)(nuxtVersion, "3.0.0-0"))
|
|
24
25
|
return;
|
|
25
|
-
const { dir: { public: publicDirectory }, } = await getConfig(dir);
|
|
26
|
-
return { publicDirectory, mayWantBackend
|
|
26
|
+
const { dir: { public: publicDirectory }, ssr: mayWantBackend, } = await getConfig(dir);
|
|
27
|
+
return { publicDirectory, mayWantBackend };
|
|
27
28
|
}
|
|
28
29
|
exports.discover = discover;
|
|
29
|
-
async function build(
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
exports.build = build;
|
|
37
|
-
async function getNuxt3App(cwd) {
|
|
38
|
-
const { loadNuxt } = await (0, utils_1.relativeRequire)(cwd, "@nuxt/kit");
|
|
39
|
-
return await loadNuxt({
|
|
30
|
+
async function build(cwd) {
|
|
31
|
+
await (0, utils_1.warnIfCustomBuildScript)(cwd, exports.name, DEFAULT_BUILD_SCRIPT);
|
|
32
|
+
const cli = (0, utils_1.getNodeModuleBin)("nuxt", cwd);
|
|
33
|
+
const { ssr: wantsBackend, app: { baseURL }, } = await getConfig(cwd);
|
|
34
|
+
const command = wantsBackend ? ["build"] : ["generate"];
|
|
35
|
+
const build = (0, cross_spawn_1.sync)(cli, command, {
|
|
40
36
|
cwd,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
37
|
+
stdio: "inherit",
|
|
38
|
+
env: Object.assign(Object.assign({}, process.env), { NITRO_PRESET: "node" }),
|
|
44
39
|
});
|
|
40
|
+
if (build.status !== 0)
|
|
41
|
+
throw new error_1.FirebaseError("Was unable to build your Nuxt application.");
|
|
42
|
+
const rewrites = wantsBackend
|
|
43
|
+
? []
|
|
44
|
+
: [
|
|
45
|
+
{
|
|
46
|
+
source: path_1.posix.join(baseURL, "**"),
|
|
47
|
+
destination: path_1.posix.join(baseURL, "200.html"),
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
return { wantsBackend, rewrites };
|
|
45
51
|
}
|
|
52
|
+
exports.build = build;
|
|
46
53
|
async function ɵcodegenPublicDirectory(root, dest) {
|
|
54
|
+
const { app: { baseURL }, } = await getConfig(root);
|
|
47
55
|
const distPath = (0, path_1.join)(root, ".output", "public");
|
|
48
|
-
|
|
56
|
+
const fullDest = (0, path_1.join)(dest, baseURL);
|
|
57
|
+
await (0, fs_extra_1.mkdirp)(fullDest);
|
|
58
|
+
await (0, fs_extra_1.copy)(distPath, fullDest);
|
|
49
59
|
}
|
|
50
60
|
exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
|
|
51
|
-
async function ɵcodegenFunctionsDirectory(sourceDir
|
|
61
|
+
async function ɵcodegenFunctionsDirectory(sourceDir) {
|
|
62
|
+
const serverDir = (0, path_1.join)(sourceDir, ".output", "server");
|
|
52
63
|
const packageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, "package.json"));
|
|
53
64
|
const packageJson = JSON.parse(packageJsonBuffer.toString());
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return { packageJson
|
|
65
|
+
packageJson.dependencies || (packageJson.dependencies = {});
|
|
66
|
+
packageJson.dependencies["nitro-output"] = `file:${serverDir}`;
|
|
67
|
+
const { app: { baseURL: baseUrl }, } = await getConfig(sourceDir);
|
|
68
|
+
return { packageJson, frameworksEntry: "nitro", baseUrl };
|
|
58
69
|
}
|
|
59
70
|
exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
|
|
60
71
|
async function getDevModeHandle(cwd) {
|
|
@@ -1,85 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.build = exports.discover = exports.type = exports.support = exports.name = void 0;
|
|
3
|
+
exports.getDevModeHandle = exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.build = exports.discover = exports.type = exports.support = exports.name = void 0;
|
|
4
4
|
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
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const utils_2 = require("../nuxt/utils");
|
|
10
|
+
const utils_3 = require("../utils");
|
|
11
|
+
const cross_spawn_1 = require("cross-spawn");
|
|
10
12
|
exports.name = "Nuxt";
|
|
11
13
|
exports.support = "experimental";
|
|
12
14
|
exports.type = 2;
|
|
13
|
-
async function
|
|
14
|
-
|
|
15
|
+
async function getAndLoadNuxt(options) {
|
|
16
|
+
const nuxt = await (0, utils_1.relativeRequire)(options.rootDir, "nuxt/dist/nuxt.js");
|
|
17
|
+
const app = await nuxt.loadNuxt(options);
|
|
18
|
+
await app.ready();
|
|
19
|
+
return { app, nuxt };
|
|
20
|
+
}
|
|
21
|
+
async function discover(rootDir) {
|
|
22
|
+
if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(rootDir, "package.json"))))
|
|
15
23
|
return;
|
|
16
|
-
const nuxtVersion = (0, utils_2.getNuxtVersion)(
|
|
17
|
-
|
|
18
|
-
if (!anyConfigFileExists && !nuxtVersion)
|
|
24
|
+
const nuxtVersion = (0, utils_2.getNuxtVersion)(rootDir);
|
|
25
|
+
if (!nuxtVersion || (nuxtVersion && (0, semver_1.gte)(nuxtVersion, "3.0.0-0")))
|
|
19
26
|
return;
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
const { app } = await getAndLoadNuxt({ rootDir, for: "build" });
|
|
28
|
+
return { mayWantBackend: true, publicDirectory: app.options.dir.static };
|
|
22
29
|
}
|
|
23
30
|
exports.discover = discover;
|
|
24
|
-
async function
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const { options: { ssr, target }, } = await nuxt.build(nuxtApp);
|
|
34
|
-
if (ssr === true && target === "server") {
|
|
35
|
-
return { wantsBackend: true };
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
if (ssr === false && target === "static") {
|
|
39
|
-
console.log("Firebase: Nuxt 2: Static target is not supported with `ssr: false`. Please use `target: 'server'` in your `nuxt.config.js` file.");
|
|
40
|
-
console.log("Firebase: Nuxt 2: Bundling only for client side.\n");
|
|
41
|
-
}
|
|
42
|
-
await buildAndGenerate(nuxt, root);
|
|
43
|
-
return { wantsBackend: false };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.build = build;
|
|
47
|
-
async function buildAndGenerate(nuxt, root) {
|
|
48
|
-
const nuxtApp = await nuxt.loadNuxt({
|
|
49
|
-
for: "start",
|
|
50
|
-
rootDir: root,
|
|
51
|
-
});
|
|
52
|
-
const builder = await nuxt.getBuilder(nuxtApp);
|
|
53
|
-
const generator = new nuxt.Generator(nuxtApp, builder);
|
|
31
|
+
async function build(rootDir) {
|
|
32
|
+
const { app, nuxt } = await getAndLoadNuxt({ rootDir, for: "build" });
|
|
33
|
+
const { options: { ssr, target }, } = app;
|
|
34
|
+
const cwd = process.cwd();
|
|
35
|
+
process.chdir(rootDir);
|
|
36
|
+
await nuxt.build(app);
|
|
37
|
+
const { app: generateApp } = await getAndLoadNuxt({ rootDir, for: "start" });
|
|
38
|
+
const builder = await nuxt.getBuilder(generateApp);
|
|
39
|
+
const generator = new nuxt.Generator(generateApp, builder);
|
|
54
40
|
await generator.generate({ build: false, init: true });
|
|
41
|
+
process.chdir(cwd);
|
|
42
|
+
const wantsBackend = ssr && target === "server";
|
|
43
|
+
const rewrites = wantsBackend ? [] : [{ source: "**", destination: "/200.html" }];
|
|
44
|
+
return { wantsBackend, rewrites };
|
|
55
45
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const { ssr, target } = nuxtConfig;
|
|
61
|
-
if (!(ssr === true && target === "server")) {
|
|
62
|
-
const source = ((_a = nuxtConfig === null || nuxtConfig === void 0 ? void 0 : nuxtConfig.generate) === null || _a === void 0 ? void 0 : _a.dir) !== undefined
|
|
63
|
-
? (0, path_1.join)(root, (_b = nuxtConfig === null || nuxtConfig === void 0 ? void 0 : nuxtConfig.generate) === null || _b === void 0 ? void 0 : _b.dir)
|
|
64
|
-
: (0, path_1.join)(root, "dist");
|
|
65
|
-
await (0, fs_extra_1.copy)(source, dest);
|
|
66
|
-
}
|
|
67
|
-
const staticPath = (0, path_1.join)(root, "static");
|
|
68
|
-
if (await (0, fs_extra_1.pathExists)(staticPath)) {
|
|
69
|
-
await (0, fs_extra_1.copy)(staticPath, dest);
|
|
70
|
-
}
|
|
46
|
+
exports.build = build;
|
|
47
|
+
async function ɵcodegenPublicDirectory(rootDir, dest) {
|
|
48
|
+
const { app: { options }, } = await getAndLoadNuxt({ rootDir, for: "build" });
|
|
49
|
+
await (0, fs_extra_1.copy)(options.generate.dir, dest);
|
|
71
50
|
}
|
|
72
51
|
exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
|
|
73
|
-
async function ɵcodegenFunctionsDirectory(
|
|
74
|
-
const packageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(
|
|
52
|
+
async function ɵcodegenFunctionsDirectory(rootDir, destDir) {
|
|
53
|
+
const packageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(rootDir, "package.json"));
|
|
75
54
|
const packageJson = JSON.parse(packageJsonBuffer.toString());
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
await (0, fs_extra_1.copy)((0, path_1.join)(
|
|
79
|
-
|
|
80
|
-
const nuxtConfigFile = nuxtConfig._nuxtConfigFile.split("/").pop();
|
|
81
|
-
await (0, fs_extra_1.copy)(nuxtConfig._nuxtConfigFile, (0, path_1.join)(destDir, nuxtConfigFile));
|
|
82
|
-
}
|
|
55
|
+
const { app: { options }, } = await getAndLoadNuxt({ rootDir, for: "build" });
|
|
56
|
+
const { buildDir, _nuxtConfigFile: configFilePath } = options;
|
|
57
|
+
await (0, fs_extra_1.copy)(buildDir, (0, path_1.join)(destDir, (0, path_1.relative)(rootDir, buildDir)));
|
|
58
|
+
await (0, fs_extra_1.copy)(configFilePath, (0, path_1.join)(destDir, (0, path_1.basename)(configFilePath)));
|
|
83
59
|
return { packageJson: Object.assign({}, packageJson), frameworksEntry: "nuxt" };
|
|
84
60
|
}
|
|
85
61
|
exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
|
|
62
|
+
async function getDevModeHandle(cwd) {
|
|
63
|
+
const host = new Promise((resolve) => {
|
|
64
|
+
const cli = (0, utils_1.getNodeModuleBin)("nuxt", cwd);
|
|
65
|
+
const serve = (0, cross_spawn_1.spawn)(cli, ["dev"], { cwd });
|
|
66
|
+
serve.stdout.on("data", (data) => {
|
|
67
|
+
process.stdout.write(data);
|
|
68
|
+
const match = data.toString().match(/(http:\/\/.+:\d+)/);
|
|
69
|
+
if (match)
|
|
70
|
+
resolve(match[1]);
|
|
71
|
+
});
|
|
72
|
+
serve.stderr.on("data", (data) => {
|
|
73
|
+
process.stderr.write(data);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return (0, utils_3.simpleProxy)(await host);
|
|
77
|
+
}
|
|
78
|
+
exports.getDevModeHandle = getDevModeHandle;
|
package/lib/frameworks/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateLocales = exports.frameworksCallToAction = exports.conjoinOptions = exports.relativeRequire = exports.findDependency = exports.getNodeModuleBin = exports.getNpmRoot = exports.simpleProxy = exports.warnIfCustomBuildScript = exports.readJSON = exports.isUrl = void 0;
|
|
3
|
+
exports.getFrameworksBuildTarget = exports.validateLocales = exports.frameworksCallToAction = exports.conjoinOptions = exports.relativeRequire = exports.findDependency = exports.getNodeModuleBin = exports.getNpmRoot = exports.simpleProxy = exports.warnIfCustomBuildScript = exports.readJSON = exports.isUrl = void 0;
|
|
4
4
|
const fs_extra_1 = require("fs-extra");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const promises_1 = require("fs/promises");
|
|
@@ -37,7 +37,8 @@ function simpleProxy(hostOrRequestHandler) {
|
|
|
37
37
|
return async (originalReq, originalRes, next) => {
|
|
38
38
|
const { method, headers, url: path } = originalReq;
|
|
39
39
|
if (!method || !path) {
|
|
40
|
-
|
|
40
|
+
originalRes.end();
|
|
41
|
+
return;
|
|
41
42
|
}
|
|
42
43
|
const firebaseDefaultsJSON = process.env.__FIREBASE_DEFAULTS__;
|
|
43
44
|
const authTokenSyncURL = firebaseDefaultsJSON && JSON.parse(firebaseDefaultsJSON)._authTokenSyncURL;
|
|
@@ -174,3 +175,30 @@ function validateLocales(locales = []) {
|
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
exports.validateLocales = validateLocales;
|
|
178
|
+
function getFrameworksBuildTarget(purpose, validOptions) {
|
|
179
|
+
const frameworksBuild = process.env.FIREBASE_FRAMEWORKS_BUILD_TARGET;
|
|
180
|
+
if (frameworksBuild) {
|
|
181
|
+
if (!validOptions.includes(frameworksBuild)) {
|
|
182
|
+
throw new error_1.FirebaseError(`Invalid value for FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable: ${frameworksBuild}. Valid values are: ${validOptions.join(", ")}`);
|
|
183
|
+
}
|
|
184
|
+
return frameworksBuild;
|
|
185
|
+
}
|
|
186
|
+
else if (process.env.NODE_ENV) {
|
|
187
|
+
switch (process.env.NODE_ENV) {
|
|
188
|
+
case "development":
|
|
189
|
+
return "development";
|
|
190
|
+
case "production":
|
|
191
|
+
case "test":
|
|
192
|
+
return "production";
|
|
193
|
+
default:
|
|
194
|
+
throw new error_1.FirebaseError(`We cannot infer your build target from a non-standard NODE_ENV. Please set the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable. Valid values are: ${validOptions.join(", ")}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else if (purpose !== "serve") {
|
|
198
|
+
return "production";
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return "development";
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.getFrameworksBuildTarget = getFrameworksBuildTarget;
|
|
@@ -62,6 +62,7 @@ async function build(root) {
|
|
|
62
62
|
process.chdir(root);
|
|
63
63
|
await build({ root, mode: "production" });
|
|
64
64
|
process.chdir(cwd);
|
|
65
|
+
return { rewrites: [{ source: "**", destination: "/index.html" }] };
|
|
65
66
|
}
|
|
66
67
|
exports.build = build;
|
|
67
68
|
async function ɵcodegenPublicDirectory(root, dest) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.endpointFromFunction = exports.functionFromEndpoint = exports.deleteFunction = exports.updateFunction = exports.listAllFunctions = exports.listFunctions = exports.getFunction = exports.createFunction = exports.generateUploadUrl = exports.mebibytes = exports.API_VERSION = void 0;
|
|
4
|
-
const clc = require("colorette");
|
|
5
4
|
const apiv2_1 = require("../apiv2");
|
|
6
5
|
const error_1 = require("../error");
|
|
7
6
|
const api_1 = require("../api");
|
|
@@ -14,6 +13,7 @@ const utils = require("../utils");
|
|
|
14
13
|
const projectConfig = require("../functions/projectConfig");
|
|
15
14
|
const constants_1 = require("../functions/constants");
|
|
16
15
|
exports.API_VERSION = "v2";
|
|
16
|
+
const DEFAULT_MAX_INSTANCE_COUNT = 100;
|
|
17
17
|
const client = new apiv2_1.Client({
|
|
18
18
|
urlPrefix: api_1.functionsV2Origin,
|
|
19
19
|
auth: true,
|
|
@@ -48,22 +48,32 @@ function mebibytes(memory) {
|
|
|
48
48
|
return bytes / (1 << 20);
|
|
49
49
|
}
|
|
50
50
|
exports.mebibytes = mebibytes;
|
|
51
|
-
function functionsOpLogReject(
|
|
52
|
-
var _a, _b, _c, _d;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
utils.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
function functionsOpLogReject(func, type, err) {
|
|
52
|
+
var _a, _b, _c, _d, _e, _f;
|
|
53
|
+
if ((_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.includes("maxScale may not exceed")) {
|
|
54
|
+
const maxInstances = func.serviceConfig.maxInstanceCount || DEFAULT_MAX_INSTANCE_COUNT;
|
|
55
|
+
utils.logLabeledWarning("functions", `Your current project quotas don't allow for the current max instances setting of ${maxInstances}. ` +
|
|
56
|
+
"Either reduce this function's maximum instances, or request a quota increase on the underlying Cloud Run service " +
|
|
57
|
+
"at https://cloud.google.com/run/quotas.");
|
|
58
|
+
const suggestedFix = func.buildConfig.runtime.startsWith("python")
|
|
59
|
+
? "firebase_functions.options.set_global_options(max_instances=10)"
|
|
60
|
+
: "setGlobalOptions({maxInstances: 10})";
|
|
61
|
+
utils.logLabeledWarning("functions", `You can adjust the max instances value in your function's runtime options:\n\t${suggestedFix}`);
|
|
59
62
|
}
|
|
60
63
|
else {
|
|
61
|
-
utils.
|
|
64
|
+
utils.logLabeledWarning("functions", `${err === null || err === void 0 ? void 0 : err.message}`);
|
|
65
|
+
if (((_c = (_b = err === null || err === void 0 ? void 0 : err.context) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.statusCode) === 429) {
|
|
66
|
+
utils.logLabeledWarning("functions", `Got "Quota Exceeded" error while trying to ${type} ${func.name}. Waiting to retry...`);
|
|
67
|
+
}
|
|
68
|
+
else if ((_d = err === null || err === void 0 ? void 0 : err.message) === null || _d === void 0 ? void 0 : _d.includes("If you recently started to use Eventarc, it may take a few minutes before all necessary permissions are propagated to the Service Agent")) {
|
|
69
|
+
utils.logLabeledWarning("functions", `Since this is your first time using 2nd gen functions, we need a little bit longer to finish setting everything up. Retry the deployment in a few minutes.`);
|
|
70
|
+
}
|
|
71
|
+
utils.logLabeledWarning("functions", ` failed to ${type} function ${func.name}`);
|
|
62
72
|
}
|
|
63
|
-
throw new error_1.FirebaseError(`Failed to ${type} function ${
|
|
73
|
+
throw new error_1.FirebaseError(`Failed to ${type} function ${func.name}`, {
|
|
64
74
|
original: err,
|
|
65
|
-
status: (
|
|
66
|
-
context: { function:
|
|
75
|
+
status: (_f = (_e = err === null || err === void 0 ? void 0 : err.context) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.statusCode,
|
|
76
|
+
context: { function: func.name },
|
|
67
77
|
});
|
|
68
78
|
}
|
|
69
79
|
async function generateUploadUrl(projectId, location) {
|
|
@@ -86,7 +96,7 @@ async function createFunction(cloudFunction) {
|
|
|
86
96
|
return res.body;
|
|
87
97
|
}
|
|
88
98
|
catch (err) {
|
|
89
|
-
throw functionsOpLogReject(cloudFunction
|
|
99
|
+
throw functionsOpLogReject(cloudFunction, "create", err);
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
102
|
exports.createFunction = createFunction;
|
|
@@ -144,7 +154,7 @@ async function updateFunction(cloudFunction) {
|
|
|
144
154
|
return res.body;
|
|
145
155
|
}
|
|
146
156
|
catch (err) {
|
|
147
|
-
throw functionsOpLogReject(cloudFunction
|
|
157
|
+
throw functionsOpLogReject(cloudFunction, "update", err);
|
|
148
158
|
}
|
|
149
159
|
}
|
|
150
160
|
exports.updateFunction = updateFunction;
|
|
@@ -154,7 +164,7 @@ async function deleteFunction(cloudFunction) {
|
|
|
154
164
|
return res.body;
|
|
155
165
|
}
|
|
156
166
|
catch (err) {
|
|
157
|
-
throw functionsOpLogReject(cloudFunction, "update", err);
|
|
167
|
+
throw functionsOpLogReject({ name: cloudFunction }, "update", err);
|
|
158
168
|
}
|
|
159
169
|
}
|
|
160
170
|
exports.deleteFunction = deleteFunction;
|
package/package.json
CHANGED
|
@@ -617,7 +617,8 @@
|
|
|
617
617
|
"nodejs12",
|
|
618
618
|
"nodejs14",
|
|
619
619
|
"nodejs16",
|
|
620
|
-
"nodejs18"
|
|
620
|
+
"nodejs18",
|
|
621
|
+
"nodejs20"
|
|
621
622
|
],
|
|
622
623
|
"type": "string"
|
|
623
624
|
},
|
|
@@ -672,7 +673,8 @@
|
|
|
672
673
|
"nodejs12",
|
|
673
674
|
"nodejs14",
|
|
674
675
|
"nodejs16",
|
|
675
|
-
"nodejs18"
|
|
676
|
+
"nodejs18",
|
|
677
|
+
"nodejs20"
|
|
676
678
|
],
|
|
677
679
|
"type": "string"
|
|
678
680
|
},
|