111 lines
4.1 KiB
JavaScript
111 lines
4.1 KiB
JavaScript
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var process_config_exports = {};
|
|
__export(process_config_exports, {
|
|
processConfig: () => processConfig,
|
|
processConfigFile: () => processConfigFile
|
|
});
|
|
module.exports = __toCommonJS(process_config_exports);
|
|
var import_path = __toESM(require("path"));
|
|
var import_lodash = __toESM(require("lodash"));
|
|
var import_utils = require("../utils");
|
|
var import_stage_build = require("./stage-build");
|
|
var import_stage_transform = require("./stage-transform");
|
|
const stageMap = {
|
|
build: import_stage_build.stageBuild,
|
|
transform: import_stage_transform.stageTransform
|
|
};
|
|
const defaultStages = ["transform", "build"];
|
|
function getDefaults(source) {
|
|
let baseConfigs = source.extends;
|
|
if (baseConfigs === void 0) {
|
|
return source.defaults || {};
|
|
}
|
|
if ((0, import_utils.isString)(baseConfigs)) {
|
|
baseConfigs = [baseConfigs];
|
|
}
|
|
if ((0, import_utils.isArray)(baseConfigs) === false) {
|
|
return source.defaults || {};
|
|
}
|
|
baseConfigs.forEach((baseConfigName) => {
|
|
let configPath = "";
|
|
let configData = {};
|
|
const [provider, identifier] = baseConfigName.split(":", 2);
|
|
if (provider !== "sass-build" && provider !== "plugin") {
|
|
return;
|
|
}
|
|
if (identifier === void 0 || identifier === "") {
|
|
return;
|
|
}
|
|
if (provider === "plugin") {
|
|
configPath = identifier;
|
|
} else {
|
|
configPath = import_path.default.resolve(__dirname, "../../lib", `sass-build-${identifier}.js`);
|
|
}
|
|
if (configPath !== "") {
|
|
configData = require(configPath);
|
|
}
|
|
source.defaults = import_lodash.default.defaultsDeep({}, source.defaults, configData.defaults);
|
|
});
|
|
return source.defaults;
|
|
}
|
|
function processConfigFile(configPath, stages = defaultStages) {
|
|
if (configPath) {
|
|
import_utils.logger.silly("process config", `Using config: ${configPath}`);
|
|
} else {
|
|
import_utils.logger.silly("process config", "Using default config: sass.config.js");
|
|
configPath = "sass.config.js";
|
|
}
|
|
if (!(0, import_utils.fileExists)(configPath)) {
|
|
(0, import_utils.exit)(2, "error", "process config", `Cannot file config file: ${configPath}`);
|
|
}
|
|
const config = (0, import_utils.requireUserFile)(configPath);
|
|
processConfig(config, stages);
|
|
}
|
|
function processConfig(config, stages = defaultStages) {
|
|
const configDefaults = getDefaults(config);
|
|
if (Array.isArray(config.files)) {
|
|
if (Array.isArray(config.build)) {
|
|
import_utils.logger.warn("process config", `Found both config.build and config.files. Using config.build.`);
|
|
} else {
|
|
import_utils.logger.warn("process config", `Prefer config.build instead of config.files.`);
|
|
config.build = Array.from(config.files);
|
|
}
|
|
delete config.files;
|
|
}
|
|
stages.forEach((stage) => {
|
|
const stageFn = stageMap[stage];
|
|
const stageData = config[stage];
|
|
const stageDefaults = configDefaults[stage] || {};
|
|
if (typeof stageFn === "function") {
|
|
stageFn(stageData, stageDefaults);
|
|
}
|
|
});
|
|
}
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
processConfig,
|
|
processConfigFile
|
|
});
|