Skip to content

Commit

Permalink
Merge branch 'master' into jh-emu_binary
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan committed May 30, 2024
2 parents e1ce2a2 + 338f426 commit a7fb756
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 95 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes some cases where Firebase Data Connect deployment fails to pretty-print errors (#7230).
2 changes: 1 addition & 1 deletion firebase-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Change Log
## NEXT

## 0.2.3

Expand Down
7 changes: 3 additions & 4 deletions firebase-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,11 @@
"scripts": {
"vscode:prepublish": "npm run build",
"copyfiles": "cp -r node_modules/@vscode/codicons/dist resources/dist",
"pkg:vsce": "node scripts/swap-pkg.js vsce && vsce package",
"pkg:monospace": "node scripts/swap-pkg.js monospace && vsce package",
"pkg": "vsce package",
"dev": "npm run copyfiles && webpack --config webpack.dev.js",
"dev:extension": "npm run copyfiles && webpack --config webpack.dev.js --config-name extension",
"dev:sidebar": "npm run copyfiles && webpack --config webpack.dev.js --config-name sidebar",
"watch": "node scripts/swap-pkg.js vsce && npm run copyfiles && webpack --config webpack.dev.js --watch",
"watch": "npm run copyfiles && webpack --config webpack.dev.js --watch",
"build": "npm run copyfiles && webpack --config webpack.prod.js --devtool hidden-source-map",
"build:extension": "webpack --config webpack.prod.js --config-name extension",
"build:sidebar": "npm run copyfiles && webpack --config webpack.prod.js --config-name sidebar",
Expand Down Expand Up @@ -262,4 +261,4 @@
"webpack-cli": "^5.0.1",
"webpack-merge": "^5.8.0"
}
}
}
14 changes: 0 additions & 14 deletions firebase-vscode/scripts/swap-pkg.js

This file was deleted.

35 changes: 35 additions & 0 deletions firebase-vscode/src/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { env, TelemetryLogger, TelemetrySender } from "vscode";
import { pluginLogger } from "./logger-wrapper";
import { AnalyticsParams, trackVSCode } from "./track";

export class AnalyticsLogger {
readonly logger: TelemetryLogger;
constructor() {
this.logger = env.createTelemetryLogger(
new GA4TelemetrySender(pluginLogger),
);
}
}

class GA4TelemetrySender implements TelemetrySender {
constructor(readonly pluginLogger) {}

sendEventData(
eventName: string,
data?: Record<string, any> | undefined,
): void {
if (!env.isTelemetryEnabled) {
pluginLogger.warn("Telemetry is not enabled.");
return;
}
if (!data) {
return;
}
trackVSCode(eventName, data as AnalyticsParams);
}

sendErrorData(error: Error, data?: Record<string, any> | undefined): void {
// n/a
// TODO: Sanatize error messages for user data
}
}
8 changes: 4 additions & 4 deletions firebase-vscode/src/data-connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Result } from "../result";
import { runEmulatorIssuesStream } from "./emulator-stream";
import { LanguageClient } from "vscode-languageclient/node";
import { registerTerminalTasks } from "./terminal";

