styles-config 2.0.0-alpha.1 → 2.0.0-alpha.10

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/types.d.ts CHANGED
@@ -7,36 +7,41 @@ export type MathMode = 'always' | 'parens-division' | 'parens' | 'strict';
7
7
  */
8
8
  export type UnitMode = 'loose' | 'preserve' | 'strict';
9
9
  /**
10
- * Equality/coercion modes for guard comparisons.
10
+ * Function-call resolution modes compiler input to the shared evaluator.
11
+ * Governs an optional (global) function call that matched a registered function
12
+ * but couldn't be evaluated: `preserve` renders it as-is (+ warning), `error`
13
+ * throws.
11
14
  */
12
- export type EqualityMode = 'coerce' | 'strict';
13
- export interface JavaScriptSandboxConfig {
14
- /**
15
- * Allow network access for script execution runtime.
16
- * @default false
17
- */
18
- allowHttp?: boolean;
19
- /**
20
- * Optional host allowlist when `allowHttp` is enabled.
21
- */
22
- allowNetHosts?: string[];
23
- /**
24
- * Optional explicit filesystem root for script reads.
25
- * If omitted, compiler resolves using entry/config roots.
26
- */
27
- jsReadRoot?: string;
28
- }
29
- export type CompileJavaScriptOption = true | JavaScriptSandboxConfig;
15
+ export type FunctionMode = 'preserve' | 'error';
16
+ /**
17
+ * Equality compatibility modes for the shared guard evaluator. The names retain
18
+ * their source-compatibility meaning (Less 4.x and Sass diverge in opposite
19
+ * directions), not separate runtime semantics:
20
+ * - `less`: Less 4.x equality (numeric coercion; quoted vs unquoted distinct)
21
+ * - `sass`: Dart Sass equality (unit-strict; quote-insensitive strings)
22
+ * - `exact`: no coercion — operands must be the same node type
23
+ */
24
+ export type EqualityMode = 'less' | 'sass' | 'exact';
25
+ export type ExtendSelectorKind = 'simple' | 'basic' | 'pseudo' | 'complex' | 'compound';
30
26
  /**
31
27
  * Less compiler options
32
28
  * Based on less.js default-options.js and bin/lessc
33
29
  */
