From 16dd8c685e0921e1deed612d94da317dea557375 Mon Sep 17 00:00:00 2001 From: Thomas Vantuycom Date: Thu, 29 Mar 2018 14:07:58 +0200 Subject: [PATCH] Replace `node-sri` with `ssri` Closes #1997. --- gulpfile.babel.js | 30 +++++++++++++++--------------- package.json | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 65cb23e86d..260c8e4be4 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -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'; @@ -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']) diff --git a/package.json b/package.json index 38a39c5cdc..75ba90703e 100644 --- a/package.json +++ b/package.json @@ -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" },