jess 1.0.8-alpha.7 → 2.0.0-alpha.2
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/bin/cli.js +47 -87
- package/lib/config.d.ts +33 -2
- package/lib/config.js +101 -14
- package/lib/config.js.map +1 -0
- package/lib/diagnostics.d.ts +14 -0
- package/lib/diagnostics.js +153 -0
- package/lib/diagnostics.js.map +1 -0
- package/lib/index.d.ts +84 -8
- package/lib/index.js +655 -20
- package/lib/index.js.map +1 -0
- package/lib/output.d.ts +1 -1
- package/lib/output.js +7 -12
- package/lib/output.js.map +1 -0
- package/lib/test/config-merge.test.d.ts +1 -0
- package/lib/test/config-merge.test.js +141 -0
- package/lib/test/config-merge.test.js.map +1 -0
- package/lib/test/debug-extend-structure.test.d.ts +1 -0
- package/lib/test/debug-extend-structure.test.js +151 -0
- package/lib/test/debug-extend-structure.test.js.map +1 -0
- package/lib/test/debug-zap-extend.test.d.ts +1 -0
- package/lib/test/debug-zap-extend.test.js +55 -0
- package/lib/test/debug-zap-extend.test.js.map +1 -0
- package/lib/test/diagnostics.test.d.ts +1 -0
- package/lib/test/diagnostics.test.js +63 -0
- package/lib/test/diagnostics.test.js.map +1 -0
- package/lib/test/files/imports/compute.d.ts +4 -0
- package/lib/test/files/imports/compute.js +7 -0
- package/lib/test/files/imports/compute.js.map +1 -0
- package/lib/test/index.d.ts +1 -0
- package/lib/test/index.js +22 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/less/all-less.test.d.ts +1 -0
- package/lib/test/less/all-less.test.js +131 -0
- package/lib/test/less/all-less.test.js.map +1 -0
- package/lib/test/less/at-plugin.test.d.ts +4 -0
- package/lib/test/less/at-plugin.test.js +299 -0
- package/lib/test/less/at-plugin.test.js.map +1 -0
- package/lib/test/less/at-rules.test.d.ts +1 -0
- package/lib/test/less/at-rules.test.js +57 -0
- package/lib/test/less/at-rules.test.js.map +1 -0
- package/lib/test/less/basic-variables.test.d.ts +1 -0
- package/lib/test/less/basic-variables.test.js +31 -0
- package/lib/test/less/basic-variables.test.js.map +1 -0
- package/lib/test/less/colors.test.d.ts +1 -0
- package/lib/test/less/colors.test.js +39 -0
- package/lib/test/less/colors.test.js.map +1 -0
- package/lib/test/less/debug-escape.test.d.ts +0 -0
- package/lib/test/less/debug-escape.test.js +2 -0
- package/lib/test/less/debug-escape.test.js.map +1 -0
- package/lib/test/less/debug-extend-count.test.d.ts +1 -0
- package/lib/test/less/debug-extend-count.test.js +67 -0
- package/lib/test/less/debug-extend-count.test.js.map +1 -0
- package/lib/test/less/debug-extend-d.test.d.ts +1 -0
- package/lib/test/less/debug-extend-d.test.js +59 -0
- package/lib/test/less/debug-extend-d.test.js.map +1 -0
- package/lib/test/less/debug-variable.test.d.ts +0 -0
- package/lib/test/less/debug-variable.test.js +2 -0
- package/lib/test/less/debug-variable.test.js.map +1 -0
- package/lib/test/less/expressions.test.d.ts +1 -0
- package/lib/test/less/expressions.test.js +43 -0
- package/lib/test/less/expressions.test.js.map +1 -0
- package/lib/test/less/functions.test.d.ts +1 -0
- package/lib/test/less/functions.test.js +295 -0
- package/lib/test/less/functions.test.js.map +1 -0
- package/lib/test/less/import-url.test.d.ts +1 -0
- package/lib/test/less/import-url.test.js +53 -0
- package/lib/test/less/import-url.test.js.map +1 -0
- package/lib/test/less/interpolated-names.test.d.ts +1 -0
- package/lib/test/less/interpolated-names.test.js +61 -0
- package/lib/test/less/interpolated-names.test.js.map +1 -0
- package/lib/test/less/less.d.ts +1 -0
- package/lib/test/less/less.js +36 -0
- package/lib/test/less/less.js.map +1 -0
- package/lib/test/less/mixin-basic.test.d.ts +1 -0
- package/lib/test/less/mixin-basic.test.js +52 -0
- package/lib/test/less/mixin-basic.test.js.map +1 -0
- package/lib/test/less/mixin-lookup-scope.test.d.ts +1 -0
- package/lib/test/less/mixin-lookup-scope.test.js +108 -0
- package/lib/test/less/mixin-lookup-scope.test.js.map +1 -0
- package/lib/test/less/mixins.test.d.ts +1 -0
- package/lib/test/less/mixins.test.js +594 -0
- package/lib/test/less/mixins.test.js.map +1 -0
- package/lib/test/less/nesting.test.d.ts +1 -0
- package/lib/test/less/nesting.test.js +34 -0
- package/lib/test/less/nesting.test.js.map +1 -0
- package/lib/test/less/operations.test.d.ts +1 -0
- package/lib/test/less/operations.test.js +288 -0
- package/lib/test/less/operations.test.js.map +1 -0
- package/lib/test/less/property-accessor.test.d.ts +1 -0
- package/lib/test/less/property-accessor.test.js +30 -0
- package/lib/test/less/property-accessor.test.js.map +1 -0
- package/lib/test/less/property-accessors.test.d.ts +1 -0
- package/lib/test/less/property-accessors.test.js +267 -0
- package/lib/test/less/property-accessors.test.js.map +1 -0
- package/lib/test/less/static-names.test.d.ts +1 -0
- package/lib/test/less/static-names.test.js +100 -0
- package/lib/test/less/static-names.test.js.map +1 -0
- package/lib/test/less/suite.test.d.ts +1 -0
- package/lib/test/less/suite.test.js +215 -0
- package/lib/test/less/suite.test.js.map +1 -0
- package/lib/test/less/token-debug.test.d.ts +1 -0
- package/lib/test/less/token-debug.test.js +28 -0
- package/lib/test/less/token-debug.test.js.map +1 -0
- package/lib/test/less/variables.test.d.ts +1 -0
- package/lib/test/less/variables.test.js +158 -0
- package/lib/test/less/variables.test.js.map +1 -0
- package/lib/test/test-utils.d.ts +17 -0
- package/lib/test/test-utils.js +61 -0
- package/lib/test/test-utils.js.map +1 -0
- package/lib/visitor/index.d.ts +2 -2
- package/lib/visitor/index.js +2 -5
- package/lib/visitor/index.js.map +1 -0
- package/package.json +51 -32
- package/lib/context.d.ts +0 -50
- package/lib/context.js +0 -88
- package/lib/parser/__tests__/cst-visitor.d.ts +0 -1
- package/lib/parser/__tests__/cst-visitor.js +0 -322
- package/lib/parser/cst-visitor.d.ts +0 -47
- package/lib/parser/cst-visitor.js +0 -250
- package/lib/parser/index.d.ts +0 -8
- package/lib/parser/index.js +0 -43
- package/lib/parser/util.d.ts +0 -15
- package/lib/parser/util.js +0 -141
- package/lib/plugin/rollup.d.ts +0 -4
- package/lib/plugin/rollup.js +0 -54
- package/lib/render-css.d.ts +0 -12
- package/lib/render-css.js +0 -26
- package/lib/render-module.d.ts +0 -14
- package/lib/render-module.js +0 -61
- package/lib/render.d.ts +0 -4
- package/lib/render.js +0 -84
- package/lib/tree/__tests__/ampersand.d.ts +0 -1
- package/lib/tree/__tests__/ampersand.js +0 -37
- package/lib/tree/__tests__/call.d.ts +0 -1
- package/lib/tree/__tests__/call.js +0 -30
- package/lib/tree/__tests__/declaration.d.ts +0 -1
- package/lib/tree/__tests__/declaration.js +0 -24
- package/lib/tree/__tests__/dimension.d.ts +0 -1
- package/lib/tree/__tests__/dimension.js +0 -33
- package/lib/tree/__tests__/element.d.ts +0 -1
- package/lib/tree/__tests__/element.js +0 -44
- package/lib/tree/__tests__/expression.d.ts +0 -1
- package/lib/tree/__tests__/expression.js +0 -13
- package/lib/tree/__tests__/include.d.ts +0 -1
- package/lib/tree/__tests__/include.js +0 -34
- package/lib/tree/__tests__/let.d.ts +0 -1
- package/lib/tree/__tests__/let.js +0 -53
- package/lib/tree/__tests__/list.d.ts +0 -1
- package/lib/tree/__tests__/list.js +0 -24
- package/lib/tree/__tests__/mixin.d.ts +0 -1
- package/lib/tree/__tests__/mixin.js +0 -32
- package/lib/tree/__tests__/root.d.ts +0 -1
- package/lib/tree/__tests__/root.js +0 -21
- package/lib/tree/__tests__/rule.d.ts +0 -1
- package/lib/tree/__tests__/rule.js +0 -36
- package/lib/tree/__tests__/ruleset.d.ts +0 -1
- package/lib/tree/__tests__/ruleset.js +0 -49
- package/lib/tree/__tests__/selector.d.ts +0 -1
- package/lib/tree/__tests__/selector.js +0 -26
- package/lib/tree/__tests__/spaced.d.ts +0 -1
- package/lib/tree/__tests__/spaced.js +0 -11
- package/lib/tree/ampersand.d.ts +0 -15
- package/lib/tree/ampersand.js +0 -29
- package/lib/tree/anonymous.d.ts +0 -12
- package/lib/tree/anonymous.js +0 -17
- package/lib/tree/at-rule.d.ts +0 -22
- package/lib/tree/at-rule.js +0 -67
- package/lib/tree/call.d.ts +0 -15
- package/lib/tree/call.js +0 -81
- package/lib/tree/color.d.ts +0 -31
- package/lib/tree/color.js +0 -172
- package/lib/tree/combinator.d.ts +0 -9
- package/lib/tree/combinator.js +0 -17
- package/lib/tree/custom.d.ts +0 -17
- package/lib/tree/custom.js +0 -46
- package/lib/tree/declaration.d.ts +0 -21
- package/lib/tree/declaration.js +0 -57
- package/lib/tree/dimension.d.ts +0 -17
- package/lib/tree/dimension.js +0 -51
- package/lib/tree/element.d.ts +0 -18
- package/lib/tree/element.js +0 -65
- package/lib/tree/expression.d.ts +0 -15
- package/lib/tree/expression.js +0 -95
- package/lib/tree/include.d.ts +0 -10
- package/lib/tree/include.js +0 -65
- package/lib/tree/index.d.ts +0 -39
- package/lib/tree/index.js +0 -63
- package/lib/tree/js-collection.d.ts +0 -13
- package/lib/tree/js-collection.js +0 -45
- package/lib/tree/js-expr.d.ts +0 -20
- package/lib/tree/js-expr.js +0 -38
- package/lib/tree/js-ident.d.ts +0 -14
- package/lib/tree/js-ident.js +0 -72
- package/lib/tree/js-import.d.ts +0 -16
- package/lib/tree/js-import.js +0 -24
- package/lib/tree/js-key-value.d.ts +0 -25
- package/lib/tree/js-key-value.js +0 -43
- package/lib/tree/js-node.d.ts +0 -8
- package/lib/tree/js-node.js +0 -10
- package/lib/tree/let.d.ts +0 -28
- package/lib/tree/let.js +0 -65
- package/lib/tree/list.d.ts +0 -16
- package/lib/tree/list.js +0 -59
- package/lib/tree/mixin.d.ts +0 -32
- package/lib/tree/mixin.js +0 -56
- package/lib/tree/nil.d.ts +0 -15
- package/lib/tree/nil.js +0 -24
- package/lib/tree/node.d.ts +0 -64
- package/lib/tree/node.js +0 -171
- package/lib/tree/paren.d.ts +0 -12
- package/lib/tree/paren.js +0 -24
- package/lib/tree/root.d.ts +0 -13
- package/lib/tree/root.js +0 -110
- package/lib/tree/rule.d.ts +0 -26
- package/lib/tree/rule.js +0 -63
- package/lib/tree/ruleset.d.ts +0 -32
- package/lib/tree/ruleset.js +0 -166
- package/lib/tree/selector.d.ts +0 -22
- package/lib/tree/selector.js +0 -94
- package/lib/tree/spaced.d.ts +0 -14
- package/lib/tree/spaced.js +0 -41
- package/lib/tree/square.d.ts +0 -12
- package/lib/tree/square.js +0 -23
- package/lib/tree/ws.d.ts +0 -13
- package/lib/tree/ws.js +0 -29
- package/lib/util.d.ts +0 -32
- package/lib/util.js +0 -51
package/bin/cli.js
CHANGED
|
@@ -1,97 +1,57 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
.option('b', {
|
|
32
|
-
alias: 'bundle',
|
|
33
|
-
default: false,
|
|
34
|
-
type: 'boolean',
|
|
35
|
-
describe: 'Create a runtime bundle module'
|
|
36
|
-
})
|
|
37
|
-
.example([
|
|
38
|
-
['$0 input.jess', 'Compile to input.css'],
|
|
39
|
-
['$0 input.jess output.css', 'Customize output file'],
|
|
40
|
-
['$0 input.jess -o dist', 'Output to the dist directory']
|
|
41
|
-
])
|
|
42
|
-
|
|
43
|
-
const argv = args.argv
|
|
2
|
+
import yargs from 'yargs/yargs';
|
|
3
|
+
import { hideBin } from 'yargs/helpers';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import { Compiler } from '../lib/index.js';
|
|
8
|
+
|
|
9
|
+
const args = yargs(hideBin(process.argv))
|
|
10
|
+
.check((argv) => {
|
|
11
|
+
const filePaths = argv._;
|
|
12
|
+
if (!filePaths.length) {
|
|
13
|
+
throw new Error(chalk.yellow('Input filename required.'));
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
})
|
|
17
|
+
.option('o', {
|
|
18
|
+
alias: 'out',
|
|
19
|
+
describe: 'Output folder',
|
|
20
|
+
type: 'string'
|
|
21
|
+
})
|
|
22
|
+
.example([
|
|
23
|
+
['$0 input.jess', 'Compile to input.css'],
|
|
24
|
+
['$0 input.less', 'Compile Less to input.css'],
|
|
25
|
+
['$0 input.jess output.css', 'Customize output file'],
|
|
26
|
+
['$0 input.jess -o dist', 'Output to the dist directory']
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
const argv = args.parseSync();
|
|
44
30
|
|
|
45
31
|
const start = async () => {
|
|
46
|
-
const startTime =
|
|
47
|
-
const files = argv._
|
|
48
|
-
const inFile = files[0]
|
|
49
|
-
let cssFile = files[1]
|
|
50
|
-
const outDir = path.resolve(process.cwd(), argv.o || path.dirname(cssFile))
|
|
51
|
-
cssFile = path.basename(cssFile)
|
|
32
|
+
const startTime = Date.now();
|
|
33
|
+
const files = argv._;
|
|
34
|
+
const inFile = String(files[0]);
|
|
35
|
+
let cssFile = files[1] ? String(files[1]) : inFile.replace(/\.(jess|less)$/, '.css');
|
|
36
|
+
const outDir = path.resolve(process.cwd(), argv.o || path.dirname(cssFile));
|
|
37
|
+
cssFile = path.basename(cssFile);
|
|
52
38
|
|
|
53
39
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
} catch (e) {
|
|
59
|
-
throw new Error(`Could not read "${inFile}"`)
|
|
40
|
+
await fs.promises.access(path.resolve(process.cwd(), inFile), fs.constants.R_OK);
|
|
41
|
+
} catch {
|
|
42
|
+
throw new Error(`Could not read "${inFile}"`);
|
|
60
43
|
}
|
|
61
|
-
|
|
62
|
-
let css
|
|
63
44
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
input: inFile,
|
|
67
|
-
plugins: [
|
|
68
|
-
commonJs(),
|
|
69
|
-
nodeResolve(),
|
|
70
|
-
jess()
|
|
71
|
-
]
|
|
72
|
-
})
|
|
73
|
-
const { output } = await bundle.generate({
|
|
74
|
-
plugins: [terser()]
|
|
75
|
-
})
|
|
76
|
-
const js = output[0].code
|
|
77
|
-
const jsFile = cssFile.replace(/\.css/, '.js')
|
|
78
|
-
await fs.promises.writeFile(path.resolve(outDir, jsFile), js)
|
|
79
|
-
css = output[1].source
|
|
80
|
-
} else {
|
|
81
|
-
/** @todo - Allow setting of options in the cli? */
|
|
82
|
-
/** @todo - Write bundles and map */
|
|
83
|
-
const result = await render(inFile, {})
|
|
84
|
-
css = result.$toCSS()
|
|
85
|
-
}
|
|
45
|
+
const compiler = new Compiler();
|
|
46
|
+
const css = await compiler.render(inFile, {});
|
|
86
47
|
|
|
87
|
-
await fs.promises.writeFile(path.resolve(outDir, cssFile), css)
|
|
48
|
+
await fs.promises.writeFile(path.resolve(outDir, cssFile), css);
|
|
88
49
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
50
|
+
const seconds = Math.round((Date.now() - startTime) / 10) / 100;
|
|
51
|
+
console.log(`${chalk.blue('Finished in')} ${chalk.cyan(seconds + 's')}`);
|
|
52
|
+
};
|
|
93
53
|
|
|
94
|
-
start()
|
|
95
|
-
.
|
|
96
|
-
|
|
97
|
-
|
|
54
|
+
start().catch((e) => {
|
|
55
|
+
console.error(chalk.red(e.message));
|
|
56
|
+
process.exit(1);
|
|
57
|
+
});
|
package/lib/config.d.ts
CHANGED
|
@@ -1,2 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { type StylesConfig } from 'styles-config';
|
|
2
|
+
/**
|
|
3
|
+
* Get configuration from styles.config.* or jess.config.* file, searching from the given directory
|
|
4
|
+
* up through parent directories.
|
|
5
|
+
*
|
|
6
|
+
* @param searchFrom - File or directory path to start searching from (searches up to root)
|
|
7
|
+
* @returns Configuration object, or empty object if no config found
|
|
8
|
+
*/
|
|
9
|
+
export declare const getConfig: (searchFrom?: string) => StylesConfig;
|
|
10
|
+
export interface ConfigWithMeta {
|
|
11
|
+
config: StylesConfig;
|
|
12
|
+
configFilePath?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const getConfigWithMeta: (searchFrom?: string) => ConfigWithMeta;
|
|
15
|
+
export interface OutputTestConfig {
|
|
16
|
+
file: string;
|
|
17
|
+
config: Partial<StylesConfig>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the expected output CSS file(s) and config(s) for testing.
|
|
21
|
+
*
|
|
22
|
+
* Supports:
|
|
23
|
+
* - No output config: Returns default {name}.css with empty config
|
|
24
|
+
* - Single output object: `output: { file: "{name}.css", collapseNesting: false, ... }`
|
|
25
|
+
* - Returns the file and uses those options for compilation
|
|
26
|
+
* - Multiple outputs array: `output: [{ file: "{name}.css", ... }, ...]`
|
|
27
|
+
* - Returns array of {file, config} objects - test should iterate and test each
|
|
28
|
+
* - Default options: First object in array without `file` property provides defaults
|
|
29
|
+
*
|
|
30
|
+
* @param lessFilePath - Path to the LESS file
|
|
31
|
+
* @returns Single output config, or array of output configs if multiple outputs defined
|
|
32
|
+
*/
|
|
33
|
+
export declare function getExpectedOutputFiles(lessFilePath: string): OutputTestConfig | OutputTestConfig[];
|
package/lib/config.js
CHANGED
|
@@ -1,15 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { loadConfigSync, loadConfigSyncWithMeta } from 'styles-config';
|
|
3
|
+
/**
|
|
4
|
+
* Get configuration from styles.config.* or jess.config.* file, searching from the given directory
|
|
5
|
+
* up through parent directories.
|
|
6
|
+
*
|
|
7
|
+
* @param searchFrom - File or directory path to start searching from (searches up to root)
|
|
8
|
+
* @returns Configuration object, or empty object if no config found
|
|
9
|
+
*/
|
|
10
|
+
export const getConfig = (searchFrom) => {
|
|
11
|
+
return loadConfigSync(searchFrom);
|
|
12
|
+
};
|
|
13
|
+
export const getConfigWithMeta = (searchFrom) => {
|
|
14
|
+
return loadConfigSyncWithMeta(searchFrom);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Get the expected output CSS file(s) and config(s) for testing.
|
|
18
|
+
*
|
|
19
|
+
* Supports:
|
|
20
|
+
* - No output config: Returns default {name}.css with empty config
|
|
21
|
+
* - Single output object: `output: { file: "{name}.css", collapseNesting: false, ... }`
|
|
22
|
+
* - Returns the file and uses those options for compilation
|
|
23
|
+
* - Multiple outputs array: `output: [{ file: "{name}.css", ... }, ...]`
|
|
24
|
+
* - Returns array of {file, config} objects - test should iterate and test each
|
|
25
|
+
* - Default options: First object in array without `file` property provides defaults
|
|
26
|
+
*
|
|
27
|
+
* @param lessFilePath - Path to the LESS file
|
|
28
|
+
* @returns Single output config, or array of output configs if multiple outputs defined
|
|
29
|
+
*/
|
|
30
|
+
export function getExpectedOutputFiles(lessFilePath) {
|
|
31
|
+
// getConfig expects a directory, so pass the directory of the less file
|
|
32
|
+
const config = getConfig(path.dirname(lessFilePath));
|
|
33
|
+
const outputConfig = config.output;
|
|
34
|
+
// Preserve non-output config (compile/language/etc.) so fixture-level styles.config
|
|
35
|
+
// can drive compiler behavior in tests.
|
|
36
|
+
const { output: ignoredOutput, ...baseConfig } = config;
|
|
37
|
+
void ignoredOutput;
|
|
38
|
+
// Extract file name without extension for {name} replacement
|
|
39
|
+
const dir = path.dirname(lessFilePath);
|
|
40
|
+
const name = path.basename(lessFilePath, path.extname(lessFilePath));
|
|
41
|
+
// No output config, default to {name}.css
|
|
42
|
+
if (!outputConfig) {
|
|
43
|
+
return {
|
|
44
|
+
file: path.join(dir, `${name}.css`),
|
|
45
|
+
config: baseConfig
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// Handle single output object
|
|
49
|
+
if (!Array.isArray(outputConfig)) {
|
|
50
|
+
const file = outputConfig.file || '{name}.css';
|
|
51
|
+
const outputFile = file.replace('{name}', name);
|
|
52
|
+
// Extract config options (everything except 'file')
|
|
53
|
+
const configOptions = Object.fromEntries(Object.entries(outputConfig).filter(([key]) => key !== 'file'));
|
|
54
|
+
return {
|
|
55
|
+
file: path.join(dir, outputFile),
|
|
56
|
+
config: { ...baseConfig, output: configOptions }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Handle array of outputs
|
|
60
|
+
if (outputConfig.length === 0) {
|
|
61
|
+
return {
|
|
62
|
+
file: path.join(dir, `${name}.css`),
|
|
63
|
+
config: {}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// First object without 'file' property is default options
|
|
67
|
+
let defaultOptions = {};
|
|
68
|
+
let startIndex = 0;
|
|
69
|
+
if (outputConfig[0] && !('file' in outputConfig[0])) {
|
|
70
|
+
defaultOptions = { ...outputConfig[0] };
|
|
71
|
+
startIndex = 1;
|
|
72
|
+
}
|
|
73
|
+
// Build array of output configs
|
|
74
|
+
const outputs = [];
|
|
75
|
+
for (let i = startIndex; i < outputConfig.length; i++) {
|
|
76
|
+
const output = outputConfig[i];
|
|
77
|
+
if (!output || typeof output !== 'object' || !('file' in output)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
// Merge default options with this output's options
|
|
81
|
+
const { file: outputFile, ...outputOptions } = output;
|
|
82
|
+
const mergedOptions = { ...defaultOptions, ...outputOptions };
|
|
83
|
+
const file = outputFile || '{name}.css';
|
|
84
|
+
const finalFile = file.replace('{name}', name);
|
|
85
|
+
outputs.push({
|
|
86
|
+
file: path.join(dir, finalFile),
|
|
87
|
+
config: { ...baseConfig, output: mergedOptions }
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// If only one output, return it directly (not as array)
|
|
91
|
+
if (outputs.length === 1) {
|
|
92
|
+
return outputs[0];
|
|
93
|
+
}
|
|
94
|
+
// Return array if multiple outputs
|
|
95
|
+
return outputs.length > 0
|
|
96
|
+
? outputs
|
|
97
|
+
: [{
|
|
98
|
+
file: path.join(dir, `${name}.css`),
|
|
99
|
+
config: baseConfig
|
|
100
|
+
}];
|
|
14
101
|
}
|
|
15
|
-
|
|
102
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAqB,MAAM,eAAe,CAAC;AAE1F;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,UAAmB,EAAgB,EAAE;IAC7D,OAAO,cAAc,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC,CAAC;AAOF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,UAAmB,EAAkB,EAAE;IACvE,OAAO,sBAAsB,CAAC,UAAU,CAAC,CAAC;AAC5C,CAAC,CAAC;AAOF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAAoB;IAEpB,wEAAwE;IACxE,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IACrD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,oFAAoF;IACpF,wCAAwC;IACxC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,UAAU,EAAE,GAAG,MAAgD,CAAC;IAClG,KAAK,aAAa,CAAC;IAEnB,6DAA6D;IAC7D,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,IAAI,C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AAE,GAAG,IAAI,MAAM,CAAC;gBACnC,MAAM,EAAE,UAAU;aACnB,CAAC,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ErrorDiagnostic, WarningDiagnostic } from '@jesscss/core';
|
|
2
|
+
/**
|
|
3
|
+
* Formats and outputs diagnostics (errors and warnings) to the console.
|
|
4
|
+
* Uses linecraft's CodeDebug component for formatted code frames.
|
|
5
|
+
*
|
|
6
|
+
* @param errors - Array of error diagnostics
|
|
7
|
+
* @param warnings - Array of warning diagnostics
|
|
8
|
+
* @param options - Output options
|
|
9
|
+
*/
|
|
10
|
+
export declare function outputDiagnostics(errors: ErrorDiagnostic[], warnings: WarningDiagnostic[], options?: {
|
|
11
|
+
suppressWarnings?: boolean;
|
|
12
|
+
breakOnError?: boolean;
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
}): void;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { relative, resolve } from 'node:path';
|
|
2
|
+
import { CodeDebug, Region } from 'linecraft';
|
|
3
|
+
/**
|
|
4
|
+
* Formats and outputs diagnostics (errors and warnings) to the console.
|
|
5
|
+
* Uses linecraft's CodeDebug component for formatted code frames.
|
|
6
|
+
*
|
|
7
|
+
* @param errors - Array of error diagnostics
|
|
8
|
+
* @param warnings - Array of warning diagnostics
|
|
9
|
+
* @param options - Output options
|
|
10
|
+
*/
|
|
11
|
+
export function outputDiagnostics(errors, warnings, options = {}) {
|
|
12
|
+
const { suppressWarnings = false, breakOnError = true, verbose = false } = options;
|
|
13
|
+
// Merge warnings intelligently:
|
|
14
|
+
// 1. Group by code + filePath + line (for similar warnings like extend targets)
|
|
15
|
+
// 2. For warnings with parameterized messages (like "Extend target X"), merge them
|
|
16
|
+
const warningGroups = new Map();
|
|
17
|
+
for (const warning of warnings) {
|
|
18
|
+
// For extend warnings and similar parameterized messages, group by code + filePath + line
|
|
19
|
+
// This merges "Extend target .a not accessible" and "Extend target .b not accessible" into one group
|
|
20
|
+
const isParameterized = warning.code === 'extend/not-found' || warning.code === 'extend/not-accessible';
|
|
21
|
+
const groupKey = isParameterized
|
|
22
|
+
? `${warning.code}:${warning.filePath ?? ''}:${warning.line}`
|
|
23
|
+
: `${warning.code}:${warning.message}:${warning.filePath ?? ''}:${warning.line}`;
|
|
24
|
+
const existing = warningGroups.get(groupKey);
|
|
25
|
+
if (existing) {
|
|
26
|
+
existing.warnings.push(warning);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
warningGroups.set(groupKey, { warnings: [warning], representative: warning });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Output warnings to stdout (unless suppressed)
|
|
33
|
+
if (!suppressWarnings && warningGroups.size > 0) {
|
|
34
|
+
for (const { warnings: groupWarnings, representative } of warningGroups.values()) {
|
|
35
|
+
if (groupWarnings.length === 1) {
|
|
36
|
+
// Single warning - output as-is
|
|
37
|
+
outputDiagnostic(representative, 'warning', process.stdout, verbose, 1);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Multiple similar warnings - merge them
|
|
41
|
+
// Don't show repeat count since we're already summarizing multiple different warnings
|
|
42
|
+
const merged = mergeSimilarWarnings(groupWarnings, representative);
|
|
43
|
+
outputDiagnostic(merged, 'warning', process.stdout, verbose, 1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Output errors to stderr
|
|
48
|
+
// By default, only output the first error (unless breakOnError is false)
|
|
49
|
+
const errorsToOutput = breakOnError ? errors.slice(0, 1) : errors;
|
|
50
|
+
for (const error of errorsToOutput) {
|
|
51
|
+
outputDiagnostic(error, 'error', process.stderr, verbose);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Merges multiple similar warnings into a single diagnostic with a combined message.
|
|
56
|
+
* For parameterized warnings like "Extend target X not accessible", combines all targets.
|
|
57
|
+
*/
|
|
58
|
+
function mergeSimilarWarnings(warnings, representative) {
|
|
59
|
+
// Extract parameterized values from messages (e.g., ".a", ".b" from "Extend target .a not accessible")
|
|
60
|
+
const targets = [];
|
|
61
|
+
for (const warning of warnings) {
|
|
62
|
+
// Extract the target from messages like "Extend target ".a" not accessible"
|
|
63
|
+
const match = warning.message.match(/Extend target "([^"]+)" (not found|not accessible)/);
|
|
64
|
+
if (match) {
|
|
65
|
+
targets.push(match[1]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Create merged message
|
|
69
|
+
let mergedMessage;
|
|
70
|
+
if (targets.length > 0) {
|
|
71
|
+
if (targets.length <= 5) {
|
|
72
|
+
// Show all targets if 5 or fewer
|
|
73
|
+
mergedMessage = `Extend target${targets.length > 1 ? 's' : ''} ${targets.map(t => `"${t}"`).join(', ')} ${representative.message.includes('not accessible') ? 'not accessible' : 'not found'}`;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Show first 3 and count if more
|
|
77
|
+
const shown = targets.slice(0, 3).map(t => `"${t}"`).join(', ');
|
|
78
|
+
const remaining = targets.length - 3;
|
|
79
|
+
mergedMessage = `Extend targets ${shown} and ${remaining} more ${representative.message.includes('not accessible') ? 'not accessible' : 'not found'}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Fallback: use representative message with count
|
|
84
|
+
mergedMessage = representative.message;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
...representative,
|
|
88
|
+
message: mergedMessage
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Outputs a single diagnostic using linecraft's CodeDebug component.
|
|
93
|
+
* The output will persist in the terminal after the region is destroyed.
|
|
94
|
+
*/
|
|
95
|
+
function outputDiagnostic(diagnostic, type, stream = process.stdout, verbose = false, repeatCount = 1) {
|
|
96
|
+
const { code, phase, message, reason, fix, filePath, line, column, lines, note } = diagnostic;
|
|
97
|
+
const endLine = 'endLine' in diagnostic ? diagnostic.endLine : undefined;
|
|
98
|
+
const endColumn = 'endColumn' in diagnostic ? diagnostic.endColumn : undefined;
|
|
99
|
+
// Get file paths
|
|
100
|
+
const fullPath = filePath ? resolve(filePath) : '';
|
|
101
|
+
const shortPath = filePath ? relative(process.cwd(), filePath) : '(unknown)';
|
|
102
|
+
// Extract lines for code frame
|
|
103
|
+
const lineNumbers = lines ? Object.keys(lines).map(Number).sort((a, b) => a - b) : [];
|
|
104
|
+
const errorLineNum = line;
|
|
105
|
+
const errorLineContent = lines?.[errorLineNum] ?? '';
|
|
106
|
+
const lineBefore = lineNumbers.length > 0 && lineNumbers[0] < errorLineNum
|
|
107
|
+
? lines?.[errorLineNum - 1] ?? null
|
|
108
|
+
: null;
|
|
109
|
+
const lineAfter = lineNumbers.length > 0 && lineNumbers[lineNumbers.length - 1] > errorLineNum
|
|
110
|
+
? lines?.[errorLineNum + 1] ?? null
|
|
111
|
+
: null;
|
|
112
|
+
// Build message - send raw strings to CodeDebug
|
|
113
|
+
const messageLines = [
|
|
114
|
+
`${code} [${phase}]`,
|
|
115
|
+
message
|
|
116
|
+
];
|
|
117
|
+
// Add repeat count if > 1 (only for exact duplicates, not merged similar warnings)
|
|
118
|
+
// The repeatCount is only meaningful when it represents the same exact warning repeated
|
|
119
|
+
if (repeatCount > 1 && !message.includes(' and ') && !message.includes('more')) {
|
|
120
|
+
messageLines.push(`(repeated ${repeatCount} time${repeatCount > 1 ? 's' : ''})`);
|
|
121
|
+
}
|
|
122
|
+
// Only include reason and fix if verbose mode is enabled
|
|
123
|
+
if (verbose) {
|
|
124
|
+
messageLines.push('');
|
|
125
|
+
messageLines.push(`Reason: ${reason}`);
|
|
126
|
+
messageLines.push(`Fix: ${fix}`);
|
|
127
|
+
}
|
|
128
|
+
if (note) {
|
|
129
|
+
messageLines.push(note.startsWith('Note:') ? note : `Note: ${note}`);
|
|
130
|
+
}
|
|
131
|
+
const fullMessage = messageLines.join('\n');
|
|
132
|
+
// Create CodeDebug component and output it to the specified stream
|
|
133
|
+
// Region will use getTerminalWidth() which should handle redirected streams
|
|
134
|
+
const region = Region({ stdout: stream });
|
|
135
|
+
region.set(CodeDebug({
|
|
136
|
+
startLine: errorLineNum,
|
|
137
|
+
startColumn: column,
|
|
138
|
+
endLine: endLine,
|
|
139
|
+
endColumn: endColumn,
|
|
140
|
+
errorLine: errorLineContent,
|
|
141
|
+
lineBefore: lineBefore,
|
|
142
|
+
lineAfter: lineAfter,
|
|
143
|
+
message: fullMessage,
|
|
144
|
+
filePath: shortPath,
|
|
145
|
+
fullPath: fullPath,
|
|
146
|
+
type: type
|
|
147
|
+
}));
|
|
148
|
+
// Flush to ensure rendering, then destroy without clearing to persist output
|
|
149
|
+
// This will write the content to the terminal permanently
|
|
150
|
+
void region.flush();
|
|
151
|
+
void region.destroy(false); // false = don't clear, persist the output
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAyB,EACzB,QAA6B,EAC7B,UAII,EAAE;IAEN,MAAM,EAAE,gBAAgB,GAAG,KAAK,EAAE,YAAY,GAAG,IAAI,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAEnF,gCAAgC;IAChC,gFAAgF;IAChF,mFAAmF;IACnF,MAAM,aAAa,GAAG,IAAI,GAAG,EAAgF,CAAC;IAE9G,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,0FAA0F;QAC1F,qGAAqG;QACrG,MAAM,eAAe,GAAG,OAAO,CAAC,IAAI,KAAK,kBAAkB,IAAI,OAAO,CAAC,IAAI,KAAK,uBAAuB,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|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Context, type ErrorDiagnostic, type WarningDiagnostic, type Deprecation } from '@jesscss/core';
|
|
2
|
+
import { type StylesConfig } from 'styles-config';
|
|
3
|
+
export type ConfigOptions = StylesConfig & {
|
|
4
|
+
/** Output file path for matching against output config options */
|
|
5
|
+
outputFile?: string;
|
|
6
|
+
/** Suppress warnings (similar to Less's suppressWarnings option) */
|
|
7
|
+
suppressWarnings?: boolean;
|
|
8
|
+
/** Break on first error (stop processing after first error). Default: true */
|
|
9
|
+
breakOnError?: boolean;
|
|
10
|
+
/** Show detailed reason and fix in diagnostics. Default: false */
|
|
11
|
+
verbose?: boolean;
|
|
12
|
+
/** Deprecation warnings of these types will cause an error to be thrown */
|
|
13
|
+
fatalDeprecations?: Iterable<Deprecation>;
|
|
14
|
+
/** Whether to limit repetition of deprecation warnings (max 5). Default: true */
|
|
15
|
+
limitDeprecationRepetition?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare class Compiler {
|
|
18
|
+
opts: ConfigOptions;
|
|
19
|
+
constructor(opts?: ConfigOptions);
|
|
20
|
+
/**
|
|
21
|
+
* Create a context with the configured plugins
|
|
22
|
+
*/
|
|
23
|
+
createContext(filePath?: string, renderOptions?: Partial<ConfigOptions>): Context;
|
|
24
|
+
compile(filePath: string, options?: Partial<ConfigOptions>): Promise<{
|
|
25
|
+
tree: any;
|
|
26
|
+
context: Context;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Render CSS from a file path
|
|
30
|
+
*/
|
|
31
|
+
render(filePath: string, options?: Partial<ConfigOptions>): Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Render CSS from a string content
|
|
34
|
+
*/
|
|
35
|
+
renderString(content: string, options?: {
|
|
36
|
+
filePath?: string;
|
|
37
|
+
language?: string;
|
|
38
|
+
extension?: string;
|
|
39
|
+
config?: Partial<ConfigOptions>;
|
|
40
|
+
}): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Renders to CSS and returns a structured result object containing CSS and metadata.
|
|
43
|
+
* Can accept either a file path or string content.
|
|
44
|
+
* Similar to dart-sass's compileToResult() pattern, but uses "render" naming to match less.js.
|
|
45
|
+
*
|
|
46
|
+
* @param input - File path (string) or source content (object with source string)
|
|
47
|
+
* @param options - Render options
|
|
48
|
+
* @returns RenderResult with css, errors, warnings, and loadedUrls
|
|
49
|
+
*/
|
|
50
|
+
renderToResult(input: string | {
|
|
51
|
+
source: string;
|
|
52
|
+
filePath?: string;
|
|
53
|
+
language?: string;
|
|
54
|
+
extension?: string;
|
|
55
|
+
}, options?: Partial<ConfigOptions> & {
|
|
56
|
+
filePath?: string;
|
|
57
|
+
language?: string;
|
|
58
|
+
extension?: string;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
css: string;
|
|
61
|
+
errors: ErrorDiagnostic[];
|
|
62
|
+
warnings: WarningDiagnostic[];
|
|
63
|
+
loadedUrls: string[];
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Safe version of compile that collects errors and warnings instead of throwing.
|
|
67
|
+
* Returns the tree (or null if compilation failed) along with collected errors and warnings.
|
|
68
|
+
*/
|
|
69
|
+
safeCompile(filePath: string, options?: Partial<ConfigOptions>): Promise<{
|
|
70
|
+
tree: any | null;
|
|
71
|
+
context: Context;
|
|
72
|
+
errors: ErrorDiagnostic[];
|
|
73
|
+
warnings: WarningDiagnostic[];
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* Safe version of render that collects errors and warnings instead of throwing.
|
|
77
|
+
* Returns the CSS (or null if rendering failed) along with collected errors and warnings.
|
|
78
|
+
*/
|
|
79
|
+
safeRender(filePath: string, options?: Partial<ConfigOptions>): Promise<{
|
|
80
|
+
css: string | null;
|
|
81
|
+
errors: ErrorDiagnostic[];
|
|
82
|
+
warnings: WarningDiagnostic[];
|
|
83
|
+
}>;
|
|
84
|
+
}
|