diff --git a/src/package-modules.js b/src/package-modules.js index 680a747..ef70f28 100644 --- a/src/package-modules.js +++ b/src/package-modules.js @@ -94,6 +94,18 @@ function chooseNameAndVersion(magentoName, composerJson, ref, givenVersion) { const composerConfig = JSON.parse(composerJson); let {version, name} = composerConfig; version = givenVersion || version; + + // If no version is found and ref looks like a branch name, convert to dev-branch format + if (!version && ref && !ref.match(/^v?\d+\.\d+/)) { + version = `dev-${ref}`; + } + + // ALWAYS convert invalid version strings that are branch names to dev-branch format + // This catches cases where composer.json itself contains "develop" as version + if (version && !version.match(/^v?\d+\.\d+/) && !version.startsWith('dev-') && version.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/)) { + version = `dev-${version}`; + } + if (!name) { throw { kind: 'NAME_UNKNOWN', @@ -166,7 +178,11 @@ async function determinePackageForRef(url, moduleDir, ref, options) { // Some refs do not have a version in the composer.json (e.g. the base package or the magento-composer-installer 0.4.0-beta1= // For those we use the ref as the version. This might be a problem, so for now we leave it as is. if (exception.kind === 'VERSION_UNKNOWN') { - return {[exception.name]: exception.ref} + // For branch names, convert to Composer dev- format + const version = exception.ref.match(/^v?(?:\d+\.){0,3}\d+(?:-[a-z]\w*|)$/i) + ? exception.ref + : `dev-${exception.ref}`; + return {[exception.name]: version} } console.log(`Unable to determine name and/or version for ${magentoName || url} in ${ref}: ${exception.message || exception}`); return {}; @@ -375,7 +391,18 @@ async function createComposerJsonOnlyPackage(url, ref, name, transform, release) isExecutable: false, }]; - const packageFilepath = archiveFilePath(name, release || ref); + // Convert branch names to proper dev-branch format for Composer + let versionForFilename = release || ref; + if (!release && ref && !ref.match(/^v?\d+\.\d+/)) { + versionForFilename = `dev-${ref}`; + } + + // Also check if versionForFilename looks like a branch name and convert it + if (versionForFilename && !versionForFilename.match(/^v?\d+\.\d+/) && !versionForFilename.startsWith('dev-')) { + versionForFilename = `dev-${versionForFilename}`; + } + + const packageFilepath = archiveFilePath(name, versionForFilename); return {packageFilepath, files} } @@ -587,6 +614,11 @@ async function determineMetaPackageFromRepoDir(url, dir, ref, release) { throw {message: `Unable find package name and in composer.json for metapackage ${ref} in ${dir}`} } version = release || version || ref; + + // If no version is found and ref looks like a branch name, convert to dev-branch format + if (!release && !composerConfig.version && ref && !ref.match(/^v?\d+\.\d+/)) { + version = `dev-${ref}`; + } return {[name]: version} } @@ -613,6 +645,11 @@ async function createMetaPackageFromRepoDir(url, dir, ref, options) { throw {message: `Unable find package name and in composer.json for metapackage ${ref} in ${dir}`} } version = release || dependencyVersions[name] || version || ref; + + // If no version is found and ref looks like a branch name, convert to dev-branch format + if (!release && !dependencyVersions[name] && !composerConfig.version && ref && !ref.match(/^v?\d+\.\d+/)) { + version = `dev-${ref}`; + } // Ensure version is set on composer config because not all repos provide the version in composer.json (e.g. // page-builder) and it is required by satis to be able to use artifact repositories. diff --git a/src/release-branch-build-tools.js b/src/release-branch-build-tools.js index 1c1c71c..2923107 100644 --- a/src/release-branch-build-tools.js +++ b/src/release-branch-build-tools.js @@ -81,6 +81,11 @@ async function getPackageVersionsForBuildInstructions(buildInstructions, suffix) } function addSuffixToVersion(version, buildSuffix) { + // Don't add suffix to dev- branch versions + if (version.startsWith('dev-')) { + return version; + } + const match = version.match(/(?(?:[\d]+\.?){1,4})(?-[^+]+)?(?\+.+)?/) if (match) { return `${match.groups.versions}-a${buildSuffix}${match.groups.legacy ? match.groups.legacy : ''}` @@ -100,6 +105,11 @@ function transformVersionsToNightlyBuildVersion(baseVersion, buildSuffix) { } function calcNightlyBuildPackageBaseVersion(version) { + // Handle dev- branch versions (e.g., dev-develop, dev-master) + if (version.startsWith('dev-')) { + return version; // Return as-is, it's already a valid Composer branch version + } + if (! version.match(/^v?(?:\d+\.){0,3}\d+(?:-[a-z]\w*|)$/i)) { throw Error(`Unable to determine branch release version for input version "${version}"`) }