34
30
  export interface LessOptions {
31
+ /**
32
+ * Restrict which selector shapes are allowed in extend targets.
33
+ * When set, any other selector kind is a parse error.
34
+ */
35
+ allowExtendSelectors?: ExtendSelectorKind[];
35
36
  /**
36
37
  * Inline Javascript - @plugin still allowed
37
38
  * @default false
38
39
  */
39
40
  javascriptEnabled?: boolean;
41
+ /**
42
+ * @deprecated Use `disableScriptModules` instead.
43
+ */
44
+ disablePluginRule?: boolean;
40
45
  /**
41
46
  * Outputs a makefile import dependency list to stdout.
42
47
  * @default false
@@ -61,6 +66,15 @@ export interface LessOptions {
61
66
  * @default []
62
67
  */
63
68
  paths?: string[];
69
+ /**
70
+ * Controls whether Less imports are loaded and emitted.
71
+ *
72
+ * Less's `processImports: false` path skips import processing; imported
73
+ * stylesheets are neither loaded nor preserved as CSS `@import` statements.
74
+ *
75
+ * @default true
76
+ */
77
+ processImports?: boolean;
64
78
  /**
65
79
  * Color output in the terminal
66
80
  * @default true
@@ -124,11 +138,21 @@ export interface LessOptions {
124
138
  * @default 'preserve'
125
139
  */
126
140
  unitMode?: UnitMode;
141
+ /**
142
+ * How to handle an optional/global function call that matched a registered
143
+ * function but couldn't be evaluated (no matching signature, or it threw) —
144
+ * e.g. `unit(80/16)`, `color("x")`. Mirrors {@link unitMode}.
145
+ * - 'preserve': render the call as-is (like an unknown CSS function) + warn
146
+ * - 'error': throw the underlying function error (Less 4.x behavior)
147
+ * Unknown function names always render as-is regardless.
148
+ * @default 'preserve'
149
+ */
150
+ functionMode?: FunctionMode;
127
151
  /**
128
152
  * How to handle equality/coercion in guards and comparisons.
129
- * - 'coerce': Less-compatible coercion behavior
153
+ * - 'loose': Less-compatible loose (coercive) equality (JS '==')
130
154
  * - 'strict': type-strict behavior
131
- * @default 'coerce'
155
+ * @default 'loose'
132
156
  */
133
157
  equalityMode?: EqualityMode;
134
158
  /**
@@ -201,6 +225,26 @@ export interface LessOptions {
201
225
  * @default false
202
226
  */
203
227
  quiet?: boolean;
228
+ /**
229
+ * Convenience preset. When `true`, sets the strict bundle for any of the
230
+ * following left `undefined` (individual options always win):
231
+ * - `unitMode: 'strict'`
232
+ * - `equalityMode: 'exact'` (the no-coercion dialect)
233
+ * - `leakyScope: false`
234
+ * - `allowOverloadedImport: false`
235
+ *
236
+ * Modeled after `tsconfig` `strict`: it only *sets* semantic options, it is not
237
+ * itself a mode.
238
+ * @default false
239
+ */
240
+ strict?: boolean;
241
+ /**
242
+ * Whether re-importing a file/namespace may contribute *overloaded* (duplicated,
243
+ * additively-merged) definitions rather than being de-duplicated like Less's
244
+ * `@import (once)`. `strict` sets this to `false`.
245
+ * @default true
246
+ */
247
+ allowOverloadedImport?: boolean;
204
248
  /**
205
249
  * @deprecated This is legacy Less behavior.
206
250
  *
@@ -212,7 +256,7 @@ export interface LessOptions {
212
256
  * - Both mixins and detached rulesets: Mixin and VarDeclaration nodes are 'private'
213
257
  * @default true
214
258
  */
215
- leakyRules?: boolean;
259
+ leakyScope?: boolean;
216
260
  /**
217
261
  * Whether to collapse nested selectors (Less 1.x-4.x style flattening)
218
262
  * When true, nested selectors like `.parent { .child { } }` are flattened to `.parent .child { }`
@@ -228,6 +272,13 @@ export interface LessOptions {
228
272
  */
229
273
  bubbleRootAtRules?: boolean;
230
274
  }
275
+ export interface ScssOptions {
276
+ allowExtendSelectors?: ExtendSelectorKind[];
277
+ unitMode?: UnitMode;
278
+ equalityMode?: EqualityMode;
279
+ collapseNesting?: boolean;
280
+ [key: string]: any;
281
+ }
231
282
  /**
232
283
  * Base interface for file-matching options
233
284
  */
