Skip to content
19 changes: 10 additions & 9 deletions src/pin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export async function pin (args: ArgumentsCamelCase<Params>): Promise<void> {
exit(`Manifest file not found: ${manifestPath}`)
}

const { contractName, contractFiles, manifestVersion } = await parseManifest(fullManifestPath)
console.log(colors.blue(`Contract name: ${contractName}`))
const { contractName, fullContractName, contractFiles, manifestVersion } = await parseManifest(fullManifestPath)
console.log(colors.blue(`Contract name: ${fullContractName}`))
console.log(colors.blue(`Manifest version: ${manifestVersion}`))

if (version) {
Expand All @@ -50,31 +50,31 @@ export async function pin (args: ArgumentsCamelCase<Params>): Promise<void> {
console.log(colors.green(`✅ Version validation passed: ${version}`))
}

const currentPinnedVersion = cheloniaConfig.contracts[contractName]?.version
const currentPinnedVersion = cheloniaConfig.contracts[fullContractName]?.version
if (currentPinnedVersion === manifestVersion) {
console.log(colors.yellow(`✨ Contract ${contractName} is already pinned to version ${manifestVersion} - no action needed`))
console.log(colors.yellow(`✨ Contract ${fullContractName} is already pinned to version ${manifestVersion} - no action needed`))
return
}

if (currentPinnedVersion) {
console.log(colors.cyan(`📌 Updating ${contractName} from version ${currentPinnedVersion} to ${manifestVersion}`))
console.log(colors.cyan(`📌 Updating ${fullContractName} from version ${currentPinnedVersion} to ${manifestVersion}`))
} else {
console.log(colors.cyan(`📌 Pinning ${contractName} to version ${manifestVersion} (first time)`))
console.log(colors.cyan(`📌 Pinning ${fullContractName} to version ${manifestVersion} (first time)`))
}

const contractVersionDir = join(projectRoot, 'contracts', contractName, manifestVersion)

if (existsSync(contractVersionDir)) {
if (!args.overwrite) {
exit(`Version ${manifestVersion} already exists for contract ${contractName}. Use --overwrite to replace it.`)
exit(`Version ${manifestVersion} already exists for contract ${fullContractName}. Use --overwrite to replace it.`)
}
console.log(colors.yellow(`Version ${manifestVersion} already exists for ${contractName} - checking files...`))
console.log(colors.yellow(`Version ${manifestVersion} already exists for ${fullContractName} - checking files...`))
} else {
await createVersionDirectory(contractName, manifestVersion)
}

await copyContractFiles(contractFiles, manifestPath, contractName, manifestVersion, args)
await updateCheloniaConfig(contractName, manifestVersion, manifestPath)
await updateCheloniaConfig(fullContractName, manifestVersion, manifestPath)
Comment thread
corrideat marked this conversation as resolved.
Outdated

console.log(colors.green(`✅ Successfully pinned ${contractName} to version ${version}`))
Comment thread
corrideat marked this conversation as resolved.
Outdated
console.log(colors.gray(`Location: contracts/${contractName}/${manifestVersion}/`))
Expand Down Expand Up @@ -103,6 +103,7 @@ async function parseManifest (manifestPath: string) {
return {
contractName,
manifestVersion,
fullContractName,
contractFiles: {
main: mainFile,
slim: slimFile
Expand Down
19 changes: 15 additions & 4 deletions src/serve/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ import { addChannelToSubscription, deleteChannelFromSubscription, postEvent, pus
// @deno-types="npm:@types/nconf"
import nconf from 'npm:nconf'

const cheloniaAppManifest = await (async () => {
try {
return await import(join(process.cwd(), 'chelonia.json'), {
with: { type: 'json' }
})
Comment thread
corrideat marked this conversation as resolved.
Outdated
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using join(process.cwd(), 'chelonia.json') as an import() specifier is not portable (e.g., backslashes on Windows) and can fail because import() expects a valid module specifier/URL. Consider converting the filesystem path to a file:// URL (e.g., via pathToFileURL) before importing.

Copilot uses AI. Check for mistakes.
} catch {
console.warn('`chelonia.json` not found. Version information will be unavailable.')
Comment thread
corrideat marked this conversation as resolved.
Outdated
}
})()

const ARCHIVE_MODE = nconf.get('server:archiveMode')

if (CREDITS_WORKER_TASK_TIME_INTERVAL && OWNER_SIZE_TOTAL_WORKER_TASK_TIME_INTERVAL > CREDITS_WORKER_TASK_TIME_INTERVAL) {
Expand All @@ -49,8 +59,6 @@ const creditsWorker = ARCHIVE_MODE || !CREDITS_WORKER_TASK_TIME_INTERVAL
? undefined
: createWorker(join(import.meta.dirname || '.', import.meta.workerDir || '.', 'creditsWorker.js'))

const { CONTRACTS_VERSION, GI_VERSION } = process.env

// Dynamic runtime import to bypass bundling issues with npm: specifier
const hapi = new Hapi.Server({
// debug: false, // <- Hapi v16 was outputing too many unnecessary debug statements
Expand Down Expand Up @@ -426,8 +434,11 @@ sbp('okTurtles.data/set', PUBSUB_INSTANCE, createServer(hapi.listener, {
serverHandlers: {
connection (socket) {
const versionInfo = {
GI_VERSION: GI_VERSION || null,
CONTRACTS_VERSION: CONTRACTS_VERSION || null
appVersion: cheloniaAppManifest?.appVersion || null,
contractsVersion: Object.fromEntries(
Object.entries(cheloniaAppManifest?.contracts || {})
.map(([k, v]) => [k, (v as Record<string, number | string>).version])
)
Comment thread
corrideat marked this conversation as resolved.
Outdated
Comment thread
corrideat marked this conversation as resolved.
Outdated
}
socket.send(createNotification(NOTIFICATION_TYPE.VERSION_INFO, versionInfo))
}
Expand Down
Loading