diff --git a/e2e/publish-canary.js b/e2e/publish-canary.js index 7cdc8ba4..683130ef 100644 --- a/e2e/publish-canary.js +++ b/e2e/publish-canary.js @@ -9,8 +9,8 @@ const { execSync } = require('child_process') // setup token const { NPM_TOKEN, REGISTRY, CURRENT_COMMIT } = process.env -if (!NPM_TOKEN) { - console.error('NPM_TOKEN is not set!') +if (!NPM_TOKEN || !REGISTRY || !CURRENT_COMMIT) { + console.error('Missing NPM_TOKEN, REGISTRY or CURRENT_COMMIT env variables!') process.exit(1) } @@ -20,23 +20,41 @@ const nodeModulesDir = path.join(__dirname, 'node_modules') const mtcuteDir = path.join(nodeModulesDir, '@mtcute') const commit = CURRENT_COMMIT.slice(0, 7) +const versions = {} for (const pkg of fs.readdirSync(mtcuteDir)) { const pkgJsonPath = path.join(mtcuteDir, pkg, 'package.json') const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8')) const version = `${pkgJson.version}-git.${commit}` + versions[pkg] = version +} - fs.writeFileSync( - pkgJsonPath, - JSON.stringify( - { - ...pkgJson, - version, - }, - null, - 4, - ), - ) +for (const pkg of fs.readdirSync(mtcuteDir)) { + const pkgJsonPath = path.join(mtcuteDir, pkg, 'package.json') + const pkgJsonOrig = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8')) + const pkgJson = JSON.parse(JSON.stringify(pkgJsonOrig)) + + const version = versions[pkg] + pkgJson.version = version + + // eslint-disable-next-line no-inner-declarations + function fixDependencies(key) { + if (!pkgJson[key]) return + + const deps = pkgJson[key] + + for (const dep of Object.keys(deps)) { + if (!dep.startsWith('@mtcute/')) continue + deps[dep] = versions[dep.slice('@mtcute/'.length)] + } + } + + fixDependencies('dependencies') + fixDependencies('peerDependencies') + fixDependencies('devDependencies') + fixDependencies('optionalDependencies') + + fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4)) execSync(`npm publish --registry ${REGISTRY} -q --tag canary`, { cwd: path.join(mtcuteDir, pkg), @@ -44,5 +62,5 @@ for (const pkg of fs.readdirSync(mtcuteDir)) { }) // restore package.json just in case - fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4)) + fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJsonOrig, null, 4)) }