@chikx/compiler 0.0.0-stage → 0.1.0
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/importPath.d.ts +27 -0
- package/dist/output/importPath.d.ts.map +1 -0
- package/dist/output/importPath.js +84 -0
- package/dist/output/importPath.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
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import specifier for the opt-in CSS side-effect import in the class map
|
|
3
|
+
* (ADR-0021).
|
|
4
|
+
*
|
|
5
|
+
* The specifier is computed from the two planned artifacts, never from authored
|
|
6
|
+
* settings, so it always names the stylesheet that is actually written:
|
|
7
|
+
*
|
|
8
|
+
* - relative to the directory of the emitted `map.js`;
|
|
9
|
+
* - POSIX separators only;
|
|
10
|
+
* - always `./`-prefixed when the stylesheet is in or below the map directory,
|
|
11
|
+
* and left as authored `..` segments when it is above it.
|
|
12
|
+
*
|
|
13
|
+
* The planner guarantees both artifacts stay inside the workspace; a
|
|
14
|
+
* non-relative result would therefore mean the plan was rejected, and callers
|
|
15
|
+
* omit the import instead of emitting a dangling specifier.
|
|
16
|
+
*/
|
|
17
|
+
import { dirnamePath, isAbsolutePath, relativePath } from "./paths.js";
|
|
18
|
+
/**
|
|
19
|
+
* Return the ESM specifier a generated map uses to import its stylesheet.
|
|
20
|
+
*
|
|
21
|
+
* @param mapFile Absolute POSIX path of the generated JS map.
|
|
22
|
+
* @param stylesheetFile Absolute POSIX path of the emitted stylesheet.
|
|
23
|
+
*/
|
|
24
|
+
export function stylesheetImportSpecifier(mapFile, stylesheetFile) {
|
|
25
|
+
const relative = relativePath(dirnamePath(mapFile), stylesheetFile);
|
|
26
|
+
if (relative === "." || relative.startsWith("../") || isAbsolutePath(relative))
|
|
27
|
+
return relative;
|
|
28
|
+
return `./${relative}`;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=import-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-path.js","sourceRoot":"","sources":["../../src/output/import-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAe,EAAE,cAAsB;IAC/E,MAAM,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC;IACpE,IAAI,QAAQ,KAAK,GAAG,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,cAAc,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAChG,OAAO,KAAK,QAAQ,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS side-effect import computation for the generated JS class map.
|
|
3
|
+
*
|
|
4
|
+
* The specifier is computed from the map file's directory to the CSS artifact,
|
|
5
|
+
* always using forward slashes and a `./` prefix when the relative form does
|
|
6
|
+
* not already start with `.`. The returned text is ready to place between
|
|
7
|
+
* double quotes in `import "…";`: backslashes, double quotes, control
|
|
8
|
+
* characters and JavaScript line separators are escaped.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Compute the import specifier from a JS map file to a CSS file.
|
|
12
|
+
*
|
|
13
|
+
* @param mapPath Absolute POSIX path of the JS map artifact.
|
|
14
|
+
* @param cssPath Absolute POSIX path of the CSS artifact.
|
|
15
|
+
* @returns Escaped JS string-literal content such as `./button.css` or
|
|
16
|
+
* `../styles/button.css`. If the paths have different roots, the absolute CSS
|
|
17
|
+
* path is returned because no relative specifier exists; such a plan is
|
|
18
|
+
* rejected earlier by containment checks.
|
|
19
|
+
*/
|
|
20
|
+
export declare function importSpecifierFor(mapPath: string, cssPath: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Escape text so it can be inserted between double quotes in a JS string
|
|
23
|
+
* literal. Ordinary path characters are unchanged, so a normal specifier such
|
|
24
|
+
* as `../styles/button.css` round-trips byte for byte.
|
|
25
|
+
*/
|
|
26
|
+
export declare function escapeJsString(value: string): string;
|
|
27
|
+
//# sourceMappingURL=importPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importPath.d.ts","sourceRoot":"","sources":["../../src/output/importPath.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQ3E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA0CpD"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS side-effect import computation for the generated JS class map.
|
|
3
|
+
*
|
|
4
|
+
* The specifier is computed from the map file's directory to the CSS artifact,
|
|
5
|
+
* always using forward slashes and a `./` prefix when the relative form does
|
|
6
|
+
* not already start with `.`. The returned text is ready to place between
|
|
7
|
+
* double quotes in `import "…";`: backslashes, double quotes, control
|
|
8
|
+
* characters and JavaScript line separators are escaped.
|
|
9
|
+
*/
|
|
10
|
+
import { dirnamePath, isAbsolutePath, relativePath } from "./paths.js";
|
|
11
|
+
/**
|
|
12
|
+
* Compute the import specifier from a JS map file to a CSS file.
|
|
13
|
+
*
|
|
14
|
+
* @param mapPath Absolute POSIX path of the JS map artifact.
|
|
15
|
+
* @param cssPath Absolute POSIX path of the CSS artifact.
|
|
16
|
+
* @returns Escaped JS string-literal content such as `./button.css` or
|
|
17
|
+
* `../styles/button.css`. If the paths have different roots, the absolute CSS
|
|
18
|
+
* path is returned because no relative specifier exists; such a plan is
|
|
19
|
+
* rejected earlier by containment checks.
|
|
20
|
+
*/
|
|
21
|
+
export function importSpecifierFor(mapPath, cssPath) {
|
|
22
|
+
const relative = relativePath(dirnamePath(mapPath), cssPath);
|
|
23
|
+
if (isAbsolutePath(relative))
|
|
24
|
+
return escapeJsString(relative);
|
|
25
|
+
let specifier = relative;
|
|
26
|
+
if (relative === ".")
|
|
27
|
+
specifier = ".";
|
|
28
|
+
else if (relative.startsWith("../") || relative.startsWith("./"))
|
|
29
|
+
specifier = relative;
|
|
30
|
+
else
|
|
31
|
+
specifier = `./${relative}`;
|
|
32
|
+
return escapeJsString(specifier);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Escape text so it can be inserted between double quotes in a JS string
|
|
36
|
+
* literal. Ordinary path characters are unchanged, so a normal specifier such
|
|
37
|
+
* as `../styles/button.css` round-trips byte for byte.
|
|
38
|
+
*/
|
|
39
|
+
export function escapeJsString(value) {
|
|
40
|
+
let escaped = "";
|
|
41
|
+
for (const character of value) {
|
|
42
|
+
const code = character.codePointAt(0) ?? 0;
|
|
43
|
+
switch (character) {
|
|
44
|
+
case "\\":
|
|
45
|
+
escaped += "\\\\";
|
|
46
|
+
break;
|
|
47
|
+
case '"':
|
|
48
|
+
escaped += '\\"';
|
|
49
|
+
break;
|
|
50
|
+
case "\n":
|
|
51
|
+
escaped += "\\n";
|
|
52
|
+
break;
|
|
53
|
+
case "\r":
|
|
54
|
+
escaped += "\\r";
|
|
55
|
+
break;
|
|
56
|
+
case "\t":
|
|
57
|
+
escaped += "\\t";
|
|
58
|
+
break;
|
|
59
|
+
case "\b":
|
|
60
|
+
escaped += "\\b";
|
|
61
|
+
break;
|
|
62
|
+
case "\f":
|
|
63
|
+
escaped += "\\f";
|
|
64
|
+
break;
|
|
65
|
+
case "\v":
|
|
66
|
+
escaped += "\\v";
|
|
67
|
+
break;
|
|
68
|
+
case "\u2028":
|
|
69
|
+
escaped += "\\u2028";
|
|
70
|
+
break;
|
|
71
|
+
case "\u2029":
|
|
72
|
+
escaped += "\\u2029";
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
if (code < 0x20)
|
|
76
|
+
escaped += `\\x${code.toString(16).padStart(2, "0")}`;
|
|
77
|
+
else
|
|
78
|
+
escaped += character;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return escaped;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=importPath.js.map
|
|
@@ -0,0 +1 @@
|
|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I;gBACP,OAAO,IAAI,KAAK,CAAC;gBACjB,MAAM;YACR,KAAK,IAAI;gBACP,OAAO,IAAI,KAAK,CAAC;gBACjB,MAAM;YACR,KAAK,IAAI;gBACP,OAAO,IAAI,KAAK,CAAC;gBACjB,MAAM;YACR,KAAK,IAAI;gBACP,OAAO,IAAI,KAAK,CAAC;gBACjB,MAAM;YACR,KAAK,QAAQ;gBACX,OAAO,IAAI,SAAS,CAAC;gBACrB,MAAM;YACR,KAAK,QAAQ;gBACX,OAAO,IAAI,SAAS,CAAC;gBACrB,MAAM;YACR;gBACE,IAAI,IAAI,GAAG,IAAI;oBAAE,OAAO,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;;oBAClE,OAAO,IAAI,SAAS,CAAC;gBAC1B,MAAM;QACV,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure output planner for Chikx (SPECIFICATION.md §9).
|
|
3
|
+
*
|
|
4
|
+
* `planOutputs` resolves every CSS, JS map, declaration and CSS source-map
|
|
5
|
+
* destination from the frozen `ResolvedSetup`/`ProjectConfig`/CLI inputs,
|
|
6
|
+
* validates the complete plan, and returns it with a matching manifest. It is
|
|
7
|
+
* synchronous, deterministic and never writes. Expected planning failures are
|
|
8
|
+
* returned as CHIKX5001 diagnostics instead of exceptions.
|
|
9
|
+
*
|
|
10
|
+
* The frozen `PlanOutputsInput` does not carry a host or trusted-output policy.
|
|
11
|
+
* This module therefore exposes an optional second context argument:
|
|
12
|
+
* `host` supplies `canonicalize` for symlink containment, and
|
|
13
|
+
* `occupiedTargets` lets a project build pass targets already planned by other
|
|
14
|
+
* entries so cross-source collisions are rejected. Without them the planner
|
|
15
|
+
* uses lexical identity canonicalization and validates one entry at a time.
|
|
16
|
+
* External output is always rejected; no trusted policy escape exists in the
|
|
17
|
+
* frozen contracts.
|
|
18
|
+
*/
|
|
19
|
+
import type { PlanOutputsInput, PlanOutputsResult } from "../types/result.js";
|
|
20
|
+
import type { OutputPlannerHost } from "./validate.js";
|
|
21
|
+
export type { OutputPlannerHost } from "./validate.js";
|
|
22
|
+
/** Optional planning context that the frozen input shape has no room for. */
|
|
23
|
+
export interface OutputPlannerContext {
|
|
24
|
+
/** Canonicalization host used to detect symlink escapes. */
|
|
25
|
+
readonly host?: OutputPlannerHost;
|
|
26
|
+
/** Absolute or workspace-relative targets already planned by other entries. */
|
|
27
|
+
readonly occupiedTargets?: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validate and return the complete output plan for one entry before anything is
|
|
31
|
+
* written.
|
|
32
|
+
*
|
|
33
|
+
* @param input Frozen planner input: source, effective setup, optional project
|
|
34
|
+
* configuration and CLI overrides, and the absolute workspace root.
|
|
35
|
+
* @param context Optional host and cross-entry occupied targets.
|
|
36
|
+
* @returns The valid plan plus diagnostics. Any error leaves an empty plan so a
|
|
37
|
+
* caller cannot accidentally write a partial or unsafe artifact set.
|
|
38
|
+
*/
|
|
39
|
+
export declare function planOutputs(input: PlanOutputsInput, context?: OutputPlannerContext): PlanOutputsResult;
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/output/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAGV,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,oBAAoB,CAAC;AAU5B,OAAO,KAAK,EAAmB,iBAAiB,EAAE,MAAM,eAAe,CAAC;AASxE,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,6EAA6E;AAC7E,MAAM,WAAW,oBAAoB;IACnC,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,CAAC,EAAE,iBAAiB,CAAC;IAClC,+EAA+E;IAC/E,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,gBAAgB,EACvB,OAAO,GAAE,oBAAyB,GACjC,iBAAiB,CAsHnB"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure output planner for Chikx (SPECIFICATION.md §9).
|
|
3
|
+
*
|
|
4
|
+
* `planOutputs` resolves every CSS, JS map, declaration and CSS source-map
|
|
5
|
+
* destination from the frozen `ResolvedSetup`/`ProjectConfig`/CLI inputs,
|
|
6
|
+
* validates the complete plan, and returns it with a matching manifest. It is
|
|
7
|
+
* synchronous, deterministic and never writes. Expected planning failures are
|
|
8
|
+
* returned as CHIKX5001 diagnostics instead of exceptions.
|
|
9
|
+
*
|
|
10
|
+
* The frozen `PlanOutputsInput` does not carry a host or trusted-output policy.
|
|
11
|
+
* This module therefore exposes an optional second context argument:
|
|
12
|
+
* `host` supplies `canonicalize` for symlink containment, and
|
|
13
|
+
* `occupiedTargets` lets a project build pass targets already planned by other
|
|
14
|
+
* entries so cross-source collisions are rejected. Without them the planner
|
|
15
|
+
* uses lexical identity canonicalization and validates one entry at a time.
|
|
16
|
+
* External output is always rejected; no trusted policy escape exists in the
|
|
17
|
+
* frozen contracts.
|
|
18
|
+
*/
|
|
19
|
+
import { error } from "../types/diagnostics.js";
|
|
20
|
+
import { buildManifest } from "./manifest.js";
|
|
21
|
+
import { isAbsolutePath, joinPath, normalizePath, relativePath } from "./paths.js";
|
|
22
|
+
import { declarationNameFor, resolveOutputSettings, resolveSource, sourceMapNameFor, } from "./resolve.js";
|
|
23
|
+
import { findDuplicateTargets, suppressedTypesWarning, validateCandidate, validateName, workspacePathFor, } from "./validate.js";
|
|
24
|
+
/**
|
|
25
|
+
* Validate and return the complete output plan for one entry before anything is
|
|
26
|
+
* written.
|
|
27
|
+
*
|
|
28
|
+
* @param input Frozen planner input: source, effective setup, optional project
|
|
29
|
+
* configuration and CLI overrides, and the absolute workspace root.
|
|
30
|
+
* @param context Optional host and cross-entry occupied targets.
|
|
31
|
+
* @returns The valid plan plus diagnostics. Any error leaves an empty plan so a
|
|
32
|
+
* caller cannot accidentally write a partial or unsafe artifact set.
|
|
33
|
+
*/
|
|
34
|
+
export function planOutputs(input, context = {}) {
|
|
35
|
+
const workspaceRoot = normalizePath(input.workspaceRoot);
|
|
36
|
+
const resolvedSource = resolveSource(input);
|
|
37
|
+
const sourceRelative = relativePath(workspaceRoot, resolvedSource.absolute);
|
|
38
|
+
const source = Object.freeze({ ...resolvedSource, relative: sourceRelative });
|
|
39
|
+
const span = Object.freeze({ start: 0, end: 0, file: sourceRelative });
|
|
40
|
+
const emptyPlan = Object.freeze({
|
|
41
|
+
outputs: Object.freeze([]),
|
|
42
|
+
manifest: Object.freeze([]),
|
|
43
|
+
});
|
|
44
|
+
const diagnostics = [];
|
|
45
|
+
if (!isAbsolutePath(workspaceRoot)) {
|
|
46
|
+
diagnostics.push(error("CHIKX5001", `Workspace root "${input.workspaceRoot}" must be an absolute POSIX or drive-letter path.`, span));
|
|
47
|
+
return freezeResult(emptyPlan, diagnostics);
|
|
48
|
+
}
|
|
49
|
+
if (isAbsolutePath(sourceRelative) ||
|
|
50
|
+
sourceRelative === ".." ||
|
|
51
|
+
sourceRelative.startsWith("../")) {
|
|
52
|
+
diagnostics.push(error("CHIKX5001", `Source "${sourceRelative}" is outside the workspace root "${workspaceRoot}".`, span));
|
|
53
|
+
return freezeResult(emptyPlan, diagnostics);
|
|
54
|
+
}
|
|
55
|
+
const settings = resolveOutputSettings(input, source, workspaceRoot);
|
|
56
|
+
let emitTypes = settings.emitTypes;
|
|
57
|
+
if (!settings.emitMap && settings.emitTypes) {
|
|
58
|
+
diagnostics.push(suppressedTypesWarning(span));
|
|
59
|
+
emitTypes = false;
|
|
60
|
+
}
|
|
61
|
+
const cssNameDiagnostic = settings.emitCss
|
|
62
|
+
? validateName(settings.cssName, "css", span)
|
|
63
|
+
: undefined;
|
|
64
|
+
if (cssNameDiagnostic !== undefined)
|
|
65
|
+
diagnostics.push(cssNameDiagnostic);
|
|
66
|
+
const mapNameDiagnostic = settings.emitMap
|
|
67
|
+
? validateName(settings.mapName, "js", span)
|
|
68
|
+
: undefined;
|
|
69
|
+
if (mapNameDiagnostic !== undefined)
|
|
70
|
+
diagnostics.push(mapNameDiagnostic);
|
|
71
|
+
if (hasError(diagnostics)) {
|
|
72
|
+
return freezeResult(emptyPlan, diagnostics);
|
|
73
|
+
}
|
|
74
|
+
const candidates = [];
|
|
75
|
+
const mapAbsolute = joinPath(settings.mapDir, settings.mapName);
|
|
76
|
+
if (settings.emitCss) {
|
|
77
|
+
for (const directory of settings.cssDirs) {
|
|
78
|
+
const cssAbsolute = joinPath(directory, settings.cssName);
|
|
79
|
+
candidates.push(toCandidate("css", cssAbsolute, source.relative, workspaceRoot));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (settings.emitMap) {
|
|
83
|
+
candidates.push(toCandidate("js", mapAbsolute, source.relative, workspaceRoot));
|
|
84
|
+
if (emitTypes) {
|
|
85
|
+
const declarationsAbsolute = joinPath(settings.mapDir, declarationNameFor(settings.mapName));
|
|
86
|
+
candidates.push(toCandidate("types", declarationsAbsolute, source.relative, workspaceRoot));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (settings.emitCss && settings.sourceMap) {
|
|
90
|
+
for (const directory of settings.cssDirs) {
|
|
91
|
+
const mapFileAbsolute = joinPath(directory, sourceMapNameFor(settings.cssName));
|
|
92
|
+
candidates.push(toCandidate("cssSourceMap", mapFileAbsolute, source.relative, workspaceRoot));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (const candidate of candidates) {
|
|
96
|
+
diagnostics.push(...validateCandidate(candidate, {
|
|
97
|
+
workspaceRoot,
|
|
98
|
+
source: { relative: source.relative, absolute: source.absolute },
|
|
99
|
+
span,
|
|
100
|
+
...(context.host === undefined ? {} : { host: context.host }),
|
|
101
|
+
...(context.occupiedTargets === undefined
|
|
102
|
+
? {}
|
|
103
|
+
: { occupiedTargets: context.occupiedTargets }),
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
diagnostics.push(...findDuplicateTargets(candidates, span));
|
|
107
|
+
if (hasError(diagnostics)) {
|
|
108
|
+
return freezeResult(emptyPlan, diagnostics);
|
|
109
|
+
}
|
|
110
|
+
const outputs = Object.freeze(candidates.map((candidate) => Object.freeze({
|
|
111
|
+
kind: candidate.kind,
|
|
112
|
+
absolutePath: candidate.absolutePath,
|
|
113
|
+
workspacePath: candidate.workspacePath,
|
|
114
|
+
sourceFile: candidate.sourceFile,
|
|
115
|
+
})));
|
|
116
|
+
return freezeResult(Object.freeze({
|
|
117
|
+
outputs,
|
|
118
|
+
manifest: buildManifest(outputs),
|
|
119
|
+
}), diagnostics);
|
|
120
|
+
}
|
|
121
|
+
function toCandidate(kind, absolutePath, sourceFile, workspaceRoot) {
|
|
122
|
+
return Object.freeze({
|
|
123
|
+
kind,
|
|
124
|
+
absolutePath: normalizePath(absolutePath),
|
|
125
|
+
workspacePath: workspacePathFor(workspaceRoot, absolutePath),
|
|
126
|
+
sourceFile,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function hasError(diagnostics) {
|
|
130
|
+
return diagnostics.some((diagnostic) => diagnostic.severity === "error");
|
|
131
|
+
}
|
|
132
|
+
function freezeResult(plan, diagnostics) {
|
|
133
|
+
return Object.freeze({
|
|
134
|
+
plan,
|
|
135
|
+
diagnostics: Object.freeze([...diagnostics]),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/output/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,KAA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AAQ,EAAE,aAAa,CAAC,OAAO,CAAC;KACjC,CAAC,EACF,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAClB,IAAgB,EAChB,YAAoB,EACpB,UAAkB,EAClB,aAAqB;IAErB,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI;QACJ,YAAY,EAAE,aAAa,CAAC,YAAY,CAAC;QACzC,aAAa,EAAE,gBAAgB,CAAC,aAAa,EAAE,YAAY,CAAC;QAC5D,UAAU;KACX,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,WAAkC;IAClD,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,YAAY,CAAC,IAAgB,EAAE,WAAyB;IAC/D,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI;QACJ,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC;KAC7C,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manifest construction for planned artifacts.
|
|
3
|
+
*
|
|
4
|
+
* A manifest records every compiler-owned artifact so `chikx clean` and watch
|
|
5
|
+
* invalidation can remove or refresh only files the compiler created. Entries
|
|
6
|
+
* never carry timestamps and follow the same order as the plan. Content hashes
|
|
7
|
+
* are added only after a successful write, so the planner omits them.
|
|
8
|
+
*/
|
|
9
|
+
import type { ManifestEntry, PlannedOutput } from "../types/result.js";
|
|
10
|
+
/**
|
|
11
|
+
* Build one manifest entry per planned artifact, in plan order.
|
|
12
|
+
*
|
|
13
|
+
* @param outputs Deterministically ordered planned artifacts.
|
|
14
|
+
* @returns Frozen manifest entries with kind, workspace path and source file.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildManifest(outputs: readonly PlannedOutput[]): readonly ManifestEntry[];
|
|
17
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/output/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEvE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,SAAS,aAAa,EAAE,CAUzF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manifest construction for planned artifacts.
|
|
3
|
+
*
|
|
4
|
+
* A manifest records every compiler-owned artifact so `chikx clean` and watch
|
|
5
|
+
* invalidation can remove or refresh only files the compiler created. Entries
|
|
6
|
+
* never carry timestamps and follow the same order as the plan. Content hashes
|
|
7
|
+
* are added only after a successful write, so the planner omits them.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Build one manifest entry per planned artifact, in plan order.
|
|
11
|
+
*
|
|
12
|
+
* @param outputs Deterministically ordered planned artifacts.
|
|
13
|
+
* @returns Frozen manifest entries with kind, workspace path and source file.
|
|
14
|
+
*/
|
|
15
|
+
export function buildManifest(outputs) {
|
|
16
|
+
return Object.freeze(outputs.map((output) => Object.freeze({
|
|
17
|
+
kind: output.kind,
|
|
18
|
+
workspacePath: output.workspacePath,
|
|
19
|
+
sourceFile: output.sourceFile,
|
|
20
|
+
})));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/output/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,OAAiC;IAC7D,OAAO,MAAM,CAAC,MAAM,CAClB,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACrB,MAAM,CAAC,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAC,CACH,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/** Convert every backslash to a forward slash. */
|
|
11
|
+
export declare function toPosix(path: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a path is absolute in the planner's POSIX-plus-drive model.
|
|
14
|
+
*
|
|
15
|
+
* A leading slash, a UNC-style double slash and a drive prefix (`C:/`, `C:`)
|
|
16
|
+
* are absolute. Bare relative paths are not.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isAbsolutePath(path: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Normalize a path to forward slashes and collapse `.`/`..` segments lexically.
|
|
21
|
+
*
|
|
22
|
+
* Absolute paths keep their root (`/`, `//` or a drive such as `C:/`) and never
|
|
23
|
+
* climb above it. Relative paths keep leading `..` segments. An empty result
|
|
24
|
+
* becomes `.`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function normalizePath(path: string): string;
|
|
27
|
+
/** Join path parts with `/`, resetting to an absolute part when one appears. */
|
|
28
|
+
export declare function joinPath(base: string, ...parts: readonly string[]): string;
|
|
29
|
+
/** Return the parent directory of a normalized path. */
|
|
30
|
+
export declare function dirnamePath(path: string): string;
|
|
31
|
+
/** Return the final path segment, or an empty string for a root. */
|
|
32
|
+
export declare function basenamePath(path: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Compute a relative path from one path to another.
|
|
35
|
+
*
|
|
36
|
+
* Both paths must share the same absolute root; otherwise the normalized target
|
|
37
|
+
* is returned unchanged. Relative inputs are compared lexically. The result is
|
|
38
|
+
* `.` when the paths are identical.
|
|
39
|
+
*/
|
|
40
|
+
export declare function relativePath(from: string, to: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Whether `target` lies inside `root`, including the root itself.
|
|
43
|
+
*
|
|
44
|
+
* Comparison is lexical. Drive-letter roots and their segments are compared
|
|
45
|
+
* case-insensitively to match Windows expectations; POSIX paths stay
|
|
46
|
+
* case-sensitive. Symlink and full case policy belong to the injected host.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isWithinPath(root: string, target: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a path is a safe, non-empty relative path that does not climb out of
|
|
51
|
+
* its base (`..`, `../x` and absolute paths are not safe).
|
|
52
|
+
*/
|
|
53
|
+
export declare function isSafeRelativePath(path: string): boolean;
|
|
54
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/output/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,kDAAkD;AAClD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGpD;AAqBD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqBlD;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAW1E;AAED,wDAAwD;AACxD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYhD;AAED,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOjD;AAcD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CA+B7D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAgBlE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIxD"}
|
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
/** Convert every backslash to a forward slash. */
|
|
11
|
+
export function toPosix(path) {
|
|
12
|
+
return path.replace(/\\/g, "/");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Whether a path is absolute in the planner's POSIX-plus-drive model.
|
|
16
|
+
*
|
|
17
|
+
* A leading slash, a UNC-style double slash and a drive prefix (`C:/`, `C:`)
|
|
18
|
+
* are absolute. Bare relative paths are not.
|
|
19
|
+
*/
|
|
20
|
+
export function isAbsolutePath(path) {
|
|
21
|
+
const slashed = toPosix(path);
|
|
22
|
+
return slashed.startsWith("/") || /^[A-Za-z]:(\/|$)/.test(slashed);
|
|
23
|
+
}
|
|
24
|
+
function splitRoot(path) {
|
|
25
|
+
const match = /^([A-Za-z]):(?=\/|$)/.exec(path);
|
|
26
|
+
if (match?.[1] !== undefined) {
|
|
27
|
+
let rest = path.slice(2);
|
|
28
|
+
if (rest.startsWith("/"))
|
|
29
|
+
rest = rest.slice(1);
|
|
30
|
+
return { root: `${match[1]}:/`, rest };
|
|
31
|
+
}
|
|
32
|
+
if (path.startsWith("//"))
|
|
33
|
+
return { root: "//", rest: path.slice(2) };
|
|
34
|
+
if (path.startsWith("/"))
|
|
35
|
+
return { root: "/", rest: path.slice(1) };
|
|
36
|
+
return { root: "", rest: path };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Normalize a path to forward slashes and collapse `.`/`..` segments lexically.
|
|
40
|
+
*
|
|
41
|
+
* Absolute paths keep their root (`/`, `//` or a drive such as `C:/`) and never
|
|
42
|
+
* climb above it. Relative paths keep leading `..` segments. An empty result
|
|
43
|
+
* becomes `.`.
|
|
44
|
+
*/
|
|
45
|
+
export function normalizePath(path) {
|
|
46
|
+
const slashed = toPosix(path);
|
|
47
|
+
const { root, rest } = splitRoot(slashed);
|
|
48
|
+
const segments = [];
|
|
49
|
+
for (const segment of rest.split("/")) {
|
|
50
|
+
if (segment === "" || segment === ".")
|
|
51
|
+
continue;
|
|
52
|
+
if (segment === "..") {
|
|
53
|
+
const last = segments[segments.length - 1];
|
|
54
|
+
if (last !== undefined && last !== "..")
|
|
55
|
+
segments.pop();
|
|
56
|
+
else if (root === "")
|
|
57
|
+
segments.push("..");
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
segments.push(segment);
|
|
61
|
+
}
|
|
62
|
+
const body = segments.join("/");
|
|
63
|
+
if (root === "")
|
|
64
|
+
return body === "" ? "." : body;
|
|
65
|
+
if (root === "/")
|
|
66
|
+
return body === "" ? "/" : `/${body}`;
|
|
67
|
+
if (root === "//")
|
|
68
|
+
return body === "" ? "//" : `//${body}`;
|
|
69
|
+
return body === "" ? root : `${root}${body}`;
|
|
70
|
+
}
|
|
71
|
+
/** Join path parts with `/`, resetting to an absolute part when one appears. */
|
|
72
|
+
export function joinPath(base, ...parts) {
|
|
73
|
+
let result = normalizePath(base);
|
|
74
|
+
for (const part of parts) {
|
|
75
|
+
if (part === undefined || part === "")
|
|
76
|
+
continue;
|
|
77
|
+
if (isAbsolutePath(part)) {
|
|
78
|
+
result = normalizePath(part);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
result = normalizePath(result === "." ? part : `${result}/${part}`);
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
/** Return the parent directory of a normalized path. */
|
|
86
|
+
export function dirnamePath(path) {
|
|
87
|
+
const normalized = normalizePath(path);
|
|
88
|
+
if (normalized === "/" || normalized === "//" || /^[A-Za-z]:\/$/.test(normalized)) {
|
|
89
|
+
return normalized;
|
|
90
|
+
}
|
|
91
|
+
const index = normalized.lastIndexOf("/");
|
|
92
|
+
if (index < 0)
|
|
93
|
+
return ".";
|
|
94
|
+
const parent = normalized.slice(0, index);
|
|
95
|
+
if (parent === "")
|
|
96
|
+
return "/";
|
|
97
|
+
if (parent === "/")
|
|
98
|
+
return "/";
|
|
99
|
+
if (/^[A-Za-z]:$/.test(parent))
|
|
100
|
+
return `${parent}/`;
|
|
101
|
+
return parent;
|
|
102
|
+
}
|
|
103
|
+
/** Return the final path segment, or an empty string for a root. */
|
|
104
|
+
export function basenamePath(path) {
|
|
105
|
+
const normalized = normalizePath(path);
|
|
106
|
+
if (normalized === "/" || normalized === "//" || /^[A-Za-z]:\/$/.test(normalized)) {
|
|
107
|
+
return "";
|
|
108
|
+
}
|
|
109
|
+
const index = normalized.lastIndexOf("/");
|
|
110
|
+
return index < 0 ? normalized : normalized.slice(index + 1);
|
|
111
|
+
}
|
|
112
|
+
function isDriveRoot(root) {
|
|
113
|
+
return /^[A-Za-z]:\/$/.test(root);
|
|
114
|
+
}
|
|
115
|
+
function rootsMatch(left, right) {
|
|
116
|
+
return left.toLowerCase() === right.toLowerCase();
|
|
117
|
+
}
|
|
118
|
+
function segmentsEqual(left, right, caseInsensitive) {
|
|
119
|
+
return caseInsensitive ? left.toLowerCase() === right.toLowerCase() : left === right;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Compute a relative path from one path to another.
|
|
123
|
+
*
|
|
124
|
+
* Both paths must share the same absolute root; otherwise the normalized target
|
|
125
|
+
* is returned unchanged. Relative inputs are compared lexically. The result is
|
|
126
|
+
* `.` when the paths are identical.
|
|
127
|
+
*/
|
|
128
|
+
export function relativePath(from, to) {
|
|
129
|
+
const source = normalizePath(from);
|
|
130
|
+
const target = normalizePath(to);
|
|
131
|
+
const sourceRoot = splitRoot(source);
|
|
132
|
+
const targetRoot = splitRoot(target);
|
|
133
|
+
if (!rootsMatch(sourceRoot.root, targetRoot.root)) {
|
|
134
|
+
return target;
|
|
135
|
+
}
|
|
136
|
+
const caseInsensitive = isDriveRoot(sourceRoot.root) && isDriveRoot(targetRoot.root);
|
|
137
|
+
const sourceSegments = sourceRoot.rest.split("/").filter((segment) => segment !== "");
|
|
138
|
+
const targetSegments = targetRoot.rest.split("/").filter((segment) => segment !== "");
|
|
139
|
+
let common = 0;
|
|
140
|
+
while (common < sourceSegments.length &&
|
|
141
|
+
common < targetSegments.length &&
|
|
142
|
+
segmentsEqual(sourceSegments[common] ?? "", targetSegments[common] ?? "", caseInsensitive)) {
|
|
143
|
+
common += 1;
|
|
144
|
+
}
|
|
145
|
+
if (sourceRoot.root === "" && common === 0)
|
|
146
|
+
return target;
|
|
147
|
+
const parts = [];
|
|
148
|
+
for (let index = common; index < sourceSegments.length; index += 1)
|
|
149
|
+
parts.push("..");
|
|
150
|
+
for (let index = common; index < targetSegments.length; index += 1) {
|
|
151
|
+
parts.push(targetSegments[index] ?? "");
|
|
152
|
+
}
|
|
153
|
+
return parts.length === 0 ? "." : parts.join("/");
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Whether `target` lies inside `root`, including the root itself.
|
|
157
|
+
*
|
|
158
|
+
* Comparison is lexical. Drive-letter roots and their segments are compared
|
|
159
|
+
* case-insensitively to match Windows expectations; POSIX paths stay
|
|
160
|
+
* case-sensitive. Symlink and full case policy belong to the injected host.
|
|
161
|
+
*/
|
|
162
|
+
export function isWithinPath(root, target) {
|
|
163
|
+
const base = normalizePath(root);
|
|
164
|
+
const candidate = normalizePath(target);
|
|
165
|
+
const baseRoot = splitRoot(base);
|
|
166
|
+
const candidateRoot = splitRoot(candidate);
|
|
167
|
+
if (!rootsMatch(baseRoot.root, candidateRoot.root))
|
|
168
|
+
return false;
|
|
169
|
+
const caseInsensitive = isDriveRoot(baseRoot.root) && isDriveRoot(candidateRoot.root);
|
|
170
|
+
const baseSegments = baseRoot.rest.split("/").filter((segment) => segment !== "");
|
|
171
|
+
const candidateSegments = candidateRoot.rest.split("/").filter((segment) => segment !== "");
|
|
172
|
+
if (baseSegments.length > candidateSegments.length)
|
|
173
|
+
return false;
|
|
174
|
+
return baseSegments.every((segment, index) => segmentsEqual(segment, candidateSegments[index] ?? "", caseInsensitive));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Whether a path is a safe, non-empty relative path that does not climb out of
|
|
178
|
+
* its base (`..`, `../x` and absolute paths are not safe).
|
|
179
|
+
*/
|
|
180
|
+
export function isSafeRelativePath(path) {
|
|
181
|
+
return (path !== "" && path !== "." && path !== ".." && !isAbsolutePath(path) && !path.startsWith("../"));
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=paths.js.map
|