styles-config 2.0.0-alpha.6 → 2.0.0-alpha.7
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 +21 -2
- package/lib/index.d.ts +3 -423
- package/lib/index.js +21 -3
- package/lib/loader.d.ts +34 -0
- package/lib/options.d.ts +70 -0
- package/lib/types.d.ts +385 -0
- package/package.json +3 -4
- package/lib/index.d.cts +0 -423
package/lib/index.cjs
CHANGED
|
@@ -120,6 +120,24 @@ function normalizeConfig(config) {
|
|
|
120
120
|
//#endregion
|
|
121
121
|
//#region src/options.ts
|
|
122
122
|
/**
|
|
123
|
+
* Expand the `strict` convenience preset. When `strict` is truthy, fills the
|
|
124
|
+
* strict bundle for any governed option left `undefined` — an explicitly set
|
|
125
|
+
* option always wins. Modeled after `tsconfig`'s `strict`: it only *sets*
|
|
126
|
+
* semantic options, it is not itself a mode. Sets the strictest value of each
|
|
127
|
+
* governed axis (`equalityMode: 'exact'` is the no-coercion dialect).
|
|
128
|
+
*
|
|
129
|
+
* Returns a new object (never mutates the input); a no-op when `strict` is falsy.
|
|
130
|
+
*/
|
|
131
|
+
function applyStrictPreset(opts) {
|
|
132
|
+
if (!opts?.strict) return opts;
|
|
133
|
+
const filled = { ...opts };
|
|
134
|
+
filled.unitMode ??= "strict";
|
|
135
|
+
filled.equalityMode ??= "exact";
|
|
136
|
+
filled.leakyScope ??= false;
|
|
137
|
+
filled.allowOverloadedImport ??= false;
|
|
138
|
+
return filled;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
123
141
|
* Map of file extensions to language keys
|
|
124
142
|
*/
|
|
125
143
|
const extensionToLanguage = new Map([
|
|
@@ -162,7 +180,7 @@ function getMatchingOptions(options, filePath) {
|
|
|
162
180
|
const optionsArray = Array.isArray(options) ? options : [options];
|
|
163
181
|
let result = {};
|
|
164
182
|
for (const opt of optionsArray) if (!opt.file || filePath && matchesFile(opt.file, filePath)) {
|
|
165
|
-
const { file
|
|
183
|
+
const { file, ...rest } = opt;
|
|
166
184
|
result = {
|
|
167
185
|
...result,
|
|
168
186
|
...rest
|
|
@@ -210,14 +228,15 @@ function getOptions(config = {}, params = {}) {
|
|
|
210
228
|
unitMode: compile.unitMode,
|
|
211
229
|
equalityMode: compile.equalityMode,
|
|
212
230
|
allowExtendSelectors: compile.allowExtendSelectors,
|
|
231
|
+
disableScriptModules: compile.disableScriptModules ?? compile.disablePluginRule,
|
|
213
232
|
paths: compile.searchPaths,
|
|
214
|
-
javascriptEnabled: compile.enableJavaScript,
|
|
215
233
|
...languageOptions,
|
|
216
234
|
...matchedInput,
|
|
217
235
|
...matchedOutput
|
|
218
236
|
};
|
|
219
237
|
}
|
|
220
238
|
//#endregion
|
|
239
|
+
exports.applyStrictPreset = applyStrictPreset;
|
|
221
240
|
exports.getOptions = getOptions;
|
|
222
241
|
exports.loadConfig = loadConfig;
|
|
223
242
|
exports.loadConfigFromPath = loadConfigFromPath;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,423 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
type MathMode = 'always' | 'parens-division' | 'parens' | 'strict';
|
|
6
|
-
/**
|
|
7
|
-
* Unit conversion modes
|
|
8
|
-
*/
|
|
9
|
-
type UnitMode = 'loose' | 'preserve' | 'strict';
|
|
10
|
-
/**
|
|
11
|
-
* Equality/coercion modes for guard comparisons.
|
|
12
|
-
*/
|
|
13
|
-
type EqualityMode = 'coerce' | 'strict';
|
|
14
|
-
type ExtendSelectorKind = 'simple' | 'basic' | 'pseudo' | 'complex' | 'compound';
|
|
15
|
-
interface JavaScriptSandboxConfig {
|
|
16
|
-
/**
|
|
17
|
-
* Allow network access for script execution runtime.
|
|
18
|
-
* @default false
|
|
19
|
-
*/
|
|
20
|
-
allowHttp?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Optional host allowlist when `allowHttp` is enabled.
|
|
23
|
-
*/
|
|
24
|
-
allowNetHosts?: string[];
|
|
25
|
-
/**
|
|
26
|
-
* Optional explicit filesystem root for script reads.
|
|
27
|
-
* If omitted, compiler resolves using entry/config roots.
|
|
28
|
-
*/
|
|
29
|
-
jsReadRoot?: string;
|
|
30
|
-
}
|
|
31
|
-
type CompileJavaScriptOption = true | JavaScriptSandboxConfig;
|
|
32
|
-
/**
|
|
33
|
-
* Less compiler options
|
|
34
|
-
* Based on less.js default-options.js and bin/lessc
|
|
35
|
-
*/
|
|
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[];
|
|
42
|
-
/**
|
|
43
|
-
* Inline Javascript - @plugin still allowed
|
|
44
|
-
* @default false
|
|
45
|
-
*/
|
|
46
|
-
javascriptEnabled?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Outputs a makefile import dependency list to stdout.
|
|
49
|
-
* @default false
|
|
50
|
-
*/
|
|
51
|
-
depends?: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated Compress using less built-in compression.
|
|
54
|
-
* This does an okay job but does not utilise all the tricks of
|
|
55
|
-
* dedicated css compression.
|
|
56
|
-
* @default false
|
|
57
|
-
*/
|
|
58
|
-
compress?: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Runs the less parser and just reports errors without any output.
|
|
61
|
-
* @default false
|
|
62
|
-
*/
|
|
63
|
-
lint?: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Sets available include paths.
|
|
66
|
-
* If the file in an @import rule does not exist at that exact location,
|
|
67
|
-
* less will look for it at the location(s) passed to this option.
|
|
68
|
-
* @default []
|
|
69
|
-
*/
|
|
70
|
-
paths?: string[];
|
|
71
|
-
/**
|
|
72
|
-
* Color output in the terminal
|
|
73
|
-
* @default true
|
|
74
|
-
*/
|
|
75
|
-
color?: boolean;
|
|
76
|
-
/**
|
|
77
|
-
* @deprecated This option has confusing behavior and may be removed in a future version.
|
|
78
|
-
*
|
|
79
|
-
* Controls how @import statements for .less files are handled inside selector blocks (rulesets).
|
|
80
|
-
*
|
|
81
|
-
* Behavior:
|
|
82
|
-
* - @import at root level: Always processed
|
|
83
|
-
* - @import inside @-rules (@media, @supports, etc.): Processed (these are not selector blocks)
|
|
84
|
-
* - @import inside selector blocks (.class, #id, etc.): Behavior depends on this option
|
|
85
|
-
*
|
|
86
|
-
* Options:
|
|
87
|
-
* - `false` (default): All @import statements are processed regardless of context.
|
|
88
|
-
* - `true`: @import statements inside selector blocks are silently ignored and not output.
|
|
89
|
-
* - `'error'`: @import statements inside selector blocks will throw an error instead of being silently ignored.
|
|
90
|
-
*
|
|
91
|
-
* Note: Only affects .less file imports. CSS imports (url(...) or .css files) are
|
|
92
|
-
* always output as CSS @import statements regardless of this setting.
|
|
93
|
-
*
|
|
94
|
-
* @see https://github.com/less/less.js/issues/656
|
|
95
|
-
* @default false
|
|
96
|
-
*/
|
|
97
|
-
strictImports?: boolean | 'error';
|
|
98
|
-
/**
|
|
99
|
-
* Allow Imports from Insecure HTTPS Hosts
|
|
100
|
-
* @default false
|
|
101
|
-
*/
|
|
102
|
-
insecure?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* Allows you to add a path to every generated import and url in your css.
|
|
105
|
-
* This does not affect less import statements that are processed, just ones
|
|
106
|
-
* that are left in the output css.
|
|
107
|
-
* @default ''
|
|
108
|
-
*/
|
|
109
|
-
rootpath?: string;
|
|
110
|
-
/**
|
|
111
|
-
* By default URLs are kept as-is, so if you import a file in a sub-directory
|
|
112
|
-
* that references an image, exactly the same URL will be output in the css.
|
|
113
|
-
* This option allows you to re-write URL's in imported files so that the
|
|
114
|
-
* URL is always relative to the base imported file
|
|
115
|
-
* @default false
|
|
116
|
-
*/
|
|
117
|
-
rewriteUrls?: boolean | 'all' | 'local' | 'off';
|
|
118
|
-
/**
|
|
119
|
-
* How to process math operations
|
|
120
|
-
* - 'always': eagerly try to solve all operations
|
|
121
|
-
* - 'parens-division': require parens for division "/"
|
|
122
|
-
* - 'parens' or 'strict': require parens for all operations
|
|
123
|
-
* @default 'parens-division'
|
|
124
|
-
*/
|
|
125
|
-
mathMode?: MathMode;
|
|
126
|
-
/**
|
|
127
|
-
* How to handle unit conversions in math operations
|
|
128
|
-
* - 'loose': Less's default 1.x-4.x behavior
|
|
129
|
-
* - 'preserve': Create calc() expressions for unit errors
|
|
130
|
-
* - 'strict': strict unit mode
|
|
131
|
-
* @default 'preserve'
|
|
132
|
-
*/
|
|
133
|
-
unitMode?: UnitMode;
|
|
134
|
-
/**
|
|
135
|
-
* How to handle equality/coercion in guards and comparisons.
|
|
136
|
-
* - 'coerce': Less-compatible coercion behavior
|
|
137
|
-
* - 'strict': type-strict behavior
|
|
138
|
-
* @default 'coerce'
|
|
139
|
-
*/
|
|
140
|
-
equalityMode?: EqualityMode;
|
|
141
|
-
/**
|
|
142
|
-
* @deprecated Use `mathMode` instead. This option maps to `mathMode` as follows:
|
|
143
|
-
* - 0 or 'always' → 'always'
|
|
144
|
-
* - 1 or 'parens-division' → 'parens-division'
|
|
145
|
-
* - 2 or 'parens' or 'strict' → 'parens'
|
|
146
|
-
* - 3 or 'strict-legacy' → 'parens' (removed, will default to 'strict)
|
|
147
|
-
* @default undefined (uses mathMode if provided, otherwise 'parens-division')
|
|
148
|
-
*/
|
|
149
|
-
math?: 0 | 1 | 2 | 3 | MathMode | 'strict-legacy';
|
|
150
|
-
/**
|
|
151
|
-
* @deprecated Use `unitMode` instead. If `true`, sets `unitMode` to 'strict'.
|
|
152
|
-
* If `false`, sets the unitMode to 'loose.
|
|
153
|
-
* If undefined, uses the `unitMode` value (defaults to 'preserve').
|
|
154
|
-
* @default false
|
|
155
|
-
*/
|
|
156
|
-
strictUnits?: boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Effectively the declaration is put at the top of your base Less file,
|
|
159
|
-
* meaning it can be used but it also can be overridden if this variable
|
|
160
|
-
* is defined in the file.
|
|
161
|
-
* @default null
|
|
162
|
-
*/
|
|
163
|
-
globalVars?: Record<string, string> | null;
|
|
164
|
-
/**
|
|
165
|
-
* As opposed to the global variable option, this puts the declaration at the
|
|
166
|
-
* end of your base file, meaning it will override anything defined in your Less file.
|
|
167
|
-
* @default null
|
|
168
|
-
*/
|
|
169
|
-
modifyVars?: Record<string, string> | null;
|
|
170
|
-
/**
|
|
171
|
-
* This option allows you to specify a argument to go on to every URL.
|
|
172
|
-
* @default ''
|
|
173
|
-
*/
|
|
174
|
-
urlArgs?: string;
|
|
175
|
-
/**
|
|
176
|
-
* @removed The dumpLineNumbers option is not useful nor supported in browsers. Use sourcemaps instead.
|
|
177
|
-
*
|
|
178
|
-
* @default undefined
|
|
179
|
-
*/
|
|
180
|
-
dumpLineNumbers?: string;
|
|
181
|
-
/**
|
|
182
|
-
* Source map options
|
|
183
|
-
* @default undefined
|
|
184
|
-
*/
|
|
185
|
-
sourceMap?: boolean | {
|
|
186
|
-
sourceMapFullFilename?: string;
|
|
187
|
-
sourceMapRootpath?: string;
|
|
188
|
-
sourceMapBasepath?: string;
|
|
189
|
-
sourceMapURL?: string;
|
|
190
|
-
sourceMapFileInline?: boolean;
|
|
191
|
-
outputSourceFiles?: boolean;
|
|
192
|
-
disableSourcemapAnnotation?: boolean;
|
|
193
|
-
sourceMapOutputFilename?: string;
|
|
194
|
-
sourceMapFilename?: string;
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* Verbose output
|
|
198
|
-
* @default false
|
|
199
|
-
*/
|
|
200
|
-
verbose?: boolean;
|
|
201
|
-
/**
|
|
202
|
-
* Silent mode (suppress errors)
|
|
203
|
-
* @default false
|
|
204
|
-
*/
|
|
205
|
-
silent?: boolean;
|
|
206
|
-
/**
|
|
207
|
-
* Quiet mode (suppress warnings)
|
|
208
|
-
* @default false
|
|
209
|
-
*/
|
|
210
|
-
quiet?: boolean;
|
|
211
|
-
/**
|
|
212
|
-
* @deprecated This is legacy Less behavior.
|
|
213
|
-
*
|
|
214
|
-
* Controls whether mixins and detached rulesets "leak" their inner rules.
|
|
215
|
-
* When true:
|
|
216
|
-
* - Mixins: Mixin and VarDeclaration nodes are 'public' and 'optional' respectively
|
|
217
|
-
* - Detached rulesets: Mixin and VarDeclaration nodes are 'public' and 'private' respectively
|
|
218
|
-
* When false:
|
|
219
|
-
* - Both mixins and detached rulesets: Mixin and VarDeclaration nodes are 'private'
|
|
220
|
-
* @default true
|
|
221
|
-
*/
|
|
222
|
-
leakyRules?: boolean;
|
|
223
|
-
/**
|
|
224
|
-
* Whether to collapse nested selectors (Less 1.x-4.x style flattening)
|
|
225
|
-
* When true, nested selectors like `.parent { .child { } }` are flattened to `.parent .child { }`
|
|
226
|
-
* @default false
|
|
227
|
-
*/
|
|
228
|
-
collapseNesting?: boolean;
|
|
229
|
-
/**
|
|
230
|
-
* @deprecated This is legacy Less behavior.
|
|
231
|
-
*
|
|
232
|
-
* Whether to bubble root-only at-rules (@font-face, @keyframes, etc.) to the root
|
|
233
|
-
* when they are nested inside rulesets. Modern CSS supports nesting these at-rules.
|
|
234
|
-
* @default true
|
|
235
|
-
*/
|
|
236
|
-
bubbleRootAtRules?: boolean;
|
|
237
|
-
}
|
|
238
|
-
interface ScssOptions {
|
|
239
|
-
allowExtendSelectors?: ExtendSelectorKind[];
|
|
240
|
-
unitMode?: UnitMode;
|
|
241
|
-
equalityMode?: EqualityMode;
|
|
242
|
-
collapseNesting?: boolean;
|
|
243
|
-
[key: string]: any;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Base interface for file-matching options
|
|
247
|
-
*/
|
|
248
|
-
interface FileMatchOptions {
|
|
249
|
-
/**
|
|
250
|
-
* File path, relative path, or glob pattern for matching.
|
|
251
|
-
* If omitted, the options serve as defaults.
|
|
252
|
-
*/
|
|
253
|
-
file?: string;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Input file options - can override compile and language settings per input file
|
|
257
|
-
*/
|
|
258
|
-
interface InputOptions extends FileMatchOptions {
|
|
259
|
-
mathMode?: MathMode;
|
|
260
|
-
unitMode?: UnitMode;
|
|
261
|
-
equalityMode?: EqualityMode;
|
|
262
|
-
allowExtendSelectors?: ExtendSelectorKind[];
|
|
263
|
-
searchPaths?: string[];
|
|
264
|
-
enableJavaScript?: boolean;
|
|
265
|
-
javascriptEnabled?: boolean;
|
|
266
|
-
paths?: string[];
|
|
267
|
-
globalVars?: Record<string, string> | null;
|
|
268
|
-
modifyVars?: Record<string, string> | null;
|
|
269
|
-
strictImports?: boolean | 'error';
|
|
270
|
-
rewriteUrls?: boolean | 'all' | 'local' | 'off';
|
|
271
|
-
rootpath?: string;
|
|
272
|
-
leakyRules?: boolean;
|
|
273
|
-
collapseNesting?: boolean;
|
|
274
|
-
bubbleRootAtRules?: boolean;
|
|
275
|
-
/** Allow additional language-specific options */
|
|
276
|
-
[key: string]: any;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Output file options - can override output settings per output file
|
|
280
|
-
*/
|
|
281
|
-
interface OutputOptions extends FileMatchOptions {
|
|
282
|
-
collapseNesting?: boolean;
|
|
283
|
-
compress?: boolean;
|
|
284
|
-
sourceMap?: boolean | {
|
|
285
|
-
sourceMapFullFilename?: string;
|
|
286
|
-
sourceMapRootpath?: string;
|
|
287
|
-
sourceMapBasepath?: string;
|
|
288
|
-
sourceMapURL?: string;
|
|
289
|
-
sourceMapFileInline?: boolean;
|
|
290
|
-
outputSourceFiles?: boolean;
|
|
291
|
-
disableSourcemapAnnotation?: boolean;
|
|
292
|
-
sourceMapOutputFilename?: string;
|
|
293
|
-
sourceMapFilename?: string;
|
|
294
|
-
};
|
|
295
|
-
/** Allow additional options */
|
|
296
|
-
[key: string]: any;
|
|
297
|
-
}
|
|
298
|
-
interface StylesConfig {
|
|
299
|
-
compile?: {
|
|
300
|
-
/**
|
|
301
|
-
* Plugins can be specified as:
|
|
302
|
-
* - Plugin instances (PluginInterface from @jesscss/core)
|
|
303
|
-
* - String keys (plugin names that get resolved elsewhere)
|
|
304
|
-
*
|
|
305
|
-
* @note - Using `any` here to avoid circular dependency with @jesscss/core.
|
|
306
|
-
* The actual type is PluginInterface from @jesscss/core.
|
|
307
|
-
*/
|
|
308
|
-
plugins?: Array<any | string>;
|
|
309
|
-
searchPaths?: string[];
|
|
310
|
-
enableJavaScript?: boolean;
|
|
311
|
-
javascript?: CompileJavaScriptOption;
|
|
312
|
-
mathMode?: MathMode;
|
|
313
|
-
unitMode?: UnitMode;
|
|
314
|
-
equalityMode?: EqualityMode;
|
|
315
|
-
allowExtendSelectors?: ExtendSelectorKind[];
|
|
316
|
-
};
|
|
317
|
-
/**
|
|
318
|
-
* Input file options. Can be a single object for defaults, or an array
|
|
319
|
-
* where entries can have a `file` property (path or glob) to match specific inputs.
|
|
320
|
-
* Entries without a `file` property serve as defaults.
|
|
321
|
-
*/
|
|
322
|
-
input?: InputOptions | InputOptions[];
|
|
323
|
-
/**
|
|
324
|
-
* Output file options. Can be a single object for defaults, or an array
|
|
325
|
-
* where entries can have a `file` property (path or glob) to match specific outputs.
|
|
326
|
-
* Entries without a `file` property serve as defaults.
|
|
327
|
-
*/
|
|
328
|
-
output?: OutputOptions | OutputOptions[];
|
|
329
|
-
language?: {
|
|
330
|
-
less?: LessOptions;
|
|
331
|
-
scss?: ScssOptions;
|
|
332
|
-
css?: Record<string, any>;
|
|
333
|
-
jess?: Record<string, any>;
|
|
334
|
-
[key: string]: LessOptions | ScssOptions | Record<string, any> | undefined;
|
|
335
|
-
};
|
|
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 };
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './loader.js';
|
|
3
|
+
export * from './options.js';
|
package/lib/index.js
CHANGED
|
@@ -95,6 +95,24 @@ function normalizeConfig(config) {
|
|
|
95
95
|
//#endregion
|
|
96
96
|
//#region src/options.ts
|
|
97
97
|
/**
|
|
98
|
+
* Expand the `strict` convenience preset. When `strict` is truthy, fills the
|
|
99
|
+
* strict bundle for any governed option left `undefined` — an explicitly set
|
|
100
|
+
* option always wins. Modeled after `tsconfig`'s `strict`: it only *sets*
|
|
101
|
+
* semantic options, it is not itself a mode. Sets the strictest value of each
|
|
102
|
+
* governed axis (`equalityMode: 'exact'` is the no-coercion dialect).
|
|
103
|
+
*
|
|
104
|
+
* Returns a new object (never mutates the input); a no-op when `strict` is falsy.
|
|
105
|
+
*/
|
|
106
|
+
function applyStrictPreset(opts) {
|
|
107
|
+
if (!opts?.strict) return opts;
|
|
108
|
+
const filled = { ...opts };
|
|
109
|
+
filled.unitMode ??= "strict";
|
|
110
|
+
filled.equalityMode ??= "exact";
|
|
111
|
+
filled.leakyScope ??= false;
|
|
112
|
+
filled.allowOverloadedImport ??= false;
|
|
113
|
+
return filled;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
98
116
|
* Map of file extensions to language keys
|
|
99
117
|
*/
|
|
100
118
|
const extensionToLanguage = new Map([
|
|
@@ -137,7 +155,7 @@ function getMatchingOptions(options, filePath) {
|
|
|
137
155
|
const optionsArray = Array.isArray(options) ? options : [options];
|
|
138
156
|
let result = {};
|
|
139
157
|
for (const opt of optionsArray) if (!opt.file || filePath && matchesFile(opt.file, filePath)) {
|
|
140
|
-
const { file
|
|
158
|
+
const { file, ...rest } = opt;
|
|
141
159
|
result = {
|
|
142
160
|
...result,
|
|
143
161
|
...rest
|
|
@@ -185,12 +203,12 @@ function getOptions(config = {}, params = {}) {
|
|
|
185
203
|
unitMode: compile.unitMode,
|
|
186
204
|
equalityMode: compile.equalityMode,
|
|
187
205
|
allowExtendSelectors: compile.allowExtendSelectors,
|
|
206
|
+
disableScriptModules: compile.disableScriptModules ?? compile.disablePluginRule,
|
|
188
207
|
paths: compile.searchPaths,
|
|
189
|
-
javascriptEnabled: compile.enableJavaScript,
|
|
190
208
|
...languageOptions,
|
|
191
209
|
...matchedInput,
|
|
192
210
|
...matchedOutput
|
|
193
211
|
};
|
|
194
212
|
}
|
|
195
213
|
//#endregion
|
|
196
|
-
export { getOptions, loadConfig, loadConfigFromPath, loadConfigFromPathSync, loadConfigSync, loadConfigSyncWithMeta };
|
|
214
|
+
export { applyStrictPreset, getOptions, loadConfig, loadConfigFromPath, loadConfigFromPathSync, loadConfigSync, loadConfigSyncWithMeta };
|
package/lib/loader.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { StylesConfig } from './types.js';
|
|
2
|
+
export interface LoadedConfigMeta {
|
|
3
|
+
config: StylesConfig;
|
|
4
|
+
configFilePath?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Load styles configuration from the file system (async)
|
|
8
|
+
* @param searchFrom - Directory to search from (defaults to process.cwd())
|
|
9
|
+
* @returns Configuration object or null if not found
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadConfig(searchFrom?: string): Promise<StylesConfig | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Load styles configuration from the file system (sync)
|
|
14
|
+
* @param searchFrom - Directory to search from (defaults to process.cwd())
|
|
15
|
+
* @returns Configuration object or empty object if not found
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadConfigSync(searchFrom?: string): StylesConfig;
|
|
18
|
+
/**
|
|
19
|
+
* Load styles configuration with metadata (sync).
|
|
20
|
+
* Includes config file path when a config file is discovered.
|
|
21
|
+
*/
|
|
22
|
+
export declare function loadConfigSyncWithMeta(searchFrom?: string): LoadedConfigMeta;
|
|
23
|
+
/**
|
|
24
|
+
* Load styles configuration from a specific file path (async)
|
|
25
|
+
* @param filePath - Path to the config file
|
|
26
|
+
* @returns Configuration object or null if not found
|
|
27
|
+
*/
|
|
28
|
+
export declare function loadConfigFromPath(filePath: string): Promise<StylesConfig | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Load styles configuration from a specific file path (sync)
|
|
31
|
+
* @param filePath - Path to the config file
|
|
32
|
+
* @returns Configuration object or empty object if not found
|
|
33
|
+
*/
|
|
34
|
+
export declare function loadConfigFromPathSync(filePath: string): StylesConfig;
|
package/lib/options.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { StylesConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options bag the `strict` preset can expand. Any bag carrying a `strict` flag
|
|
4
|
+
* plus the semantic modes it governs.
|
|
5
|
+
*/
|
|
6
|
+
export interface StrictPresetOptions {
|
|
7
|
+
strict?: boolean;
|
|
8
|
+
unitMode?: 'loose' | 'preserve' | 'strict';
|
|
9
|
+
equalityMode?: 'less' | 'sass' | 'exact';
|
|
10
|
+
leakyScope?: boolean;
|
|
11
|
+
allowOverloadedImport?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Expand the `strict` convenience preset. When `strict` is truthy, fills the
|
|
15
|
+
* strict bundle for any governed option left `undefined` — an explicitly set
|
|
16
|
+
* option always wins. Modeled after `tsconfig`'s `strict`: it only *sets*
|
|
17
|
+
* semantic options, it is not itself a mode. Sets the strictest value of each
|
|
18
|
+
* governed axis (`equalityMode: 'exact'` is the no-coercion dialect).
|
|
19
|
+
*
|
|
20
|
+
* Returns a new object (never mutates the input); a no-op when `strict` is falsy.
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyStrictPreset<T extends StrictPresetOptions>(opts: T): T;
|
|
23
|
+
/**
|
|
24
|
+
* Options for retrieving merged configuration
|
|
25
|
+
*/
|
|
26
|
+
export interface GetOptionsParams {
|
|
27
|
+
/**
|
|
28
|
+
* Language key to get options for (e.g., 'less', 'scss', 'jess').
|
|
29
|
+
* If omitted but `input` is provided, language is inferred from the file extension.
|
|
30
|
+
*/
|
|
31
|
+
language?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Input file path to match against input options.
|
|
34
|
+
* Also used to infer language if `language` is not specified.
|
|
35
|
+
*/
|
|
36
|
+
input?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Output file path to match against output options
|
|
39
|
+
*/
|
|
40
|
+
output?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get merged options by combining compile, language, input, and output settings.
|
|
44
|
+
*
|
|
45
|
+
* Merge priority (later wins):
|
|
46
|
+
* 1. compile options (base)
|
|
47
|
+
* 2. language-specific options (inferred from input extension or explicitly specified)
|
|
48
|
+
* 3. matched input options (if input path provided and matches)
|
|
49
|
+
* 4. matched output options (if output path provided and matches)
|
|
50
|
+
*
|
|
51
|
+
* @param config - The styles configuration object
|
|
52
|
+
* @param params - Options specifying language, input file, and output file
|
|
53
|
+
* @returns Merged options object
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Get Less options for a specific input/output (language inferred from .less extension)
|
|
57
|
+
* const options = getOptions(config, {
|
|
58
|
+
* input: 'src/styles/main.less',
|
|
59
|
+
* output: 'dist/main.css'
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Explicitly specify language
|
|
64
|
+
* const options = getOptions(config, { language: 'less' });
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // Get base options without language-specific settings
|
|
68
|
+
* const options = getOptions(config);
|
|
69
|
+
*/
|
|
70
|
+
export declare function getOptions(config?: StylesConfig, params?: GetOptionsParams): Record<string, any>;
|