Skip to content

Commit

Permalink
Merge pull request #18 from Becklyn/support-underscore
Browse files Browse the repository at this point in the history
Support underscores in imported files from node_modules
  • Loading branch information
Jannik Zschiesche authored Jan 18, 2020
2 parents 144bb7e + 3e0d5cc commit d1d01a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea
/.stylelintcache
/node_modules
/package-lock.json

Expand All @@ -9,4 +10,3 @@

# Allow test files
!/tests/**/*.js
/.stylelintcache
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 d1d01a2

Please sign in to comment.