Skip to content

Commit

Permalink
Ensure all packages are packed while tracing (#28263)
Browse files Browse the repository at this point in the history
* Ensure all packages are packed while tracing

* bump
  • Loading branch information
ijjk committed Aug 18, 2021
1 parent a342fba commit f2fa4f3
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions scripts/trace-next-server.js
Expand Up @@ -5,6 +5,8 @@ const fs = require('fs-extra')
const prettyBytes = require('pretty-bytes')
const gzipSize = require('next/dist/compiled/gzip-size')
const { nodeFileTrace } = require('next/dist/compiled/@vercel/nft')
const { linkPackages } =
require('../.github/actions/next-stats-action/src/prepare/repo-setup')()

const MAX_COMPRESSED_SIZE = 250 * 1000
const MAX_UNCOMPRESSED_SIZE = 2.5 * 1000 * 1000
Expand All @@ -16,26 +18,20 @@ const MAX_UNCOMPRESSED_SIZE = 2.5 * 1000 * 1000
// version so isn't pre-traced
async function main() {
const tmpdir = os.tmpdir()
await execa('yarn', ['pack'], {
cwd: path.join(__dirname, '../packages/next'),
stdio: ['ignore', 'inherit', 'inherit'],
})
const packagePath = path.join(
__dirname,
`../packages/next/next-v${
require('../packages/next/package.json').version
}.tgz`
)
const repoDir = path.join(__dirname, '..')
const workDir = path.join(tmpdir, `trace-next-${Date.now()}`)

console.log('using workdir', workDir)
await fs.ensureDir(workDir)

const pkgPaths = await linkPackages(repoDir)

await fs.writeFile(
path.join(workDir, 'package.json'),
JSON.stringify(
{
dependencies: {
next: packagePath,
next: pkgPaths.get('next'),
},
private: true,
},
Expand All @@ -52,6 +48,16 @@ async function main() {
},
})

// remove temporary package packs
pkgPaths.forEach((packagePath) => {
fs.unlinkSync(packagePath)
})
// remove changes to package.json files from packing
await execa('git', ['checkout', '.'], {
cwd: repoDir,
stdio: ['ignore', 'inherit', 'inherit'],
})

const nextServerPath = path.join(
workDir,
'node_modules/next/dist/server/next-server.js'
Expand Down Expand Up @@ -112,7 +118,6 @@ async function main() {
version: 1,
})
)
await fs.unlink(packagePath)
await fs.remove(workDir)

console.timeEnd(traceLabel)
Expand Down

0 comments on commit f2fa4f3

Please sign in to comment.