@ultrst-armada/kloks 1.24.3 → 1.24.5
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/.krusbl-release-attestation.json +3 -3
- package/package.json +6 -2
- package/packages/backend/dist/development/client.js +240 -12
- package/packages/backend/dist/development/index.d.ts +139 -3
- package/packages/backend/dist/development/index.js +639 -30
- package/packages/backend/dist/index.d.ts +0 -4
- package/packages/backend/dist/index.js +0 -63
- package/packages/backend/package.json +1 -1
- package/packages/services/dist/index.js +8 -3
- package/packages/backend/dist/chunk-7K552XGT.js +0 -425
- package/packages/backend/dist/chunk-AGI3VKCZ.js +0 -253
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createService,
|
|
3
|
-
createServiceDefinition
|
|
4
|
-
} from "./chunk-MWSYNRNZ.js";
|
|
5
|
-
|
|
6
|
-
// src/development/webContainerService.ts
|
|
7
|
-
var COMMANDS = {
|
|
8
|
-
install: { command: "pnpm", args: ["install", "--no-frozen-lockfile"] },
|
|
9
|
-
lint: { command: "pnpm", args: ["lint"] },
|
|
10
|
-
test: { command: "pnpm", args: ["test"] },
|
|
11
|
-
build: { command: "pnpm", args: ["build"] },
|
|
12
|
-
validate: { command: "pnpm", args: ["validate"] },
|
|
13
|
-
check: { command: "pnpm", args: ["lint"] }
|
|
14
|
-
};
|
|
15
|
-
function parseDevelopmentDiagnostics(output, exitCode = 0) {
|
|
16
|
-
const diagnostics = [];
|
|
17
|
-
const seen = /* @__PURE__ */ new Set();
|
|
18
|
-
const add = (diagnostic) => {
|
|
19
|
-
const key = [diagnostic.source, diagnostic.code, diagnostic.file, diagnostic.line, diagnostic.message].join("|");
|
|
20
|
-
if (!seen.has(key)) {
|
|
21
|
-
seen.add(key);
|
|
22
|
-
diagnostics.push(diagnostic);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
for (const line of output.split(/\r?\n/)) {
|
|
26
|
-
const typescript = line.match(/^(.+?)\((\d+),(\d+)\):\s*(error|warning)\s+(TS\d+):\s*(.+)$/);
|
|
27
|
-
if (typescript) {
|
|
28
|
-
add({ source: "typescript", severity: typescript[4], file: typescript[1], line: Number(typescript[2]), column: Number(typescript[3]), code: typescript[5], message: typescript[6] });
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const eslint = line.match(/^(.+?):(\d+):(\d+)\s+(error|warning)\s+(.+?)\s+([^\s]+)$/);
|
|
32
|
-
if (eslint) {
|
|
33
|
-
add({ source: "eslint", severity: eslint[4], file: eslint[1], line: Number(eslint[2]), column: Number(eslint[3]), code: eslint[6], message: eslint[5] });
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
const bundler = line.match(/(?:✘|×|ERROR|error:|Error:)\s*(.+)$/);
|
|
37
|
-
if (bundler) add({ source: "bundler", severity: "error", message: bundler[1].trim() });
|
|
38
|
-
if (/\bWARN(?:ING)?\b/i.test(line)) add({ source: "package-manager", severity: "warning", message: line.trim() });
|
|
39
|
-
}
|
|
40
|
-
if (exitCode !== 0 && diagnostics.every((item) => item.severity !== "error")) {
|
|
41
|
-
add({ source: "unknown", severity: "error", message: "Command failed with exit code " + exitCode + "; inspect captured output for details." });
|
|
42
|
-
}
|
|
43
|
-
return diagnostics;
|
|
44
|
-
}
|
|
45
|
-
function captureDevelopmentProcess(process) {
|
|
46
|
-
const [consumerOutput, diagnosticOutput] = process.output.tee();
|
|
47
|
-
const logs = (async () => {
|
|
48
|
-
const reader = diagnosticOutput.getReader();
|
|
49
|
-
let output = "";
|
|
50
|
-
try {
|
|
51
|
-
while (true) {
|
|
52
|
-
const next = await reader.read();
|
|
53
|
-
if (next.done) break;
|
|
54
|
-
output += next.value;
|
|
55
|
-
}
|
|
56
|
-
} finally {
|
|
57
|
-
reader.releaseLock();
|
|
58
|
-
}
|
|
59
|
-
const exitCode = await process.exit;
|
|
60
|
-
return { output, exitCode, diagnostics: parseDevelopmentDiagnostics(output, exitCode) };
|
|
61
|
-
})();
|
|
62
|
-
return { ...process, output: consumerOutput, logs };
|
|
63
|
-
}
|
|
64
|
-
function resolveWebContainerCommand(task) {
|
|
65
|
-
const command = COMMANDS[task];
|
|
66
|
-
return { command: command.command, args: [...command.args] };
|
|
67
|
-
}
|
|
68
|
-
var runQueue = Promise.resolve();
|
|
69
|
-
var sharedContainer = null;
|
|
70
|
-
var sharedContainerPromise = null;
|
|
71
|
-
var WebContainerRuntime = class {
|
|
72
|
-
async boot() {
|
|
73
|
-
if (typeof window !== "undefined" && !window.crossOriginIsolated) {
|
|
74
|
-
throw new Error("WebContainer requires a cross-origin-isolated page. Ensure COOP=same-origin and COEP=require-corp are served.");
|
|
75
|
-
}
|
|
76
|
-
if (sharedContainer) return sharedContainer;
|
|
77
|
-
if (!sharedContainerPromise) {
|
|
78
|
-
sharedContainerPromise = import("@webcontainer/api").then(async (module) => {
|
|
79
|
-
const container = await module.WebContainer.boot({
|
|
80
|
-
coep: "require-corp",
|
|
81
|
-
workdirName: "kloks-development"
|
|
82
|
-
});
|
|
83
|
-
sharedContainer = container;
|
|
84
|
-
return container;
|
|
85
|
-
}).catch((error) => {
|
|
86
|
-
sharedContainerPromise = null;
|
|
87
|
-
throw error;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return sharedContainerPromise;
|
|
91
|
-
}
|
|
92
|
-
async mount(files, mountPoint) {
|
|
93
|
-
const container = await this.boot();
|
|
94
|
-
await container.mount(files, mountPoint ? { mountPoint } : void 0);
|
|
95
|
-
return { mounted: true, mountPoint: mountPoint ?? "/" };
|
|
96
|
-
}
|
|
97
|
-
async runProcess(command, args, cwd, env) {
|
|
98
|
-
const container = await this.boot();
|
|
99
|
-
const process = await container.spawn(command, args, { cwd, env });
|
|
100
|
-
const started = Date.now();
|
|
101
|
-
let output = "";
|
|
102
|
-
const reader = process.output.getReader();
|
|
103
|
-
try {
|
|
104
|
-
while (true) {
|
|
105
|
-
const next = await reader.read();
|
|
106
|
-
if (next.done) break;
|
|
107
|
-
output += next.value;
|
|
108
|
-
}
|
|
109
|
-
} finally {
|
|
110
|
-
reader.releaseLock();
|
|
111
|
-
}
|
|
112
|
-
const exitCode = await process.exit;
|
|
113
|
-
return { exitCode, output, command: [command, ...args].join(" "), durationMs: Date.now() - started, diagnostics: parseDevelopmentDiagnostics(output, exitCode) };
|
|
114
|
-
}
|
|
115
|
-
async run(task, cwd, env) {
|
|
116
|
-
const spec = resolveWebContainerCommand(task);
|
|
117
|
-
return this.runCommand(spec.command, spec.args, cwd, env);
|
|
118
|
-
}
|
|
119
|
-
async runCommand(command, args = [], cwd, env) {
|
|
120
|
-
const previous = runQueue;
|
|
121
|
-
let release;
|
|
122
|
-
runQueue = new Promise((resolve) => {
|
|
123
|
-
release = resolve;
|
|
124
|
-
});
|
|
125
|
-
await previous;
|
|
126
|
-
try {
|
|
127
|
-
return await this.runProcess(command, args, cwd, env);
|
|
128
|
-
} finally {
|
|
129
|
-
release();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async spawnCommand(command, args = [], cwd, env) {
|
|
133
|
-
const container = await this.boot();
|
|
134
|
-
const process = await container.spawn(command, args, { cwd, env });
|
|
135
|
-
return captureDevelopmentProcess(process);
|
|
136
|
-
}
|
|
137
|
-
async teardown() {
|
|
138
|
-
const container = sharedContainer;
|
|
139
|
-
sharedContainer = null;
|
|
140
|
-
sharedContainerPromise = null;
|
|
141
|
-
await container?.teardown();
|
|
142
|
-
return { tornDown: true };
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
var runtime = new WebContainerRuntime();
|
|
146
|
-
var WebContainerServiceDefinition = createServiceDefinition({
|
|
147
|
-
id: "kloks.backend.webContainer",
|
|
148
|
-
name: "WebContainerService",
|
|
149
|
-
version: "1.2.0",
|
|
150
|
-
operations: {
|
|
151
|
-
boot: { id: "WebContainerService.boot", name: "boot", handler: async () => {
|
|
152
|
-
await runtime.boot();
|
|
153
|
-
return { ready: true };
|
|
154
|
-
} },
|
|
155
|
-
mount: { id: "WebContainerService.mount", name: "mount", handler: async (input) => runtime.mount(input.files, input.mountPoint) },
|
|
156
|
-
run: { id: "WebContainerService.run", name: "run", handler: async (input) => runtime.run(input.task, input.cwd, input.env) },
|
|
157
|
-
runCommand: { id: "WebContainerService.runCommand", name: "runCommand", handler: async (input) => runtime.runCommand(input.command, input.args, input.cwd, input.env) },
|
|
158
|
-
teardown: { id: "WebContainerService.teardown", name: "teardown", handler: async () => runtime.teardown() },
|
|
159
|
-
command: { id: "WebContainerService.command", name: "command", handler: async (input) => ({ task: input.task, command: resolveWebContainerCommand(input.task) }) }
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
var WebContainerServiceFacade = {
|
|
163
|
-
id: WebContainerServiceDefinition.id,
|
|
164
|
-
name: WebContainerServiceDefinition.name,
|
|
165
|
-
version: WebContainerServiceDefinition.version,
|
|
166
|
-
runtime: "client",
|
|
167
|
-
deployment: "local",
|
|
168
|
-
definition: WebContainerServiceDefinition,
|
|
169
|
-
createInstance: () => createService(WebContainerServiceDefinition),
|
|
170
|
-
execute: async (op, input) => {
|
|
171
|
-
const instance = createService(WebContainerServiceDefinition);
|
|
172
|
-
await instance.start();
|
|
173
|
-
return instance.call(op, input);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// src/development/codeValidationService.ts
|
|
178
|
-
var COMMANDS2 = {
|
|
179
|
-
syntax: { command: "pnpm", args: ["exec", "tsc", "--noEmit"] },
|
|
180
|
-
lint: { command: "pnpm", args: ["run", "lint", "--if-present"] },
|
|
181
|
-
test: { command: "pnpm", args: ["run", "test", "--if-present"] },
|
|
182
|
-
build: { command: "pnpm", args: ["run", "build", "--if-present"] },
|
|
183
|
-
krnl: { command: "pnpm", args: ["exec", "krnl", "validate"] },
|
|
184
|
-
frnl: { command: "pnpm", args: ["exec", "frnl", "validate"] },
|
|
185
|
-
"lockfile-check": { command: "pnpm", args: ["install", "--frozen-lockfile", "--ignore-scripts"] }
|
|
186
|
-
};
|
|
187
|
-
var DEFAULT_LAYERS = ["lockfile-check", "syntax", "lint", "krnl", "frnl"];
|
|
188
|
-
var commandText = (command, args) => [command, ...args].join(" ");
|
|
189
|
-
var CodeValidationRuntime = class {
|
|
190
|
-
constructor(runtime3 = new WebContainerRuntime()) {
|
|
191
|
-
this.runtime = runtime3;
|
|
192
|
-
}
|
|
193
|
-
runtime;
|
|
194
|
-
async validate(input = {}) {
|
|
195
|
-
if (input.files) await this.runtime.mount(input.files);
|
|
196
|
-
const diagnostics = [];
|
|
197
|
-
if (input.install) {
|
|
198
|
-
const installed = await this.runtime.runCommand("pnpm", ["install", "--frozen-lockfile", "--ignore-scripts"], input.cwd, input.env);
|
|
199
|
-
diagnostics.push({ layer: "lockfile-check", ok: installed.exitCode === 0, exitCode: installed.exitCode, output: installed.output, command: "pnpm install --frozen-lockfile --ignore-scripts" });
|
|
200
|
-
if (installed.exitCode !== 0) return { ok: false, diagnostics, failedLayers: ["lockfile-check"] };
|
|
201
|
-
}
|
|
202
|
-
const layers = input.layers?.length ? input.layers : DEFAULT_LAYERS;
|
|
203
|
-
for (const layer of layers) {
|
|
204
|
-
if (layer === "law-l9") {
|
|
205
|
-
diagnostics.push(await this.validateLawL9(input.cwd, input.maxLines ?? 200));
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
const spec = COMMANDS2[layer];
|
|
209
|
-
const result = await this.runtime.runCommand(spec.command, spec.args, input.cwd, input.env);
|
|
210
|
-
diagnostics.push({ layer, ok: result.exitCode === 0, exitCode: result.exitCode, output: result.output, command: commandText(spec.command, spec.args) });
|
|
211
|
-
if (result.exitCode !== 0) break;
|
|
212
|
-
}
|
|
213
|
-
return { ok: diagnostics.every((item) => item.ok), diagnostics, failedLayers: diagnostics.filter((item) => !item.ok).map((item) => item.layer) };
|
|
214
|
-
}
|
|
215
|
-
async validateLawL9(cwd = ".", maxLines = 200) {
|
|
216
|
-
const script = `python3 -c 'import os,sys; bad=[]; root="src"; [bad.append(os.path.join(r,f)+": "+str(len(open(os.path.join(r,f),encoding="utf-8",errors="ignore").readlines()))+" lines") for r,_,fs in os.walk(root) for f in fs if f.endswith((".ts",".tsx",".js",".jsx")) and not f.endswith(".d.ts") and len(open(os.path.join(r,f),encoding="utf-8",errors="ignore").readlines())>200]; print("\\n".join(bad)); sys.exit(1 if bad else 0)'`;
|
|
217
|
-
const result = await this.runtime.runCommand("sh", ["-lc", script], cwd);
|
|
218
|
-
return { layer: "law-l9", ok: result.exitCode === 0, exitCode: result.exitCode, output: result.output, command: script };
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
var runtime2 = new CodeValidationRuntime();
|
|
222
|
-
var CodeValidationServiceDefinition = createServiceDefinition({
|
|
223
|
-
id: "kloks.backend.codeValidation",
|
|
224
|
-
name: "CodeValidationService",
|
|
225
|
-
version: "1.1.0",
|
|
226
|
-
operations: { validate: { id: "CodeValidationService.validate", name: "validate", handler: async (input) => runtime2.validate(input) } }
|
|
227
|
-
});
|
|
228
|
-
var CodeValidationServiceFacade = {
|
|
229
|
-
id: CodeValidationServiceDefinition.id,
|
|
230
|
-
name: CodeValidationServiceDefinition.name,
|
|
231
|
-
version: CodeValidationServiceDefinition.version,
|
|
232
|
-
runtime: "client",
|
|
233
|
-
deployment: "local",
|
|
234
|
-
definition: CodeValidationServiceDefinition,
|
|
235
|
-
createInstance: () => createService(CodeValidationServiceDefinition),
|
|
236
|
-
execute: async (op, input) => {
|
|
237
|
-
const instance = createService(CodeValidationServiceDefinition);
|
|
238
|
-
await instance.start();
|
|
239
|
-
return instance.call(op, input);
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
export {
|
|
244
|
-
parseDevelopmentDiagnostics,
|
|
245
|
-
captureDevelopmentProcess,
|
|
246
|
-
resolveWebContainerCommand,
|
|
247
|
-
WebContainerRuntime,
|
|
248
|
-
WebContainerServiceDefinition,
|
|
249
|
-
WebContainerServiceFacade,
|
|
250
|
-
CodeValidationRuntime,
|
|
251
|
-
CodeValidationServiceDefinition,
|
|
252
|
-
CodeValidationServiceFacade
|
|
253
|
-
};
|