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

Commit 04874dc

Browse files
author
Walker
committed
Fixes from PR feedback
1 parent f7672e8 commit 04874dc

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ language: node_js
22

33
node_js:
44
- "8"
5-
- "6"
65

76
script:
87
- npm test

lib/util.js

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,21 @@ const readPkgUp = require('read-pkg-up');
99
const postcss = require('postcss');
1010
const atImport = require('postcss-import');
1111

12-
module.exports.identifyCssModule = function identifyCssModule (filePath) {
13-
return readPkgUp({
12+
module.exports.identifyCssModule = async function identifyCssModule(filePath) {
13+
const { pkg: { name, version }, path: packagePath } = await readPkgUp({
1414
normalize: false,
15-
cwd: path.dirname(filePath),
16-
}).then(result => {
17-
const { name, version } = result.pkg;
18-
const ref = filePath.replace(path.dirname(result.path), name);
19-
20-
return {
21-
id: hasher(`${name}|${version}|${ref}`),
22-
name,
23-
version,
24-
file: ref,
25-
};
15+
cwd: path.dirname(filePath)
2616
});
17+
const file = filePath.replace(path.dirname(packagePath), name);
18+
19+
const id = hasher(`${name}|${version}|${file}`);
20+
return { id, name, version, file };
2721
};
2822

29-
module.exports.bundleCssModule = function bundleCssModule (filePath) {
30-
return readFile(filePath, 'utf8').then(css =>
31-
postcss()
32-
.use(atImport())
33-
.process(css, {
34-
from: filePath,
35-
})
36-
.then(({ css }) => css)
37-
);
23+
module.exports.bundleCssModule = async function bundleCssModule(filePath) {
24+
const fileContents = await readFile(filePath, 'utf8');
25+
const { css } = await postcss()
26+
.use(atImport())
27+
.process(fileContents, { from: filePath });
28+
return css;
3829
};

lib/writer.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { isAbsolute } = require('path');
77
const assert = require('assert');
88

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

1313
assert(
@@ -22,19 +22,19 @@ module.exports = class Writer extends Readable {
2222
}
2323
}
2424

25-
_read () {
25+
async _read() {
2626
const file = this.files.shift();
2727
if (!file) {
2828
this.push(null);
2929
return;
3030
}
31-
Promise.all([bundleCssModule(file), identifyCssModule(file)])
32-
.then(([css, meta]) => {
33-
meta.content = css;
34-
this.push(meta);
35-
})
36-
.catch(err => {
37-
process.nextTick(() => this.emit('error', err));
38-
});
31+
32+
try {
33+
const [css, meta] = await Promise.all([bundleCssModule(file), identifyCssModule(file)]);
34+
meta.content = css;
35+
this.push(meta);
36+
} catch (err) {
37+
this.emit('error', err);
38+
}
3939
}
4040
};

test/writer.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ test('new Writer(filePath)', () => {
5959
writer.on('end', () => {
6060
const result1 = items[0];
6161
const result2 = items[1];
62-
6362
expect(result1.id).toBe(hasher(`my-module-1|1.0.1|${fileRef}`));
6463
expect(result2).toBeFalsy();
6564
});
@@ -87,7 +86,6 @@ test('new Writer([filePath])', () => {
8786
writer.on('end', () => {
8887
const result1 = items[0];
8988
const result2 = items[1];
90-
9189
expect(result1.id).toBe(hasher(`my-module-1|1.0.1|${fileRef}`));
9290
expect(result2).toBeFalsy();
9391
});

0 commit comments

Comments
 (0)