Skip to content

Commit

Permalink
Use temp repo copy while linking packages (#28301)
Browse files Browse the repository at this point in the history
* Use temp repo copy while linking packages

* Apply suggestions from code review

Co-authored-by: Jiachi Liu <inbox@huozhi.im>

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
  • Loading branch information
ijjk and huozhi committed Aug 19, 2021
1 parent 4e76911 commit f525ab6
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions scripts/trace-next-server.js
Expand Up @@ -18,10 +18,18 @@ const MAX_UNCOMPRESSED_SIZE = 2.5 * 1000 * 1000
// version so isn't pre-traced
async function main() {
const tmpdir = os.tmpdir()
const repoDir = path.join(__dirname, '..')
const origRepoDir = path.join(__dirname, '..')
const repoDir = path.join(tmpdir, `tmp-next-${Date.now()}`)
const workDir = path.join(tmpdir, `trace-next-${Date.now()}`)

await fs.copy(origRepoDir, repoDir, {
filter: (item) => {
return !item.includes('node_modules')
},
})

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

const pkgPaths = await linkPackages(repoDir)
Expand All @@ -48,16 +56,6 @@ 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 @@ -119,6 +117,7 @@ async function main() {
})
)
await fs.remove(workDir)
await fs.remove(repoDir)

console.timeEnd(traceLabel)

Expand Down

0 comments on commit f525ab6

Please sign in to comment.