Skip to content

Commit 4e68a5f

Browse files
refactor: code (#232)
1 parent da566a6 commit 4e68a5f

13 files changed

+205
-235
lines changed

.eslintignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/coverage
22
/dist
3+
/bench
34
/node_modules
4-
/test/fixtures
5+
/test/fixtures

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
root: true,
33
extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'],
4-
};
4+
};

README.md

+40-36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# stylus-loader
2+
23
A [stylus](http://learnboost.github.io/stylus/) loader for [webpack](https://github.com/webpack/webpack).
34

45
[![build status](https://secure.travis-ci.org/shama/stylus-loader.svg)](https://travis-ci.org/shama/stylus-loader)
@@ -29,10 +30,13 @@ Or within the webpack config:
2930

3031
```js
3132
module: {
32-
loaders: [{
33-
test: /\.styl$/,
34-
loader: 'css-loader!stylus-loader?paths=node_modules/bootstrap-stylus/stylus/'
35-
}]
33+
loaders: [
34+
{
35+
test: /\.styl$/,
36+
loader:
37+
'css-loader!stylus-loader?paths=node_modules/bootstrap-stylus/stylus/',
38+
},
39+
];
3640
}
3741
```
3842

@@ -43,8 +47,8 @@ Use in tandem with the [style-loader](https://github.com/webpack/style-loader) t
4347
```js
4448
module: {
4549
loaders: [
46-
{ test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' }
47-
]
50+
{ test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' },
51+
];
4852
}
4953
```
5054

@@ -55,7 +59,7 @@ and then `require('./file.styl');` will compile and add the CSS to your page.
5559
```js
5660
module: {
5761
resolve: {
58-
extensions: ['', '.js', '.styl']
62+
extensions: ['', '.js', '.styl'];
5963
}
6064
}
6165
```
@@ -82,7 +86,6 @@ stylus: {
8286

8387
Multiple configs can be used by giving other configs different names and referring to the with the `config` query option.
8488

85-
8689
```js
8790
var stylus_plugin = require('stylus_plugin');
8891
module: {
@@ -194,38 +197,39 @@ npm test
194197
open http://localhost:8080/test/
195198
```
196199

197-
198200
## Contributing
201+
199202
In lieu of a formal styleguide, take care to maintain the existing coding style.
200203

201204
## Release History
202-
* Please see https://github.com/shama/stylus-loader/releases
203-
* 3.0.1 - Update install instructions mentioning how to get a version supporting webpack 1 (@mzgoddard)
204-
* 3.0.0 - Fix loader-utils deprecation warning (@ryani33), Drop webpack 1 and Node<4 support (@mzgoddard)
205-
* 2.5.1 - Fix paths mutation in options (@vio)
206-
* 2.5.0 - Define paths in global stylusOptions, in addtion to query params (@JounQin)
207-
* 2.4.0 - Add OptionsPlugin to help support webpack 2 (@mzgoddard)
208-
* 2.3.1 - Fix typo in README (@stevewillard)
209-
* 2.3.0 - Fix most use cases of relative path resolving (@mzgoddard), Add option to prefer a path resolver (webpack or stylus) (@mzgoddard)
210-
* 2.2.0 - Let stylus use option be just a function (@yuffiy), Track json calls as imports like use calls (@gnarf)
211-
* 2.1.2 - Fix support for stylus include config (@andrewburgess), Add block-level imports to listimports (@kenaniah)
212-
* 2.1.1 - Support Node 6 (@yyx990803), Test in webpack 1 and 2 (@phyllisstein)
213-
* 2.1.0 - Add support for stylus's include and set (@michaek)
214-
* 2.0.1 - Add peer dependency on stylus (@jchitel), fix PathCache for webpack 2 (@Unhelpful)
215-
* 2.0.0 - Remove dependency on stylus (@kossnocorps)
216-
* 1.6.1 - Remove version breaking change in 1.6.0
217-
* 1.6.0 - Remove dependency on stylus (@kossnocorps)
218-
* 1.3.0 - resolve use() calls (@mzgoddard), manual imports through path cache (@mzgoddard)
219-
* 1.2.0 - files in package.json (@SimenB), test running with testem (@mzgoddard), and some performance changes (@mzgoddard)
220-
* 1.1.0 - Pass through sourceMap option to stylus instead of defaulting to inline. Inherit source-map from devtool (@jordansexton).
221-
* 1.0.0 - Basic source map support (@skozin). Remove nib as dep. stylus is now a direct dep (as peerDependencies are deprecated).
222-
* 0.6.0 - Support loader prefixes when resolving paths (@kpdecker).
223-
* 0.5.0 - Disable Stylus parser caching in listImports (@DaQuirm). Update to [email protected] and [email protected] as peerDependencies (@kompot).
224-
* 0.4.0 - Allow configuration of plugins through webpack config (@bobzoller). Update to stylus 0.47.2 (@shanewilson).
225-
* 0.3.1 - Fix when dependency (@tkellen)
226-
* 0.3.0 - Define url resolver() when "resolve url" option is true (@mzgoddard).
227-
* 0.2.0 - Now tracks dependencies for @import statements making cacheable work. Update stylus dep.
228-
* 0.1.0 - Initial release
205+
206+
- Please see https://github.com/shama/stylus-loader/releases
207+
- 3.0.1 - Update install instructions mentioning how to get a version supporting webpack 1 (@mzgoddard)
208+
- 3.0.0 - Fix loader-utils deprecation warning (@ryani33), Drop webpack 1 and Node<4 support (@mzgoddard)
209+
- 2.5.1 - Fix paths mutation in options (@vio)
210+
- 2.5.0 - Define paths in global stylusOptions, in addtion to query params (@JounQin)
211+
- 2.4.0 - Add OptionsPlugin to help support webpack 2 (@mzgoddard)
212+
- 2.3.1 - Fix typo in README (@stevewillard)
213+
- 2.3.0 - Fix most use cases of relative path resolving (@mzgoddard), Add option to prefer a path resolver (webpack or stylus) (@mzgoddard)
214+
- 2.2.0 - Let stylus use option be just a function (@yuffiy), Track json calls as imports like use calls (@gnarf)
215+
- 2.1.2 - Fix support for stylus include config (@andrewburgess), Add block-level imports to listimports (@kenaniah)
216+
- 2.1.1 - Support Node 6 (@yyx990803), Test in webpack 1 and 2 (@phyllisstein)
217+
- 2.1.0 - Add support for stylus's include and set (@michaek)
218+
- 2.0.1 - Add peer dependency on stylus (@jchitel), fix PathCache for webpack 2 (@Unhelpful)
219+
- 2.0.0 - Remove dependency on stylus (@kossnocorps)
220+
- 1.6.1 - Remove version breaking change in 1.6.0
221+
- 1.6.0 - Remove dependency on stylus (@kossnocorps)
222+
- 1.3.0 - resolve use() calls (@mzgoddard), manual imports through path cache (@mzgoddard)
223+
- 1.2.0 - files in package.json (@SimenB), test running with testem (@mzgoddard), and some performance changes (@mzgoddard)
224+
- 1.1.0 - Pass through sourceMap option to stylus instead of defaulting to inline. Inherit source-map from devtool (@jordansexton).
225+
- 1.0.0 - Basic source map support (@skozin). Remove nib as dep. stylus is now a direct dep (as peerDependencies are deprecated).
226+
- 0.6.0 - Support loader prefixes when resolving paths (@kpdecker).
227+
- 0.5.0 - Disable Stylus parser caching in listImports (@DaQuirm). Update to [email protected] and [email protected] as peerDependencies (@kompot).
228+
- 0.4.0 - Allow configuration of plugins through webpack config (@bobzoller). Update to stylus 0.47.2 (@shanewilson).
229+
- 0.3.1 - Fix when dependency (@tkellen)
230+
- 0.3.0 - Define url resolver() when "resolve url" option is true (@mzgoddard).
231+
- 0.2.0 - Now tracks dependencies for @import statements making cacheable work. Update stylus dep.
232+
- 0.1.0 - Initial release
229233

230234
## License
231235

bench/index.js

+82-76
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ var when = require('when');
1313
var importWebpackConfig = require('./fixtures/imports/webpack.config');
1414

1515
function resolveOnComplete(fn) {
16-
return function() {
16+
return function () {
1717
var _this = this;
1818
var args = arguments;
19-
return when.promise(function(resolve) {
19+
return when.promise(function (resolve) {
2020
var result = fn.apply(_this, args);
21-
result.on('complete', function() {
21+
result.on('complete', function () {
2222
resolve();
2323
});
2424
});
@@ -27,80 +27,86 @@ function resolveOnComplete(fn) {
2727

2828
when
2929
.resolve()
30-
.then(resolveOnComplete(function() {
31-
var suite = new Benchmark.Suite;
32-
suite
33-
.add('imports', {
34-
defer: true,
35-
fn: function(deferred) {
36-
var compiler = webpack(importWebpackConfig, function(error, stats) {
37-
deferred.resolve();
38-
});
39-
compiler.outputFileSystem = new MemoryFileSystem();
40-
},
41-
})
42-
.on('cycle', function(event) {
43-
console.log(String(event.target));
44-
})
45-
.run({ async: true });
46-
return suite;
47-
}))
48-
.then(resolveOnComplete(function() {
49-
global.n = 0;
50-
global.dirname = __dirname;
51-
global.done = function() {};
52-
var suite = new Benchmark.Suite()
53-
.add('lr imports', {
54-
defer: true,
55-
fn: function(deferred) {
56-
try {
57-
global.done = function() {
58-
global.done = function() {};
59-
deferred.resolve();
60-
};
61-
global.n++;
62-
global.fs.writeFile(global.dirname + '/fixtures/imports/aa.styl', [
63-
'.aa {',
64-
' color: #aaa;',
65-
'}',
66-
(n % 2 == 0) ? '' : ' '
67-
].join('\n'), function(error) {
68-
global.compiler.run(function() {
69-
(done || global.done)();
70-
});
71-
});
72-
} catch (error) {
73-
console.log(error);
74-
}
75-
},
30+
.then(
31+
resolveOnComplete(function () {
32+
var suite = new Benchmark.Suite();
33+
suite
34+
.add('imports', {
35+
defer: true,
36+
fn: function (deferred) {
37+
var compiler = webpack(importWebpackConfig, function (
38+
error,
39+
stats
40+
) {
41+
deferred.resolve();
42+
});
43+
compiler.outputFileSystem = new MemoryFileSystem();
44+
},
45+
})
46+
.on('cycle', function (event) {
47+
console.log(String(event.target));
48+
})
49+
.run({ async: true });
50+
return suite;
7651
})
77-
// add listeners
78-
.on('error', console.error.bind(console))
79-
.on('cycle', function(event) {
80-
console.log(String(event.target));
81-
});
52+
)
53+
.then(
54+
resolveOnComplete(function () {
55+
global.n = 0;
56+
global.dirname = __dirname;
57+
global.done = function () {};
58+
var suite = new Benchmark.Suite()
59+
.add('lr imports', {
60+
defer: true,
61+
fn: function (deferred) {
62+
try {
63+
global.done = function () {
64+
global.done = function () {};
65+
deferred.resolve();
66+
};
67+
global.n++;
68+
global.fs.writeFile(
69+
global.dirname + '/fixtures/imports/aa.styl',
70+
['.aa {', ' color: #aaa;', '}', n % 2 == 0 ? '' : ' '].join(
71+
'\n'
72+
),
73+
function (error) {
74+
global.compiler.run(function () {
75+
(done || global.done)();
76+
});
77+
}
78+
);
79+
} catch (error) {
80+
console.log(error);
81+
}
82+
},
83+
})
84+
// add listeners
85+
.on('error', console.error.bind(console))
86+
.on('cycle', function (event) {
87+
console.log(String(event.target));
88+
});
8289

83-
var webpackConfig = Object.create(importWebpackConfig);
84-
webpackConfig.watch = true;
85-
webpackConfig.keepAlive = true;
86-
webpackConfig.catch = true;
87-
var compiler = global.compiler = webpack(webpackConfig);
88-
compiler.outputFileSystem = new MemoryFileSystem();
89-
done = function() {
90-
done = null;
91-
suite.run({ 'async': true });
92-
};
93-
compiler.run(function() {
94-
(done || global.done || function() {})();
95-
});
90+
var webpackConfig = Object.create(importWebpackConfig);
91+
webpackConfig.watch = true;
92+
webpackConfig.keepAlive = true;
93+
webpackConfig.catch = true;
94+
var compiler = (global.compiler = webpack(webpackConfig));
95+
compiler.outputFileSystem = new MemoryFileSystem();
96+
done = function () {
97+
done = null;
98+
suite.run({ async: true });
99+
};
100+
compiler.run(function () {
101+
(done || global.done || function () {})();
102+
});
96103

97-
return suite;
98-
}))
99-
.then(function() {
100-
fs.writeFile(__dirname + '/fixtures/imports/aa.styl', [
101-
'.aa {',
102-
' color: #aaa;',
103-
'}',
104-
''
105-
].join('\n'));
104+
return suite;
105+
})
106+
)
107+
.then(function () {
108+
fs.writeFile(
109+
__dirname + '/fixtures/imports/aa.styl',
110+
['.aa {', ' color: #aaa;', '}', ''].join('\n')
111+
);
106112
});

commitlint.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
22
extends: ['@commitlint/config-conventional'],
3-
};
3+
};

husky.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ module.exports = {
33
'pre-commit': 'lint-staged',
44
'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
55
},
6-
};
6+
};

lint-staged.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
'*.js': ['prettier --write', 'eslint --fix', 'git add'],
33
'*.{json,md,yml,css,ts}': ['prettier --write', 'git add'],
4-
};
4+
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"security": "npm audit",
2525
"lint:prettier": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different",
2626
"lint:js": "eslint --cache .",
27-
"lint": "",
27+
"lint": "npm-run-all -l -p \"lint:**\"",
2828
"test:only": "cross-env NODE_ENV=test jest",
2929
"test:watch": "npm run test:only -- --watch",
3030
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",

0 commit comments

Comments
 (0)