Skip to content

Commit 633216c

Browse files
committed
replace node-sass peer dependency with ensureRequire
1 parent b5f7df3 commit 633216c

File tree

6 files changed

+1429
-7
lines changed

6 files changed

+1429
-7
lines changed

lib/process-style/scss.js renamed to lib/compilers/scss-compiler.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
const path = require('path')
22
const fs = require('fs')
3-
const sass = require('node-sass')
3+
const ensureRequire = require('../ensure-require')
4+
const cwd = process.cwd()
45

56
const rewriteImports = (content, filePath) => content.replace(/@import\s+(?:'([^']+)'|"([^"]+)"|([^\s;]+))/g, (entire, single, double, unquoted) => {
67
const oldImportPath = single || double || unquoted
78
const absoluteImportPath = path.join(path.dirname(filePath), oldImportPath)
89
const lastCharacter = entire[entire.length - 1]
910
const quote = lastCharacter === "'" || lastCharacter === '"' ? lastCharacter : ''
10-
const importPath = path.relative(process.cwd(), absoluteImportPath)
11+
const importPath = path.relative(cwd, absoluteImportPath)
1112
return '@import ' + quote + importPath + quote
1213
})
1314

1415
module.exports = (content, filePath, config) => {
16+
ensureRequire('scss', ['node-sass'])
17+
const sass = require('node-sass')
18+
1519
let scssResources = ''
16-
if (config.resources && config.resources.scss) {
20+
if (config && config.resources && config.resources.scss) {
1721
scssResources = config.resources.scss
1822
.map(scssResource => path.resolve(process.cwd(), scssResource))
1923
.filter(scssResourcePath => fs.existsSync(scssResourcePath))
File renamed without changes.

lib/process-style/index.js renamed to lib/process-style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const cssExtract = require('extract-from-css')
33
module.exports = function processStyle (stylePart, filePath, config) {
44
if (!stylePart) return {}
55

6-
const processStyleByLang = lang => require('./' + lang)(stylePart.content, filePath, config)
6+
const processStyleByLang = lang => require('./compilers/' + lang + '-compiler')(stylePart.content, filePath, config)
77

88
let cssCode = stylePart.content
99
switch (stylePart.lang) {

0 commit comments

Comments
 (0)