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

Commit 2ae77ee

Browse files
committed
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
1 parent 5819800 commit 2ae77ee

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

lib/writer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ class Stream extends Readable {
2727
bundleCssModule(file),
2828
identifyCssModule(file),
2929
]);
30-
meta.id = hasher(
31-
`${meta.name}|${meta.version}|${meta.file}|${css}`
32-
);
30+
meta.id = hasher(css);
3331
meta.content = css;
3432
this.push(meta);
3533
} catch (err) {

test/writer.test.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ test('bundleCssModule(filePath)', async () => {
6161
test('new Writer(filePath)', done => {
6262
expect.assertions(2);
6363
const filePath = path.join(__dirname, 'test-assets/my-module-1/main.css');
64-
const fileRef = 'my-module-1/main.css';
6564

6665
const writer = new Writer(filePath).bundle();
6766
const items = [];
@@ -73,9 +72,7 @@ test('new Writer(filePath)', done => {
7372
writer.on('end', () => {
7473
const result1 = items[0];
7574
const result2 = items[1];
76-
expect(result1.id).toBe(
77-
hasher(`my-module-1|1.0.1|${fileRef}|${result1.content}`)
78-
);
75+
expect(result1.id).toBe(hasher(result1.content));
7976
expect(result2).toBeFalsy();
8077
done();
8178
});
@@ -118,7 +115,6 @@ test('new Writer(filePath) relative paths throw error', () => {
118115
test('new Writer([filePath])', done => {
119116
expect.assertions(2);
120117
const filePath = path.join(__dirname, 'test-assets/my-module-1/main.css');
121-
const fileRef = 'my-module-1/main.css';
122118

123119
const writer = new Writer([filePath]).bundle();
124120
const items = [];
@@ -130,9 +126,7 @@ test('new Writer([filePath])', done => {
130126
writer.on('end', () => {
131127
const result1 = items[0];
132128
const result2 = items[1];
133-
expect(result1.id).toBe(
134-
hasher(`my-module-1|1.0.1|${fileRef}|${result1.content}`)
135-
);
129+
expect(result1.id).toBe(hasher(result1.content));
136130
expect(result2).toBeFalsy();
137131
done();
138132
});
@@ -144,7 +138,6 @@ test('Writer processes @import statements', done => {
144138
__dirname,
145139
'test-assets/my-module-3/css/main.css'
146140
);
147-
const fileRef = 'my-module-3/css/main.css';
148141

149142
const writer = new Writer([filePath]).bundle();
150143
const items = [];
@@ -157,9 +150,7 @@ test('Writer processes @import statements', done => {
157150
const result1 = items[0];
158151
const result2 = items[1];
159152

160-
expect(result1.id).toBe(
161-
hasher(`my-module-3|1.0.1|${fileRef}|${result1.content}`)
162-
);
153+
expect(result1.id).toBe(hasher(result1.content));
163154
expect(result1.content).toMatch('my-module-3/main.css');
164155
expect(result1.content).toMatch('my-module-3/dep.css');
165156
expect(result1.content).toMatch('dep/main.css');
@@ -171,12 +162,10 @@ test('Writer processes @import statements', done => {
171162
test('new Writer([filePath1, filePath2]) ensures correct order', done => {
172163
expect.assertions(3);
173164
const filePath1 = path.join(__dirname, 'test-assets/my-module-1/main.css');
174-
const fileRef1 = 'my-module-1/main.css';
175165
const filePath2 = path.join(
176166
__dirname,
177167
'test-assets/my-module-2/css/main.css'
178168
);
179-
const fileRef2 = 'my-module-2/css/main.css';
180169

181170
const writer = new Writer([filePath1, filePath2]).bundle();
182171
const items = [];
@@ -190,12 +179,8 @@ test('new Writer([filePath1, filePath2]) ensures correct order', done => {
190179
const result2 = items[1];
191180
const result3 = items[2];
192181

193-
expect(result1.id).toBe(
194-
hasher(`my-module-1|1.0.1|${fileRef1}|${result1.content}`)
195-
);
196-
expect(result2.id).toBe(
197-
hasher(`my-module-2|1.0.1|${fileRef2}|${result2.content}`)
198-
);
182+
expect(result1.id).toBe(hasher(result1.content));
183+
expect(result2.id).toBe(hasher(result2.content));
199184
expect(result3).toBeFalsy();
200185
done();
201186
});

0 commit comments

Comments
 (0)