Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure all packages are packed while tracing #28263

Merged
merged 3 commits into from Aug 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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', '.'], {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be package.json instead of .?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that remove changes to all package.json files in the tree or just the top-level one? This currently modifies all packages/*/package.json files to ensure we link to the packed versions correctly and then we want to undo those changes here after we're done installing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. then it could be git checkout packages/*/package.json but I suppose theres no harm in checking out everything.

Also if there are additional files created you could do git clean -fd

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