Skip to content

Commit

Permalink
feat: compatibility with webpack-subresource-integrity@5.1.0
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- `integrity: true` now requires `webpack-subresource-integrity`>=`5.0.0`
- webpack@3 support with its `after-emit` hook is dropped

Closes: ztoben#451
  • Loading branch information
Den-dp committed Dec 15, 2022
1 parent 2d438a7 commit d560560
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
13 changes: 4 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ AssetsWebpackPlugin.prototype = {
)
self.writer = createQueuedWriter(createOutputWriter(self.options))

const emitPlugin = (compilation, callback) => {
const emitPlugin = (file, { compilation }, callback) => {
const options = compiler.options
const stats = compilation.getStats().toJson({
hash: true,
Expand Down Expand Up @@ -119,7 +119,7 @@ AssetsWebpackPlugin.prototype = {
if (self.options.includeAllFileTypes || self.options.fileTypes.includes(typeName)) {
const combinedPath = assetPath && assetPath.slice(-1) !== '/' ? `${assetPath}/${asset}` : assetPath + asset
const type = typeof typeMap[typeName]
const compilationAsset = compilation.assets[asset]
const compilationAsset = stats.assets.find(statAsset => statAsset.name === asset)
const integrity = compilationAsset && compilationAsset.integrity
const loadingBehavior = obj.loadingBehavior

Expand Down Expand Up @@ -203,13 +203,8 @@ AssetsWebpackPlugin.prototype = {
})
}

if (compiler.hooks) {
const plugin = { name: 'AssetsWebpackPlugin' }

compiler.hooks.emit.tapAsync(plugin, emitPlugin)
} else {
compiler.plugin('after-emit', emitPlugin)
}
const plugin = { name: 'AssetsWebpackPlugin' }
compiler.hooks.assetEmitted.tapAsync(plugin, emitPlugin)
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"snazzy": "9.0.0",
"standard": "16.0.3",
"style-loader": "2.0.0",
"webpack": "5.53.0",
"webpack-subresource-integrity": "1.5.2"
"webpack": "5.75.0",
"webpack-subresource-integrity": "5.1.0"
},
"dependencies": {
"camelcase": "^6.0.0",
Expand Down
9 changes: 3 additions & 6 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Plugin = require('../index.js')
const OUTPUT_DIR = path.join(__dirname, '../tmp')
const expectOutput = require('./utils/expectOutput')(OUTPUT_DIR)
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const SriPlugin = require('webpack-subresource-integrity')
const { SubresourceIntegrityPlugin } = require('webpack-subresource-integrity')

describe('Plugin', function () {
beforeEach(function (done) {
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('Plugin', function () {
expectOutput(args, done)
})

it('works with SriPlugin for multiple entries', function (done) {
it('works with SubresourceIntegrityPlugin for multiple entries', function (done) {
const webpackConfig = {
entry: {
one: path.join(__dirname, 'fixtures/one.js'),
Expand All @@ -268,10 +268,7 @@ describe('Plugin', function () {
path: 'tmp',
integrity: true
}),
new SriPlugin({
hashFuncNames: ['sha384'],
enabled: true
})
new SubresourceIntegrityPlugin()
]
}

Expand Down

0 comments on commit d560560

Please sign in to comment.