typed-scss-modules
Version:
TypeScript type definition generator for SCSS CSS Modules
50 lines (49 loc) • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getImplementation = exports.getDefaultImplementation = exports.IMPLEMENTATIONS = void 0;
/**
* A list of all possible SASS package implementations that can be used to
* perform the compilation and parsing of the SASS files. The expectation is
* that they provide a nearly identical API so they can be swapped out but
* all of the same logic can be reused.
*/
exports.IMPLEMENTATIONS = ["node-sass", "sass"];
/**
* Determine which default implementation to use by checking which packages
* are actually installed and available to use.
*
* @param resolver DO NOT USE - this is unfortunately necessary only for testing.
*/
const getDefaultImplementation = (resolver = require.resolve) => {
let pkg = "node-sass";
try {
resolver("node-sass");
}
catch (error) {
try {
resolver("sass");
pkg = "sass";
}
catch (ignoreError) {
pkg = "node-sass";
}
}
return pkg;
};
exports.getDefaultImplementation = getDefaultImplementation;
/**
* Retrieve the desired implementation.
*
* @param implementation the desired implementation.
*/
const getImplementation = (implementation) => {
if (implementation === "sass") {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return require("sass");
}
else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return require("node-sass");
}
};
exports.getImplementation = getImplementation;