From ff24bdd32a5bfb7a266a7e2b4350a35de365b796 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 3 Aug 2025 09:05:21 +0200 Subject: [PATCH 1/3] feat: gzip no html for backwards compatibility --- .../assets/deploy/deploy.execute.services.ts | 28 ++++++++--- src/services/deploy.services.ts | 49 ++++++++++++++----- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/services/assets/deploy/deploy.execute.services.ts b/src/services/assets/deploy/deploy.execute.services.ts index 73abedfc..ea038a52 100644 --- a/src/services/assets/deploy/deploy.execute.services.ts +++ b/src/services/assets/deploy/deploy.execute.services.ts @@ -15,6 +15,7 @@ import type {SatelliteParametersWithId} from '../../../types/satellite'; import {assertConfigAndLoadSatelliteContext} from '../../../utils/satellite.utils'; import {assertSatelliteMemorySize} from './deploy.assert.services'; import {listAssets} from './deploy.list.services'; +import type {SatelliteConfig} from '@junobuild/config'; export interface DeployFnParams { deploy: DeployParams; @@ -26,29 +27,33 @@ export type UploadFileFnParamsWithProposal = UploadFileFnParams & {proposalId: b export const executeDeployWithProposal = async ({ deployFn, - uploadFileFn + uploadFileFn, + options }: { - args?: string[]; deployFn: (params: DeployFnParams) => Promise; uploadFileFn: (params: UploadFileFnParamsWithProposal) => Promise; + options: {deprecatedGzip?: string} }): Promise => { return await executeDeploy({ deployFn, - uploadFileFn + uploadFileFn, + options }); }; export const executeDeployImmediate = async ({ deployFn, - uploadFileFn + uploadFileFn, + options }: { - args?: string[]; deployFn: (params: DeployFnParams) => Promise; uploadFileFn: (params: UploadFileFnParams) => Promise; + options: {deprecatedGzip?: string} }): Promise => { return await executeDeploy({ deployFn, - uploadFileFn + uploadFileFn, + options }); }; @@ -57,16 +62,23 @@ const executeDeploy = async < R extends DeployResult | DeployResultWithProposal >({ deployFn, - uploadFileFn + uploadFileFn, + options }: { deployFn: (params: DeployFnParams<(params: P) => Promise>) => Promise; uploadFileFn: (params: P & {satellite: SatelliteParametersWithId}) => Promise; + options: {deprecatedGzip?: string} }): Promise => { const assertMemory = async () => { await assertSatelliteMemorySize(); }; - const {satellite, satelliteConfig} = await assertConfigAndLoadSatelliteContext(); + const {satellite, satelliteConfig: satelliteConfigRead} = await assertConfigAndLoadSatelliteContext(); + + const satelliteConfig: SatelliteConfig = { + ...satelliteConfigRead, + gzip: satelliteConfigRead?.gzip ?? options.deprecatedGzip + } const listExistingAssets = async ({startAfter}: {startAfter?: string}): Promise => await listAssets({ diff --git a/src/services/deploy.services.ts b/src/services/deploy.services.ts index 668937c4..daaf8c23 100644 --- a/src/services/deploy.services.ts +++ b/src/services/deploy.services.ts @@ -22,11 +22,24 @@ import {clearProposalStagedAssets} from './changes/changes.clear.services'; import {getSatelliteVersion} from './version.services'; export const deploy = async (args?: string[]) => { + // TODO: Remove fetching the version. We use it for backwards compatibility reasons. + const result = await getSatelliteVersion(); + + if (result.result === 'error') { + return; + } + + // TODO: There was an issue in Satellite that prevented gzipping HTML files. + // This was fixed in version v0.1.1. However, for backward compatibility, we + // fall back to not gzipping HTML files in earlier versions. While gzipping HTML + // wouldn't harm usage, it might prevent crawlers from properly fetching content. + const deprecatedGzip = compare(result.version, '0.1.0') < 0 ? '**/*.+(css|js|mjs)' : undefined; + const clearOption = hasArgs({args, options: ['--clear']}); const immediate = hasArgs({args, options: ['-i', '--immediate']}); if (immediate) { - await deployImmediate({clearOption}); + await deployImmediate({clearOption, deprecatedGzip}); return; } @@ -34,24 +47,26 @@ export const deploy = async (args?: string[]) => { // Without falling back to `deploy --immediate`, we can't roll out GitHub Actions support // without requiring developers to either upgrade their Satellites or add the `--immediate` flag in CI. // To ease the release, we temporarily check the version. - const result = await getSatelliteVersion(); - - if (result.result === 'error') { - return; - } - if (compare(result.version, '0.1.0') < 0) { console.log( `${yellow('[Warn]')} Your Satellite is outdated. Please upgrade to take full advantage of the new deployment flow.` ); - await deployImmediate({clearOption}); + await deployImmediate({clearOption, deprecatedGzip}); return; } - await deployWithProposal({args, clearOption}); + await deployWithProposal({args, clearOption, deprecatedGzip}); }; -const deployWithProposal = async ({args, clearOption}: {args?: string[]; clearOption: boolean}) => { +const deployWithProposal = async ({ + args, + clearOption, + deprecatedGzip +}: { + args?: string[]; + clearOption: boolean; + deprecatedGzip: string | undefined; +}) => { const noCommit = hasArgs({args, options: ['--no-apply']}); const deployFn = async ({ @@ -104,7 +119,8 @@ const deployWithProposal = async ({args, clearOption}: {args?: string[]; clearOp const result = await executeDeployWithProposal({ deployFn, - uploadFileFn + uploadFileFn, + options: {deprecatedGzip} }); if (result.result !== 'deployed') { @@ -119,7 +135,13 @@ const deployWithProposal = async ({args, clearOption}: {args?: string[]; clearOp }); }; -const deployImmediate = async ({clearOption}: {clearOption: boolean}) => { +const deployImmediate = async ({ + clearOption, + deprecatedGzip +}: { + clearOption: boolean; + deprecatedGzip: string | undefined; +}) => { if (clearOption) { await clear(); } @@ -150,6 +172,7 @@ const deployImmediate = async ({clearOption}: {clearOption: boolean}) => { await executeDeployImmediate({ deployFn, - uploadFileFn + uploadFileFn, + options: {deprecatedGzip} }); }; From cda485ee71e1ebacd864c64a6dc33b904ac72af1 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 3 Aug 2025 09:07:35 +0200 Subject: [PATCH 2/3] chore: lint --- .../assets/deploy/deploy.execute.services.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/services/assets/deploy/deploy.execute.services.ts b/src/services/assets/deploy/deploy.execute.services.ts index ea038a52..38189fce 100644 --- a/src/services/assets/deploy/deploy.execute.services.ts +++ b/src/services/assets/deploy/deploy.execute.services.ts @@ -8,6 +8,7 @@ import type { UploadFileWithProposal } from '@junobuild/cli-tools'; import {postDeploy as cliPostDeploy, preDeploy as cliPreDeploy} from '@junobuild/cli-tools'; +import type {SatelliteConfig} from '@junobuild/config'; import {type Asset} from '@junobuild/core'; import {red} from 'kleur'; import {lstatSync} from 'node:fs'; @@ -15,7 +16,6 @@ import type {SatelliteParametersWithId} from '../../../types/satellite'; import {assertConfigAndLoadSatelliteContext} from '../../../utils/satellite.utils'; import {assertSatelliteMemorySize} from './deploy.assert.services'; import {listAssets} from './deploy.list.services'; -import type {SatelliteConfig} from '@junobuild/config'; export interface DeployFnParams { deploy: DeployParams; @@ -32,7 +32,7 @@ export const executeDeployWithProposal = async ({ }: { deployFn: (params: DeployFnParams) => Promise; uploadFileFn: (params: UploadFileFnParamsWithProposal) => Promise; - options: {deprecatedGzip?: string} + options: {deprecatedGzip?: string}; }): Promise => { return await executeDeploy({ deployFn, @@ -48,7 +48,7 @@ export const executeDeployImmediate = async ({ }: { deployFn: (params: DeployFnParams) => Promise; uploadFileFn: (params: UploadFileFnParams) => Promise; - options: {deprecatedGzip?: string} + options: {deprecatedGzip?: string}; }): Promise => { return await executeDeploy({ deployFn, @@ -67,18 +67,19 @@ const executeDeploy = async < }: { deployFn: (params: DeployFnParams<(params: P) => Promise>) => Promise; uploadFileFn: (params: P & {satellite: SatelliteParametersWithId}) => Promise; - options: {deprecatedGzip?: string} + options: {deprecatedGzip?: string}; }): Promise => { const assertMemory = async () => { await assertSatelliteMemorySize(); }; - const {satellite, satelliteConfig: satelliteConfigRead} = await assertConfigAndLoadSatelliteContext(); + const {satellite, satelliteConfig: satelliteConfigRead} = + await assertConfigAndLoadSatelliteContext(); const satelliteConfig: SatelliteConfig = { ...satelliteConfigRead, - gzip: satelliteConfigRead?.gzip ?? options.deprecatedGzip - } + gzip: satelliteConfigRead.gzip ?? options.deprecatedGzip + }; const listExistingAssets = async ({startAfter}: {startAfter?: string}): Promise => await listAssets({ From 1c4ab886430664efe6f03dbacac2bcb017795d8b Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sun, 3 Aug 2025 09:11:14 +0200 Subject: [PATCH 3/3] feat: implement for 0.1.1 --- src/services/assets/deploy/deploy.execute.services.ts | 5 ++++- src/services/deploy.services.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/services/assets/deploy/deploy.execute.services.ts b/src/services/assets/deploy/deploy.execute.services.ts index 38189fce..92fc101f 100644 --- a/src/services/assets/deploy/deploy.execute.services.ts +++ b/src/services/assets/deploy/deploy.execute.services.ts @@ -1,3 +1,4 @@ +import {nonNullish} from '@dfinity/utils'; import type { DeployParams, DeployResult, @@ -76,9 +77,11 @@ const executeDeploy = async < const {satellite, satelliteConfig: satelliteConfigRead} = await assertConfigAndLoadSatelliteContext(); + const gzip = satelliteConfigRead.gzip ?? options.deprecatedGzip; + const satelliteConfig: SatelliteConfig = { ...satelliteConfigRead, - gzip: satelliteConfigRead.gzip ?? options.deprecatedGzip + ...(nonNullish(gzip) && {gzip}) }; const listExistingAssets = async ({startAfter}: {startAfter?: string}): Promise => diff --git a/src/services/deploy.services.ts b/src/services/deploy.services.ts index daaf8c23..19386641 100644 --- a/src/services/deploy.services.ts +++ b/src/services/deploy.services.ts @@ -33,7 +33,7 @@ export const deploy = async (args?: string[]) => { // This was fixed in version v0.1.1. However, for backward compatibility, we // fall back to not gzipping HTML files in earlier versions. While gzipping HTML // wouldn't harm usage, it might prevent crawlers from properly fetching content. - const deprecatedGzip = compare(result.version, '0.1.0') < 0 ? '**/*.+(css|js|mjs)' : undefined; + const deprecatedGzip = compare(result.version, '0.1.1') < 0 ? '**/*.+(css|js|mjs)' : undefined; const clearOption = hasArgs({args, options: ['--clear']}); const immediate = hasArgs({args, options: ['-i', '--immediate']});