@r_masseater/vite-plus-adopt 0.14.0 → 0.16.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/README.md +42 -3
- package/dist/attw.mjs +135 -157
- package/dist/attw.mjs.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +11 -1
- package/dist/index.mjs +1 -1
- package/dist/{vpa-jp87uBqF.mjs → vpa-Br-ls0AQ.mjs} +452 -124
- package/dist/vpa-Br-ls0AQ.mjs.map +1 -0
- package/package.json +3 -4
- package/skills/configure-checks/SKILL.md +0 -1
- package/dist/vpa-jp87uBqF.mjs.map +0 -1
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { n as toJson } from "./json-QtVKpodH.mjs";
|
|
2
|
-
import { Array, Boolean as Boolean$1, Config, Context, Effect, Exit, FileSystem, Function, Layer, Option, Order, Path, Predicate, Record, Redacted, Schedule, Schema, Stdio, Stream, String as String$1, pipe } from "effect";
|
|
2
|
+
import { Array, Boolean as Boolean$1, Config, Context, Effect, Exit, FileSystem, Function, Layer, Match, Option, Order, Path, Predicate, Record, Redacted, Schedule, Schema, Stdio, Stream, String as String$1, pipe } from "effect";
|
|
3
3
|
import { resolveConfigFromFile } from "vite-plus";
|
|
4
|
-
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
5
4
|
import format from "@commitlint/format";
|
|
6
5
|
import lint from "@commitlint/lint";
|
|
7
6
|
import load from "@commitlint/load";
|
|
8
7
|
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
8
|
+
import { createLinter, loadLinterFormatter } from "textlint";
|
|
9
9
|
import { loadPackagesFromRawConfig } from "@textlint/config-loader";
|
|
10
10
|
import { TextlintKernelDescriptor } from "@textlint/kernel";
|
|
11
|
-
import { createLinter, loadLinterFormatter } from "textlint";
|
|
12
11
|
import { loadBuiltinPlugins } from "textlint/lib/src/loader/TextlintrcLoader.js";
|
|
13
12
|
import { normalizeTextlintPresetSubRuleKey } from "@textlint/utils";
|
|
13
|
+
import { format as format$1, makeDetector } from "@r_masseater/h56m";
|
|
14
|
+
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
14
15
|
import { minimatch } from "minimatch";
|
|
15
16
|
import { parse } from "yaml";
|
|
16
17
|
import { Tar } from "effect/encoding";
|
|
17
|
-
import { format as format$1, makeDetector } from "@r_masseater/h56m";
|
|
18
18
|
import { findWorkspaceProjectsNoCheck } from "@pnpm/workspace.projects-reader";
|
|
19
19
|
import { readWorkspaceManifest } from "@pnpm/workspace.workspace-manifest-reader";
|
|
20
20
|
import { intersects, valid, validRange } from "semver";
|
|
@@ -97,9 +97,9 @@ const withSection = Function.dual(2, (key, run) => (context) => pipe(Option.from
|
|
|
97
97
|
onSome: (section) => Effect.asSome(run(section, context))
|
|
98
98
|
})));
|
|
99
99
|
// src/shared/lib/git.ts
|
|
100
|
-
const DATA_FIRST_ARITY$
|
|
100
|
+
const DATA_FIRST_ARITY$7 = 2;
|
|
101
101
|
/** @internal */
|
|
102
|
-
const listGitFiles = Function.dual(DATA_FIRST_ARITY$
|
|
102
|
+
const listGitFiles = Function.dual(DATA_FIRST_ARITY$7, (root, pathspecs) => Effect.gen(function* list() {
|
|
103
103
|
const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
|
|
104
104
|
"-c",
|
|
105
105
|
"core.quotePath=false",
|
|
@@ -113,7 +113,7 @@ const listGitFiles = Function.dual(DATA_FIRST_ARITY$4, (root, pathspecs) => Effe
|
|
|
113
113
|
return pipe(String$1.split(output, "\0"), Array.filter(String$1.isNonEmpty));
|
|
114
114
|
}));
|
|
115
115
|
/** @internal */
|
|
116
|
-
const listCommitMessages = Function.dual(DATA_FIRST_ARITY$
|
|
116
|
+
const listCommitMessages = Function.dual(DATA_FIRST_ARITY$7, (root, range) => Effect.gen(function* messages() {
|
|
117
117
|
const output = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).string(ChildProcess.make("git", [
|
|
118
118
|
"log",
|
|
119
119
|
"-z",
|
|
@@ -143,44 +143,136 @@ const presetRulesOf = (config) => {
|
|
|
143
143
|
}));
|
|
144
144
|
};
|
|
145
145
|
/** @internal */
|
|
146
|
+
const filterRulesOf = ({ config, wrap }) => {
|
|
147
|
+
const settings = config.filters ?? {};
|
|
148
|
+
return pipe(Record.toEntries(config.filterModules ?? {}), Array.filter(([name]) => Boolean(settings[name])), Array.map(([name, rule]) => ({
|
|
149
|
+
ruleId: name,
|
|
150
|
+
rule: wrap(rule),
|
|
151
|
+
options: pipe(Record.get(settings, name), Option.filter(isRuleOptions), Option.getOrElse(() => true))
|
|
152
|
+
})));
|
|
153
|
+
};
|
|
154
|
+
/** @internal */
|
|
146
155
|
const rawConfigOf = (config) => {
|
|
147
|
-
const { ignores: _ignores, presets = {}, sources: _sources, ...rawConfig } = config;
|
|
156
|
+
const { ignores: _ignores, presets = {}, filterModules = {}, reportUnusedDirectives: _report, sources: _sources, ...rawConfig } = config;
|
|
148
157
|
return {
|
|
149
158
|
...rawConfig,
|
|
150
|
-
rules: pipe(rawConfig.rules ?? {}, Record.filter((_setting, name) => !Record.has(presets, name)))
|
|
159
|
+
rules: pipe(rawConfig.rules ?? {}, Record.filter((_setting, name) => !Record.has(presets, name))),
|
|
160
|
+
filters: pipe(rawConfig.filters ?? {}, Record.filter((_setting, name) => !Record.has(filterModules, name)))
|
|
151
161
|
};
|
|
152
162
|
};
|
|
153
|
-
// src/features/check-text/model/textlint.ts
|
|
154
|
-
|
|
155
|
-
const descriptorOf = (
|
|
156
|
-
|
|
163
|
+
// src/features/check-text/model/textlint-descriptor.ts
|
|
164
|
+
/** @internal */
|
|
165
|
+
const descriptorOf = ({ root, config, wrap }) => Effect.gen(function* descriptor() {
|
|
166
|
+
const path = yield* Path.Path;
|
|
167
|
+
const loaded = yield* attempt("textlint")(() => loadPackagesFromRawConfig({
|
|
168
|
+
rawConfig: rawConfigOf(config),
|
|
169
|
+
node_moduleDir: path.join(root, "node_modules")
|
|
170
|
+
}));
|
|
171
|
+
if (!loaded.ok) return yield* toolFailed("textlint")(loaded.error.message);
|
|
157
172
|
const { rules, filterRules, plugins } = loaded.config;
|
|
158
|
-
|
|
173
|
+
const builtIn = yield* attempt("textlint")(loadBuiltinPlugins);
|
|
174
|
+
return new TextlintKernelDescriptor({
|
|
159
175
|
rules: [...rules, ...presetRulesOf(config)],
|
|
160
|
-
filterRules,
|
|
176
|
+
filterRules: [...filterRules, ...filterRulesOf({
|
|
177
|
+
config,
|
|
178
|
+
wrap
|
|
179
|
+
})],
|
|
161
180
|
plugins: [...builtIn.plugin.toKernelPluginsFormat(), ...plugins],
|
|
162
181
|
configBaseDir: root
|
|
163
|
-
})
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
// src/features/check-text/model/unused-directives.ts
|
|
185
|
+
const WILDCARD = "*";
|
|
186
|
+
const FIRST = 1;
|
|
187
|
+
const START$2 = 0;
|
|
188
|
+
const positionOf = (text, index) => {
|
|
189
|
+
const before = pipe(text, String$1.slice(START$2, index), String$1.split("\n"));
|
|
190
|
+
return {
|
|
191
|
+
line: before.length,
|
|
192
|
+
column: pipe(Array.last(before), Option.getOrElse(() => ""), String$1.length) + FIRST
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
const ruleIdOf = (optional) => Match.value(optional["ruleId"]).pipe(Match.when(Match.string, (ruleId) => ruleId), Match.orElse(() => WILDCARD));
|
|
196
|
+
const delegating = (context, shouldIgnore) => ({
|
|
197
|
+
id: context.id,
|
|
198
|
+
Syntax: context.Syntax,
|
|
199
|
+
severity: context.severity,
|
|
200
|
+
RuleError: context.RuleError,
|
|
201
|
+
locator: context.locator,
|
|
202
|
+
getFilePath: () => context.getFilePath(),
|
|
203
|
+
getSource: (...args) => context.getSource(...args),
|
|
204
|
+
getConfigBaseDir: () => context.getConfigBaseDir(),
|
|
205
|
+
shouldIgnore
|
|
206
|
+
});
|
|
207
|
+
const recording = () => {
|
|
208
|
+
const found = [];
|
|
209
|
+
return {
|
|
210
|
+
wrap: (reporter) => (context, options) => reporter(delegating(context, (range, optional) => {
|
|
211
|
+
const file = pipe(Option.fromNullishOr(context.getFilePath()), Option.getOrElse(() => ""));
|
|
212
|
+
found.push({
|
|
213
|
+
file,
|
|
214
|
+
range,
|
|
215
|
+
ruleId: ruleIdOf(optional),
|
|
216
|
+
...positionOf(context.getSource(), range[START$2])
|
|
217
|
+
});
|
|
218
|
+
context.shouldIgnore(range, optional);
|
|
219
|
+
}), options),
|
|
220
|
+
ignored: () => found
|
|
221
|
+
};
|
|
164
222
|
};
|
|
223
|
+
const suppresses = (ignored, message) => {
|
|
224
|
+
const [start, end] = ignored.range;
|
|
225
|
+
const [from, to] = message.range;
|
|
226
|
+
return start <= from && to <= end && (ignored.ruleId === WILDCARD || ignored.ruleId === message.ruleId);
|
|
227
|
+
};
|
|
228
|
+
const unusedMessage = (ignored) => Match.value(ignored.ruleId).pipe(Match.when(WILDCARD, () => "This textlint-disable comment hides no message."), Match.orElse((ruleId) => `This textlint-disable comment hides no message of ${ruleId}.`));
|
|
229
|
+
const unusedIn = ({ unfiltered, ignored }) => pipe(ignored, Array.filter((entry) => !pipe(unfiltered, Array.filter((result) => result.filePath === entry.file), Array.flatMap((result) => result.messages), Array.some((message) => suppresses(entry, message)))), Array.map(({ file, line, column, ...entry }) => ({
|
|
230
|
+
file,
|
|
231
|
+
line,
|
|
232
|
+
column,
|
|
233
|
+
message: unusedMessage({
|
|
234
|
+
file,
|
|
235
|
+
line,
|
|
236
|
+
column,
|
|
237
|
+
...entry
|
|
238
|
+
})
|
|
239
|
+
})));
|
|
240
|
+
const filesWithDirectives = (ignored) => pipe(ignored, Array.map(({ file }) => file), Array.dedupe);
|
|
241
|
+
const formatUnused = (unused) => pipe(unused, Array.map(({ file, line, column, message }) => `${file}\n ${String(line)}:${String(column)} error ${message} unused-directive`), Array.join("\n\n"));
|
|
242
|
+
// src/features/check-text/model/textlint.ts
|
|
243
|
+
const DATA_FIRST_ARITY_3 = 3;
|
|
244
|
+
const unusedOf = (config, descriptor, recorder) => {
|
|
245
|
+
const ignored = recorder.ignored();
|
|
246
|
+
if (config.reportUnusedDirectives !== true || Array.isReadonlyArrayEmpty(ignored)) return Effect.succeed([]);
|
|
247
|
+
const bare = descriptor.shallowMerge({ filterRules: [] });
|
|
248
|
+
return attempt("textlint")(() => createLinter({ descriptor: bare }).lintFiles([...filesWithDirectives(ignored)])).pipe(Effect.map((unfiltered) => unusedIn({
|
|
249
|
+
unfiltered,
|
|
250
|
+
ignored
|
|
251
|
+
})));
|
|
252
|
+
};
|
|
253
|
+
const wrapperOf = (config, recorder) => pipe(Option.liftPredicate(recorder.wrap, () => config.reportUnusedDirectives === true), Option.getOrElse(() => Function.identity));
|
|
254
|
+
const reportOf = (formatted, results, unused) => ({
|
|
255
|
+
valid: Array.isReadonlyArrayEmpty(unused) && pipe(results, Array.every((result) => Array.isArrayEmpty(result.messages))),
|
|
256
|
+
output: pipe([formatted, formatUnused(unused)], Array.filter(String$1.isNonEmpty), Array.join("\n"))
|
|
257
|
+
});
|
|
165
258
|
/** @internal */
|
|
166
259
|
const lintTexts = Function.dual(DATA_FIRST_ARITY_3, (config, root, files) => Effect.gen(function* lint() {
|
|
167
260
|
const path = yield* Path.Path;
|
|
168
261
|
yield* attempt("textlint")(() => import("vite-plus/register"));
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
262
|
+
const recorder = recording();
|
|
263
|
+
const descriptor = yield* descriptorOf({
|
|
264
|
+
root,
|
|
265
|
+
config,
|
|
266
|
+
wrap: wrapperOf(config, recorder)
|
|
267
|
+
});
|
|
174
268
|
const absolute = pipe(files, Array.map((file) => path.join(root, file)));
|
|
175
269
|
const results = yield* attempt("textlint")(() => createLinter({ descriptor }).lintFiles([...absolute]));
|
|
270
|
+
const unused = yield* unusedOf(config, descriptor, recorder);
|
|
176
271
|
const formatter = yield* attempt("textlint")(() => loadLinterFormatter({
|
|
177
272
|
formatterName: "stylish",
|
|
178
273
|
color: false
|
|
179
274
|
}));
|
|
180
|
-
return
|
|
181
|
-
valid: pipe(results, Array.every((result) => Array.isArrayEmpty(result.messages))),
|
|
182
|
-
output: formatter.format(results)
|
|
183
|
-
};
|
|
275
|
+
return reportOf(formatter.format(results), results, unused);
|
|
184
276
|
}));
|
|
185
277
|
// src/features/check-text/model/text-checks.ts
|
|
186
278
|
const MARKDOWN = "*.md";
|
|
@@ -194,15 +286,81 @@ const mergeReports = (reports) => ({
|
|
|
194
286
|
/** @internal */
|
|
195
287
|
const textlintCheck = withSection("textlint", (config, { root }) => {
|
|
196
288
|
const markdown = markdownFiles(root, config.ignores).pipe(Effect.flatMap((files) => lintTexts(config, root, files)));
|
|
197
|
-
const presets =
|
|
289
|
+
const { presets = {}, filterModules = {}, reportUnusedDirectives = false } = config;
|
|
198
290
|
const sources = pipe(config.sources ?? [], Array.map(({ files, ...source }) => Effect.flatMap(sourceFiles(root, files), (listed) => lintTexts({
|
|
199
291
|
...source,
|
|
200
|
-
presets
|
|
292
|
+
presets,
|
|
293
|
+
filterModules,
|
|
294
|
+
reportUnusedDirectives
|
|
201
295
|
}, root, listed))));
|
|
202
296
|
return Effect.all([markdown, ...sources], { concurrency: 1 }).pipe(Effect.map(mergeReports));
|
|
203
297
|
});
|
|
204
298
|
/** @internal */
|
|
205
299
|
const commitlintCheck = withSection("commitlint", (config, { root, range }) => listCommitMessages(root, range).pipe(Effect.flatMap((messages) => lintCommitMessages(config, root, messages))));
|
|
300
|
+
// src/features/scan-secrets/model/secret-checks.ts
|
|
301
|
+
const DATA_FIRST_ARITY$6 = 2;
|
|
302
|
+
const SUCCESS$1 = 0;
|
|
303
|
+
const RANGE = "..";
|
|
304
|
+
const HEAD = "HEAD";
|
|
305
|
+
const lacksHistory = (root) => Effect.gen(function* history() {
|
|
306
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
307
|
+
const shallow = yield* spawner.string(ChildProcess.make("git", ["rev-parse", "--is-shallow-repository"], { cwd: root }));
|
|
308
|
+
const promisor = yield* spawner.exitCode(ChildProcess.make("git", [
|
|
309
|
+
"config",
|
|
310
|
+
"--get",
|
|
311
|
+
"remote.origin.promisor"
|
|
312
|
+
], { cwd: root }));
|
|
313
|
+
return String$1.trim(shallow) === "true" || promisor === SUCCESS$1;
|
|
314
|
+
});
|
|
315
|
+
const historyOf = (range) => pipe(String$1.split(range, RANGE), Array.match({
|
|
316
|
+
onEmpty: () => ({
|
|
317
|
+
type: "history",
|
|
318
|
+
head: HEAD
|
|
319
|
+
}),
|
|
320
|
+
onNonEmpty: ([base, ...rest]) => Array.match(rest, {
|
|
321
|
+
onEmpty: () => ({
|
|
322
|
+
type: "history",
|
|
323
|
+
head: range
|
|
324
|
+
}),
|
|
325
|
+
onNonEmpty: ([head]) => ({
|
|
326
|
+
type: "history",
|
|
327
|
+
bases: [base],
|
|
328
|
+
head
|
|
329
|
+
})
|
|
330
|
+
})
|
|
331
|
+
}));
|
|
332
|
+
const sourceOf = (partial, range) => Boolean$1.match(partial, {
|
|
333
|
+
onTrue: () => ({
|
|
334
|
+
type: "snapshot",
|
|
335
|
+
revision: HEAD
|
|
336
|
+
}),
|
|
337
|
+
onFalse: () => historyOf(range)
|
|
338
|
+
});
|
|
339
|
+
const scan = (config, root, source) => Effect.gen(function* scanSource() {
|
|
340
|
+
const found = yield* (yield* makeDetector(config)).scanGit({
|
|
341
|
+
root,
|
|
342
|
+
source
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
valid: Array.isReadonlyArrayEmpty(found),
|
|
346
|
+
output: pipe(found, Array.map(format$1), Array.join("\n"))
|
|
347
|
+
};
|
|
348
|
+
}).pipe(Effect.mapError(toolFailed("h56m")));
|
|
349
|
+
/** @internal */
|
|
350
|
+
const h56mCheck = withSection("h56m", (config, { root, range }) => lacksHistory(root).pipe(Effect.flatMap((partial) => scan(config, root, sourceOf(partial, range)))));
|
|
351
|
+
/** @internal */
|
|
352
|
+
const scanStagedSecrets = Function.dual(DATA_FIRST_ARITY$6, (config, root) => scan(config, root, { type: "staged" }));
|
|
353
|
+
/** @internal */
|
|
354
|
+
const writeTo = Function.dual(2, (sink, text) => Effect.gen(function* write() {
|
|
355
|
+
const stdio = yield* Stdio.Stdio;
|
|
356
|
+
yield* Stream.make(text).pipe(Stream.run(stdio[sink]()), Effect.orDie);
|
|
357
|
+
}));
|
|
358
|
+
/** @internal */
|
|
359
|
+
const finish = (report) => {
|
|
360
|
+
if (!report.valid) return Effect.fail(checksFailed(report.output));
|
|
361
|
+
if (report.output === "") return Effect.void;
|
|
362
|
+
return writeTo("stdout", `${report.output}\n`);
|
|
363
|
+
};
|
|
206
364
|
// src/shared/config/skills.ts
|
|
207
365
|
const Repository = Schema.String.check(Schema.isPattern(/^[\w-][\w.-]*\/[\w.-]+$/u));
|
|
208
366
|
const LocalDirectory = Schema.String.check(Schema.isPattern(/^\.\/[\w.-]+(?:\/[\w.-]+)*$/u));
|
|
@@ -216,9 +374,22 @@ const RemoteSkillSourceSchema = Schema.Struct({
|
|
|
216
374
|
});
|
|
217
375
|
const LocalSkillSourceSchema = Schema.Struct({ skills: Selection });
|
|
218
376
|
const SkillsSectionSchema = Schema.Record(Schema.Union([Repository, LocalDirectory]), Schema.Union([RemoteSkillSourceSchema, LocalSkillSourceSchema]));
|
|
219
|
-
// src/
|
|
220
|
-
const
|
|
221
|
-
const
|
|
377
|
+
// src/shared/config/tools.ts
|
|
378
|
+
const ToolName = Schema.String.check(Schema.isPattern(/^[\w-][\w.-]*(?:\/[\w.-]+)?$/u));
|
|
379
|
+
const Platform = Schema.String.check(Schema.isPattern(/^(?:linux|darwin|win32)-(?:x64|arm64)$/u));
|
|
380
|
+
const Version = Schema.String.check(Schema.isPattern(/^\d[\w.+-]*$/u));
|
|
381
|
+
const BinaryName = Schema.String.check(Schema.isPattern(/^[\w][\w.-]*$/u));
|
|
382
|
+
const AssetFile = Schema.String.check(Schema.isPattern(/^[\w{}][\w.{}+-]*$/u));
|
|
383
|
+
const BinaryNames = Schema.NonEmptyArray(BinaryName);
|
|
384
|
+
const ToolSourceSchema = Schema.Struct({
|
|
385
|
+
version: Version,
|
|
386
|
+
base: Schema.optional(Schema.String),
|
|
387
|
+
bin: Schema.optional(BinaryNames),
|
|
388
|
+
assets: Schema.Record(Platform, AssetFile)
|
|
389
|
+
});
|
|
390
|
+
const ToolsSectionSchema = Schema.Record(ToolName, ToolSourceSchema);
|
|
391
|
+
// src/shared/lib/cache.ts
|
|
392
|
+
const ROOT$2 = ["vpa"];
|
|
222
393
|
const variable = (name) => Config.option(Config.NonEmptyString(name)).pipe(Effect.orElseSucceed(Option.none));
|
|
223
394
|
const platformCache = Effect.gen(function* platformCache() {
|
|
224
395
|
const path = yield* Path.Path;
|
|
@@ -231,15 +402,21 @@ const baseDirectory = variable("XDG_CACHE_HOME").pipe(Effect.flatMap(Option.matc
|
|
|
231
402
|
onSome: Effect.succeedSome
|
|
232
403
|
})), Effect.flatMap(Effect.fromOption), Effect.mapError(() => configMissing("No cache directory: set XDG_CACHE_HOME or HOME")));
|
|
233
404
|
/** @internal */
|
|
234
|
-
const
|
|
405
|
+
const vpaCacheDirectory = (subdirectory) => Effect.gen(function* vpaCache() {
|
|
235
406
|
const path = yield* Path.Path;
|
|
407
|
+
const base = yield* baseDirectory;
|
|
408
|
+
return path.join(base, ...ROOT$2, subdirectory);
|
|
409
|
+
});
|
|
410
|
+
// src/features/install-skills/model/cache.ts
|
|
411
|
+
const SkillCacheDirectory = Context.Reference("vite-plus-adopt/SkillCacheDirectory", { defaultValue: Option.none });
|
|
412
|
+
/** @internal */
|
|
413
|
+
const skillCacheDirectory = Effect.gen(function* skillCache() {
|
|
236
414
|
const configured = yield* SkillCacheDirectory;
|
|
237
415
|
if (Option.isSome(configured)) return configured.value;
|
|
238
|
-
|
|
239
|
-
return path.join(base, ...SUBDIRECTORY);
|
|
416
|
+
return yield* vpaCacheDirectory("skills");
|
|
240
417
|
});
|
|
241
418
|
// src/shared/lib/process.ts
|
|
242
|
-
const SUCCESS
|
|
419
|
+
const SUCCESS = 0;
|
|
243
420
|
const stdinOf = (input) => pipe(Option.fromNullishOr(input), Option.match({
|
|
244
421
|
onNone: () => "ignore",
|
|
245
422
|
onSome: (text) => Stream.make(new TextEncoder().encode(text))
|
|
@@ -254,7 +431,7 @@ const runCaptured = ({ root, file, args, env = {}, input, output = "all" }) => E
|
|
|
254
431
|
}));
|
|
255
432
|
const [text, exitCode] = yield* Effect.all([handle[output].pipe(Stream.decodeText, Stream.mkString), handle.exitCode], { concurrency: "unbounded" });
|
|
256
433
|
return {
|
|
257
|
-
valid: exitCode === SUCCESS
|
|
434
|
+
valid: exitCode === SUCCESS,
|
|
258
435
|
output: text
|
|
259
436
|
};
|
|
260
437
|
}).pipe(Effect.scoped);
|
|
@@ -391,6 +568,17 @@ const isInside = (directory) => (path) => path !== directory && (directory === R
|
|
|
391
568
|
const below = (directory) => (path) => pipe(Option.liftPredicate(path, () => String$1.isEmpty(directory)), Option.orElse(() => afterPrefix(`${directory}/`)(path)));
|
|
392
569
|
String$1.startsWith("!");
|
|
393
570
|
String$1.slice(1);
|
|
571
|
+
// src/shared/lib/http.ts
|
|
572
|
+
const RETRY_DELAY = "1 second";
|
|
573
|
+
const RETRIES = 4;
|
|
574
|
+
/** @internal */
|
|
575
|
+
const fetchBytes = (request) => Effect.gen(function* fetchArchive() {
|
|
576
|
+
const body = yield* (yield* (yield* HttpClient.HttpClient).pipe(HttpClient.filterStatusOk, HttpClient.retryTransient({
|
|
577
|
+
schedule: Schedule.exponential(RETRY_DELAY),
|
|
578
|
+
times: RETRIES
|
|
579
|
+
})).execute(request)).arrayBuffer;
|
|
580
|
+
return new Uint8Array(body);
|
|
581
|
+
});
|
|
394
582
|
// src/shared/lib/tar-gz.ts
|
|
395
583
|
const gunzipped = (data) => {
|
|
396
584
|
const compressed = new Blob([new Uint8Array(data)]).stream();
|
|
@@ -405,7 +593,7 @@ const readTarGz = (data) => Effect.flatMap(gunzipped(data), untarred);
|
|
|
405
593
|
const SKILL_FILE$1 = "SKILL.md";
|
|
406
594
|
const FRONTMATTER = /^---\r?\n(?<yaml>[\s\S]*?)\r?\n---/u;
|
|
407
595
|
const NEXT = 1;
|
|
408
|
-
const START = 0;
|
|
596
|
+
const START$1 = 0;
|
|
409
597
|
const SINGLE$2 = 1;
|
|
410
598
|
const SHORT_COMMIT = 7;
|
|
411
599
|
const Frontmatter = Schema.Struct({ name: Schema.String });
|
|
@@ -425,7 +613,7 @@ const withoutTopDirectory = ({ header, bytes }) => ({
|
|
|
425
613
|
});
|
|
426
614
|
const parentOf = (path) => pipe(path, String$1.lastIndexOf("/"), Option.match({
|
|
427
615
|
onNone: () => "",
|
|
428
|
-
onSome: (at) => String$1.slice(START, at)(path)
|
|
616
|
+
onSome: (at) => String$1.slice(START$1, at)(path)
|
|
429
617
|
}));
|
|
430
618
|
const isSkillFile = (root) => (entry) => entry.header.type === "File" && (entry.header.path === SKILL_FILE$1 || String$1.endsWith(`/${SKILL_FILE$1}`)(entry.header.path)) && isInside(root)(entry.header.path);
|
|
431
619
|
const isOutermost = (candidates) => ({ directory }) => !pipe(candidates, Array.some((other) => other.directory !== directory && isInside(other.directory)(directory)));
|
|
@@ -448,18 +636,9 @@ const skillsIn = ({ repository, source }) => (entries) => {
|
|
|
448
636
|
return Effect.succeed(found);
|
|
449
637
|
};
|
|
450
638
|
/** @internal */
|
|
451
|
-
const labelOf = ({ repository, source }) => `${repository}@${String$1.slice(START, SHORT_COMMIT)(source.commit)}`;
|
|
452
|
-
const RETRY_DELAY = "1 second";
|
|
453
|
-
const RETRIES = 4;
|
|
639
|
+
const labelOf = ({ repository, source }) => `${repository}@${String$1.slice(START$1, SHORT_COMMIT)(source.commit)}`;
|
|
454
640
|
const codeload = ({ repository, source }) => HttpClientRequest.get(`https://codeload.github.com/${repository}/tar.gz/${source.commit}`);
|
|
455
641
|
const api = ({ repository, source }) => (token) => HttpClientRequest.get(`https://api.github.com/repos/${repository}/tarball/${source.commit}`).pipe(HttpClientRequest.bearerToken(Redacted.value(token)));
|
|
456
|
-
const fetchBytes = (request) => Effect.gen(function* fetchArchive() {
|
|
457
|
-
const body = yield* (yield* (yield* HttpClient.HttpClient).pipe(HttpClient.filterStatusOk, HttpClient.retryTransient({
|
|
458
|
-
schedule: Schedule.exponential(RETRY_DELAY),
|
|
459
|
-
times: RETRIES
|
|
460
|
-
})).execute(request)).arrayBuffer;
|
|
461
|
-
return new Uint8Array(body);
|
|
462
|
-
});
|
|
463
642
|
const githubToken = Config.option(Config.Redacted("GITHUB_TOKEN")).pipe(Effect.orElseSucceed(Option.none));
|
|
464
643
|
const download = (declared) => Effect.gen(function* downloadArchive() {
|
|
465
644
|
const fromCodeload = yield* codeload(declared).pipe(fetchBytes, Effect.exit);
|
|
@@ -499,25 +678,15 @@ const resolveLocal = (root) => ({ directory, skills }) => Effect.gen(function* r
|
|
|
499
678
|
directory: base
|
|
500
679
|
};
|
|
501
680
|
});
|
|
502
|
-
// src/
|
|
503
|
-
/** @internal */
|
|
504
|
-
const INDEX = ".index.json";
|
|
505
|
-
const READ_ONLY = 292;
|
|
506
|
-
const READ_ONLY_EXECUTABLE = 365;
|
|
507
|
-
const OWNER_EXECUTE = 64;
|
|
508
|
-
const BIT = 2;
|
|
509
|
-
const SET = 1;
|
|
510
|
-
const modeOf = (mode) => {
|
|
511
|
-
if (Math.trunc(mode / OWNER_EXECUTE) % BIT === SET) return READ_ONLY_EXECUTABLE;
|
|
512
|
-
return READ_ONLY;
|
|
513
|
-
};
|
|
681
|
+
// src/shared/lib/place.ts
|
|
514
682
|
const renameOrKeep = (staging, target) => Effect.gen(function* renameOrKeepPlaced() {
|
|
515
683
|
const fs = yield* FileSystem.FileSystem;
|
|
516
684
|
const renamed = yield* Effect.exit(fs.rename(staging, target));
|
|
517
685
|
if (Exit.isSuccess(renamed) || !(yield* fs.exists(target))) return yield* renamed;
|
|
518
686
|
return yield* fs.remove(staging, { recursive: true });
|
|
519
687
|
});
|
|
520
|
-
|
|
688
|
+
/** @internal */
|
|
689
|
+
const placeAtomically = Function.dual(2, (target, write) => Effect.gen(function* place() {
|
|
521
690
|
const fs = yield* FileSystem.FileSystem;
|
|
522
691
|
const path = yield* Path.Path;
|
|
523
692
|
yield* fs.makeDirectory(path.dirname(target), { recursive: true });
|
|
@@ -527,7 +696,19 @@ const placeAtomically = (target, write) => Effect.gen(function* place() {
|
|
|
527
696
|
});
|
|
528
697
|
yield* write(staging);
|
|
529
698
|
yield* renameOrKeep(staging, target);
|
|
530
|
-
});
|
|
699
|
+
}));
|
|
700
|
+
// src/features/install-skills/model/extract.ts
|
|
701
|
+
/** @internal */
|
|
702
|
+
const INDEX = ".index.json";
|
|
703
|
+
const READ_ONLY = 292;
|
|
704
|
+
const READ_ONLY_EXECUTABLE = 365;
|
|
705
|
+
const OWNER_EXECUTE = 64;
|
|
706
|
+
const BIT = 2;
|
|
707
|
+
const SET = 1;
|
|
708
|
+
const modeOf = (mode) => {
|
|
709
|
+
if (Math.trunc(mode / OWNER_EXECUTE) % BIT === SET) return READ_ONLY_EXECUTABLE;
|
|
710
|
+
return READ_ONLY;
|
|
711
|
+
};
|
|
531
712
|
const writeEntry = (staging, skill) => ({ header, bytes }) => Effect.gen(function* writeFile() {
|
|
532
713
|
const fs = yield* FileSystem.FileSystem;
|
|
533
714
|
const path = yield* Path.Path;
|
|
@@ -620,7 +801,7 @@ const resolveSource = (cache) => (declared) => Effect.gen(function* resolve() {
|
|
|
620
801
|
const isRemote = Schema.is(RemoteSkillSourceSchema);
|
|
621
802
|
const LOCAL_PREFIX = "./";
|
|
622
803
|
const SINGLE$1 = 1;
|
|
623
|
-
const decodeSection = (raw) => Schema.decodeUnknownEffect(SkillsSectionSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((failure) => checksFailed(`vite.config "skills": ${failure.message}`)));
|
|
804
|
+
const decodeSection$1 = (raw) => Schema.decodeUnknownEffect(SkillsSectionSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((failure) => checksFailed(`vite.config "skills": ${failure.message}`)));
|
|
624
805
|
const namedLinks = (path) => ({ repository, names, directory }) => pipe(names, Array.map((name) => ({
|
|
625
806
|
name,
|
|
626
807
|
repository,
|
|
@@ -657,77 +838,229 @@ const installSkills = (root) => Effect.gen(function* install() {
|
|
|
657
838
|
const config = yield* loadViteConfig(root);
|
|
658
839
|
const raw = Option.fromNullishOr(config.skills);
|
|
659
840
|
if (Option.isNone(raw)) return Option.none();
|
|
660
|
-
const section = yield* decodeSection(raw.value);
|
|
841
|
+
const section = yield* decodeSection$1(raw.value);
|
|
661
842
|
const cache = yield* skillCacheDirectory;
|
|
662
843
|
const resolved = yield* Effect.forEach(Record.toEntries(section), resolveEntry(root, cache), { concurrency: "unbounded" });
|
|
663
844
|
const links = yield* linksOf(resolved);
|
|
664
845
|
yield* linkSkills(root)(links);
|
|
665
846
|
return Option.some(links.length);
|
|
666
847
|
});
|
|
667
|
-
// src/features/
|
|
668
|
-
const
|
|
669
|
-
const
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
848
|
+
// src/features/install-tools/model/find-executable.ts
|
|
849
|
+
const WINDOWS_EXTENSION = ".exe";
|
|
850
|
+
const SEPARATORS = /[\\/]/u;
|
|
851
|
+
const fileNameOf = (name) => {
|
|
852
|
+
if (process.platform === "win32") return `${name}${WINDOWS_EXTENSION}`;
|
|
853
|
+
return name;
|
|
854
|
+
};
|
|
855
|
+
const depthOf = (entry) => Array.length(String$1.split(SEPARATORS)(entry));
|
|
856
|
+
const byDepth = Order.mapInput(Order.Number, depthOf);
|
|
857
|
+
/** @internal */
|
|
858
|
+
const findExecutable = (directory) => (name) => Effect.gen(function* find() {
|
|
859
|
+
const fs = yield* FileSystem.FileSystem;
|
|
860
|
+
const path = yield* Path.Path;
|
|
861
|
+
const entries = yield* fs.readDirectory(directory, { recursive: true });
|
|
862
|
+
const wanted = fileNameOf(name);
|
|
863
|
+
return yield* pipe(entries, Array.filter((entry) => path.basename(entry) === wanted), Array.sortBy(byDepth), Array.head, Option.map((entry) => path.join(directory, entry)), Effect.fromOption, Effect.mapError(() => checksFailed(`${wanted} is not in the archive unpacked at ${directory}`)));
|
|
681
864
|
});
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
head: range
|
|
691
|
-
}),
|
|
692
|
-
onNonEmpty: ([head]) => ({
|
|
693
|
-
type: "history",
|
|
694
|
-
bases: [base],
|
|
695
|
-
head
|
|
696
|
-
})
|
|
697
|
-
})
|
|
698
|
-
}));
|
|
699
|
-
const sourceOf = (partial, range) => Boolean$1.match(partial, {
|
|
700
|
-
onTrue: () => ({
|
|
701
|
-
type: "snapshot",
|
|
702
|
-
revision: HEAD
|
|
703
|
-
}),
|
|
704
|
-
onFalse: () => historyOf(range)
|
|
865
|
+
// src/features/install-tools/model/download.ts
|
|
866
|
+
const HEX = 16;
|
|
867
|
+
const BYTE_DIGITS = 2;
|
|
868
|
+
const hexOf = (digest) => pipe([...new Uint8Array(digest)], Array.map((byte) => String$1.padStart(BYTE_DIGITS, "0")(byte.toString(HEX))), Array.join(""));
|
|
869
|
+
const sha256Of = (bytes) => attempt("sha256")(() => crypto.subtle.digest("SHA-256", new Uint8Array(bytes))).pipe(Effect.map(hexOf));
|
|
870
|
+
const verified = (url, expected) => (downloaded) => Option.match(expected, {
|
|
871
|
+
onNone: () => Effect.succeed(downloaded),
|
|
872
|
+
onSome: (pinned) => Effect.filterOrFail(Effect.succeed(downloaded), ({ sha256 }) => sha256 === pinned, ({ sha256 }) => checksFailed(`${url} has sha256 ${sha256}, but vpa-lock.json pins ${pinned}`))
|
|
705
873
|
});
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
874
|
+
/** @internal */
|
|
875
|
+
const downloadAsset = (expected) => ({ name, version, url }) => fetchBytes(HttpClientRequest.get(url)).pipe(Effect.mapError(toolFailed(`downloading ${name}@${version}`)), Effect.flatMap((bytes) => sha256Of(bytes).pipe(Effect.map((sha256) => ({
|
|
876
|
+
bytes,
|
|
877
|
+
sha256
|
|
878
|
+
})))), Effect.flatMap(verified(url, expected)));
|
|
879
|
+
// src/features/install-tools/model/extract.ts
|
|
880
|
+
const ARCHIVE_SUFFIX = ".archive";
|
|
881
|
+
const DEFAULT_SYSTEM_ROOT = String.raw`C:\Windows`;
|
|
882
|
+
const tarFile = Effect.gen(function* tarFile() {
|
|
883
|
+
if (process.platform !== "win32") return "tar";
|
|
884
|
+
const path = yield* Path.Path;
|
|
885
|
+
const systemRoot = yield* Config.NonEmptyString("SystemRoot").pipe(Effect.orElseSucceed(() => DEFAULT_SYSTEM_ROOT));
|
|
886
|
+
return path.join(systemRoot, "System32", "tar.exe");
|
|
887
|
+
});
|
|
888
|
+
const untar = (archive, directory) => Effect.gen(function* run() {
|
|
889
|
+
const file = yield* tarFile;
|
|
890
|
+
const report = yield* runCaptured({
|
|
891
|
+
root: directory,
|
|
892
|
+
file,
|
|
893
|
+
args: [
|
|
894
|
+
"-xf",
|
|
895
|
+
archive,
|
|
896
|
+
"-C",
|
|
897
|
+
directory
|
|
898
|
+
]
|
|
710
899
|
});
|
|
900
|
+
yield* Effect.filterOrFail(Effect.succeed(report), ({ valid }) => valid, ({ output }) => toolFailed("tar")(output));
|
|
901
|
+
});
|
|
902
|
+
/** @internal */
|
|
903
|
+
const unpackArchive = (target) => (bytes) => placeAtomically(target, (staging) => Effect.gen(function* unpack() {
|
|
904
|
+
const fs = yield* FileSystem.FileSystem;
|
|
905
|
+
const archive = `${staging}${ARCHIVE_SUFFIX}`;
|
|
906
|
+
yield* fs.writeFile(archive, bytes);
|
|
907
|
+
yield* untar(archive, staging);
|
|
908
|
+
yield* fs.remove(archive);
|
|
909
|
+
}));
|
|
910
|
+
// src/features/install-tools/model/install-one.ts
|
|
911
|
+
const SHORT_HASH = 12;
|
|
912
|
+
const DATA_FIRST_ARITY$3 = 3;
|
|
913
|
+
const START = 0;
|
|
914
|
+
const SEPARATOR$1 = "/";
|
|
915
|
+
const directoryFor = (cache, { name, version, platform }, sha256) => Effect.gen(function* directory() {
|
|
916
|
+
return (yield* Path.Path).join(cache, ...String$1.split(SEPARATOR$1)(name), `${version}-${platform}-${String$1.slice(START, SHORT_HASH)(sha256)}`);
|
|
917
|
+
});
|
|
918
|
+
const alreadyInstalled = (cache, planned, locked) => Effect.gen(function* lookup() {
|
|
919
|
+
const fs = yield* FileSystem.FileSystem;
|
|
920
|
+
if (Option.isNone(locked)) return Option.none();
|
|
921
|
+
const directory = yield* directoryFor(cache, planned, locked.value);
|
|
922
|
+
const present = yield* fs.exists(directory).pipe(Effect.orElseSucceed(() => false));
|
|
923
|
+
return Option.liftPredicate(directory, () => present);
|
|
924
|
+
});
|
|
925
|
+
/** @internal */
|
|
926
|
+
const installOne = Function.dual(DATA_FIRST_ARITY$3, (cache, lock, planned) => Effect.gen(function* install() {
|
|
927
|
+
const locked = Record.get(lock, planned.url);
|
|
928
|
+
const cached = yield* alreadyInstalled(cache, planned, locked);
|
|
929
|
+
if (Option.isSome(cached)) return {
|
|
930
|
+
planned,
|
|
931
|
+
directory: cached.value,
|
|
932
|
+
recorded: Option.none()
|
|
933
|
+
};
|
|
934
|
+
const { bytes, sha256 } = yield* downloadAsset(locked)(planned);
|
|
935
|
+
const directory = yield* directoryFor(cache, planned, sha256);
|
|
936
|
+
yield* unpackArchive(directory)(bytes);
|
|
711
937
|
return {
|
|
712
|
-
|
|
713
|
-
|
|
938
|
+
planned,
|
|
939
|
+
directory,
|
|
940
|
+
recorded: Option.liftPredicate([planned.url, sha256], () => Option.isNone(locked))
|
|
714
941
|
};
|
|
715
|
-
})
|
|
942
|
+
}));
|
|
943
|
+
// src/features/install-tools/model/link-bin.ts
|
|
944
|
+
const BIN_DIRECTORY = ["node_modules", ".bin"];
|
|
945
|
+
const launcher = (target) => `@"${target}" %*\r\n`;
|
|
716
946
|
/** @internal */
|
|
717
|
-
const
|
|
947
|
+
const linkExecutable = (root) => ({ name, target }) => Effect.gen(function* linkOne() {
|
|
948
|
+
const fs = yield* FileSystem.FileSystem;
|
|
949
|
+
const path = yield* Path.Path;
|
|
950
|
+
const directory = path.join(root, ...BIN_DIRECTORY);
|
|
951
|
+
yield* fs.makeDirectory(directory, { recursive: true });
|
|
952
|
+
if (process.platform === "win32") return yield* fs.writeFileString(path.join(directory, `${name}.cmd`), launcher(target));
|
|
953
|
+
const entry = path.join(directory, name);
|
|
954
|
+
yield* fs.remove(entry, { force: true });
|
|
955
|
+
return yield* fs.symlink(target, entry);
|
|
956
|
+
});
|
|
957
|
+
// src/features/install-tools/model/lock.ts
|
|
718
958
|
/** @internal */
|
|
719
|
-
const
|
|
959
|
+
const LOCK_FILE = "vpa-lock.json";
|
|
960
|
+
const Sha256 = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/u));
|
|
961
|
+
const LockFile = Schema.Record(Schema.String, Sha256).pipe(Schema.fromJsonString);
|
|
962
|
+
const byUrl = Order.mapInput(String$1.Order, ([url]) => url);
|
|
963
|
+
const entryLine = ([url, sha256]) => ` ${toJson(url)}: ${toJson(sha256)}`;
|
|
964
|
+
const render = (lock) => pipe(Record.toEntries(lock), Array.sortBy(byUrl), Array.map(entryLine), Array.join(",\n"), (body) => `{\n${body}\n}\n`);
|
|
720
965
|
/** @internal */
|
|
721
|
-
const
|
|
722
|
-
const
|
|
723
|
-
yield*
|
|
724
|
-
|
|
966
|
+
const readLock = (root) => Effect.gen(function* read() {
|
|
967
|
+
const fs = yield* FileSystem.FileSystem;
|
|
968
|
+
const path = yield* Path.Path;
|
|
969
|
+
const text = yield* fs.readFileString(path.join(root, LOCK_FILE));
|
|
970
|
+
return yield* Schema.decodeEffect(LockFile)(text);
|
|
971
|
+
}).pipe(Effect.orElseSucceed(() => ({})));
|
|
725
972
|
/** @internal */
|
|
726
|
-
const
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
973
|
+
const writeLock = (root) => (lock) => Effect.gen(function* write() {
|
|
974
|
+
const fs = yield* FileSystem.FileSystem;
|
|
975
|
+
const path = yield* Path.Path;
|
|
976
|
+
yield* fs.writeFileString(path.join(root, LOCK_FILE), render(lock));
|
|
977
|
+
});
|
|
978
|
+
// src/features/install-tools/model/plan.ts
|
|
979
|
+
const SEPARATOR = "/";
|
|
980
|
+
const PLACEHOLDER = "{version}";
|
|
981
|
+
const DATA_FIRST_ARITY$2 = 2;
|
|
982
|
+
const withVersion = (version) => (template) => String$1.replaceAll(PLACEHOLDER, version)(template);
|
|
983
|
+
const defaultBase = (name) => Option.liftPredicate(`https://github.com/${name}/releases/download/v${PLACEHOLDER}`, () => String$1.includes(SEPARATOR)(name));
|
|
984
|
+
const binsOf = (name, bin) => Option.getOrElse(Option.fromNullishOr(bin), () => [pipe(String$1.split(SEPARATOR)(name), Array.last, Option.getOrElse(() => name))]);
|
|
985
|
+
const planOne = (platform) => ([name, source]) => {
|
|
986
|
+
const file = Record.get(source.assets, platform);
|
|
987
|
+
if (Option.isNone(file)) return Effect.succeedNone;
|
|
988
|
+
const base = Option.orElse(Option.fromNullishOr(source.base), () => defaultBase(name));
|
|
989
|
+
if (Option.isNone(base)) return Effect.fail(checksFailed(`vite.config "tools": ${name} needs a "base" URL`));
|
|
990
|
+
const render = withVersion(source.version);
|
|
991
|
+
return Effect.succeedSome({
|
|
992
|
+
name,
|
|
993
|
+
version: source.version,
|
|
994
|
+
platform,
|
|
995
|
+
url: `${render(base.value)}/${render(file.value)}`,
|
|
996
|
+
bins: binsOf(name, source.bin)
|
|
997
|
+
});
|
|
730
998
|
};
|
|
999
|
+
/** @internal */
|
|
1000
|
+
const planTools = Function.dual(DATA_FIRST_ARITY$2, (section, platform) => pipe(Record.toEntries(section), Effect.forEach(planOne(platform), { concurrency: 1 }), Effect.map(Array.getSomes)));
|
|
1001
|
+
// src/features/install-tools/model/section.ts
|
|
1002
|
+
const DISABLED = [
|
|
1003
|
+
"false",
|
|
1004
|
+
"0",
|
|
1005
|
+
"off"
|
|
1006
|
+
];
|
|
1007
|
+
/** @internal */
|
|
1008
|
+
const decodeSection = (raw) => Schema.decodeUnknownEffect(ToolsSectionSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((failure) => checksFailed(`vite.config "tools": ${failure.message}`)));
|
|
1009
|
+
/** @internal */
|
|
1010
|
+
const toolsEnabled = Config.option(Config.String("VPA_TOOLS")).pipe(Effect.map(Option.exists((value) => Array.contains(DISABLED, String$1.toLowerCase(value)))), Effect.map((disabled) => !disabled), Effect.orElseSucceed(() => true));
|
|
1011
|
+
// src/features/install-tools/model/install-tools.ts
|
|
1012
|
+
const CONCURRENCY = 4;
|
|
1013
|
+
const executablesOf = ({ planned, directory }) => Effect.forEach(planned.bins, (name) => findExecutable(directory)(name).pipe(Effect.map((target) => ({
|
|
1014
|
+
name,
|
|
1015
|
+
target
|
|
1016
|
+
}))), { concurrency: 1 });
|
|
1017
|
+
const record = (root, lock) => (installed) => {
|
|
1018
|
+
const recorded = pipe(installed, Array.flatMap(({ recorded: entry }) => Option.toArray(entry)));
|
|
1019
|
+
if (Array.isReadonlyArrayEmpty(recorded)) return Effect.void;
|
|
1020
|
+
return writeLock(root)({
|
|
1021
|
+
...lock,
|
|
1022
|
+
...Record.fromEntries(recorded)
|
|
1023
|
+
});
|
|
1024
|
+
};
|
|
1025
|
+
const plannedTools = (root) => Effect.gen(function* plan() {
|
|
1026
|
+
const config = yield* loadViteConfig(root);
|
|
1027
|
+
const enabled = yield* toolsEnabled;
|
|
1028
|
+
const raw = Option.fromNullishOr(config.tools);
|
|
1029
|
+
if (Option.isNone(raw) || !enabled) return Option.none();
|
|
1030
|
+
const section = yield* decodeSection(raw.value);
|
|
1031
|
+
const planned = yield* planTools(section, `${process.platform}-${process.arch}`);
|
|
1032
|
+
return Option.some(planned);
|
|
1033
|
+
});
|
|
1034
|
+
const installAll = (root, planned) => Effect.gen(function* installPlanned() {
|
|
1035
|
+
const lock = yield* readLock(root);
|
|
1036
|
+
const cache = yield* vpaCacheDirectory("tools");
|
|
1037
|
+
const installed = yield* Effect.forEach(planned, (tool) => installOne(cache, lock, tool), { concurrency: CONCURRENCY });
|
|
1038
|
+
yield* record(root, lock)(installed);
|
|
1039
|
+
const found = yield* Effect.forEach(installed, executablesOf, { concurrency: CONCURRENCY });
|
|
1040
|
+
const executables = Array.flatten(found);
|
|
1041
|
+
yield* Effect.forEach(executables, linkExecutable(root), {
|
|
1042
|
+
concurrency: 1,
|
|
1043
|
+
discard: true
|
|
1044
|
+
});
|
|
1045
|
+
return Array.length(executables);
|
|
1046
|
+
});
|
|
1047
|
+
/** @internal */
|
|
1048
|
+
const installTools = (root) => plannedTools(root).pipe(Effect.flatMap(Option.match({
|
|
1049
|
+
onNone: () => Effect.succeedNone,
|
|
1050
|
+
onSome: (planned) => installAll(root, planned).pipe(Effect.asSome)
|
|
1051
|
+
})));
|
|
1052
|
+
// src/app/prepare.ts
|
|
1053
|
+
const reportLinked = (what, destination) => (count) => Option.match(count, {
|
|
1054
|
+
onNone: () => Effect.void,
|
|
1055
|
+
onSome: (linked) => writeTo("stdout", `Linked ${linked} ${what} into ${destination}\n`)
|
|
1056
|
+
});
|
|
1057
|
+
/** @internal */
|
|
1058
|
+
const prepare = (root) => Layer.build(FetchHttpClient.layer).pipe(Effect.flatMap((context) => Effect.provideContext(Effect.gen(function* prepareAll() {
|
|
1059
|
+
const skills = yield* installSkills(root);
|
|
1060
|
+
yield* reportLinked("skills", ".agents/skills")(skills);
|
|
1061
|
+
const tools = yield* installTools(root);
|
|
1062
|
+
yield* reportLinked("tools", "node_modules/.bin")(tools);
|
|
1063
|
+
}), context)), Effect.scoped);
|
|
731
1064
|
// src/shared/lib/workspace.ts
|
|
732
1065
|
const DEPENDENCY_FIELDS = [
|
|
733
1066
|
"dependencies",
|
|
@@ -979,7 +1312,7 @@ const runAllChecks = (root) => Effect.gen(function* all() {
|
|
|
979
1312
|
const DATA_FIRST_ARITY = 2;
|
|
980
1313
|
const USAGE = pipe([
|
|
981
1314
|
"Usage: vpa run every check configured in vite.config.ts",
|
|
982
|
-
" vpa --prepare install the skills in vite.config.ts
|
|
1315
|
+
" vpa --prepare install the skills and tools in vite.config.ts (prepare)",
|
|
983
1316
|
" vpa --staged scan the staged changes for secrets (pre-commit)",
|
|
984
1317
|
" vpa --commit-msg <file> lint a commit message (commit-msg)",
|
|
985
1318
|
" vpa --message <text> lint a message"
|
|
@@ -996,11 +1329,6 @@ const lintMessage = (toMessage) => (root, rest) => pipe(Array.head(rest), Option
|
|
|
996
1329
|
})
|
|
997
1330
|
}));
|
|
998
1331
|
const readMessage = (file) => FileSystem.FileSystem.pipe(Effect.flatMap((fs) => fs.readFileString(file)));
|
|
999
|
-
const reportLinked = Option.match({
|
|
1000
|
-
onNone: () => Effect.void,
|
|
1001
|
-
onSome: (count) => writeTo("stdout", `Linked ${count} skills into .agents/skills\n`)
|
|
1002
|
-
});
|
|
1003
|
-
const prepare = (root) => Layer.build(FetchHttpClient.layer).pipe(Effect.flatMap((context) => Effect.provideContext(installSkills(root), context)), Effect.flatMap(reportLinked), Effect.scoped);
|
|
1004
1332
|
const HOOKS = {
|
|
1005
1333
|
"--prepare": prepare,
|
|
1006
1334
|
"--staged": stagedSecrets,
|
|
@@ -1017,4 +1345,4 @@ const runVpa = Function.dual(DATA_FIRST_ARITY, (root, args) => pipe(args, Array.
|
|
|
1017
1345
|
})));
|
|
1018
1346
|
export { VpToolsError as i, writeTo as n, loadViteConfig as r, runVpa as t };
|
|
1019
1347
|
|
|
1020
|
-
//# sourceMappingURL=vpa-
|
|
1348
|
+
//# sourceMappingURL=vpa-Br-ls0AQ.mjs.map
|