Skip to content

Commit

Permalink
Added support for loading _ prefixed packages from node_modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannik Zschiesche committed Jan 18, 2020
1 parent 47a174c commit 3e0d5cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.3.3
=====

* (improvement) Added support for loading `_` prefixed packages from node_modules.


3.3.2
=====

Expand Down
21 changes: 13 additions & 8 deletions src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,24 @@ export class Compiler
if (url[0] === "~")
{
// map of file extensions and whether the file should be directly loaded or just as path returned
let extensions: {[extension: string]: boolean} = {
".scss": false,
".css": true,
"": false,
const fileNamePatterns: {[extension: string]: boolean} = {
"_%s.scss": false,
"_%s.css": true,
"%s.scss": false,
"%s.css": true,
"%s": false,
};

for (let extension in extensions)
for (let pattern in fileNamePatterns)
{
try {
let loadFileContent = extensions[extension];
let filePath = require.resolve(`${url.substr(1)}${extension}`);
const shouldLoadFileContent = fileNamePatterns[pattern];
const dir = path.dirname(url.substr(1));
const filename = path.basename(url.substr(1));

if (loadFileContent)
const filePath = require.resolve(`${dir}/${pattern.replace('%s', filename)}`);

if (shouldLoadFileContent)
{
return {
contents: fs.readFileSync(filePath, "utf-8"),
Expand Down

0 comments on commit 3e0d5cc

Please sign in to comment.