Skip to content

Commit a6ad897

Browse files
authored
Merge pull request #42 from waysact/remove-deprecated-features
Remove deprecated code
2 parents 6d3af66 + 93698ff commit a6ad897

File tree

3 files changed

+2
-249
lines changed

3 files changed

+2
-249
lines changed

README.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,6 @@ When this value is falsy, the plugin doesn't run and no integrity
123123
values are calculated. It is recommended to disable the plugin in
124124
development mode.
125125

126-
#### crossorigin
127-
128-
**DEPRECATED**. Use webpack option `output.crossOriginLoading`
129-
instead.
130-
131-
~~Default value: `"anonymous"`~~
132-
133-
~~When using `HtmlWebpackPlugin({ inject: true })`, this option
134-
specifies the value to be used for the `crossorigin` attribute for
135-
injected assets.~~
136-
137-
~~The value will also be available as
138-
`htmlWebpackPlugin.options.sriCrossOrigin` in html-webpack-plugin
139-
templates.~~
140-
141-
~~See
142-
[SRI: Cross-origin data leakage](https://www.w3.org/TR/SRI/#cross-origin-data-leakage) and
143-
[MDN: CORS settings attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)~~
144-
145126
## Caveats
146127

147128
### Proxies

index.js

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ var ReplaceSource = require('webpack-core/lib/ReplaceSource');
55
// https://www.w3.org/TR/2016/REC-SRI-20160623/#cryptographic-hash-functions
66
var standardHashFuncNames = ['sha256', 'sha384', 'sha512'];
77

8-
// https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes
9-
var standardCrossoriginOptions = ['anonymous', 'use-credentials'];
10-
118
function makePlaceholder(id) {
129
return '*-*-*-CHUNK-SRI-HASH-' + id + '-*-*-*';
1310
}
@@ -73,17 +70,7 @@ WebIntegrityJsonpMainTemplatePlugin.prototype.apply = function apply(mainTemplat
7370

7471
function SubresourceIntegrityPlugin(options) {
7572
var useOptions;
76-
if (typeof options === 'string') {
77-
useOptions = {
78-
hashFuncNames: [options],
79-
deprecatedOptions: true
80-
};
81-
} else if (Array.isArray(options)) {
82-
useOptions = {
83-
hashFuncNames: options,
84-
deprecatedOptions: true
85-
};
86-
} else if (options === null || typeof options === 'undefined') {
73+
if (options === null || typeof options === 'undefined') {
8774
useOptions = {};
8875
} else if (typeof options === 'object') {
8976
useOptions = options;
@@ -124,14 +111,6 @@ SubresourceIntegrityPlugin.prototype.validateOptions = function validateOptions(
124111
return;
125112
}
126113
this.optionsValidated = true;
127-
if (this.options.deprecatedOptions) {
128-
this.warnOnce(
129-
compilation,
130-
'Passing a string or array to the plugin constructor is deprecated. ' +
131-
'Support will be removed in webpack-subresource-integrity 1.0.0. ' +
132-
'Please update your code. ' +
133-
'See https://github.com/waysact/webpack-subresource-integrity/issues/18 for more information.');
134-
}
135114
if (this.options.enabled && !compilation.compiler.options.output.crossOriginLoading) {
136115
this.warnOnce(
137116
compilation,
@@ -178,32 +157,6 @@ SubresourceIntegrityPlugin.prototype.validateOptions = function validateOptions(
178157
'See http://www.w3.org/TR/SRI/#cryptographic-hash-functions for more information.');
179158
}
180159
}
181-
if (typeof this.options.crossorigin === 'undefined') {
182-
this.options.crossorigin =
183-
compilation.compiler.options.output.crossOriginLoading || 'anonymous';
184-
} else {
185-
this.warnOnce(
186-
compilation,
187-
'Specifying options.crossorigin is deprecated. ' +
188-
'Instead, set webpack option output.crossOriginLoading. ' +
189-
'Support will be removed in webpack-subresource-integrity 1.0.0. ' +
190-
'See https://github.com/waysact/webpack-subresource-integrity/issues/20 for more information.');
191-
if (typeof this.options.crossorigin !== 'string' &&
192-
!(this.options.crossorigin instanceof String)) {
193-
this.error(
194-
compilation,
195-
'options.crossorigin must be a string.');
196-
this.options.enabled = false;
197-
return;
198-
}
199-
if (standardCrossoriginOptions.indexOf(this.options.crossorigin) < 0) {
200-
this.warnOnce(
201-
compilation,
202-
'You\'ve specified a value for the crossorigin option that is not part of the set of standard values. ' +
203-
'These are: ' + standardCrossoriginOptions.join(', ') + '. ' +
204-
'See https://www.w3.org/TR/SRI/#cross-origin-data-leakage for more information.');
205-
}
206-
}
207160
};
208161

209162
/* Given a public URL path to an asset, as generated by
@@ -350,7 +303,7 @@ SubresourceIntegrityPlugin.prototype.apply = function apply(compiler) {
350303

351304
/* eslint-disable no-param-reassign */
352305
tag.attributes.integrity = checksum;
353-
tag.attributes.crossorigin = self.options.crossorigin;
306+
tag.attributes.crossorigin = compilation.compiler.options.output.crossOriginLoading || 'anonymous';
354307
/* eslint-enable no-param-reassign */
355308
}
356309

@@ -373,16 +326,6 @@ SubresourceIntegrityPlugin.prototype.apply = function apply(compiler) {
373326
return compilation.assets[src].integrity;
374327
});
375328
});
376-
Object.defineProperty(
377-
pluginArgs.plugin.options, 'sriCrossOrigin', {
378-
get: function get() {
379-
self.warnOnce(
380-
compilation,
381-
'htmlWebpackPlugin.options.sriCrossOrigin is deprecated, use webpackConfig.output.crossOriginLoading instead.'
382-
);
383-
return self.options.crossorigin;
384-
}
385-
});
386329
callback(null, pluginArgs);
387330
}
388331

