styles-config 2.0.0-alpha.5 → 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/package.json CHANGED
@@ -1,35 +1,40 @@
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.5",
7
+ "version": "2.0.0-alpha.7",
7
8
  "description": "General-purpose configuration for styling frameworks (Jess, Less, Sass, Tailwind, etc.)",
8
- "main": "lib/index.js",
9
+ "main": "lib/index.cjs",
9
10
  "types": "lib/index.d.ts",
10
11
  "exports": {
11
12
  ".": {
12
- "import": "./lib/index.js",
13
13
  "types": "./lib/index.d.ts",
14
- "source": "./src/index.ts"
14
+ "import": "./lib/index.js",
15
+ "require": "./lib/index.cjs"
15
16
  }
16
17
  },
18
+ "files": [
19
+ "lib"
20
+ ],
17
21
  "dependencies": {
18
22
  "cosmiconfig": "^9.0.0",
19
23
  "picomatch": "^4.0.2",
20
- "@jesscss/core": "2.0.0-alpha.5"
24
+ "@jesscss/core": "2.0.0-alpha.7"
21
25
  },
22
26
  "devDependencies": {
23
27
  "@types/node": "^22.10.2",
24
28
  "@types/picomatch": "^3.0.1",
25
29
  "typescript": "^5.7.2",
26
- "vitest": "^2.1.8"
30
+ "vitest": "^4.1.0"
27
31
  },
28
32
  "author": "Matthew Dean",
29
33
  "license": "MIT",
34
+ "module": "lib/index.js",
30
35
  "scripts": {
31
36
  "build": "pnpm compile",
32
- "compile": "tsc -p tsconfig.build.json",
37
+ "compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly --noCheck",
33
38
  "test": "vitest"
34
39
  }
