Skip to content

Commit 782a9c9

Browse files
committed
satisfy eslint
1 parent 583ec9c commit 782a9c9

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

lib/load-config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const path = require('path')
2+
const fs = require('fs')
23

34
module.exports = function loadConfig () {
4-
5-
let initConfig = {
5+
const initConfig = {
66
resources: {}
77
}
88

99
const rootPJSONPath = path.resolve(process.cwd(), 'package.json')
1010
if (!fs.existsSync(rootPJSONPath)) return initConfig
11-
11+
1212
const vueJestConfig = require(rootPJSONPath).vueJest
1313

1414
return Object.assign(initConfig, vueJestConfig)
15-
}
15+
}

lib/process-style/scss.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,31 @@ const sass = require('node-sass')
44
const cwd = process.cwd()
55

66
module.exports = (content, dir, config) => {
7-
87
const getRelativeImportPath = (oldImportPath, absoluteImportPath) => (/^\~/.test(oldImportPath))
98
? oldImportPath
10-
: path.relative(cwd, absoluteImportPath);
9+
: path.relative(cwd, absoluteImportPath)
1110

12-
const scssResources = (!config.resources || !config.resources.scss)
13-
? ''
14-
: config.resources.scss
15-
.map(scssResource => path.resolve(cwd, scssResource))
16-
.filter(scssResourcePath => fs.existsSync(scssResourcePath))
17-
.map(scssResourcePath => fs.readFileSync(scssResourcePath).toString()
18-
.replace(/@import\s+(?:'([^']+)'|"([^"]+)"|([^\s;]+))/g, (entire, single, double, unquoted) => {
19-
var oldImportPath = single || double || unquoted;
20-
var absoluteImportPath = path.join(path.dirname(scssResourcePath), oldImportPath);
21-
var relImportPath = getRelativeImportPath(oldImportPath, absoluteImportPath);
22-
var newImportPath = relImportPath.split(path.sep).join('/');
23-
var lastCharacter = entire[entire.length - 1];
24-
var quote = lastCharacter === "'" || lastCharacter === '"' ? lastCharacter : '';
25-
return '@import ' + quote + newImportPath + quote;
26-
})
27-
)
28-
.join('\n')
11+
let scssResources = ''
12+
if (config.resources && config.resources.scss) {
13+
scssResources = config.resources.scss
14+
.map(scssResource => path.resolve(cwd, scssResource))
15+
.filter(scssResourcePath => fs.existsSync(scssResourcePath))
16+
.map(scssResourcePath => fs.readFileSync(scssResourcePath).toString()
17+
.replace(/@import\s+(?:'([^']+)'|"([^"]+)"|([^\s;]+))/g, (entire, single, double, unquoted) => {
18+
const oldImportPath = single || double || unquoted
19+
const absoluteImportPath = path.join(path.dirname(scssResourcePath), oldImportPath)
20+
const relImportPath = getRelativeImportPath(oldImportPath, absoluteImportPath)
21+
const newImportPath = relImportPath.split(path.sep).join('/')
22+
const lastCharacter = entire[entire.length - 1]
23+
const quote = lastCharacter === "'" || lastCharacter === '"' ? lastCharacter : ''
24+
return '@import ' + quote + newImportPath + quote
25+
})
26+
)
27+
.join('\n')
28+
}
2929

3030
return sass.renderSync({
3131
data: scssResources + content,
3232
outputStyle: 'compressed'
3333
}).css.toString()
34-
35-
}
34+
}

lib/process-style/stylus.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
const stylus = require('stylus')
2-
module.exports = (content, dir, config) => stylus.render(content, { paths: [dir, process.cwd()] })
2+
module.exports = (content, dir, config) => stylus.render(content, { paths: [dir, process.cwd()] })

lib/process.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const processStyle = require('./process-style')
1010
const fs = require('fs')
1111
const path = require('path')
1212
const join = path.join
13-
const cssExtract = require('extract-from-css')
1413
const logger = require('./logger')
1514
const splitRE = /\r?\n/g
1615
const config = require('./load-config')()
@@ -92,7 +91,7 @@ module.exports = function (src, filePath) {
9291
const styleObj = (/^sass|less|pcss|postcss/.test(ast.lang))
9392
? {}
9493
: processStyle(ast, filePath, config)
95-
94+
9695
const moduleName = ast.module === true ? '$style' : ast.module
9796

9897
return '\n this[\'' + moduleName + '\'] = ' + JSON.stringify(styleObj)

0 commit comments

Comments
 (0)