diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fa4fc6d298..6669dc6f1f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,2 @@ - Updated `cross-env` and `cross-spawn` dependencies to avoid vulnerable versions. (#7979) +- Fixed an issue with the Data Connect emulator where `dataDir` and `--export` were relative to the current directory insead of `firebase.json`. diff --git a/firebase-vscode/CHANGELOG.md b/firebase-vscode/CHANGELOG.md index c26eb3b4706..e0cbeedd9c4 100644 --- a/firebase-vscode/CHANGELOG.md +++ b/firebase-vscode/CHANGELOG.md @@ -1,6 +1,7 @@ ## NEXT - [Added] Added support for emulator import/export. +- [Added] Added `debug` setting to run commands with `--debug` ## 0.12.0 diff --git a/firebase-vscode/package.json b/firebase-vscode/package.json index 8b3d99666c2..1ae236d40b4 100644 --- a/firebase-vscode/package.json +++ b/firebase-vscode/package.json @@ -91,6 +91,11 @@ "type": "boolean", "default": false, "markdownDescription": "%ext.config.emulators.exportOnExit%" + }, + "firebase.debug": { + "type": "boolean", + "default": false, + "markdownDescription": "%ext.config.debug%" } } }, diff --git a/firebase-vscode/package.nls.json b/firebase-vscode/package.nls.json index 209372943ec..b61e3840ba3 100644 --- a/firebase-vscode/package.nls.json +++ b/firebase-vscode/package.nls.json @@ -9,5 +9,5 @@ "ext.config.emulators.importPath": "Path to import emulator data from", "ext.config.emulators.exportPath": "Path to export emulator data to", "ext.config.emulators.exportOnExit": "If true, data will be exported to exportPath when the emulator shuts down" - + "ext.config.debug": "When true, add the --debug flag to any commands run by the extension", } diff --git a/firebase-vscode/src/data-connect/terminal.ts b/firebase-vscode/src/data-connect/terminal.ts index 5bc64d02348..e48147adb97 100644 --- a/firebase-vscode/src/data-connect/terminal.ts +++ b/firebase-vscode/src/data-connect/terminal.ts @@ -17,6 +17,7 @@ export function setTerminalEnvVars(envVar: string, value: string) { } export function runCommand(command: string) { + const settings = getSettings(); const terminalOptions: TerminalOptions = { name: "Data Connect Terminal", env: environmentVariables, @@ -30,6 +31,9 @@ export function runCommand(command: string) { if (currentProjectId.value) { command = `${command} --project ${currentProjectId.value}`; } + if (settings.debug) { + command = `${command} --debug`; + } terminal.sendText(command); } @@ -38,6 +42,7 @@ export function runTerminalTask( command: string, presentationOptions: vscode.TaskPresentationOptions = { focus: true }, ): Promise { + const settings = getSettings(); const type = "firebase-" + Date.now(); return new Promise(async (resolve, reject) => { vscode.tasks.onDidEndTaskProcess(async (e) => { @@ -60,7 +65,7 @@ export function runTerminalTask( vscode.TaskScope.Workspace, taskName, "firebase", - new vscode.ShellExecution(command, executionOptions), + new vscode.ShellExecution(`${command}${settings.debug ? " --debug" : ""}`, executionOptions), ); task.presentationOptions = presentationOptions; await vscode.tasks.executeTask(task); diff --git a/firebase-vscode/src/utils/settings.ts b/firebase-vscode/src/utils/settings.ts index 1ab811cb2c7..a61499725a1 100644 --- a/firebase-vscode/src/utils/settings.ts +++ b/firebase-vscode/src/utils/settings.ts @@ -10,6 +10,7 @@ export interface Settings { readonly importPath?: string; readonly exportPath: string; readonly exportOnExit: boolean; + readonly debug: boolean; } // TODO: Temporary fallback for bashing, this should probably point to the global firebase binary on the system @@ -43,6 +44,7 @@ export function getSettings(): Settings { importPath: config.get("emulators.importPath"), exportPath: config.get("emulators.exportPath", "./exportedData"), exportOnExit: config.get("emulators.exportOnExit", false), + debug: config.get("debug", false), }; } diff --git a/firebase-vscode/webpack.common.js b/firebase-vscode/webpack.common.js index aa3ffbbbe41..60212c2d6e8 100644 --- a/firebase-vscode/webpack.common.js +++ b/firebase-vscode/webpack.common.js @@ -191,19 +191,20 @@ const extensionConfig = { from: "../schema", to: "./schema", }, + // TODO(hlshen): Sanity check if these should be fixed or removed. AFIACT, they exist for functions and hosting deploys, which are not relevant anymore. // Copy uncompiled JS files called at runtime by // firebase-tools/src/parseTriggers.ts - { - from: "*.js", - to: "./", - context: "../src/deploy/functions/runtimes/node", - }, - // Copy cross-env-shell.js used to run predeploy scripts - // to ensure they work in Windows - { - from: "../node_modules/cross-env/dist", - to: "./cross-env/dist", - }, + // { + // from: "*.js", + // to: "./", + // context: "../src/deploy/functions/runtimes/node", + // }, + // // Copy cross-env-shell.js used to run predeploy scripts + // // to ensure they work in Windows + // { + // from: "../node_modules/cross-env/dist", + // to: "./cross-env/dist", + // }, ], }), ], diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index da429c1286d..2b3ce3e9621 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -14637,9 +14637,10 @@ } }, "node_modules/nan": { - "version": "2.17.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz", - "integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==", + "version": "2.22.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.22.0.tgz", + "integrity": "sha512-nbajikzWTMwsW+eSsNm3QwlOs7het9gGJU5dDZzRTQGk03vyBOauxgI4VakDzE0PtsGTmXPsXTbbjVhRwR5mpw==", + "license": "MIT", "optional": true }, "node_modules/nanoid": { @@ -31852,9 +31853,9 @@ } }, "nan": { - "version": "2.17.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz", - "integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==", + "version": "2.22.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.22.0.tgz", + "integrity": "sha512-nbajikzWTMwsW+eSsNm3QwlOs7het9gGJU5dDZzRTQGk03vyBOauxgI4VakDzE0PtsGTmXPsXTbbjVhRwR5mpw==", "optional": true }, "nanoid": { diff --git a/src/emulator/apphosting/serve.ts b/src/emulator/apphosting/serve.ts index 51db30fa0c8..3e31a0dcdf3 100644 --- a/src/emulator/apphosting/serve.ts +++ b/src/emulator/apphosting/serve.ts @@ -12,6 +12,8 @@ import { logger } from "./developmentServer"; import { Emulators } from "../types"; import { getLocalAppHostingConfiguration } from "./config"; import { resolveProjectPath } from "../../projectPath"; +import { EmulatorRegistry } from "../registry"; +import { setEnvVarsForEmulators } from "../env"; interface StartOptions { port?: number; @@ -55,6 +57,7 @@ async function serve( } const environmentVariablesToInject = { + ...getEmulatorEnvs(), ...environmentVariablesAsRecord, PORT: port.toString(), }; @@ -81,3 +84,11 @@ function availablePort(host: string, port: number): Promise { family: isIPv4(host) ? "IPv4" : "IPv6", }); } + +function getEmulatorEnvs(): Record { + const envs: Record = {}; + const emulatorInfos = EmulatorRegistry.listRunningWithInfo(); + setEnvVarsForEmulators(envs, emulatorInfos); + + return envs; +} diff --git a/src/emulator/dataconnectEmulator.ts b/src/emulator/dataconnectEmulator.ts index 2273bbf47be..1905aa2ab0c 100644 --- a/src/emulator/dataconnectEmulator.ts +++ b/src/emulator/dataconnectEmulator.ts @@ -114,9 +114,12 @@ export class DataConnectEmulator implements EmulatorInstance { `FIREBASE_DATACONNECT_POSTGRESQL_STRING is set to ${clc.bold(connStr)} - using that instead of starting a new database`, ); } else if (pgHost && pgPort) { - const dataDirectory = this.args.config.get("emulators.dataconnect.dataDir"); + let dataDirectory = this.args.config.get("emulators.dataconnect.dataDir"); + if (dataDirectory) { + dataDirectory = this.args.config.path(dataDirectory); + } const postgresDumpPath = this.args.importPath - ? path.join(this.args.importPath, "postgres.tar.gz") + ? path.join(this.args.config.path(this.args.importPath), "postgres.tar.gz") : undefined; this.postgresServer = new PostgresServer({ dataDirectory, @@ -205,7 +208,9 @@ export class DataConnectEmulator implements EmulatorInstance { async exportData(exportPath: string): Promise { if (this.postgresServer) { - await this.postgresServer.exportData(path.join(exportPath, "postgres.tar.gz")); + await this.postgresServer.exportData( + path.join(this.args.config.path(exportPath), "postgres.tar.gz"), + ); } else { throw new FirebaseError( "The Data Connect emulator is currently connected to a separate Postgres instance. Export is not supported.",