fix(e2e): fixed canary publishing

This commit is contained in:
alina 🌸 2023-12-24 18:48:09 +03:00
parent c175e41616
commit 09c2bf03b3
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -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))
}