firebase-tools-with-isolate 13.26.0 → 13.27.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/apphosting/config.js +86 -1
- package/lib/apphosting/secrets/index.js +1 -39
- package/lib/apphosting/yaml.js +3 -0
- package/lib/commands/apphosting-config-export.js +3 -26
- package/lib/commands/index.js +2 -4
- package/lib/deploy/functions/prepare.js +23 -20
- package/lib/deploy/functions/prepareFunctionsUpload.js +15 -16
- package/lib/deploy/functions/release/fabricator.js +1 -1
- package/lib/emulator/apphosting/developmentServer.js +32 -0
- package/lib/emulator/apphosting/index.js +4 -3
- package/lib/emulator/apphosting/serve.js +7 -7
- package/lib/emulator/commandUtils.js +2 -1
- package/lib/emulator/controller.js +27 -18
- package/lib/emulator/dataconnect/pgliteServer.js +51 -18
- package/lib/emulator/dataconnectEmulator.js +26 -2
- package/lib/emulator/hub.js +16 -0
- package/lib/emulator/hubExport.js +23 -0
- package/lib/emulator/initEmulators.js +48 -0
- package/lib/emulator/types.js +2 -2
- package/lib/gcp/cloudfunctionsv2.js +1 -0
- package/lib/init/features/emulators.js +11 -0
- package/lib/utils.js +16 -1
- package/package.json +1 -1
- package/schema/firebase-config.json +3 -0
- package/lib/emulator/apphosting/utils.js +0 -18
package/lib/apphosting/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadConfigForEnvironment = exports.maybeAddSecretToYaml = exports.upsertEnv = exports.findEnv = exports.store = exports.load = exports.listAppHostingFilesInPath = exports.discoverBackendRoot = exports.APPHOSTING_YAML_FILE_REGEX = exports.APPHOSTING_LOCAL_YAML_FILE = exports.APPHOSTING_BASE_YAML_FILE = void 0;
|
|
3
|
+
exports.loadConfigToExportSecrets = exports.loadConfigForEnvironment = exports.exportConfig = exports.maybeAddSecretToYaml = exports.upsertEnv = exports.findEnv = exports.store = exports.load = exports.listAppHostingFilesInPath = exports.discoverBackendRoot = exports.APPHOSTING_YAML_FILE_REGEX = exports.APPHOSTING_LOCAL_YAML_FILE = exports.APPHOSTING_BASE_YAML_FILE = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const yaml = require("yaml");
|
|
@@ -8,9 +8,17 @@ const fs = require("../fsutils");
|
|
|
8
8
|
const prompt = require("../prompt");
|
|
9
9
|
const dialogs = require("./secrets/dialogs");
|
|
10
10
|
const yaml_1 = require("./yaml");
|
|
11
|
+
const error_1 = require("../error");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const secrets_1 = require("./secrets");
|
|
14
|
+
const logger_1 = require("../logger");
|
|
15
|
+
const utils_2 = require("../utils");
|
|
16
|
+
const projects_1 = require("../management/projects");
|
|
11
17
|
exports.APPHOSTING_BASE_YAML_FILE = "apphosting.yaml";
|
|
12
18
|
exports.APPHOSTING_LOCAL_YAML_FILE = "apphosting.local.yaml";
|
|
13
19
|
exports.APPHOSTING_YAML_FILE_REGEX = /^apphosting(\.[a-z0-9_]+)?\.yaml$/;
|
|
20
|
+
const SECRET_CONFIG = "Secret";
|
|
21
|
+
const EXPORTABLE_CONFIG = [SECRET_CONFIG];
|
|
14
22
|
function discoverBackendRoot(cwd) {
|
|
15
23
|
let dir = cwd;
|
|
16
24
|
while (!fs.fileExistsSync((0, path_1.resolve)(dir, exports.APPHOSTING_BASE_YAML_FILE))) {
|
|
@@ -108,6 +116,49 @@ async function maybeAddSecretToYaml(secretName) {
|
|
|
108
116
|
dynamicDispatch.store(path, projectYaml);
|
|
109
117
|
}
|
|
110
118
|
exports.maybeAddSecretToYaml = maybeAddSecretToYaml;
|
|
119
|
+
async function exportConfig(cwd, projectRoot, backendRoot, projectId, userGivenConfigFile) {
|
|
120
|
+
const choices = await prompt.prompt({}, [
|
|
121
|
+
{
|
|
122
|
+
type: "checkbox",
|
|
123
|
+
name: "configurations",
|
|
124
|
+
message: "What configs would you like to export?",
|
|
125
|
+
choices: EXPORTABLE_CONFIG,
|
|
126
|
+
},
|
|
127
|
+
]);
|
|
128
|
+
if (!choices.configurations.includes(SECRET_CONFIG)) {
|
|
129
|
+
logger_1.logger.info("No configs selected to export");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!projectId) {
|
|
133
|
+
const project = await (0, projects_1.getOrPromptProject)({});
|
|
134
|
+
projectId = project.projectId;
|
|
135
|
+
}
|
|
136
|
+
let localAppHostingConfig = yaml_1.AppHostingYamlConfig.empty();
|
|
137
|
+
const localAppHostingConfigPath = (0, path_1.resolve)(backendRoot, exports.APPHOSTING_LOCAL_YAML_FILE);
|
|
138
|
+
if (fs.fileExistsSync(localAppHostingConfigPath)) {
|
|
139
|
+
localAppHostingConfig = await yaml_1.AppHostingYamlConfig.loadFromFile(localAppHostingConfigPath);
|
|
140
|
+
}
|
|
141
|
+
const configToExport = await loadConfigToExportSecrets(cwd, userGivenConfigFile);
|
|
142
|
+
const secretsToExport = configToExport.secrets;
|
|
143
|
+
if (!secretsToExport) {
|
|
144
|
+
logger_1.logger.info("No secrets found to export in the chosen App Hosting config files");
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const secretMaterial = await (0, secrets_1.fetchSecrets)(projectId, secretsToExport);
|
|
148
|
+
for (const [key, value] of secretMaterial) {
|
|
149
|
+
localAppHostingConfig.addEnvironmentVariable({
|
|
150
|
+
variable: key,
|
|
151
|
+
value: value,
|
|
152
|
+
availability: ["RUNTIME"],
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
localAppHostingConfig.clearSecrets();
|
|
156
|
+
localAppHostingConfig.upsertFile(localAppHostingConfigPath);
|
|
157
|
+
logger_1.logger.info(`Wrote secrets as environment variables to ${exports.APPHOSTING_LOCAL_YAML_FILE}.`);
|
|
158
|
+
(0, utils_2.updateOrCreateGitignore)(projectRoot, [exports.APPHOSTING_LOCAL_YAML_FILE]);
|
|
159
|
+
logger_1.logger.info(`${exports.APPHOSTING_LOCAL_YAML_FILE} has been automatically added to your .gitignore.`);
|
|
160
|
+
}
|
|
161
|
+
exports.exportConfig = exportConfig;
|
|
111
162
|
async function loadConfigForEnvironment(envYamlPath, baseYamlPath) {
|
|
112
163
|
const envYamlConfig = await yaml_1.AppHostingYamlConfig.loadFromFile(envYamlPath);
|
|
113
164
|
if (baseYamlPath) {
|
|
@@ -118,3 +169,37 @@ async function loadConfigForEnvironment(envYamlPath, baseYamlPath) {
|
|
|
118
169
|
return envYamlConfig;
|
|
119
170
|
}
|
|
120
171
|
exports.loadConfigForEnvironment = loadConfigForEnvironment;
|
|
172
|
+
async function loadConfigToExportSecrets(cwd, userGivenConfigFile) {
|
|
173
|
+
if (userGivenConfigFile && !exports.APPHOSTING_YAML_FILE_REGEX.test(userGivenConfigFile)) {
|
|
174
|
+
throw new error_1.FirebaseError("Invalid apphosting yaml config file provided. File must be in format: 'apphosting.yaml' or 'apphosting.<environment>.yaml'");
|
|
175
|
+
}
|
|
176
|
+
const allConfigs = getValidConfigs(cwd);
|
|
177
|
+
let userGivenConfigFilePath;
|
|
178
|
+
if (userGivenConfigFile) {
|
|
179
|
+
if (!allConfigs.has(userGivenConfigFile)) {
|
|
180
|
+
throw new error_1.FirebaseError(`The provided app hosting config file "${userGivenConfigFile}" does not exist`);
|
|
181
|
+
}
|
|
182
|
+
userGivenConfigFilePath = allConfigs.get(userGivenConfigFile);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
userGivenConfigFilePath = await (0, utils_1.promptForAppHostingYaml)(allConfigs, "Which environment would you like to export secrets from Secret Manager for?");
|
|
186
|
+
}
|
|
187
|
+
if (userGivenConfigFile === exports.APPHOSTING_BASE_YAML_FILE) {
|
|
188
|
+
return yaml_1.AppHostingYamlConfig.loadFromFile(allConfigs.get(exports.APPHOSTING_BASE_YAML_FILE));
|
|
189
|
+
}
|
|
190
|
+
const baseFilePath = allConfigs.get(exports.APPHOSTING_BASE_YAML_FILE);
|
|
191
|
+
return await loadConfigForEnvironment(userGivenConfigFilePath, baseFilePath);
|
|
192
|
+
}
|
|
193
|
+
exports.loadConfigToExportSecrets = loadConfigToExportSecrets;
|
|
194
|
+
function getValidConfigs(cwd) {
|
|
195
|
+
const appHostingConfigPaths = listAppHostingFilesInPath(cwd).filter((path) => !path.endsWith(exports.APPHOSTING_LOCAL_YAML_FILE));
|
|
196
|
+
if (appHostingConfigPaths.length === 0) {
|
|
197
|
+
throw new error_1.FirebaseError("No apphosting.*.yaml configs found");
|
|
198
|
+
}
|
|
199
|
+
const fileNameToPathMap = new Map();
|
|
200
|
+
for (const path of appHostingConfigPaths) {
|
|
201
|
+
const fileName = (0, path_1.basename)(path);
|
|
202
|
+
fileNameToPathMap.set(fileName, path);
|
|
203
|
+
}
|
|
204
|
+
return fileNameToPathMap;
|
|
205
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSecretNameParts = exports.
|
|
3
|
+
exports.getSecretNameParts = exports.fetchSecrets = exports.upsertSecret = exports.grantSecretAccess = exports.serviceAccountsForBackend = exports.toMulti = void 0;
|
|
4
4
|
const error_1 = require("../../error");
|
|
5
5
|
const gcsm = require("../../gcp/secretManager");
|
|
6
6
|
const gcb = require("../../gcp/cloudbuild");
|
|
@@ -10,10 +10,6 @@ const secretManager_1 = require("../../gcp/secretManager");
|
|
|
10
10
|
const secretManager_2 = require("../../gcp/secretManager");
|
|
11
11
|
const utils = require("../../utils");
|
|
12
12
|
const prompt = require("../../prompt");
|
|
13
|
-
const path_1 = require("path");
|
|
14
|
-
const config_1 = require("../config");
|
|
15
|
-
const utils_1 = require("../utils");
|
|
16
|
-
const yaml_1 = require("../yaml");
|
|
17
13
|
function toMulti(accounts) {
|
|
18
14
|
const m = {
|
|
19
15
|
buildServiceAccounts: [accounts.buildServiceAccount],
|
|
@@ -124,40 +120,6 @@ async function fetchSecrets(projectId, secrets) {
|
|
|
124
120
|
return secretsKeyValuePairs;
|
|
125
121
|
}
|
|
126
122
|
exports.fetchSecrets = fetchSecrets;
|
|
127
|
-
async function loadConfigToExport(cwd, userGivenConfigFile) {
|
|
128
|
-
if (userGivenConfigFile && !config_1.APPHOSTING_YAML_FILE_REGEX.test(userGivenConfigFile)) {
|
|
129
|
-
throw new error_1.FirebaseError("Invalid apphosting yaml config file provided. File must be in format: 'apphosting.yaml' or 'apphosting.<environment>.yaml'");
|
|
130
|
-
}
|
|
131
|
-
const allConfigs = getValidConfigs(cwd);
|
|
132
|
-
let userGivenConfigFilePath;
|
|
133
|
-
if (userGivenConfigFile) {
|
|
134
|
-
if (!allConfigs.has(userGivenConfigFile)) {
|
|
135
|
-
throw new error_1.FirebaseError(`The provided app hosting config file "${userGivenConfigFile}" does not exist`);
|
|
136
|
-
}
|
|
137
|
-
userGivenConfigFilePath = allConfigs.get(userGivenConfigFile);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
userGivenConfigFilePath = await (0, utils_1.promptForAppHostingYaml)(allConfigs, "Which environment would you like to export secrets from Secret Manager for?");
|
|
141
|
-
}
|
|
142
|
-
if (userGivenConfigFile === config_1.APPHOSTING_BASE_YAML_FILE) {
|
|
143
|
-
return yaml_1.AppHostingYamlConfig.loadFromFile(allConfigs.get(config_1.APPHOSTING_BASE_YAML_FILE));
|
|
144
|
-
}
|
|
145
|
-
const baseFilePath = allConfigs.get(config_1.APPHOSTING_BASE_YAML_FILE);
|
|
146
|
-
return await (0, config_1.loadConfigForEnvironment)(userGivenConfigFilePath, baseFilePath);
|
|
147
|
-
}
|
|
148
|
-
exports.loadConfigToExport = loadConfigToExport;
|
|
149
|
-
function getValidConfigs(cwd) {
|
|
150
|
-
const appHostingConfigPaths = (0, config_1.listAppHostingFilesInPath)(cwd).filter((path) => !path.endsWith(config_1.APPHOSTING_LOCAL_YAML_FILE));
|
|
151
|
-
if (appHostingConfigPaths.length === 0) {
|
|
152
|
-
throw new error_1.FirebaseError("No apphosting.*.yaml configs found");
|
|
153
|
-
}
|
|
154
|
-
const fileNameToPathMap = new Map();
|
|
155
|
-
for (const path of appHostingConfigPaths) {
|
|
156
|
-
const fileName = (0, path_1.basename)(path);
|
|
157
|
-
fileNameToPathMap.set(fileName, path);
|
|
158
|
-
}
|
|
159
|
-
return fileNameToPathMap;
|
|
160
|
-
}
|
|
161
123
|
function getSecretNameParts(secret) {
|
|
162
124
|
let [name, version] = secret.split("@");
|
|
163
125
|
if (!version) {
|
package/lib/apphosting/yaml.js
CHANGED
|
@@ -42,6 +42,9 @@ class AppHostingYamlConfig {
|
|
|
42
42
|
addSecret(secret) {
|
|
43
43
|
this._secrets.set(secret.variable, secret);
|
|
44
44
|
}
|
|
45
|
+
clearSecrets() {
|
|
46
|
+
this._secrets.clear();
|
|
47
|
+
}
|
|
45
48
|
merge(other) {
|
|
46
49
|
for (const [key, value] of other._environmentVariables) {
|
|
47
50
|
this._environmentVariables.set(key, value);
|
|
@@ -2,17 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.command = void 0;
|
|
4
4
|
const command_1 = require("../command");
|
|
5
|
-
const logger_1 = require("../logger");
|
|
6
5
|
const projectUtils_1 = require("../projectUtils");
|
|
7
6
|
const requireAuth_1 = require("../requireAuth");
|
|
8
7
|
const secretManager = require("../gcp/secretManager");
|
|
9
8
|
const requirePermissions_1 = require("../requirePermissions");
|
|
10
9
|
const config_1 = require("../apphosting/config");
|
|
11
|
-
const secrets_1 = require("../apphosting/secrets");
|
|
12
|
-
const path_1 = require("path");
|
|
13
|
-
const fs = require("../fsutils");
|
|
14
|
-
const yaml_1 = require("../apphosting/yaml");
|
|
15
10
|
const error_1 = require("../error");
|
|
11
|
+
const detectProjectRoot_1 = require("../detectProjectRoot");
|
|
16
12
|
exports.command = new command_1.Command("apphosting:config:export")
|
|
17
13
|
.description("Export App Hosting configurations such as secrets into an apphosting.local.yaml file")
|
|
18
14
|
.option("-s, --secrets <apphosting.yaml or apphosting.<environment>.yaml file to export secrets from>", "This command combines the base apphosting.yaml with the specified environment-specific file (e.g., apphosting.staging.yaml). If keys conflict, the environment-specific file takes precedence.")
|
|
@@ -23,29 +19,10 @@ exports.command = new command_1.Command("apphosting:config:export")
|
|
|
23
19
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
24
20
|
const environmentConfigFile = options.secrets;
|
|
25
21
|
const cwd = process.cwd();
|
|
26
|
-
let localAppHostingConfig = yaml_1.AppHostingYamlConfig.empty();
|
|
27
22
|
const backendRoot = (0, config_1.discoverBackendRoot)(cwd);
|
|
28
23
|
if (!backendRoot) {
|
|
29
24
|
throw new error_1.FirebaseError("Missing apphosting.yaml: This command requires an apphosting.yaml configuration file. Please run 'firebase init apphosting' and try again.");
|
|
30
25
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
localAppHostingConfig = await yaml_1.AppHostingYamlConfig.loadFromFile(localAppHostingConfigPath);
|
|
34
|
-
}
|
|
35
|
-
const configToExport = await (0, secrets_1.loadConfigToExport)(cwd, environmentConfigFile);
|
|
36
|
-
const secretsToExport = configToExport.secrets;
|
|
37
|
-
if (!secretsToExport) {
|
|
38
|
-
logger_1.logger.warn("No secrets found to export in the chosen App Hosting config files");
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const secretMaterial = await (0, secrets_1.fetchSecrets)(projectId, secretsToExport);
|
|
42
|
-
for (const [key, value] of secretMaterial) {
|
|
43
|
-
localAppHostingConfig.addEnvironmentVariable({
|
|
44
|
-
variable: key,
|
|
45
|
-
value: value,
|
|
46
|
-
availability: ["RUNTIME"],
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
localAppHostingConfig.upsertFile(localAppHostingConfigPath);
|
|
50
|
-
logger_1.logger.info(`Wrote secrets as environment variables to ${config_1.APPHOSTING_LOCAL_YAML_FILE}.`);
|
|
26
|
+
const projectRoot = (0, detectProjectRoot_1.detectProjectRoot)({}) ?? backendRoot;
|
|
27
|
+
await (0, config_1.exportConfig)(cwd, projectRoot, backendRoot, projectId, environmentConfigFile);
|
|
51
28
|
});
|
package/lib/commands/index.js
CHANGED
|
@@ -172,6 +172,8 @@ function load(client) {
|
|
|
172
172
|
client.apphosting.secrets.grantaccess = loadCommand("apphosting-secrets-grantaccess");
|
|
173
173
|
client.apphosting.secrets.describe = loadCommand("apphosting-secrets-describe");
|
|
174
174
|
client.apphosting.secrets.access = loadCommand("apphosting-secrets-access");
|
|
175
|
+
client.apphosting.config = {};
|
|
176
|
+
client.apphosting.config.export = loadCommand("apphosting-config-export");
|
|
175
177
|
if (experiments.isEnabled("internaltesting")) {
|
|
176
178
|
client.apphosting.builds = {};
|
|
177
179
|
client.apphosting.builds.get = loadCommand("apphosting-builds-get");
|
|
@@ -182,10 +184,6 @@ function load(client) {
|
|
|
182
184
|
client.apphosting.rollouts.create = loadCommand("apphosting-rollouts-create");
|
|
183
185
|
client.apphosting.rollouts.list = loadCommand("apphosting-rollouts-list");
|
|
184
186
|
}
|
|
185
|
-
if (experiments.isEnabled("emulatorapphosting")) {
|
|
186
|
-
client.apphosting.config = {};
|
|
187
|
-
client.apphosting.config.export = loadCommand("apphosting-config-export");
|
|
188
|
-
}
|
|
189
187
|
}
|
|
190
188
|
client.login = loadCommand("login");
|
|
191
189
|
client.login.add = loadCommand("login-add");
|
|
@@ -2,32 +2,32 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadCodebases = exports.resolveCpuAndConcurrency = exports.inferBlockingDetails = exports.updateEndpointTargetedStatus = exports.inferDetailsFromExisting = exports.prepare = exports.EVENTARC_SOURCE_ENV = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
|
-
const
|
|
6
|
-
const build = require("./build");
|
|
5
|
+
const api_1 = require("../../api");
|
|
7
6
|
const ensureApiEnabled = require("../../ensureApiEnabled");
|
|
8
|
-
const
|
|
7
|
+
const error_1 = require("../../error");
|
|
8
|
+
const functional_1 = require("../../functional");
|
|
9
9
|
const functionsEnv = require("../../functions/env");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
10
|
+
const v1_1 = require("../../functions/events/v1");
|
|
11
|
+
const projectConfig_1 = require("../../functions/projectConfig");
|
|
12
|
+
const functionsConfig = require("../../functionsConfig");
|
|
13
|
+
const serviceusage_1 = require("../../gcp/serviceusage");
|
|
14
|
+
const logger_1 = require("../../logger");
|
|
15
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
16
|
+
const utils_1 = require("../../utils");
|
|
17
|
+
const prepare_1 = require("../extensions/prepare");
|
|
18
|
+
const backend = require("./backend");
|
|
19
|
+
const backend_1 = require("./backend");
|
|
20
|
+
const build = require("./build");
|
|
21
|
+
const applyHash_1 = require("./cache/applyHash");
|
|
22
|
+
const checkIam_1 = require("./checkIam");
|
|
13
23
|
const ensure = require("./ensure");
|
|
14
|
-
const api_1 = require("../../api");
|
|
15
24
|
const functionsDeployHelper_1 = require("./functionsDeployHelper");
|
|
16
|
-
const utils_1 = require("../../utils");
|
|
17
25
|
const prepareFunctionsUpload_1 = require("./prepareFunctionsUpload");
|
|
18
26
|
const prompts_1 = require("./prompts");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
27
|
+
const runtimes = require("./runtimes");
|
|
28
|
+
const supported = require("./runtimes/supported");
|
|
21
29
|
const triggerRegionHelper_1 = require("./triggerRegionHelper");
|
|
22
|
-
const
|
|
23
|
-
const error_1 = require("../../error");
|
|
24
|
-
const projectConfig_1 = require("../../functions/projectConfig");
|
|
25
|
-
const v1_1 = require("../../functions/events/v1");
|
|
26
|
-
const serviceusage_1 = require("../../gcp/serviceusage");
|
|
27
|
-
const applyHash_1 = require("./cache/applyHash");
|
|
28
|
-
const backend_1 = require("./backend");
|
|
29
|
-
const functional_1 = require("../../functional");
|
|
30
|
-
const prepare_1 = require("../extensions/prepare");
|
|
30
|
+
const validate = require("./validate");
|
|
31
31
|
exports.EVENTARC_SOURCE_ENV = "EVENTARC_CLOUD_EVENT_SOURCE";
|
|
32
32
|
async function prepare(context, options, payload) {
|
|
33
33
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
@@ -137,11 +137,14 @@ async function prepare(context, options, payload) {
|
|
|
137
137
|
for (const [codebase, wantBackend] of Object.entries(wantBackends)) {
|
|
138
138
|
const config = (0, projectConfig_1.configForCodebase)(context.config, codebase);
|
|
139
139
|
const sourceDirName = config.source;
|
|
140
|
-
|
|
140
|
+
let sourceDir = options.config.path(sourceDirName);
|
|
141
141
|
const source = {};
|
|
142
142
|
if (backend.someEndpoint(wantBackend, () => true)) {
|
|
143
143
|
(0, utils_1.logLabeledBullet)("functions", `preparing ${clc.bold(sourceDirName)} directory for uploading...`);
|
|
144
144
|
}
|
|
145
|
+
if (config.isolate === true) {
|
|
146
|
+
sourceDir = await (0, prepareFunctionsUpload_1.runIsolate)(config);
|
|
147
|
+
}
|
|
145
148
|
if (backend.someEndpoint(wantBackend, (e) => e.platform === "gcfv2")) {
|
|
146
149
|
const packagedSource = await (0, prepareFunctionsUpload_1.prepareFunctionsUpload)(sourceDir, config);
|
|
147
150
|
source.functionsSourceV2 = packagedSource?.pathToSource;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertToSortedKeyValueArray = exports.prepareFunctionsUpload = exports.getFunctionsConfig = void 0;
|
|
3
|
+
exports.convertToSortedKeyValueArray = exports.runIsolate = exports.prepareFunctionsUpload = exports.getFunctionsConfig = void 0;
|
|
4
4
|
const archiver = require("archiver");
|
|
5
5
|
const clc = require("colorette");
|
|
6
6
|
const filesize = require("filesize");
|
|
@@ -92,24 +92,23 @@ async function packageSource(sourceDir, config, runtimeConfig) {
|
|
|
92
92
|
return { pathToSource: tmpFile, hash };
|
|
93
93
|
}
|
|
94
94
|
async function prepareFunctionsUpload(sourceDir, config, runtimeConfig) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
throw err;
|
|
106
|
-
}
|
|
95
|
+
return packageSource(sourceDir, config, runtimeConfig);
|
|
96
|
+
}
|
|
97
|
+
exports.prepareFunctionsUpload = prepareFunctionsUpload;
|
|
98
|
+
async function runIsolate(_config) {
|
|
99
|
+
try {
|
|
100
|
+
utils.logLabeledBullet("functions", `Isolate the source`);
|
|
101
|
+
const { isolate } = (await (0, dynamicImport_1.dynamicImport)("isolate-package"));
|
|
102
|
+
const isolateDir = await isolate();
|
|
103
|
+
utils.logLabeledBullet("functions", `Finished isolation at ${clc.bold(isolateDir)}`);
|
|
104
|
+
return isolateDir;
|
|
107
105
|
}
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
catch (err) {
|
|
107
|
+
utils.logLabeledBullet("functions", `Isolation failed: ${err.message}`, "error");
|
|
108
|
+
throw err;
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
|
-
exports.
|
|
111
|
+
exports.runIsolate = runIsolate;
|
|
113
112
|
function convertToSortedKeyValueArray(config) {
|
|
114
113
|
if (typeof config !== "object" || config === null)
|
|
115
114
|
return config;
|
|
@@ -307,7 +307,7 @@ class Fabricator {
|
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
309
|
}
|
|
310
|
-
endpoint.uri = resultFunction.
|
|
310
|
+
endpoint.uri = resultFunction.url;
|
|
311
311
|
const serviceName = resultFunction.serviceConfig?.service;
|
|
312
312
|
endpoint.runServiceId = utils.last(serviceName?.split("/"));
|
|
313
313
|
if (!serviceName) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectStartCommand = exports.detectPackageManager = exports.logger = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const emulatorLogger_1 = require("../emulatorLogger");
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
const error_1 = require("../../error");
|
|
9
|
+
exports.logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.APPHOSTING);
|
|
10
|
+
async function detectPackageManager(rootdir) {
|
|
11
|
+
if (await (0, fs_extra_1.pathExists)((0, path_1.join)(rootdir, "pnpm-lock.yaml"))) {
|
|
12
|
+
return "pnpm";
|
|
13
|
+
}
|
|
14
|
+
if (await (0, fs_extra_1.pathExists)((0, path_1.join)(rootdir, "yarn.lock"))) {
|
|
15
|
+
return "yarn";
|
|
16
|
+
}
|
|
17
|
+
if (await (0, fs_extra_1.pathExists)((0, path_1.join)(rootdir, "package-lock.json"))) {
|
|
18
|
+
return "npm";
|
|
19
|
+
}
|
|
20
|
+
throw new error_1.FirebaseError("Unsupported package manager");
|
|
21
|
+
}
|
|
22
|
+
exports.detectPackageManager = detectPackageManager;
|
|
23
|
+
async function detectStartCommand(rootDir) {
|
|
24
|
+
try {
|
|
25
|
+
const packageManager = await detectPackageManager(rootDir);
|
|
26
|
+
return `${packageManager} run dev`;
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw new error_1.FirebaseError("Failed to auto-detect your project's start command. Consider manually setting the start command by setting `firebase.json#emulators.apphosting.startCommandOverride`");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.detectStartCommand = detectStartCommand;
|
|
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AppHostingEmulator = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const serve_1 = require("./serve");
|
|
6
|
-
const
|
|
6
|
+
const developmentServer_1 = require("./developmentServer");
|
|
7
7
|
class AppHostingEmulator {
|
|
8
8
|
constructor(args) {
|
|
9
9
|
this.args = args;
|
|
10
10
|
}
|
|
11
11
|
async start() {
|
|
12
12
|
const { hostname, port } = await (0, serve_1.start)({
|
|
13
|
+
port: this.args.port,
|
|
13
14
|
startCommand: this.args.startCommandOverride,
|
|
14
15
|
rootDirectory: this.args.rootDirectory,
|
|
15
16
|
});
|
|
@@ -17,11 +18,11 @@ class AppHostingEmulator {
|
|
|
17
18
|
this.args.options.port = port;
|
|
18
19
|
}
|
|
19
20
|
connect() {
|
|
20
|
-
|
|
21
|
+
developmentServer_1.logger.logLabeled("INFO", types_1.Emulators.APPHOSTING, "connecting apphosting emulator");
|
|
21
22
|
return Promise.resolve();
|
|
22
23
|
}
|
|
23
24
|
stop() {
|
|
24
|
-
|
|
25
|
+
developmentServer_1.logger.logLabeled("INFO", types_1.Emulators.APPHOSTING, "stopping apphosting emulator");
|
|
25
26
|
return Promise.resolve();
|
|
26
27
|
}
|
|
27
28
|
getInfo() {
|
|
@@ -3,16 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.start = void 0;
|
|
4
4
|
const net_1 = require("net");
|
|
5
5
|
const portUtils_1 = require("../portUtils");
|
|
6
|
-
const
|
|
6
|
+
const developmentServer_1 = require("./developmentServer");
|
|
7
7
|
const constants_1 = require("../constants");
|
|
8
8
|
const spawn_1 = require("../../init/spawn");
|
|
9
|
-
const
|
|
9
|
+
const developmentServer_2 = require("./developmentServer");
|
|
10
10
|
const types_1 = require("../types");
|
|
11
11
|
const config_1 = require("./config");
|
|
12
12
|
const projectPath_1 = require("../../projectPath");
|
|
13
13
|
async function start(options) {
|
|
14
14
|
const hostname = constants_1.DEFAULT_HOST;
|
|
15
|
-
let port = constants_1.DEFAULT_PORTS.apphosting;
|
|
15
|
+
let port = options?.port ?? constants_1.DEFAULT_PORTS.apphosting;
|
|
16
16
|
while (!(await availablePort(hostname, port))) {
|
|
17
17
|
port += 1;
|
|
18
18
|
}
|
|
@@ -33,13 +33,13 @@ async function serve(port, startCommand, backendRelativeDir) {
|
|
|
33
33
|
PORT: port.toString(),
|
|
34
34
|
};
|
|
35
35
|
if (startCommand) {
|
|
36
|
-
|
|
36
|
+
developmentServer_2.logger.logLabeled("BULLET", types_1.Emulators.APPHOSTING, `running custom start command: '${startCommand}'`);
|
|
37
37
|
await (0, spawn_1.spawnWithCommandString)(startCommand, backendRoot, environmentVariablesToInject);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
await (0, spawn_1.
|
|
40
|
+
const detectedStartCommand = await (0, developmentServer_1.detectStartCommand)(backendRoot);
|
|
41
|
+
developmentServer_2.logger.logLabeled("BULLET", types_1.Emulators.APPHOSTING, `starting app with: '${detectedStartCommand}'`);
|
|
42
|
+
await (0, spawn_1.spawnWithCommandString)(detectedStartCommand, backendRoot, environmentVariablesToInject);
|
|
43
43
|
}
|
|
44
44
|
function availablePort(host, port) {
|
|
45
45
|
return (0, portUtils_1.checkListenable)({
|
|
@@ -301,8 +301,9 @@ async function emulatorExec(script, options) {
|
|
|
301
301
|
exitCode = await runScript(script, extraEnv);
|
|
302
302
|
await controller.onExit(options);
|
|
303
303
|
}
|
|
304
|
-
catch {
|
|
304
|
+
catch (err) {
|
|
305
305
|
await (0, webhook_1.sendVSCodeMessage)({ message: webhook_1.VSCODE_MESSAGE.EMULATORS_START_ERRORED });
|
|
306
|
+
throw err;
|
|
306
307
|
}
|
|
307
308
|
finally {
|
|
308
309
|
await controller.cleanShutdown();
|
|
@@ -58,7 +58,7 @@ async function exportOnExit(options) {
|
|
|
58
58
|
await exportEmulatorData(exportOnExitDir, options, "exit");
|
|
59
59
|
}
|
|
60
60
|
catch (e) {
|
|
61
|
-
utils.logWarning(e);
|
|
61
|
+
utils.logWarning(`${e}`);
|
|
62
62
|
utils.logWarning(`Automatic export to "${exportOnExitDir}" failed, going to exit now...`);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -566,19 +566,30 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
566
566
|
else if (config.length > 1) {
|
|
567
567
|
logger_1.logger.warn(`TODO: Add support for multiple services in the Data Connect emulator. Currently emulating first service ${config[0].source}`);
|
|
568
568
|
}
|
|
569
|
-
const
|
|
570
|
-
const dataConnectEmulator = new dataconnectEmulator_1.DataConnectEmulator({
|
|
569
|
+
const args = {
|
|
571
570
|
listen: listenForEmulator.dataconnect,
|
|
572
571
|
projectId,
|
|
573
572
|
auto_download: true,
|
|
574
|
-
configDir,
|
|
573
|
+
configDir: config[0].source,
|
|
575
574
|
rc: options.rc,
|
|
576
575
|
config: options.config,
|
|
577
576
|
autoconnectToPostgres: true,
|
|
578
577
|
postgresListen: listenForEmulator["dataconnect.postgres"],
|
|
579
578
|
enable_output_generated_sdk: true,
|
|
580
579
|
enable_output_schema_extensions: true,
|
|
581
|
-
}
|
|
580
|
+
};
|
|
581
|
+
if (exportMetadata.dataconnect) {
|
|
582
|
+
utils.assertIsString(options.import);
|
|
583
|
+
const importDirAbsPath = path.resolve(options.import);
|
|
584
|
+
const exportMetadataFilePath = path.resolve(importDirAbsPath, exportMetadata.dataconnect.path);
|
|
585
|
+
emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.DATACONNECT).logLabeled("BULLET", "dataconnect", `Importing data from ${exportMetadataFilePath}`);
|
|
586
|
+
args.importPath = exportMetadataFilePath;
|
|
587
|
+
void (0, track_1.trackEmulator)("emulator_import", {
|
|
588
|
+
initiated_by: "start",
|
|
589
|
+
emulator_name: types_1.Emulators.DATACONNECT,
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
const dataConnectEmulator = new dataconnectEmulator_1.DataConnectEmulator(args);
|
|
582
593
|
await startEmulator(dataConnectEmulator);
|
|
583
594
|
}
|
|
584
595
|
if (listenForEmulator.storage) {
|
|
@@ -606,19 +617,17 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
606
617
|
});
|
|
607
618
|
await startEmulator(hostingEmulator);
|
|
608
619
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
await startEmulator(apphostingEmulator);
|
|
621
|
-
}
|
|
620
|
+
const apphostingConfig = options.config.src.emulators?.[types_1.Emulators.APPHOSTING];
|
|
621
|
+
if (listenForEmulator.apphosting) {
|
|
622
|
+
const apphostingAddr = legacyGetFirstAddr(types_1.Emulators.APPHOSTING);
|
|
623
|
+
const apphostingEmulator = new apphosting_1.AppHostingEmulator({
|
|
624
|
+
host: apphostingAddr.host,
|
|
625
|
+
port: apphostingAddr.port,
|
|
626
|
+
startCommandOverride: apphostingConfig?.startCommandOverride,
|
|
627
|
+
rootDirectory: apphostingConfig?.rootDirectory,
|
|
628
|
+
options,
|
|
629
|
+
});
|
|
630
|
+
await startEmulator(apphostingEmulator);
|
|
622
631
|
}
|
|
623
632
|
if (listenForEmulator.logging) {
|
|
624
633
|
const loggingAddr = legacyGetFirstAddr(types_1.Emulators.LOGGING);
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PGliteExtendedQueryPatch = exports.PostgresServer = void 0;
|
|
3
|
+
exports.PGliteExtendedQueryPatch = exports.PostgresServer = exports.TRUNCATE_TABLES_SQL = void 0;
|
|
4
4
|
const pglite_1 = require("@electric-sql/pglite");
|
|
5
5
|
const { dynamicImport } = require(true && "../../dynamicImport");
|
|
6
6
|
const net = require("node:net");
|
|
7
|
+
const fs = require("fs");
|
|
7
8
|
const index_1 = require("./pg-gateway/index");
|
|
8
9
|
const node_1 = require("./pg-gateway/platforms/node");
|
|
9
10
|
const logger_1 = require("../../logger");
|
|
11
|
+
exports.TRUNCATE_TABLES_SQL = `
|
|
12
|
+
DO $do$
|
|
13
|
+
BEGIN
|
|
14
|
+
EXECUTE
|
|
15
|
+
(SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE'
|
|
16
|
+
FROM pg_class
|
|
17
|
+
WHERE relkind = 'r'
|
|
18
|
+
AND relnamespace = 'public'::regnamespace
|
|
19
|
+
);
|
|
20
|
+
END
|
|
21
|
+
$do$;`;
|
|
10
22
|
class PostgresServer {
|
|
11
23
|
async createPGServer(host = "127.0.0.1", port) {
|
|
12
|
-
const
|
|
13
|
-
await db.waitReady;
|
|
24
|
+
const getDb = this.getDb.bind(this);
|
|
14
25
|
const server = net.createServer(async (socket) => {
|
|
15
26
|
const connection = await (0, node_1.fromNodeSocket)(socket, {
|
|
16
27
|
serverVersion: "16.3 (PGlite 0.2.0)",
|
|
@@ -19,6 +30,7 @@ class PostgresServer {
|
|
|
19
30
|
if (!isAuthenticated) {
|
|
20
31
|
return;
|
|
21
32
|
}
|
|
33
|
+
const db = await getDb();
|
|
22
34
|
const result = await db.execProtocolRaw(data);
|
|
23
35
|
return extendedQueryPatch.filterResponse(data, result);
|
|
24
36
|
},
|
|
@@ -36,29 +48,50 @@ class PostgresServer {
|
|
|
36
48
|
resolve();
|
|
37
49
|
});
|
|
38
50
|
});
|
|
39
|
-
await db.waitReady;
|
|
40
51
|
await listeningPromise;
|
|
41
52
|
return server;
|
|
42
53
|
}
|
|
43
54
|
async getDb() {
|
|
44
|
-
if (this.db) {
|
|
45
|
-
|
|
55
|
+
if (!this.db) {
|
|
56
|
+
const vector = (await dynamicImport("@electric-sql/pglite/vector")).vector;
|
|
57
|
+
const uuidOssp = (await dynamicImport("@electric-sql/pglite/contrib/uuid_ossp")).uuid_ossp;
|
|
58
|
+
const pgliteArgs = {
|
|
59
|
+
username: this.username,
|
|
60
|
+
database: this.database,
|
|
61
|
+
debug: 0,
|
|
62
|
+
extensions: {
|
|
63
|
+
vector,
|
|
64
|
+
uuidOssp,
|
|
65
|
+
},
|
|
66
|
+
dataDir: this.dataDirectory,
|
|
67
|
+
};
|
|
68
|
+
if (this.importPath) {
|
|
69
|
+
logger_1.logger.debug(`Importing from ${this.importPath}`);
|
|
70
|
+
const rf = fs.readFileSync(this.importPath);
|
|
71
|
+
const file = new File([rf], this.importPath);
|
|
72
|
+
pgliteArgs.loadDataDir = file;
|
|
73
|
+
}
|
|
74
|
+
this.db = await pglite_1.PGlite.create(pgliteArgs);
|
|
75
|
+
await this.db.waitReady;
|
|
46
76
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
return this.db;
|
|
78
|
+
}
|
|
79
|
+
async clearDb() {
|
|
80
|
+
const db = await this.getDb();
|
|
81
|
+
await db.query(exports.TRUNCATE_TABLES_SQL);
|
|
82
|
+
}
|
|
83
|
+
async exportData(exportPath) {
|
|
84
|
+
const db = await this.getDb();
|
|
85
|
+
const dump = await db.dumpDataDir();
|
|
86
|
+
const arrayBuff = await dump.arrayBuffer();
|
|
87
|
+
fs.writeFileSync(exportPath, new Uint8Array(arrayBuff));
|
|
58
88
|
}
|
|
59
|
-
constructor(database, username) {
|
|
89
|
+
constructor(database, username, dataDirectory, importPath) {
|
|
90
|
+
this.db = undefined;
|
|
60
91
|
this.username = username;
|
|
61
92
|
this.database = database;
|
|
93
|
+
this.dataDirectory = dataDirectory;
|
|
94
|
+
this.importPath = importPath;
|
|
62
95
|
}
|
|
63
96
|
}
|
|
64
97
|
exports.PostgresServer = PostgresServer;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DataConnectEmulatorClient = exports.DataConnectEmulator = exports.dataConnectEmulatorEvents = void 0;
|
|
4
4
|
const childProcess = require("child_process");
|
|
5
|
+
const pg = require("pg");
|
|
5
6
|
const events_1 = require("events");
|
|
6
7
|
const clc = require("colorette");
|
|
8
|
+
const path = require("path");
|
|
7
9
|
const api_1 = require("../api");
|
|
8
10
|
const constants_1 = require("./constants");
|
|
9
11
|
const downloadableEmulators_1 = require("./downloadableEmulators");
|
|
@@ -62,8 +64,12 @@ class DataConnectEmulator {
|
|
|
62
64
|
this.logger.logLabeled("INFO", "dataconnect", `FIREBASE_DATACONNECT_POSTGRESQL_STRING is set to ${clc.bold(connStr)} - using that instead of starting a new database`);
|
|
63
65
|
}
|
|
64
66
|
else if (pgHost && pgPort) {
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
+
const dataDirectory = this.args.config.get("emulators.dataconnect.dataDir");
|
|
68
|
+
const postgresDumpPath = this.args.importPath
|
|
69
|
+
? path.join(this.args.importPath, "postgres.tar.gz")
|
|
70
|
+
: undefined;
|
|
71
|
+
this.postgresServer = new pgliteServer_1.PostgresServer(dbId, "postgres", dataDirectory, postgresDumpPath);
|
|
72
|
+
const server = await this.postgresServer.createPGServer(pgHost, pgPort);
|
|
67
73
|
const connectableHost = (0, utils_1.connectableHostname)(pgHost);
|
|
68
74
|
connStr = `postgres://${connectableHost}:${pgPort}/${dbId}?sslmode=disable`;
|
|
69
75
|
server.on("error", (err) => {
|
|
@@ -109,6 +115,24 @@ class DataConnectEmulator {
|
|
|
109
115
|
getName() {
|
|
110
116
|
return types_1.Emulators.DATACONNECT;
|
|
111
117
|
}
|
|
118
|
+
async clearData() {
|
|
119
|
+
if (this.postgresServer) {
|
|
120
|
+
await this.postgresServer.clearDb();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const conn = new pg.Client((0, api_1.dataConnectLocalConnString)());
|
|
124
|
+
await conn.query(pgliteServer_1.TRUNCATE_TABLES_SQL);
|
|
125
|
+
await conn.end();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async exportData(exportPath) {
|
|
129
|
+
if (this.postgresServer) {
|
|
130
|
+
await this.postgresServer.exportData(path.join(exportPath, "postgres.tar.gz"));
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
throw new error_1.FirebaseError("The Data Connect emulator is currently connected to a separate Postgres instance. Export is not supported.");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
112
136
|
static async generate(args) {
|
|
113
137
|
const commandInfo = await (0, downloadableEmulators_1.downloadIfNecessary)(types_1.Emulators.DATACONNECT);
|
|
114
138
|
const cmd = [
|
package/lib/emulator/hub.js
CHANGED
|
@@ -112,6 +112,21 @@ class EmulatorHub extends ExpressBasedEmulator_1.ExpressBasedEmulator {
|
|
|
112
112
|
await emu.reloadTriggers();
|
|
113
113
|
res.status(200).json({ enabled: true });
|
|
114
114
|
});
|
|
115
|
+
app.post(EmulatorHub.PATH_CLEAR_DATA_CONNECT, async (req, res) => {
|
|
116
|
+
if (req.headers.origin) {
|
|
117
|
+
res.status(403).json({
|
|
118
|
+
message: `Clear Data Connect cannot be triggered by external callers.`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
utils.logLabeledBullet("emulators", `Clearing data from Data Connect data sources.`);
|
|
122
|
+
const instance = registry_1.EmulatorRegistry.get(types_1.Emulators.DATACONNECT);
|
|
123
|
+
if (!instance) {
|
|
124
|
+
res.status(400).json({ error: "The Data Connect emulator is not running." });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
await instance.clearData();
|
|
128
|
+
res.status(200).send("Data cleared");
|
|
129
|
+
});
|
|
115
130
|
return app;
|
|
116
131
|
}
|
|
117
132
|
async stop() {
|
|
@@ -176,3 +191,4 @@ EmulatorHub.PATH_EXPORT = "/_admin/export";
|
|
|
176
191
|
EmulatorHub.PATH_DISABLE_FUNCTIONS = "/functions/disableBackgroundTriggers";
|
|
177
192
|
EmulatorHub.PATH_ENABLE_FUNCTIONS = "/functions/enableBackgroundTriggers";
|
|
178
193
|
EmulatorHub.PATH_EMULATORS = "/emulators";
|
|
194
|
+
EmulatorHub.PATH_CLEAR_DATA_CONNECT = "/dataconnect/clearData";
|
|
@@ -71,6 +71,13 @@ class HubExport {
|
|
|
71
71
|
};
|
|
72
72
|
await this.exportStorage(metadata);
|
|
73
73
|
}
|
|
74
|
+
if (shouldExport(types_1.Emulators.DATACONNECT)) {
|
|
75
|
+
metadata.dataconnect = {
|
|
76
|
+
version: hub_1.EmulatorHub.CLI_VERSION,
|
|
77
|
+
path: "dataconnect_export",
|
|
78
|
+
};
|
|
79
|
+
await this.exportDataConnect(metadata);
|
|
80
|
+
}
|
|
74
81
|
if (!fs.existsSync(this.exportPath)) {
|
|
75
82
|
fs.mkdirSync(this.exportPath);
|
|
76
83
|
}
|
|
@@ -197,6 +204,22 @@ class HubExport {
|
|
|
197
204
|
throw new error_1.FirebaseError(`Failed to export storage: ${await res.response.text()}`);
|
|
198
205
|
}
|
|
199
206
|
}
|
|
207
|
+
async exportDataConnect(metadata) {
|
|
208
|
+
void (0, track_1.trackEmulator)("emulator_export", {
|
|
209
|
+
initiated_by: this.options.initiatedBy,
|
|
210
|
+
emulator_name: types_1.Emulators.DATACONNECT,
|
|
211
|
+
});
|
|
212
|
+
const instance = registry_1.EmulatorRegistry.get(types_1.Emulators.DATACONNECT);
|
|
213
|
+
if (!instance) {
|
|
214
|
+
throw new error_1.FirebaseError("Unable to export Data Connect emulator data: the Data Connect emulator is not running.");
|
|
215
|
+
}
|
|
216
|
+
const dataconnectExportPath = path.join(this.tmpDir, metadata.dataconnect.path);
|
|
217
|
+
if (fs.existsSync(dataconnectExportPath)) {
|
|
218
|
+
fse.removeSync(dataconnectExportPath);
|
|
219
|
+
}
|
|
220
|
+
fs.mkdirSync(dataconnectExportPath);
|
|
221
|
+
await instance.exportData(dataconnectExportPath);
|
|
222
|
+
}
|
|
200
223
|
}
|
|
201
224
|
exports.HubExport = HubExport;
|
|
202
225
|
HubExport.METADATA_FILE_NAME = "firebase-export-metadata.json";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdditionalInitFns = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const prompt_1 = require("../prompt");
|
|
6
|
+
const developmentServer_1 = require("./apphosting/developmentServer");
|
|
7
|
+
const emulatorLogger_1 = require("./emulatorLogger");
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
const config_1 = require("../apphosting/config");
|
|
10
|
+
const detectProjectRoot_1 = require("../detectProjectRoot");
|
|
11
|
+
exports.AdditionalInitFns = {
|
|
12
|
+
[types_1.Emulators.APPHOSTING]: async () => {
|
|
13
|
+
const cwd = process.cwd();
|
|
14
|
+
const additionalConfigs = new Map();
|
|
15
|
+
const logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.APPHOSTING);
|
|
16
|
+
logger.logLabeled("INFO", "Initializing Emulator");
|
|
17
|
+
const backendRelativeDir = await (0, prompt_1.promptOnce)({
|
|
18
|
+
name: "rootDir",
|
|
19
|
+
type: "input",
|
|
20
|
+
default: "./",
|
|
21
|
+
message: "Specify your app's root directory relative to your repository",
|
|
22
|
+
});
|
|
23
|
+
additionalConfigs.set("rootDirectory", backendRelativeDir);
|
|
24
|
+
const backendRoot = (0, path_1.join)(cwd, backendRelativeDir);
|
|
25
|
+
try {
|
|
26
|
+
const startCommand = await (0, developmentServer_1.detectStartCommand)(backendRoot);
|
|
27
|
+
additionalConfigs.set("startCommandOverride", startCommand);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
logger.log("WARN", "Failed to auto-detect your project's start command. Consider manually setting the start command by setting `firebase.json#emulators.apphosting.startCommandOverride`");
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const projectRoot = (0, detectProjectRoot_1.detectProjectRoot)({}) ?? backendRoot;
|
|
34
|
+
await (0, config_1.exportConfig)(cwd, projectRoot, backendRoot);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
logger.log("WARN", "failed to export app hosting configs");
|
|
38
|
+
}
|
|
39
|
+
return mapToObject(additionalConfigs);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
function mapToObject(map) {
|
|
43
|
+
const newObject = {};
|
|
44
|
+
for (const [key, value] of map) {
|
|
45
|
+
newObject[key] = value;
|
|
46
|
+
}
|
|
47
|
+
return newObject;
|
|
48
|
+
}
|
package/lib/emulator/types.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Severity = exports.EmulatorLog = exports.FunctionsExecutionMode = exports.isEmulator = exports.isDownloadableEmulator = exports.ALL_EMULATORS = exports.EMULATORS_SUPPORTED_BY_USE_EMULATOR = exports.EMULATORS_SUPPORTED_BY_UI = exports.EMULATORS_SUPPORTED_BY_FUNCTIONS = exports.ALL_SERVICE_EMULATORS = exports.IMPORT_EXPORT_EMULATORS = exports.DOWNLOADABLE_EMULATORS = exports.Emulators = void 0;
|
|
4
|
-
const experiments = require("../experiments");
|
|
5
4
|
var Emulators;
|
|
6
5
|
(function (Emulators) {
|
|
7
6
|
Emulators["AUTH"] = "auth";
|
|
@@ -33,9 +32,10 @@ exports.IMPORT_EXPORT_EMULATORS = [
|
|
|
33
32
|
Emulators.DATABASE,
|
|
34
33
|
Emulators.AUTH,
|
|
35
34
|
Emulators.STORAGE,
|
|
35
|
+
Emulators.DATACONNECT,
|
|
36
36
|
];
|
|
37
37
|
exports.ALL_SERVICE_EMULATORS = [
|
|
38
|
-
|
|
38
|
+
Emulators.APPHOSTING,
|
|
39
39
|
Emulators.AUTH,
|
|
40
40
|
Emulators.FUNCTIONS,
|
|
41
41
|
Emulators.FIRESTORE,
|
|
@@ -409,6 +409,7 @@ function endpointFromFunction(gcfFunction) {
|
|
|
409
409
|
endpoint.runServiceId = utils.last(serviceName.split("/"));
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
+
proto.renameIfPresent(endpoint, gcfFunction, "uri", "url");
|
|
412
413
|
endpoint.codebase = gcfFunction.labels?.[constants_1.CODEBASE_LABEL] || projectConfig.DEFAULT_CODEBASE;
|
|
413
414
|
if (gcfFunction.labels?.[constants_1.HASH_LABEL]) {
|
|
414
415
|
endpoint.hash = gcfFunction.labels[constants_1.HASH_LABEL];
|
|
@@ -7,6 +7,7 @@ const prompt_1 = require("../../prompt");
|
|
|
7
7
|
const types_1 = require("../../emulator/types");
|
|
8
8
|
const constants_1 = require("../../emulator/constants");
|
|
9
9
|
const downloadableEmulators_1 = require("../../emulator/downloadableEmulators");
|
|
10
|
+
const initEmulators_1 = require("../../emulator/initEmulators");
|
|
10
11
|
async function doSetup(setup, config) {
|
|
11
12
|
const choices = types_1.ALL_SERVICE_EMULATORS.map((e) => {
|
|
12
13
|
return {
|
|
@@ -45,6 +46,16 @@ async function doSetup(setup, config) {
|
|
|
45
46
|
},
|
|
46
47
|
]);
|
|
47
48
|
}
|
|
49
|
+
const additionalInitFn = initEmulators_1.AdditionalInitFns[selected];
|
|
50
|
+
if (additionalInitFn) {
|
|
51
|
+
const additionalOptions = await additionalInitFn();
|
|
52
|
+
if (additionalOptions) {
|
|
53
|
+
setup.config.emulators[selected] = {
|
|
54
|
+
...setup.config.emulators[selected],
|
|
55
|
+
...additionalOptions,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
48
59
|
}
|
|
49
60
|
if (selections.emulators.length) {
|
|
50
61
|
const uiDesc = constants_1.Constants.description(types_1.Emulators.UI);
|
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.openInBrowser = exports.connectableHostname = exports.randomInt = exports.debounce = exports.last = exports.cloneDeep = exports.groupBy = exports.assertIsStringOrUndefined = exports.assertIsNumber = exports.assertIsString = exports.thirtyDaysFromNow = exports.isRunningInWSL = exports.isCloudEnvironment = exports.datetimeString = exports.createDestroyer = exports.sleep = exports.promiseWithSpinner = exports.setupLoggers = exports.tryParse = exports.tryStringify = exports.promiseProps = exports.withTimeout = exports.promiseWhile = exports.promiseAllSettled = exports.getFunctionsEventProvider = exports.endpoint = exports.makeActiveProject = exports.streamToString = exports.stringToStream = exports.explainStdin = exports.allSettled = exports.reject = exports.logLabeledError = exports.logLabeledWarning = exports.logWarning = exports.logLabeledBullet = exports.logBullet = exports.logLabeledSuccess = exports.logSuccess = exports.addSubdomain = exports.addDatabaseNamespace = exports.getDatabaseViewDataUrl = exports.getDatabaseUrl = exports.envOverride = exports.setVSCodeEnvVars = exports.getInheritedOption = exports.consoleUrl = exports.vscodeEnvVars = exports.envOverrides = exports.IS_WINDOWS = void 0;
|
|
4
|
-
exports.readSecretValue = exports.generateId = exports.wrappedSafeLoad = exports.readFileFromDirectory = exports.getHostnameFromUrl = exports.openInBrowserPopup = void 0;
|
|
4
|
+
exports.updateOrCreateGitignore = exports.readSecretValue = exports.generateId = exports.wrappedSafeLoad = exports.readFileFromDirectory = exports.getHostnameFromUrl = exports.openInBrowserPopup = void 0;
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
6
|
const tty = require("tty");
|
|
7
7
|
const path = require("node:path");
|
|
@@ -597,3 +597,18 @@ function readSecretValue(prompt, dataFile) {
|
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
599
|
exports.readSecretValue = readSecretValue;
|
|
600
|
+
function updateOrCreateGitignore(dirPath, entries) {
|
|
601
|
+
const gitignorePath = path.join(dirPath, ".gitignore");
|
|
602
|
+
if (!fs.existsSync(gitignorePath)) {
|
|
603
|
+
fs.writeFileSync(gitignorePath, entries.join("\n"));
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
let content = fs.readFileSync(gitignorePath, "utf-8");
|
|
607
|
+
for (const entry of entries) {
|
|
608
|
+
if (!content.includes(entry)) {
|
|
609
|
+
content += `\n${entry}\n`;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
fs.writeFileSync(gitignorePath, content);
|
|
613
|
+
}
|
|
614
|
+
exports.updateOrCreateGitignore = updateOrCreateGitignore;
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.discoverPackageManager = exports.logger = void 0;
|
|
4
|
-
const fs_extra_1 = require("fs-extra");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const emulatorLogger_1 = require("../emulatorLogger");
|
|
7
|
-
const types_1 = require("../types");
|
|
8
|
-
exports.logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.APPHOSTING);
|
|
9
|
-
async function discoverPackageManager(rootdir) {
|
|
10
|
-
if (await (0, fs_extra_1.pathExists)((0, path_1.join)(rootdir, "pnpm-lock.yaml"))) {
|
|
11
|
-
return "pnpm";
|
|
12
|
-
}
|
|
13
|
-
if (await (0, fs_extra_1.pathExists)((0, path_1.join)(rootdir, "yarn.lock"))) {
|
|
14
|
-
return "yarn";
|
|
15
|
-
}
|
|
16
|
-
return "npm";
|
|
17
|
-
}
|
|
18
|
-
exports.discoverPackageManager = discoverPackageManager;
|