@chikx/compiler 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/emitter/index.d.ts +96 -0
- package/dist/emitter/index.d.ts.map +1 -0
- package/dist/emitter/index.js +415 -0
- package/dist/emitter/index.js.map +1 -0
- package/dist/formatter/index.d.ts +53 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +464 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/host/node.d.ts +34 -0
- package/dist/host/node.d.ts.map +1 -0
- package/dist/host/node.js +80 -0
- package/dist/host/node.js.map +1 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +792 -0
- package/dist/index.js.map +1 -0
- package/dist/ir/factories.d.ts +35 -0
- package/dist/ir/factories.d.ts.map +1 -0
- package/dist/ir/factories.js +47 -0
- package/dist/ir/factories.js.map +1 -0
- package/dist/ir/index.d.ts +13 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +2 -0
- package/dist/ir/index.js.map +1 -0
- package/dist/ir/types.d.ts +139 -0
- package/dist/ir/types.d.ts.map +1 -0
- package/dist/ir/types.js +2 -0
- package/dist/ir/types.js.map +1 -0
- package/dist/lexer/at-keywords.d.ts +27 -0
- package/dist/lexer/at-keywords.d.ts.map +1 -0
- package/dist/lexer/at-keywords.js +35 -0
- package/dist/lexer/at-keywords.js.map +1 -0
- package/dist/lexer/characters.d.ts +38 -0
- package/dist/lexer/characters.d.ts.map +1 -0
- package/dist/lexer/characters.js +74 -0
- package/dist/lexer/characters.js.map +1 -0
- package/dist/lexer/comments.d.ts +22 -0
- package/dist/lexer/comments.d.ts.map +1 -0
- package/dist/lexer/comments.js +20 -0
- package/dist/lexer/comments.js.map +1 -0
- package/dist/lexer/diagnostics.d.ts +24 -0
- package/dist/lexer/diagnostics.d.ts.map +1 -0
- package/dist/lexer/diagnostics.js +29 -0
- package/dist/lexer/diagnostics.js.map +1 -0
- package/dist/lexer/dollar-refs.d.ts +13 -0
- package/dist/lexer/dollar-refs.d.ts.map +1 -0
- package/dist/lexer/dollar-refs.js +22 -0
- package/dist/lexer/dollar-refs.js.map +1 -0
- package/dist/lexer/index.d.ts +32 -0
- package/dist/lexer/index.d.ts.map +1 -0
- package/dist/lexer/index.js +26 -0
- package/dist/lexer/index.js.map +1 -0
- package/dist/lexer/names.d.ts +23 -0
- package/dist/lexer/names.d.ts.map +1 -0
- package/dist/lexer/names.js +48 -0
- package/dist/lexer/names.js.map +1 -0
- package/dist/lexer/numbers.d.ts +22 -0
- package/dist/lexer/numbers.d.ts.map +1 -0
- package/dist/lexer/numbers.js +60 -0
- package/dist/lexer/numbers.js.map +1 -0
- package/dist/lexer/scanner.d.ts +30 -0
- package/dist/lexer/scanner.d.ts.map +1 -0
- package/dist/lexer/scanner.js +158 -0
- package/dist/lexer/scanner.js.map +1 -0
- package/dist/lexer/strings.d.ts +25 -0
- package/dist/lexer/strings.d.ts.map +1 -0
- package/dist/lexer/strings.js +41 -0
- package/dist/lexer/strings.js.map +1 -0
- package/dist/lexer/urls.d.ts +28 -0
- package/dist/lexer/urls.d.ts.map +1 -0
- package/dist/lexer/urls.js +54 -0
- package/dist/lexer/urls.js.map +1 -0
- package/dist/lowering/expand-groups.d.ts +61 -0
- package/dist/lowering/expand-groups.d.ts.map +1 -0
- package/dist/lowering/expand-groups.js +117 -0
- package/dist/lowering/expand-groups.js.map +1 -0
- package/dist/lowering/group.d.ts +30 -0
- package/dist/lowering/group.d.ts.map +1 -0
- package/dist/lowering/group.js +109 -0
- package/dist/lowering/group.js.map +1 -0
- package/dist/lowering/index.d.ts +26 -0
- package/dist/lowering/index.d.ts.map +1 -0
- package/dist/lowering/index.js +23 -0
- package/dist/lowering/index.js.map +1 -0
- package/dist/lowering/lower.d.ts +21 -0
- package/dist/lowering/lower.d.ts.map +1 -0
- package/dist/lowering/lower.js +296 -0
- package/dist/lowering/lower.js.map +1 -0
- package/dist/lowering/media.d.ts +63 -0
- package/dist/lowering/media.d.ts.map +1 -0
- package/dist/lowering/media.js +237 -0
- package/dist/lowering/media.js.map +1 -0
- package/dist/lowering/merge.d.ts +35 -0
- package/dist/lowering/merge.d.ts.map +1 -0
- package/dist/lowering/merge.js +146 -0
- package/dist/lowering/merge.js.map +1 -0
- package/dist/lowering/property-families.d.ts +50 -0
- package/dist/lowering/property-families.d.ts.map +1 -0
- package/dist/lowering/property-families.js +175 -0
- package/dist/lowering/property-families.js.map +1 -0
- package/dist/lowering/spans.d.ts +36 -0
- package/dist/lowering/spans.d.ts.map +1 -0
- package/dist/lowering/spans.js +100 -0
- package/dist/lowering/spans.js.map +1 -0
- package/dist/naming/index.d.ts +37 -0
- package/dist/naming/index.d.ts.map +1 -0
- package/dist/naming/index.js +34 -0
- package/dist/naming/index.js.map +1 -0
- package/dist/naming/mapgen.d.ts +70 -0
- package/dist/naming/mapgen.d.ts.map +1 -0
- package/dist/naming/mapgen.js +153 -0
- package/dist/naming/mapgen.js.map +1 -0
- package/dist/naming/merge.d.ts +62 -0
- package/dist/naming/merge.d.ts.map +1 -0
- package/dist/naming/merge.js +77 -0
- package/dist/naming/merge.js.map +1 -0
- package/dist/naming/rewrite.d.ts +14 -0
- package/dist/naming/rewrite.d.ts.map +1 -0
- package/dist/naming/rewrite.js +191 -0
- package/dist/naming/rewrite.js.map +1 -0
- package/dist/naming/scan.d.ts +80 -0
- package/dist/naming/scan.d.ts.map +1 -0
- package/dist/naming/scan.js +193 -0
- package/dist/naming/scan.js.map +1 -0
- package/dist/naming/table.d.ts +68 -0
- package/dist/naming/table.d.ts.map +1 -0
- package/dist/naming/table.js +132 -0
- package/dist/naming/table.js.map +1 -0
- package/dist/naming/types.d.ts +94 -0
- package/dist/naming/types.d.ts.map +1 -0
- package/dist/naming/types.js +2 -0
- package/dist/naming/types.js.map +1 -0
- package/dist/output/import-path.d.ts +24 -0
- package/dist/output/import-path.d.ts.map +1 -0
- package/dist/output/import-path.js +30 -0
- package/dist/output/import-path.js.map +1 -0
- package/dist/output/index.d.ts +40 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +138 -0
- package/dist/output/index.js.map +1 -0
- package/dist/output/manifest.d.ts +17 -0
- package/dist/output/manifest.d.ts.map +1 -0
- package/dist/output/manifest.js +22 -0
- package/dist/output/manifest.js.map +1 -0
- package/dist/output/paths.d.ts +54 -0
- package/dist/output/paths.d.ts.map +1 -0
- package/dist/output/paths.js +183 -0
- package/dist/output/paths.js.map +1 -0
- package/dist/output/resolve.d.ts +100 -0
- package/dist/output/resolve.d.ts.map +1 -0
- package/dist/output/resolve.js +313 -0
- package/dist/output/resolve.js.map +1 -0
- package/dist/output/validate.d.ts +82 -0
- package/dist/output/validate.d.ts.map +1 -0
- package/dist/output/validate.js +128 -0
- package/dist/output/validate.js.map +1 -0
- package/dist/parser/cursor.d.ts +55 -0
- package/dist/parser/cursor.d.ts.map +1 -0
- package/dist/parser/cursor.js +120 -0
- package/dist/parser/cursor.js.map +1 -0
- package/dist/parser/declaration.d.ts +21 -0
- package/dist/parser/declaration.d.ts.map +1 -0
- package/dist/parser/declaration.js +201 -0
- package/dist/parser/declaration.js.map +1 -0
- package/dist/parser/diagnostics.d.ts +52 -0
- package/dist/parser/diagnostics.d.ts.map +1 -0
- package/dist/parser/diagnostics.js +55 -0
- package/dist/parser/diagnostics.js.map +1 -0
- package/dist/parser/group.d.ts +26 -0
- package/dist/parser/group.d.ts.map +1 -0
- package/dist/parser/group.js +219 -0
- package/dist/parser/group.js.map +1 -0
- package/dist/parser/index.d.ts +30 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +48 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/modifier.d.ts +25 -0
- package/dist/parser/modifier.d.ts.map +1 -0
- package/dist/parser/modifier.js +41 -0
- package/dist/parser/modifier.js.map +1 -0
- package/dist/parser/recovery.d.ts +23 -0
- package/dist/parser/recovery.d.ts.map +1 -0
- package/dist/parser/recovery.js +80 -0
- package/dist/parser/recovery.js.map +1 -0
- package/dist/parser/rule.d.ts +39 -0
- package/dist/parser/rule.d.ts.map +1 -0
- package/dist/parser/rule.js +337 -0
- package/dist/parser/rule.js.map +1 -0
- package/dist/parser/statement.d.ts +21 -0
- package/dist/parser/statement.d.ts.map +1 -0
- package/dist/parser/statement.js +48 -0
- package/dist/parser/statement.js.map +1 -0
- package/dist/parser/statements.d.ts +33 -0
- package/dist/parser/statements.d.ts.map +1 -0
- package/dist/parser/statements.js +605 -0
- package/dist/parser/statements.js.map +1 -0
- package/dist/parser/value.d.ts +57 -0
- package/dist/parser/value.d.ts.map +1 -0
- package/dist/parser/value.js +226 -0
- package/dist/parser/value.js.map +1 -0
- package/dist/resolver/graph.d.ts +20 -0
- package/dist/resolver/graph.d.ts.map +1 -0
- package/dist/resolver/graph.js +382 -0
- package/dist/resolver/graph.js.map +1 -0
- package/dist/resolver/groups.d.ts +70 -0
- package/dist/resolver/groups.d.ts.map +1 -0
- package/dist/resolver/groups.js +143 -0
- package/dist/resolver/groups.js.map +1 -0
- package/dist/resolver/index.d.ts +46 -0
- package/dist/resolver/index.d.ts.map +1 -0
- package/dist/resolver/index.js +46 -0
- package/dist/resolver/index.js.map +1 -0
- package/dist/resolver/keyframes.d.ts +56 -0
- package/dist/resolver/keyframes.d.ts.map +1 -0
- package/dist/resolver/keyframes.js +102 -0
- package/dist/resolver/keyframes.js.map +1 -0
- package/dist/resolver/paths.d.ts +37 -0
- package/dist/resolver/paths.d.ts.map +1 -0
- package/dist/resolver/paths.js +135 -0
- package/dist/resolver/paths.js.map +1 -0
- package/dist/resolver/rules.d.ts +34 -0
- package/dist/resolver/rules.d.ts.map +1 -0
- package/dist/resolver/rules.js +52 -0
- package/dist/resolver/rules.js.map +1 -0
- package/dist/resolver/scopes.d.ts +44 -0
- package/dist/resolver/scopes.d.ts.map +1 -0
- package/dist/resolver/scopes.js +213 -0
- package/dist/resolver/scopes.js.map +1 -0
- package/dist/resolver/types.d.ts +238 -0
- package/dist/resolver/types.d.ts.map +1 -0
- package/dist/resolver/types.js +11 -0
- package/dist/resolver/types.js.map +1 -0
- package/dist/selectors/flatten.d.ts +95 -0
- package/dist/selectors/flatten.d.ts.map +1 -0
- package/dist/selectors/flatten.js +384 -0
- package/dist/selectors/flatten.js.map +1 -0
- package/dist/selectors/index.d.ts +15 -0
- package/dist/selectors/index.d.ts.map +1 -0
- package/dist/selectors/index.js +14 -0
- package/dist/selectors/index.js.map +1 -0
- package/dist/selectors/scan.d.ts +54 -0
- package/dist/selectors/scan.d.ts.map +1 -0
- package/dist/selectors/scan.js +191 -0
- package/dist/selectors/scan.js.map +1 -0
- package/dist/selectors/specificity.d.ts +28 -0
- package/dist/selectors/specificity.d.ts.map +1 -0
- package/dist/selectors/specificity.js +297 -0
- package/dist/selectors/specificity.js.map +1 -0
- package/dist/setup-list.d.ts +41 -0
- package/dist/setup-list.d.ts.map +1 -0
- package/dist/setup-list.js +122 -0
- package/dist/setup-list.js.map +1 -0
- package/dist/sourcemaps/index.d.ts +14 -0
- package/dist/sourcemaps/index.d.ts.map +1 -0
- package/dist/sourcemaps/index.js +13 -0
- package/dist/sourcemaps/index.js.map +1 -0
- package/dist/sourcemaps/mappings.d.ts +77 -0
- package/dist/sourcemaps/mappings.d.ts.map +1 -0
- package/dist/sourcemaps/mappings.js +124 -0
- package/dist/sourcemaps/mappings.js.map +1 -0
- package/dist/sourcemaps/vlq.d.ts +12 -0
- package/dist/sourcemaps/vlq.d.ts.map +1 -0
- package/dist/sourcemaps/vlq.js +29 -0
- package/dist/sourcemaps/vlq.js.map +1 -0
- package/dist/types/ast.d.ts +291 -0
- package/dist/types/ast.d.ts.map +1 -0
- package/dist/types/ast.js +2 -0
- package/dist/types/ast.js.map +1 -0
- package/dist/types/diagnostics.d.ts +55 -0
- package/dist/types/diagnostics.d.ts.map +1 -0
- package/dist/types/diagnostics.js +61 -0
- package/dist/types/diagnostics.js.map +1 -0
- package/dist/types/options.d.ts +274 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/options.js +11 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/result.d.ts +112 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +2 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/span.d.ts +19 -0
- package/dist/types/span.d.ts.map +1 -0
- package/dist/types/span.js +2 -0
- package/dist/types/span.js.map +1 -0
- package/dist/types/token.d.ts +68 -0
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/token.js +2 -0
- package/dist/types/token.js.map +1 -0
- package/dist/variables/ast.d.ts +56 -0
- package/dist/variables/ast.d.ts.map +1 -0
- package/dist/variables/ast.js +167 -0
- package/dist/variables/ast.js.map +1 -0
- package/dist/variables/expand.d.ts +109 -0
- package/dist/variables/expand.d.ts.map +1 -0
- package/dist/variables/expand.js +213 -0
- package/dist/variables/expand.js.map +1 -0
- package/dist/variables/index.d.ts +36 -0
- package/dist/variables/index.d.ts.map +1 -0
- package/dist/variables/index.js +33 -0
- package/dist/variables/index.js.map +1 -0
- package/dist/variables/naming.d.ts +39 -0
- package/dist/variables/naming.d.ts.map +1 -0
- package/dist/variables/naming.js +14 -0
- package/dist/variables/naming.js.map +1 -0
- package/dist/variables/runtime.d.ts +81 -0
- package/dist/variables/runtime.d.ts.map +1 -0
- package/dist/variables/runtime.js +228 -0
- package/dist/variables/runtime.js.map +1 -0
- package/dist/variables/substitute.d.ts +65 -0
- package/dist/variables/substitute.d.ts.map +1 -0
- package/dist/variables/substitute.js +73 -0
- package/dist/variables/substitute.js.map +1 -0
- package/dist/variables/walk.d.ts +37 -0
- package/dist/variables/walk.d.ts.map +1 -0
- package/dist/variables/walk.js +113 -0
- package/dist/variables/walk.js.map +1 -0
- package/package.json +35 -4
- package/src/emitter/index.ts +658 -0
- package/src/formatter/index.ts +544 -0
- package/src/host/node.ts +85 -0
- package/src/index.ts +1021 -0
- package/src/ir/factories.ts +85 -0
- package/src/ir/index.ts +28 -0
- package/src/ir/types.ts +145 -0
- package/src/lexer/at-keywords.ts +35 -0
- package/src/lexer/characters.ts +82 -0
- package/src/lexer/comments.ts +27 -0
- package/src/lexer/diagnostics.ts +42 -0
- package/src/lexer/dollar-refs.ts +23 -0
- package/src/lexer/index.ts +37 -0
- package/src/lexer/names.ts +49 -0
- package/src/lexer/numbers.ts +59 -0
- package/src/lexer/scanner.ts +199 -0
- package/src/lexer/strings.ts +52 -0
- package/src/lexer/urls.ts +63 -0
- package/src/lowering/expand-groups.ts +206 -0
- package/src/lowering/group.ts +119 -0
- package/src/lowering/index.ts +43 -0
- package/src/lowering/lower.ts +441 -0
- package/src/lowering/media.ts +314 -0
- package/src/lowering/merge.ts +163 -0
- package/src/lowering/property-families.ts +194 -0
- package/src/lowering/spans.ts +118 -0
- package/src/naming/index.ts +44 -0
- package/src/naming/mapgen.ts +252 -0
- package/src/naming/merge.ts +114 -0
- package/src/naming/rewrite.ts +333 -0
- package/src/naming/scan.ts +267 -0
- package/src/naming/table.ts +153 -0
- package/src/naming/types.ts +100 -0
- package/src/output/import-path.ts +30 -0
- package/src/output/index.ts +213 -0
- package/src/output/manifest.ts +28 -0
- package/src/output/paths.ts +200 -0
- package/src/output/resolve.ts +401 -0
- package/src/output/validate.ts +251 -0
- package/src/parser/cursor.ts +138 -0
- package/src/parser/declaration.ts +247 -0
- package/src/parser/diagnostics.ts +75 -0
- package/src/parser/group.ts +303 -0
- package/src/parser/index.ts +50 -0
- package/src/parser/modifier.ts +60 -0
- package/src/parser/recovery.ts +88 -0
- package/src/parser/rule.ts +370 -0
- package/src/parser/statement.ts +47 -0
- package/src/parser/statements.ts +667 -0
- package/src/parser/value.ts +265 -0
- package/src/resolver/graph.ts +467 -0
- package/src/resolver/groups.ts +177 -0
- package/src/resolver/index.ts +68 -0
- package/src/resolver/keyframes.ts +131 -0
- package/src/resolver/paths.ts +142 -0
- package/src/resolver/rules.ts +54 -0
- package/src/resolver/scopes.ts +342 -0
- package/src/resolver/types.ts +259 -0
- package/src/selectors/flatten.ts +448 -0
- package/src/selectors/index.ts +14 -0
- package/src/selectors/scan.ts +227 -0
- package/src/selectors/specificity.ts +319 -0
- package/src/setup-list.ts +172 -0
- package/src/sourcemaps/index.ts +25 -0
- package/src/sourcemaps/mappings.ts +190 -0
- package/src/sourcemaps/vlq.ts +29 -0
- package/src/types/ast.ts +318 -0
- package/src/types/diagnostics.ts +124 -0
- package/src/types/options.ts +286 -0
- package/src/types/result.ts +121 -0
- package/src/types/span.ts +18 -0
- package/src/types/token.ts +77 -0
- package/src/variables/ast.ts +182 -0
- package/src/variables/expand.ts +319 -0
- package/src/variables/index.ts +38 -0
- package/src/variables/naming.ts +46 -0
- package/src/variables/runtime.ts +336 -0
- package/src/variables/substitute.ts +148 -0
- package/src/variables/walk.ts +147 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure POSIX path utilities for output planning.
|
|
3
|
+
*
|
|
4
|
+
* The output planner never touches the filesystem and never imports `node:path`.
|
|
5
|
+
* All paths are normalized to forward slashes, `.`/`..` segments are collapsed
|
|
6
|
+
* lexically, and Windows drive prefixes such as `C:\project` are preserved as
|
|
7
|
+
* `C:/project`. Hosts still own symlink and case policy; these helpers only
|
|
8
|
+
* provide deterministic, platform-independent string handling.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Convert every backslash to a forward slash. */
|
|
12
|
+
export function toPosix(path: string): string {
|
|
13
|
+
return path.replace(/\\/g, "/");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether a path is absolute in the planner's POSIX-plus-drive model.
|
|
18
|
+
*
|
|
19
|
+
* A leading slash, a UNC-style double slash and a drive prefix (`C:/`, `C:`)
|
|
20
|
+
* are absolute. Bare relative paths are not.
|
|
21
|
+
*/
|
|
22
|
+
export function isAbsolutePath(path: string): boolean {
|
|
23
|
+
const slashed = toPosix(path);
|
|
24
|
+
return slashed.startsWith("/") || /^[A-Za-z]:(\/|$)/.test(slashed);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface SplitRoot {
|
|
28
|
+
/** Root prefix including its trailing slash, or an empty string. */
|
|
29
|
+
readonly root: string;
|
|
30
|
+
/** Path text after the root, without a leading slash. */
|
|
31
|
+
readonly rest: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function splitRoot(path: string): SplitRoot {
|
|
35
|
+
const match = /^([A-Za-z]):(?=\/|$)/.exec(path);
|
|
36
|
+
if (match?.[1] !== undefined) {
|
|
37
|
+
let rest = path.slice(2);
|
|
38
|
+
if (rest.startsWith("/")) rest = rest.slice(1);
|
|
39
|
+
return { root: `${match[1]}:/`, rest };
|
|
40
|
+
}
|
|
41
|
+
if (path.startsWith("//")) return { root: "//", rest: path.slice(2) };
|
|
42
|
+
if (path.startsWith("/")) return { root: "/", rest: path.slice(1) };
|
|
43
|
+
return { root: "", rest: path };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Normalize a path to forward slashes and collapse `.`/`..` segments lexically.
|
|
48
|
+
*
|
|
49
|
+
* Absolute paths keep their root (`/`, `//` or a drive such as `C:/`) and never
|
|
50
|
+
* climb above it. Relative paths keep leading `..` segments. An empty result
|
|
51
|
+
* becomes `.`.
|
|
52
|
+
*/
|
|
53
|
+
export function normalizePath(path: string): string {
|
|
54
|
+
const slashed = toPosix(path);
|
|
55
|
+
const { root, rest } = splitRoot(slashed);
|
|
56
|
+
const segments: string[] = [];
|
|
57
|
+
|
|
58
|
+
for (const segment of rest.split("/")) {
|
|
59
|
+
if (segment === "" || segment === ".") continue;
|
|
60
|
+
if (segment === "..") {
|
|
61
|
+
const last = segments[segments.length - 1];
|
|
62
|
+
if (last !== undefined && last !== "..") segments.pop();
|
|
63
|
+
else if (root === "") segments.push("..");
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
segments.push(segment);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const body = segments.join("/");
|
|
70
|
+
if (root === "") return body === "" ? "." : body;
|
|
71
|
+
if (root === "/") return body === "" ? "/" : `/${body}`;
|
|
72
|
+
if (root === "//") return body === "" ? "//" : `//${body}`;
|
|
73
|
+
return body === "" ? root : `${root}${body}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Join path parts with `/`, resetting to an absolute part when one appears. */
|
|
77
|
+
export function joinPath(base: string, ...parts: readonly string[]): string {
|
|
78
|
+
let result = normalizePath(base);
|
|
79
|
+
for (const part of parts) {
|
|
80
|
+
if (part === undefined || part === "") continue;
|
|
81
|
+
if (isAbsolutePath(part)) {
|
|
82
|
+
result = normalizePath(part);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
result = normalizePath(result === "." ? part : `${result}/${part}`);
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Return the parent directory of a normalized path. */
|
|
91
|
+
export function dirnamePath(path: string): string {
|
|
92
|
+
const normalized = normalizePath(path);
|
|
93
|
+
if (normalized === "/" || normalized === "//" || /^[A-Za-z]:\/$/.test(normalized)) {
|
|
94
|
+
return normalized;
|
|
95
|
+
}
|
|
96
|
+
const index = normalized.lastIndexOf("/");
|
|
97
|
+
if (index < 0) return ".";
|
|
98
|
+
const parent = normalized.slice(0, index);
|
|
99
|
+
if (parent === "") return "/";
|
|
100
|
+
if (parent === "/") return "/";
|
|
101
|
+
if (/^[A-Za-z]:$/.test(parent)) return `${parent}/`;
|
|
102
|
+
return parent;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Return the final path segment, or an empty string for a root. */
|
|
106
|
+
export function basenamePath(path: string): string {
|
|
107
|
+
const normalized = normalizePath(path);
|
|
108
|
+
if (normalized === "/" || normalized === "//" || /^[A-Za-z]:\/$/.test(normalized)) {
|
|
109
|
+
return "";
|
|
110
|
+
}
|
|
111
|
+
const index = normalized.lastIndexOf("/");
|
|
112
|
+
return index < 0 ? normalized : normalized.slice(index + 1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function isDriveRoot(root: string): boolean {
|
|
116
|
+
return /^[A-Za-z]:\/$/.test(root);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function rootsMatch(left: string, right: string): boolean {
|
|
120
|
+
return left.toLowerCase() === right.toLowerCase();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function segmentsEqual(left: string, right: string, caseInsensitive: boolean): boolean {
|
|
124
|
+
return caseInsensitive ? left.toLowerCase() === right.toLowerCase() : left === right;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Compute a relative path from one path to another.
|
|
129
|
+
*
|
|
130
|
+
* Both paths must share the same absolute root; otherwise the normalized target
|
|
131
|
+
* is returned unchanged. Relative inputs are compared lexically. The result is
|
|
132
|
+
* `.` when the paths are identical.
|
|
133
|
+
*/
|
|
134
|
+
export function relativePath(from: string, to: string): string {
|
|
135
|
+
const source = normalizePath(from);
|
|
136
|
+
const target = normalizePath(to);
|
|
137
|
+
const sourceRoot = splitRoot(source);
|
|
138
|
+
const targetRoot = splitRoot(target);
|
|
139
|
+
|
|
140
|
+
if (!rootsMatch(sourceRoot.root, targetRoot.root)) {
|
|
141
|
+
return target;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const caseInsensitive = isDriveRoot(sourceRoot.root) && isDriveRoot(targetRoot.root);
|
|
145
|
+
const sourceSegments = sourceRoot.rest.split("/").filter((segment) => segment !== "");
|
|
146
|
+
const targetSegments = targetRoot.rest.split("/").filter((segment) => segment !== "");
|
|
147
|
+
|
|
148
|
+
let common = 0;
|
|
149
|
+
while (
|
|
150
|
+
common < sourceSegments.length &&
|
|
151
|
+
common < targetSegments.length &&
|
|
152
|
+
segmentsEqual(sourceSegments[common] ?? "", targetSegments[common] ?? "", caseInsensitive)
|
|
153
|
+
) {
|
|
154
|
+
common += 1;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (sourceRoot.root === "" && common === 0) return target;
|
|
158
|
+
|
|
159
|
+
const parts: string[] = [];
|
|
160
|
+
for (let index = common; index < sourceSegments.length; index += 1) parts.push("..");
|
|
161
|
+
for (let index = common; index < targetSegments.length; index += 1) {
|
|
162
|
+
parts.push(targetSegments[index] ?? "");
|
|
163
|
+
}
|
|
164
|
+
return parts.length === 0 ? "." : parts.join("/");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Whether `target` lies inside `root`, including the root itself.
|
|
169
|
+
*
|
|
170
|
+
* Comparison is lexical. Drive-letter roots and their segments are compared
|
|
171
|
+
* case-insensitively to match Windows expectations; POSIX paths stay
|
|
172
|
+
* case-sensitive. Symlink and full case policy belong to the injected host.
|
|
173
|
+
*/
|
|
174
|
+
export function isWithinPath(root: string, target: string): boolean {
|
|
175
|
+
const base = normalizePath(root);
|
|
176
|
+
const candidate = normalizePath(target);
|
|
177
|
+
const baseRoot = splitRoot(base);
|
|
178
|
+
const candidateRoot = splitRoot(candidate);
|
|
179
|
+
|
|
180
|
+
if (!rootsMatch(baseRoot.root, candidateRoot.root)) return false;
|
|
181
|
+
|
|
182
|
+
const caseInsensitive = isDriveRoot(baseRoot.root) && isDriveRoot(candidateRoot.root);
|
|
183
|
+
const baseSegments = baseRoot.rest.split("/").filter((segment) => segment !== "");
|
|
184
|
+
const candidateSegments = candidateRoot.rest.split("/").filter((segment) => segment !== "");
|
|
185
|
+
|
|
186
|
+
if (baseSegments.length > candidateSegments.length) return false;
|
|
187
|
+
return baseSegments.every((segment, index) =>
|
|
188
|
+
segmentsEqual(segment, candidateSegments[index] ?? "", caseInsensitive),
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Whether a path is a safe, non-empty relative path that does not climb out of
|
|
194
|
+
* its base (`..`, `../x` and absolute paths are not safe).
|
|
195
|
+
*/
|
|
196
|
+
export function isSafeRelativePath(path: string): boolean {
|
|
197
|
+
return (
|
|
198
|
+
path !== "" && path !== "." && path !== ".." && !isAbsolutePath(path) && !path.startsWith("../")
|
|
199
|
+
);
|
|
200
|
+
}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Destination resolution for the pure output planner.
|
|
3
|
+
*
|
|
4
|
+
* Precedence is built-in defaults, project configuration, file `@setup` and
|
|
5
|
+
* explicit CLI overrides (SPECIFICATION.md §9.1). File-level directories are
|
|
6
|
+
* exact and resolve against the source directory; project-level directories
|
|
7
|
+
* resolve against the workspace root and preserve the source-relative
|
|
8
|
+
* subdirectory; CLI directories resolve against the workspace root and are
|
|
9
|
+
* exact because path overrides are single-entry only.
|
|
10
|
+
*
|
|
11
|
+
* `ResolvedSetup` is required and therefore cannot record whether a value was
|
|
12
|
+
* authored or copied from a default. The planner treats a file-layer value that
|
|
13
|
+
* equals the built-in default as unset so project configuration can still take
|
|
14
|
+
* effect, and uses authored-value equality with `projectConfig.output` to infer
|
|
15
|
+
* project-level directory provenance. This limitation is documented in
|
|
16
|
+
* `.ai/reports/CSSX-A10.md`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { ResolvedSetup } from "../types/options.js";
|
|
20
|
+
import type { PlanOutputsInput } from "../types/result.js";
|
|
21
|
+
import {
|
|
22
|
+
basenamePath,
|
|
23
|
+
dirnamePath,
|
|
24
|
+
isAbsolutePath,
|
|
25
|
+
isSafeRelativePath,
|
|
26
|
+
isWithinPath,
|
|
27
|
+
joinPath,
|
|
28
|
+
normalizePath,
|
|
29
|
+
relativePath,
|
|
30
|
+
toPosix,
|
|
31
|
+
} from "./paths.js";
|
|
32
|
+
|
|
33
|
+
/** Built-in output defaults from SPECIFICATION.md §9. */
|
|
34
|
+
export const OUTPUT_DEFAULTS: Readonly<{
|
|
35
|
+
readonly emitCss: boolean;
|
|
36
|
+
readonly emitMap: boolean;
|
|
37
|
+
readonly emitTypes: boolean;
|
|
38
|
+
readonly sourceMap: boolean;
|
|
39
|
+
readonly minify: boolean;
|
|
40
|
+
readonly mapInherit: boolean;
|
|
41
|
+
readonly importCss: boolean;
|
|
42
|
+
}> = Object.freeze({
|
|
43
|
+
emitCss: true,
|
|
44
|
+
emitMap: true,
|
|
45
|
+
// `.d.ts` beside the JS map is opt-in (`map-types`, CSSX-A52).
|
|
46
|
+
emitTypes: false,
|
|
47
|
+
sourceMap: false,
|
|
48
|
+
// Compact CSS by default (ADR-0022); readers opt out with `minify: false`.
|
|
49
|
+
minify: true,
|
|
50
|
+
// Style-merged modules join the importing map unless they opt out (ADR-0020).
|
|
51
|
+
mapInherit: true,
|
|
52
|
+
// The map carries a CSS import only when a bundler consumer opts in (ADR-0021).
|
|
53
|
+
importCss: false,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** Where a directory or filename came from, used to apply the correct base. */
|
|
57
|
+
export type SettingOrigin = "default" | "project" | "file" | "cli";
|
|
58
|
+
|
|
59
|
+
interface DirectorySetting {
|
|
60
|
+
/** Authored directory, or an absolute source directory for the default. */
|
|
61
|
+
readonly value: string;
|
|
62
|
+
readonly origin: SettingOrigin;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface NameSetting {
|
|
66
|
+
readonly value: string;
|
|
67
|
+
readonly origin: SettingOrigin;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Effective names, directories and flags after precedence resolution. */
|
|
71
|
+
export interface ResolvedOutputSettings {
|
|
72
|
+
/** Absolute POSIX CSS output directory. */
|
|
73
|
+
readonly cssDir: string;
|
|
74
|
+
/**
|
|
75
|
+
* Absolute POSIX CSS destinations in authored order. A scalar input yields one
|
|
76
|
+
* entry identical to {@link cssDir}; a file `css-dir` list yields one per item
|
|
77
|
+
* (ADR-0019).
|
|
78
|
+
*/
|
|
79
|
+
readonly cssDirs: readonly string[];
|
|
80
|
+
/** Absolute POSIX JS map output directory. */
|
|
81
|
+
readonly mapDir: string;
|
|
82
|
+
/** Validated CSS basename. */
|
|
83
|
+
readonly cssName: string;
|
|
84
|
+
/** Validated JS map basename. */
|
|
85
|
+
readonly mapName: string;
|
|
86
|
+
/** Write the stylesheet. */
|
|
87
|
+
readonly emitCss: boolean;
|
|
88
|
+
/** Write the JS class map. */
|
|
89
|
+
readonly emitMap: boolean;
|
|
90
|
+
/** Write declarations beside the JS map. */
|
|
91
|
+
readonly emitTypes: boolean;
|
|
92
|
+
/** Write the CSS source map. */
|
|
93
|
+
readonly sourceMap: boolean;
|
|
94
|
+
/** Compact generated CSS whitespace. */
|
|
95
|
+
readonly minify: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Normalized source path used for all destination calculations. */
|
|
99
|
+
export interface ResolvedSource {
|
|
100
|
+
/** Workspace-relative POSIX source path. */
|
|
101
|
+
readonly relative: string;
|
|
102
|
+
/** Absolute POSIX source path. */
|
|
103
|
+
readonly absolute: string;
|
|
104
|
+
/** Absolute POSIX source directory. */
|
|
105
|
+
readonly directory: string;
|
|
106
|
+
/** Source basename without its final extension. */
|
|
107
|
+
readonly stem: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Resolve the workspace-relative and absolute forms of the entry source. */
|
|
111
|
+
export function resolveSource(input: PlanOutputsInput): ResolvedSource {
|
|
112
|
+
const workspaceRoot = normalizePath(input.workspaceRoot);
|
|
113
|
+
const raw = normalizePath(input.sourceFile);
|
|
114
|
+
const absolute = isAbsolutePath(raw) ? raw : joinPath(workspaceRoot, raw);
|
|
115
|
+
const relative = relativePath(workspaceRoot, absolute);
|
|
116
|
+
return Object.freeze({
|
|
117
|
+
relative,
|
|
118
|
+
absolute,
|
|
119
|
+
directory: dirnamePath(absolute),
|
|
120
|
+
stem: sourceStem(absolute),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function sourceStem(absolute: string): string {
|
|
125
|
+
const base = basenamePath(absolute);
|
|
126
|
+
const dot = base.lastIndexOf(".");
|
|
127
|
+
if (dot > 0) return base.slice(0, dot);
|
|
128
|
+
return base === "" ? "index" : base;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Default CSS and JS basenames for a source stem. */
|
|
132
|
+
export function defaultNames(stem: string): { readonly cssName: string; readonly mapName: string } {
|
|
133
|
+
return Object.freeze({ cssName: `${stem}.css`, mapName: `${stem}.map.js` });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Apply defaults, project configuration, file setup and CLI overrides, then
|
|
138
|
+
* resolve all directories to absolute POSIX paths.
|
|
139
|
+
*/
|
|
140
|
+
export function resolveOutputSettings(
|
|
141
|
+
input: PlanOutputsInput,
|
|
142
|
+
source: ResolvedSource,
|
|
143
|
+
workspaceRoot: string,
|
|
144
|
+
): ResolvedOutputSettings {
|
|
145
|
+
const defaults = defaultNames(source.stem);
|
|
146
|
+
let cssDir: DirectorySetting = { value: source.directory, origin: "default" };
|
|
147
|
+
let cssDirs: readonly string[] | undefined;
|
|
148
|
+
let mapDir: DirectorySetting = { value: source.directory, origin: "default" };
|
|
149
|
+
let cssName: NameSetting = { value: defaults.cssName, origin: "default" };
|
|
150
|
+
let mapName: NameSetting = { value: defaults.mapName, origin: "default" };
|
|
151
|
+
let emitCss: boolean = OUTPUT_DEFAULTS.emitCss;
|
|
152
|
+
let emitMap: boolean = OUTPUT_DEFAULTS.emitMap;
|
|
153
|
+
let emitTypes: boolean = OUTPUT_DEFAULTS.emitTypes;
|
|
154
|
+
let sourceMap: boolean = OUTPUT_DEFAULTS.sourceMap;
|
|
155
|
+
let minify: boolean = OUTPUT_DEFAULTS.minify;
|
|
156
|
+
|
|
157
|
+
const projectOutput = input.projectConfig?.output;
|
|
158
|
+
if (projectOutput?.cssDir !== undefined) {
|
|
159
|
+
cssDir = { value: projectOutput.cssDir, origin: "project" };
|
|
160
|
+
}
|
|
161
|
+
if (projectOutput?.mapDir !== undefined) {
|
|
162
|
+
mapDir = { value: projectOutput.mapDir, origin: "project" };
|
|
163
|
+
}
|
|
164
|
+
if (projectOutput?.cssName !== undefined) {
|
|
165
|
+
cssName = { value: projectOutput.cssName, origin: "project" };
|
|
166
|
+
}
|
|
167
|
+
if (projectOutput?.mapName !== undefined) {
|
|
168
|
+
mapName = { value: projectOutput.mapName, origin: "project" };
|
|
169
|
+
}
|
|
170
|
+
if (projectOutput?.emitCss !== undefined) emitCss = projectOutput.emitCss;
|
|
171
|
+
if (projectOutput?.emitMap !== undefined) emitMap = projectOutput.emitMap;
|
|
172
|
+
if (projectOutput?.emitTypes !== undefined) emitTypes = projectOutput.emitTypes;
|
|
173
|
+
// `map-types` is the canonical spelling; it wins over the legacy alias.
|
|
174
|
+
if (projectOutput?.mapTypes !== undefined) emitTypes = projectOutput.mapTypes;
|
|
175
|
+
if (projectOutput?.sourceMap !== undefined) sourceMap = projectOutput.sourceMap;
|
|
176
|
+
if (projectOutput?.minify !== undefined) minify = projectOutput.minify;
|
|
177
|
+
|
|
178
|
+
const fileCssDirs = input.setup.cssDirs;
|
|
179
|
+
if (fileCssDirs !== undefined && fileCssDirs.length > 1) {
|
|
180
|
+
// A file-level list replaces project/CLI single directories entirely and
|
|
181
|
+
// resolves every item exactly against the source file (ADR-0019).
|
|
182
|
+
cssDirs = fileCssDirs;
|
|
183
|
+
cssDir = { value: fileCssDirs[0] ?? ".", origin: "file" };
|
|
184
|
+
} else if (
|
|
185
|
+
projectOutput?.cssDir !== undefined &&
|
|
186
|
+
sameAuthoredPath(input.setup.cssDir, projectOutput.cssDir)
|
|
187
|
+
) {
|
|
188
|
+
cssDir = { value: projectOutput.cssDir, origin: "project" };
|
|
189
|
+
} else if (!isDefaultDirectory(input.setup.cssDir, source, workspaceRoot)) {
|
|
190
|
+
cssDir = { value: input.setup.cssDir, origin: "file" };
|
|
191
|
+
}
|
|
192
|
+
if (
|
|
193
|
+
projectOutput?.mapDir !== undefined &&
|
|
194
|
+
sameAuthoredPath(input.setup.mapDir, projectOutput.mapDir)
|
|
195
|
+
) {
|
|
196
|
+
mapDir = { value: projectOutput.mapDir, origin: "project" };
|
|
197
|
+
} else if (!isDefaultDirectory(input.setup.mapDir, source, workspaceRoot)) {
|
|
198
|
+
mapDir = { value: input.setup.mapDir, origin: "file" };
|
|
199
|
+
}
|
|
200
|
+
if (input.setup.cssName !== defaults.cssName) {
|
|
201
|
+
cssName = { value: input.setup.cssName, origin: "file" };
|
|
202
|
+
}
|
|
203
|
+
if (input.setup.mapName !== defaults.mapName) {
|
|
204
|
+
mapName = { value: input.setup.mapName, origin: "file" };
|
|
205
|
+
}
|
|
206
|
+
if (input.setup.emitCss !== OUTPUT_DEFAULTS.emitCss) emitCss = input.setup.emitCss;
|
|
207
|
+
if (input.setup.emitMap !== OUTPUT_DEFAULTS.emitMap) emitMap = input.setup.emitMap;
|
|
208
|
+
if (input.setup.emitTypes !== OUTPUT_DEFAULTS.emitTypes) emitTypes = input.setup.emitTypes;
|
|
209
|
+
if (input.setup.sourceMap !== OUTPUT_DEFAULTS.sourceMap) sourceMap = input.setup.sourceMap;
|
|
210
|
+
if (input.setup.minify !== OUTPUT_DEFAULTS.minify) minify = input.setup.minify;
|
|
211
|
+
|
|
212
|
+
const cli = input.cliOverrides;
|
|
213
|
+
if (cli?.cssDir !== undefined) {
|
|
214
|
+
cssDir = { value: cli.cssDir, origin: "cli" };
|
|
215
|
+
cssDirs = undefined;
|
|
216
|
+
}
|
|
217
|
+
if (cli?.mapDir !== undefined) mapDir = { value: cli.mapDir, origin: "cli" };
|
|
218
|
+
if (cli?.cssName !== undefined) cssName = { value: cli.cssName, origin: "cli" };
|
|
219
|
+
if (cli?.mapName !== undefined) mapName = { value: cli.mapName, origin: "cli" };
|
|
220
|
+
if (cli?.emitCss !== undefined) emitCss = cli.emitCss;
|
|
221
|
+
if (cli?.emitMap !== undefined) emitMap = cli.emitMap;
|
|
222
|
+
if (cli?.emitTypes !== undefined) emitTypes = cli.emitTypes;
|
|
223
|
+
if (cli?.mapTypes !== undefined) emitTypes = cli.mapTypes;
|
|
224
|
+
if (cli?.sourceMap !== undefined) sourceMap = cli.sourceMap;
|
|
225
|
+
if (cli?.minify !== undefined) minify = cli.minify;
|
|
226
|
+
|
|
227
|
+
const include = input.projectConfig?.include;
|
|
228
|
+
const resolvedCssDirs =
|
|
229
|
+
cssDirs === undefined
|
|
230
|
+
? [resolveDirectory(cssDir, source, workspaceRoot, include)]
|
|
231
|
+
: cssDirs.map((value) => resolveFileDirectory(value, source));
|
|
232
|
+
return Object.freeze({
|
|
233
|
+
cssDir: resolvedCssDirs[0] ?? source.directory,
|
|
234
|
+
cssDirs: Object.freeze(resolvedCssDirs),
|
|
235
|
+
mapDir: resolveDirectory(mapDir, source, workspaceRoot, include),
|
|
236
|
+
cssName: cssName.value,
|
|
237
|
+
mapName: mapName.value,
|
|
238
|
+
emitCss,
|
|
239
|
+
emitMap,
|
|
240
|
+
emitTypes,
|
|
241
|
+
sourceMap,
|
|
242
|
+
minify,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function sameAuthoredPath(left: string, right: string): boolean {
|
|
247
|
+
return normalizeAuthored(left) === normalizeAuthored(right);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function normalizeAuthored(value: string): string {
|
|
251
|
+
const slashed = toPosix(value).trim();
|
|
252
|
+
if (slashed === "") return ".";
|
|
253
|
+
return slashed.endsWith("/") && slashed !== "/" ? slashed.slice(0, -1) : slashed;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Whether a file-layer directory value is just the built-in default for this
|
|
258
|
+
* source (the source directory), regardless of whether the caller wrote `.`,
|
|
259
|
+
* `src`, an absolute path or an empty string.
|
|
260
|
+
*/
|
|
261
|
+
function isDefaultDirectory(value: string, source: ResolvedSource, workspaceRoot: string): boolean {
|
|
262
|
+
const normalized = normalizePath(value);
|
|
263
|
+
if (normalized === ".") return true;
|
|
264
|
+
if (isAbsolutePath(normalized)) return normalizePath(normalized) === source.directory;
|
|
265
|
+
return (
|
|
266
|
+
normalizePath(joinPath(workspaceRoot, value)) === source.directory ||
|
|
267
|
+
normalizePath(joinPath(source.directory, value)) === source.directory
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function resolveDirectory(
|
|
272
|
+
setting: DirectorySetting,
|
|
273
|
+
source: ResolvedSource,
|
|
274
|
+
workspaceRoot: string,
|
|
275
|
+
include: readonly string[] | undefined,
|
|
276
|
+
): string {
|
|
277
|
+
switch (setting.origin) {
|
|
278
|
+
case "default":
|
|
279
|
+
return source.directory;
|
|
280
|
+
case "file":
|
|
281
|
+
return resolveFileDirectory(setting.value, source);
|
|
282
|
+
case "cli":
|
|
283
|
+
return isAbsolutePath(setting.value)
|
|
284
|
+
? normalizePath(setting.value)
|
|
285
|
+
: joinPath(workspaceRoot, setting.value);
|
|
286
|
+
case "project":
|
|
287
|
+
return resolveProjectDirectory(setting.value, source, workspaceRoot, include);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Resolve a file-level directory exactly against the source directory. */
|
|
292
|
+
function resolveFileDirectory(value: string, source: ResolvedSource): string {
|
|
293
|
+
return isAbsolutePath(value) ? normalizePath(value) : joinPath(source.directory, value);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function resolveProjectDirectory(
|
|
297
|
+
value: string,
|
|
298
|
+
source: ResolvedSource,
|
|
299
|
+
workspaceRoot: string,
|
|
300
|
+
include: readonly string[] | undefined,
|
|
301
|
+
): string {
|
|
302
|
+
if (isAbsolutePath(value)) return normalizePath(value);
|
|
303
|
+
const base = joinPath(workspaceRoot, value);
|
|
304
|
+
const sourceRoot = sourceRootFor(workspaceRoot, include, source.absolute);
|
|
305
|
+
const mirror = relativePath(sourceRoot, source.directory);
|
|
306
|
+
if (mirror === ".") return base;
|
|
307
|
+
if (isSafeRelativePath(mirror)) return joinPath(base, mirror);
|
|
308
|
+
|
|
309
|
+
const fallback = relativePath(workspaceRoot, source.directory);
|
|
310
|
+
if (isSafeRelativePath(fallback)) return joinPath(base, fallback);
|
|
311
|
+
return base;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Derive a project source root from static prefixes in `include` patterns.
|
|
316
|
+
*
|
|
317
|
+
* `src/**\/*.cssx` yields `<workspace>/src`, so project output directories can
|
|
318
|
+
* mirror `pages/dashboard` instead of flattening or repeating `src`. When the
|
|
319
|
+
* include list has no common static prefix, the workspace root is used.
|
|
320
|
+
*/
|
|
321
|
+
export function sourceRootFor(
|
|
322
|
+
workspaceRoot: string,
|
|
323
|
+
include: readonly string[] | undefined,
|
|
324
|
+
sourceAbsolute: string,
|
|
325
|
+
): string {
|
|
326
|
+
if (include === undefined || include.length === 0) return workspaceRoot;
|
|
327
|
+
|
|
328
|
+
const prefixes: string[][] = [];
|
|
329
|
+
for (const pattern of include) {
|
|
330
|
+
const normalized = toPosix(pattern).trim();
|
|
331
|
+
if (normalized === "" || normalized.startsWith("!")) continue;
|
|
332
|
+
const segments = normalized.split("/").filter((segment) => segment !== "" && segment !== ".");
|
|
333
|
+
const prefix: string[] = [];
|
|
334
|
+
for (const segment of segments) {
|
|
335
|
+
if (isGlobSegment(segment)) break;
|
|
336
|
+
prefix.push(segment);
|
|
337
|
+
}
|
|
338
|
+
if (prefix.length > 0) prefixes.push(prefix);
|
|
339
|
+
}
|
|
340
|
+
if (prefixes.length === 0) return workspaceRoot;
|
|
341
|
+
|
|
342
|
+
const common = [...(prefixes[0] ?? [])];
|
|
343
|
+
for (const prefix of prefixes.slice(1)) {
|
|
344
|
+
let index = 0;
|
|
345
|
+
while (index < common.length && index < prefix.length && common[index] === prefix[index]) {
|
|
346
|
+
index += 1;
|
|
347
|
+
}
|
|
348
|
+
common.length = index;
|
|
349
|
+
}
|
|
350
|
+
if (common.length === 0) return workspaceRoot;
|
|
351
|
+
|
|
352
|
+
const candidate = joinPath(workspaceRoot, ...common);
|
|
353
|
+
return isWithinPath(candidate, sourceAbsolute) ? candidate : workspaceRoot;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function isGlobSegment(segment: string): boolean {
|
|
357
|
+
return (
|
|
358
|
+
segment.includes("*") ||
|
|
359
|
+
segment.includes("?") ||
|
|
360
|
+
segment.includes("[") ||
|
|
361
|
+
segment.includes("]") ||
|
|
362
|
+
segment.includes("{") ||
|
|
363
|
+
segment.includes("}")
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** Derive the declaration basename from a map basename (`classes.js` → `classes.d.ts`). */
|
|
368
|
+
export function declarationNameFor(mapName: string): string {
|
|
369
|
+
return `${mapName.slice(0, -3)}.d.ts`;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Derive the CSS source-map basename (`theme.css` → `theme.css.map`). */
|
|
373
|
+
export function sourceMapNameFor(cssName: string): string {
|
|
374
|
+
return `${cssName}.map`;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Baseline settings shape used by callers and tests when a source has no file
|
|
379
|
+
* `@setup`. Directories point at the source directory so the planner sees the
|
|
380
|
+
* documented default rather than an accidental override.
|
|
381
|
+
*/
|
|
382
|
+
export function defaultSetupFor(file: string): ResolvedSetup {
|
|
383
|
+
const base = basenamePath(file);
|
|
384
|
+
const dot = base.lastIndexOf(".");
|
|
385
|
+
const stem = dot > 0 ? base.slice(0, dot) : base;
|
|
386
|
+
const directory = dirnamePath(normalizePath(file));
|
|
387
|
+
return {
|
|
388
|
+
prefix: "",
|
|
389
|
+
cssDir: directory,
|
|
390
|
+
mapDir: directory,
|
|
391
|
+
cssName: `${stem}.css`,
|
|
392
|
+
mapName: `${stem}.map.js`,
|
|
393
|
+
emitCss: OUTPUT_DEFAULTS.emitCss,
|
|
394
|
+
emitMap: OUTPUT_DEFAULTS.emitMap,
|
|
395
|
+
emitTypes: OUTPUT_DEFAULTS.emitTypes,
|
|
396
|
+
sourceMap: OUTPUT_DEFAULTS.sourceMap,
|
|
397
|
+
minify: OUTPUT_DEFAULTS.minify,
|
|
398
|
+
mapInherit: OUTPUT_DEFAULTS.mapInherit,
|
|
399
|
+
importCss: OUTPUT_DEFAULTS.importCss,
|
|
400
|
+
};
|
|
401
|
+
}
|