styles-config 2.0.0-alpha.5 → 2.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +226 -0
- package/{src/types.ts → lib/index.d.cts} +115 -51
- package/lib/index.d.ts +423 -3
- package/lib/index.js +196 -4
- package/package.json +13 -7
- package/eslint.config.mjs +0 -6
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/loader.d.ts +0 -34
- package/lib/loader.d.ts.map +0 -1
- package/lib/loader.js +0 -99
- package/lib/loader.js.map +0 -1
- package/lib/options.d.ts +0 -49
- package/lib/options.d.ts.map +0 -1
- package/lib/options.js +0 -128
- package/lib/options.js.map +0 -1
- package/lib/types.d.ts +0 -320
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/src/index.ts +0 -3
- package/src/loader.ts +0 -112
- package/src/options.ts +0 -172
- package/test/options.test.ts +0 -256
- package/tsconfig.build.json +0 -10
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -10
- package/tsconfig.tsbuildinfo +0 -1
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let cosmiconfig = require("cosmiconfig");
|
|
25
|
+
let picomatch = require("picomatch");
|
|
26
|
+
picomatch = __toESM(picomatch);
|
|
27
|
+
let path = require("path");
|
|
28
|
+
path = __toESM(path);
|
|
29
|
+
//#region src/loader.ts
|
|
30
|
+
const explorer = (0, cosmiconfig.cosmiconfig)("styles", {
|
|
31
|
+
searchPlaces: [
|
|
32
|
+
"styles.config.ts",
|
|
33
|
+
"styles.config.js",
|
|
34
|
+
"styles.config.mts",
|
|
35
|
+
"styles.config.mjs",
|
|
36
|
+
"styles.config.cjs",
|
|
37
|
+
"styles.config.cts"
|
|
38
|
+
],
|
|
39
|
+
loaders: {
|
|
40
|
+
".mts": cosmiconfig.defaultLoadersSync[".ts"],
|
|
41
|
+
".cts": cosmiconfig.defaultLoadersSync[".ts"],
|
|
42
|
+
".mjs": cosmiconfig.defaultLoadersSync[".js"],
|
|
43
|
+
".cjs": cosmiconfig.defaultLoadersSync[".cjs"]
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const explorerSync = (0, cosmiconfig.cosmiconfigSync)("styles", {
|
|
47
|
+
searchPlaces: [
|
|
48
|
+
"styles.config.ts",
|
|
49
|
+
"styles.config.js",
|
|
50
|
+
"styles.config.mts",
|
|
51
|
+
"styles.config.mjs",
|
|
52
|
+
"styles.config.cjs",
|
|
53
|
+
"styles.config.cts"
|
|
54
|
+
],
|
|
55
|
+
loaders: {
|
|
56
|
+
".mts": cosmiconfig.defaultLoadersSync[".ts"],
|
|
57
|
+
".cts": cosmiconfig.defaultLoadersSync[".ts"],
|
|
58
|
+
".mjs": cosmiconfig.defaultLoadersSync[".js"],
|
|
59
|
+
".cjs": cosmiconfig.defaultLoadersSync[".cjs"]
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Load styles configuration from the file system (async)
|
|
64
|
+
* @param searchFrom - Directory to search from (defaults to process.cwd())
|
|
65
|
+
* @returns Configuration object or null if not found
|
|
66
|
+
*/
|
|
67
|
+
async function loadConfig(searchFrom) {
|
|
68
|
+
const result = await explorer.search(searchFrom);
|
|
69
|
+
return result?.config ? normalizeConfig(result.config) : null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Load styles configuration from the file system (sync)
|
|
73
|
+
* @param searchFrom - Directory to search from (defaults to process.cwd())
|
|
74
|
+
* @returns Configuration object or empty object if not found
|
|
75
|
+
*/
|
|
76
|
+
function loadConfigSync(searchFrom) {
|
|
77
|
+
const result = explorerSync.search(searchFrom);
|
|
78
|
+
return result?.config ? normalizeConfig(result.config) : {};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Load styles configuration with metadata (sync).
|
|
82
|
+
* Includes config file path when a config file is discovered.
|
|
83
|
+
*/
|
|
84
|
+
function loadConfigSyncWithMeta(searchFrom) {
|
|
85
|
+
const result = explorerSync.search(searchFrom);
|
|
86
|
+
return {
|
|
87
|
+
config: result?.config ? normalizeConfig(result.config) : {},
|
|
88
|
+
configFilePath: result?.filepath
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Load styles configuration from a specific file path (async)
|
|
93
|
+
* @param filePath - Path to the config file
|
|
94
|
+
* @returns Configuration object or null if not found
|
|
95
|
+
*/
|
|
96
|
+
async function loadConfigFromPath(filePath) {
|
|
97
|
+
const result = await explorer.load(filePath);
|
|
98
|
+
return result?.config ? normalizeConfig(result.config) : null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Load styles configuration from a specific file path (sync)
|
|
102
|
+
* @param filePath - Path to the config file
|
|
103
|
+
* @returns Configuration object or empty object if not found
|
|
104
|
+
*/
|
|
105
|
+
function loadConfigFromPathSync(filePath) {
|
|
106
|
+
const result = explorerSync.load(filePath);
|
|
107
|
+
return result?.config ? normalizeConfig(result.config) : {};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Normalize config object - handle default exports and ensure proper type
|
|
111
|
+
*/
|
|
112
|
+
function isStylesConfig(value) {
|
|
113
|
+
return typeof value === "object" && value !== null;
|
|
114
|
+
}
|
|
115
|
+
function normalizeConfig(config) {
|
|
116
|
+
if (isStylesConfig(config) && "default" in config) return normalizeConfig(config.default);
|
|
117
|
+
if (isStylesConfig(config)) return config;
|
|
118
|
+
return {};
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/options.ts
|
|
122
|
+
/**
|
|
123
|
+
* Map of file extensions to language keys
|
|
124
|
+
*/
|
|
125
|
+
const extensionToLanguage = new Map([
|
|
126
|
+
[".less", "less"],
|
|
127
|
+
[".scss", "scss"],
|
|
128
|
+
[".sass", "scss"],
|
|
129
|
+
[".jess", "jess"],
|
|
130
|
+
[".css", "css"]
|
|
131
|
+
]);
|
|
132
|
+
/**
|
|
133
|
+
* Infer language from a file path's extension
|
|
134
|
+
*/
|
|
135
|
+
function inferLanguage(filePath) {
|
|
136
|
+
if (!filePath) return;
|
|
137
|
+
const ext = path.default.extname(filePath).toLowerCase();
|
|
138
|
+
return extensionToLanguage.get(ext);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Check if a file path matches a pattern (exact path, relative path, or glob)
|
|
142
|
+
*/
|
|
143
|
+
function matchesFile(pattern, filePath) {
|
|
144
|
+
if (!pattern || !filePath) return false;
|
|
145
|
+
const normalizedPattern = path.default.normalize(pattern);
|
|
146
|
+
const normalizedFile = path.default.normalize(filePath);
|
|
147
|
+
if (normalizedPattern === normalizedFile) return true;
|
|
148
|
+
if (path.default.basename(normalizedFile) === normalizedPattern) return true;
|
|
149
|
+
const isMatch = (0, picomatch.default)(pattern, { dot: true });
|
|
150
|
+
return isMatch(filePath) || isMatch(normalizedFile);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get matching options from an array of file-based options.
|
|
154
|
+
* Returns merged options from:
|
|
155
|
+
* 1. All entries without a `file` property (defaults)
|
|
156
|
+
* 2. All entries whose `file` pattern matches the given path
|
|
157
|
+
*
|
|
158
|
+
* Later entries override earlier ones.
|
|
159
|
+
*/
|
|
160
|
+
function getMatchingOptions(options, filePath) {
|
|
161
|
+
if (!options) return {};
|
|
162
|
+
const optionsArray = Array.isArray(options) ? options : [options];
|
|
163
|
+
let result = {};
|
|
164
|
+
for (const opt of optionsArray) if (!opt.file || filePath && matchesFile(opt.file, filePath)) {
|
|
165
|
+
const { file: _file, ...rest } = opt;
|
|
166
|
+
result = {
|
|
167
|
+
...result,
|
|
168
|
+
...rest
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get merged options by combining compile, language, input, and output settings.
|
|
175
|
+
*
|
|
176
|
+
* Merge priority (later wins):
|
|
177
|
+
* 1. compile options (base)
|
|
178
|
+
* 2. language-specific options (inferred from input extension or explicitly specified)
|
|
179
|
+
* 3. matched input options (if input path provided and matches)
|
|
180
|
+
* 4. matched output options (if output path provided and matches)
|
|
181
|
+
*
|
|
182
|
+
* @param config - The styles configuration object
|
|
183
|
+
* @param params - Options specifying language, input file, and output file
|
|
184
|
+
* @returns Merged options object
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* // Get Less options for a specific input/output (language inferred from .less extension)
|
|
188
|
+
* const options = getOptions(config, {
|
|
189
|
+
* input: 'src/styles/main.less',
|
|
190
|
+
* output: 'dist/main.css'
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* // Explicitly specify language
|
|
195
|
+
* const options = getOptions(config, { language: 'less' });
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* // Get base options without language-specific settings
|
|
199
|
+
* const options = getOptions(config);
|
|
200
|
+
*/
|
|
201
|
+
function getOptions(config = {}, params = {}) {
|
|
202
|
+
const { input: inputFile, output: outputFile } = params;
|
|
203
|
+
const { compile = {}, input, output, language: languageConfig = {} } = config;
|
|
204
|
+
const language = params.language ?? inferLanguage(inputFile);
|
|
205
|
+
const languageOptions = language ? languageConfig[language] ?? {} : {};
|
|
206
|
+
const matchedInput = getMatchingOptions(input, inputFile);
|
|
207
|
+
const matchedOutput = getMatchingOptions(output, outputFile);
|
|
208
|
+
return {
|
|
209
|
+
mathMode: compile.mathMode,
|
|
210
|
+
unitMode: compile.unitMode,
|
|
211
|
+
equalityMode: compile.equalityMode,
|
|
212
|
+
allowExtendSelectors: compile.allowExtendSelectors,
|
|
213
|
+
paths: compile.searchPaths,
|
|
214
|
+
javascriptEnabled: compile.enableJavaScript,
|
|
215
|
+
...languageOptions,
|
|
216
|
+
...matchedInput,
|
|
217
|
+
...matchedOutput
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
//#endregion
|
|
221
|
+
exports.getOptions = getOptions;
|
|
222
|
+
exports.loadConfig = loadConfig;
|
|
223
|
+
exports.loadConfigFromPath = loadConfigFromPath;
|
|
224
|
+
exports.loadConfigFromPathSync = loadConfigFromPathSync;
|
|
225
|
+
exports.loadConfigSync = loadConfigSync;
|
|
226
|
+
exports.loadConfigSyncWithMeta = loadConfigSyncWithMeta;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Math processing modes
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
type MathMode = 'always' | 'parens-division' | 'parens' | 'strict';
|
|
6
6
|
/**
|
|
7
7
|
* Unit conversion modes
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
type UnitMode = 'loose' | 'preserve' | 'strict';
|
|
11
10
|
/**
|
|
12
11
|
* Equality/coercion modes for guard comparisons.
|
|
13
12
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
type EqualityMode = 'coerce' | 'strict';
|
|
14
|
+
type ExtendSelectorKind = 'simple' | 'basic' | 'pseudo' | 'complex' | 'compound';
|
|
15
|
+
interface JavaScriptSandboxConfig {
|
|
17
16
|
/**
|
|
18
17
|
* Allow network access for script execution runtime.
|
|
19
18
|
* @default false
|
|
@@ -29,26 +28,27 @@ export interface JavaScriptSandboxConfig {
|
|
|
29
28
|
*/
|
|
30
29
|
jsReadRoot?: string;
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
export type CompileJavaScriptOption = true | JavaScriptSandboxConfig;
|
|
34
|
-
|
|
31
|
+
type CompileJavaScriptOption = true | JavaScriptSandboxConfig;
|
|
35
32
|
/**
|
|
36
33
|
* Less compiler options
|
|
37
34
|
* Based on less.js default-options.js and bin/lessc
|
|
38
35
|
*/
|
|
39
|
-
|
|
36
|
+
interface LessOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Restrict which selector shapes are allowed in extend targets.
|
|
39
|
+
* When set, any other selector kind is a parse error.
|
|
40
|
+
*/
|
|
41
|
+
allowExtendSelectors?: ExtendSelectorKind[];
|
|
40
42
|
/**
|
|
41
43
|
* Inline Javascript - @plugin still allowed
|
|
42
44
|
* @default false
|
|
43
45
|
*/
|
|
44
46
|
javascriptEnabled?: boolean;
|
|
45
|
-
|
|
46
47
|
/**
|
|
47
48
|
* Outputs a makefile import dependency list to stdout.
|
|
48
49
|
* @default false
|
|
49
50
|
*/
|
|
50
51
|
depends?: boolean;
|
|
51
|
-
|
|
52
52
|
/**
|
|
53
53
|
* @deprecated Compress using less built-in compression.
|
|
54
54
|
* This does an okay job but does not utilise all the tricks of
|
|
@@ -56,13 +56,11 @@ export interface LessOptions {
|
|
|
56
56
|
* @default false
|
|
57
57
|
*/
|
|
58
58
|
compress?: boolean;
|
|
59
|
-
|
|
60
59
|
/**
|
|
61
60
|
* Runs the less parser and just reports errors without any output.
|
|
62
61
|
* @default false
|
|
63
62
|
*/
|
|
64
63
|
lint?: boolean;
|
|
65
|
-
|
|
66
64
|
/**
|
|
67
65
|
* Sets available include paths.
|
|
68
66
|
* If the file in an @import rule does not exist at that exact location,
|
|
@@ -70,13 +68,11 @@ export interface LessOptions {
|
|
|
70
68
|
* @default []
|
|
71
69
|
*/
|
|
72
70
|
paths?: string[];
|
|
73
|
-
|
|
74
71
|
/**
|
|
75
72
|
* Color output in the terminal
|
|
76
73
|
* @default true
|
|
77
74
|
*/
|
|
78
75
|
color?: boolean;
|
|
79
|
-
|
|
80
76
|
/**
|
|
81
77
|
* @deprecated This option has confusing behavior and may be removed in a future version.
|
|
82
78
|
*
|
|
@@ -99,13 +95,11 @@ export interface LessOptions {
|
|
|
99
95
|
* @default false
|
|
100
96
|
*/
|
|
101
97
|
strictImports?: boolean | 'error';
|
|
102
|
-
|
|
103
98
|
/**
|
|
104
99
|
* Allow Imports from Insecure HTTPS Hosts
|
|
105
100
|
* @default false
|
|
106
101
|
*/
|
|
107
102
|
insecure?: boolean;
|
|
108
|
-
|
|
109
103
|
/**
|
|
110
104
|
* Allows you to add a path to every generated import and url in your css.
|
|
111
105
|
* This does not affect less import statements that are processed, just ones
|
|
@@ -113,7 +107,6 @@ export interface LessOptions {
|
|
|
113
107
|
* @default ''
|
|
114
108
|
*/
|
|
115
109
|
rootpath?: string;
|
|
116
|
-
|
|
117
110
|
/**
|
|
118
111
|
* By default URLs are kept as-is, so if you import a file in a sub-directory
|
|
119
112
|
* that references an image, exactly the same URL will be output in the css.
|
|
@@ -122,7 +115,6 @@ export interface LessOptions {
|
|
|
122
115
|
* @default false
|
|
123
116
|
*/
|
|
124
117
|
rewriteUrls?: boolean | 'all' | 'local' | 'off';
|
|
125
|
-
|
|
126
118
|
/**
|
|
127
119
|
* How to process math operations
|
|
128
120
|
* - 'always': eagerly try to solve all operations
|
|
@@ -131,7 +123,6 @@ export interface LessOptions {
|
|
|
131
123
|
* @default 'parens-division'
|
|
132
124
|
*/
|
|
133
125
|
mathMode?: MathMode;
|
|
134
|
-
|
|
135
126
|
/**
|
|
136
127
|
* How to handle unit conversions in math operations
|
|
137
128
|
* - 'loose': Less's default 1.x-4.x behavior
|
|
@@ -140,7 +131,6 @@ export interface LessOptions {
|
|
|
140
131
|
* @default 'preserve'
|
|
141
132
|
*/
|
|
142
133
|
unitMode?: UnitMode;
|
|
143
|
-
|
|
144
134
|
/**
|
|
145
135
|
* How to handle equality/coercion in guards and comparisons.
|
|
146
136
|
* - 'coerce': Less-compatible coercion behavior
|
|
@@ -148,7 +138,6 @@ export interface LessOptions {
|
|
|
148
138
|
* @default 'coerce'
|
|
149
139
|
*/
|
|
150
140
|
equalityMode?: EqualityMode;
|
|
151
|
-
|
|
152
141
|
/**
|
|
153
142
|
* @deprecated Use `mathMode` instead. This option maps to `mathMode` as follows:
|
|
154
143
|
* - 0 or 'always' → 'always'
|
|
@@ -158,7 +147,6 @@ export interface LessOptions {
|
|
|
158
147
|
* @default undefined (uses mathMode if provided, otherwise 'parens-division')
|
|
159
148
|
*/
|
|
160
149
|
math?: 0 | 1 | 2 | 3 | MathMode | 'strict-legacy';
|
|
161
|
-
|
|
162
150
|
/**
|
|
163
151
|
* @deprecated Use `unitMode` instead. If `true`, sets `unitMode` to 'strict'.
|
|
164
152
|
* If `false`, sets the unitMode to 'loose.
|
|
@@ -166,7 +154,6 @@ export interface LessOptions {
|
|
|
166
154
|
* @default false
|
|
167
155
|
*/
|
|
168
156
|
strictUnits?: boolean;
|
|
169
|
-
|
|
170
157
|
/**
|
|
171
158
|
* Effectively the declaration is put at the top of your base Less file,
|
|
172
159
|
* meaning it can be used but it also can be overridden if this variable
|
|
@@ -174,27 +161,23 @@ export interface LessOptions {
|
|
|
174
161
|
* @default null
|
|
175
162
|
*/
|
|
176
163
|
globalVars?: Record<string, string> | null;
|
|
177
|
-
|
|
178
164
|
/**
|
|
179
165
|
* As opposed to the global variable option, this puts the declaration at the
|
|
180
166
|
* end of your base file, meaning it will override anything defined in your Less file.
|
|
181
167
|
* @default null
|
|
182
168
|
*/
|
|
183
169
|
modifyVars?: Record<string, string> | null;
|
|
184
|
-
|
|
185
170
|
/**
|
|
186
171
|
* This option allows you to specify a argument to go on to every URL.
|
|
187
172
|
* @default ''
|
|
188
173
|
*/
|
|
189
174
|
urlArgs?: string;
|
|
190
|
-
|
|
191
175
|
/**
|
|
192
176
|
* @removed The dumpLineNumbers option is not useful nor supported in browsers. Use sourcemaps instead.
|
|
193
177
|
*
|
|
194
178
|
* @default undefined
|
|
195
179
|
*/
|
|
196
180
|
dumpLineNumbers?: string;
|
|
197
|
-
|
|
198
181
|
/**
|
|
199
182
|
* Source map options
|
|
200
183
|
* @default undefined
|
|
@@ -210,25 +193,21 @@ export interface LessOptions {
|
|
|
210
193
|
sourceMapOutputFilename?: string;
|
|
211
194
|
sourceMapFilename?: string;
|
|
212
195
|
};
|
|
213
|
-
|
|
214
196
|
/**
|
|
215
197
|
* Verbose output
|
|
216
198
|
* @default false
|
|
217
199
|
*/
|
|
218
200
|
verbose?: boolean;
|
|
219
|
-
|
|
220
201
|
/**
|
|
221
202
|
* Silent mode (suppress errors)
|
|
222
203
|
* @default false
|
|
223
204
|
*/
|
|
224
205
|
silent?: boolean;
|
|
225
|
-
|
|
226
206
|
/**
|
|
227
207
|
* Quiet mode (suppress warnings)
|
|
228
208
|
* @default false
|
|
229
209
|
*/
|
|
230
210
|
quiet?: boolean;
|
|
231
|
-
|
|
232
211
|
/**
|
|
233
212
|
* @deprecated This is legacy Less behavior.
|
|
234
213
|
*
|
|
@@ -241,14 +220,12 @@ export interface LessOptions {
|
|
|
241
220
|
* @default true
|
|
242
221
|
*/
|
|
243
222
|
leakyRules?: boolean;
|
|
244
|
-
|
|
245
223
|
/**
|
|
246
224
|
* Whether to collapse nested selectors (Less 1.x-4.x style flattening)
|
|
247
225
|
* When true, nested selectors like `.parent { .child { } }` are flattened to `.parent .child { }`
|
|
248
226
|
* @default false
|
|
249
227
|
*/
|
|
250
228
|
collapseNesting?: boolean;
|
|
251
|
-
|
|
252
229
|
/**
|
|
253
230
|
* @deprecated This is legacy Less behavior.
|
|
254
231
|
*
|
|
@@ -258,30 +235,33 @@ export interface LessOptions {
|
|
|
258
235
|
*/
|
|
259
236
|
bubbleRootAtRules?: boolean;
|
|
260
237
|
}
|
|
261
|
-
|
|
238
|
+
interface ScssOptions {
|
|
239
|
+
allowExtendSelectors?: ExtendSelectorKind[];
|
|
240
|
+
unitMode?: UnitMode;
|
|
241
|
+
equalityMode?: EqualityMode;
|
|
242
|
+
collapseNesting?: boolean;
|
|
243
|
+
[key: string]: any;
|
|
244
|
+
}
|
|
262
245
|
/**
|
|
263
246
|
* Base interface for file-matching options
|
|
264
247
|
*/
|
|
265
|
-
|
|
248
|
+
interface FileMatchOptions {
|
|
266
249
|
/**
|
|
267
250
|
* File path, relative path, or glob pattern for matching.
|
|
268
251
|
* If omitted, the options serve as defaults.
|
|
269
252
|
*/
|
|
270
253
|
file?: string;
|
|
271
254
|
}
|
|
272
|
-
|
|
273
255
|
/**
|
|
274
256
|
* Input file options - can override compile and language settings per input file
|
|
275
257
|
*/
|
|
276
|
-
|
|
277
|
-
// Compile-level options that can be overridden per-input
|
|
258
|
+
interface InputOptions extends FileMatchOptions {
|
|
278
259
|
mathMode?: MathMode;
|
|
279
260
|
unitMode?: UnitMode;
|
|
280
261
|
equalityMode?: EqualityMode;
|
|
262
|
+
allowExtendSelectors?: ExtendSelectorKind[];
|
|
281
263
|
searchPaths?: string[];
|
|
282
264
|
enableJavaScript?: boolean;
|
|
283
|
-
|
|
284
|
-
// Less-specific options that can be overridden per-input
|
|
285
265
|
javascriptEnabled?: boolean;
|
|
286
266
|
paths?: string[];
|
|
287
267
|
globalVars?: Record<string, string> | null;
|
|
@@ -292,15 +272,13 @@ export interface InputOptions extends FileMatchOptions {
|
|
|
292
272
|
leakyRules?: boolean;
|
|
293
273
|
collapseNesting?: boolean;
|
|
294
274
|
bubbleRootAtRules?: boolean;
|
|
295
|
-
|
|
296
275
|
/** Allow additional language-specific options */
|
|
297
276
|
[key: string]: any;
|
|
298
277
|
}
|
|
299
|
-
|
|
300
278
|
/**
|
|
301
279
|
* Output file options - can override output settings per output file
|
|
302
280
|
*/
|
|
303
|
-
|
|
281
|
+
interface OutputOptions extends FileMatchOptions {
|
|
304
282
|
collapseNesting?: boolean;
|
|
305
283
|
compress?: boolean;
|
|
306
284
|
sourceMap?: boolean | {
|
|
@@ -314,12 +292,10 @@ export interface OutputOptions extends FileMatchOptions {
|
|
|
314
292
|
sourceMapOutputFilename?: string;
|
|
315
293
|
sourceMapFilename?: string;
|
|
316
294
|
};
|
|
317
|
-
|
|
318
295
|
/** Allow additional options */
|
|
319
296
|
[key: string]: any;
|
|
320
297
|
}
|
|
321
|
-
|
|
322
|
-
export interface StylesConfig {
|
|
298
|
+
interface StylesConfig {
|
|
323
299
|
compile?: {
|
|
324
300
|
/**
|
|
325
301
|
* Plugins can be specified as:
|
|
@@ -336,6 +312,7 @@ export interface StylesConfig {
|
|
|
336
312
|
mathMode?: MathMode;
|
|
337
313
|
unitMode?: UnitMode;
|
|
338
314
|
equalityMode?: EqualityMode;
|
|
315
|
+
allowExtendSelectors?: ExtendSelectorKind[];
|
|
339
316
|
};
|
|
340
317
|
/**
|
|
341
318
|
* Input file options. Can be a single object for defaults, or an array
|
|
@@ -351,9 +328,96 @@ export interface StylesConfig {
|
|
|
351
328
|
output?: OutputOptions | OutputOptions[];
|
|
352
329
|
language?: {
|
|
353
330
|
less?: LessOptions;
|
|
354
|
-
scss?:
|
|
331
|
+
scss?: ScssOptions;
|
|
355
332
|
css?: Record<string, any>;
|
|
356
333
|
jess?: Record<string, any>;
|
|
357
|
-
[key: string]: LessOptions | Record<string, any> | undefined;
|
|
334
|
+
[key: string]: LessOptions | ScssOptions | Record<string, any> | undefined;
|
|
358
335
|
};
|
|
359
336
|
}
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/loader.d.ts
|
|
339
|
+
interface LoadedConfigMeta {
|
|
340
|
+
config: StylesConfig;
|
|
341
|
+
configFilePath?: string;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Load styles configuration from the file system (async)
|
|
345
|
+
* @param searchFrom - Directory to search from (defaults to process.cwd())
|
|
346
|
+
* @returns Configuration object or null if not found
|
|
347
|
+
*/
|
|
348
|
+
declare function loadConfig(searchFrom?: string): Promise<StylesConfig | null>;
|
|
349
|
+
/**
|
|
350
|
+
* Load styles configuration from the file system (sync)
|
|
351
|
+
* @param searchFrom - Directory to search from (defaults to process.cwd())
|
|
352
|
+
* @returns Configuration object or empty object if not found
|
|
353
|
+
*/
|
|
354
|
+
declare function loadConfigSync(searchFrom?: string): StylesConfig;
|
|
355
|
+
/**
|
|
356
|
+
* Load styles configuration with metadata (sync).
|
|
357
|
+
* Includes config file path when a config file is discovered.
|
|
358
|
+
*/
|
|
359
|
+
declare function loadConfigSyncWithMeta(searchFrom?: string): LoadedConfigMeta;
|
|
360
|
+
/**
|
|
361
|
+
* Load styles configuration from a specific file path (async)
|
|
362
|
+
* @param filePath - Path to the config file
|
|
363
|
+
* @returns Configuration object or null if not found
|
|
364
|
+
*/
|
|
365
|
+
declare function loadConfigFromPath(filePath: string): Promise<StylesConfig | null>;
|
|
366
|
+
/**
|
|
367
|
+
* Load styles configuration from a specific file path (sync)
|
|
368
|
+
* @param filePath - Path to the config file
|
|
369
|
+
* @returns Configuration object or empty object if not found
|
|
370
|
+
*/
|
|
371
|
+
declare function loadConfigFromPathSync(filePath: string): StylesConfig;
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region src/options.d.ts
|
|
374
|
+
/**
|
|
375
|
+
* Options for retrieving merged configuration
|
|
376
|
+
*/
|
|
377
|
+
interface GetOptionsParams {
|
|
378
|
+
/**
|
|
379
|
+
* Language key to get options for (e.g., 'less', 'scss', 'jess').
|
|
380
|
+
* If omitted but `input` is provided, language is inferred from the file extension.
|
|
381
|
+
*/
|
|
382
|
+
language?: string;
|
|
383
|
+
/**
|
|
384
|
+
* Input file path to match against input options.
|
|
385
|
+
* Also used to infer language if `language` is not specified.
|
|
386
|
+
*/
|
|
387
|
+
input?: string;
|
|
388
|
+
/**
|
|
389
|
+
* Output file path to match against output options
|
|
390
|
+
*/
|
|
391
|
+
output?: string;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Get merged options by combining compile, language, input, and output settings.
|
|
395
|
+
*
|
|
396
|
+
* Merge priority (later wins):
|
|
397
|
+
* 1. compile options (base)
|
|
398
|
+
* 2. language-specific options (inferred from input extension or explicitly specified)
|
|
399
|
+
* 3. matched input options (if input path provided and matches)
|
|
400
|
+
* 4. matched output options (if output path provided and matches)
|
|
401
|
+
*
|
|
402
|
+
* @param config - The styles configuration object
|
|
403
|
+
* @param params - Options specifying language, input file, and output file
|
|
404
|
+
* @returns Merged options object
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* // Get Less options for a specific input/output (language inferred from .less extension)
|
|
408
|
+
* const options = getOptions(config, {
|
|
409
|
+
* input: 'src/styles/main.less',
|
|
410
|
+
* output: 'dist/main.css'
|
|
411
|
+
* });
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* // Explicitly specify language
|
|
415
|
+
* const options = getOptions(config, { language: 'less' });
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* // Get base options without language-specific settings
|
|
419
|
+
* const options = getOptions(config);
|
|
420
|
+
*/
|
|
421
|
+
declare function getOptions(config?: StylesConfig, params?: GetOptionsParams): Record<string, any>;
|
|
422
|
+
//#endregion
|
|
423
|
+
export { CompileJavaScriptOption, EqualityMode, ExtendSelectorKind, FileMatchOptions, GetOptionsParams, InputOptions, JavaScriptSandboxConfig, LessOptions, LoadedConfigMeta, MathMode, OutputOptions, ScssOptions, StylesConfig, UnitMode, getOptions, loadConfig, loadConfigFromPath, loadConfigFromPathSync, loadConfigSync, loadConfigSyncWithMeta };
|