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

Commit f61439d

Browse files
fix: more consistent cache (#385)
1 parent 15e38e8 commit f61439d

File tree

10 files changed

+1412
-3440
lines changed

10 files changed

+1412
-3440
lines changed

package-lock.json

Lines changed: 1194 additions & 3231 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,12 @@ class UglifyJsPlugin {
228228
};
229229

230230
if (this.options.cache) {
231-
const { outputPath } = compiler;
232231
const defaultCacheKeys = {
233232
// eslint-disable-next-line global-require
234233
'uglify-js': require('uglify-js/package.json').version,
235234
// eslint-disable-next-line global-require
236235
'uglifyjs-webpack-plugin': require('../package.json').version,
237236
'uglifyjs-webpack-plugin-options': this.options,
238-
path: `${outputPath ? `${outputPath}/` : ''}${file}`,
239237
hash: crypto
240238
.createHash('md4')
241239
.update(input)

test/__snapshots__/cache-option.test.js.snap

Lines changed: 163 additions & 142 deletions
Large diffs are not rendered by default.

test/__snapshots__/test-option.test.js.snap

Lines changed: 29 additions & 31 deletions
Large diffs are not rendered by default.

test/cache-option.test.js

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import path from 'path';
2-
31
import cacache from 'cacache';
42
import findCacheDir from 'find-cache-dir';
53

@@ -16,10 +14,11 @@ describe('when applied with `cache` option', () => {
1614
beforeEach(() => {
1715
compiler = createCompiler({
1816
entry: {
19-
one: `${__dirname}/fixtures/entry.js`,
20-
two: `${__dirname}/fixtures/entry.js`,
21-
three: `${__dirname}/fixtures/entry.js`,
22-
four: `${__dirname}/fixtures/entry.js`,
17+
one: `${__dirname}/fixtures/cache.js`,
18+
two: `${__dirname}/fixtures/cache-1.js`,
19+
three: `${__dirname}/fixtures/cache-2.js`,
20+
four: `${__dirname}/fixtures/cache-3.js`,
21+
five: `${__dirname}/fixtures/cache-4.js`,
2322
},
2423
});
2524

@@ -105,18 +104,6 @@ describe('when applied with `cache` option', () => {
105104
// Make sure that we cached files
106105
expect(cacheKeys.length).toBe(countAssets);
107106

108-
cacheKeys.forEach((cacheEntry) => {
109-
// eslint-disable-next-line no-new-func
110-
const cacheEntryOptions = new Function(
111-
`'use strict'\nreturn ${cacheEntry}`
112-
)();
113-
const basename = path.basename(cacheEntryOptions.path);
114-
115-
expect([basename, cacheEntryOptions.hash]).toMatchSnapshot(
116-
basename
117-
);
118-
});
119-
120107
cacache.get.mockClear();
121108
cacache.put.mockClear();
122109
})
@@ -192,18 +179,6 @@ describe('when applied with `cache` option', () => {
192179
// Make sure that we cached files
193180
expect(cacheKeys.length).toBe(countAssets);
194181

195-
cacheKeys.forEach((cacheEntry) => {
196-
// eslint-disable-next-line no-new-func
197-
const cacheEntryOptions = new Function(
198-
`'use strict'\nreturn ${cacheEntry}`
199-
)();
200-
const basename = path.basename(cacheEntryOptions.path);
201-
202-
expect([basename, cacheEntryOptions.hash]).toMatchSnapshot(
203-
basename
204-
);
205-
});
206-
207182
cacache.get.mockClear();
208183
cacache.put.mockClear();
209184
})
@@ -294,15 +269,11 @@ describe('when applied with `cache` option', () => {
294269
const cacheEntryOptions = new Function(
295270
`'use strict'\nreturn ${cacheEntry}`
296271
)();
297-
const basename = path.basename(cacheEntryOptions.path);
298272

299273
expect(cacheEntryOptions.myCacheKey).toBe(1);
300274
expect(cacheEntryOptions.myCacheKeyBasedOnFile).toMatch(
301275
/file-(.+)?\.js/
302276
);
303-
expect([basename, cacheEntryOptions.hash]).toMatchSnapshot(
304-
basename
305-
);
306277
});
307278

308279
cacache.get.mockClear();

test/fixtures/cache-1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'string';

test/fixtures/cache-2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = function getRegExp() { return /test/ };

test/fixtures/cache-3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = function foo() {};

test/fixtures/cache-4.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// foo
2+
/* @preserve*/
3+
// bar
4+
var a = 2 + 2;
5+
6+
module.exports = function Foo() {
7+
var b = 2 + 2;
8+
console.log(b + 1 + 2);
9+
};

test/fixtures/cache.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// foo
2+
/* @preserve*/
3+
// bar
4+
var a = 2 + 2;
5+
6+
module.exports = function Foo() {
7+
var b = 2 + 2;
8+
console.log(b + 1 + 2);
9+
};

0 commit comments

Comments
 (0)