Skip to content

Commit

Permalink
Merge pull request #274 from cdnjs/sven/fix-sri
Browse files Browse the repository at this point in the history
don't write SRIs when already existing
  • Loading branch information
xtuc authored Jan 26, 2024
2 parents 890c5c8 + 50041b2 commit 4a8ab76
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions cmd/process-version/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ func (j optimizeJob) emitFromWorkspace(src string) {
ext := path.Ext(src)
if _, ok := calculateSRI[ext]; ok {
outSRI := fmt.Sprintf("%s.sri", dest)
sri.CalculateFileSRI(src, outSRI)
log.Printf("sri %s -> %s\n", src, outSRI)
if _, err := os.Stat(outSRI); err == nil {
log.Printf("file %s already exists at the output\n", outSRI)
} else {
sri.CalculateFileSRI(src, outSRI)
log.Printf("sri %s -> %s\n", src, outSRI)
}
}

if _, ok := doNotCompress[ext]; !ok {
Expand Down
8 changes: 4 additions & 4 deletions packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ func (p *Package) NpmFilesFrom(base string) []NpmFileMoveOp {
util.Check(err) // should have already run before in checker so panic if glob invalid

for _, f := range list {
fp := path.Join(basePath, f)
filename := path.Join(basePath, f)

// check if file has been processed before
if _, ok := seen[fp]; ok {
if _, ok := seen[filename]; ok {
continue
}
seen[fp] = true
seen[filename] = true

info, staterr := os.Stat(fp)
info, staterr := os.Stat(filename)
if staterr != nil {
log.Printf("stat: %s\n", staterr.Error())
continue
Expand Down
6 changes: 4 additions & 2 deletions scripts/test-process-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ set -e
echo "processing $package $version"

export DOCKER_BUILDKIT=1
rm -rf /tmp/output /tmp/input
mkdir -p /tmp/input /tmp/output
rm -rf /tmp/output/* /tmp/input/*

echo "loading new version files"
curl --fail https://storage.googleapis.com/cdnjs-incoming-prod/$package-$version.tgz > /tmp/input/new-version.tgz
echo "loading package configuration"
curl --fail https://raw.githubusercontent.com/cdnjs/packages/master/packages/${package::1}/$package.json > /tmp/input/config.json

cat /tmp/input/config.json
cat /tmp/input/config.json | jq .

echo "----------------- input files -----------------"
ls -lh /tmp/input

tar -tvf /tmp/input/new-version.tgz

docker build -f docker/process-version/Dockerfile -t sandbox .
docker run -it -v /tmp/input:/input -v /tmp/output:/output sandbox

Expand Down

0 comments on commit 4a8ab76

Please sign in to comment.