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

Commit 3745855

Browse files
committed
style(lib): Formats files after changes to repo
1 parent 4ac05bc commit 3745855

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

lib/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const readPkgUp = require('read-pkg-up');
88
const postcss = require('postcss');
99
const atImport = require('postcss-import');
1010

11-
module.exports.identifyCssModule = async function identifyCssModule (filePath) {
11+
module.exports.identifyCssModule = async function identifyCssModule(filePath) {
1212
const { pkg: { name, version }, path: packagePath } = await readPkgUp({
1313
normalize: false,
1414
cwd: path.dirname(filePath),
@@ -18,7 +18,7 @@ module.exports.identifyCssModule = async function identifyCssModule (filePath) {
1818
return { name, version, file };
1919
};
2020

21-
module.exports.bundleCssModule = async function bundleCssModule (filePath) {
21+
module.exports.bundleCssModule = async function bundleCssModule(filePath) {
2222
const fileContents = await readFile(filePath, 'utf8');
2323
const { css } = await postcss()
2424
.use(atImport())

lib/writer.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const assert = require('assert');
88
const { hasher } = require('asset-pipe-common');
99

1010
module.exports = class Writer extends Readable {
11-
constructor (files = []) {
11+
constructor(files = []) {
1212
super({ objectMode: true });
1313

1414
assert(
@@ -17,22 +17,36 @@ module.exports = class Writer extends Readable {
1717
);
1818
this.files = Array.isArray(files) ? files : [files];
1919
for (const file of this.files) {
20-
assert(typeof file === 'string', `Expected 'file' (${file}) to be of type 'string', instead got '${typeof file}'`);
21-
assert(isAbsolute(file), `Expected 'file' (${file}) to be an absolute path to a file but it was not`);
22-
assert(existsSync(file), `Expected 'file' (${file}) to exist on file system but it did not`);
20+
assert(
21+
typeof file === 'string',
22+
`Expected 'file' (${file}) to be of type 'string', instead got '${typeof file}'`
23+
);
24+
assert(
25+
isAbsolute(file),
26+
`Expected 'file' (${file}) to be an absolute path to a file but it was not`
27+
);
28+
assert(
29+
existsSync(file),
30+
`Expected 'file' (${file}) to exist on file system but it did not`
31+
);
2332
}
2433
}
2534

26-
async _read () {
35+
async _read() {
2736
const file = this.files.shift();
2837
if (!file) {
2938
this.push(null);
3039
return;
3140
}
3241

3342
try {
34-
const [css, meta] = await Promise.all([bundleCssModule(file), identifyCssModule(file)]);
35-
meta.id = hasher(`${meta.name}|${meta.version}|${meta.file}|${css}`);
43+
const [css, meta] = await Promise.all([
44+
bundleCssModule(file),
45+
identifyCssModule(file),
46+
]);
47+
meta.id = hasher(
48+
`${meta.name}|${meta.version}|${meta.file}|${css}`
49+
);
3650
meta.content = css;
3751
this.push(meta);
3852
} catch (err) {

test/writer.test.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ test('identifyCssModule(filePath)', async () => {
2929

3030
test('identifyCssModule(filePath) css in nested directory', async () => {
3131
expect.assertions(1);
32-
const filePath = path.join(__dirname, 'test-assets/my-module-2/css/main.css');
32+
const filePath = path.join(
33+
__dirname,
34+
'test-assets/my-module-2/css/main.css'
35+
);
3336
const fileRef = 'my-module-2/css/main.css';
3437

3538
const result = await identifyCssModule(filePath);
@@ -44,7 +47,10 @@ test('identifyCssModule(filePath) css in nested directory', async () => {
4447

4548
test('bundleCssModule(filePath)', async () => {
4649
expect.assertions(3);
47-
const filePath = path.join(__dirname, 'test-assets/my-module-3/css/main.css');
50+
const filePath = path.join(
51+
__dirname,
52+
'test-assets/my-module-3/css/main.css'
53+
);
4854

4955
const result = await bundleCssModule(filePath);
5056

@@ -68,7 +74,9 @@ test('new Writer(filePath)', done => {
6874
writer.on('end', () => {
6975
const result1 = items[0];
7076
const result2 = items[1];
71-
expect(result1.id).toBe(hasher(`my-module-1|1.0.1|${fileRef}|${result1.content}`));
77+
expect(result1.id).toBe(
78+
hasher(`my-module-1|1.0.1|${fileRef}|${result1.content}`)
79+
);
7280
expect(result2).toBeFalsy();
7381
done();
7482
});
@@ -98,15 +106,20 @@ test('new Writer([filePath])', done => {
98106
writer.on('end', () => {
99107
const result1 = items[0];
100108
const result2 = items[1];
101-
expect(result1.id).toBe(hasher(`my-module-1|1.0.1|${fileRef}|${result1.content}`));
109+
expect(result1.id).toBe(
110+
hasher(`my-module-1|1.0.1|${fileRef}|${result1.content}`)
111+
);
102112
expect(result2).toBeFalsy();
103113
done();
104114
});
105115
});
106116

107117
test('Writer processes @import statements', done => {
108118
expect.assertions(5);
109-
const filePath = path.join(__dirname, 'test-assets/my-module-3/css/main.css');
119+
const filePath = path.join(
120+
__dirname,
121+
'test-assets/my-module-3/css/main.css'
122+
);
110123
const fileRef = 'my-module-3/css/main.css';
111124

112125
const writer = new Writer([filePath]);
@@ -120,7 +133,9 @@ test('Writer processes @import statements', done => {
120133
const result1 = items[0];
121134
const result2 = items[1];
122135

123-
expect(result1.id).toBe(hasher(`my-module-3|1.0.1|${fileRef}|${result1.content}`));
136+
expect(result1.id).toBe(
137+
hasher(`my-module-3|1.0.1|${fileRef}|${result1.content}`)
138+
);
124139
expect(result1.content).toMatch('my-module-3/main.css');
125140
expect(result1.content).toMatch('my-module-3/dep.css');
126141
expect(result1.content).toMatch('dep/main.css');
@@ -133,7 +148,10 @@ test('new Writer([filePath1, filePath2]) ensures correct order', done => {
133148
expect.assertions(3);
134149
const filePath1 = path.join(__dirname, 'test-assets/my-module-1/main.css');
135150
const fileRef1 = 'my-module-1/main.css';
136-
const filePath2 = path.join(__dirname, 'test-assets/my-module-2/css/main.css');
151+
const filePath2 = path.join(
152+
__dirname,
153+
'test-assets/my-module-2/css/main.css'
154+
);
137155
const fileRef2 = 'my-module-2/css/main.css';
138156

139157
const writer = new Writer([filePath1, filePath2]);
@@ -148,8 +166,12 @@ test('new Writer([filePath1, filePath2]) ensures correct order', done => {
148166
const result2 = items[1];
149167
const result3 = items[2];
150168

151-
expect(result1.id).toBe(hasher(`my-module-1|1.0.1|${fileRef1}|${result1.content}`));
152-
expect(result2.id).toBe(hasher(`my-module-2|1.0.1|${fileRef2}|${result2.content}`));
169+
expect(result1.id).toBe(
170+
hasher(`my-module-1|1.0.1|${fileRef1}|${result1.content}`)
171+
);
172+
expect(result2.id).toBe(
173+
hasher(`my-module-2|1.0.1|${fileRef2}|${result2.content}`)
174+
);
153175
expect(result3).toBeFalsy();
154176
done();
155177
});
@@ -212,10 +234,10 @@ test('new Writer([filePath]) ensures valid filePaths provided in array', () => {
212234
test('writer emits error', done => {
213235
expect.assertions(1);
214236
jest.mock('../lib/util.js', () => ({
215-
bundleCssModule () {
237+
bundleCssModule() {
216238
throw new Error();
217239
},
218-
identifyCssModule () {
240+
identifyCssModule() {
219241
throw new Error();
220242
},
221243
}));

0 commit comments

Comments
 (0)