@@ -244,9 +295,18 @@ export interface FileMatchOptions {
244
295
  export interface InputOptions extends FileMatchOptions {
245
296
  mathMode?: MathMode;
246
297
  unitMode?: UnitMode;
298
+ functionMode?: FunctionMode;
247
299
  equalityMode?: EqualityMode;
300
+ strict?: boolean;
301
+ allowOverloadedImport?: boolean;
302
+ processImports?: boolean;
303
+ allowExtendSelectors?: ExtendSelectorKind[];
304
+ disableScriptModules?: boolean;
305
+ /**
306
+ * @deprecated Use `disableScriptModules` instead.
307
+ */
308
+ disablePluginRule?: boolean;
248
309
  searchPaths?: string[];
249
- enableJavaScript?: boolean;
250
310
  javascriptEnabled?: boolean;
251
311
  paths?: string[];
252
312
  globalVars?: Record<string, string> | null;
@@ -254,7 +314,7 @@ export interface InputOptions extends FileMatchOptions {
254
314
  strictImports?: boolean | 'error';
255
315
  rewriteUrls?: boolean | 'all' | 'local' | 'off';
256
316
  rootpath?: string;
257
- leakyRules?: boolean;
317
+ leakyScope?: boolean;
258
318
  collapseNesting?: boolean;
259
319
  bubbleRootAtRules?: boolean;
260
320
  /** Allow additional language-specific options */
@@ -292,11 +352,30 @@ export interface StylesConfig {
292
352
  */
293
353
  plugins?: Array<any | string>;
294
354
  searchPaths?: string[];
295
- enableJavaScript?: boolean;
296
- javascript?: CompileJavaScriptOption;
297
355
  mathMode?: MathMode;
298
356
  unitMode?: UnitMode;
357
+ functionMode?: FunctionMode;
299
358
  equalityMode?: EqualityMode;
359
+ /** See {@link LessOptions.strict}. Expanded onto the other compile modes. */
360
+ strict?: boolean;
361
+ /** See {@link LessOptions.allowOverloadedImport}. */
362
+ allowOverloadedImport?: boolean;
363
+ /** See {@link LessOptions.leakyScope}. */
364
+ leakyScope?: boolean;
365
+ /** See {@link LessOptions.processImports}. */
366
+ processImports?: boolean;
367
+ allowExtendSelectors?: ExtendSelectorKind[];
368
+ disableScriptModules?: boolean;
369
+ /**
370
+ * @deprecated Use `disableScriptModules` instead.
371
+ */
372
+ disablePluginRule?: boolean;
373
+ /**
374
+ * Filesystem root that Less `@plugin` / script-module scripts are allowed to
375
+ * be read from. When set, it overrides the default (the entry file's
376
+ * directory). Paths outside this root are rejected by @jesscss/plugin-js.
377
+ */
378
+ jsReadRoot?: string;
300
379
  };
301
380
  /**
302
381
  * Input file options. Can be a single object for defaults, or an array
@@ -312,9 +391,9 @@ export interface StylesConfig {
312
391
  output?: OutputOptions | OutputOptions[];
313
392
  language?: {
314
393
  less?: LessOptions;
315
- scss?: Record<string, any>;
394
+ scss?: ScssOptions;
316
395
  css?: Record<string, any>;
317
396
  jess?: Record<string, any>;
318
- [key: string]: LessOptions | Record<string, any> | undefined;
397
+ [key: string]: LessOptions | ScssOptions | Record<string, any> | undefined;
319
398
  };
320
399
  }
package/package.json CHANGED
@@ -1,35 +1,43 @@
1
1
  {
2
2
  "name": "styles-config",
3
+ "type": "module",
3
4
  "publishConfig": {
4
5
  "access": "public"
5
6
  },
6
- "version": "2.0.0-alpha.1",
7
+ "version": "2.0.0-alpha.10",
8
+ "engines": {
9
+ "node": "^20.19.0 || >=22.12.0"
10
+ },
7
11
  "description": "General-purpose configuration for styling frameworks (Jess, Less, Sass, Tailwind, etc.)",
8
- "main": "lib/index.js",
12
+ "main": "lib/index.cjs",
9
13
  "types": "lib/index.d.ts",
10
14
  "exports": {
11
15
  ".": {
12
- "import": "./lib/index.js",
13
16
  "types": "./lib/index.d.ts",
14
- "source": "./src/index.ts"
17
+ "import": "./lib/index.js",
18
+ "require": "./lib/index.cjs"
15
19
  }
16
20
  },
21
+ "files": [
22
+ "lib"
23
+ ],
17
24
  "dependencies": {
18
- "cosmiconfig": "^9.0.0",
25
+ "cosmiconfig": "^9.0.2",
19
26
  "picomatch": "^4.0.2",
20
- "@jesscss/core": "2.0.0-alpha.1"
27
+ "@jesscss/core": "2.0.0-alpha.10"
21
28
  },
22
29
  "devDependencies": {
23
30
  "@types/node": "^22.10.2",
24
31
  "@types/picomatch": "^3.0.1",
25
32
  "typescript": "^5.7.2",
26
- "vitest": "^2.1.8"
33
+ "vitest": "^4.1.0"
27
34
  },
28
35
  "author": "Matthew Dean",
29
36
  "license": "MIT",
37
+ "module": "lib/index.js",
30
38
  "scripts": {
31
39
  "build": "pnpm compile",
32
- "compile": "tsc -p tsconfig.build.json",
40
+ "compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly --noCheck",
33
41
  "test": "vitest"
34
42
  }
35
43
  }
package/eslint.config.mjs DELETED
@@ -1,6 +0,0 @@
1
- import baseConfig from '../_shared/eslint.config.mjs';
2
-
3
- export default [
4
- ...baseConfig
5
- ];
6
-
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA4C5C;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAGlF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,YAAY,CAGhE;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAGvF;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAGrE"}
package/lib/loader.js DELETED
@@ -1,99 +0,0 @@
1
- import { cosmiconfig, cosmiconfigSync, defaultLoadersSync } from 'cosmiconfig';
2
- const explorer = cosmiconfig('styles', {
3
- searchPlaces: [
4
- 'styles.config.ts',
5
- 'styles.config.js',
6
- 'styles.config.mts',
7
- 'styles.config.mjs',
8
- 'styles.config.cjs',
9
- 'styles.config.cts'
10
- ],
11
- loaders: {
12
- // eslint-disable-next-line @typescript-eslint/naming-convention
13
- '.mts': defaultLoadersSync['.ts'],
14
- // eslint-disable-next-line @typescript-eslint/naming-convention
15
- '.cts': defaultLoadersSync['.ts'],
16
- // eslint-disable-next-line @typescript-eslint/naming-convention
17
- '.mjs': defaultLoadersSync['.js'],
18
- // eslint-disable-next-line @typescript-eslint/naming-convention
19
- '.cjs': defaultLoadersSync['.cjs']
20
- }
21
- });
22
- const explorerSync = cosmiconfigSync('styles', {
23
- searchPlaces: [
24
- 'styles.config.ts',
25
- 'styles.config.js',
26
- 'styles.config.mts',
27
- 'styles.config.mjs',
28
- 'styles.config.cjs',
29
- 'styles.config.cts'
30
- ],
31
- loaders: {
32
- // eslint-disable-next-line @typescript-eslint/naming-convention
33
- '.mts': defaultLoadersSync['.ts'],
34
- // eslint-disable-next-line @typescript-eslint/naming-convention
35
- '.cts': defaultLoadersSync['.ts'],
36
- // eslint-disable-next-line @typescript-eslint/naming-convention
37
- '.mjs': defaultLoadersSync['.js'],
38
- // eslint-disable-next-line @typescript-eslint/naming-convention
39
- '.cjs': defaultLoadersSync['.cjs']
40
- }
41
- });
42
- /**
43
- * Load styles configuration from the file system (async)
44
- * @param searchFrom - Directory to search from (defaults to process.cwd())
45
- * @returns Configuration object or null if not found
46
- */
47
- export async function loadConfig(searchFrom) {
48
- const result = await explorer.search(searchFrom);
49
- return result?.config ? normalizeConfig(result.config) : null;
50
- }
51
- /**
52
- * Load styles configuration from the file system (sync)
53
- * @param searchFrom - Directory to search from (defaults to process.cwd())
54
- * @returns Configuration object or empty object if not found
55
- */
56
- export function loadConfigSync(searchFrom) {
57
- const result = explorerSync.search(searchFrom);
58
- return result?.config ? normalizeConfig(result.config) : {};
59
- }
60
- /**
61
- * Load styles configuration with metadata (sync).
62
- * Includes config file path when a config file is discovered.
63
- */
64
- export function loadConfigSyncWithMeta(searchFrom) {
65
- const result = explorerSync.search(searchFrom);
66
- return {
67
- config: result?.config ? normalizeConfig(result.config) : {},
68
- configFilePath: result?.filepath
69
- };
70
- }
71
- /**
72
- * Load styles configuration from a specific file path (async)
73
- * @param filePath - Path to the config file
74
- * @returns Configuration object or null if not found
75
- */
76
- export async function loadConfigFromPath(filePath) {
77
- const result = await explorer.load(filePath);
78
- return result?.config ? normalizeConfig(result.config) : null;
79
- }
80
- /**
81
- * Load styles configuration from a specific file path (sync)
82
- * @param filePath - Path to the config file
83
- * @returns Configuration object or empty object if not found
84
- */
85
- export function loadConfigFromPathSync(filePath) {
86
- const result = explorerSync.load(filePath);
87
- return result?.config ? normalizeConfig(result.config) : {};
88
- }
89
- /**
90
- * Normalize config object - handle default exports and ensure proper type
91
- */
92
- function normalizeConfig(config) {
93
- // Handle default export (common in ES modules)
94
- if (typeof config === 'object' && config !== null && 'default' in config) {
95
- return config.default;
96
- }
97
- return config;
98
- }
99
- //# sourceMappingURL=loader.js.map
package/lib/loader.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQ/E,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,EAAE;IACrC,YAAY,EAAE;QACZ,kBAAkB;QAClB,kBAAkB;QAClB,mBAAmB;QACnB,mBAAmB;QACnB,mBAAmB;QACnB,mBAAmB;KACpB;IACD,OAAO,EAAE;QACP,gEAAgE;QAChE,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC;QACjC,gEAAgE;QAChE,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC;QACjC,gEAAgE;QAChE,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC;QACjC,gEAAgE;QAChE,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC;KACnC;CACF,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,EAAE;IAC7C,YAAY,EAAE;QACZ,kBAAkB;QAClB,kBAAkB;QAClB,mBAAmB;QACnB,mBAAmB;QACnB,mBAAmB;QACnB,mBAAmB;KACpB;IACD,OAAO,EAAE;QACP,gEAAgE;QAChE,MA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C,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,MAAW;IAClC,+CAA+C;IAC/C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QACzE,OAAO,MAAM,CAAC,OAAuB,CAAC;IACxC,CAAC;IACD,OAAO,MAAsB,CAAC;AAChC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEzD;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,GAAE,YAAiB,GAAG,WAAW,CAcrE;AACD;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,GAAE,YAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAc7E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,GAAE,YAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAc7E"}
package/lib/options.js DELETED
@@ -1,128 +0,0 @@
1
- import picomatch from 'picomatch';
2
- import path from 'path';
3
- /**
4
- * Map of file extensions to language keys
5
- */
6
- const extensionToLanguage = new Map([
7
- ['.less', 'less'],
8
- ['.scss', 'scss'],
9
- ['.sass', 'scss'],
10
- ['.jess', 'jess'],
11
- ['.css', 'css']
12
- ]);
13
- /**
14
- * Infer language from a file path's extension
15
- */
16
- function inferLanguage(filePath) {
17
- if (!filePath) {
18
- return undefined;
19
- }
20
- const ext = path.extname(filePath).toLowerCase();
21
- return extensionToLanguage.get(ext);
22
- }
23
- /**
24
- * Check if a file path matches a pattern (exact path, relative path, or glob)
25
- */
26
- function matchesFile(pattern, filePath) {
27
- if (!pattern || !filePath) {
28
- return false;
29
- }
30
- // Normalize paths for comparison
31
- const normalizedPattern = path.normalize(pattern);
32
- const normalizedFile = path.normalize(filePath);
33
- // Try exact match first
34
- if (normalizedPattern === normalizedFile) {
35
- return true;
36
- }
37
- // Try basename match (e.g., pattern "styles.less" matches "/path/to/styles.less")
38
- if (path.basename(normalizedFile) === normalizedPattern) {
39
- return true;
40
- }
41
- // Try glob/pattern match using picomatch
42
- const isMatch = picomatch(pattern, { dot: true });
43
- return isMatch(filePath) || isMatch(normalizedFile);
44
- }
45
- /**
46
- * Get matching options from an array of file-based options.
47
- * Returns merged options from:
48
- * 1. All entries without a `file` property (defaults)
49
- * 2. All entries whose `file` pattern matches the given path
50
- *
51
- * Later entries override earlier ones.
52
- */
53
- function getMatchingOptions(options, filePath) {
54
- if (!options) {
55
- return {};
56
- }
57
- const optionsArray = Array.isArray(options) ? options : [options];
58
- let result = {};
59
- for (const opt of optionsArray) {
60
- // Include if: no file pattern (default), or file pattern matches
61
- if (!opt.file || (filePath && matchesFile(opt.file, filePath))) {
62
- // Merge this entry's options, excluding the 'file' property
63
- const rest = { ...opt };
64
- delete rest.file;
65
- result = { ...result, ...rest };
66
- }
67
- }
68
- return result;
69
- }
70
- /**
71
- * Get merged options by combining compile, language, input, and output settings.
72
- *
73
- * Merge priority (later wins):
74
- * 1. compile options (base)
75
- * 2. language-specific options (inferred from input extension or explicitly specified)
76
- * 3. matched input options (if input path provided and matches)
77
- * 4. matched output options (if output path provided and matches)
78
- *
79
- * @param config - The styles configuration object
80
- * @param params - Options specifying language, input file, and output file
81
- * @returns Merged options object
82
- *
83
- * @example
84
- * // Get Less options for a specific input/output (language inferred from .less extension)
85
- * const options = getOptions(config, {
86
- * input: 'src/styles/main.less',
87
- * output: 'dist/main.css'
88
- * });
89
- *
90
- * @example
91
- * // Explicitly specify language
92
- * const options = getOptions(config, { language: 'less' });
93
- *
94
- * @example
95
- * // Get base options without language-specific settings
96
- * const options = getOptions(config);
97
- */
98
- export function getOptions(config = {}, params = {}) {
99
- const { input: inputFile, output: outputFile } = params;
100
- const { compile = {}, input, output, language: languageConfig = {} } = config;
101
- // Determine language: explicit param > inferred from input extension
102
- const language = params.language ?? inferLanguage(inputFile);
103
- // Get language-specific options if language is determined
104
- const languageOptions = language ? (languageConfig[language] ?? {}) : {};
105
- // Get matched input and output options
106
- const matchedInput = getMatchingOptions(input, inputFile);
107
- const matchedOutput = getMatchingOptions(output, outputFile);
108
- // Build result with proper merge priority:
109
- // 1. compile (base)
110
- // 2. language-specific
111
- // 3. matched input
112
- // 4. matched output
113
- return {
114
- // Start with compile-level settings
115
- mathMode: compile.mathMode,
116
- unitMode: compile.unitMode,
117
- equalityMode: compile.equalityMode,
118
- paths: compile.searchPaths,
119
- javascriptEnabled: compile.enableJavaScript,
120
- // Override with language-specific settings
121
- ...languageOptions,
122
- // Override with matched input settings
123
- ...matchedInput,
124
- // Override with matched output settings
125
- ...matchedOutput
126
- };
127
- }
128
- //# sourceMappingURL=options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,IAAI,MAAM,MAAM,CAAC;AAsBxB;;GAEG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAiB;IAClD,CAAC,OAAO,EAAE,MAAM,CAAC;IACjB,CAAC,OAAO,EAAE,MAAM,CAAC;IACjB,CAAC,OAAO,EAAE,MAAM,CAAC;IACjB,CAAC,OAAO,EAAE,MAAM,CAAC;IACjB,CAAC,MAAM,EAAE,KAAK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AAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;KAC9D,CAAC;CACH;AAGD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
package/lib/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/lib/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './types.js';
2
- export * from './loader.js';
3
- export * from './options.js';
package/src/loader.ts DELETED
@@ -1,112 +0,0 @@
1
- import { cosmiconfig, cosmiconfigSync, defaultLoadersSync } from 'cosmiconfig';
2
- import type { StylesConfig } from './types.js';
3
-
4
- export interface LoadedConfigMeta {
5
- config: StylesConfig;
6
- configFilePath?: string;
7
- }
8
-
9
- const explorer = cosmiconfig('styles', {
10
- searchPlaces: [
11
- 'styles.config.ts',
12
- 'styles.config.js',
13
- 'styles.config.mts',
14
- 'styles.config.mjs',
15
- 'styles.config.cjs',
16
- 'styles.config.cts'
17
- ],
18
- loaders: {
19
- // eslint-disable-next-line @typescript-eslint/naming-convention
20
- '.mts': defaultLoadersSync['.ts'],
21
- // eslint-disable-next-line @typescript-eslint/naming-convention
22
- '.cts': defaultLoadersSync['.ts'],
23
- // eslint-disable-next-line @typescript-eslint/naming-convention
24
- '.mjs': defaultLoadersSync['.js'],
25
- // eslint-disable-next-line @typescript-eslint/naming-convention
26
- '.cjs': defaultLoadersSync['.cjs']
27
- }
28
- });
29
-
30
- const explorerSync = cosmiconfigSync('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
- // eslint-disable-next-line @typescript-eslint/naming-convention
41
- '.mts': defaultLoadersSync['.ts'],
42
- // eslint-disable-next-line @typescript-eslint/naming-convention
43
- '.cts': defaultLoadersSync['.ts'],
44
- // eslint-disable-next-line @typescript-eslint/naming-convention
45
- '.mjs': defaultLoadersSync['.js'],
46
- // eslint-disable-next-line @typescript-eslint/naming-convention
47
- '.cjs': defaultLoadersSync['.cjs']
48
- }
49
- });
50
-
51
- /**
52
- * Load styles configuration from the file system (async)
53
- * @param searchFrom - Directory to search from (defaults to process.cwd())
54
- * @returns Configuration object or null if not found
55
- */
56
- export async function loadConfig(searchFrom?: string): Promise<StylesConfig | null> {
57
- const result = await explorer.search(searchFrom);
58
- return result?.config ? normalizeConfig(result.config) : null;
59
- }
60
-
61
- /**
62
- * Load styles configuration from the file system (sync)
63
- * @param searchFrom - Directory to search from (defaults to process.cwd())
64
- * @returns Configuration object or empty object if not found
65
- */
66
- export function loadConfigSync(searchFrom?: string): StylesConfig {
67
- const result = explorerSync.search(searchFrom);
68
- return result?.config ? normalizeConfig(result.config) : {};
69
- }
70
-
71
- /**
72
- * Load styles configuration with metadata (sync).
73
- * Includes config file path when a config file is discovered.
74
- */
75
- export function loadConfigSyncWithMeta(searchFrom?: string): LoadedConfigMeta {
76
- const result = explorerSync.search(searchFrom);
77
- return {
78
- config: result?.config ? normalizeConfig(result.config) : {},
79
- configFilePath: result?.filepath
80
- };
81
- }
82
-
83
- /**
84
- * Load styles configuration from a specific file path (async)
85
- * @param filePath - Path to the config file
86
- * @returns Configuration object or null if not found
87
- */
88
- export async function loadConfigFromPath(filePath: string): Promise<StylesConfig | null> {
89
- const result = await explorer.load(filePath);
90
- return result?.config ? normalizeConfig(result.config) : null;
91
- }
92
-
93
- /**
94
- * Load styles configuration from a specific file path (sync)
95
- * @param filePath - Path to the config file
96
- * @returns Configuration object or empty object if not found
97
- */
98
- export function loadConfigFromPathSync(filePath: string): StylesConfig {
99
- const result = explorerSync.load(filePath);
100
- return result?.config ? normalizeConfig(result.config) : {};
101
- }
102
-
103
- /**
104
- * Normalize config object - handle default exports and ensure proper type
105
- */
106
- function normalizeConfig(config: any): StylesConfig {
107
- // Handle default export (common in ES modules)
108
- if (typeof config === 'object' && config !== null && 'default' in config) {
109
- return config.default as StylesConfig;
110
- }
111
- return config as StylesConfig;
112
- }