Unverified Commit 98a2448e authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix release stats (#45027)

parent a4d9373b
...@@ -5,8 +5,8 @@ const benchTitle = 'Page Load Tests' ...@@ -5,8 +5,8 @@ const benchTitle = 'Page Load Tests'
const workDir = path.join(os.tmpdir(), 'next-stats') const workDir = path.join(os.tmpdir(), 'next-stats')
const mainRepoName = 'main-repo' const mainRepoName = 'main-repo'
const diffRepoName = 'diff-repo' const diffRepoName = 'diff-repo'
const mainRepoDir = path.join(os.tmpdir(), mainRepoName) const mainRepoDir = path.join(workDir, mainRepoName)
const diffRepoDir = path.join(os.tmpdir(), diffRepoName) const diffRepoDir = path.join(workDir, diffRepoName)
const statsAppDir = path.join(workDir, 'stats-app') const statsAppDir = path.join(workDir, 'stats-app')
const diffingDir = path.join(workDir, 'diff') const diffingDir = path.join(workDir, 'diff')
const yarnEnvValues = { const yarnEnvValues = {
......
...@@ -55,27 +55,138 @@ module.exports = (actionInfo) => { ...@@ -55,27 +55,138 @@ module.exports = (actionInfo) => {
} }
}, },
async linkPackages({ repoDir, nextSwcVersion }) { async linkPackages({ repoDir, nextSwcVersion }) {
execa.sync('pnpm', ['turbo', 'run', 'test-pack'], { let hasTestPack = false
cwd: repoDir,
env: { NEXT_SWC_VERSION: nextSwcVersion }, try {
}) hasTestPack = Boolean(
((await fs.readJSON(path.join(repoDir, 'package.json'))).scripts ||
const pkgPaths = new Map() {})['test-pack']
const pkgs = await fs.readdir(path.join(repoDir, 'packages'))
pkgs.forEach((pkgDirname) => {
const { name } = require(path.join(
repoDir,
'packages',
pkgDirname,
'package.json'
))
pkgPaths.set(
name,
path.join(repoDir, 'packages', pkgDirname, `packed-${pkgDirname}.tgz`)
) )
}) } catch (err) {
return pkgPaths console.error(err)
}
if (hasTestPack) {
execa.sync('pnpm', ['turbo', 'run', 'test-pack'], {
cwd: repoDir,
env: { NEXT_SWC_VERSION: nextSwcVersion },
})
const pkgPaths = new Map()
const pkgs = await fs.readdir(path.join(repoDir, 'packages'))
pkgs.forEach((pkgDirname) => {
const { name } = require(path.join(
repoDir,
'packages',
pkgDirname,
'package.json'
))
pkgPaths.set(
name,
path.join(
repoDir,
'packages',
pkgDirname,
`packed-${pkgDirname}.tgz`
)
)
})
return pkgPaths
} else {
// TODO: remove after next stable release (current v13.1.2)
const pkgPaths = new Map()
const pkgDatas = new Map()
let pkgs
try {
pkgs = await fs.readdir(path.join(repoDir, 'packages'))
} catch (err) {
if (err.code === 'ENOENT') {
require('console').log('no packages to link')
return pkgPaths
}
throw err
}
for (const pkg of pkgs) {
const pkgPath = path.join(repoDir, 'packages', pkg)
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)
const pkgDataPath = path.join(pkgPath, 'package.json')
if (!fs.existsSync(pkgDataPath)) {
require('console').log(`Skipping ${pkgDataPath}`)
continue
}
const pkgData = require(pkgDataPath)
const { name } = pkgData
pkgDatas.set(name, {
pkgDataPath,
pkg,
pkgPath,
pkgData,
packedPkgPath,
})
pkgPaths.set(name, packedPkgPath)
}
for (const pkg of pkgDatas.keys()) {
const { pkgDataPath, pkgData } = pkgDatas.get(pkg)
for (const pkg of pkgDatas.keys()) {
const { packedPkgPath } = pkgDatas.get(pkg)
if (!pkgData.dependencies || !pkgData.dependencies[pkg]) continue
pkgData.dependencies[pkg] = packedPkgPath
}
// make sure native binaries are included in local linking
if (pkg === '@next/swc') {
if (!pkgData.files) {
pkgData.files = []
}
pkgData.files.push('native')
require('console').log(
'using swc binaries: ',
await exec(`ls ${path.join(path.dirname(pkgDataPath), 'native')}`)
)
}
if (pkg === 'next') {
if (nextSwcVersion) {
Object.assign(pkgData.dependencies, {
'@next/swc-linux-x64-gnu': nextSwcVersion,
})
} else {
if (pkgDatas.get('@next/swc')) {
pkgData.dependencies['@next/swc'] =
pkgDatas.get('@next/swc').packedPkgPath
} else {
pkgData.files.push('native')
}
}
}
await fs.writeFile(
pkgDataPath,
JSON.stringify(pkgData, null, 2),
'utf8'
)
}
// wait to pack packages until after dependency paths have been updated
// to the correct versions
await Promise.all(
Array.from(pkgDatas.keys()).map(async (pkgName) => {
const { pkg, pkgPath } = pkgDatas.get(pkgName)
await exec(
`cd ${pkgPath} && yarn pack -f '${pkg}-packed.tgz'`,
true
)
})
)
return pkgPaths
}
}, },
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment