@icebreakers/monorepo 5.6.0 → 5.7.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 +2 -0
- package/dist/baseline-DPfotf4y.mjs +146 -0
- package/dist/bundle-B9vRch4R.mjs +49 -0
- package/dist/catalog-CDEyc1uA.mjs +299 -0
- package/dist/cli.mjs +1487 -156
- package/dist/commands-TS8ABFdP.mjs +13820 -0
- package/dist/config-C38c_Q8L.mjs +66 -0
- package/dist/{create-flow-CXRhfGbb.mjs → create-flow-CCr2hfSY.mjs} +90 -24
- package/dist/deps-CUdI2DaB.mjs +47 -0
- package/dist/execute-PX1hT0qv.mjs +68 -0
- package/dist/execute-Vi4qHe-D.mjs +663 -0
- package/dist/format-DZ7L34rf.mjs +28 -0
- package/dist/index-CoCTFWZJ.d.mts +2150 -0
- package/dist/index.d.mts +1738 -112
- package/dist/index.mjs +60 -7
- package/dist/inputs-_xIVONmB.mjs +50 -0
- package/dist/npm-B25nrSyz.mjs +82 -0
- package/dist/plan-B5aE_WNF.mjs +75 -0
- package/dist/run-Lu7y1bNf.mjs +165 -0
- package/dist/save-CdCf630Z.mjs +79 -0
- package/dist/scan-4nboHNXP.mjs +293 -0
- package/dist/template-drift-BBhnrHY1.mjs +2740 -0
- package/dist/tooling-entry.d.mts +1 -1
- package/dist/tooling-entry.mjs +2 -2
- package/dist/transaction-DAhY8EpG.mjs +168 -0
- package/dist/tsconfig-CGntrzBM.mjs +1483 -0
- package/dist/{vitest-Blzbh8xZ.mjs → vitest-DkGh4Ygo.mjs} +1 -1
- package/dist/workspace-tasks-CnB8kkS0.mjs +4435 -0
- package/package.json +22 -4
- package/resources/api-report/runner.cjs +76 -0
- package/resources/devcontainer/setup.mjs +36 -0
- package/resources/knip/reporter.mjs +46 -0
- package/resources/maintenance/migration-lanes.mjs +141 -0
- package/resources/maintenance/migration-lock.mjs +119 -0
- package/resources/maintenance/migrations.mjs +215 -0
- package/resources/maintenance/presets.mjs +130 -0
- package/resources/maintenance/validate.mjs +233 -0
- package/resources/maintenance/workflow.yml +151 -0
- package/resources/skills/repoctl/SKILL.md +2 -0
- package/resources/skills/repoctl/references/commands.md +224 -13
- package/resources/skills/repoctl/references/config.md +70 -6
- package/resources/skills/repoctl/references/dependencies.md +37 -0
- package/resources/skills/repoctl/references/knip.md +34 -0
- package/resources/skills/repoctl/references/templates.md +23 -0
- package/dist/commands-D4xZQ5t-.mjs +0 -5685
- package/dist/config-p842Knhq.mjs +0 -114
- package/dist/index-Bl_PB2Ch.d.mts +0 -1039
- package/dist/tsconfig-BrjI_5yI.mjs +0 -75
- package/dist/types-MAUIQpfp.mjs +0 -499
- package/dist/workspace-MCKewElu.mjs +0 -123
|
@@ -0,0 +1,1483 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { findWorkspaceDir } from "@pnpm/find-workspace-dir";
|
|
4
|
+
import path, { normalize } from "pathe";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { lstat, readFile, realpath } from "node:fs/promises";
|
|
7
|
+
import fs$1 from "node:fs";
|
|
8
|
+
import { loadConfig } from "c12";
|
|
9
|
+
import { satisfies, valid, validRange } from "semver";
|
|
10
|
+
import validatePackageName from "validate-npm-package-name";
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import path$1 from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { parse as parse$1 } from "comment-json";
|
|
15
|
+
//#region src/core/config/context.ts
|
|
16
|
+
/** Workspace-wide commands always consume root policy, even when invoked in a package. */
|
|
17
|
+
async function commandConfigDirectory(name, cwd) {
|
|
18
|
+
return [
|
|
19
|
+
"clean",
|
|
20
|
+
"deps",
|
|
21
|
+
"doctor",
|
|
22
|
+
"env"
|
|
23
|
+
].includes(name) ? await findWorkspaceDir(cwd) ?? cwd : cwd;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/core/config/refresh.ts
|
|
27
|
+
/** Keep C12's resolution and merging while bypassing native ESM's immutable cache. */
|
|
28
|
+
function freshConfigLoading(files) {
|
|
29
|
+
return {
|
|
30
|
+
jitiOptions: {
|
|
31
|
+
tryNative: false,
|
|
32
|
+
moduleCache: false,
|
|
33
|
+
fsCache: false
|
|
34
|
+
},
|
|
35
|
+
resolve(_source, { jiti }) {
|
|
36
|
+
if (jiti) jiti.import = async (filename, options) => {
|
|
37
|
+
const { bundleConfig } = await import("./bundle-B9vRch4R.mjs");
|
|
38
|
+
const bundled = await bundleConfig(filename);
|
|
39
|
+
for (const file of bundled.files) files.add(file);
|
|
40
|
+
const loaded = await jiti.evalModule(bundled.code, {
|
|
41
|
+
filename,
|
|
42
|
+
async: true,
|
|
43
|
+
forceTranspile: true
|
|
44
|
+
});
|
|
45
|
+
return options?.default ? loaded?.default ?? loaded : loaded;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/core/config/paths.ts
|
|
52
|
+
/** Dot paths escape literal dots and backslashes in dynamic map keys. */
|
|
53
|
+
function appendConfigPath(prefix, key) {
|
|
54
|
+
const escaped = key.replaceAll("\\", "\\\\").replaceAll(".", "\\.");
|
|
55
|
+
return prefix ? `${prefix}.${escaped}` : escaped;
|
|
56
|
+
}
|
|
57
|
+
function splitConfigPath(field) {
|
|
58
|
+
const parts = [""];
|
|
59
|
+
let escaped = false;
|
|
60
|
+
for (const character of field) if (escaped) {
|
|
61
|
+
parts[parts.length - 1] += character;
|
|
62
|
+
escaped = false;
|
|
63
|
+
} else if (character === "\\") escaped = true;
|
|
64
|
+
else if (character === ".") parts.push("");
|
|
65
|
+
else parts[parts.length - 1] += character;
|
|
66
|
+
return parts;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/core/config/validation/schema.ts
|
|
70
|
+
const string = {
|
|
71
|
+
expected: "string",
|
|
72
|
+
accepts: (value) => typeof value === "string"
|
|
73
|
+
};
|
|
74
|
+
const nonempty = {
|
|
75
|
+
expected: "nonempty string",
|
|
76
|
+
accepts: (value) => typeof value === "string" && value.trim().length > 0
|
|
77
|
+
};
|
|
78
|
+
const boolean = {
|
|
79
|
+
expected: "boolean",
|
|
80
|
+
accepts: (value) => typeof value === "boolean"
|
|
81
|
+
};
|
|
82
|
+
const positive = {
|
|
83
|
+
expected: "positive finite number",
|
|
84
|
+
accepts: (value) => typeof value === "number" && Number.isFinite(value) && value > 0
|
|
85
|
+
};
|
|
86
|
+
const opaque = {
|
|
87
|
+
expected: "native tool configuration",
|
|
88
|
+
accepts: () => true
|
|
89
|
+
};
|
|
90
|
+
const isRecord = (value) => value !== null && typeof value === "object" && [Object.prototype, null].includes(Object.getPrototypeOf(value));
|
|
91
|
+
const object = (fields, required) => ({
|
|
92
|
+
expected: "object",
|
|
93
|
+
accepts: isRecord,
|
|
94
|
+
fields,
|
|
95
|
+
...required ? { required } : {}
|
|
96
|
+
});
|
|
97
|
+
const array = (items) => ({
|
|
98
|
+
expected: `array of ${items.expected}`,
|
|
99
|
+
accepts: Array.isArray,
|
|
100
|
+
items
|
|
101
|
+
});
|
|
102
|
+
const record = (values) => ({
|
|
103
|
+
expected: "object map",
|
|
104
|
+
accepts: isRecord,
|
|
105
|
+
values
|
|
106
|
+
});
|
|
107
|
+
const choices = (...values) => ({
|
|
108
|
+
expected: values.map(String).join(" | "),
|
|
109
|
+
accepts: (value) => values.includes(value)
|
|
110
|
+
});
|
|
111
|
+
const union = (...schemas) => ({
|
|
112
|
+
expected: schemas.map((schema) => schema.expected).join(" | "),
|
|
113
|
+
accepts: (value) => schemas.some((schema) => schema.accepts(value)),
|
|
114
|
+
alternatives: schemas
|
|
115
|
+
});
|
|
116
|
+
const strings = array(string);
|
|
117
|
+
const names = array(nonempty);
|
|
118
|
+
function actualType(value) {
|
|
119
|
+
if (value === null) return "null";
|
|
120
|
+
if (Array.isArray(value)) return "array";
|
|
121
|
+
return typeof value;
|
|
122
|
+
}
|
|
123
|
+
function validateSchema(value, schema, path, diagnostics, ancestors = /* @__PURE__ */ new Set()) {
|
|
124
|
+
if (value === void 0) return;
|
|
125
|
+
if (!schema.accepts(value)) {
|
|
126
|
+
diagnostics.push({
|
|
127
|
+
id: "config.invalid-type",
|
|
128
|
+
path,
|
|
129
|
+
actualType: actualType(value),
|
|
130
|
+
expected: schema.expected,
|
|
131
|
+
suggestion: `Use ${schema.expected}; omit an optional field instead of using null.`
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (schema.alternatives) {
|
|
136
|
+
validateSchema(value, schema.alternatives.find((item) => item.accepts(value)), path, diagnostics, ancestors);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (!schema.fields && !schema.items && !schema.values) return;
|
|
140
|
+
if (ancestors.has(value)) {
|
|
141
|
+
diagnostics.push({
|
|
142
|
+
id: "config.invalid-value",
|
|
143
|
+
path,
|
|
144
|
+
actualType: "object",
|
|
145
|
+
expected: "acyclic configuration",
|
|
146
|
+
suggestion: "Remove the circular reference from repoctl-owned fields."
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const parents = new Set(ancestors).add(value);
|
|
151
|
+
if (schema.items && Array.isArray(value)) value.forEach((item, index) => validateSchema(item, schema.items, `${path}[${index}]`, diagnostics, parents));
|
|
152
|
+
if (!isRecord(value)) return;
|
|
153
|
+
for (const key of schema.required ?? []) if (value[key] === void 0) diagnostics.push({
|
|
154
|
+
id: "config.invalid-value",
|
|
155
|
+
path: appendConfigPath(path, key),
|
|
156
|
+
actualType: "undefined",
|
|
157
|
+
expected: schema.fields[key].expected,
|
|
158
|
+
suggestion: "Provide this required field."
|
|
159
|
+
});
|
|
160
|
+
for (const [key, item] of Object.entries(value)) {
|
|
161
|
+
const childPath = appendConfigPath(path, key);
|
|
162
|
+
const child = schema.fields && Object.hasOwn(schema.fields, key) ? schema.fields[key] : schema.values;
|
|
163
|
+
if (child) validateSchema(item, child, childPath, diagnostics, parents);
|
|
164
|
+
else diagnostics.push({
|
|
165
|
+
id: "config.unknown-field",
|
|
166
|
+
path: childPath,
|
|
167
|
+
actualType: actualType(item),
|
|
168
|
+
expected: `one of: ${Object.keys(schema.fields ?? {}).join(", ")}`,
|
|
169
|
+
suggestion: "Correct the field name or move native options into the documented tool passthrough."
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/core/presets/reference.ts
|
|
175
|
+
const presetPackageName = {
|
|
176
|
+
expected: "npm package name",
|
|
177
|
+
accepts: (value) => typeof value === "string" && validatePackageName(value).validForNewPackages
|
|
178
|
+
};
|
|
179
|
+
const presetVersion = {
|
|
180
|
+
expected: "exact semantic version",
|
|
181
|
+
accepts: (value) => typeof value === "string" && valid(value) === value
|
|
182
|
+
};
|
|
183
|
+
const presetReferencesSchema = array(object({
|
|
184
|
+
packageName: presetPackageName,
|
|
185
|
+
version: presetVersion
|
|
186
|
+
}, ["packageName", "version"]));
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/core/config/validation/commands.ts
|
|
189
|
+
const dependencyTypes = array(choices("dependencies", "devDependencies", "peerDependencies", "optionalDependencies"));
|
|
190
|
+
const toolingTargets = array(choices("commitlint", "eslint", "stylelint", "lint-staged", "tsconfig", "vitest"));
|
|
191
|
+
const remote = union({
|
|
192
|
+
...object({
|
|
193
|
+
kind: choices("npm"),
|
|
194
|
+
packageName: nonempty,
|
|
195
|
+
version: nonempty,
|
|
196
|
+
registry: nonempty
|
|
197
|
+
}, [
|
|
198
|
+
"kind",
|
|
199
|
+
"packageName",
|
|
200
|
+
"version"
|
|
201
|
+
]),
|
|
202
|
+
accepts: (value) => isRecord(value) && value["kind"] === "npm"
|
|
203
|
+
}, {
|
|
204
|
+
...object({
|
|
205
|
+
kind: choices("git"),
|
|
206
|
+
repository: nonempty,
|
|
207
|
+
ref: nonempty
|
|
208
|
+
}, [
|
|
209
|
+
"kind",
|
|
210
|
+
"repository",
|
|
211
|
+
"ref"
|
|
212
|
+
]),
|
|
213
|
+
accepts: (value) => isRecord(value) && value["kind"] === "git"
|
|
214
|
+
});
|
|
215
|
+
const template = object({
|
|
216
|
+
source: nonempty,
|
|
217
|
+
target: nonempty,
|
|
218
|
+
label: string,
|
|
219
|
+
category: choices("app", "docs", "library", "service", "tool"),
|
|
220
|
+
description: string,
|
|
221
|
+
remote
|
|
222
|
+
}, ["source", "target"]);
|
|
223
|
+
const templateValue$1 = {
|
|
224
|
+
...template,
|
|
225
|
+
expected: "nonempty string or template definition",
|
|
226
|
+
accepts: (value) => nonempty.accepts(value) || template.accepts(value)
|
|
227
|
+
};
|
|
228
|
+
const env = object({
|
|
229
|
+
tasks: names,
|
|
230
|
+
include: names,
|
|
231
|
+
exclude: names,
|
|
232
|
+
frameworkInference: boolean,
|
|
233
|
+
suppressions: array(object({
|
|
234
|
+
rule: nonempty,
|
|
235
|
+
reason: nonempty,
|
|
236
|
+
package: nonempty,
|
|
237
|
+
task: nonempty,
|
|
238
|
+
variable: nonempty,
|
|
239
|
+
path: nonempty
|
|
240
|
+
}, ["rule", "reason"]))
|
|
241
|
+
});
|
|
242
|
+
const doctor = object({
|
|
243
|
+
rules: names,
|
|
244
|
+
suppressions: array(object({
|
|
245
|
+
id: nonempty,
|
|
246
|
+
reason: nonempty,
|
|
247
|
+
path: string,
|
|
248
|
+
expires: string
|
|
249
|
+
}, ["id", "reason"]))
|
|
250
|
+
});
|
|
251
|
+
const branches = object({
|
|
252
|
+
stable: nonempty,
|
|
253
|
+
maintenance: array(object({
|
|
254
|
+
branch: nonempty,
|
|
255
|
+
range: nonempty,
|
|
256
|
+
tag: nonempty
|
|
257
|
+
}, [
|
|
258
|
+
"branch",
|
|
259
|
+
"range",
|
|
260
|
+
"tag"
|
|
261
|
+
])),
|
|
262
|
+
prerelease: array(object({
|
|
263
|
+
branch: nonempty,
|
|
264
|
+
lane: nonempty,
|
|
265
|
+
tag: nonempty,
|
|
266
|
+
target: nonempty
|
|
267
|
+
}, [
|
|
268
|
+
"branch",
|
|
269
|
+
"lane",
|
|
270
|
+
"tag"
|
|
271
|
+
]))
|
|
272
|
+
});
|
|
273
|
+
const commandSchemas = {
|
|
274
|
+
ai: object({
|
|
275
|
+
output: string,
|
|
276
|
+
baseDir: string,
|
|
277
|
+
force: boolean,
|
|
278
|
+
format: choices("md", "json"),
|
|
279
|
+
tasksFile: string
|
|
280
|
+
}),
|
|
281
|
+
clean: object({
|
|
282
|
+
autoConfirm: boolean,
|
|
283
|
+
dryRun: boolean,
|
|
284
|
+
ignorePackages: strings,
|
|
285
|
+
includePrivate: boolean,
|
|
286
|
+
pinnedVersion: nonempty
|
|
287
|
+
}),
|
|
288
|
+
create: object({
|
|
289
|
+
offline: boolean,
|
|
290
|
+
cacheDir: nonempty,
|
|
291
|
+
name: string,
|
|
292
|
+
renameJson: boolean,
|
|
293
|
+
type: nonempty,
|
|
294
|
+
templatesDir: nonempty,
|
|
295
|
+
templateMap: record(templateValue$1),
|
|
296
|
+
choices: array(object({
|
|
297
|
+
value: nonempty,
|
|
298
|
+
name: string,
|
|
299
|
+
description: string,
|
|
300
|
+
short: string,
|
|
301
|
+
disabled: union(boolean, string)
|
|
302
|
+
}, ["value"])),
|
|
303
|
+
defaultTemplate: nonempty
|
|
304
|
+
}),
|
|
305
|
+
deps: object({ groups: array(object({
|
|
306
|
+
name: nonempty,
|
|
307
|
+
workspaces: names,
|
|
308
|
+
dependencies: names,
|
|
309
|
+
sections: dependencyTypes,
|
|
310
|
+
reason: nonempty,
|
|
311
|
+
ignore: boolean
|
|
312
|
+
}, [
|
|
313
|
+
"name",
|
|
314
|
+
"workspaces",
|
|
315
|
+
"dependencies",
|
|
316
|
+
"reason"
|
|
317
|
+
])) }),
|
|
318
|
+
doctor,
|
|
319
|
+
env,
|
|
320
|
+
init: object({
|
|
321
|
+
skipReadme: boolean,
|
|
322
|
+
skipPkgJson: boolean,
|
|
323
|
+
skipChangeset: boolean,
|
|
324
|
+
skipIssueTemplateConfig: boolean,
|
|
325
|
+
tooling: toolingTargets,
|
|
326
|
+
preset: choices("minimal", "standard"),
|
|
327
|
+
force: boolean
|
|
328
|
+
}),
|
|
329
|
+
mirror: object({ env: record(string) }),
|
|
330
|
+
release: object({
|
|
331
|
+
branches,
|
|
332
|
+
qualityScripts: names,
|
|
333
|
+
hooks: object({
|
|
334
|
+
verify: names,
|
|
335
|
+
beforeVersion: names,
|
|
336
|
+
afterVersion: names,
|
|
337
|
+
beforePublish: names,
|
|
338
|
+
afterPublish: array(object({
|
|
339
|
+
script: nonempty,
|
|
340
|
+
continueOnError: boolean,
|
|
341
|
+
idempotent: boolean
|
|
342
|
+
}, ["script"]))
|
|
343
|
+
})
|
|
344
|
+
}),
|
|
345
|
+
upgrade: object({
|
|
346
|
+
interactive: boolean,
|
|
347
|
+
core: boolean,
|
|
348
|
+
outDir: string,
|
|
349
|
+
cwd: string,
|
|
350
|
+
skipOverwrite: boolean,
|
|
351
|
+
yes: boolean,
|
|
352
|
+
overwrite: boolean,
|
|
353
|
+
noOverwrite: boolean,
|
|
354
|
+
overwriteRelease: boolean,
|
|
355
|
+
targets: strings,
|
|
356
|
+
mergeTargets: boolean,
|
|
357
|
+
scripts: record(string),
|
|
358
|
+
skipChangesetMarkdown: boolean
|
|
359
|
+
})
|
|
360
|
+
};
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/core/config/validation/admission.ts
|
|
363
|
+
const admissionSchema = object({
|
|
364
|
+
rules: array(object({
|
|
365
|
+
id: nonempty,
|
|
366
|
+
workspaces: names,
|
|
367
|
+
dependencies: names,
|
|
368
|
+
effect: choices("allow", "deny"),
|
|
369
|
+
sections: dependencyTypes,
|
|
370
|
+
reason: nonempty,
|
|
371
|
+
alternative: string,
|
|
372
|
+
severity: choices("warn", "fail")
|
|
373
|
+
}, [
|
|
374
|
+
"id",
|
|
375
|
+
"workspaces",
|
|
376
|
+
"dependencies",
|
|
377
|
+
"effect",
|
|
378
|
+
"sections",
|
|
379
|
+
"reason"
|
|
380
|
+
])),
|
|
381
|
+
exceptions: array(object({
|
|
382
|
+
rule: nonempty,
|
|
383
|
+
workspace: nonempty,
|
|
384
|
+
dependency: nonempty,
|
|
385
|
+
section: choices("dependencies", "devDependencies", "peerDependencies", "optionalDependencies"),
|
|
386
|
+
reason: nonempty,
|
|
387
|
+
expiresOn: string
|
|
388
|
+
}, [
|
|
389
|
+
"rule",
|
|
390
|
+
"workspace",
|
|
391
|
+
"dependency",
|
|
392
|
+
"section",
|
|
393
|
+
"reason"
|
|
394
|
+
]))
|
|
395
|
+
}, ["rules"]);
|
|
396
|
+
const installationSecuritySchema = object({
|
|
397
|
+
minimumReleaseAge: {
|
|
398
|
+
expected: "nonnegative finite number",
|
|
399
|
+
accepts: (value) => typeof value === "number" && Number.isFinite(value) && value >= 0
|
|
400
|
+
},
|
|
401
|
+
trustPolicy: choices("no-downgrade"),
|
|
402
|
+
requireBuildApproval: boolean,
|
|
403
|
+
severity: choices("warn", "fail"),
|
|
404
|
+
exceptions: array(object({
|
|
405
|
+
key: choices("minimumReleaseAgeExclude", "trustPolicyExclude"),
|
|
406
|
+
package: nonempty,
|
|
407
|
+
reason: nonempty
|
|
408
|
+
}, [
|
|
409
|
+
"key",
|
|
410
|
+
"package",
|
|
411
|
+
"reason"
|
|
412
|
+
]))
|
|
413
|
+
});
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/core/template-source/request.ts
|
|
416
|
+
function gitRef(value) {
|
|
417
|
+
return Boolean(value) && value !== "@" && !/[\s\p{Cc}]/u.test(value) && ![
|
|
418
|
+
"~",
|
|
419
|
+
"^",
|
|
420
|
+
":",
|
|
421
|
+
"?",
|
|
422
|
+
"*",
|
|
423
|
+
"[",
|
|
424
|
+
"\\"
|
|
425
|
+
].some((character) => value.includes(character)) && !value.startsWith("-") && !value.includes("..") && !value.includes("@{") && !value.endsWith(".") && value.split("/").every((part) => part && !part.startsWith(".") && !part.endsWith(".lock"));
|
|
426
|
+
}
|
|
427
|
+
function templateSourcePath(value) {
|
|
428
|
+
if (value === ".") return value;
|
|
429
|
+
if (typeof value !== "string" || !value || value.includes("\\") || value.includes(":") || value.includes("\0") || value.split("/").some((part) => !part || part === "." || part === "..")) throw new Error("Remote template source must be a portable relative directory, or . for the archive root.");
|
|
430
|
+
return value;
|
|
431
|
+
}
|
|
432
|
+
function registryUrl(value) {
|
|
433
|
+
let url;
|
|
434
|
+
try {
|
|
435
|
+
url = new URL(String(value));
|
|
436
|
+
} catch {
|
|
437
|
+
throw new Error("npm registry must be an HTTP or HTTPS URL without embedded credentials.");
|
|
438
|
+
}
|
|
439
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new Error("npm registry must be an HTTP or HTTPS URL without embedded credentials.");
|
|
440
|
+
return url.href.endsWith("/") ? url.href : `${url.href}/`;
|
|
441
|
+
}
|
|
442
|
+
function normalizeTemplateRemoteSource(value) {
|
|
443
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Template remote source must be an npm or Git declaration.");
|
|
444
|
+
const source = value;
|
|
445
|
+
if (source["kind"] === "npm") {
|
|
446
|
+
if (Object.keys(source).some((key) => ![
|
|
447
|
+
"kind",
|
|
448
|
+
"packageName",
|
|
449
|
+
"version",
|
|
450
|
+
"registry"
|
|
451
|
+
].includes(key)) || typeof source["packageName"] !== "string" || !validatePackageName(source["packageName"]).validForNewPackages || typeof source["version"] !== "string" || valid(source["version"]) !== source["version"]) throw new Error("An npm template source requires packageName and an exact semantic version, without tags or ranges.");
|
|
452
|
+
return {
|
|
453
|
+
kind: "npm",
|
|
454
|
+
packageName: source["packageName"],
|
|
455
|
+
version: source["version"],
|
|
456
|
+
...source["registry"] !== void 0 ? { registry: registryUrl(source["registry"]) } : {}
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
if (source["kind"] === "git") {
|
|
460
|
+
if (Object.keys(source).some((key) => ![
|
|
461
|
+
"kind",
|
|
462
|
+
"repository",
|
|
463
|
+
"ref"
|
|
464
|
+
].includes(key)) || typeof source["repository"] !== "string" || typeof source["ref"] !== "string" || !gitRef(source["ref"])) throw new Error("A Git template source requires a repository URL and an explicit ref or commit.");
|
|
465
|
+
let repository;
|
|
466
|
+
try {
|
|
467
|
+
repository = new URL(source["repository"]);
|
|
468
|
+
} catch {
|
|
469
|
+
throw new Error("Use an https://, ssh:// or file:// Git repository URL without embedded credentials.");
|
|
470
|
+
}
|
|
471
|
+
if (![
|
|
472
|
+
"https:",
|
|
473
|
+
"ssh:",
|
|
474
|
+
"file:"
|
|
475
|
+
].includes(repository.protocol) || repository.password || repository.username && !(repository.protocol === "ssh:" && repository.username === "git") || repository.search || repository.hash) throw new Error("Git URLs must use HTTPS, SSH or file transport and cannot contain credentials, queries or fragments; use the Git credential helper or SSH agent.");
|
|
476
|
+
return {
|
|
477
|
+
kind: "git",
|
|
478
|
+
repository: repository.href,
|
|
479
|
+
ref: source["ref"]
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
throw new Error("Unsupported template remote source kind; use npm or git.");
|
|
483
|
+
}
|
|
484
|
+
function normalizeTemplateSourceRequest(source, templatePath) {
|
|
485
|
+
return {
|
|
486
|
+
source: normalizeTemplateRemoteSource(source),
|
|
487
|
+
templatePath: templateSourcePath(templatePath)
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function sourceRequestKey(request) {
|
|
491
|
+
return createHash("sha256").update(JSON.stringify(request)).digest("hex");
|
|
492
|
+
}
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region src/core/config/validation/template-sources.ts
|
|
495
|
+
function validateTemplateSources(config, diagnostics) {
|
|
496
|
+
const commands = config["commands"];
|
|
497
|
+
const templates = (isRecord(commands) && isRecord(commands["create"]) ? commands["create"] : void 0)?.["templateMap"];
|
|
498
|
+
if (!isRecord(templates)) return;
|
|
499
|
+
for (const [key, definition] of Object.entries(templates)) {
|
|
500
|
+
if (!isRecord(definition) || definition["remote"] === void 0 || typeof definition["source"] !== "string") continue;
|
|
501
|
+
const path = `${appendConfigPath("commands.create.templateMap", key)}.remote`;
|
|
502
|
+
if (diagnostics.some((diagnostic) => diagnostic.path === path || diagnostic.path.startsWith(`${path}.`))) continue;
|
|
503
|
+
try {
|
|
504
|
+
normalizeTemplateSourceRequest(definition["remote"], definition["source"]);
|
|
505
|
+
} catch (error) {
|
|
506
|
+
diagnostics.push({
|
|
507
|
+
id: "config.invalid-value",
|
|
508
|
+
path,
|
|
509
|
+
actualType: "object",
|
|
510
|
+
expected: "fixed npm or Git template source without credentials",
|
|
511
|
+
suggestion: error instanceof Error ? error.message : "Use a fixed npm or Git template source."
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const toolingSchema = object({
|
|
517
|
+
apiReports: record(object({
|
|
518
|
+
entries: record(object({
|
|
519
|
+
entryPoint: string,
|
|
520
|
+
baseline: string
|
|
521
|
+
}, ["entryPoint", "baseline"])),
|
|
522
|
+
tsconfig: string
|
|
523
|
+
}, ["entries"])),
|
|
524
|
+
projectReferences: object({
|
|
525
|
+
enabled: boolean,
|
|
526
|
+
root: string,
|
|
527
|
+
projects: strings,
|
|
528
|
+
exclude: strings,
|
|
529
|
+
relations: array(object({
|
|
530
|
+
source: string,
|
|
531
|
+
target: string
|
|
532
|
+
}, ["source", "target"]))
|
|
533
|
+
}),
|
|
534
|
+
commitlint: opaque,
|
|
535
|
+
eslint: opaque,
|
|
536
|
+
stylelint: opaque,
|
|
537
|
+
lintStaged: object({
|
|
538
|
+
repoCommand: string,
|
|
539
|
+
config: opaque
|
|
540
|
+
}),
|
|
541
|
+
tsconfig: object({
|
|
542
|
+
extends: union(string, strings),
|
|
543
|
+
compilerOptions: record(opaque),
|
|
544
|
+
include: strings,
|
|
545
|
+
exclude: strings,
|
|
546
|
+
files: strings,
|
|
547
|
+
references: array(object({ path: string }, ["path"])),
|
|
548
|
+
compileOnSave: boolean
|
|
549
|
+
}),
|
|
550
|
+
vitest: object({
|
|
551
|
+
rootDir: string,
|
|
552
|
+
projectRoots: strings,
|
|
553
|
+
configCandidates: strings,
|
|
554
|
+
workspaceFile: string,
|
|
555
|
+
includeWorkspaceRootConfig: boolean,
|
|
556
|
+
coverageExclude: strings,
|
|
557
|
+
coverageEnabled: boolean,
|
|
558
|
+
coverageAll: boolean,
|
|
559
|
+
coverageSkipFull: boolean,
|
|
560
|
+
overrides: opaque
|
|
561
|
+
}),
|
|
562
|
+
vitestProject: object({
|
|
563
|
+
alias: array(object({
|
|
564
|
+
find: {
|
|
565
|
+
expected: "string | RegExp",
|
|
566
|
+
accepts: (value) => typeof value === "string" || value instanceof RegExp
|
|
567
|
+
},
|
|
568
|
+
replacement: string
|
|
569
|
+
}, ["find", "replacement"])),
|
|
570
|
+
globals: boolean,
|
|
571
|
+
testTimeout: positive,
|
|
572
|
+
environment: string
|
|
573
|
+
}),
|
|
574
|
+
husky: object({
|
|
575
|
+
preCommitCommand: string,
|
|
576
|
+
commitMsgCommand: string
|
|
577
|
+
})
|
|
578
|
+
});
|
|
579
|
+
//#endregion
|
|
580
|
+
//#region src/core/config/validation/index.ts
|
|
581
|
+
const selector = object({
|
|
582
|
+
packages: names,
|
|
583
|
+
paths: names,
|
|
584
|
+
tags: names,
|
|
585
|
+
private: boolean
|
|
586
|
+
});
|
|
587
|
+
const severity = choices("warn", "fail");
|
|
588
|
+
const cycles = object({
|
|
589
|
+
dependencyTypes,
|
|
590
|
+
severity
|
|
591
|
+
});
|
|
592
|
+
const boundaries = object({
|
|
593
|
+
tags: record(object({
|
|
594
|
+
packages: names,
|
|
595
|
+
paths: names,
|
|
596
|
+
private: boolean
|
|
597
|
+
})),
|
|
598
|
+
rules: array(object({
|
|
599
|
+
id: nonempty,
|
|
600
|
+
from: selector,
|
|
601
|
+
allow: array(selector),
|
|
602
|
+
dependencyTypes,
|
|
603
|
+
severity
|
|
604
|
+
}, [
|
|
605
|
+
"id",
|
|
606
|
+
"from",
|
|
607
|
+
"allow"
|
|
608
|
+
])),
|
|
609
|
+
cycles: {
|
|
610
|
+
...cycles,
|
|
611
|
+
expected: "false or cycle policy",
|
|
612
|
+
accepts: (value) => value === false || cycles.accepts(value)
|
|
613
|
+
},
|
|
614
|
+
exceptions: array(object({
|
|
615
|
+
rule: nonempty,
|
|
616
|
+
source: nonempty,
|
|
617
|
+
target: nonempty,
|
|
618
|
+
type: choices("dependencies", "devDependencies", "peerDependencies", "optionalDependencies"),
|
|
619
|
+
reason: nonempty
|
|
620
|
+
}, [
|
|
621
|
+
"rule",
|
|
622
|
+
"source",
|
|
623
|
+
"target",
|
|
624
|
+
"type",
|
|
625
|
+
"reason"
|
|
626
|
+
]))
|
|
627
|
+
});
|
|
628
|
+
const rootSchema = object({
|
|
629
|
+
presets: presetReferencesSchema,
|
|
630
|
+
commands: object(commandSchemas),
|
|
631
|
+
tooling: toolingSchema,
|
|
632
|
+
boundaries,
|
|
633
|
+
dependencyPolicy: admissionSchema,
|
|
634
|
+
installationSecurity: installationSecuritySchema,
|
|
635
|
+
codeowners: object({ owners: record(names) }, ["owners"])
|
|
636
|
+
});
|
|
637
|
+
var ConfigValidationError = class extends Error {
|
|
638
|
+
diagnostics;
|
|
639
|
+
code = "REPOCTL_CONFIG_INVALID";
|
|
640
|
+
constructor(diagnostics) {
|
|
641
|
+
super(diagnostics.map((item) => `${item.id}: ${item.path || "<root>"} (${item.actualType}); ${item.suggestion}`).join("\n"));
|
|
642
|
+
this.diagnostics = diagnostics;
|
|
643
|
+
this.name = "ConfigValidationError";
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
/** Validate owned fields only. C12 metadata and environment layers retain their native shape. */
|
|
647
|
+
function validateMonorepoConfig(value) {
|
|
648
|
+
const diagnostics = [];
|
|
649
|
+
if (!isRecord(value)) {
|
|
650
|
+
validateSchema(value === void 0 ? null : value, rootSchema, "", diagnostics);
|
|
651
|
+
return diagnostics;
|
|
652
|
+
}
|
|
653
|
+
validateSchema(Object.fromEntries(Object.entries(value).filter(([key]) => key !== "extends" && !key.startsWith("$") && key !== "_layers")), rootSchema, "", diagnostics);
|
|
654
|
+
validateTemplateSources(value, diagnostics);
|
|
655
|
+
const upgrade = isRecord(value["commands"]) && isRecord(value["commands"]["upgrade"]) ? value["commands"]["upgrade"] : void 0;
|
|
656
|
+
if (upgrade?.["overwrite"] === true && (upgrade["noOverwrite"] === true || upgrade["skipOverwrite"] === true)) diagnostics.push({
|
|
657
|
+
id: "config.conflict",
|
|
658
|
+
path: "commands.upgrade.overwrite",
|
|
659
|
+
actualType: "boolean",
|
|
660
|
+
expected: "one overwrite policy",
|
|
661
|
+
suggestion: "Choose overwrite or noOverwrite/skipOverwrite, not both."
|
|
662
|
+
});
|
|
663
|
+
return diagnostics;
|
|
664
|
+
}
|
|
665
|
+
function assertMonorepoConfig(value) {
|
|
666
|
+
const diagnostics = validateMonorepoConfig(value);
|
|
667
|
+
if (diagnostics.length) throw new ConfigValidationError(diagnostics);
|
|
668
|
+
}
|
|
669
|
+
//#endregion
|
|
670
|
+
//#region src/core/config/loading.ts
|
|
671
|
+
/** Check original exports before C12 merging can discard nulls or unknown empty values. */
|
|
672
|
+
function validatedConfigLoading(files, refresh) {
|
|
673
|
+
const fresh = refresh ? freshConfigLoading(files) : void 0;
|
|
674
|
+
const wrapped = /* @__PURE__ */ new WeakSet();
|
|
675
|
+
return {
|
|
676
|
+
...fresh,
|
|
677
|
+
jitiOptions: {
|
|
678
|
+
...fresh?.jitiOptions,
|
|
679
|
+
fsCache: false
|
|
680
|
+
},
|
|
681
|
+
async resolve(source, options) {
|
|
682
|
+
await fresh?.resolve?.(source, options);
|
|
683
|
+
const jiti = options.jiti;
|
|
684
|
+
if (jiti && (refresh || !wrapped.has(jiti))) {
|
|
685
|
+
wrapped.add(jiti);
|
|
686
|
+
const importConfig = jiti.import.bind(jiti);
|
|
687
|
+
jiti.import = async (filename, importOptions) => {
|
|
688
|
+
const result = await importConfig(filename, importOptions);
|
|
689
|
+
if (typeof result === "function") return (async (...args) => {
|
|
690
|
+
const config = await result(...args);
|
|
691
|
+
assertMonorepoConfig(config);
|
|
692
|
+
return config;
|
|
693
|
+
});
|
|
694
|
+
assertMonorepoConfig(result);
|
|
695
|
+
return result;
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region src/core/config/merge.ts
|
|
703
|
+
/** Preset boundaries merge objects and replace arrays, without changing C12's project merge. */
|
|
704
|
+
function mergeConfigValues(layers) {
|
|
705
|
+
const values = {};
|
|
706
|
+
const sources = {};
|
|
707
|
+
function clear(field) {
|
|
708
|
+
for (const key of Object.keys(sources)) if (key === field || key.startsWith(`${field}.`)) delete sources[key];
|
|
709
|
+
}
|
|
710
|
+
function merge(target, input, source, prefix = "", parents = /* @__PURE__ */ new Set()) {
|
|
711
|
+
const next = new Set(parents).add(input);
|
|
712
|
+
for (const [key, value] of Object.entries(input)) {
|
|
713
|
+
if (value === void 0) continue;
|
|
714
|
+
const field = appendConfigPath(prefix, key);
|
|
715
|
+
if (isRecord(value) && !next.has(value)) {
|
|
716
|
+
const existing = Object.hasOwn(target, key) && isRecord(target[key]);
|
|
717
|
+
if (!existing) clear(field);
|
|
718
|
+
else if (Object.keys(value).length) delete sources[field];
|
|
719
|
+
const child = existing ? target[key] : {};
|
|
720
|
+
Object.defineProperty(target, key, {
|
|
721
|
+
value: child,
|
|
722
|
+
enumerable: true,
|
|
723
|
+
configurable: true,
|
|
724
|
+
writable: true
|
|
725
|
+
});
|
|
726
|
+
merge(child, value, source, field, next);
|
|
727
|
+
if (!Object.keys(child).length) sources[field] = source;
|
|
728
|
+
} else {
|
|
729
|
+
clear(field);
|
|
730
|
+
Object.defineProperty(target, key, {
|
|
731
|
+
value: Array.isArray(value) ? [...value] : value,
|
|
732
|
+
enumerable: true,
|
|
733
|
+
configurable: true,
|
|
734
|
+
writable: true
|
|
735
|
+
});
|
|
736
|
+
sources[field] = source;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
for (const layer of layers) merge(values, layer.values, layer.source);
|
|
741
|
+
return {
|
|
742
|
+
values,
|
|
743
|
+
sources
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
//#endregion
|
|
747
|
+
//#region package.json
|
|
748
|
+
var name = "@icebreakers/monorepo";
|
|
749
|
+
var version = "5.7.0";
|
|
750
|
+
var package_default = {
|
|
751
|
+
name,
|
|
752
|
+
type: "module",
|
|
753
|
+
version,
|
|
754
|
+
description: "Core engine and programmatic APIs for repoctl",
|
|
755
|
+
author: "ice breaker <hi@sonofmagic.top>",
|
|
756
|
+
license: "MIT",
|
|
757
|
+
homepage: "https://repoctl.icebreaker.top",
|
|
758
|
+
repository: {
|
|
759
|
+
"type": "git",
|
|
760
|
+
"url": "git+https://github.com/icelib/repoctl.git",
|
|
761
|
+
"directory": "packages/monorepo"
|
|
762
|
+
},
|
|
763
|
+
bugs: { "url": "https://github.com/icelib/repoctl/issues" },
|
|
764
|
+
keywords: [
|
|
765
|
+
"monorepo",
|
|
766
|
+
"repoctl",
|
|
767
|
+
"tooling",
|
|
768
|
+
"icebreaker"
|
|
769
|
+
],
|
|
770
|
+
sideEffects: false,
|
|
771
|
+
exports: {
|
|
772
|
+
".": {
|
|
773
|
+
"types": "./dist/index.d.mts",
|
|
774
|
+
"default": "./dist/index.mjs"
|
|
775
|
+
},
|
|
776
|
+
"./cli": {
|
|
777
|
+
"types": "./dist/cli.d.mts",
|
|
778
|
+
"default": "./dist/cli.mjs"
|
|
779
|
+
},
|
|
780
|
+
"./tooling": {
|
|
781
|
+
"types": "./dist/tooling-entry.d.mts",
|
|
782
|
+
"default": "./dist/tooling-entry.mjs"
|
|
783
|
+
},
|
|
784
|
+
"./tsconfig": "./tsconfig.base.json",
|
|
785
|
+
"./tsconfig.json": "./tsconfig.base.json",
|
|
786
|
+
"./package.json": "./package.json"
|
|
787
|
+
},
|
|
788
|
+
main: "./dist/index.mjs",
|
|
789
|
+
module: "./dist/index.mjs",
|
|
790
|
+
types: "./dist/index.d.mts",
|
|
791
|
+
bin: {
|
|
792
|
+
"repo": "bin/repo.js",
|
|
793
|
+
"repoctl": "bin/repoctl.js"
|
|
794
|
+
},
|
|
795
|
+
files: [
|
|
796
|
+
"README.md",
|
|
797
|
+
"bin",
|
|
798
|
+
"dist",
|
|
799
|
+
"resources",
|
|
800
|
+
"tsconfig.base.json"
|
|
801
|
+
],
|
|
802
|
+
engines: { "node": ">=22.13.0" },
|
|
803
|
+
scripts: {
|
|
804
|
+
"dev": "tsdown --watch --sourcemap",
|
|
805
|
+
"build": "tsdown",
|
|
806
|
+
"test": "vitest run",
|
|
807
|
+
"test:dev": "vitest",
|
|
808
|
+
"typecheck": "pnpm --filter @icebreakers/monorepo-templates build && node ../../node_modules/typescript/bin/tsc -p tsconfig.json",
|
|
809
|
+
"tsd": "pnpm build && tsd --files test-d/**/*.test-d.ts",
|
|
810
|
+
"release": "pnpm publish",
|
|
811
|
+
"lint": "eslint .",
|
|
812
|
+
"lint:fix": "eslint . --fix"
|
|
813
|
+
},
|
|
814
|
+
peerDependencies: {
|
|
815
|
+
"@commitlint/cli": "catalog:",
|
|
816
|
+
"eslint": "^9.0.0 || ^10.0.0",
|
|
817
|
+
"stylelint": "catalog:",
|
|
818
|
+
"typescript": "^5.0.0 || ^6.0.0"
|
|
819
|
+
},
|
|
820
|
+
peerDependenciesMeta: {
|
|
821
|
+
"@commitlint/cli": { "optional": true },
|
|
822
|
+
"eslint": { "optional": true },
|
|
823
|
+
"stylelint": { "optional": true },
|
|
824
|
+
"typescript": { "optional": true }
|
|
825
|
+
},
|
|
826
|
+
dependencies: {
|
|
827
|
+
"@arethetypeswrong/core": "0.18.5",
|
|
828
|
+
"@babel/parser": "^7.29.8",
|
|
829
|
+
"@icebreakers/commitlint-config": "workspace:*",
|
|
830
|
+
"@icebreakers/eslint-config": "workspace:*",
|
|
831
|
+
"@icebreakers/monorepo-templates": "workspace:*",
|
|
832
|
+
"@icebreakers/stylelint-config": "workspace:*",
|
|
833
|
+
"@npmcli/config": "10.14.0",
|
|
834
|
+
"@pnpm/find-workspace-dir": "^1000.1.5",
|
|
835
|
+
"@pnpm/logger": "^1100.0.0",
|
|
836
|
+
"@pnpm/types": "^1102.1.1",
|
|
837
|
+
"@pnpm/worker": "^1100.4.6",
|
|
838
|
+
"@pnpm/workspace.find-packages": "^1000.0.65",
|
|
839
|
+
"@pnpm/workspace.read-manifest": "^1000.3.1",
|
|
840
|
+
"c12": "^3.3.4",
|
|
841
|
+
"commander": "catalog:",
|
|
842
|
+
"comment-json": "catalog:",
|
|
843
|
+
"consola": "^3.4.2",
|
|
844
|
+
"cross-spawn": "^7.0.6",
|
|
845
|
+
"esbuild": "catalog:",
|
|
846
|
+
"git-url-parse": "^16.1.0",
|
|
847
|
+
"json5": "^2.2.3",
|
|
848
|
+
"klaw": "^4.1.0",
|
|
849
|
+
"lint-staged": "^17.6.0",
|
|
850
|
+
"micromatch": "^4.0.8",
|
|
851
|
+
"node-diff3": "~3.1.2",
|
|
852
|
+
"p-queue": "^9.3.3",
|
|
853
|
+
"pacote": "21.5.1",
|
|
854
|
+
"pathe": "^2.0.3",
|
|
855
|
+
"picocolors": "^1.1.1",
|
|
856
|
+
"publint": "0.3.25",
|
|
857
|
+
"semver": "catalog:",
|
|
858
|
+
"simple-git": "^3.36.0",
|
|
859
|
+
"tar": "7.5.22",
|
|
860
|
+
"tinyglobby": "^0.2.17",
|
|
861
|
+
"validate-npm-package-name": "^7.0.2",
|
|
862
|
+
"vitest": "catalog:",
|
|
863
|
+
"yaml": "catalog:"
|
|
864
|
+
},
|
|
865
|
+
devDependencies: {
|
|
866
|
+
"@microsoft/api-extractor": "7.52.12",
|
|
867
|
+
"@types/cross-spawn": "^6.0.6",
|
|
868
|
+
"@types/klaw": "^3.0.8",
|
|
869
|
+
"@types/micromatch": "^4.0.10",
|
|
870
|
+
"@types/npmcli__config": "^6.0.4",
|
|
871
|
+
"@types/pacote": "^11.1.8",
|
|
872
|
+
"@types/semver": "catalog:",
|
|
873
|
+
"@types/validate-npm-package-name": "^4.0.2",
|
|
874
|
+
"ci-info": "^4.4.0",
|
|
875
|
+
"fdir": "^6.5.0",
|
|
876
|
+
"knip": "6.39.0"
|
|
877
|
+
},
|
|
878
|
+
publishConfig: {
|
|
879
|
+
"access": "public",
|
|
880
|
+
"registry": "https://registry.npmjs.org"
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
//#endregion
|
|
884
|
+
//#region src/core/file-transaction/paths.ts
|
|
885
|
+
function hash(content) {
|
|
886
|
+
return createHash("sha256").update(content).digest("hex");
|
|
887
|
+
}
|
|
888
|
+
async function canonicalDirectory(directory) {
|
|
889
|
+
const requested = path.normalize(directory);
|
|
890
|
+
try {
|
|
891
|
+
const resolved = path.normalize(await realpath(requested));
|
|
892
|
+
if (!(await lstat(resolved)).isDirectory()) throw new Error(`Not a directory: ${directory}`);
|
|
893
|
+
return resolved;
|
|
894
|
+
} catch (error) {
|
|
895
|
+
if (error.code !== "ENOENT") throw error;
|
|
896
|
+
const parent = path.dirname(requested);
|
|
897
|
+
const networkRoot = /^\/\/[^/]+(?:\/[^/]+)?\/?$/.test(requested);
|
|
898
|
+
if (parent === requested || path.parse(requested).root === requested || networkRoot) throw error;
|
|
899
|
+
return path.join(await canonicalDirectory(parent), path.basename(requested));
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
function relativeFile(relative) {
|
|
903
|
+
if (typeof relative !== "string" || !relative || path.isAbsolute(relative) || relative.includes("\\") || relative.split("/").some((part) => !part || [
|
|
904
|
+
".",
|
|
905
|
+
"..",
|
|
906
|
+
".git"
|
|
907
|
+
].includes(part))) throw new Error(`Unsafe upgrade path: ${relative}`);
|
|
908
|
+
return relative;
|
|
909
|
+
}
|
|
910
|
+
/** Reject linked components and non-files; missing parents are valid planned additions. */
|
|
911
|
+
async function checkedFile(root, relative, owned) {
|
|
912
|
+
relativeFile(relative);
|
|
913
|
+
if (await canonicalDirectory(root) !== root) throw new Error(`Upgrade root changed: ${root}`);
|
|
914
|
+
let current = root;
|
|
915
|
+
const parts = relative.split("/");
|
|
916
|
+
for (const [index, part] of parts.entries()) {
|
|
917
|
+
current = path.join(current, part);
|
|
918
|
+
try {
|
|
919
|
+
const info = await lstat(current, { bigint: true });
|
|
920
|
+
const ownLink = owned && info.ino === owned.ino && info.dev === owned.dev;
|
|
921
|
+
if (info.isSymbolicLink() || (index < parts.length - 1 ? !info.isDirectory() : !info.isFile() || info.nlink !== 1n && !ownLink)) throw new Error(`Linked or non-file upgrade target: ${relative}`);
|
|
922
|
+
} catch (error) {
|
|
923
|
+
if (error.code !== "ENOENT") throw error;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return path.join(root, relative);
|
|
927
|
+
}
|
|
928
|
+
async function readOptional(root, relative, owned) {
|
|
929
|
+
const filename = await checkedFile(root, relative, owned);
|
|
930
|
+
try {
|
|
931
|
+
return await readFile(filename);
|
|
932
|
+
} catch (error) {
|
|
933
|
+
if (error.code === "ENOENT") return null;
|
|
934
|
+
throw error;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region src/core/presets/files.ts
|
|
939
|
+
const presetManifestName = "repoctl.preset.json";
|
|
940
|
+
const hashPresetFile = (content) => createHash("sha256").update(content).digest("hex");
|
|
941
|
+
/** Portable relative paths; preset declarations cannot escape their package or target root. */
|
|
942
|
+
function presetRelativePath(value) {
|
|
943
|
+
if (!value || value !== value.trim() || value.includes("\\") || /[:*?"<>|]/u.test(value) || Array.from(value).some((character) => character.charCodeAt(0) < 32) || path.isAbsolute(value) || value.split("/").some((part) => !part || part === "." || part === ".." || /[. ]$/u.test(part) || /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/iu.test(part))) throw new Error("Preset paths must be portable relative file paths without parent traversal.");
|
|
944
|
+
return value;
|
|
945
|
+
}
|
|
946
|
+
/** Package roots may be pnpm links; symlinks inside the package are never followed. */
|
|
947
|
+
async function readPresetFile(root, relative) {
|
|
948
|
+
const parts = presetRelativePath(relative).split("/");
|
|
949
|
+
let filename = root;
|
|
950
|
+
for (const [index, part] of parts.entries()) {
|
|
951
|
+
filename = path.join(filename, part);
|
|
952
|
+
const info = await lstat(filename);
|
|
953
|
+
if (info.isSymbolicLink() || (index === parts.length - 1 ? !info.isFile() : !info.isDirectory())) throw new Error(`Preset input is not an ordinary file path: ${relative}`);
|
|
954
|
+
if (index === parts.length - 1 && info.size > 1048576) throw new Error(`Preset input exceeds 1 MiB: ${relative}`);
|
|
955
|
+
}
|
|
956
|
+
if (path.normalize(await realpath(filename)) !== filename) throw new Error(`Preset input path changed: ${relative}`);
|
|
957
|
+
const content = await readFile(filename);
|
|
958
|
+
if (content.length > 1048576) throw new Error(`Preset input exceeds 1 MiB: ${relative}`);
|
|
959
|
+
return {
|
|
960
|
+
filename,
|
|
961
|
+
content,
|
|
962
|
+
hash: hashPresetFile(content)
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
function parsePresetJson(content, name) {
|
|
966
|
+
try {
|
|
967
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(content));
|
|
968
|
+
} catch {
|
|
969
|
+
throw new Error(`Preset input must be UTF-8 JSON: ${name}`);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
/** Resolve data paths only. Package exports and JavaScript entrypoints are never loaded. */
|
|
973
|
+
async function installedPresetDirectory(packageName, fromDirectory) {
|
|
974
|
+
const require = createRequire(path.join(fromDirectory, "__repoctl_preset__.cjs"));
|
|
975
|
+
const localPaths = /* @__PURE__ */ new Set();
|
|
976
|
+
let parent = path.resolve(fromDirectory);
|
|
977
|
+
while (true) {
|
|
978
|
+
localPaths.add(path.join(parent, "node_modules"));
|
|
979
|
+
const next = path.dirname(parent);
|
|
980
|
+
if (next === parent) break;
|
|
981
|
+
parent = next;
|
|
982
|
+
}
|
|
983
|
+
for (const directory of require.resolve.paths(packageName) ?? []) {
|
|
984
|
+
if (!localPaths.has(path.normalize(directory))) continue;
|
|
985
|
+
const candidate = path.join(directory, packageName);
|
|
986
|
+
try {
|
|
987
|
+
const root = path.normalize(await realpath(candidate));
|
|
988
|
+
if ((await lstat(root)).isDirectory()) return root;
|
|
989
|
+
} catch (error) {
|
|
990
|
+
if (!["ENOENT", "ENOTDIR"].includes(error.code ?? "")) throw error;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
//#endregion
|
|
996
|
+
//#region src/commands/tooling-capabilities/registry.ts
|
|
997
|
+
const capabilities = [{
|
|
998
|
+
id: "playwright",
|
|
999
|
+
version: 1,
|
|
1000
|
+
description: "Add an independent Chromium E2E workspace to an existing Vue/React Vite app.",
|
|
1001
|
+
requirements: [
|
|
1002
|
+
"A named Vue or React Vite workspace",
|
|
1003
|
+
"build and preview scripts",
|
|
1004
|
+
"An explicit route, click target and expected text"
|
|
1005
|
+
]
|
|
1006
|
+
}, {
|
|
1007
|
+
id: "storybook",
|
|
1008
|
+
version: 1,
|
|
1009
|
+
description: "Add optional stories and headless play tests for an existing Vue/React component library.",
|
|
1010
|
+
requirements: ["A named Vue 3 or React 18/19 component library with a build script", "An explicit named component export and interaction example"]
|
|
1011
|
+
}];
|
|
1012
|
+
/** Discovery is static: it never imports project configuration or installs a browser. */
|
|
1013
|
+
function listToolingCapabilities() {
|
|
1014
|
+
return structuredClone(capabilities);
|
|
1015
|
+
}
|
|
1016
|
+
//#endregion
|
|
1017
|
+
//#region src/core/presets/assets.ts
|
|
1018
|
+
const rootAssets = /* @__PURE__ */ new Set([
|
|
1019
|
+
".editorconfig",
|
|
1020
|
+
".gitattributes",
|
|
1021
|
+
".gitignore",
|
|
1022
|
+
".npmrc",
|
|
1023
|
+
"commitlint.config.cjs",
|
|
1024
|
+
"commitlint.config.js",
|
|
1025
|
+
"commitlint.config.mjs",
|
|
1026
|
+
"eslint.config.js",
|
|
1027
|
+
"eslint.config.mjs",
|
|
1028
|
+
"eslint.config.ts",
|
|
1029
|
+
"lint-staged.config.js",
|
|
1030
|
+
"lint-staged.config.mjs",
|
|
1031
|
+
"stylelint.config.cjs",
|
|
1032
|
+
"stylelint.config.js",
|
|
1033
|
+
"stylelint.config.mjs",
|
|
1034
|
+
"tsconfig.base.json",
|
|
1035
|
+
"tsconfig.json",
|
|
1036
|
+
"turbo.json",
|
|
1037
|
+
"vitest.config.ts",
|
|
1038
|
+
"vitest.workspace.ts"
|
|
1039
|
+
]);
|
|
1040
|
+
/** Organization packages manage engineering files, never business code or dependency manifests. */
|
|
1041
|
+
function presetAssetTarget(value) {
|
|
1042
|
+
const target = presetRelativePath(value);
|
|
1043
|
+
if (rootAssets.has(target) || /^\.github\/(?:workflows\/[^/]+\.ya?ml|ISSUE_TEMPLATE\/[^/]+\.(?:ya?ml|md)|PULL_REQUEST_TEMPLATE\.md)$/u.test(target) || /^\.vscode\/(?:settings|extensions|tasks)\.json$/u.test(target) || /^scripts\/.+\.(?:[cm]?js|ts|sh)$/u.test(target) && !target.split("/").some((part) => part === "node_modules" || part === ".git")) return target;
|
|
1044
|
+
throw new Error("Preset assets must target supported root tooling files, GitHub/VS Code configuration, or engineering scripts.");
|
|
1045
|
+
}
|
|
1046
|
+
//#endregion
|
|
1047
|
+
//#region src/core/presets/manifest.ts
|
|
1048
|
+
const templateValue = commandSchemas.create.fields["templateMap"].values;
|
|
1049
|
+
const schema = object({
|
|
1050
|
+
schemaVersion: {
|
|
1051
|
+
expected: "1",
|
|
1052
|
+
accepts: (value) => value === 1
|
|
1053
|
+
},
|
|
1054
|
+
requires: object({ repoctl: {
|
|
1055
|
+
expected: "semantic version range",
|
|
1056
|
+
accepts: (value) => typeof value === "string" && Boolean(validRange(value))
|
|
1057
|
+
} }, ["repoctl"]),
|
|
1058
|
+
extends: presetReferencesSchema,
|
|
1059
|
+
config: opaque,
|
|
1060
|
+
templates: record({
|
|
1061
|
+
...templateValue,
|
|
1062
|
+
expected: "template definition object",
|
|
1063
|
+
accepts: isRecord
|
|
1064
|
+
}),
|
|
1065
|
+
capabilities: array(object({
|
|
1066
|
+
id: nonempty,
|
|
1067
|
+
reason: string
|
|
1068
|
+
}, ["id"])),
|
|
1069
|
+
assets: array(object({
|
|
1070
|
+
source: nonempty,
|
|
1071
|
+
target: nonempty
|
|
1072
|
+
}, ["source", "target"]))
|
|
1073
|
+
}, ["schemaVersion", "requires"]);
|
|
1074
|
+
function parseOrganizationPresetManifest(value) {
|
|
1075
|
+
const diagnostics = [];
|
|
1076
|
+
validateSchema(value, schema, "preset", diagnostics);
|
|
1077
|
+
if (diagnostics.length) throw new ConfigValidationError(diagnostics);
|
|
1078
|
+
const manifest = value;
|
|
1079
|
+
if (manifest.config !== void 0) {
|
|
1080
|
+
assertMonorepoConfig(manifest.config);
|
|
1081
|
+
if (Object.keys(manifest.config).some((key) => key === "presets" || key === "extends" || key === "_layers" || key.startsWith("$"))) throw new Error("Use preset.extends for package references; preset.config contains resolved repoctl values only.");
|
|
1082
|
+
if (manifest.config.commands?.create?.templatesDir !== void 0 || manifest.config.commands?.create?.templateMap !== void 0) throw new Error("Declare package templates in preset.templates so their source identity remains explicit.");
|
|
1083
|
+
}
|
|
1084
|
+
const capabilities = new Set(listToolingCapabilities().map((item) => item.id));
|
|
1085
|
+
const selected = /* @__PURE__ */ new Set();
|
|
1086
|
+
for (const recommendation of manifest.capabilities ?? []) {
|
|
1087
|
+
if (!capabilities.has(recommendation.id) || selected.has(recommendation.id)) throw new Error("Preset capability recommendations must use unique supported capability IDs.");
|
|
1088
|
+
selected.add(recommendation.id);
|
|
1089
|
+
}
|
|
1090
|
+
const targets = /* @__PURE__ */ new Set();
|
|
1091
|
+
for (const asset of manifest.assets ?? []) {
|
|
1092
|
+
presetRelativePath(asset.source);
|
|
1093
|
+
presetAssetTarget(asset.target);
|
|
1094
|
+
if (targets.has(asset.target)) throw new Error("Each preset asset target must be declared once.");
|
|
1095
|
+
targets.add(asset.target);
|
|
1096
|
+
}
|
|
1097
|
+
for (const [key, template] of Object.entries(manifest.templates ?? {})) {
|
|
1098
|
+
if (!key.trim() || key !== key.trim()) throw new Error("Preset template keys must be nonempty and contain no surrounding whitespace.");
|
|
1099
|
+
presetRelativePath(template.source);
|
|
1100
|
+
presetRelativePath(template.target);
|
|
1101
|
+
if ("remote" in template) throw new Error("Preset templates use the exact npm package declaring them; external remote overrides are not supported.");
|
|
1102
|
+
}
|
|
1103
|
+
return manifest;
|
|
1104
|
+
}
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region src/core/presets/load.ts
|
|
1107
|
+
/** Read installed data only: no importing package entrypoints, download, cache write or lifecycle execution. */
|
|
1108
|
+
async function resolveOrganizationPresets(cwd, references) {
|
|
1109
|
+
const result = {
|
|
1110
|
+
workspaceDir: normalize(path$1.resolve(cwd)),
|
|
1111
|
+
layers: [],
|
|
1112
|
+
diagnostics: [],
|
|
1113
|
+
inputs: [],
|
|
1114
|
+
locations: []
|
|
1115
|
+
};
|
|
1116
|
+
if (!Array.isArray(references)) {
|
|
1117
|
+
result.diagnostics.push({
|
|
1118
|
+
id: "preset.invalid-reference",
|
|
1119
|
+
status: "fail",
|
|
1120
|
+
path: "presets",
|
|
1121
|
+
source: null,
|
|
1122
|
+
detail: "Preset references must be an array of exact npm package identities."
|
|
1123
|
+
});
|
|
1124
|
+
return result;
|
|
1125
|
+
}
|
|
1126
|
+
const invalid = [];
|
|
1127
|
+
validateSchema(references, presetReferencesSchema, "presets", invalid);
|
|
1128
|
+
if (invalid.length || references.length > 64) {
|
|
1129
|
+
result.diagnostics.push(...invalid.map((item) => ({
|
|
1130
|
+
id: "preset.invalid-reference",
|
|
1131
|
+
status: "fail",
|
|
1132
|
+
path: item.path,
|
|
1133
|
+
source: null,
|
|
1134
|
+
detail: item.suggestion
|
|
1135
|
+
})));
|
|
1136
|
+
if (references.length > 64) result.diagnostics.push({
|
|
1137
|
+
id: "preset.limit",
|
|
1138
|
+
status: "fail",
|
|
1139
|
+
path: "presets",
|
|
1140
|
+
source: null,
|
|
1141
|
+
detail: "A project can reference at most 64 presets."
|
|
1142
|
+
});
|
|
1143
|
+
return result;
|
|
1144
|
+
}
|
|
1145
|
+
if (!references.length) return result;
|
|
1146
|
+
const workspaceDir = await canonicalDirectory(await findWorkspaceDir(cwd) ?? cwd);
|
|
1147
|
+
result.workspaceDir = workspaceDir;
|
|
1148
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
1149
|
+
const versions = /* @__PURE__ */ new Map();
|
|
1150
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1151
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1152
|
+
async function readJson(root, relative) {
|
|
1153
|
+
const file = await readPresetFile(root, relative);
|
|
1154
|
+
const previous = inputs.get(file.filename);
|
|
1155
|
+
if (previous && previous !== file.hash) throw new Error("A preset input changed while resolving its dependencies.");
|
|
1156
|
+
inputs.set(file.filename, file.hash);
|
|
1157
|
+
return {
|
|
1158
|
+
file,
|
|
1159
|
+
value: parsePresetJson(file.content, relative)
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
const diagnostic = (id, field, source, detail, status = "fail") => {
|
|
1163
|
+
result.diagnostics.push({
|
|
1164
|
+
id,
|
|
1165
|
+
status,
|
|
1166
|
+
path: field,
|
|
1167
|
+
source,
|
|
1168
|
+
detail
|
|
1169
|
+
});
|
|
1170
|
+
};
|
|
1171
|
+
async function visit(reference, from, consumer, field, chain) {
|
|
1172
|
+
const id = `${reference.packageName}@${reference.version}`;
|
|
1173
|
+
if (chain.includes(id)) {
|
|
1174
|
+
diagnostic("preset.cycle", field, id, `Preset dependency cycle: ${[...chain, id].join(" -> ")}`);
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
if (chain.length >= 16 || !visited.has(id) && visited.size >= 64) {
|
|
1178
|
+
diagnostic("preset.limit", field, id, "Preset resolution allows at most 16 dependency levels and 64 packages.");
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
visited.add(id);
|
|
1182
|
+
if (versions.has(reference.packageName) && versions.get(reference.packageName) !== reference.version) {
|
|
1183
|
+
diagnostic("preset.conflicting-version", field, id, "The same preset package cannot contribute multiple versions to one project.");
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
const dependencies = isRecord(consumer) && isRecord(consumer["dependencies"]) ? consumer["dependencies"] : {};
|
|
1187
|
+
const development = isRecord(consumer) && isRecord(consumer["devDependencies"]) ? consumer["devDependencies"] : {};
|
|
1188
|
+
if (dependencies[reference.packageName] !== reference.version && development[reference.packageName] !== reference.version) {
|
|
1189
|
+
diagnostic("preset.invalid-reference", field, id, "Declare the preset as an exact dependency in the consuming package.json before referencing it.");
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
try {
|
|
1193
|
+
const directory = await installedPresetDirectory(reference.packageName, from);
|
|
1194
|
+
if (!directory) {
|
|
1195
|
+
diagnostic("preset.missing-package", field, id, "The referenced preset is not installed. Install the declared dependency explicitly, then inspect again.");
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
result.locations.push({
|
|
1199
|
+
packageName: reference.packageName,
|
|
1200
|
+
fromDirectory: from,
|
|
1201
|
+
directory
|
|
1202
|
+
});
|
|
1203
|
+
const metadata = await readJson(directory, "package.json");
|
|
1204
|
+
if (!isRecord(metadata.value) || metadata.value["name"] !== reference.packageName || metadata.value["version"] !== reference.version) {
|
|
1205
|
+
diagnostic("preset.version-mismatch", field, id, "The installed package name/version does not match the exact preset reference.");
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
const contents = await readJson(directory, presetManifestName);
|
|
1209
|
+
const manifest = parseOrganizationPresetManifest(contents.value);
|
|
1210
|
+
if (!satisfies(version, manifest.requires.repoctl)) {
|
|
1211
|
+
diagnostic("preset.incompatible", field, id, "The installed repoctl version does not satisfy this preset’s requires.repoctl range.");
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
const source = {
|
|
1215
|
+
...reference,
|
|
1216
|
+
id,
|
|
1217
|
+
directory,
|
|
1218
|
+
manifestFile: contents.file.filename,
|
|
1219
|
+
manifestHash: contents.file.hash,
|
|
1220
|
+
packageJsonHash: metadata.file.hash
|
|
1221
|
+
};
|
|
1222
|
+
const prior = seen.get(id);
|
|
1223
|
+
if (prior) {
|
|
1224
|
+
if (prior.manifestHash !== source.manifestHash || prior.packageJsonHash !== source.packageJsonHash) diagnostic("preset.invalid-manifest", field, id, "The same fixed package identity resolves to different installed contents.");
|
|
1225
|
+
else diagnostic("preset.duplicate", field, id, "This fixed preset was already loaded; its configuration is applied once.", "warn");
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
versions.set(reference.packageName, reference.version);
|
|
1229
|
+
for (const [index, child] of (manifest.extends ?? []).entries()) await visit(child, directory, metadata.value, `${field}.extends[${index}]`, [...chain, id]);
|
|
1230
|
+
seen.set(id, source);
|
|
1231
|
+
result.layers.push({
|
|
1232
|
+
source,
|
|
1233
|
+
manifest
|
|
1234
|
+
});
|
|
1235
|
+
} catch (error) {
|
|
1236
|
+
diagnostic("preset.invalid-manifest", field, id, error instanceof Error ? error.message : "The installed preset could not be read as validated JSON.");
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
try {
|
|
1240
|
+
const root = await readJson(workspaceDir, "package.json");
|
|
1241
|
+
for (const [index, reference] of references.entries()) await visit(reference, workspaceDir, root.value, `presets[${index}]`, []);
|
|
1242
|
+
} catch {
|
|
1243
|
+
diagnostic("preset.invalid-reference", "presets", null, "Preset references require a readable workspace package.json with exact dependency declarations.");
|
|
1244
|
+
}
|
|
1245
|
+
result.inputs = [...inputs].map(([filename, hash]) => ({
|
|
1246
|
+
path: filename,
|
|
1247
|
+
hash
|
|
1248
|
+
})).sort((left, right) => left.path.localeCompare(right.path));
|
|
1249
|
+
return result;
|
|
1250
|
+
}
|
|
1251
|
+
//#endregion
|
|
1252
|
+
//#region src/core/config.ts
|
|
1253
|
+
var config_exports = /* @__PURE__ */ __exportAll({
|
|
1254
|
+
configExtensions: () => configExtensions,
|
|
1255
|
+
defineMonorepoConfig: () => defineMonorepoConfig,
|
|
1256
|
+
getRepoctlConfigCandidates: () => getRepoctlConfigCandidates,
|
|
1257
|
+
loadMonorepoConfig: () => loadMonorepoConfig,
|
|
1258
|
+
loadMonorepoConfigDetails: () => loadMonorepoConfigDetails,
|
|
1259
|
+
resolveCommandConfig: () => resolveCommandConfig,
|
|
1260
|
+
resolveToolingConfig: () => resolveToolingConfig
|
|
1261
|
+
});
|
|
1262
|
+
/**
|
|
1263
|
+
* 简单的内存缓存,避免同一次命令中重复走磁盘加载配置。
|
|
1264
|
+
*/
|
|
1265
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1266
|
+
const configExtensions = [
|
|
1267
|
+
"ts",
|
|
1268
|
+
"mts",
|
|
1269
|
+
"cts",
|
|
1270
|
+
"js",
|
|
1271
|
+
"mjs",
|
|
1272
|
+
"cjs"
|
|
1273
|
+
];
|
|
1274
|
+
function getRepoctlConfigCandidates(cwd) {
|
|
1275
|
+
return configExtensions.map((ext) => path.resolve(cwd, `repoctl.config.${ext}`));
|
|
1276
|
+
}
|
|
1277
|
+
function findConfigFiles(cwd) {
|
|
1278
|
+
return getRepoctlConfigCandidates(cwd).filter((file) => fs$1.existsSync(file));
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* 基于 c12 的通用配置加载逻辑,支持多种配置文件格式。
|
|
1282
|
+
*/
|
|
1283
|
+
async function loadConfigInternal(cwd, refresh = false) {
|
|
1284
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
1285
|
+
const { config, configFile, layers } = await loadConfig({
|
|
1286
|
+
name: "repoctl",
|
|
1287
|
+
cwd,
|
|
1288
|
+
rcFile: false,
|
|
1289
|
+
defaults: {},
|
|
1290
|
+
globalRc: false,
|
|
1291
|
+
packageJson: false,
|
|
1292
|
+
...validatedConfigLoading(dependencies, refresh)
|
|
1293
|
+
}).catch((error) => {
|
|
1294
|
+
if (error instanceof ConfigValidationError) throw error;
|
|
1295
|
+
throw new ConfigValidationError([{
|
|
1296
|
+
id: "config.load-failed",
|
|
1297
|
+
path: "",
|
|
1298
|
+
actualType: "unknown",
|
|
1299
|
+
expected: "loadable repoctl configuration",
|
|
1300
|
+
suggestion: "Check configuration syntax, imports and evaluation in your local editor."
|
|
1301
|
+
}]);
|
|
1302
|
+
});
|
|
1303
|
+
for (const layer of layers ?? []) assertMonorepoConfig(layer.config ?? {});
|
|
1304
|
+
assertMonorepoConfig(config ?? {});
|
|
1305
|
+
const matchedConfigFile = configFile && fs$1.existsSync(configFile) ? findConfigFiles(cwd).find((file) => path.basename(file).toLowerCase() === path.basename(configFile).toLowerCase()) : void 0;
|
|
1306
|
+
const files = await Promise.all([.../* @__PURE__ */ new Set([
|
|
1307
|
+
configFile,
|
|
1308
|
+
...(layers ?? []).map((layer) => layer.configFile),
|
|
1309
|
+
...dependencies
|
|
1310
|
+
])].filter((file) => Boolean(file && fs$1.existsSync(file))).map(async (file) => path.normalize(await realpath(file))));
|
|
1311
|
+
const file = matchedConfigFile ? await realpath(matchedConfigFile) : configFile && fs$1.existsSync(configFile) ? await realpath(configFile) : null;
|
|
1312
|
+
const presets = await resolveOrganizationPresets(cwd, config?.presets ?? []);
|
|
1313
|
+
const failures = presets.diagnostics.filter((item) => item.status === "fail");
|
|
1314
|
+
if (failures.length) throw new ConfigValidationError(failures.map((item) => ({
|
|
1315
|
+
id: "config.invalid-value",
|
|
1316
|
+
path: item.path,
|
|
1317
|
+
actualType: "preset",
|
|
1318
|
+
expected: "valid installed organization preset",
|
|
1319
|
+
suggestion: `${item.id}: ${item.detail}`
|
|
1320
|
+
})));
|
|
1321
|
+
const sourceLayers = [...presets.layers.map((layer) => ({
|
|
1322
|
+
source: {
|
|
1323
|
+
kind: "preset",
|
|
1324
|
+
file: layer.source.manifestFile,
|
|
1325
|
+
packageName: layer.source.packageName,
|
|
1326
|
+
version: layer.source.version
|
|
1327
|
+
},
|
|
1328
|
+
config: layer.manifest.config ?? {}
|
|
1329
|
+
})), {
|
|
1330
|
+
source: {
|
|
1331
|
+
kind: "project",
|
|
1332
|
+
file
|
|
1333
|
+
},
|
|
1334
|
+
config: config ?? {}
|
|
1335
|
+
}];
|
|
1336
|
+
const merged = mergeConfigValues(sourceLayers.map((layer) => ({
|
|
1337
|
+
source: layer.source,
|
|
1338
|
+
values: layer.config
|
|
1339
|
+
})));
|
|
1340
|
+
assertMonorepoConfig(merged.values);
|
|
1341
|
+
return {
|
|
1342
|
+
file,
|
|
1343
|
+
files: [.../* @__PURE__ */ new Set([...files, ...presets.inputs.map((input) => input.path)])],
|
|
1344
|
+
config: merged.values,
|
|
1345
|
+
rawLayers: (layers ?? []).map((layer) => layer.config ?? {}),
|
|
1346
|
+
sourceLayers,
|
|
1347
|
+
sources: merged.sources,
|
|
1348
|
+
presets
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* 为 `repoctl.config.ts` 提供类型提示的辅助函数。
|
|
1353
|
+
*
|
|
1354
|
+
* 推荐在用户项目中这样写:
|
|
1355
|
+
*
|
|
1356
|
+
* @example
|
|
1357
|
+
* ```ts
|
|
1358
|
+
* import { defineMonorepoConfig } from 'repoctl'
|
|
1359
|
+
*
|
|
1360
|
+
* export default defineMonorepoConfig({
|
|
1361
|
+
* tooling: {
|
|
1362
|
+
* vitest: {
|
|
1363
|
+
* includeWorkspaceRootConfig: false,
|
|
1364
|
+
* },
|
|
1365
|
+
* },
|
|
1366
|
+
* })
|
|
1367
|
+
* ```
|
|
1368
|
+
*/
|
|
1369
|
+
function defineMonorepoConfig(config) {
|
|
1370
|
+
return config;
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* 加载配置对象和实际命中的配置文件路径,供诊断和脚本集成使用。
|
|
1374
|
+
*
|
|
1375
|
+
* @param cwd 配置文件解析起点
|
|
1376
|
+
* @returns 配置文件路径和解析后的配置对象;未找到时 file 为 null、config 为空对象
|
|
1377
|
+
*/
|
|
1378
|
+
async function loadMonorepoConfigDetails(cwd, options = {}) {
|
|
1379
|
+
const key = path.resolve(cwd);
|
|
1380
|
+
if (options.refresh) cache.delete(key);
|
|
1381
|
+
if (!cache.has(key)) cache.set(key, loadConfigInternal(key, options.refresh));
|
|
1382
|
+
return cache.get(key);
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* 加载指定目录的 `repoctl.config.*`,并在当前进程内做内存缓存。
|
|
1386
|
+
*
|
|
1387
|
+
* @param cwd 配置文件解析起点
|
|
1388
|
+
* @returns 解析后的配置对象;未找到时返回空对象
|
|
1389
|
+
*/
|
|
1390
|
+
async function loadMonorepoConfig(cwd) {
|
|
1391
|
+
const { config } = await loadMonorepoConfigDetails(cwd);
|
|
1392
|
+
return config;
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* 获取单个命令对应的配置块。
|
|
1396
|
+
*
|
|
1397
|
+
* @param name 命令名称,对应 `repoctl.config.ts -> commands.<name>`
|
|
1398
|
+
* @param cwd 配置文件解析起点
|
|
1399
|
+
* @returns 对应命令配置;未配置时返回空对象
|
|
1400
|
+
*/
|
|
1401
|
+
async function resolveCommandConfig(name, cwd) {
|
|
1402
|
+
return ((await loadMonorepoConfig(await commandConfigDirectory(name, cwd))).commands ?? {})[name] ?? {};
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* 获取 `repoctl.config.ts` 中完整的 `tooling` 配置块。
|
|
1406
|
+
*
|
|
1407
|
+
* @param cwd 配置文件解析起点
|
|
1408
|
+
* @returns `tooling` 配置;未配置时返回空对象
|
|
1409
|
+
*/
|
|
1410
|
+
async function resolveToolingConfig(cwd) {
|
|
1411
|
+
return (await loadMonorepoConfig(cwd)).tooling ?? {};
|
|
1412
|
+
}
|
|
1413
|
+
//#endregion
|
|
1414
|
+
//#region src/tooling/shared.ts
|
|
1415
|
+
/**
|
|
1416
|
+
* 读取当前工作目录下的 `repoctl.config.*` 中 `tooling` 配置块。
|
|
1417
|
+
*
|
|
1418
|
+
* @param cwd 配置文件解析起点。默认使用 `process.cwd()`
|
|
1419
|
+
* @returns 标准化后的 tooling 配置;未配置时返回空对象
|
|
1420
|
+
*
|
|
1421
|
+
* @example
|
|
1422
|
+
* ```ts
|
|
1423
|
+
* import { loadMonorepoToolingConfig } from 'repoctl/tooling'
|
|
1424
|
+
*
|
|
1425
|
+
* const tooling = await loadMonorepoToolingConfig()
|
|
1426
|
+
* console.log(tooling.vitest?.includeWorkspaceRootConfig)
|
|
1427
|
+
* ```
|
|
1428
|
+
*/
|
|
1429
|
+
async function loadMonorepoToolingConfig(cwd = process.cwd()) {
|
|
1430
|
+
return (await loadMonorepoConfig(cwd)).tooling ?? {};
|
|
1431
|
+
}
|
|
1432
|
+
async function loadToolingSection(key, cwd = process.cwd()) {
|
|
1433
|
+
return (await loadMonorepoToolingConfig(cwd))[key];
|
|
1434
|
+
}
|
|
1435
|
+
function resolveConfigInput(input) {
|
|
1436
|
+
return {
|
|
1437
|
+
cwd: input?.cwd ?? process.cwd(),
|
|
1438
|
+
options: input?.options
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
function isDefineConfigWrapper(input) {
|
|
1442
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) return false;
|
|
1443
|
+
return "cwd" in input || "options" in input;
|
|
1444
|
+
}
|
|
1445
|
+
//#endregion
|
|
1446
|
+
//#region src/tooling/tsconfig.ts
|
|
1447
|
+
const monorepoTsconfigPath = fileURLToPath(import.meta.resolve("@icebreakers/monorepo/tsconfig"));
|
|
1448
|
+
function mergeTsconfig(base, override) {
|
|
1449
|
+
if (!override) return base;
|
|
1450
|
+
return {
|
|
1451
|
+
...base,
|
|
1452
|
+
...override,
|
|
1453
|
+
...base.compilerOptions || override.compilerOptions ? { compilerOptions: {
|
|
1454
|
+
...base.compilerOptions ?? {},
|
|
1455
|
+
...override.compilerOptions ?? {}
|
|
1456
|
+
} } : {}
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
function loadBundledTsconfig() {
|
|
1460
|
+
const configContent = fs$1.readFileSync(monorepoTsconfigPath, "utf8");
|
|
1461
|
+
return parse$1(configContent);
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* 创建 monorepo 内置的 TypeScript 基线配置。
|
|
1465
|
+
*
|
|
1466
|
+
* @param options 额外覆盖项,会与包内置 `tsconfig.base.json` 合并
|
|
1467
|
+
* @returns 可直接写入或二次扩展的 `tsconfig.json` 配置对象
|
|
1468
|
+
*/
|
|
1469
|
+
function createMonorepoTsconfig(options = {}) {
|
|
1470
|
+
return mergeTsconfig(loadBundledTsconfig(), options);
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* 从 `repoctl.config.ts` 读取 `tooling.tsconfig`,并生成最终的 TypeScript 配置对象。
|
|
1474
|
+
*
|
|
1475
|
+
* @param input `cwd` 用于指定配置文件解析起点,`options` 用于追加运行时覆盖项
|
|
1476
|
+
* @returns 可直接写入或导出的 `tsconfig.json` 配置对象
|
|
1477
|
+
*/
|
|
1478
|
+
async function defineTsconfigConfig(input = {}) {
|
|
1479
|
+
const resolved = resolveConfigInput(input);
|
|
1480
|
+
return createMonorepoTsconfig(mergeTsconfig(await loadToolingSection("tsconfig", resolved.cwd) ?? {}, resolved.options));
|
|
1481
|
+
}
|
|
1482
|
+
//#endregion
|
|
1483
|
+
export { mergeConfigValues as A, presetPackageName as B, checkedFile as C, name as D, relativeFile as E, normalizeTemplateSourceRequest as F, commandConfigDirectory as G, validateSchema as H, registryUrl as I, sourceRequestKey as L, assertMonorepoConfig as M, validateMonorepoConfig as N, package_default as O, normalizeTemplateRemoteSource as P, templateSourcePath as R, canonicalDirectory as S, readOptional as T, appendConfigPath as U, presetVersion as V, splitConfigPath as W, listToolingCapabilities as _, loadToolingSection as a, presetRelativePath as b, config_exports as c, loadMonorepoConfig as d, loadMonorepoConfigDetails as f, presetAssetTarget as g, resolveOrganizationPresets as h, loadMonorepoToolingConfig as i, ConfigValidationError as j, version as k, defineMonorepoConfig as l, resolveToolingConfig as m, defineTsconfigConfig as n, resolveConfigInput as o, resolveCommandConfig as p, isDefineConfigWrapper as r, configExtensions as s, createMonorepoTsconfig as t, getRepoctlConfigCandidates as u, installedPresetDirectory as v, hash as w, readPresetFile as x, parsePresetJson as y, commandSchemas as z };
|