Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
fix: handle files with query params
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Mar 6, 2018
1 parent 14d2c4c commit d9f4e24
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UglifyJsPlugin {

const {
uglifyOptions = {},
test = /\.js$/i,
test = /.((js)?)(\?[a-z0-9]+)?$/i,
warningsFilter = () => true,
extractComments = false,
sourceMap = false,
Expand Down
13 changes: 13 additions & 0 deletions test/__snapshots__/test.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`empty option: errors 1`] = `Array []`;

exports[`empty option: importExport.js?var=c3528f4503928cc8accd 1`] = `"webpackJsonp([0],[,,function(t,a,e){\\"use strict\\";Object.defineProperty(a,\\"__esModule\\",{value:!0});var n=e(3);a.default=function(){const t=n.b,a=\`baz\${Math.random()}\`;return()=>({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[2]);"`;
exports[`empty option: js.js?var=c3528f4503928cc8accd 1`] = `"webpackJsonp([2],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`;
exports[`empty option: manifest.js?var=c3528f4503928cc8accd 1`] = `"!function(e){var r=window.webpackJsonp;window.webpackJsonp=function(n,c,i){for(var u,a,f,s=0,p=[];s<n.length;s++)a=n[s],t[a]&&p.push(t[a][0]),t[a]=0;for(u in c)Object.prototype.hasOwnProperty.call(c,u)&&(e[u]=c[u]);for(r&&r(n,c,i);p.length;)p.shift()();if(i)for(s=0;s<i.length;s++)f=o(o.s=i[s]);return f};var n={},t={3:0};function o(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,o),t.l=!0,t.exports}o.e=function(e){var r=t[e];if(0===r)return new Promise(function(e){e()});if(r)return r[2];var n=new Promise(function(n,o){r=t[e]=[n,o]});r[2]=n;var c=document.getElementsByTagName(\\"head\\")[0],i=document.createElement(\\"script\\");i.type=\\"text/javascript\\",i.charset=\\"utf-8\\",i.async=!0,i.timeout=12e4,o.nc&&i.setAttribute(\\"nonce\\",o.nc),i.src=o.p+\\"\\"+e+\\".\\"+({0:\\"importExport\\",1:\\"mjs\\",2:\\"js\\"}[e]||e)+\\".js?ver=c3528f4503928cc8accd\\";var u=setTimeout(a,12e4);function a(){i.onerror=i.onload=null,clearTimeout(u);var r=t[e];0!==r&&(r&&r[1](new Error(\\"Loading chunk \\"+e+\\" failed.\\")),t[e]=void 0)}return i.onerror=i.onload=a,c.appendChild(i),n},o.m=e,o.c=n,o.d=function(e,r,n){o.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},o.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(r,\\"a\\",r),r},o.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},o.p=\\"\\",o.oe=function(e){throw console.error(e),e}}([]);"`;
exports[`empty option: mjs.js?var=c3528f4503928cc8accd 1`] = `"webpackJsonp([1],[,function(o,n){o.exports=function(){console.log(7)}}],[1]);"`;
exports[`empty option: warnings 1`] = `Array []`;
9 changes: 9 additions & 0 deletions test/fixtures/entry.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// foo
/* @preserve*/
// bar
const a = 2 + 2;

module.exports = function Foo() {
const b = 2 + 2;
console.log(b + 1 + 2);
};
39 changes: 39 additions & 0 deletions test/test.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import UglifyJsPlugin from '../src/index';
import {
cleanErrorStack,
createCompiler,
compile,
} from './helpers';

describe('when applied with test option', () => {
it('with empty value', () => {
const compiler = createCompiler({
entry: {
js: `${__dirname}/fixtures/entry.js`,
mjs: `${__dirname}/fixtures/entry.mjs`,
importExport: `${__dirname}/fixtures/import-export/entry.js`,
},
output: {
path: `${__dirname}/dist`,
filename: '[name].js?var=[hash]',
chunkFilename: '[id].[name].js?ver=[hash]',
},
});

new UglifyJsPlugin().apply(compiler);

return compile(compiler).then((stats) => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);

expect(errors).toMatchSnapshot('empty option: errors');
expect(warnings).toMatchSnapshot('empty option: warnings');

for (const file in stats.compilation.assets) {
if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) {
expect(stats.compilation.assets[file].source()).toMatchSnapshot(`empty option: ${file}`);
}
}
});
});
});

0 comments on commit d9f4e24

Please sign in to comment.