-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage.go
29 lines (22 loc) · 837 Bytes
/
package.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main
import (
"package_size_calculator/internal"
"package_size_calculator/pkg/npm"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)
func measurePackageSize(package_ npm.DependencyInfo) (uint64, internal.TmpDir, error) {
l := log.With().Str("package", package_.String()).Logger()
tmpDir, err := installPackageInContainer(package_)
if err != nil {
return 0, tmpDir, errors.Wrapf(err, "failed to install package \"%s\"", package_.String())
}
l.Debug().Str("tempDir", tmpDir.String()).Msg("Installed package")
// ignore the package.json and package-lock.json files
bytes, err := internal.DirSize(tmpDir.Join("node_modules"))
if err != nil {
return 0, tmpDir, errors.Wrap(err, "failed to measure package size")
}
l.Debug().Uint64("bytes", bytes).Msg("Measured package size")
return bytes, tmpDir, nil
}