eyeglass
Version:
Sass modules for npm.
56 lines • 2.31 kB
JavaScript
;
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = __importStar(require("path"));
const perf_1 = require("../util/perf");
const ImportUtilities_1 = __importDefault(require("./ImportUtilities"));
const FSImporter = function (eyeglass, sass, options, fallbackImporter) {
let fsURI = /^fs\(([-_a-zA-Z][-_a-zA-Z0-9]+)\)$/;
return ImportUtilities_1.default.createImporter("fs", function (uri, prev, done) {
let importUtils = new ImportUtilities_1.default(eyeglass, sass, options, fallbackImporter, this);
let match = uri.match(fsURI);
if (match) {
let identifier = match[1];
let absolutePath = null;
if (identifier === "root") {
absolutePath = options.eyeglass.root;
}
else if (!perf_1.existsSync(prev)) {
absolutePath = path.resolve(".");
}
else {
absolutePath = path.resolve(path.dirname(prev));
}
/* istanbul ignore else - TODO: revisit this */
if (absolutePath) {
let sassContents = '@import "eyeglass/fs"; @include fs-register-path('
+ identifier + ', "' + absolutePath + '");';
let data = {
contents: sassContents,
file: "fs:" + identifier + ":" + absolutePath
};
importUtils.importOnce(data, done);
}
else {
// TODO (test) - how do we get here? needs test case
done(new Error("Cannot resolve filesystem location of " + prev));
}
}
else {
importUtils.fallback(uri, prev, done, function () {
done(null);
});
}
});
};
exports.default = FSImporter;
//# sourceMappingURL=FSImporter.js.map