Skip to content

Commit

Permalink
[do not merge] run stats for #69484
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Sep 9, 2024
1 parent 2195a10 commit b41dab8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
50 changes: 40 additions & 10 deletions .github/actions/next-stats-action/src/run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function runConfigs(
let diffRepoStats
let diffs

let i = 0
for (const pkgPaths of [mainRepoPkgPaths, diffRepoPkgPaths]) {
let curStats = {
General: {
Expand All @@ -48,7 +49,42 @@ async function runConfigs(
}

// links local builds of the packages and installs dependencies
await linkPkgs(statsAppDir, pkgPaths)
const pkgJsonPath = path.join(statsAppDir, 'package.json')
const isMainRepo = i === 0
if (isMainRepo) {
// TODO: Remove me before merging
const original = await fs.readFile(
path.join(statsAppDir, 'package.json'),
'utf8'
)
await fs.writeFile(
path.join(statsAppDir, 'package.json'),
original.replaceAll('^18.2.0', '19.0.0-rc-7771d3a7-20240827'),
'utf8'
)
} else {
// TODO: Remove me before merging
const original = await fs.readFile(
path.join(statsAppDir, 'package.json'),
'utf8'
)
await fs.writeFile(
path.join(statsAppDir, 'package.json'),
original.replaceAll('19.0.0-rc-7771d3a7-20240827', '^18.2.0'),
'utf8'
)
}

const initialPkg = JSON.parse(
await fs.readFile(path.join(statsAppDir, 'package.json'), 'utf8')
)

const pkgData = await linkPkgs(statsAppDir, initialPkg, pkgPaths)
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgData, null, 2), 'utf8')
await exec(
`cd ${statsAppDir} && pnpm install --strict-peer-dependencies=false`,
false
)

if (!diffing) {
curStats.General.nodeModulesSize = await getDirSize(
Expand Down Expand Up @@ -156,6 +192,7 @@ async function runConfigs(
await exec(`cd ${statsAppDir} && ${statsConfig.appBuildCommand}`, false)
)
curStats.General.buildDurationCached = Date.now() - secondBuildStart
i++
}

logger(`Finished running: ${config.title}`)
Expand All @@ -171,15 +208,12 @@ async function runConfigs(
return results
}

async function linkPkgs(pkgDir = '', pkgPaths) {
async function linkPkgs(pkgDir = '', pkgData, pkgPaths) {
await fs.rm(path.join(pkgDir, 'node_modules'), {
recursive: true,
force: true,
})

const pkgJsonPath = path.join(pkgDir, 'package.json')
const pkgData = require(pkgJsonPath)

if (!pkgData.dependencies && !pkgData.devDependencies) return

for (const pkg of pkgPaths.keys()) {
Expand All @@ -191,12 +225,8 @@ async function linkPkgs(pkgDir = '', pkgPaths) {
pkgData.devDependencies[pkg] = pkgPath
}
}
await fs.writeFile(pkgJsonPath, JSON.stringify(pkgData, null, 2), 'utf8')

await exec(
`cd ${pkgDir} && pnpm install --strict-peer-dependencies=false`,
false
)
return pkgData
}

module.exports = runConfigs
4 changes: 2 additions & 2 deletions test/.stats-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"license": "MIT",
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react": "19.0.0-rc-7771d3a7-20240827",
"react-dom": "19.0.0-rc-7771d3a7-20240827"
},
"engines": {
"node": ">=18.18.0"
Expand Down

0 comments on commit b41dab8

Please sign in to comment.