Skip to content

Commit

Permalink
fix relative paths being the same as node modules (#1556)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper De Moor authored and devongovett committed Jun 17, 2018
1 parent cc6018e commit f536e8b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/assets/LESSAsset.js
Expand Up @@ -4,6 +4,7 @@ const promisify = require('../utils/promisify');
const Resolver = require('../Resolver');
const fs = require('../utils/fs');
const path = require('path');
const parseCSSImport = require('../utils/parseCSSImport');

class LESSAsset extends Asset {
constructor(name, options) {
Expand Down Expand Up @@ -80,6 +81,7 @@ function getFileManager(less, options) {
}

async loadFile(filename, currentDirectory) {
filename = parseCSSImport(filename);
let resolved = await resolver.resolve(
filename,
path.join(currentDirectory, 'index')
Expand Down
7 changes: 2 additions & 5 deletions src/assets/SASSAsset.js
Expand Up @@ -4,6 +4,7 @@ const promisify = require('../utils/promisify');
const path = require('path');
const os = require('os');
const Resolver = require('../Resolver');
const parseCSSImport = require('../utils/parseCSSImport');

class SASSAsset extends Asset {
constructor(name, options) {
Expand Down Expand Up @@ -50,11 +51,7 @@ class SASSAsset extends Asset {
? opts.importer
: [opts.importer];
opts.importer.push((url, prev, done) => {
if (!/^(~|\.\/|\/)/.test(url)) {
url = './' + url;
} else if (!/^(~\/|\.\/|\/)/.test(url)) {
url = url.substring(1);
}
url = parseCSSImport(url);
resolver
.resolve(url, prev === 'stdin' ? this.name : prev)
.then(resolved => resolved.path)
Expand Down
10 changes: 10 additions & 0 deletions src/utils/parseCSSImport.js
@@ -0,0 +1,10 @@
function parseCSSImport(url) {
if (!/^(~|\.\/|\/)/.test(url)) {
url = './' + url;
} else if (!/^(~\/|\.\/|\/)/.test(url)) {
url = url.substring(1);
}
return url;
}

module.exports = parseCSSImport;
2 changes: 2 additions & 0 deletions test/integration/less-import/base.less
@@ -1,3 +1,5 @@
@import '~external-less/a.less';

@base: #f938ab;

.base {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f536e8b

Please sign in to comment.