Skip to content

make Solana.toml optional for deploy command #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/curvy-cycles-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mucho": minor
---

make Solana.toml optional for deploy command
67 changes: 26 additions & 41 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,52 +146,26 @@ export function deployCommand() {

// process the user's config file if they have one
if (config?.programs) {
// make sure the user has the cluster program declared
if (!getSafeClusterMoniker(selectedCluster, config.programs)) {
warnMessage(
`Unable to locate '${selectedCluster}' programs in your Solana.toml`,
);

console.log("The following programs are declared:");
Object.keys(config.programs).forEach((cl) => {
console.log(` - ${cl}:`);
Object.keys(config.programs[cl]).forEach((name) => {
console.log(` - ${name}`);
});
});

process.exit();
}

if (
!config?.programs?.[selectedCluster] ||
!Object.hasOwn(config.programs[selectedCluster], options.programName)
) {
warnMessage(
`Program '${options.programName}' not found in 'programs.${selectedCluster}'`,
);
process.exit();
// Check if the program is declared in the toml for this cluster
if (config?.programs?.[selectedCluster]?.[options.programName]) {
programId = config.programs[selectedCluster][options.programName];
}
// Note: We no longer exit if program is not in toml, just continue with auto-detection
}

programId = config.programs[selectedCluster][options.programName];
} else {
// if the user does not have a config file, we will try to auto detect the program id to use
// todo: this

if (programKeypair) {
programId = programKeypair.address;
warnMessage(`Auto detected default program keypair file:`);
console.log(` - keypair path: ${programIdPath}`);
console.log(` - program id: ${programId}`);
} else {
warnMessage(`Unable to locate any program id or program keypair.`);
process.exit();
}
// If we don't have a program ID from the toml (or no toml exists), try auto-detection
if (!programId && programKeypair) {
programId = programKeypair.address;
warnMessage(`Auto detected default program keypair file:`);
console.log(` - keypair path: ${programIdPath}`);
console.log(` - program id: ${programId}`);
}

if (!programId) {
return warnMessage(
`Unable to locate program id for '${options.programName}'. Do you have it declared?`,
`Unable to locate program id for '${options.programName}'. Either:\n` +
`1. Declare it in Solana.toml under programs.${selectedCluster}\n` +
`2. Ensure ${programIdPath} exists`,
);
}

Expand Down Expand Up @@ -235,9 +209,20 @@ export function deployCommand() {
}

const authorityKeypair = await loadKeypairFromFile(
config.settings.keypair,
options.keypair ||
config?.settings?.keypair ||
"~/.config/solana/id.json",
);

if (!authorityKeypair) {
return warnMessage(
`Unable to locate keypair file. Either:\n` +
`1. Specify with --keypair\n` +
`2. Declare it in Solana.toml settings.keypair\n` +
`3. Ensure ~/.config/solana/id.json exists`,
);
}

/**
* todo: assorted pre-deploy checks to add
* + is program already deployed
Expand Down