Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .tape.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ module.exports = {
require('.')
),
processOptions: processOptions
},
'sass-error': {
message: 'exits cleanly on SASS syntax error',
error: {
reason: /^Missed semicolon/
},
plugin: () => require('postcss')(
require('.')
),
processOptions: processOptions
}
}
};
82 changes: 50 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,60 @@ export default postcss.plugin('postcss-sass', opts => (root, result) => {

return new Promise(
// promise sass results
(resolve, reject) => sass.render(
// pass options directly into node-sass
Object.assign({}, opts, requiredSassConfig, {
file: `${postConfig.from}#sass`,
outFile: postConfig.from,
data: postCSS,
importer(id, parentId, done) {
// resolve the absolute parent
const parent = pathResolve(parentId);
(resolve, reject) => {

// cwds is the list of all directories to search
const cwds = [dirname(parent)].concat(includePaths).map(includePath => pathResolve(includePath));
try {

let sassResult = sass.renderSync(
// pass options directly into node-sass
Object.assign({}, opts, requiredSassConfig, {
file: `${postConfig.from}#sass`,
outFile: postConfig.from,
data: postCSS,
importer(id, parentId, done) {

cwds.reduce(
// resolve the first available files
(promise, cwd) => promise.catch(
() => sassResolve(id, { cwd, cache, readFile: true })
),
Promise.reject()
).then(
({ file, contents }) => {
// push the dependency to watch tasks
result.messages.push({ type: 'dependency', file, parent });
// resolve the absolute parent
const parent = pathResolve(parentId);

// pass the file and contents back to sass
done({ file, contents });
},
importerError => {
// otherwise, pass the error
done(importerError);
// cwds is the list of all directories to search
const cwds = [dirname(parent)].concat(includePaths).map(includePath => pathResolve(includePath));

cwds.reduce(
// resolve the first available files
(promise, cwd) => promise.catch(
() => sassResolve(id, { cwd, cache, readFile: true })
),
Promise.reject()
).then(
({ file, contents }) => {
// push the dependency to watch tasks
result.messages.push({ type: 'dependency', file, parent });

// pass the file and contents back to sass
if(done) {
// done is undefined, for example, when SASS issues a (deprecation) warning
// anything else to be done here?
done({ file, contents });
}
},
importerError => {
// otherwise, pass the error
done(importerError);
}
);
}
);
}
}),
(sassError, sassResult) => sassError ? reject(sassError) : resolve(sassResult)
)
})
);

resolve(sassResult);

} catch(sassError){

reject(sassError);

}

}
).then(
({ css: sassCSS, map: sassMap }) => {
// update root to post-node-sass ast
Expand Down
3 changes: 3 additions & 0 deletions test/sass-error.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$var1: hi
$var2: there;