firebase-tools 12.1.0 → 12.2.1
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/emulator/downloadableEmulators.js +3 -3
- package/lib/emulator/functionsEmulator.js +6 -1
- package/lib/emulator/storage/index.js +0 -5
- package/lib/emulator/storage/rules/manager.js +4 -0
- package/lib/emulator/storage/rules/runtime.js +21 -7
- package/lib/emulator/storage/server.js +0 -52
- package/lib/frameworks/angular/index.js +43 -12
- package/lib/frameworks/angular/utils.js +124 -75
- package/lib/frameworks/constants.js +10 -2
- package/lib/frameworks/express/index.js +4 -4
- package/lib/frameworks/frameworks.js +29 -0
- package/lib/frameworks/index.js +26 -23
- package/lib/frameworks/next/index.js +2 -2
- package/lib/frameworks/nuxt/index.js +33 -22
- package/lib/frameworks/nuxt2/index.js +55 -62
- package/lib/frameworks/utils.js +33 -2
- package/lib/frameworks/vite/index.js +1 -0
- package/lib/gcp/cloudfunctionsv2.js +26 -16
- package/package.json +1 -1
- package/templates/init/storage/storage.rules +4 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEndpointFiltered = exports.isCodebaseFiltered = exports.groupEndpointsByCodebase = exports.targetCodebases = exports.getFunctionLabel = exports.getEndpointFilters = exports.parseFunctionSelector = exports.endpointMatchesFilter = exports.endpointMatchesAnyFilter = void 0;
|
|
3
|
+
exports.isEndpointFiltered = exports.isCodebaseFiltered = exports.groupEndpointsByCodebase = exports.targetCodebases = exports.getFunctionLabel = exports.getHumanFriendlyPlatformName = exports.getEndpointFilters = exports.parseFunctionSelector = exports.endpointMatchesFilter = exports.endpointMatchesAnyFilter = void 0;
|
|
4
4
|
const backend = require("./backend");
|
|
5
5
|
const projectConfig_1 = require("../../functions/projectConfig");
|
|
6
6
|
function endpointMatchesAnyFilter(endpoint, filters) {
|
|
@@ -67,6 +67,13 @@ function getEndpointFilters(options) {
|
|
|
67
67
|
return filters;
|
|
68
68
|
}
|
|
69
69
|
exports.getEndpointFilters = getEndpointFilters;
|
|
70
|
+
function getHumanFriendlyPlatformName(platform) {
|
|
71
|
+
if (platform === "gcfv1") {
|
|
72
|
+
return "1st Gen";
|
|
73
|
+
}
|
|
74
|
+
return "2nd Gen";
|
|
75
|
+
}
|
|
76
|
+
exports.getHumanFriendlyPlatformName = getHumanFriendlyPlatformName;
|
|
70
77
|
function getFunctionLabel(fn) {
|
|
71
78
|
let id = `${fn.id}(${fn.region})`;
|
|
72
79
|
if (fn.codebase && fn.codebase !== projectConfig_1.DEFAULT_CODEBASE) {
|
|
@@ -25,6 +25,7 @@ const utils = require("../../../utils");
|
|
|
25
25
|
const services = require("../services");
|
|
26
26
|
const v1_1 = require("../../../functions/events/v1");
|
|
27
27
|
const checkIam_1 = require("../checkIam");
|
|
28
|
+
const functionsDeployHelper_1 = require("../functionsDeployHelper");
|
|
28
29
|
const gcfV1PollerOptions = {
|
|
29
30
|
apiOrigin: api_1.functionsOrigin,
|
|
30
31
|
apiVersion: gcf.API_VERSION,
|
|
@@ -536,8 +537,9 @@ class Fabricator {
|
|
|
536
537
|
}
|
|
537
538
|
logOpStart(op, endpoint) {
|
|
538
539
|
const runtime = (0, runtimes_1.getHumanFriendlyRuntimeName)(endpoint.runtime);
|
|
540
|
+
const platform = (0, functionsDeployHelper_1.getHumanFriendlyPlatformName)(endpoint.platform);
|
|
539
541
|
const label = helper.getFunctionLabel(endpoint);
|
|
540
|
-
utils.logLabeledBullet("functions", `${op} ${runtime} function ${clc.bold(label)}...`);
|
|
542
|
+
utils.logLabeledBullet("functions", `${op} ${runtime} (${platform}) function ${clc.bold(label)}...`);
|
|
541
543
|
}
|
|
542
544
|
logOpSuccess(op, endpoint) {
|
|
543
545
|
utils.logSuccess(this.getLogSuccessMessage(op, endpoint));
|
|
@@ -18,9 +18,9 @@ const EMULATOR_INSTANCE_KILL_TIMEOUT = 4000;
|
|
|
18
18
|
const CACHE_DIR = process.env.FIREBASE_EMULATORS_PATH || path.join(os.homedir(), ".cache", "firebase", "emulators");
|
|
19
19
|
const EMULATOR_UPDATE_DETAILS = {
|
|
20
20
|
database: {
|
|
21
|
-
version: "4.11.
|
|
22
|
-
expectedSize:
|
|
23
|
-
expectedChecksum: "
|
|
21
|
+
version: "4.11.2",
|
|
22
|
+
expectedSize: 34495935,
|
|
23
|
+
expectedChecksum: "2fd771101c0e1f7898c04c9204f2ce63",
|
|
24
24
|
},
|
|
25
25
|
firestore: {
|
|
26
26
|
version: "1.17.4",
|
|
@@ -332,7 +332,12 @@ class FunctionsEmulator {
|
|
|
332
332
|
this.logger.logLabeled("ERROR", "functions", `Failed to load function definition from source: ${e}`);
|
|
333
333
|
return;
|
|
334
334
|
}
|
|
335
|
-
this.
|
|
335
|
+
if (this.debugMode) {
|
|
336
|
+
this.workerPools[emulatableBackend.codebase].exit();
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
this.workerPools[emulatableBackend.codebase].refresh();
|
|
340
|
+
}
|
|
336
341
|
this.blockingFunctionsConfig = {};
|
|
337
342
|
const toSetup = triggerDefinitions.filter((definition) => {
|
|
338
343
|
if (force) {
|
|
@@ -82,11 +82,6 @@ class StorageEmulator {
|
|
|
82
82
|
getApp() {
|
|
83
83
|
return this._app;
|
|
84
84
|
}
|
|
85
|
-
async replaceRules(rules) {
|
|
86
|
-
await this._rulesManager.stop();
|
|
87
|
-
this._rulesManager = this.createRulesManager(rules);
|
|
88
|
-
return this._rulesManager.start();
|
|
89
|
-
}
|
|
90
85
|
createRulesManager(rules) {
|
|
91
86
|
return (0, manager_1.createStorageRulesManager)(rules, this._rulesRuntime);
|
|
92
87
|
}
|
|
@@ -20,6 +20,7 @@ class DefaultStorageRulesManager {
|
|
|
20
20
|
this._rules = _rules;
|
|
21
21
|
}
|
|
22
22
|
async start() {
|
|
23
|
+
this._runtime.start();
|
|
23
24
|
const issues = await this.loadRuleset();
|
|
24
25
|
this.updateWatcher(this._rules.name);
|
|
25
26
|
return issues;
|
|
@@ -29,6 +30,9 @@ class DefaultStorageRulesManager {
|
|
|
29
30
|
}
|
|
30
31
|
async stop() {
|
|
31
32
|
await this._watcher.close();
|
|
33
|
+
if (this._runtime.alive) {
|
|
34
|
+
await this._runtime.stop();
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
updateWatcher(rulesFile) {
|
|
34
38
|
this._watcher = chokidar
|
|
@@ -71,6 +71,9 @@ class StorageRulesRuntime {
|
|
|
71
71
|
}
|
|
72
72
|
async start(autoDownload = true) {
|
|
73
73
|
var _a, _b;
|
|
74
|
+
if (this.alive) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
74
77
|
const downloadDetails = downloadableEmulators_1.DownloadDetails[types_2.Emulators.STORAGE];
|
|
75
78
|
const hasEmulator = fs.existsSync(downloadDetails.downloadPath);
|
|
76
79
|
if (!hasEmulator) {
|
|
@@ -90,11 +93,11 @@ class StorageRulesRuntime {
|
|
|
90
93
|
this._childprocess = (0, cross_spawn_1.spawn)(command.binary, command.args, {
|
|
91
94
|
stdio: ["pipe", "pipe", "pipe"],
|
|
92
95
|
});
|
|
93
|
-
this._childprocess.on("exit", (
|
|
96
|
+
this._childprocess.on("exit", () => {
|
|
97
|
+
var _a;
|
|
94
98
|
this._alive = false;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
99
|
+
(_a = this._childprocess) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
|
|
100
|
+
this._childprocess = undefined;
|
|
98
101
|
});
|
|
99
102
|
const startPromise = new Promise((resolve) => {
|
|
100
103
|
this._requests[-1] = {
|
|
@@ -152,12 +155,23 @@ class StorageRulesRuntime {
|
|
|
152
155
|
return startPromise;
|
|
153
156
|
}
|
|
154
157
|
stop() {
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
emulatorLogger_1.EmulatorLogger.forEmulator(types_2.Emulators.STORAGE).log("DEBUG", "Stopping rules runtime.");
|
|
159
|
+
return new Promise((resolve) => {
|
|
160
|
+
var _a;
|
|
161
|
+
if (this.alive) {
|
|
162
|
+
this._childprocess.on("exit", () => {
|
|
163
|
+
resolve();
|
|
164
|
+
});
|
|
165
|
+
(_a = this._childprocess) === null || _a === void 0 ? void 0 : _a.kill("SIGINT");
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
resolve();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
157
171
|
}
|
|
158
172
|
async _sendRequest(rab, overrideId) {
|
|
159
173
|
if (!this._childprocess) {
|
|
160
|
-
throw new error_1.FirebaseError("
|
|
174
|
+
throw new error_1.FirebaseError("Failed to send Cloud Storage rules request due to rules runtime not available.");
|
|
161
175
|
}
|
|
162
176
|
const runtimeActionRequest = Object.assign(Object.assign({}, rab), { id: overrideId !== null && overrideId !== void 0 ? overrideId : this._requestCount++ });
|
|
163
177
|
if (overrideId !== undefined) {
|
|
@@ -8,7 +8,6 @@ const types_1 = require("../types");
|
|
|
8
8
|
const bodyParser = require("body-parser");
|
|
9
9
|
const gcloud_1 = require("./apis/gcloud");
|
|
10
10
|
const firebase_1 = require("./apis/firebase");
|
|
11
|
-
const errors_1 = require("../auth/errors");
|
|
12
11
|
function createApp(defaultProjectId, emulator) {
|
|
13
12
|
const { storageLayer } = emulator;
|
|
14
13
|
const app = express();
|
|
@@ -51,54 +50,6 @@ function createApp(defaultProjectId, emulator) {
|
|
|
51
50
|
await storageLayer.export(path, { initiatedBy });
|
|
52
51
|
res.sendStatus(200);
|
|
53
52
|
});
|
|
54
|
-
app.put("/internal/setRules", async (req, res) => {
|
|
55
|
-
const rulesRaw = req.body.rules;
|
|
56
|
-
if (!(rulesRaw && Array.isArray(rulesRaw.files) && rulesRaw.files.length > 0)) {
|
|
57
|
-
res.status(400).json({
|
|
58
|
-
message: "Request body must include 'rules.files' array",
|
|
59
|
-
});
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const { files } = rulesRaw;
|
|
63
|
-
function parseRulesFromFiles(files) {
|
|
64
|
-
if (files.length === 1) {
|
|
65
|
-
const file = files[0];
|
|
66
|
-
if (!isRulesFile(file)) {
|
|
67
|
-
throw new errors_1.InvalidArgumentError("Each member of 'rules.files' array must contain 'name' and 'content'");
|
|
68
|
-
}
|
|
69
|
-
return { name: file.name, content: file.content };
|
|
70
|
-
}
|
|
71
|
-
const rules = [];
|
|
72
|
-
for (const file of files) {
|
|
73
|
-
if (!isRulesFile(file) || !file.resource) {
|
|
74
|
-
throw new errors_1.InvalidArgumentError("Each member of 'rules.files' array must contain 'name', 'content', and 'resource'");
|
|
75
|
-
}
|
|
76
|
-
rules.push({ resource: file.resource, rules: { name: file.name, content: file.content } });
|
|
77
|
-
}
|
|
78
|
-
return rules;
|
|
79
|
-
}
|
|
80
|
-
let rules;
|
|
81
|
-
try {
|
|
82
|
-
rules = parseRulesFromFiles(files);
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
if (err instanceof errors_1.InvalidArgumentError) {
|
|
86
|
-
res.status(400).json({ message: err.message });
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
throw err;
|
|
90
|
-
}
|
|
91
|
-
const issues = await emulator.replaceRules(rules);
|
|
92
|
-
if (issues.errors.length > 0) {
|
|
93
|
-
res.status(400).json({
|
|
94
|
-
message: "There was an error updating rules, see logs for more details",
|
|
95
|
-
});
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
res.status(200).json({
|
|
99
|
-
message: "Rules updated successfully",
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
53
|
app.post("/internal/reset", (req, res) => {
|
|
103
54
|
emulator.reset();
|
|
104
55
|
res.sendStatus(200);
|
|
@@ -108,6 +59,3 @@ function createApp(defaultProjectId, emulator) {
|
|
|
108
59
|
return Promise.resolve(app);
|
|
109
60
|
}
|
|
110
61
|
exports.createApp = createApp;
|
|
111
|
-
function isRulesFile(file) {
|
|
112
|
-
return (typeof file.name === "string" && typeof file.content === "string");
|
|
113
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.getDevModeHandle = exports.build = exports.init = exports.discover = exports.docsUrl = exports.type = exports.support = exports.name = void 0;
|
|
3
|
+
exports.ɵcodegenFunctionsDirectory = exports.shouldUseDevModeHandle = exports.getValidBuildTargets = exports.ɵcodegenPublicDirectory = exports.getDevModeHandle = exports.build = exports.init = exports.discover = exports.docsUrl = exports.type = exports.support = exports.name = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
6
|
const cross_spawn_1 = require("cross-spawn");
|
|
@@ -43,8 +43,8 @@ async function init(setup, config) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
exports.init = init;
|
|
46
|
-
async function build(dir) {
|
|
47
|
-
const { targets, serverTarget, serveOptimizedImages, locales } = await (0, utils_2.getBuildConfig)(dir);
|
|
46
|
+
async function build(dir, configuration) {
|
|
47
|
+
const { targets, serverTarget, serveOptimizedImages, locales, baseHref } = await (0, utils_2.getBuildConfig)(dir, configuration);
|
|
48
48
|
await (0, utils_1.warnIfCustomBuildScript)(dir, exports.name, DEFAULT_BUILD_SCRIPT);
|
|
49
49
|
for (const target of targets) {
|
|
50
50
|
const cli = (0, utils_1.getNodeModuleBin)("ng", dir);
|
|
@@ -56,15 +56,23 @@ async function build(dir) {
|
|
|
56
56
|
throw new error_1.FirebaseError(`Unable to build ${target}`);
|
|
57
57
|
}
|
|
58
58
|
const wantsBackend = !!serverTarget || serveOptimizedImages;
|
|
59
|
+
const rewrites = serverTarget
|
|
60
|
+
? []
|
|
61
|
+
: [
|
|
62
|
+
{
|
|
63
|
+
source: path_1.posix.join(baseHref, "**"),
|
|
64
|
+
destination: path_1.posix.join(baseHref, "index.html"),
|
|
65
|
+
},
|
|
66
|
+
];
|
|
59
67
|
const i18n = !!locales;
|
|
60
|
-
return { wantsBackend, i18n };
|
|
68
|
+
return { wantsBackend, i18n, rewrites };
|
|
61
69
|
}
|
|
62
70
|
exports.build = build;
|
|
63
|
-
async function getDevModeHandle(dir) {
|
|
71
|
+
async function getDevModeHandle(dir, configuration) {
|
|
64
72
|
const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
|
|
65
|
-
const { serveTarget } = await (0, utils_2.getContext)(dir);
|
|
73
|
+
const { serveTarget } = await (0, utils_2.getContext)(dir, configuration);
|
|
66
74
|
if (!serveTarget)
|
|
67
|
-
|
|
75
|
+
throw new Error("Could not find the serveTarget");
|
|
68
76
|
const host = new Promise((resolve) => {
|
|
69
77
|
const cli = (0, utils_1.getNodeModuleBin)("ng", dir);
|
|
70
78
|
const serve = (0, cross_spawn_1.spawn)(cli, ["run", targetStringFromTarget(serveTarget), "--host", "localhost"], {
|
|
@@ -83,8 +91,8 @@ async function getDevModeHandle(dir) {
|
|
|
83
91
|
return (0, utils_1.simpleProxy)(await host);
|
|
84
92
|
}
|
|
85
93
|
exports.getDevModeHandle = getDevModeHandle;
|
|
86
|
-
async function ɵcodegenPublicDirectory(sourceDir, destDir) {
|
|
87
|
-
const { outputPath, baseHref, defaultLocale, locales } = await (0, utils_2.getBrowserConfig)(sourceDir);
|
|
94
|
+
async function ɵcodegenPublicDirectory(sourceDir, destDir, configuration) {
|
|
95
|
+
const { outputPath, baseHref, defaultLocale, locales } = await (0, utils_2.getBrowserConfig)(sourceDir, configuration);
|
|
88
96
|
await (0, promises_1.mkdir)((0, path_1.join)(destDir, baseHref), { recursive: true });
|
|
89
97
|
if (locales) {
|
|
90
98
|
await Promise.all([
|
|
@@ -102,11 +110,33 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir) {
|
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
112
|
exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
|
|
105
|
-
async function
|
|
113
|
+
async function getValidBuildTargets(purpose, dir) {
|
|
114
|
+
const validTargetNames = new Set(["development", "production"]);
|
|
115
|
+
try {
|
|
116
|
+
const { workspaceProject, browserTarget, serverTarget, serveTarget } = await (0, utils_2.getContext)(dir);
|
|
117
|
+
const { target } = ((purpose === "serve" && serveTarget) || serverTarget || browserTarget);
|
|
118
|
+
const workspaceTarget = workspaceProject.targets.get(target);
|
|
119
|
+
Object.keys(workspaceTarget.configurations || {}).forEach((it) => validTargetNames.add(it));
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
}
|
|
123
|
+
const allTargets = await (0, utils_2.getAllTargets)(purpose, dir);
|
|
124
|
+
return [...validTargetNames, ...allTargets];
|
|
125
|
+
}
|
|
126
|
+
exports.getValidBuildTargets = getValidBuildTargets;
|
|
127
|
+
async function shouldUseDevModeHandle(targetOrConfiguration, dir) {
|
|
128
|
+
const { serveTarget } = await (0, utils_2.getContext)(dir, targetOrConfiguration);
|
|
129
|
+
if (!serveTarget)
|
|
130
|
+
return false;
|
|
131
|
+
return serveTarget.configuration !== "production";
|
|
132
|
+
}
|
|
133
|
+
exports.shouldUseDevModeHandle = shouldUseDevModeHandle;
|
|
134
|
+
async function ɵcodegenFunctionsDirectory(sourceDir, destDir, configuration) {
|
|
106
135
|
var _a;
|
|
107
136
|
var _b;
|
|
108
|
-
const { packageJson, serverOutputPath, browserOutputPath, defaultLocale, serverLocales, browserLocales, bundleDependencies, externalDependencies, baseHref: baseUrl, serveOptimizedImages, } = await (0, utils_2.getServerConfig)(sourceDir);
|
|
137
|
+
const { packageJson, serverOutputPath, browserOutputPath, defaultLocale, serverLocales, browserLocales, bundleDependencies, externalDependencies, baseHref: baseUrl, serveOptimizedImages, } = await (0, utils_2.getServerConfig)(sourceDir, configuration);
|
|
109
138
|
const dotEnv = { __NG_BROWSER_OUTPUT_PATH__: browserOutputPath };
|
|
139
|
+
let rewriteSource = undefined;
|
|
110
140
|
await Promise.all([
|
|
111
141
|
serverOutputPath
|
|
112
142
|
? (0, promises_1.mkdir)((0, path_1.join)(destDir, serverOutputPath), { recursive: true }).then(() => (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, serverOutputPath), (0, path_1.join)(destDir, serverOutputPath)))
|
|
@@ -157,7 +187,8 @@ exports.handle = function(req,res) {
|
|
|
157
187
|
}
|
|
158
188
|
else {
|
|
159
189
|
bootstrapScript = `exports.handle = (res, req) => req.sendStatus(404);\n`;
|
|
190
|
+
rewriteSource = path_1.posix.join(baseUrl, "__image__");
|
|
160
191
|
}
|
|
161
|
-
return { bootstrapScript, packageJson, baseUrl, dotEnv };
|
|
192
|
+
return { bootstrapScript, packageJson, baseUrl, dotEnv, rewriteSource };
|
|
162
193
|
}
|
|
163
194
|
exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBuildConfig = exports.getServerConfig = exports.getBrowserConfig = exports.getContext = void 0;
|
|
3
|
+
exports.getBuildConfig = exports.getServerConfig = exports.getBrowserConfig = exports.getContext = exports.getAllTargets = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const error_1 = require("../../error");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -49,7 +49,46 @@ async function localesForTarget(dir, architectHost, target, workspaceProject) {
|
|
|
49
49
|
(0, utils_1.validateLocales)(locales);
|
|
50
50
|
return { locales, defaultLocale };
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
const DEV_SERVER_TARGETS = [
|
|
53
|
+
"@angular-devkit/build-angular:dev-server",
|
|
54
|
+
"@nguniversal/builders:ssr-dev-server",
|
|
55
|
+
];
|
|
56
|
+
function getValidBuilders(purpose) {
|
|
57
|
+
return [
|
|
58
|
+
"@angular/fire:deploy",
|
|
59
|
+
"@angular-devkit/build-angular:browser",
|
|
60
|
+
"@nguniversal/builders:prerender",
|
|
61
|
+
...(purpose === "deploy" ? [] : DEV_SERVER_TARGETS),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
async function getAllTargets(purpose, dir) {
|
|
65
|
+
const validBuilders = getValidBuilders(purpose);
|
|
66
|
+
const { NodeJsAsyncHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node");
|
|
67
|
+
const { workspaces } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core");
|
|
68
|
+
const { targetStringFromTarget } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect");
|
|
69
|
+
const host = workspaces.createWorkspaceHost(new NodeJsAsyncHost());
|
|
70
|
+
const { workspace } = await workspaces.readWorkspace(dir, host);
|
|
71
|
+
const targets = [];
|
|
72
|
+
workspace.projects.forEach((projectDefinition, project) => {
|
|
73
|
+
if (projectDefinition.extensions.projectType !== "application")
|
|
74
|
+
return;
|
|
75
|
+
projectDefinition.targets.forEach((targetDefinition, target) => {
|
|
76
|
+
if (!validBuilders.includes(targetDefinition.builder))
|
|
77
|
+
return;
|
|
78
|
+
const configurations = Object.keys(targetDefinition.configurations || {});
|
|
79
|
+
if (!configurations.includes("production"))
|
|
80
|
+
configurations.push("production");
|
|
81
|
+
if (!configurations.includes("development"))
|
|
82
|
+
configurations.push("development");
|
|
83
|
+
configurations.forEach((configuration) => {
|
|
84
|
+
targets.push(targetStringFromTarget({ project, target, configuration }));
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
return targets;
|
|
89
|
+
}
|
|
90
|
+
exports.getAllTargets = getAllTargets;
|
|
91
|
+
async function getContext(dir, targetOrConfiguration) {
|
|
53
92
|
const { NodeJsAsyncHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core/node");
|
|
54
93
|
const { workspaces } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/core");
|
|
55
94
|
const { WorkspaceNodeModulesArchitectHost } = (0, utils_1.relativeRequire)(dir, "@angular-devkit/architect/node");
|
|
@@ -59,12 +98,26 @@ async function getContext(dir) {
|
|
|
59
98
|
const { workspace } = await workspaces.readWorkspace(dir, host);
|
|
60
99
|
const architectHost = new WorkspaceNodeModulesArchitectHost(workspace, dir);
|
|
61
100
|
const architect = new Architect(architectHost);
|
|
62
|
-
let
|
|
101
|
+
let overrideTarget;
|
|
102
|
+
let project;
|
|
63
103
|
let browserTarget;
|
|
64
104
|
let serverTarget;
|
|
65
105
|
let prerenderTarget;
|
|
66
106
|
let serveTarget;
|
|
67
107
|
let serveOptimizedImages = false;
|
|
108
|
+
let deployTargetName;
|
|
109
|
+
let configuration = undefined;
|
|
110
|
+
if (targetOrConfiguration) {
|
|
111
|
+
try {
|
|
112
|
+
overrideTarget = targetFromTargetString(targetOrConfiguration);
|
|
113
|
+
configuration = overrideTarget.configuration;
|
|
114
|
+
project = overrideTarget.project;
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
deployTargetName = "deploy";
|
|
118
|
+
configuration = targetOrConfiguration;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
68
121
|
if (!project) {
|
|
69
122
|
const angularJson = parse(await host.readFile((0, path_1.join)(dir, "angular.json")));
|
|
70
123
|
project = angularJson.defaultProject;
|
|
@@ -79,11 +132,25 @@ async function getContext(dir) {
|
|
|
79
132
|
project = apps[0];
|
|
80
133
|
}
|
|
81
134
|
if (!project)
|
|
82
|
-
throw new error_1.FirebaseError("Unable to determine the application to deploy,
|
|
135
|
+
throw new error_1.FirebaseError("Unable to determine the application to deploy, specify a target via the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable");
|
|
83
136
|
const workspaceProject = workspace.projects.get(project);
|
|
84
137
|
if (!workspaceProject)
|
|
85
138
|
throw new error_1.FirebaseError(`No project ${project} found.`);
|
|
86
|
-
|
|
139
|
+
if (overrideTarget) {
|
|
140
|
+
const target = workspaceProject.targets.get(overrideTarget.target);
|
|
141
|
+
const builder = target.builder;
|
|
142
|
+
if (builder === "@angular/fire:deploy")
|
|
143
|
+
deployTargetName = overrideTarget.target;
|
|
144
|
+
if (builder === "@angular-devkit/build-angular:browser")
|
|
145
|
+
browserTarget = overrideTarget;
|
|
146
|
+
if (builder === "@nguniversal/builders:prerender")
|
|
147
|
+
prerenderTarget = overrideTarget;
|
|
148
|
+
if (typeof builder === "string" && DEV_SERVER_TARGETS.includes(builder))
|
|
149
|
+
serveTarget = overrideTarget;
|
|
150
|
+
}
|
|
151
|
+
const deployTargetDefinition = deployTargetName
|
|
152
|
+
? workspaceProject.targets.get(deployTargetName)
|
|
153
|
+
: undefined;
|
|
87
154
|
if ((deployTargetDefinition === null || deployTargetDefinition === void 0 ? void 0 : deployTargetDefinition.builder) === "@angular/fire:deploy") {
|
|
88
155
|
const options = deployTargetDefinition.options;
|
|
89
156
|
if (typeof (options === null || options === void 0 ? void 0 : options.prerenderTarget) === "string")
|
|
@@ -107,76 +174,57 @@ async function getContext(dir) {
|
|
|
107
174
|
console.warn("Treating the application as fully rendered. Add a serverTarget to your deploy target in angular.json to utilize server-side rendering.");
|
|
108
175
|
}
|
|
109
176
|
}
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
throw new Error(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
177
|
+
if (!overrideTarget && !prerenderTarget && workspaceProject.targets.has("prerender")) {
|
|
178
|
+
const { defaultConfiguration = "production" } = workspaceProject.targets.get("prerender");
|
|
179
|
+
prerenderTarget = { project, target: "prerender", configuration: defaultConfiguration };
|
|
180
|
+
}
|
|
181
|
+
if (serveTarget) {
|
|
182
|
+
const options = await architectHost.getOptionsForTarget(serveTarget);
|
|
183
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.browserTarget) !== "string")
|
|
184
|
+
throw new Error(`${serveTarget.target} browserTarget expected to be string, check your angular.json.`);
|
|
185
|
+
browserTarget = targetFromTargetString(options.browserTarget);
|
|
186
|
+
if (options === null || options === void 0 ? void 0 : options.serverTarget) {
|
|
187
|
+
if (typeof options.serverTarget !== "string")
|
|
188
|
+
throw new Error(`${serveTarget.target} serverTarget expected to be string, check your angular.json.`);
|
|
189
|
+
serverTarget = targetFromTargetString(options.serverTarget);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else if (prerenderTarget) {
|
|
193
|
+
const options = await architectHost.getOptionsForTarget(prerenderTarget);
|
|
194
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.browserTarget) !== "string")
|
|
123
195
|
throw new Error("Prerender browserTarget expected to be string, check your angular.json.");
|
|
124
|
-
browserTarget = targetFromTargetString(
|
|
125
|
-
if (typeof (
|
|
196
|
+
browserTarget = targetFromTargetString(options.browserTarget);
|
|
197
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.serverTarget) !== "string")
|
|
126
198
|
throw new Error("Prerender serverTarget expected to be string, check your angular.json.");
|
|
127
|
-
serverTarget = targetFromTargetString(
|
|
199
|
+
serverTarget = targetFromTargetString(options.serverTarget);
|
|
200
|
+
}
|
|
201
|
+
if (!browserTarget && workspaceProject.targets.has("build")) {
|
|
202
|
+
const { defaultConfiguration = "production" } = workspaceProject.targets.get("build");
|
|
203
|
+
browserTarget = { project, target: "build", configuration: defaultConfiguration };
|
|
204
|
+
}
|
|
205
|
+
if (!serverTarget && workspaceProject.targets.has("server")) {
|
|
206
|
+
const { defaultConfiguration = "production" } = workspaceProject.targets.get("server");
|
|
207
|
+
serverTarget = { project, target: "server", configuration: defaultConfiguration };
|
|
128
208
|
}
|
|
129
|
-
|
|
130
|
-
if (workspaceProject.targets.has("
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
const configuration = configurations.includes("production")
|
|
134
|
-
? "production"
|
|
135
|
-
: target.defaultConfiguration;
|
|
136
|
-
if (!configuration)
|
|
137
|
-
throw new Error("No production or default configuration found for build.");
|
|
138
|
-
if (configuration !== "production")
|
|
139
|
-
console.warn(`Using ${configuration} configuration for the browser deploy, we suggest adding a production target.`);
|
|
140
|
-
browserTarget = { project, target: "build", configuration };
|
|
209
|
+
if (!serveTarget) {
|
|
210
|
+
if (serverTarget && workspaceProject.targets.has("serve-ssr")) {
|
|
211
|
+
const { defaultConfiguration = "development" } = workspaceProject.targets.get("serve-ssr");
|
|
212
|
+
serveTarget = { project, target: "serve-ssr", configuration: defaultConfiguration };
|
|
141
213
|
}
|
|
142
|
-
if (workspaceProject.targets.has("
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
const configuration = configurations.includes("production")
|
|
146
|
-
? "production"
|
|
147
|
-
: target.defaultConfiguration;
|
|
148
|
-
if (!configuration)
|
|
149
|
-
throw new Error("No production or default configutation found for server.");
|
|
150
|
-
if (configuration !== "production")
|
|
151
|
-
console.warn(`Using ${configuration} configuration for the server deploy, we suggest adding a production target.`);
|
|
152
|
-
serverTarget = { project, target: "server", configuration };
|
|
214
|
+
else if (workspaceProject.targets.has("serve")) {
|
|
215
|
+
const { defaultConfiguration = "development" } = workspaceProject.targets.get("serve");
|
|
216
|
+
serveTarget = { project, target: "serve", configuration: defaultConfiguration };
|
|
153
217
|
}
|
|
154
218
|
}
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const configuration = configurations.includes("development")
|
|
159
|
-
? "development"
|
|
160
|
-
: target.defaultConfiguration;
|
|
161
|
-
if (!configuration)
|
|
162
|
-
throw new Error("No development or default configutation found for serve-ssr.");
|
|
163
|
-
if (configuration !== "development")
|
|
164
|
-
console.warn(`Using ${configuration} configuration for the local server, we suggest adding a development target.`);
|
|
165
|
-
serveTarget = { project, target: "serve-ssr", configuration };
|
|
166
|
-
}
|
|
167
|
-
else if (workspaceProject.targets.has("serve")) {
|
|
219
|
+
if (configuration) {
|
|
220
|
+
if (prerenderTarget)
|
|
221
|
+
prerenderTarget.configuration = configuration;
|
|
168
222
|
if (serverTarget)
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
: target.defaultConfiguration;
|
|
175
|
-
if (!configuration)
|
|
176
|
-
throw new Error("No development or default configutation found for serve.");
|
|
177
|
-
if (configuration !== "development")
|
|
178
|
-
console.warn(`Using ${configuration} configuration for the local server, we suggest adding a development target.`);
|
|
179
|
-
serveTarget = { project, target: "serve", configuration };
|
|
223
|
+
serverTarget.configuration = configuration;
|
|
224
|
+
if (browserTarget)
|
|
225
|
+
browserTarget.configuration = configuration;
|
|
226
|
+
if (serveTarget)
|
|
227
|
+
serveTarget.configuration = configuration;
|
|
180
228
|
}
|
|
181
229
|
if (!browserTarget)
|
|
182
230
|
throw new error_1.FirebaseError(`No browser target on ${project}`);
|
|
@@ -184,7 +232,7 @@ async function getContext(dir) {
|
|
|
184
232
|
if (!browserTargetOptions) {
|
|
185
233
|
throw new error_1.FirebaseError(`Couldn't find options for ${targetStringFromTarget(browserTarget)}.`);
|
|
186
234
|
}
|
|
187
|
-
const baseHref = browserTargetOptions.baseHref || "";
|
|
235
|
+
const baseHref = browserTargetOptions.baseHref || "/";
|
|
188
236
|
if (typeof baseHref !== "string") {
|
|
189
237
|
throw new error_1.FirebaseError(`baseHref on ${targetStringFromTarget(browserTarget)} was not a string`);
|
|
190
238
|
}
|
|
@@ -202,8 +250,8 @@ async function getContext(dir) {
|
|
|
202
250
|
};
|
|
203
251
|
}
|
|
204
252
|
exports.getContext = getContext;
|
|
205
|
-
async function getBrowserConfig(sourceDir) {
|
|
206
|
-
const { architectHost, browserTarget, baseHref, workspaceProject } = await getContext(sourceDir);
|
|
253
|
+
async function getBrowserConfig(sourceDir, configuration) {
|
|
254
|
+
const { architectHost, browserTarget, baseHref, workspaceProject } = await getContext(sourceDir, configuration);
|
|
207
255
|
const { locales, defaultLocale } = await localesForTarget(sourceDir, architectHost, browserTarget, workspaceProject);
|
|
208
256
|
const browserTargetOptions = await architectHost.getOptionsForTarget(browserTarget);
|
|
209
257
|
if (typeof (browserTargetOptions === null || browserTargetOptions === void 0 ? void 0 : browserTargetOptions.outputPath) !== "string")
|
|
@@ -212,9 +260,9 @@ async function getBrowserConfig(sourceDir) {
|
|
|
212
260
|
return { locales, baseHref, outputPath, defaultLocale };
|
|
213
261
|
}
|
|
214
262
|
exports.getBrowserConfig = getBrowserConfig;
|
|
215
|
-
async function getServerConfig(sourceDir) {
|
|
263
|
+
async function getServerConfig(sourceDir, configuration) {
|
|
216
264
|
var _a;
|
|
217
|
-
const { architectHost, host, serverTarget, browserTarget, baseHref, workspaceProject, serveOptimizedImages, } = await getContext(sourceDir);
|
|
265
|
+
const { architectHost, host, serverTarget, browserTarget, baseHref, workspaceProject, serveOptimizedImages, } = await getContext(sourceDir, configuration);
|
|
218
266
|
const browserTargetOptions = await architectHost.getOptionsForTarget(browserTarget);
|
|
219
267
|
if (typeof (browserTargetOptions === null || browserTargetOptions === void 0 ? void 0 : browserTargetOptions.outputPath) !== "string")
|
|
220
268
|
throw new Error("browserTarget output path is not a string");
|
|
@@ -259,13 +307,14 @@ async function getServerConfig(sourceDir) {
|
|
|
259
307
|
};
|
|
260
308
|
}
|
|
261
309
|
exports.getServerConfig = getServerConfig;
|
|
262
|
-
async function getBuildConfig(sourceDir) {
|
|
310
|
+
async function getBuildConfig(sourceDir, configuration) {
|
|
263
311
|
const { targetStringFromTarget } = (0, utils_1.relativeRequire)(sourceDir, "@angular-devkit/architect");
|
|
264
|
-
const { browserTarget, prerenderTarget, serverTarget, architectHost, workspaceProject, serveOptimizedImages, } = await getContext(sourceDir);
|
|
312
|
+
const { browserTarget, baseHref, prerenderTarget, serverTarget, architectHost, workspaceProject, serveOptimizedImages, } = await getContext(sourceDir, configuration);
|
|
265
313
|
const targets = (prerenderTarget ? [prerenderTarget] : [browserTarget, serverTarget].filter((it) => !!it)).map((it) => targetStringFromTarget(it));
|
|
266
314
|
const locales = await localesForTarget(sourceDir, architectHost, browserTarget, workspaceProject);
|
|
267
315
|
return {
|
|
268
316
|
targets,
|
|
317
|
+
baseHref,
|
|
269
318
|
serverTarget,
|
|
270
319
|
locales,
|
|
271
320
|
serveOptimizedImages,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebFrameworks = exports.I18N_ROOT = exports.ALLOWED_SSR_REGIONS = exports.DEFAULT_REGION = exports.VALID_LOCALE_FORMATS = exports.VALID_ENGINES = exports.NODE_VERSION = exports.SHARP_VERSION = exports.FIREBASE_ADMIN_VERSION = exports.FIREBASE_FUNCTIONS_VERSION = exports.FIREBASE_FRAMEWORKS_VERSION = exports.MAILING_LIST_URL = exports.FEATURE_REQUEST_URL = exports.FILE_BUG_URL = exports.DEFAULT_DOCS_URL = exports.SupportLevelWarnings = exports.NPM_COMMAND_TIMEOUT_MILLIES = void 0;
|
|
3
|
+
exports.DEFAULT_SHOULD_USE_DEV_MODE_HANDLE = exports.GET_DEFAULT_BUILD_TARGETS = exports.WebFrameworks = exports.I18N_ROOT = exports.ALLOWED_SSR_REGIONS = exports.DEFAULT_REGION = exports.VALID_LOCALE_FORMATS = exports.VALID_ENGINES = exports.NODE_VERSION = exports.SHARP_VERSION = exports.FIREBASE_ADMIN_VERSION = exports.FIREBASE_FUNCTIONS_VERSION = exports.FIREBASE_FRAMEWORKS_VERSION = exports.MAILING_LIST_URL = exports.FEATURE_REQUEST_URL = exports.FILE_BUG_URL = exports.DEFAULT_DOCS_URL = exports.SupportLevelWarnings = exports.NPM_COMMAND_TIMEOUT_MILLIES = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const clc = require("colorette");
|
|
@@ -21,7 +21,7 @@ exports.FIREBASE_FUNCTIONS_VERSION = "^4.3.0";
|
|
|
21
21
|
exports.FIREBASE_ADMIN_VERSION = "^11.0.1";
|
|
22
22
|
exports.SHARP_VERSION = "^0.32.1";
|
|
23
23
|
exports.NODE_VERSION = parseInt(process.versions.node, 10);
|
|
24
|
-
exports.VALID_ENGINES = { node: [16, 18] };
|
|
24
|
+
exports.VALID_ENGINES = { node: [16, 18, 20] };
|
|
25
25
|
exports.VALID_LOCALE_FORMATS = [/^ALL_[a-z]+$/, /^[a-z]+_ALL$/, /^[a-z]+(_[a-z]+)?$/];
|
|
26
26
|
exports.DEFAULT_REGION = "us-central1";
|
|
27
27
|
exports.ALLOWED_SSR_REGIONS = [
|
|
@@ -43,3 +43,11 @@ exports.WebFrameworks = Object.fromEntries((0, fs_1.readdirSync)(__dirname)
|
|
|
43
43
|
}
|
|
44
44
|
})
|
|
45
45
|
.filter(([, obj]) => obj && obj.name && obj.discover && obj.build && obj.type !== undefined && obj.support));
|
|
46
|
+
function GET_DEFAULT_BUILD_TARGETS() {
|
|
47
|
+
return Promise.resolve(["production", "development"]);
|
|
48
|
+
}
|
|
49
|
+
exports.GET_DEFAULT_BUILD_TARGETS = GET_DEFAULT_BUILD_TARGETS;
|
|
50
|
+
function DEFAULT_SHOULD_USE_DEV_MODE_HANDLE(target) {
|
|
51
|
+
return Promise.resolve(target === "development");
|
|
52
|
+
}
|
|
53
|
+
exports.DEFAULT_SHOULD_USE_DEV_MODE_HANDLE = DEFAULT_SHOULD_USE_DEV_MODE_HANDLE;
|
|
@@ -21,10 +21,10 @@ async function getConfig(root) {
|
|
|
21
21
|
async function discover(dir) {
|
|
22
22
|
if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
|
|
23
23
|
return;
|
|
24
|
-
const { serveDir } = await getConfig(dir);
|
|
25
|
-
if (!
|
|
24
|
+
const { serveDir: publicDirectory } = await getConfig(dir);
|
|
25
|
+
if (!publicDirectory)
|
|
26
26
|
return;
|
|
27
|
-
return { mayWantBackend: true };
|
|
27
|
+
return { mayWantBackend: true, publicDirectory };
|
|
28
28
|
}
|
|
29
29
|
exports.discover = discover;
|
|
30
30
|
async function build(cwd) {
|
|
@@ -88,7 +88,7 @@ async function getBootstrapScript(root, _bootstrapScript = "", _entry) {
|
|
|
88
88
|
async function ɵcodegenFunctionsDirectory(root, dest) {
|
|
89
89
|
const bootstrapScript = await getBootstrapScript(root);
|
|
90
90
|
if (!bootstrapScript)
|
|
91
|
-
|
|
91
|
+
throw new Error("Cloud not find bootstrapScript");
|
|
92
92
|
await (0, promises_1.mkdir)(dest, { recursive: true });
|
|
93
93
|
const { packageJson } = await getConfig(root);
|
|
94
94
|
const packResults = (0, child_process_1.execSync)(`npm pack ${root} --json`, { cwd: dest });
|
|
@@ -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 = {});
|
|
@@ -312,7 +319,7 @@ async function prepareFrameworks(targetNames, context, options, emulators = [])
|
|
|
312
319
|
cwd: functionsDist,
|
|
313
320
|
});
|
|
314
321
|
if (result.status !== 0)
|
|
315
|
-
throw new
|
|
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) {
|
|
@@ -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,33 @@ 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 (purpose === "deploy") {
|
|
187
|
+
return "production";
|
|
188
|
+
}
|
|
189
|
+
else if (process.env.NODE_ENV) {
|
|
190
|
+
switch (process.env.NODE_ENV) {
|
|
191
|
+
case "development":
|
|
192
|
+
return "development";
|
|
193
|
+
case "production":
|
|
194
|
+
case "test":
|
|
195
|
+
return "production";
|
|
196
|
+
default:
|
|
197
|
+
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(", ")}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (purpose === "test") {
|
|
201
|
+
return "production";
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return "development";
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
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
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
rules_version = '2';
|
|
2
|
+
|
|
3
|
+
// Craft rules based on data in your Firestore database
|
|
4
|
+
// allow write: if firestore.get(
|
|
5
|
+
// /databases/(default)/documents/users/$(request.auth.uid)).data.isAdmin;
|
|
2
6
|
service firebase.storage {
|
|
3
7
|
match /b/{bucket}/o {
|
|
4
8
|
match /{allPaths=**} {
|