Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/services/modules/upgrade/upgrade-assert.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {isNullish} from '@dfinity/utils';
import {satelliteBuildType, type SatelliteParameters} from '@junobuild/admin';
import {cyan, yellow} from 'kleur';
import type {AssertWasmModule, UpgradeWasm} from '../../../types/upgrade';
import {isHeadless} from '../../../utils/process.utils';
import {NEW_CMD_LINE, confirmAndExit} from '../../../utils/prompt.utils';
import {readWasmModuleMetadata} from '../../../utils/wasm.utils';

Expand All @@ -25,7 +26,7 @@ export const assertSatelliteBuildType = async ({
globalThis.console.warn = hideAgentJsConsoleWarn;

if (wasmMetadataResult.status === 'rejected') {
throw new Error(`The custom sections of the WASM module you try to upgrade cannot be read.`);
throw new Error('The custom sections of the WASM module you try to upgrade cannot be read.');
}

// Agent-js throw an exception when a metadata path cannot be found therefore we assumed here that this happens because the Satellite version is < 0.0.15.
Expand All @@ -38,13 +39,21 @@ export const assertSatelliteBuildType = async ({

const {buildType: wasmType} = wasmMetadata;

if (satelliteType === 'extended' && (wasmType === 'stock' || isNullish(wasmType))) {
const warning = satelliteType === 'extended' && (wasmType === 'stock' || isNullish(wasmType));

if (isHeadless() && warning) {
throw new Error(
'Your satellite uses serverless functions. Reverting to the stock version would remove your custom features! '
);
}

if (warning) {
await confirmAndExit(
`Your satellite is currently running on an ${cyan(
`extended`
)} build.${NEW_CMD_LINE}However, you are about to upgrade it to the ${yellow(
`Your satellite uses ${cyan(
`serverless functions`
)}.${NEW_CMD_LINE}However, you are about to revert it to the ${yellow(
`stock`
)} version.${NEW_CMD_LINE}Are you sure you want to proceed?`
)} version which will remove your custom features!${NEW_CMD_LINE}Are you sure you want to proceed?`
);
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/services/modules/upgrade/upgrade.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ const executeUpgradeWasm = async ({
reset = false,
assetKey
}: {assetKey: AssetKey} & UpgradeWasm) => {
await assert?.({wasmModule: wasm});

if (isNotHeadless()) {
await assert?.({wasmModule: wasm});
await assertUpgradeHash({hash, reset});
}

Expand Down