Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
fix: change bundle's id to just be hash of content
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SimenB committed Nov 23, 2017
1 parent 5819800 commit 2ae77ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
4 changes: 1 addition & 3 deletions lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 5 additions & 20 deletions test/writer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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();
});
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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();
});
Expand All @@ -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 = [];
Expand All @@ -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');
Expand All @@ -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 = [];
Expand All @@ -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();
});
Expand Down

1 comment on commit 2ae77ee

@sveisvei
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff

Please sign in to comment.