test/test-webpack.js

Lines changed: 0 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -359,30 +359,6 @@ describe('plugin options', function describe() {
359359
'the set for which support is mandated by the specification'));
360360
});
361361

362-
it('supports legacy constructor with single hash function name', function it() {
363-
var plugin = new SriPlugin('sha256');
364-
var dummyCompilation = testCompilation();
365-
expect(plugin.options.hashFuncNames).toEqual(['sha256']);
366-
expect(plugin.options.deprecatedOptions).toBeTruthy();
367-
plugin.validateOptions(dummyCompilation);
368-
expect(dummyCompilation.errors.length).toBe(0);
369-
expect(dummyCompilation.warnings.length).toBe(1);
370-
expect(dummyCompilation.warnings[0].message).toMatch(
371-
/Passing a string or array to the plugin constructor is deprecated/);
372-
});
373-
374-
it('supports legacy constructor with array of hash function names', function it() {
375-
var plugin = new SriPlugin(['sha256', 'sha384']);
376-
var dummyCompilation = testCompilation();
377-
expect(plugin.options.hashFuncNames).toEqual(['sha256', 'sha384']);
378-
expect(plugin.options.deprecatedOptions).toBeTruthy();
379-
plugin.validateOptions(dummyCompilation);
380-
expect(dummyCompilation.errors.length).toBe(0);
381-
expect(dummyCompilation.warnings.length).toBe(1);
382-
expect(dummyCompilation.warnings[0].message).toMatch(
383-
/Passing a string or array to the plugin constructor is deprecated/);
384-
});
385-
386362
it('supports new constructor with array of hash function names', function it() {
387363
var plugin = new SriPlugin({
388364
hashFuncNames: ['sha256', 'sha384']
@@ -434,69 +410,6 @@ describe('plugin options', function describe() {
434410
expect(plugin.options.enabled).toBeFalsy();
435411
});
436412

437-
it('errors if the crossorigin attribute is not a string', function it() {
438-
var plugin = new SriPlugin({
439-
hashFuncNames: ['sha256'],
440-
crossorigin: 1234
441-
});
442-
var dummyCompilation = testCompilation();
443-
expect(plugin.options.hashFuncNames).toEqual(['sha256']);
444-
expect(plugin.options.deprecatedOptions).toBeFalsy();
445-
plugin.validateOptions(dummyCompilation);
446-
expect(dummyCompilation.errors.length).toBe(1);
447-
expect(dummyCompilation.warnings.length).toBe(1);
448-
expect(dummyCompilation.errors[0].message).toMatch(
449-
/options.crossorigin must be a string./);
450-
expect(dummyCompilation.warnings[0].message).toMatch(
451-
/set webpack option output.crossOriginLoading/);
452-
});
453-
454-
it('warns if the crossorigin attribute is not recognized', function it() {
455-
var plugin = new SriPlugin({
456-
hashFuncNames: ['sha256'],
457-
crossorigin: 'foo'
458-
});
459-
var dummyCompilation = testCompilation();
460-
461-
expect(plugin.options.hashFuncNames).toEqual(['sha256']);
462-
expect(plugin.options.crossorigin).toBe('foo');
463-
expect(plugin.options.deprecatedOptions).toBeFalsy();
464-
plugin.validateOptions(dummyCompilation);
465-
expect(dummyCompilation.errors.length).toBe(0);
466-
expect(dummyCompilation.warnings.length).toBe(2);
467-
expect(dummyCompilation.warnings[0].message).toMatch(
468-
/set webpack option output.crossOriginLoading/);
469-
expect(dummyCompilation.warnings[1].message).toMatch(new RegExp(
470-
'specified a value for the crossorigin option that is not part of ' +
471-
'the set of standard values'));
472-
});
473-
474-
it('accepts anonymous crossorigin without warning about standard values', function it() {
475-
var plugin = new SriPlugin({
476-
hashFuncNames: ['sha256'],
477-
crossorigin: 'anonymous'
478-
});
479-
var dummyCompilation = testCompilation();
480-
plugin.validateOptions(dummyCompilation);
481-
expect(dummyCompilation.errors.length).toBe(0);
482-
expect(dummyCompilation.warnings.length).toBe(1);
483-
expect(dummyCompilation.warnings[0].message).toMatch(
484-
/set webpack option output.crossOriginLoading/);
485-
});
486-
487-
it('accepts use-credentials crossorigin without warning about standard values', function it() {
488-
var plugin = new SriPlugin({
489-
hashFuncNames: ['sha256'],
490-
crossorigin: 'use-credentials'
491-
});
492-
var dummyCompilation = testCompilation();
493-
plugin.validateOptions(dummyCompilation);
494-
expect(dummyCompilation.errors.length).toBe(0);
495-
expect(dummyCompilation.warnings.length).toBe(1);
496-
expect(dummyCompilation.warnings[0].message).toMatch(
497-
/set webpack option output.crossOriginLoading/);
498-
});
499-
500413
it('uses default options', function it() {
501414
var plugin = new SriPlugin({
502415
hashFuncNames: ['sha256']
@@ -507,7 +420,6 @@ describe('plugin options', function describe() {
507420
expect(plugin.options.deprecatedOptions).toBeFalsy();
508421
dummyCompilation = testCompilation();
509422
plugin.validateOptions(dummyCompilation);
510-
expect(plugin.options.crossorigin).toBe('anonymous');
511423
expect(dummyCompilation.errors.length).toBe(0);
512424
expect(dummyCompilation.warnings.length).toBe(0);
513425
});
@@ -633,53 +545,6 @@ describe('html-webpack-plugin', function describe() {
633545
});
634546
});
635547

636-
it('should use the crossorigin configuration option', function it(callback) {
637-
var tmpDir = tmp.dirSync();
638-
var webpackConfig;
639-
var handler;
640-
var scripts;
641-
var parser;
642-
function cleanup() {
643-
fs.unlinkSync(path.join(tmpDir.name, 'index.html'));
644-
fs.unlinkSync(path.join(tmpDir.name, 'bundle.js'));
645-
tmpDir.removeCallback();
646-
}
647-
webpackConfig = {
648-
entry: path.join(__dirname, './dummy.js'),
649-
output: {
650-
path: tmpDir.name,
651-
filename: 'bundle.js',
652-
crossOriginLoading: 'anonymous'
653-
},
654-
plugins: [
655-
new HtmlWebpackPlugin(),
656-
new SriPlugin({ hashFuncNames: ['sha256'], crossorigin: 'foo' })
657-
]
658-
};
659-
webpack(webpackConfig, function webpackCallback(err) {
660-
if (err) {
661-
cleanup();
662-
callback(err);
663-
}
664-
665-
handler = new htmlparser.DefaultHandler(function htmlparserCallback(error, dom) {
666-
if (error) {
667-
cleanup();
668-
callback(error);
669-
} else {
670-
scripts = select(dom, 'script');
671-
expect(scripts.length).toEqual(1);
672-
expect(scripts[0].attribs.crossorigin).toEqual('foo');
673-
674-
cleanup();
675-
callback();
676-
}
677-
});
678-
parser = new htmlparser.Parser(handler);
679-
parser.parseComplete(fs.readFileSync(path.join(tmpDir.name, 'index.html'), 'utf-8'));
680-
});
681-
});
682-
683548
it('should work with subdirectories', function it(callback) {
684549
var tmpDir = tmp.dirSync();
685550
var webpackConfig;
@@ -737,42 +602,6 @@ describe('html-webpack-plugin', function describe() {
737602
});
738603
});
739604

740-
it('should warn when calling htmlWebpackPlugin.options.sriCrossOrigin', function it(callback) {
741-
var tmpDir = tmp.dirSync();
742-
var indexEjs = path.join(tmpDir.name, 'index.ejs');
743-
var webpackConfig;
744-
function cleanup(err) {
745-
fs.unlinkSync(indexEjs);
746-
fs.unlinkSync(path.join(tmpDir.name, 'bundle.js'));
747-
fs.unlinkSync(path.join(tmpDir.name, 'index.html'));
748-
tmpDir.removeCallback();
749-
callback(err);
750-
}
751-
fs.writeFileSync(indexEjs, '<% htmlWebpackPlugin.options.sriCrossOrigin %>');
752-
webpackConfig = {
753-
entry: path.join(__dirname, './dummy.js'),
754-
output: {
755-
filename: 'bundle.js',
756-
path: tmpDir.name,
757-
crossOriginLoading: 'anonymous'
758-
},
759-
plugins: [
760-
new HtmlWebpackPlugin({
761-
template: indexEjs
762-
}),
763-
new SriPlugin({ hashFuncNames: ['sha256', 'sha384'] })
764-
]
765-
};
766-
webpack(webpackConfig, function webpackCallback(err, result) {
767-
expect(result.compilation.warnings.length).toEqual(1);
768-
expect(result.compilation.warnings[0]).toBeAn(Error);
769-
expect(result.compilation.warnings[0].message).toEqual(
770-
'webpack-subresource-integrity: htmlWebpackPlugin.options.sriCrossOrigin is deprecated, use webpackConfig.output.crossOriginLoading instead.'
771-
);
772-
cleanup(err);
773-
});
774-
});
775-
776605
it('should work with subdirectories and a custom template', function it(callback) {
777606
var tmpDir = tmp.dirSync();
778607
var webpackConfig;

0 commit comments

Comments
 (0)