import { AnalyticsLogger } from "../analytics";
class CodeActionsProvider implements vscode.CodeActionProvider {
constructor(
private configs: Signal<
Expand Down Expand Up @@ -136,6 +136,7 @@ export function registerFdc(
broker: ExtensionBrokerImpl,
authService: AuthService,
emulatorController: EmulatorsController,
analyticsLogger: AnalyticsLogger,
): Disposable {
const codeActions = vscode.languages.registerCodeActionsProvider(
[
Expand All @@ -156,9 +157,8 @@ export function registerFdc(

// activate language client/serer
let client: LanguageClient;
const lsOutputChannel: vscode.OutputChannel = vscode.window.createOutputChannel(
"Firebase GraphQL Language Server",
);
const lsOutputChannel: vscode.OutputChannel =
vscode.window.createOutputChannel("Firebase GraphQL Language Server");

// setup new language client on config change
context.subscriptions.push({
Expand Down
5 changes: 3 additions & 2 deletions firebase-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getSettings } from "./utils/settings";
import { registerHosting } from "./hosting";
import { registerFdc } from "./data-connect";
import { AuthService } from "./auth/service";

import { AnalyticsLogger } from "./analytics";
// This method is called when your extension is activated
export async function activate(context: vscode.ExtensionContext) {
const settings = getSettings();
Expand All @@ -27,6 +27,7 @@ export async function activate(context: vscode.ExtensionContext) {
>(new ExtensionBroker());

const authService = new AuthService(broker);
const analyticsLogger = new AnalyticsLogger();

const [emulatorsController, coreDisposable] = await registerCore({
broker,
Expand All @@ -42,6 +43,6 @@ export async function activate(context: vscode.ExtensionContext) {
}),
registerHosting(broker),
authService,
registerFdc(context, broker, authService, emulatorsController)
registerFdc(context, broker, authService, emulatorsController, analyticsLogger)
);
}
47 changes: 47 additions & 0 deletions scripts/publish-vsce.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -e

printusage() {
echo "publish-vsce.sh <version> <cli-version-number>"
echo "Should be run as part of publish.sh."
echo ""
echo ""
echo "Arguments:"
echo " version: 'patch', 'minor', or 'major'."
echo " cli-version-number: the version number of the CLI code that is bundled in this release."
}

VERSION=$1

CLI_VERSION=$2
if [[ $VERSION == "" || $CLI_VERSION == ""]]; then
printusage
exit 1
elif [[ ! ($VERSION == "patch" || $VERSION == "minor" || $VERSION == "major") ]]; then
printusage
exit 1
fi

cd firebase-vscode
echo "Running npm install for VSCode..."
npm install
echo "Ran npm install for VSCode."

echo "Making a $VERSION version of VSCode..."
npm version $VERSION
NEW_VSCODE_VERSION=$(jq -r ".version" package.json)
NEXT_HEADER="## NEXT"
NEW_HEADER="## NEXT \n\n## $NEW_VSCODE_VERSION\n\n- Updated internal firebase-tools dependency to $CLI_VERSION"
sed -i '' -e "s/$NEXT_HEADER/$NEW_HEADER/g" CHANGELOG.md
echo "Made a $VERSION version of VSCode."

echo "Building firebase-vscode .VSIX file"
npm run pkg
echo "Built firebase-vscode .VSIX file."

echo "Uploading VSIX file to GCS..."
VSIX="firebase-vscode-$NEW_VSCODE_VERSION.vsix"
gsutil cp $VSIX gs://firemat-preview-drop/vsix/$VSIX
gsutil cp $VSIX gs://firemat-preview-drop/vsix/firebase-vscode-latest.vsix
echo "Uploaded VSIX file to GCS."
cd ..
27 changes: 14 additions & 13 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
set -e

printusage() {
echo "publish.sh <version>"
echo "publish.sh <version> [vscode-version]"
echo "REPOSITORY_ORG and REPOSITORY_NAME should be set in the environment."
echo "e.g. REPOSITORY_ORG=user, REPOSITORY_NAME=repo"
echo ""
echo "Arguments:"
echo " version: 'patch', 'minor', or 'major'."
echo " vscode-version: Optional. If omitted, defaults to <version>. May be 'patch', 'minor', or 'major'."
}

VERSION=$1
Expand All @@ -19,6 +20,14 @@ elif [[ ! ($VERSION == "patch" || $VERSION == "minor" || $VERSION == "major") ]]
exit 1
fi

VSCODE_VERSION=$2
if [[ $VSCODE_VERSION == "" ]]; then
VSCODE_VERSION=$VERSION
elif [[ ! ($VSCODE_VERSION == "patch" || $VSCODE_VERSION == "minor" || $VSCODE_VERSION == "major") ]]; then
printusage
exit 1
fi

if [[ $REPOSITORY_ORG == "" ]]; then
printusage
exit 1
Expand All @@ -44,12 +53,6 @@ which jq &> /dev/null
trap - ERR
echo "Checked for commands."

echo "Checking for Twitter credentials..."
trap "echo 'Missing Twitter credentials.'; exit 1" ERR
test -f "${WDIR}/scripts/twitter.json"
trap - ERR
echo "Checked for Twitter credentials..."

echo "Checking for logged-in npm user..."
trap "echo 'Please login to npm using \`npm login --registry https://wombat-dressing-room.appspot.com\`'; exit 1" ERR
npm whoami --registry https://wombat-dressing-room.appspot.com
Expand Down Expand Up @@ -87,6 +90,10 @@ npm version $VERSION
NEW_VERSION=$(jq -r ".version" package.json)
echo "Made a $VERSION version."

echo "Publishing a $VSCODE_VERSION version of the VSCode extension..."
./scripts/publish-vscode.sh $VSCODE_VERSION $NEW_VERSION
echo "Published a $VSCODE_VERSION version of the VSCode extension."

echo "Making the release notes..."
RELEASE_NOTES_FILE=$(mktemp)
echo "[DEBUG] ${RELEASE_NOTES_FILE}"
Expand All @@ -112,9 +119,3 @@ echo "Pushed to GitHub."
echo "Publishing release notes..."
hub release create --file "${RELEASE_NOTES_FILE}" "v${NEW_VERSION}"
echo "Published release notes."

echo "Making the tweet..."
npm install --no-save twitter@1.7.1
cp -v "${WDIR}/scripts/twitter.json" "${TEMPDIR}/${REPOSITORY_NAME}/scripts/"
node ./scripts/tweet.js ${NEW_VERSION}
echo "Made the tweet."
51 changes: 0 additions & 51 deletions scripts/tweet.js

This file was deleted.

9 changes: 6 additions & 3 deletions src/dataconnect/graphqlError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { GraphqlError } from "./types";

export function prettify(err: GraphqlError): string {
const message = err.message;
let header = err.extensions.file ?? "";
if (err.locations) {
header += `:${err.locations[0].line}`;
let header = err.extensions?.file ?? "";
if (err.locations && err.locations.length) {
const line = err.locations[0]?.line ?? "";
if (line) {
header += `:${line}`;
}
}
return header.length ? `${header}: ${message}` : message;
}
4 changes: 2 additions & 2 deletions src/dataconnect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ export interface Diff {

export interface GraphqlError {
message: string;
locations: {
locations?: {
line: number;
column: number;
}[];
extensions: {
extensions?: {
file?: string;
[key: string]: any;
};
Expand Down
42 changes: 41 additions & 1 deletion src/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type cliEventNames =
| "function_deploy"
| "codebase_deploy"
| "function_deploy_group";
type GA4Property = "cli" | "emulator";
type GA4Property = "cli" | "emulator" | "vscode";
interface GA4Info {
measurementId: string;
apiSecret: string;
Expand All @@ -41,6 +41,12 @@ export const GA4_PROPERTIES: Record<GA4Property, GA4Info> = {
apiSecret: process.env.FIREBASE_EMULATOR_GA4_API_SECRET || "2V_zBYc4TdeoppzDaIu0zw",
clientIdKey: "emulator-analytics-clientId",
},
// Info for the GA4 property for the VSCode Extension only.
vscode: {
measurementId: process.env.FIREBASE_VSCODE_GA4_MEASUREMENT_ID || "G-FYJ489XM2T",
apiSecret: process.env.FIREBASE_VSCODE_GA4_API_SECRET || "XAEWKHe7RM-ygCK44N52Ww",
clientIdKey: "vscode-analytics-clientId",
},
};
/**
* UA is enabled only if:
Expand Down Expand Up @@ -151,6 +157,36 @@ export async function trackEmulator(eventName: string, params?: AnalyticsParams)
});
}

/**
* Record a vscode-related event for Analytics.
*
* @param eventName the event name in snake_case. (Formal requirement:
* length <= 40, alpha-numeric characters and underscores only
* (*no spaces*), and must start with an alphabetic character)
* @param params custom and standard parameters attached to the event
* @return a Promise fulfilled when the event reaches the server or fails
*
* Note: On performance or latency critical paths, the returned Promise may be
* safely ignored with the statement `void trackVSCode(...)`.
*/
export async function trackVSCode(eventName: string, params?: AnalyticsParams): Promise<void> {
const session = vscodeSession();
if (!session) {
return;
}

const oldTotalEngagementSeconds = session.totalEngagementSeconds;
session.totalEngagementSeconds = process.uptime();
const duration = session.totalEngagementSeconds - oldTotalEngagementSeconds;
return _ga4Track({
session,
apiSecret: GA4_PROPERTIES.vscode.apiSecret,
eventName,
params,
duration,
});
}

async function _ga4Track(args: {
session: AnalyticsSession;
apiSecret: string;
Expand Down Expand Up @@ -269,6 +305,10 @@ export function emulatorSession(): AnalyticsSession | undefined {
return session("emulator");
}

export function vscodeSession(): AnalyticsSession | undefined {
return session("vscode");
}

export function cliSession(): AnalyticsSession | undefined {
return session("cli");
}
Expand Down

0 comments on commit a7fb756

Please sign in to comment.