Skip to content

Commit

Permalink
test(client): measure zip size
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 committed Mar 26, 2021
1 parent 7936d45 commit 62feac6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/packages/client/.gitignore
Expand Up @@ -30,3 +30,4 @@ write-test
prisma-client-*.tgz
*.tsbuildinfo
pnpm-lock.yaml
*.zip
Expand Up @@ -40,32 +40,56 @@ suite
console.log(String(event.target))
})
.on('complete', () => {
getSize('@prisma/client')
getSize('.prisma/client')
getSize('.prisma/client/index.d.ts')
getSize('.prisma/client/index.js')
getSize('./node_modules/@prisma/client')
getSize('./node_modules/.prisma/client')
getSize('./node_modules/.prisma/client/index.d.ts')
getSize('./node_modules/.prisma/client/index.js')
// For GitHub CI
getSize('.prisma/client/query-engine-debian-openssl-1.1.x')
getSize('./node_modules/.prisma/client/query-engine-darwin')

// Zip .prisma/client and @prisma/client and check size
execa.sync('rm', ['-rf', `./dotPlusAtPrismaClientFolder.zip`], {
stdout: 'pipe',
cwd: __dirname,
})
execa.sync(
'zip',
[
'-r',
'dotPlusAtPrismaClientFolder.zip',
'./node_modules/.prisma/client',
'./node_modules/@prisma/client',
],
{
stdout: 'pipe',
cwd: __dirname,
},
)
getSize('./dotPlusAtPrismaClientFolder.zip')
})
.run()

const regex = new RegExp(/([\d]{1,99}([.]\d{1,99})?)(\w)/)

function getSize(packageName: string): { size: string; unit: string } {
// const listFiles = execa.sync('ls', ['-la', `./node_modules/${packageName}`], {
function getSize(targetPath: string): { size: string; unit: string } {
// const listFiles = execa.sync('ls', ['-la', `./node_modules/${targetPath}`], {
// stdout: 'pipe',
// cwd: __dirname,
// })
// console.log(listFiles)

const output = execa.sync('du', ['-sh', `./node_modules/${packageName}`], {
const output = execa.sync('du', ['-sh', targetPath], {
stdout: 'pipe',
cwd: __dirname,
})
const str = output.stdout.split('\t')[0]
const match = regex.exec(str)
const pkgSize = { size: match[1], unit: match[3] }
console.log(
`${packageName} size x ${pkgSize.size} ${pkgSize.unit}B ±0.00% (1 runs sampled)`,
`${targetPath.replace('./node_modules/', '').replace('./', '')} size x ${
pkgSize.size
} ${pkgSize.unit}B ±0.00% (1 runs sampled)`,
)

return pkgSize
}

0 comments on commit 62feac6

Please sign in to comment.