Skip to content

Commit

Permalink
Replace node-sri with ssri (#2031)
Browse files Browse the repository at this point in the history
Closes #1997.
  • Loading branch information
TheDancingCode authored and roblarsen committed Mar 29, 2018
1 parent d6561f2 commit 7523c41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import runSequence from 'run-sequence';
import archiver from 'archiver';
import glob from 'glob';
import del from 'del';
import sri from 'node-sri';
import ssri from 'ssri';
import modernizr from 'modernizr';

import pkg from './package.json';
Expand Down Expand Up @@ -91,20 +91,20 @@ gulp.task('copy:.htaccess', () =>
.pipe(gulp.dest(dirs.dist))
);

gulp.task('copy:index.html', (done) =>
sri.hash('node_modules/jquery/dist/jquery.min.js', (err, hash) => {
if (err) throw err;

let version = pkg.devDependencies.jquery;
let modernizrVersion = pkg.devDependencies.modernizr;
gulp.src(`${dirs.src}/index.html`)
.pipe(plugins().replace(/{{JQUERY_VERSION}}/g, version))
.pipe(plugins().replace(/{{MODERNIZR_VERSION}}/g, modernizrVersion))
.pipe(plugins().replace(/{{JQUERY_SRI_HASH}}/g, hash))
.pipe(gulp.dest(dirs.dist));
done();
})
);
gulp.task('copy:index.html', () => {
const hash = ssri.fromData(
fs.readFileSync('node_modules/jquery/dist/jquery.min.js'),
{ algorithms: ['sha256'] }
);
let version = pkg.devDependencies.jquery;
let modernizrVersion = pkg.devDependencies.modernizr;

gulp.src(`${dirs.src}/index.html`)
.pipe(plugins().replace(/{{JQUERY_VERSION}}/g, version))
.pipe(plugins().replace(/{{MODERNIZR_VERSION}}/g, modernizrVersion))
.pipe(plugins().replace(/{{JQUERY_SRI_HASH}}/g, hash.toString()))
.pipe(gulp.dest(dirs.dist));
});

gulp.task('copy:jquery', () =>
gulp.src(['node_modules/jquery/dist/jquery.min.js'])
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"jshint-stylish": "^2.2.1",
"mocha": "^5.0.1",
"modernizr": "3.6.0",
"node-sri": "^1.1.1",
"normalize.css": "8.0.0",
"run-sequence": "^2.2.1",
"ssri": "^5.3.0",
"strip-json-comments": "^2.0.1",
"travis-after-all": "^1.4.5"
},
Expand Down

0 comments on commit 7523c41

Please sign in to comment.