Skip to content

Commit

Permalink
stop experimental dfx.json values from being used in a stable canister
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Aug 28, 2024
1 parent b9ee2a2 commit a903e55
Showing 1 changed file with 53 additions and 12 deletions.
65 changes: 53 additions & 12 deletions src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { runCommand as runNewCommand } from './stable/commands/new';
import { runCommand as runVersionCommand } from './stable/commands/version';
import { getCanisterConfig } from './stable/utils/get_canister_config';
import { AZLE_PACKAGE_PATH } from './stable/utils/global_paths';
import { Command } from './stable/utils/types';
import { CanisterConfig, Command } from './stable/utils/types';

build();

Expand Down Expand Up @@ -101,19 +101,10 @@ async function handleCompileCommand(ioType: IOType): Promise<void> {
const experimental = canisterConfig?.custom?.experimental === true;

if (experimental === false) {
checkForExperimentalDfxJsonFields(canisterConfig);

await runStableCompileCommand(canisterName, canisterConfig, ioType);
} else {
// TODO the developer needs to somehow have their build process fail if they try to
// TODO do something that isn't experimental in their code
// TODO how will this work with the build process?
// TODO hmmmm...at runtime we check for imports
// TODO and we will check for globals
// TODO and if they try to import from any azle code it will throw
// TODO is that good enough?
// TODO maybe we need to check for experimental values in the dfx.json custom property
// TODO and throw if we see them?
// TODO we must throw if they EVER try to do anything experimental and they have not
// TODO set the experimental flag
await runExperimentalCompileCommand(
canisterName,
canisterConfig,
Expand Down Expand Up @@ -143,3 +134,53 @@ async function handleNewCommand(): Promise<void> {
await runNewCommand(azleVersion, templatePath);
}
}

function checkForExperimentalDfxJsonFields(
canisterConfig: CanisterConfig
): void {
if (canisterConfig.custom?.assets !== undefined) {
throw new Error(
experimentalMessageDfxJson('the assets field in your dfx.json file')
);
}

if (canisterConfig.custom?.build_assets !== undefined) {
throw new Error(
experimentalMessageDfxJson(
'the build_assets field in your dfx.json file'
)
);
}

if (canisterConfig.custom?.candid_gen === 'http') {
throw new Error(
experimentalMessageDfxJson(
'the "candid_gen": "http" field in your dfx.json file'
)
);
}

if (canisterConfig.custom?.esm_aliases !== undefined) {
throw new Error(
experimentalMessageDfxJson(
'the esm_aliases field in your dfx.json file'
)
);
}

if (canisterConfig.custom?.esm_externals !== undefined) {
throw new Error(
experimentalMessageDfxJson(
'the esm_externals field in your dfx.json file'
)
);
}

if (canisterConfig.custom?.openValueSharing !== undefined) {
throw new Error(
experimentalMessageDfxJson(
'the openValueSharing field in your dfx.json file'
)
);
}
}

0 comments on commit a903e55

Please sign in to comment.