Skip to content

Commit

Permalink
Merge branch 'master' into jh-import-export-vsce
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan authored Jan 9, 2025
2 parents 7688793 + 2b3c729 commit 5bd2ab3
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions firebase-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

- [Added] Added support for emulator import/export.
- [Added] Added `debug` setting to run commands with `--debug`

## 0.12.0

Expand Down
5 changes: 5 additions & 0 deletions firebase-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
"type": "boolean",
"default": false,
"markdownDescription": "%ext.config.emulators.exportOnExit%"
},
"firebase.debug": {
"type": "boolean",
"default": false,
"markdownDescription": "%ext.config.debug%"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion firebase-vscode/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
7 changes: 6 additions & 1 deletion firebase-vscode/src/data-connect/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

Expand All @@ -38,6 +42,7 @@ export function runTerminalTask(
command: string,
presentationOptions: vscode.TaskPresentationOptions = { focus: true },
): Promise<string> {
const settings = getSettings();
const type = "firebase-" + Date.now();
return new Promise(async (resolve, reject) => {
vscode.tasks.onDidEndTaskProcess(async (e) => {
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions firebase-vscode/src/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,6 +44,7 @@ export function getSettings(): Settings {
importPath: config.get<string>("emulators.importPath"),
exportPath: config.get<string>("emulators.exportPath", "./exportedData"),
exportOnExit: config.get<boolean>("emulators.exportOnExit", false),
debug: config.get<boolean>("debug", false),
};
}

Expand Down
23 changes: 12 additions & 11 deletions firebase-vscode/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
// },
],
}),
],
Expand Down
13 changes: 7 additions & 6 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/emulator/apphosting/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +57,7 @@ async function serve(
}

const environmentVariablesToInject = {
...getEmulatorEnvs(),
...environmentVariablesAsRecord,
PORT: port.toString(),
};
Expand All @@ -81,3 +84,11 @@ function availablePort(host: string, port: number): Promise<boolean> {
family: isIPv4(host) ? "IPv4" : "IPv6",
});
}

function getEmulatorEnvs(): Record<string, string> {
const envs: Record<string, string> = {};
const emulatorInfos = EmulatorRegistry.listRunningWithInfo();
setEnvVarsForEmulators(envs, emulatorInfos);

return envs;
}
11 changes: 8 additions & 3 deletions src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -205,7 +208,9 @@ export class DataConnectEmulator implements EmulatorInstance {

async exportData(exportPath: string): Promise<void> {
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.",
Expand Down

0 comments on commit 5bd2ab3

Please sign in to comment.