From 2ae77eea821067c601c44663ddb1b8e9a71735f5 Mon Sep 17 00:00:00 2001 From: simbekkh Date: Thu, 23 Nov 2017 13:38:44 +0100 Subject: [PATCH] fix: change bundle's id to just be hash of content Previusly the hash was determined by the name and version of the module, in addition to the path to and content of the file. We now just look at the content BREAKING CHANGE: Hashing stretegy has changed --- lib/writer.js | 4 +--- test/writer.test.js | 25 +++++-------------------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/lib/writer.js b/lib/writer.js index 2c31c9c..75b97e9 100644 --- a/lib/writer.js +++ b/lib/writer.js @@ -27,9 +27,7 @@ class Stream extends Readable { bundleCssModule(file), identifyCssModule(file), ]); - meta.id = hasher( - `${meta.name}|${meta.version}|${meta.file}|${css}` - ); + meta.id = hasher(css); meta.content = css; this.push(meta); } catch (err) { diff --git a/test/writer.test.js b/test/writer.test.js index b275b93..81f0729 100644 --- a/test/writer.test.js +++ b/test/writer.test.js @@ -61,7 +61,6 @@ test('bundleCssModule(filePath)', async () => { test('new Writer(filePath)', done => { expect.assertions(2); const filePath = path.join(__dirname, 'test-assets/my-module-1/main.css'); - const fileRef = 'my-module-1/main.css'; const writer = new Writer(filePath).bundle(); const items = []; @@ -73,9 +72,7 @@ test('new Writer(filePath)', done => { writer.on('end', () => { const result1 = items[0]; const result2 = items[1]; - expect(result1.id).toBe( - hasher(`my-module-1|1.0.1|${fileRef}|${result1.content}`) - ); + expect(result1.id).toBe(hasher(result1.content)); expect(result2).toBeFalsy(); done(); }); @@ -118,7 +115,6 @@ test('new Writer(filePath) relative paths throw error', () => { test('new Writer([filePath])', done => { expect.assertions(2); const filePath = path.join(__dirname, 'test-assets/my-module-1/main.css'); - const fileRef = 'my-module-1/main.css'; const writer = new Writer([filePath]).bundle(); const items = []; @@ -130,9 +126,7 @@ test('new Writer([filePath])', done => { writer.on('end', () => { const result1 = items[0]; const result2 = items[1]; - expect(result1.id).toBe( - hasher(`my-module-1|1.0.1|${fileRef}|${result1.content}`) - ); + expect(result1.id).toBe(hasher(result1.content)); expect(result2).toBeFalsy(); done(); }); @@ -144,7 +138,6 @@ test('Writer processes @import statements', done => { __dirname, 'test-assets/my-module-3/css/main.css' ); - const fileRef = 'my-module-3/css/main.css'; const writer = new Writer([filePath]).bundle(); const items = []; @@ -157,9 +150,7 @@ test('Writer processes @import statements', done => { const result1 = items[0]; const result2 = items[1]; - expect(result1.id).toBe( - hasher(`my-module-3|1.0.1|${fileRef}|${result1.content}`) - ); + expect(result1.id).toBe(hasher(result1.content)); expect(result1.content).toMatch('my-module-3/main.css'); expect(result1.content).toMatch('my-module-3/dep.css'); expect(result1.content).toMatch('dep/main.css'); @@ -171,12 +162,10 @@ test('Writer processes @import statements', done => { test('new Writer([filePath1, filePath2]) ensures correct order', done => { expect.assertions(3); const filePath1 = path.join(__dirname, 'test-assets/my-module-1/main.css'); - const fileRef1 = 'my-module-1/main.css'; const filePath2 = path.join( __dirname, 'test-assets/my-module-2/css/main.css' ); - const fileRef2 = 'my-module-2/css/main.css'; const writer = new Writer([filePath1, filePath2]).bundle(); const items = []; @@ -190,12 +179,8 @@ test('new Writer([filePath1, filePath2]) ensures correct order', done => { const result2 = items[1]; const result3 = items[2]; - expect(result1.id).toBe( - hasher(`my-module-1|1.0.1|${fileRef1}|${result1.content}`) - ); - expect(result2.id).toBe( - hasher(`my-module-2|1.0.1|${fileRef2}|${result2.content}`) - ); + expect(result1.id).toBe(hasher(result1.content)); + expect(result2.id).toBe(hasher(result2.content)); expect(result3).toBeFalsy(); done(); });