Skip to content

Commit

Permalink
fix plugin-sass partial loading
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Dec 10, 2020
1 parent 14d2274 commit 64024cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions plugins/plugin-sass/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ module.exports = function sassPlugin(_, {native, compilerOptions = {}} = {}) {
async load({filePath, isDev}) {
const fileExt = path.extname(filePath);
const contents = fs.readFileSync(filePath, 'utf8');

// Sass partials should never be loaded directly, return nothing to ignore.
if (path.basename(filePath).startsWith('_')) {
return;
}

// During development, we need to track changes to Sass dependencies.
if (isDev) {
const sassImports = scanSassImports(contents, filePath, fileExt);
Expand Down
10 changes: 9 additions & 1 deletion plugins/plugin-sass/test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const plugin = require('../plugin.js');
const path = require('path');

const pathToSassApp = path.join(__dirname, 'fixtures/sass/App.sass');
const pathToSassBase = path.join(__dirname, 'fixtures/sass/base.sass');
const pathToSassBase = path.join(__dirname, 'fixtures/sass/_base.sass');
const pathToScssApp = path.join(__dirname, 'fixtures/scss/App.scss');
const pathToBadCode = path.join(__dirname, 'fixtures/bad/bad.scss');

Expand All @@ -15,6 +15,14 @@ describe('plugin-sass', () => {
expect(scssResult).toMatchSnapshot('App.scss');
});

test('returns undefined when a sass partial is loaded directly', async () => {
const p = plugin(null, {});
const devResult = await p.load({filePath: pathToSassBase, isDev: false});
expect(devResult).toEqual(undefined);
const prodResult = await p.load({filePath: pathToSassBase, isDev: true});
expect(prodResult).toEqual(undefined);
});

test('throws an error when stderr output is returned', async () => {
const p = plugin(null, {});
await expect(p.load({filePath: pathToBadCode, isDev: false})).rejects.toThrow(
Expand Down

0 comments on commit 64024cc

Please sign in to comment.