@icebreakers/monorepo 5.5.10 → 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-C811m80z.mjs → create-flow-CCr2hfSY.mjs} +103 -40
- 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 +1741 -111
- package/dist/index.mjs +60 -6
- 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 -1
- package/dist/transaction-DAhY8EpG.mjs +168 -0
- package/dist/tsconfig-CGntrzBM.mjs +1483 -0
- package/dist/{tooling-BfXlmCi-.mjs → vitest-DkGh4Ygo.mjs} +108 -167
- package/dist/workspace-tasks-CnB8kkS0.mjs +4435 -0
- package/package.json +25 -7
- 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 +4 -2
- 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 +26 -2
- package/dist/commands-CIzCAxyY.mjs +0 -5672
- package/dist/config-p842Knhq.mjs +0 -114
- package/dist/index-DDQKKYet.d.mts +0 -1025
- package/dist/types-m8JLwKzl.mjs +0 -499
- package/dist/workspace-MCKewElu.mjs +0 -123
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { i as
|
|
3
|
-
import { C as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { $ as WorkspaceGraphQueryError, At as exists, B as saveKnipBaseline, Bt as writeJSON, Dt as copy, Ft as outputJson, Gt as getWorkspacePackages, Ht as clearWorkspaceCache, I as getKnipConfigurationSuggestions, It as pathExists, J as getWorkspaceGraph, Lt as readJSON, M as formatEnvironmentCache, Mt as isIgnorableFsError, Nt as outputFile, Ot as ensureDir, P as checkEnvironmentCache, Pt as outputJSON, Q as whyWorkspaceDependency, R as planKnipCheck, Rt as readJson, Ut as getWorkspaceData, Vt as writeJson, W as analyzeTurboRuns, Wt as getWorkspacePackageSummaries, X as filterWorkspaceGraph, Z as getWorkspaceImpact, _ as planTemplateLink, _t as assetsDir, a as inspectWorkspaceOwners, b as planGenerate, bt as rootDir, c as loadTemplateInstanceRegistry, f as recoverTemplateUpgrade, ft as setByPath, g as applyTemplateLinkPlan, i as planCodeowners, kt as ensureFile, l as rebuildTemplateInstanceBaseline, m as planTemplateUpgrade, n as locateWorkspace, o as listTemplateInstances, p as applyTemplateUpgradePlan, qt as GitClient, r as applyCodeownersPlan, s as loadTemplateBaseline, t as getWorkspaceTaskCatalog, tt as resolveWorkspaceGraphNode, u as relocateTemplateInstance, vt as cliName, x as generators, xt as templatesDir, y as applyGeneratePlan, yt as packageDir, z as runKnipCheck, zt as remove } from "./workspace-tasks-CnB8kkS0.mjs";
|
|
2
|
+
import { a as resolveFullWorkspaceCheckPlan, c as verifyCommitMsg, f as logger, i as getKnownRepoCheckCommands, l as verifyPreCommit, o as resolveRecommendedCheckPlan, r as resolveAffectedCheckPlan, s as runRecommendedCheck, t as runCheckWithReport, u as verifyStagedTypecheck } from "./execute-Vi4qHe-D.mjs";
|
|
3
|
+
import { $ as GitHubApiError, A as resolveAffectedCheckMatrix, At as updateIssueTemplateConfig, B as syncSkills, Bt as generateAgenticTemplates, C as applyOrganizationPresetAssets, Ct as getCreateChoices, D as applyInstallSecurityPreset, E as planDevContainer, Et as resolveRemoteTemplateSource, F as upgradeMonorepo, Ft as cleanProjects, G as prepareStable, H as createReleasePullRequest, I as formatUpgradePlan, It as verifyPrePush, J as reconcileRelease, K as publishStable, L as checkTemplates, Lt as createTimestampFolderName, M as applyPublicApiUpdate, Mt as explainMonorepoConfig, N as planPublicApiUpdate, Nt as sanitizeConfigReport, O as planInstallSecurityPreset, Ot as resolveTemplateCatalog, P as formatPublicApiReport, Pt as validateConfigFile, Q as GitHubClient, R as getSkillTargetPaths, Rt as defaultAgenticBaseDir, S as detectMaintenanceVersionChange, St as resolveCreateNewProjectPlan, T as applyDevContainerPlan, Tt as templateMap, U as recoverUnpublished, V as repairReleaseNotes, Vt as loadAgenticTasks, W as releaseCi, X as exitPrerelease, Y as enterPrerelease, Z as releasePrerelease, _ as applyProjectReferencesPlan, _t as resolveReleaseBranches, a as planWorkspaceMove, at as initTooling, b as getMaintenanceWorkflow, bt as createNewProject, c as applyToolingCapability, ct as createContext, d as planTemplateValidation, dt as collectEnvSnapshot, et as parsePublishSummary, f as releaseSnapshot, ft as collectEnvSupportBundle, g as syncProjectReferences, gt as planUpgrade, h as checkProjectReferences, ht as planDoctorFix, i as applyWorkspaceMovePlan, it as initMetadata, j as checkPublicApi, jt as inspectMonorepoConfig, k as checkPeerDependencies, l as planToolingCapability, lt as collectEnvInfo, m as createReleasePlan, mt as applyDoctorFixPlan, n as applyWorkspaceRemovalPlan, nt as setVscodeBinaryMirror, o as applyWorkspaceArtifactPlan, ot as normalizeInitToolingTargets, p as createSnapshotPlan, pt as runDoctor, q as releaseStable, r as planWorkspaceRemoval, rt as init, s as planWorkspaceArtifact, st as initToolingTargets, u as validateTemplate, ut as collectEnvPaths, v as planProjectReferences, vt as applyUpgradePlan, w as planOrganizationPresetAssets, wt as getTemplateMap, x as prepareMaintenanceUpgrade, y as checkPackages, yt as applyCreateNewProjectPlan, z as skillTargets, zt as generateAgenticTemplate } from "./commands-TS8ABFdP.mjs";
|
|
4
|
+
import { D as name, M as assertMonorepoConfig, N as validateMonorepoConfig, _ as listToolingCapabilities, d as loadMonorepoConfig, f as loadMonorepoConfigDetails, h as resolveOrganizationPresets, i as loadMonorepoToolingConfig, j as ConfigValidationError, k as version, l as defineMonorepoConfig, m as resolveToolingConfig, n as defineTsconfigConfig, p as resolveCommandConfig, s as configExtensions, t as createMonorepoTsconfig, u as getRepoctlConfigCandidates } from "./tsconfig-CGntrzBM.mjs";
|
|
5
|
+
import { c as selectCommandOverrides, s as resolveCommandValues } from "./scan-4nboHNXP.mjs";
|
|
6
|
+
import { F as toWorkspaceAssetPath, I as toWorkspaceGitignorePath, N as isGitignoreFile, P as toPublishGitignorePath, S as checkDependencyAdmission, f as inspectInstallSecurity, i as hasTemplateDriftIssues, l as getDoctorRuleIds, r as formatTemplateDriftReport, t as checkTemplateDrift, x as checkWorkspaceBoundaries } from "./template-drift-BBhnrHY1.mjs";
|
|
7
|
+
import { a as createMonorepoCommitlintConfig, c as defineCommitlintConfig, d as createMonorepoLintStagedConfig, f as defineLintStagedConfig, i as defineVitestProjectConfig, l as defineEslintConfig, n as createMonorepoVitestProjectConfig, o as createMonorepoEslintConfig, r as defineVitestConfig, s as createMonorepoStylelintConfig, t as createMonorepoVitestConfig, u as defineStylelintConfig } from "./vitest-DkGh4Ygo.mjs";
|
|
8
|
+
import { i as applyDependencyFixPlan, r as planDependencyFix, t as checkDependencies } from "./deps-CUdI2DaB.mjs";
|
|
9
|
+
import { i as applyCatalogMigrationPlan, n as checkCatalogs, r as planCatalogMigration } from "./catalog-CDEyc1uA.mjs";
|
|
10
|
+
import crypto from "node:crypto";
|
|
11
|
+
import { Buffer } from "node:buffer";
|
|
12
|
+
//#region src/utils/hash.ts
|
|
13
|
+
function toHashInput(data) {
|
|
14
|
+
return typeof data === "string" || ArrayBuffer.isView(data) ? data : Buffer.from(data);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 生成给定内容的 md5 摘要。
|
|
18
|
+
*
|
|
19
|
+
* @param data 任意 `crypto.BinaryLike` 内容
|
|
20
|
+
* @returns 32 位十六进制 md5 字符串
|
|
21
|
+
*/
|
|
22
|
+
function getFileHash(data) {
|
|
23
|
+
const hashSum = crypto.createHash("md5");
|
|
24
|
+
hashSum.update(toHashInput(data));
|
|
25
|
+
return hashSum.digest("hex");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 对比两段内容的 md5,判断内容是否发生变化。
|
|
29
|
+
*
|
|
30
|
+
* @param src 当前内容
|
|
31
|
+
* @param dest 旧内容
|
|
32
|
+
* @returns 两者 md5 不一致时返回 `true`
|
|
33
|
+
*/
|
|
34
|
+
function isFileChanged(src, dest) {
|
|
35
|
+
try {
|
|
36
|
+
return getFileHash(src) !== getFileHash(dest);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
logger.error("Error calculating file hash:", err);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/utils/regexp.ts
|
|
44
|
+
const regexpSpecialCharacterPattern = /[|\\{}()[\]^$+*?.]/g;
|
|
45
|
+
const hyphenPattern = /-/g;
|
|
46
|
+
/**
|
|
47
|
+
* 逃逸正则表达式中所有特殊字符,避免被当做模式解析。
|
|
48
|
+
*/
|
|
49
|
+
function escapeStringRegexp(str) {
|
|
50
|
+
return str.replace(regexpSpecialCharacterPattern, "\\$&").replace(hyphenPattern, "\\x2d");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 判断字符串是否命中任意一个正则,用于过滤要同步的资产文件。
|
|
54
|
+
*/
|
|
55
|
+
function isMatch(str, arr) {
|
|
56
|
+
for (const reg of arr) if (reg.test(str)) return true;
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { ConfigValidationError, GitClient, GitHubApiError, GitHubClient, WorkspaceGraphQueryError, analyzeTurboRuns, applyCatalogMigrationPlan, applyCodeownersPlan, applyCreateNewProjectPlan, applyDependencyFixPlan, applyDevContainerPlan, applyDoctorFixPlan, applyGeneratePlan, applyInstallSecurityPreset, applyOrganizationPresetAssets, applyProjectReferencesPlan, applyPublicApiUpdate, applyTemplateLinkPlan, applyTemplateUpgradePlan, applyToolingCapability, applyUpgradePlan, applyWorkspaceArtifactPlan, applyWorkspaceMovePlan, applyWorkspaceRemovalPlan, assertMonorepoConfig, assetsDir, checkCatalogs, checkDependencies, checkDependencyAdmission, checkEnvironmentCache, checkPackages, checkPeerDependencies, checkProjectReferences, checkPublicApi, checkTemplateDrift, checkTemplates, checkWorkspaceBoundaries, cleanProjects, clearWorkspaceCache, cliName, collectEnvInfo, collectEnvPaths, collectEnvSnapshot, collectEnvSupportBundle, configExtensions, copy, createContext, createMonorepoCommitlintConfig, createMonorepoEslintConfig, createMonorepoLintStagedConfig, createMonorepoStylelintConfig, createMonorepoTsconfig, createMonorepoVitestConfig, createMonorepoVitestProjectConfig, createNewProject, createReleasePlan, createReleasePullRequest, createSnapshotPlan, createTimestampFolderName, defaultAgenticBaseDir, defineCommitlintConfig, defineEslintConfig, defineLintStagedConfig, defineMonorepoConfig, defineStylelintConfig, defineTsconfigConfig, defineVitestConfig, defineVitestProjectConfig, detectMaintenanceVersionChange, ensureDir, ensureFile, enterPrerelease, escapeStringRegexp, exists, exitPrerelease, explainMonorepoConfig, filterWorkspaceGraph, formatEnvironmentCache, formatPublicApiReport, formatTemplateDriftReport, formatUpgradePlan, generateAgenticTemplate, generateAgenticTemplates, generators, getCreateChoices, getDoctorRuleIds, getFileHash, getKnipConfigurationSuggestions, getKnownRepoCheckCommands, getMaintenanceWorkflow, getRepoctlConfigCandidates, getSkillTargetPaths, getTemplateMap, getWorkspaceData, getWorkspaceGraph, getWorkspaceImpact, getWorkspacePackageSummaries, getWorkspacePackages, getWorkspaceTaskCatalog, hasTemplateDriftIssues, init, initMetadata, initTooling, initToolingTargets, inspectInstallSecurity, inspectMonorepoConfig, inspectWorkspaceOwners, isFileChanged, isGitignoreFile, isIgnorableFsError, isMatch, listTemplateInstances, listToolingCapabilities, loadAgenticTasks, loadMonorepoConfig, loadMonorepoConfigDetails, loadMonorepoToolingConfig, loadTemplateBaseline, loadTemplateInstanceRegistry, locateWorkspace, logger, normalizeInitToolingTargets, outputFile, outputJSON, outputJson, packageDir, name as packageName, parsePublishSummary, pathExists, planCatalogMigration, planCodeowners, planDependencyFix, planDevContainer, planDoctorFix, planGenerate, planInstallSecurityPreset, planKnipCheck, planOrganizationPresetAssets, planProjectReferences, planPublicApiUpdate, planTemplateLink, planTemplateUpgrade, planTemplateValidation, planToolingCapability, planUpgrade, planWorkspaceArtifact, planWorkspaceMove, planWorkspaceRemoval, prepareMaintenanceUpgrade, prepareStable, publishStable, readJSON, readJson, rebuildTemplateInstanceBaseline, reconcileRelease, recoverTemplateUpgrade, recoverUnpublished, releaseCi, releasePrerelease, releaseSnapshot, releaseStable, relocateTemplateInstance, remove, repairReleaseNotes, resolveAffectedCheckMatrix, resolveAffectedCheckPlan, resolveCommandConfig, resolveCommandValues, resolveCreateNewProjectPlan, resolveFullWorkspaceCheckPlan, resolveOrganizationPresets, resolveRecommendedCheckPlan, resolveReleaseBranches, resolveRemoteTemplateSource, resolveTemplateCatalog, resolveToolingConfig, resolveWorkspaceGraphNode, rootDir, runCheckWithReport, runDoctor, runKnipCheck, runRecommendedCheck, sanitizeConfigReport, saveKnipBaseline, selectCommandOverrides, setByPath, setVscodeBinaryMirror, skillTargets, syncProjectReferences, syncSkills, templateMap, templatesDir, toPublishGitignorePath, toWorkspaceAssetPath, toWorkspaceGitignorePath, updateIssueTemplateConfig, upgradeMonorepo, validateConfigFile, validateMonorepoConfig, validateTemplate, verifyCommitMsg, verifyPreCommit, verifyPrePush, verifyStagedTypecheck, version, whyWorkspaceDependency, writeJSON, writeJson };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { at as record, rt as hash } from "./workspace-tasks-CnB8kkS0.mjs";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
4
|
+
import YAML from "yaml";
|
|
5
|
+
//#region src/commands/check/knip/inputs.ts
|
|
6
|
+
const knipConfigNames = [
|
|
7
|
+
"knip.json",
|
|
8
|
+
"knip.jsonc",
|
|
9
|
+
".knip.json",
|
|
10
|
+
".knip.jsonc",
|
|
11
|
+
"knip.ts",
|
|
12
|
+
"knip.js",
|
|
13
|
+
"knip.config.ts",
|
|
14
|
+
"knip.config.js"
|
|
15
|
+
];
|
|
16
|
+
/** Track primary native configuration without treating source/dependency fixes as policy changes. */
|
|
17
|
+
async function knipConfigurationInputs(root, explicit) {
|
|
18
|
+
const packageJson = JSON.parse(await readFile(path.join(root, "package.json"), "utf8"));
|
|
19
|
+
const inputs = /* @__PURE__ */ new Map([["package.json#knip", hash(JSON.stringify(packageJson.knip ?? null))]]);
|
|
20
|
+
const candidates = new Set(explicit ? [explicit] : []);
|
|
21
|
+
if (!explicit) {
|
|
22
|
+
let directory = root;
|
|
23
|
+
while (true) {
|
|
24
|
+
for (const name of knipConfigNames) candidates.add(path.join(directory, name));
|
|
25
|
+
const parent = path.dirname(directory);
|
|
26
|
+
if (parent === directory) break;
|
|
27
|
+
directory = parent;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (const file of candidates) try {
|
|
31
|
+
if (!(await lstat(file)).isDirectory()) inputs.set(path.relative(root, file), hash(await readFile(file, "utf8")));
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (error.code !== "ENOENT") throw error;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const workspace = record(YAML.parse(await readFile(path.join(root, "pnpm-workspace.yaml"), "utf8")));
|
|
37
|
+
inputs.set("pnpm-workspace.yaml#packages", hash(JSON.stringify(workspace?.["packages"] ?? null)));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error.code !== "ENOENT") throw error;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
rootName: typeof packageJson.name === "string" ? packageJson.name : null,
|
|
43
|
+
configuration: [...inputs].sort(([a], [b]) => a.localeCompare(b)).map(([file, digest]) => ({
|
|
44
|
+
path: file,
|
|
45
|
+
hash: digest
|
|
46
|
+
}))
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { knipConfigurationInputs as t };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { I as registryUrl } from "./tsconfig-CGntrzBM.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { createWriteStream } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pipeline } from "node:stream/promises";
|
|
6
|
+
import Config from "@npmcli/config";
|
|
7
|
+
import definitionsModule from "@npmcli/config/lib/definitions/index.js";
|
|
8
|
+
import pacote from "pacote";
|
|
9
|
+
//#region src/core/template-source/npm.ts
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
async function npmTemplateConfiguration(source, cwd) {
|
|
12
|
+
const config = new Config({
|
|
13
|
+
...definitionsModule,
|
|
14
|
+
npmPath: path.dirname(require.resolve("@npmcli/config/package.json")),
|
|
15
|
+
argv: [],
|
|
16
|
+
cwd
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
await config.load();
|
|
20
|
+
if (!config.validate()) throw new Error("Invalid configuration.");
|
|
21
|
+
} catch {
|
|
22
|
+
throw new Error("Could not read valid npm configuration; check registry and scoped authentication in .npmrc.");
|
|
23
|
+
}
|
|
24
|
+
const scope = source.packageName.startsWith("@") ? source.packageName.split("/")[0] : void 0;
|
|
25
|
+
const registry = registryUrl(source.registry ?? (scope ? config.flat[`${scope}:registry`] : void 0) ?? config.flat["registry"]);
|
|
26
|
+
return {
|
|
27
|
+
registry,
|
|
28
|
+
options: {
|
|
29
|
+
...config.flat,
|
|
30
|
+
registry,
|
|
31
|
+
...scope ? { [`${scope}:registry`]: registry } : {}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function downloadNpmTemplate(source, directory, cwd, timeout, configuration) {
|
|
36
|
+
try {
|
|
37
|
+
const options = {
|
|
38
|
+
...configuration.options,
|
|
39
|
+
where: cwd,
|
|
40
|
+
cache: path.join(directory, "npm-cache"),
|
|
41
|
+
ignoreScripts: true,
|
|
42
|
+
fetchTimeout: timeout,
|
|
43
|
+
fetchRetries: 0,
|
|
44
|
+
retry: { retries: 0 }
|
|
45
|
+
};
|
|
46
|
+
const specifier = `${source.packageName}@${source.version}`;
|
|
47
|
+
const resolved = await pacote.manifest(specifier, options);
|
|
48
|
+
const integrity = resolved.dist?.integrity ?? resolved._integrity;
|
|
49
|
+
if (resolved.name !== source.packageName || resolved.version !== source.version || typeof integrity !== "string" || !integrity) throw new Error("The registry did not provide the requested version and integrity.");
|
|
50
|
+
const archive = path.join(directory, "archive.tgz");
|
|
51
|
+
await pacote.tarball.stream(specifier, async (stream) => {
|
|
52
|
+
await pipeline(stream, async function* limit(source) {
|
|
53
|
+
let bytes = 0;
|
|
54
|
+
for await (const chunk of source) {
|
|
55
|
+
bytes += chunk.length;
|
|
56
|
+
if (bytes > 67108864) throw new Error("Template archive exceeds 64 MiB.");
|
|
57
|
+
yield chunk;
|
|
58
|
+
}
|
|
59
|
+
}, createWriteStream(archive), { signal: AbortSignal.timeout(timeout) });
|
|
60
|
+
}, {
|
|
61
|
+
...options,
|
|
62
|
+
integrity
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
archive,
|
|
66
|
+
prefix: "package",
|
|
67
|
+
resolved: {
|
|
68
|
+
kind: "npm",
|
|
69
|
+
packageName: source.packageName,
|
|
70
|
+
requestedVersion: source.version,
|
|
71
|
+
version: resolved.version,
|
|
72
|
+
registry: configuration.registry,
|
|
73
|
+
integrity
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error.code === "EINTEGRITY") throw new Error("npm template integrity verification failed; no target files were created.");
|
|
78
|
+
throw new Error("npm template download failed. Verify the exact version, registry and scoped authentication in .npmrc, and network access; no target files were created.");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { downloadNpmTemplate, npmTemplateConfiguration };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { at as record, yt as packageDir } from "./workspace-tasks-CnB8kkS0.mjs";
|
|
2
|
+
import { findWorkspaceDir } from "@pnpm/find-workspace-dir";
|
|
3
|
+
import path from "pathe";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { readFile, realpath, stat } from "node:fs/promises";
|
|
6
|
+
import semver from "semver";
|
|
7
|
+
//#region src/commands/check/knip/plan.ts
|
|
8
|
+
const supportedKnip = ">=6.39.0 <7";
|
|
9
|
+
async function knipRoot(cwd) {
|
|
10
|
+
return path.resolve(await realpath(await findWorkspaceDir(cwd) ?? cwd));
|
|
11
|
+
}
|
|
12
|
+
async function planKnipCheck(cwd, options = {}) {
|
|
13
|
+
if ([
|
|
14
|
+
options.newOnly,
|
|
15
|
+
options.production,
|
|
16
|
+
options.strict
|
|
17
|
+
].some((value) => value !== void 0 && typeof value !== "boolean")) throw new Error("Knip newOnly, production and strict must be boolean options.");
|
|
18
|
+
if (options.newOnly && !options.baseline) throw new Error("Knip new-only mode requires an explicit baseline file.");
|
|
19
|
+
for (const value of [options.config, options.baseline]) if (value !== void 0 && (typeof value !== "string" || !value.trim())) throw new Error("Knip config and baseline paths must be non-empty strings.");
|
|
20
|
+
const timeoutMs = options.timeoutMs ?? 12e4;
|
|
21
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) throw new Error("Knip timeoutMs must be a positive integer.");
|
|
22
|
+
const root = await knipRoot(cwd);
|
|
23
|
+
const toolDirectory = path.join(root, "node_modules/knip");
|
|
24
|
+
let version = null;
|
|
25
|
+
let entry = null;
|
|
26
|
+
let status = "missing_tool";
|
|
27
|
+
try {
|
|
28
|
+
const manifest = JSON.parse(await readFile(path.join(toolDirectory, "package.json"), "utf8"));
|
|
29
|
+
version = typeof manifest.version === "string" ? manifest.version : null;
|
|
30
|
+
const bin = typeof manifest.bin === "string" ? manifest.bin : record(manifest.bin)?.["knip"];
|
|
31
|
+
const target = typeof bin === "string" ? path.resolve(toolDirectory, bin) : "";
|
|
32
|
+
const relative = path.relative(toolDirectory, target);
|
|
33
|
+
if (manifest.name !== "knip" || !version || !semver.satisfies(version, ">=6.39.0 <7") || !relative || relative.startsWith("../") || path.isAbsolute(relative) || !(await stat(target)).isFile()) status = "unsupported_tool";
|
|
34
|
+
else {
|
|
35
|
+
entry = target;
|
|
36
|
+
status = "ready";
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error.code !== "ENOENT") status = "unsupported_tool";
|
|
40
|
+
}
|
|
41
|
+
const config = options.config ? path.resolve(cwd, options.config) : null;
|
|
42
|
+
if (config && !(await stat(config)).isFile()) throw new Error("The explicit Knip configuration must be a file.");
|
|
43
|
+
const args = entry ? [
|
|
44
|
+
entry,
|
|
45
|
+
"--no-progress",
|
|
46
|
+
"--reporter",
|
|
47
|
+
path.join(packageDir, "resources/knip/reporter.mjs"),
|
|
48
|
+
...config ? ["--config", config] : [],
|
|
49
|
+
...options.production ? ["--production"] : [],
|
|
50
|
+
...options.strict ? ["--strict"] : []
|
|
51
|
+
] : [];
|
|
52
|
+
return {
|
|
53
|
+
schemaVersion: 1,
|
|
54
|
+
kind: "knip-check",
|
|
55
|
+
workspaceDir: root,
|
|
56
|
+
status,
|
|
57
|
+
tool: {
|
|
58
|
+
name: "knip",
|
|
59
|
+
version,
|
|
60
|
+
supported: supportedKnip,
|
|
61
|
+
entry
|
|
62
|
+
},
|
|
63
|
+
executable: process.execPath,
|
|
64
|
+
args,
|
|
65
|
+
config,
|
|
66
|
+
baseline: options.baseline ? path.resolve(root, options.baseline) : null,
|
|
67
|
+
newOnly: options.newOnly === true,
|
|
68
|
+
production: options.production === true || options.strict === true,
|
|
69
|
+
strict: options.strict === true,
|
|
70
|
+
timeoutMs,
|
|
71
|
+
guidance: status === "ready" ? [] : ["Install a supported workspace-local tool explicitly: pnpm add -Dw knip@^6.39.0", "This check never downloads Knip or falls back to a parent/global installation."]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { knipRoot, planKnipCheck };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { U as stopCheckProcessTree } from "./workspace-tasks-CnB8kkS0.mjs";
|
|
2
|
+
import { t as knipConfigurationInputs } from "./inputs-_xIVONmB.mjs";
|
|
3
|
+
import { planKnipCheck } from "./plan-B5aE_WNF.mjs";
|
|
4
|
+
import { i as summarizeKnip, r as parseKnipOutput, t as compareKnipBaseline } from "./baseline-DPfotf4y.mjs";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { Buffer } from "node:buffer";
|
|
8
|
+
import { isDeepStrictEqual } from "node:util";
|
|
9
|
+
//#region src/commands/check/knip/process.ts
|
|
10
|
+
async function executeKnip(executable, args, cwd, timeout, signal) {
|
|
11
|
+
if (signal?.aborted) return {
|
|
12
|
+
exitCode: null,
|
|
13
|
+
stdout: "",
|
|
14
|
+
stderr: "",
|
|
15
|
+
failure: {
|
|
16
|
+
code: "ABORT_ERR",
|
|
17
|
+
message: "Knip analysis was cancelled."
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const result = {
|
|
22
|
+
exitCode: null,
|
|
23
|
+
stdout: "",
|
|
24
|
+
stderr: "",
|
|
25
|
+
failure: null
|
|
26
|
+
};
|
|
27
|
+
const child = spawn(executable, args, {
|
|
28
|
+
cwd,
|
|
29
|
+
stdio: [
|
|
30
|
+
"ignore",
|
|
31
|
+
"pipe",
|
|
32
|
+
"pipe"
|
|
33
|
+
],
|
|
34
|
+
detached: process.platform !== "win32",
|
|
35
|
+
env: {
|
|
36
|
+
...process.env,
|
|
37
|
+
JITI_FS_CACHE: "false"
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
let escalation;
|
|
41
|
+
let bytes = 0;
|
|
42
|
+
const stop = (code, message) => {
|
|
43
|
+
if (result.failure) return;
|
|
44
|
+
result.failure = {
|
|
45
|
+
code,
|
|
46
|
+
message
|
|
47
|
+
};
|
|
48
|
+
stopCheckProcessTree(child, "SIGTERM");
|
|
49
|
+
escalation = setTimeout(stopCheckProcessTree, 1e3, child, "SIGKILL");
|
|
50
|
+
escalation.unref();
|
|
51
|
+
};
|
|
52
|
+
const abort = () => stop("ABORT_ERR", "Knip analysis was cancelled.");
|
|
53
|
+
const timer = setTimeout(stop, timeout, "TIMEOUT", `Knip analysis exceeded ${timeout} ms.`);
|
|
54
|
+
const append = (key, chunk) => {
|
|
55
|
+
bytes += Buffer.byteLength(chunk);
|
|
56
|
+
if (bytes > 33554432) stop("OUTPUT_LIMIT", "Knip analysis exceeded the 32 MiB output limit.");
|
|
57
|
+
else result[key] += chunk;
|
|
58
|
+
};
|
|
59
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => append("stdout", chunk));
|
|
60
|
+
child.stderr.setEncoding("utf8").on("data", (chunk) => append("stderr", chunk));
|
|
61
|
+
child.once("error", (error) => {
|
|
62
|
+
result.failure ??= {
|
|
63
|
+
code: error.code ?? "SPAWN_ERROR",
|
|
64
|
+
message: error.message
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
child.once("close", (code, childSignal) => {
|
|
68
|
+
clearTimeout(timer);
|
|
69
|
+
if (escalation) clearTimeout(escalation);
|
|
70
|
+
signal?.removeEventListener("abort", abort);
|
|
71
|
+
result.exitCode = code;
|
|
72
|
+
if (result.failure) stopCheckProcessTree(child, "SIGKILL");
|
|
73
|
+
else if (childSignal || code !== 0 && code !== 1) result.failure = {
|
|
74
|
+
code: childSignal ?? `KNIP_EXIT_${code}`,
|
|
75
|
+
message: `Knip analysis stopped with ${childSignal ?? `exit code ${code}`}.`
|
|
76
|
+
};
|
|
77
|
+
resolve(result);
|
|
78
|
+
});
|
|
79
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
80
|
+
if (signal?.aborted) abort();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/commands/check/knip/run.ts
|
|
85
|
+
async function runKnipCheck(cwd, options = {}) {
|
|
86
|
+
const plan = await planKnipCheck(cwd, options);
|
|
87
|
+
const report = {
|
|
88
|
+
schemaVersion: 1,
|
|
89
|
+
kind: "knip-report",
|
|
90
|
+
workspaceDir: plan.workspaceDir,
|
|
91
|
+
status: "failed",
|
|
92
|
+
exitCode: 2,
|
|
93
|
+
nativeExitCode: null,
|
|
94
|
+
plan,
|
|
95
|
+
scope: null,
|
|
96
|
+
findings: [],
|
|
97
|
+
summary: summarizeKnip([]),
|
|
98
|
+
baseline: {
|
|
99
|
+
status: "none",
|
|
100
|
+
path: plan.baseline,
|
|
101
|
+
existing: [],
|
|
102
|
+
added: [],
|
|
103
|
+
fixed: []
|
|
104
|
+
},
|
|
105
|
+
diagnostics: []
|
|
106
|
+
};
|
|
107
|
+
if (plan.status !== "ready") {
|
|
108
|
+
report.diagnostics.push({
|
|
109
|
+
code: plan.status,
|
|
110
|
+
message: plan.guidance.join("\n")
|
|
111
|
+
});
|
|
112
|
+
return report;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const inputs = await knipConfigurationInputs(plan.workspaceDir, plan.config);
|
|
116
|
+
const result = await executeKnip(plan.executable, plan.args, plan.workspaceDir, plan.timeoutMs, options.signal);
|
|
117
|
+
report.nativeExitCode = result.exitCode;
|
|
118
|
+
if (result.stderr.trim()) report.diagnostics.push({
|
|
119
|
+
code: "knip_stderr",
|
|
120
|
+
message: result.stderr.trim()
|
|
121
|
+
});
|
|
122
|
+
if (result.failure) {
|
|
123
|
+
report.diagnostics.push(result.failure);
|
|
124
|
+
return report;
|
|
125
|
+
}
|
|
126
|
+
const native = parseKnipOutput(plan.workspaceDir, result.stdout);
|
|
127
|
+
if (native.output) report.diagnostics.push({
|
|
128
|
+
code: "knip_stdout",
|
|
129
|
+
message: native.output
|
|
130
|
+
});
|
|
131
|
+
if (!isDeepStrictEqual(inputs, await knipConfigurationInputs(plan.workspaceDir, plan.config))) throw new Error("Knip primary configuration changed during analysis. Run the check again.");
|
|
132
|
+
report.findings = native.findings;
|
|
133
|
+
report.summary = summarizeKnip(native.findings);
|
|
134
|
+
report.scope = {
|
|
135
|
+
toolVersion: plan.tool.version,
|
|
136
|
+
production: plan.production,
|
|
137
|
+
strict: plan.strict,
|
|
138
|
+
...inputs,
|
|
139
|
+
workspaces: native.workspaces,
|
|
140
|
+
configFile: native.configFile,
|
|
141
|
+
report: native.report,
|
|
142
|
+
plugins: native.plugins
|
|
143
|
+
};
|
|
144
|
+
if (result.exitCode === 1 && report.summary.errors === 0) throw new Error("Knip failed without a reported error diagnostic; the analysis cannot pass or update a baseline.");
|
|
145
|
+
report.baseline = await compareKnipBaseline(plan.baseline, report.scope, report.findings);
|
|
146
|
+
if (report.baseline.status === "invalid") {
|
|
147
|
+
report.diagnostics.push({
|
|
148
|
+
code: "invalid_baseline",
|
|
149
|
+
message: report.baseline.reason
|
|
150
|
+
});
|
|
151
|
+
return report;
|
|
152
|
+
}
|
|
153
|
+
const blocking = plan.newOnly ? summarizeKnip(report.baseline.added).errors : report.summary.errors;
|
|
154
|
+
report.status = "completed";
|
|
155
|
+
report.exitCode = blocking ? 1 : 0;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
report.diagnostics.push({
|
|
158
|
+
code: "incomplete_analysis",
|
|
159
|
+
message: error.message
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return report;
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
export { runKnipCheck };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ht as isWithin, mt as assertSafePath, ot as safeFile } from "./workspace-tasks-CnB8kkS0.mjs";
|
|
2
|
+
import { knipRoot } from "./plan-B5aE_WNF.mjs";
|
|
3
|
+
import { n as validateKnipBaseline } from "./baseline-DPfotf4y.mjs";
|
|
4
|
+
import path from "pathe";
|
|
5
|
+
import { link, lstat, open, readFile, rename, unlink } from "node:fs/promises";
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
//#region src/commands/check/knip/save.ts
|
|
8
|
+
/** Only explicit writes can create/update a valid baseline; never overwrite arbitrary user files. */
|
|
9
|
+
async function saveKnipBaseline(cwd, report, file) {
|
|
10
|
+
const root = await knipRoot(cwd);
|
|
11
|
+
if (report.schemaVersion !== 1 || report.kind !== "knip-report" || report.status !== "completed" || report.workspaceDir !== root || !report.scope || !file.trim()) throw new Error("Only a complete successful Knip analysis can be saved as a baseline.");
|
|
12
|
+
const baseline = validateKnipBaseline({
|
|
13
|
+
schemaVersion: 1,
|
|
14
|
+
kind: "knip-baseline",
|
|
15
|
+
scope: report.scope,
|
|
16
|
+
findings: report.findings
|
|
17
|
+
});
|
|
18
|
+
const target = path.resolve(root, file);
|
|
19
|
+
if (!isWithin(root, target)) throw new Error("Knip baseline output must be inside the workspace.");
|
|
20
|
+
const parent = path.dirname(target);
|
|
21
|
+
if (parent !== root) await assertSafePath(root, parent, "directory");
|
|
22
|
+
const original = await lstat(target).then(async () => {
|
|
23
|
+
const content = await readFile(await safeFile(root, path.relative(root, target)), "utf8");
|
|
24
|
+
validateKnipBaseline(JSON.parse(content));
|
|
25
|
+
return content;
|
|
26
|
+
}, (error) => {
|
|
27
|
+
if (error.code === "ENOENT") return null;
|
|
28
|
+
throw error;
|
|
29
|
+
});
|
|
30
|
+
const content = `${JSON.stringify(baseline, null, 2)}\n`;
|
|
31
|
+
if (original === content) return {
|
|
32
|
+
status: "unchanged",
|
|
33
|
+
path: target,
|
|
34
|
+
cleanupPending: []
|
|
35
|
+
};
|
|
36
|
+
const temporary = `${target}.repoctl-knip-${randomUUID()}.tmp`;
|
|
37
|
+
const handle = await open(temporary, "wx", 384);
|
|
38
|
+
let owned;
|
|
39
|
+
let wrote = false;
|
|
40
|
+
const cleanup = async () => {
|
|
41
|
+
if (parent !== root) await assertSafePath(root, parent, "directory");
|
|
42
|
+
const metadata = await lstat(temporary, { bigint: true });
|
|
43
|
+
if (!owned || !metadata.isFile() || metadata.ino !== owned.ino || metadata.dev !== owned.dev || !wrote || await readFile(temporary, "utf8") !== content) throw new Error("The baseline temporary file changed; preserve it for review.");
|
|
44
|
+
await unlink(temporary);
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
owned = await handle.stat({ bigint: true });
|
|
48
|
+
await handle.writeFile(content, "utf8");
|
|
49
|
+
await handle.close();
|
|
50
|
+
wrote = true;
|
|
51
|
+
if (parent !== root) await assertSafePath(root, parent, "directory");
|
|
52
|
+
await safeFile(root, path.relative(root, temporary));
|
|
53
|
+
if (await lstat(target).then(async () => readFile(await safeFile(root, path.relative(root, target)), "utf8"), (error) => {
|
|
54
|
+
if (error.code === "ENOENT") return null;
|
|
55
|
+
throw error;
|
|
56
|
+
}) !== original) throw new Error("Knip baseline changed concurrently; generate a new explicit save.");
|
|
57
|
+
if (original === null) {
|
|
58
|
+
await link(temporary, target);
|
|
59
|
+
return {
|
|
60
|
+
status: "created",
|
|
61
|
+
path: target,
|
|
62
|
+
cleanupPending: await cleanup().then(() => [], () => [temporary])
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
await rename(temporary, target);
|
|
66
|
+
return {
|
|
67
|
+
status: "updated",
|
|
68
|
+
path: target,
|
|
69
|
+
cleanupPending: []
|
|
70
|
+
};
|
|
71
|
+
} catch (error) {
|
|
72
|
+
await handle.close().catch(() => {});
|
|
73
|
+
await cleanup().catch(() => {});
|
|
74
|
+
if (await lstat(temporary).then(() => true, () => false)) throw new AggregateError([error], `Knip baseline save failed; inspect retained temporary file: ${temporary}`);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { saveKnipBaseline };
|