35
40
  }
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,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAA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AAM,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,CAAC;CAChB,CAAC,CAAC;AAEH;;G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,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
- }
package/src/options.ts DELETED
@@ -1,172 +0,0 @@
1
- import type { StylesConfig, FileMatchOptions } from './types.js';
2
- import picomatch from 'picomatch';
3
- import path from 'path';
4
-
5
- /**
6
- * Options for retrieving merged configuration
7
- */
8
- export interface GetOptionsParams {
9
- /**
10
- * Language key to get options for (e.g., 'less', 'scss', 'jess').
11
- * If omitted but `input` is provided, language is inferred from the file extension.
12
- */
13
- language?: string;
14
- /**
15
- * Input file path to match against input options.
16
- * Also used to infer language if `language` is not specified.
17
- */
18
- input?: string;
19
- /**
20
- * Output file path to match against output options
21
- */
22
- output?: string;
23
- }
24
-
25
- /**
26
- * Map of file extensions to language keys
27
- */
28
- const extensionToLanguage = new Map<string, string>([
29
- ['.less', 'less'],
30
- ['.scss', 'scss'],
31
- ['.sass', 'scss'],
32
- ['.jess', 'jess'],
33
- ['.css', 'css']
34
- ]);
35
-
36
- /**
37
- * Infer language from a file path's extension
38
- */
39
- function inferLanguage(filePath: string | undefined): string | undefined {
40
- if (!filePath) {
41
- return undefined;
42
- }
43
- const ext = path.extname(filePath).toLowerCase();
44
- return extensionToLanguage.get(ext);
45
- }
46
-
47
- /**
48
- * Check if a file path matches a pattern (exact path, relative path, or glob)
49
- */
50
- function matchesFile(pattern: string | undefined, filePath: string | undefined): boolean {
51
- if (!pattern || !filePath) {
52
- return false;
53
- }
54
-
55
- // Normalize paths for comparison
56
- const normalizedPattern = path.normalize(pattern);
57
- const normalizedFile = path.normalize(filePath);
58
-
59
- // Try exact match first
60
- if (normalizedPattern === normalizedFile) {
61
- return true;
62
- }
63
-
64
- // Try basename match (e.g., pattern "styles.less" matches "/path/to/styles.less")
65
- if (path.basename(normalizedFile) === normalizedPattern) {
66
- return true;
67
- }
68
-
69
- // Try glob/pattern match using picomatch
70
- const isMatch = picomatch(pattern, { dot: true });
71
- return isMatch(filePath) || isMatch(normalizedFile);
72
- }
73
-
74
- /**
75
- * Get matching options from an array of file-based options.
76
- * Returns merged options from:
77
- * 1. All entries without a `file` property (defaults)
78
- * 2. All entries whose `file` pattern matches the given path
79
- *
80
- * Later entries override earlier ones.
81
- */
82
- function getMatchingOptions<T extends FileMatchOptions>(
83
- options: T | T[] | undefined,
84
- filePath?: string
85
- ): Partial<T> {
86
- if (!options) {
87
- return {};
88
- }
89
-
90
- const optionsArray = Array.isArray(options) ? options : [options];
91
- let result: Partial<T> = {};
92
-
93
- for (const opt of optionsArray) {
94
- // Include if: no file pattern (default), or file pattern matches
95
- if (!opt.file || (filePath && matchesFile(opt.file, filePath))) {
96
- // Merge this entry's options, excluding the 'file' property
97
- const rest = { ...opt } as Record<string, unknown>;
98
- delete rest.file;
99
- result = { ...result, ...rest };
100
- }
101
- }
102
-
103
- return result;
104
- }
105
- /**
106
- * Get merged options by combining compile, language, input, and output settings.
107
- *
108
- * Merge priority (later wins):
109
- * 1. compile options (base)
110
- * 2. language-specific options (inferred from input extension or explicitly specified)
111
- * 3. matched input options (if input path provided and matches)
112
- * 4. matched output options (if output path provided and matches)
113
- *
114
- * @param config - The styles configuration object
115
- * @param params - Options specifying language, input file, and output file
116
- * @returns Merged options object
117
- *
118
- * @example
119
- * // Get Less options for a specific input/output (language inferred from .less extension)
120
- * const options = getOptions(config, {
121
- * input: 'src/styles/main.less',
122
- * output: 'dist/main.css'
123
- * });
124
- *
125
- * @example
126
- * // Explicitly specify language
127
- * const options = getOptions(config, { language: 'less' });
128
- *
129
- * @example
130
- * // Get base options without language-specific settings
131
- * const options = getOptions(config);
132
- */
133
- export function getOptions(
134
- config: StylesConfig = {},
135
- params: GetOptionsParams = {}
136
- ): Record<string, any> {
137
- const { input: inputFile, output: outputFile } = params;
138
- const { compile = {}, input, output, language: languageConfig = {} } = config;
139
-
140
- // Determine language: explicit param > inferred from input extension
141
- const language = params.language ?? inferLanguage(inputFile);
142
-
143
- // Get language-specific options if language is determined
144
- const languageOptions = language ? (languageConfig[language] ?? {}) : {};
145
-
146
- // Get matched input and output options
147
- const matchedInput = getMatchingOptions(input, inputFile);
148
- const matchedOutput = getMatchingOptions(output, outputFile);
149
-
150
- // Build result with proper merge priority:
151
- // 1. compile (base)
152
- // 2. language-specific
153
- // 3. matched input
154
- // 4. matched output
155
- return {
156
- // Start with compile-level settings
157
- mathMode: compile.mathMode,
158
- unitMode: compile.unitMode,
159
- equalityMode: compile.equalityMode,
160
- paths: compile.searchPaths,
161
- javascriptEnabled: compile.enableJavaScript,
162
-
163
- // Override with language-specific settings
164
- ...languageOptions,
165
-
166
- // Override with matched input settings
167
- ...matchedInput,
168
-
169
- // Override with matched output settings
170
- ...matchedOutput
171
- };
172
- }