@rafters/veneer 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sean Silvius
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/bin.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/bin.mjs ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import { t as check } from "./check-DxTxqBre.mjs";
3
+ //#region src/bin.ts
4
+ const [root, ...rest] = process.argv.slice(2);
5
+ if (root?.startsWith("-") || rest.length > 0) {
6
+ process.stderr.write("usage: rafters-check [root]\n");
7
+ process.exitCode = 1;
8
+ } else {
9
+ const result = await check(root ?? process.cwd());
10
+ if (result.ok) {
11
+ process.stdout.write(result.report);
12
+ for (const { message } of result.notices) process.stderr.write(`${message}\n`);
13
+ process.exitCode = result.diagnostics.some(({ severity }) => severity === "error") ? 1 : 0;
14
+ } else {
15
+ for (const { message } of result.errors) process.stderr.write(`${message}\n`);
16
+ process.exitCode = 1;
17
+ }
18
+ }
19
+ //#endregion
20
+ export {};
@@ -0,0 +1,156 @@
1
+ import { a as ProjectError, i as resolveComponents, n as report, o as openProject, r as compareCodePoints, s as readConfig, t as lint } from "./lint-BabXVYQJ.mjs";
2
+ import path from "node:path";
3
+ import { mkdir, rename, rm, writeFile } from "node:fs/promises";
4
+ import { lstatSync } from "node:fs";
5
+ //#region src/docs.ts
6
+ function propLine(prop) {
7
+ return {
8
+ name: prop.name,
9
+ type: prop.type,
10
+ optional: prop.optional,
11
+ ...prop.default !== void 0 && { default: prop.default },
12
+ ...prop.values !== void 0 && { values: prop.values },
13
+ ...prop.doc !== void 0 && { doc: prop.doc },
14
+ file: prop.file,
15
+ line: prop.line,
16
+ column: prop.column
17
+ };
18
+ }
19
+ function componentLine(component) {
20
+ return {
21
+ kind: "component",
22
+ name: component.name,
23
+ file: component.file,
24
+ resolved: component.resolved,
25
+ ...component.reason !== void 0 && { reason: component.reason },
26
+ ...component.description !== void 0 && { description: component.description },
27
+ tags: component.tags,
28
+ props: component.props.map(propLine),
29
+ inherited: component.inherited,
30
+ inheritedDefaults: component.inheritedDefaults
31
+ };
32
+ }
33
+ function docsText(intent, components) {
34
+ return [{
35
+ kind: "project",
36
+ intent
37
+ }, ...components.map(componentLine)].map((line) => `${JSON.stringify(line)}\n`).join("");
38
+ }
39
+ async function writeWhole(docsPath, text) {
40
+ const temporary = `${docsPath}.tmp`;
41
+ await mkdir(path.dirname(docsPath), { recursive: true });
42
+ try {
43
+ await rm(temporary, { force: true });
44
+ await writeFile(temporary, text, { flag: "wx" });
45
+ await rename(temporary, docsPath);
46
+ } catch (error) {
47
+ await rm(temporary, { force: true });
48
+ throw error;
49
+ }
50
+ }
51
+ async function openOrError(root, unsaved) {
52
+ try {
53
+ return await openProject(root, { unsaved });
54
+ } catch (error) {
55
+ if (error instanceof ProjectError && error.code === "tsconfig-missing") return {
56
+ code: error.code,
57
+ message: error.message
58
+ };
59
+ throw error;
60
+ }
61
+ }
62
+ function outputSymlinkError(root) {
63
+ const symlink = [".rafters", ".rafters/veneer"].find((folder) => lstatSync(path.join(root, folder), { throwIfNoEntry: false })?.isSymbolicLink());
64
+ if (!symlink) return void 0;
65
+ return {
66
+ code: "output-symlink",
67
+ message: `${symlink} is a symbolic link; veneer writes only inside the project`
68
+ };
69
+ }
70
+ function sortedNotices(notices) {
71
+ return notices.toSorted((a, b) => compareCodePoints(a.code, b.code) || compareCodePoints(a.message, b.message));
72
+ }
73
+ async function writeDocsFrom(project, config) {
74
+ const { components, notices } = await resolveComponents(project, config.componentFolders);
75
+ const docsPath = path.join(project.root, ".rafters/veneer/docs.jsonl");
76
+ await writeWhole(docsPath, docsText(config.intent, components));
77
+ return {
78
+ docsPath,
79
+ notices: sortedNotices([...config.notices, ...notices])
80
+ };
81
+ }
82
+ async function writeDocs(projectRoot) {
83
+ const root = path.resolve(projectRoot);
84
+ const config = await readConfig(root);
85
+ if (!config.ok) return {
86
+ ok: false,
87
+ errors: config.errors
88
+ };
89
+ const symlink = outputSymlinkError(root);
90
+ if (symlink) return {
91
+ ok: false,
92
+ errors: [symlink]
93
+ };
94
+ const project = await openOrError(root);
95
+ if ("code" in project) return {
96
+ ok: false,
97
+ errors: [project]
98
+ };
99
+ try {
100
+ return {
101
+ ok: true,
102
+ ...await writeDocsFrom(project, config)
103
+ };
104
+ } finally {
105
+ project.close();
106
+ }
107
+ }
108
+ //#endregion
109
+ //#region src/check.ts
110
+ function outsideProgram(file) {
111
+ return {
112
+ code: "outside-program",
113
+ message: `${file} is not in the tsconfig's files, so it was not checked`
114
+ };
115
+ }
116
+ async function check(projectRoot, options = {}) {
117
+ const root = path.resolve(projectRoot);
118
+ const config = await readConfig(root);
119
+ if (!config.ok) return {
120
+ ok: false,
121
+ errors: config.errors
122
+ };
123
+ const unsaved = options.unsaved ?? {};
124
+ const unsavedFiles = Object.keys(unsaved);
125
+ const isSave = options.save === true && unsavedFiles.length === 0;
126
+ const symlink = isSave ? outputSymlinkError(root) : void 0;
127
+ if (symlink) return {
128
+ ok: false,
129
+ errors: [symlink]
130
+ };
131
+ const project = await openOrError(root, unsaved);
132
+ if ("code" in project) return {
133
+ ok: false,
134
+ errors: [project]
135
+ };
136
+ try {
137
+ const roots = project.checker.getRootFileNames();
138
+ const outside = unsavedFiles.filter((file) => !roots.includes(path.join(root, file)));
139
+ const asked = options.paths ?? (unsavedFiles.length > 0 ? unsavedFiles : void 0);
140
+ const diagnostics = await lint(project, {
141
+ componentFolders: config.componentFolders,
142
+ files: isSave ? void 0 : asked?.filter((file) => !outside.includes(file))
143
+ });
144
+ const written = isSave ? await writeDocsFrom(project, config) : void 0;
145
+ return {
146
+ ok: true,
147
+ diagnostics,
148
+ report: report(diagnostics),
149
+ ...written ?? { notices: sortedNotices([...config.notices, ...outside.map(outsideProgram)]) }
150
+ };
151
+ } finally {
152
+ project.close();
153
+ }
154
+ }
155
+ //#endregion
156
+ export { writeDocs as n, check as t };
@@ -0,0 +1,82 @@
1
+ import { AstroCheck, Diagnostic as Diagnostic$1 } from "@astrojs/language-server";
2
+ import * as TypeScript from "typescript";
3
+ //#region src/config.d.ts
4
+ interface Notice {
5
+ code: string;
6
+ message: string;
7
+ }
8
+ interface VeneerError {
9
+ code: string;
10
+ message: string;
11
+ field?: string;
12
+ value?: unknown;
13
+ }
14
+ //#endregion
15
+ //#region src/read.d.ts
16
+ export declare class ProjectError extends Error {
17
+ readonly code: "already-open" | "tsconfig-missing" | "bad-path" | "not-root-file" | "closed";
18
+ constructor(code: ProjectError["code"], message: string);
19
+ }
20
+ interface Diagnostic {
21
+ file: string;
22
+ line: number;
23
+ column: number;
24
+ endLine: number;
25
+ endColumn: number;
26
+ severity: "error" | "warning" | "info" | "hint";
27
+ code: string;
28
+ message: Diagnostic$1["message"];
29
+ }
30
+ interface Project {
31
+ readonly ts: typeof TypeScript;
32
+ readonly checker: AstroCheck["linter"];
33
+ readonly root: string;
34
+ program(): TypeScript.Program;
35
+ diagnostics(file: string): Promise<Diagnostic[]>;
36
+ setUnsaved(file: string, text: string): void;
37
+ clearUnsaved(file: string): void;
38
+ close(): void;
39
+ }
40
+ export declare function openProject(projectRoot: string, options?: {
41
+ unsaved?: Record<string, string>;
42
+ }): Promise<Project>;
43
+ //#endregion
44
+ //#region src/lint.d.ts
45
+ interface LintDiagnostic extends Diagnostic {
46
+ help?: string;
47
+ }
48
+ export declare function lint(project: Project, options: {
49
+ componentFolders: string[];
50
+ files?: string[];
51
+ }): Promise<LintDiagnostic[]>;
52
+ export declare function report(diagnostics: LintDiagnostic[]): string;
53
+ //#endregion
54
+ //#region src/check.d.ts
55
+ type CheckResult = {
56
+ ok: true;
57
+ diagnostics: LintDiagnostic[];
58
+ report: string;
59
+ notices: Notice[];
60
+ docsPath?: string;
61
+ } | {
62
+ ok: false;
63
+ errors: VeneerError[];
64
+ };
65
+ export declare function check(projectRoot: string, options?: {
66
+ save?: boolean;
67
+ paths?: string[];
68
+ unsaved?: Record<string, string>;
69
+ }): Promise<CheckResult>;
70
+ //#endregion
71
+ //#region src/docs.d.ts
72
+ type DocsResult = {
73
+ ok: true;
74
+ docsPath: string;
75
+ notices: Notice[];
76
+ } | {
77
+ ok: false;
78
+ errors: VeneerError[];
79
+ };
80
+ export declare function writeDocs(projectRoot: string): Promise<DocsResult>;
81
+ //#endregion
82
+ export type { CheckResult, Diagnostic, DocsResult, LintDiagnostic, Notice, Project, VeneerError };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { a as ProjectError, n as report, o as openProject, t as lint } from "./lint-BabXVYQJ.mjs";
2
+ import { n as writeDocs, t as check } from "./check-DxTxqBre.mjs";
3
+ export { ProjectError, check, lint, openProject, report, writeDocs };