Skip to content

Commit

Permalink
fix: Add version to embed.js and preview.js (#16182)
Browse files Browse the repository at this point in the history
  • Loading branch information
hariombalhara authored and zomars committed Sep 4, 2024
1 parent e81cc38 commit add80d8
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/embeds/embed-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"embed-web-start": "yarn workspace @calcom/web start",
"__build": "yarn tailwind && vite build && tsc --emitDeclarationOnly --declarationDir dist && cp -r ../../../apps/web/public/embed ./dist/",
"__dev": "yarn tailwind && vite build --mode development",
"build": "rm -rf dist && NEXT_PUBLIC_EMBED_FINGER_PRINT=$(git rev-parse --short HEAD) yarn __build",
"build": "rm -rf dist && NEXT_PUBLIC_EMBED_FINGER_PRINT=$(git rev-parse --short HEAD) NEXT_PUBLIC_EMBED_VERSION=$(node -p 'require(\"./package.json\").version') yarn __build",
"build-preview": "PREVIEW_BUILD=1 yarn __build ",
"vite": "vite",
"tailwind": "yarn tailwindcss -i ./src/styles.css -o ./src/tailwind.generated.css",
Expand Down
2 changes: 2 additions & 0 deletions packages/embeds/embed-core/src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ if (!globalCal || !globalCal.q) {
// TODO: Ideally it should be the version as per package.json and then it can be renamed to version.
// But because it is built on local machine right now, it is much more reliable to have the commit hash.
globalCal.fingerprint = process.env.EMBED_PUBLIC_EMBED_FINGER_PRINT as string;
globalCal.version = process.env.EMBED_PUBLIC_EMBED_VERSION as string;
globalCal.__css = allCss;
document.head.appendChild(document.createElement("style")).innerHTML = css;

Expand Down Expand Up @@ -810,6 +811,7 @@ export interface GlobalCalWithoutNs {
instance?: Cal;
__css?: string;
fingerprint?: string;
version?: string;
__logQueue?: unknown[];
}

Expand Down
1 change: 1 addition & 0 deletions packages/embeds/embed-core/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ if (!bookerUrl || !embedLibUrl) {
})(window, embedLibUrl, "init");
const previewWindow = window;
previewWindow.Cal.fingerprint = process.env.EMBED_PUBLIC_EMBED_FINGER_PRINT as string;
previewWindow.Cal.version = process.env.EMBED_PUBLIC_EMBED_VERSION as string;

previewWindow.Cal("init", {
origin: bookerUrl,
Expand Down
1 change: 1 addition & 0 deletions packages/embeds/embed-core/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = defineConfig((configEnv) => {
plugins: [
EnvironmentPlugin({
EMBED_PUBLIC_EMBED_FINGER_PRINT: embedCoreEnvVars.EMBED_PUBLIC_EMBED_FINGER_PRINT,
EMBED_PUBLIC_EMBED_VERSION: embedCoreEnvVars.EMBED_PUBLIC_EMBED_VERSION,
EMBED_PUBLIC_VERCEL_URL: embedCoreEnvVars.EMBED_PUBLIC_VERCEL_URL,
EMBED_PUBLIC_WEBAPP_URL: embedCoreEnvVars.EMBED_PUBLIC_WEBAPP_URL,
}),
Expand Down
3 changes: 3 additions & 0 deletions packages/embeds/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ process.env.EMBED_PUBLIC_WEBAPP_URL = process.env.NEXT_PUBLIC_WEBAPP_URL;
process.env.EMBED_PUBLIC_EMBED_LIB_URL = process.env.NEXT_PUBLIC_EMBED_LIB_URL;
// eslint-disable-next-line turbo/no-undeclared-env-vars
process.env.EMBED_PUBLIC_EMBED_FINGER_PRINT = process.env.NEXT_PUBLIC_EMBED_FINGER_PRINT;
// eslint-disable-next-line turbo/no-undeclared-env-vars
process.env.EMBED_PUBLIC_EMBED_VERSION = process.env.NEXT_PUBLIC_EMBED_VERSION;

// Problem: typeof process.env.EMBED_PUBLIC_EMBED_LIB_URL is "undefined"(truthy) if process.env.NEXT_PUBLIC_EMBED_LIB_URL is undefined(falsy)
// This is probably because environment variables are always string, so this weird automatic conversion to string happens
Expand All @@ -30,6 +32,7 @@ const viteBaseConfig = {
export default viteBaseConfig;
export const embedCoreEnvVars = {
EMBED_PUBLIC_EMBED_FINGER_PRINT: process.env.EMBED_PUBLIC_EMBED_FINGER_PRINT ?? "",
EMBED_PUBLIC_EMBED_VERSION: process.env.EMBED_PUBLIC_EMBED_VERSION ?? "",
EMBED_PUBLIC_VERCEL_URL: process.env.EMBED_PUBLIC_VERCEL_URL ?? "http://localhost:3000",
EMBED_PUBLIC_WEBAPP_URL:
process.env.EMBED_PUBLIC_WEBAPP_URL ??
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"@calcom/embed-core#build": {
"cache": false,
"outputs": ["../../../apps/web/public/embed/**"],
"env": ["EMBED_PUBLIC_VERCEL_URL", "EMBED_PUBLIC_WEBAPP_URL", "EMBED_PUBLIC_EMBED_FINGER_PRINT"]
"env": ["EMBED_PUBLIC_VERCEL_URL", "EMBED_PUBLIC_WEBAPP_URL", "EMBED_PUBLIC_EMBED_FINGER_PRINT", "EMBED_PUBLIC_EMBED_VERSION"]
},
"embed-tests-update-snapshots:ci": {
"cache": false,
Expand Down Expand Up @@ -418,6 +418,7 @@
"CLOUDFLARE_VERCEL_CNAME",
"CLOUDFLARE_DNS",
"EMBED_PUBLIC_EMBED_FINGER_PRINT",
"EMBED_PUBLIC_EMBED_VERSION",
"EMBED_PUBLIC_WEBAPP_URL",
"EMBED_PUBLIC_VERCEL_URL",
"NEXT_PUBLIC_ENABLE_PROFILE_SWITCHER",
Expand Down

0 comments on commit add80d8

Please sign in to comment.