Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
jgerigmeyer committed Feb 23, 2024
1 parent b2c49ae commit 6da9413
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,8 @@ export const runSass = function (
}

// Add the Sass Node.js package importer, if available
if (!sassOpts.importers) {
try {
sassOpts.importers = [new compiler.NodePackageImporter()];
} catch (err) {
// skip if `NodePackageImporter` isn't available
}
if (!sassOpts.importers && compiler.NodePackageImporter) {
sassOpts.importers = [new compiler.NodePackageImporter()];
}

const compilerFn =
Expand Down
20 changes: 11 additions & 9 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ describe('#runSass', () => {
{
...trueOpts,
sass: {
NodePackageImporter: class {},
compile(src, opts) {
if (opts.importers[0] instanceof this.NodePackageImporter) {
NodePackageImporter: class {
constructor() {
throw new Error('NodePackageImporter added');
}
throw new Error('failed');
},
compile() {
throw new Error('not added');
},
},
},
Expand All @@ -213,20 +214,21 @@ describe('#runSass', () => {
{
...trueOpts,
sass: {
NodePackageImporter: class {},
compile(src, opts) {
if (opts.importers[0] instanceof this.NodePackageImporter) {
NodePackageImporter: class {
constructor() {
throw new Error('NodePackageImporter added');
}
throw new Error('failed');
},
compile() {
throw new Error('not added');
},
},
},
'',
{ importers: [] },
);
};
expect(attempt).to.throw('failed');
expect(attempt).to.throw('not added');
});
});

Expand Down

0 comments on commit 6da9413

Please sign in to comment.