@a16njs/engine 0.5.0 → 0.6.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/dist/index.d.ts +41 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -75
- package/dist/index.js.map +1 -1
- package/dist/plugin-discovery.d.ts +78 -0
- package/dist/plugin-discovery.d.ts.map +1 -0
- package/dist/plugin-discovery.js +203 -0
- package/dist/plugin-discovery.js.map +1 -0
- package/dist/plugin-loader.d.ts +96 -0
- package/dist/plugin-loader.d.ts.map +1 -0
- package/dist/plugin-loader.js +112 -0
- package/dist/plugin-loader.js.map +1 -0
- package/dist/plugin-registry.d.ts +94 -0
- package/dist/plugin-registry.d.ts.map +1 -0
- package/dist/plugin-registry.js +89 -0
- package/dist/plugin-registry.js.map +1 -0
- package/dist/transformation.d.ts +93 -0
- package/dist/transformation.d.ts.map +1 -0
- package/dist/transformation.js +56 -0
- package/dist/transformation.js.map +1 -0
- package/dist/workspace.d.ts +73 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +178 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
export { LocalWorkspace, toWorkspace } from '@a16njs/models';
|
|
3
|
+
/**
|
|
4
|
+
* Read-only wrapper around another workspace.
|
|
5
|
+
* Allows read operations but throws on any write operation.
|
|
6
|
+
* Useful for dry-run scenarios.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const ws = new LocalWorkspace('source', '/project');
|
|
11
|
+
* const readOnly = new ReadOnlyWorkspace(ws);
|
|
12
|
+
* await readOnly.read('file.md'); // works
|
|
13
|
+
* await readOnly.write('file.md', 'content'); // throws!
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export class ReadOnlyWorkspace {
|
|
17
|
+
underlying;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new ReadOnlyWorkspace wrapping another workspace.
|
|
20
|
+
* @param underlying - The workspace to wrap
|
|
21
|
+
*/
|
|
22
|
+
constructor(underlying) {
|
|
23
|
+
this.underlying = underlying;
|
|
24
|
+
}
|
|
25
|
+
get id() {
|
|
26
|
+
return this.underlying.id;
|
|
27
|
+
}
|
|
28
|
+
get root() {
|
|
29
|
+
return this.underlying.root;
|
|
30
|
+
}
|
|
31
|
+
resolve(relativePath) {
|
|
32
|
+
return this.underlying.resolve(relativePath);
|
|
33
|
+
}
|
|
34
|
+
exists(relativePath) {
|
|
35
|
+
return this.underlying.exists(relativePath);
|
|
36
|
+
}
|
|
37
|
+
read(relativePath) {
|
|
38
|
+
return this.underlying.read(relativePath);
|
|
39
|
+
}
|
|
40
|
+
async write(_relativePath, _content) {
|
|
41
|
+
throw new Error('Cannot write to read-only workspace');
|
|
42
|
+
}
|
|
43
|
+
readdir(relativePath) {
|
|
44
|
+
return this.underlying.readdir(relativePath);
|
|
45
|
+
}
|
|
46
|
+
async mkdir(_relativePath) {
|
|
47
|
+
throw new Error('Cannot mkdir in read-only workspace');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* In-memory workspace for testing.
|
|
52
|
+
* Stores files in a Map, no filesystem access.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const ws = new MemoryWorkspace('test');
|
|
57
|
+
* await ws.write('rules/my-rule.md', '# Rule');
|
|
58
|
+
* const content = await ws.read('rules/my-rule.md');
|
|
59
|
+
* const entries = await ws.readdir('rules');
|
|
60
|
+
* // entries: [{ name: 'my-rule.md', isFile: true, isDirectory: false }]
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export class MemoryWorkspace {
|
|
64
|
+
id;
|
|
65
|
+
root = '/memory';
|
|
66
|
+
files = new Map();
|
|
67
|
+
directories = new Set();
|
|
68
|
+
/**
|
|
69
|
+
* Create a new MemoryWorkspace.
|
|
70
|
+
* @param id - Unique identifier for this workspace
|
|
71
|
+
* @param initialFiles - Optional map of relative paths to file contents
|
|
72
|
+
*/
|
|
73
|
+
constructor(id, initialFiles) {
|
|
74
|
+
this.id = id;
|
|
75
|
+
if (initialFiles) {
|
|
76
|
+
for (const [filePath, content] of Object.entries(initialFiles)) {
|
|
77
|
+
this.files.set(this.normalizePath(filePath), content);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
resolve(relativePath) {
|
|
82
|
+
const normalized = this.normalizePath(relativePath);
|
|
83
|
+
if (normalized === '')
|
|
84
|
+
return this.root;
|
|
85
|
+
return this.root + '/' + normalized;
|
|
86
|
+
}
|
|
87
|
+
async exists(relativePath) {
|
|
88
|
+
const normalized = this.normalizePath(relativePath);
|
|
89
|
+
// Check if it's a file
|
|
90
|
+
if (this.files.has(normalized))
|
|
91
|
+
return true;
|
|
92
|
+
// Check if it's an explicit directory
|
|
93
|
+
if (this.directories.has(normalized))
|
|
94
|
+
return true;
|
|
95
|
+
// Check if it's an implicit directory (some file has this as a prefix)
|
|
96
|
+
if (normalized === '')
|
|
97
|
+
return true;
|
|
98
|
+
const prefix = normalized + '/';
|
|
99
|
+
for (const key of this.files.keys()) {
|
|
100
|
+
if (key.startsWith(prefix))
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
async read(relativePath) {
|
|
106
|
+
const normalized = this.normalizePath(relativePath);
|
|
107
|
+
const content = this.files.get(normalized);
|
|
108
|
+
if (content === undefined) {
|
|
109
|
+
throw new Error(`File not found: ${relativePath} in workspace ${this.id}`);
|
|
110
|
+
}
|
|
111
|
+
return content;
|
|
112
|
+
}
|
|
113
|
+
async write(relativePath, content) {
|
|
114
|
+
const normalized = this.normalizePath(relativePath);
|
|
115
|
+
this.files.set(normalized, content);
|
|
116
|
+
}
|
|
117
|
+
async readdir(relativePath) {
|
|
118
|
+
const normalized = this.normalizePath(relativePath);
|
|
119
|
+
// Check directory exists
|
|
120
|
+
if (!(await this.exists(normalized))) {
|
|
121
|
+
throw new Error(`Directory not found: ${relativePath} in workspace ${this.id}`);
|
|
122
|
+
}
|
|
123
|
+
const prefix = normalized === '' ? '' : normalized + '/';
|
|
124
|
+
const entries = new Map();
|
|
125
|
+
// Scan files for entries under this directory
|
|
126
|
+
for (const key of this.files.keys()) {
|
|
127
|
+
if (!key.startsWith(prefix))
|
|
128
|
+
continue;
|
|
129
|
+
const rest = key.slice(prefix.length);
|
|
130
|
+
const slashIndex = rest.indexOf('/');
|
|
131
|
+
if (slashIndex === -1) {
|
|
132
|
+
// Direct child file
|
|
133
|
+
entries.set(rest, { name: rest, isFile: true, isDirectory: false });
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
// Subdirectory (from file path)
|
|
137
|
+
const dirName = rest.slice(0, slashIndex);
|
|
138
|
+
if (!entries.has(dirName)) {
|
|
139
|
+
entries.set(dirName, { name: dirName, isFile: false, isDirectory: true });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Also scan explicit directories
|
|
144
|
+
for (const dir of this.directories) {
|
|
145
|
+
if (!dir.startsWith(prefix))
|
|
146
|
+
continue;
|
|
147
|
+
const rest = dir.slice(prefix.length);
|
|
148
|
+
if (rest === '')
|
|
149
|
+
continue;
|
|
150
|
+
const slashIndex = rest.indexOf('/');
|
|
151
|
+
const dirName = slashIndex === -1 ? rest : rest.slice(0, slashIndex);
|
|
152
|
+
if (!entries.has(dirName)) {
|
|
153
|
+
entries.set(dirName, { name: dirName, isFile: false, isDirectory: true });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return Array.from(entries.values());
|
|
157
|
+
}
|
|
158
|
+
async mkdir(relativePath) {
|
|
159
|
+
const normalized = this.normalizePath(relativePath);
|
|
160
|
+
if (normalized !== '') {
|
|
161
|
+
this.directories.add(normalized);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get all file paths stored in this workspace (for test assertions).
|
|
166
|
+
* @returns Array of normalized file paths
|
|
167
|
+
*/
|
|
168
|
+
getAllPaths() {
|
|
169
|
+
return Array.from(this.files.keys());
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Normalize a path to use forward slashes and strip leading slash.
|
|
173
|
+
*/
|
|
174
|
+
normalizePath(p) {
|
|
175
|
+
return p.split(path.sep).join('/').replace(/^\//, '');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.js","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAK7B,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7D;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,iBAAiB;IAKC;IAJ7B;;;OAGG;IACH,YAA6B,UAAqB;QAArB,eAAU,GAAV,UAAU,CAAW;IAAG,CAAC;IAEtD,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;IAC5B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,OAAO,CAAC,YAAoB;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,YAAoB;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,CAAC,YAAoB;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,aAAqB,EAAE,QAAgB;QACjD,MAAM,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
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Conversion engine for a16n",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"author": "Texarkanine",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"dist"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@a16njs/models": "0.
|
|
34
|
+
"@a16njs/models": "0.10.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "^20.0.0",
|
|
38
38
|
"typescript": "^5.4.0",
|
|
39
39
|
"vitest": "^2.0.0",
|
|
40
|
-
"@a16njs/plugin-cursor": "0.
|
|
41
|
-
"@a16njs/plugin-claude": "0.
|
|
40
|
+
"@a16njs/plugin-cursor": "0.10.1",
|
|
41
|
+
"@a16njs/plugin-claude": "0.10.1"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsc",
|