@codefast/cli 0.5.0-canary.4 → 0.5.0-canary.6
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 +106 -480
- package/dist/arrange/analyze.js +25 -0
- package/dist/arrange/analyze.js.map +1 -0
- package/dist/arrange/cli-schema.js +29 -0
- package/dist/arrange/cli-schema.js.map +1 -0
- package/dist/arrange/command.js +170 -0
- package/dist/arrange/command.js.map +1 -0
- package/dist/arrange/domain/analyze-service.js +122 -0
- package/dist/arrange/domain/analyze-service.js.map +1 -0
- package/dist/arrange/domain/ast/ast-node.js +240 -0
- package/dist/arrange/domain/ast/ast-node.js.map +1 -0
- package/dist/arrange/domain/ast/collectors-cn.js +81 -0
- package/dist/arrange/domain/ast/collectors-cn.js.map +1 -0
- package/dist/arrange/domain/ast/collectors-jsx.js +24 -0
- package/dist/arrange/domain/ast/collectors-jsx.js.map +1 -0
- package/dist/arrange/domain/ast/collectors-tv.js +319 -0
- package/dist/arrange/domain/ast/collectors-tv.js.map +1 -0
- package/dist/arrange/domain/ast/helpers.js +151 -0
- package/dist/arrange/domain/ast/helpers.js.map +1 -0
- package/dist/arrange/domain/ast/simplify-targets.js +161 -0
- package/dist/arrange/domain/ast/simplify-targets.js.map +1 -0
- package/dist/arrange/domain/ast/targets.js +182 -0
- package/dist/arrange/domain/ast/targets.js.map +1 -0
- package/dist/arrange/domain/constants.js +225 -0
- package/dist/arrange/domain/constants.js.map +1 -0
- package/dist/arrange/domain/grouping-service.js +128 -0
- package/dist/arrange/domain/grouping-service.js.map +1 -0
- package/dist/arrange/domain/grouping.js +435 -0
- package/dist/arrange/domain/grouping.js.map +1 -0
- package/dist/arrange/domain/imports.js +160 -0
- package/dist/arrange/domain/imports.js.map +1 -0
- package/dist/arrange/domain/source-text-formatters.js +100 -0
- package/dist/arrange/domain/source-text-formatters.js.map +1 -0
- package/dist/arrange/domain/tailwind-token.js +50 -0
- package/dist/arrange/domain/tailwind-token.js.map +1 -0
- package/dist/arrange/domain/token-classifier.js +448 -0
- package/dist/arrange/domain/token-classifier.js.map +1 -0
- package/dist/arrange/domain/types.js +11 -0
- package/dist/arrange/domain/types.js.map +1 -0
- package/dist/arrange/output.js +120 -0
- package/dist/arrange/output.js.map +1 -0
- package/dist/arrange/process-file.js +44 -0
- package/dist/arrange/process-file.js.map +1 -0
- package/dist/arrange/resolve-target.js +33 -0
- package/dist/arrange/resolve-target.js.map +1 -0
- package/dist/arrange/scan-target.js +30 -0
- package/dist/arrange/scan-target.js.map +1 -0
- package/dist/arrange/simplify-process-file.js +29 -0
- package/dist/arrange/simplify-process-file.js.map +1 -0
- package/dist/arrange/simplify-sync.js +29 -0
- package/dist/arrange/simplify-sync.js.map +1 -0
- package/dist/arrange/source-parse.js +17 -0
- package/dist/arrange/source-parse.js.map +1 -0
- package/dist/arrange/suggest.js +14 -0
- package/dist/arrange/suggest.js.map +1 -0
- package/dist/arrange/sync.js +48 -0
- package/dist/arrange/sync.js.map +1 -0
- package/dist/arrange/typescript-ast-translator.js +455 -0
- package/dist/arrange/typescript-ast-translator.js.map +1 -0
- package/dist/arrange/workspace.js +31 -0
- package/dist/arrange/workspace.js.map +1 -0
- package/dist/audit/cli-schema.js +22 -0
- package/dist/audit/cli-schema.js.map +1 -0
- package/dist/audit/command.js +60 -0
- package/dist/audit/command.js.map +1 -0
- package/dist/audit/domain/audit-file.js +101 -0
- package/dist/audit/domain/audit-file.js.map +1 -0
- package/dist/audit/domain/mappings.js +103 -0
- package/dist/audit/domain/mappings.js.map +1 -0
- package/dist/audit/domain/tokenize.js +83 -0
- package/dist/audit/domain/tokenize.js.map +1 -0
- package/dist/audit/domain/types.js +2 -0
- package/dist/audit/domain/types.js.map +1 -0
- package/dist/audit/output.js +44 -0
- package/dist/audit/output.js.map +1 -0
- package/dist/audit/prepare.js +42 -0
- package/dist/audit/prepare.js.map +1 -0
- package/dist/audit/run.js +57 -0
- package/dist/audit/run.js.map +1 -0
- package/dist/{bin.mjs → bin.js} +2 -4
- package/dist/bin.js.map +1 -0
- package/dist/cli.js +45 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/cli/format-error.js +19 -0
- package/dist/core/cli/format-error.js.map +1 -0
- package/dist/core/cli/global-options.js +10 -0
- package/dist/core/cli/global-options.js.map +1 -0
- package/dist/core/cli/positional.js +9 -0
- package/dist/core/cli/positional.js.map +1 -0
- package/dist/core/cli/result-handle.js +69 -0
- package/dist/core/cli/result-handle.js.map +1 -0
- package/dist/core/config/loader.js +88 -0
- package/dist/core/config/loader.js.map +1 -0
- package/dist/core/config/schema.js +97 -0
- package/dist/core/config/schema.js.map +1 -0
- package/dist/core/config/warnings.js +12 -0
- package/dist/core/config/warnings.js.map +1 -0
- package/dist/core/config.js +18 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.js +58 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/exit-codes.js +15 -0
- package/dist/core/exit-codes.js.map +1 -0
- package/dist/core/filesystem/node.js +33 -0
- package/dist/core/filesystem/node.js.map +1 -0
- package/dist/core/filesystem/port.js +2 -0
- package/dist/core/filesystem/port.js.map +1 -0
- package/dist/core/glob.js +20 -0
- package/dist/core/glob.js.map +1 -0
- package/dist/core/logger.js +13 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/result.js +16 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/schema-parse.js +21 -0
- package/dist/core/schema-parse.js.map +1 -0
- package/dist/core/source-text-edit.js +62 -0
- package/dist/core/source-text-edit.js.map +1 -0
- package/dist/core/verbose-diagnostics.js +9 -0
- package/dist/core/verbose-diagnostics.js.map +1 -0
- package/dist/core/workspace/resolver.js +208 -0
- package/dist/core/workspace/resolver.js.map +1 -0
- package/dist/core/workspace/typescript-walk.js +41 -0
- package/dist/core/workspace/typescript-walk.js.map +1 -0
- package/dist/mirror/cli-result.js +20 -0
- package/dist/mirror/cli-result.js.map +1 -0
- package/dist/mirror/cli-schema.js +11 -0
- package/dist/mirror/cli-schema.js.map +1 -0
- package/dist/mirror/command.js +73 -0
- package/dist/mirror/command.js.map +1 -0
- package/dist/mirror/dist-filesystem-impl.js +53 -0
- package/dist/mirror/dist-filesystem-impl.js.map +1 -0
- package/dist/mirror/domain/constants.js +21 -0
- package/dist/mirror/domain/constants.js.map +1 -0
- package/dist/mirror/domain/dirent-guard.js +16 -0
- package/dist/mirror/domain/dirent-guard.js.map +1 -0
- package/dist/mirror/domain/dist-filesystem.js +2 -0
- package/dist/mirror/domain/dist-filesystem.js.map +1 -0
- package/dist/mirror/domain/errors.js +19 -0
- package/dist/mirror/domain/errors.js.map +1 -0
- package/dist/mirror/domain/exports.js +284 -0
- package/dist/mirror/domain/exports.js.map +1 -0
- package/dist/mirror/domain/package-display-name.js +10 -0
- package/dist/mirror/domain/package-display-name.js.map +1 -0
- package/dist/mirror/domain/path-normalizer.js +8 -0
- package/dist/mirror/domain/path-normalizer.js.map +1 -0
- package/dist/mirror/domain/types.js +2 -0
- package/dist/mirror/domain/types.js.map +1 -0
- package/dist/mirror/output.js +47 -0
- package/dist/mirror/output.js.map +1 -0
- package/dist/mirror/package-path.js +40 -0
- package/dist/mirror/package-path.js.map +1 -0
- package/dist/mirror/prepare.js +37 -0
- package/dist/mirror/prepare.js.map +1 -0
- package/dist/mirror/supplement-exports.js +157 -0
- package/dist/mirror/supplement-exports.js.map +1 -0
- package/dist/mirror/sync-reporter.js +125 -0
- package/dist/mirror/sync-reporter.js.map +1 -0
- package/dist/mirror/sync-types.js +2 -0
- package/dist/mirror/sync-types.js.map +1 -0
- package/dist/mirror/sync-workspace-package.js +117 -0
- package/dist/mirror/sync-workspace-package.js.map +1 -0
- package/dist/mirror/sync.js +90 -0
- package/dist/mirror/sync.js.map +1 -0
- package/dist/mirror/write-exports.js +145 -0
- package/dist/mirror/write-exports.js.map +1 -0
- package/dist/tag/cli-result.js +12 -0
- package/dist/tag/cli-result.js.map +1 -0
- package/dist/tag/cli-schema.js +13 -0
- package/dist/tag/cli-schema.js.map +1 -0
- package/dist/tag/command.js +69 -0
- package/dist/tag/command.js.map +1 -0
- package/dist/tag/domain/types.js +2 -0
- package/dist/tag/domain/types.js.map +1 -0
- package/dist/tag/output.js +101 -0
- package/dist/tag/output.js.map +1 -0
- package/dist/tag/prepare.js +30 -0
- package/dist/tag/prepare.js.map +1 -0
- package/dist/tag/resolve-target-path.js +14 -0
- package/dist/tag/resolve-target-path.js.map +1 -0
- package/dist/tag/since-writer.js +231 -0
- package/dist/tag/since-writer.js.map +1 -0
- package/dist/tag/sync.js +166 -0
- package/dist/tag/sync.js.map +1 -0
- package/dist/tag/target-candidates.js +79 -0
- package/dist/tag/target-candidates.js.map +1 -0
- package/dist/tag/target-runner.js +25 -0
- package/dist/tag/target-runner.js.map +1 -0
- package/dist/tag/version-resolver.js +28 -0
- package/dist/tag/version-resolver.js.map +1 -0
- package/package.json +25 -20
- package/dist/arrange/analyze.mjs +0 -24
- package/dist/arrange/cli-schema.mjs +0 -27
- package/dist/arrange/command.mjs +0 -130
- package/dist/arrange/domain/analyze-service.mjs +0 -102
- package/dist/arrange/domain/ast/ast-node.mjs +0 -215
- package/dist/arrange/domain/ast/collectors-cn.mjs +0 -64
- package/dist/arrange/domain/ast/collectors-jsx.mjs +0 -23
- package/dist/arrange/domain/ast/collectors-tv.mjs +0 -189
- package/dist/arrange/domain/ast/helpers.mjs +0 -108
- package/dist/arrange/domain/ast/simplify-targets.mjs +0 -109
- package/dist/arrange/domain/ast/targets.mjs +0 -134
- package/dist/arrange/domain/constants.mjs +0 -213
- package/dist/arrange/domain/grouping-service.mjs +0 -121
- package/dist/arrange/domain/grouping.mjs +0 -338
- package/dist/arrange/domain/imports.mjs +0 -107
- package/dist/arrange/domain/source-text-formatters.mjs +0 -88
- package/dist/arrange/domain/tailwind-token.mjs +0 -40
- package/dist/arrange/domain/token-classifier.mjs +0 -218
- package/dist/arrange/domain/types.mjs +0 -1
- package/dist/arrange/output.mjs +0 -87
- package/dist/arrange/process-file.mjs +0 -42
- package/dist/arrange/resolve-target.mjs +0 -24
- package/dist/arrange/scan-target.mjs +0 -29
- package/dist/arrange/simplify-process-file.mjs +0 -35
- package/dist/arrange/simplify-sync.mjs +0 -32
- package/dist/arrange/source-parse.mjs +0 -18
- package/dist/arrange/suggest.mjs +0 -15
- package/dist/arrange/sync.mjs +0 -51
- package/dist/arrange/typescript-ast-translator.mjs +0 -354
- package/dist/arrange/workspace.mjs +0 -31
- package/dist/cli.mjs +0 -34
- package/dist/core/cli/format-error.mjs +0 -15
- package/dist/core/cli/global-options.mjs +0 -10
- package/dist/core/cli/positional.mjs +0 -11
- package/dist/core/cli/result-handle.mjs +0 -51
- package/dist/core/config/loader.mjs +0 -79
- package/dist/core/config/schema.mjs +0 -60
- package/dist/core/config/warnings.mjs +0 -12
- package/dist/core/config.mjs +0 -19
- package/dist/core/errors.mjs +0 -35
- package/dist/core/exit-codes.mjs +0 -17
- package/dist/core/filesystem/node.mjs +0 -32
- package/dist/core/filesystem/port.mjs +0 -1
- package/dist/core/glob.mjs +0 -20
- package/dist/core/logger.mjs +0 -15
- package/dist/core/result.mjs +0 -21
- package/dist/core/schema-parse.mjs +0 -18
- package/dist/core/source-text-edit.mjs +0 -56
- package/dist/core/verbose-diagnostics.mjs +0 -11
- package/dist/core/workspace/resolver.mjs +0 -177
- package/dist/core/workspace/typescript-walk.mjs +0 -36
- package/dist/mirror/cli-result.mjs +0 -22
- package/dist/mirror/cli-schema.mjs +0 -13
- package/dist/mirror/command.mjs +0 -58
- package/dist/mirror/dist-filesystem-impl.mjs +0 -42
- package/dist/mirror/domain/constants.mjs +0 -31
- package/dist/mirror/domain/dirent-guard.mjs +0 -16
- package/dist/mirror/domain/dist-filesystem.mjs +0 -1
- package/dist/mirror/domain/errors.mjs +0 -21
- package/dist/mirror/domain/exports.mjs +0 -226
- package/dist/mirror/domain/package-display-name.mjs +0 -12
- package/dist/mirror/domain/path-normalizer.mjs +0 -10
- package/dist/mirror/domain/types.mjs +0 -1
- package/dist/mirror/output.mjs +0 -48
- package/dist/mirror/package-path.mjs +0 -32
- package/dist/mirror/prepare.mjs +0 -33
- package/dist/mirror/supplement-exports.mjs +0 -114
- package/dist/mirror/sync-reporter.mjs +0 -107
- package/dist/mirror/sync-types.mjs +0 -1
- package/dist/mirror/sync-workspace-package.mjs +0 -109
- package/dist/mirror/sync.mjs +0 -88
- package/dist/mirror/write-exports.mjs +0 -94
- package/dist/tag/cli-result.mjs +0 -11
- package/dist/tag/cli-schema.mjs +0 -15
- package/dist/tag/command.mjs +0 -56
- package/dist/tag/domain/types.mjs +0 -1
- package/dist/tag/output.mjs +0 -87
- package/dist/tag/prepare.mjs +0 -29
- package/dist/tag/resolve-target-path.mjs +0 -12
- package/dist/tag/since-writer.mjs +0 -131
- package/dist/tag/sync.mjs +0 -149
- package/dist/tag/target-candidates.mjs +0 -68
- package/dist/tag/target-runner.mjs +0 -26
- package/dist/tag/version-resolver.mjs +0 -25
package/dist/tag/sync.mjs
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { AppError, messageFrom } from "../core/errors.mjs";
|
|
2
|
-
import { err, ok } from "../core/result.mjs";
|
|
3
|
-
import { createAnyGlobMatcher } from "../core/glob.mjs";
|
|
4
|
-
import { resolveTagTargetCandidates } from "./target-candidates.mjs";
|
|
5
|
-
import { runTagOnTarget } from "./target-runner.mjs";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
//#region src/tag/sync.ts
|
|
8
|
-
/**
|
|
9
|
-
* @since 0.3.16-canary.0
|
|
10
|
-
*/
|
|
11
|
-
async function runTagSync(fs, input) {
|
|
12
|
-
try {
|
|
13
|
-
const tagConfig = input.config;
|
|
14
|
-
const { includedCandidates, skippedPackages } = filterSkippedCandidates(await resolveTagTargetCandidates(fs, input.rootDir, input.targetPath), input.skipPackages);
|
|
15
|
-
const selectedTargets = includedCandidates.map((candidate) => resolveTargetSelection(fs, candidate, input.rootDir));
|
|
16
|
-
const targetExecutionResults = await Promise.all(selectedTargets.map((resolvedTarget) => runOnResolvedTarget(fs, resolvedTarget, input.write, input.listener)));
|
|
17
|
-
const allFileResults = targetExecutionResults.flatMap((targetResult) => targetResult.result?.fileResults ?? []);
|
|
18
|
-
const filesScanned = targetExecutionResults.reduce((sum, targetResult) => sum + (targetResult.result?.filesScanned ?? 0), 0);
|
|
19
|
-
const filesChanged = targetExecutionResults.reduce((sum, targetResult) => sum + (targetResult.result?.filesChanged ?? 0), 0);
|
|
20
|
-
const taggedDeclarations = targetExecutionResults.reduce((sum, targetResult) => sum + (targetResult.result?.taggedDeclarations ?? 0), 0);
|
|
21
|
-
const modifiedFiles = allFileResults.filter((entry) => entry.changed).map((entry) => entry.filePath);
|
|
22
|
-
const hookError = input.write && modifiedFiles.length > 0 ? await runTagOnAfterWriteHook(tagConfig?.onAfterWrite, modifiedFiles) : null;
|
|
23
|
-
const versionsSet = extractDistinctVersions(targetExecutionResults);
|
|
24
|
-
const distinctVersions = [...versionsSet].toSorted((left, right) => left.localeCompare(right));
|
|
25
|
-
return ok({
|
|
26
|
-
mode: input.write ? "applied" : "dry-run",
|
|
27
|
-
selectedTargets,
|
|
28
|
-
skippedPackages,
|
|
29
|
-
targetResults: targetExecutionResults,
|
|
30
|
-
filesScanned,
|
|
31
|
-
filesChanged,
|
|
32
|
-
taggedDeclarations,
|
|
33
|
-
versionSummary: summarizeVersions(versionsSet),
|
|
34
|
-
distinctVersions,
|
|
35
|
-
modifiedFiles,
|
|
36
|
-
hookError
|
|
37
|
-
});
|
|
38
|
-
} catch (caughtError) {
|
|
39
|
-
return err(new AppError("INFRA_FAILURE", messageFrom(caughtError), caughtError));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
async function runTagOnAfterWriteHook(hook, modifiedFiles) {
|
|
43
|
-
if (!hook || modifiedFiles.length === 0) return null;
|
|
44
|
-
try {
|
|
45
|
-
await hook({ files: modifiedFiles });
|
|
46
|
-
return null;
|
|
47
|
-
} catch (caughtHookError) {
|
|
48
|
-
return `[tag] onAfterWrite hook failed: ${messageFrom(caughtHookError)}`;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function summarizeVersions(distinctVersions) {
|
|
52
|
-
if (distinctVersions.size === 0) return "none";
|
|
53
|
-
if (distinctVersions.size > 1) return "mixed";
|
|
54
|
-
return distinctVersions.values().next().value ?? "none";
|
|
55
|
-
}
|
|
56
|
-
function extractDistinctVersions(targetResults) {
|
|
57
|
-
return new Set(targetResults.map((targetResult) => targetResult.result?.version).filter((version) => typeof version === "string" && version.length > 0));
|
|
58
|
-
}
|
|
59
|
-
function chooseWorkspacePackageTargetPath(fs, candidate) {
|
|
60
|
-
if (candidate.source !== "workspace-package") return {
|
|
61
|
-
targetPath: candidate.candidatePath,
|
|
62
|
-
source: candidate.source
|
|
63
|
-
};
|
|
64
|
-
const preferredSourceDir = path.join(candidate.candidatePath, "src");
|
|
65
|
-
try {
|
|
66
|
-
if (fs.statSync(preferredSourceDir).isDirectory()) return {
|
|
67
|
-
targetPath: preferredSourceDir,
|
|
68
|
-
source: "workspace-package-selected-src"
|
|
69
|
-
};
|
|
70
|
-
} catch {}
|
|
71
|
-
return {
|
|
72
|
-
targetPath: candidate.candidatePath,
|
|
73
|
-
source: "workspace-package-selected-root"
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function resolveTargetSelection(fs, candidate, rootDir) {
|
|
77
|
-
const selectedTarget = chooseWorkspacePackageTargetPath(fs, candidate);
|
|
78
|
-
const rootRelativeTargetPath = path.relative(rootDir, selectedTarget.targetPath).split(path.sep).join("/");
|
|
79
|
-
return {
|
|
80
|
-
targetPath: selectedTarget.targetPath,
|
|
81
|
-
rootRelativeTargetPath: rootRelativeTargetPath || ".",
|
|
82
|
-
source: selectedTarget.source,
|
|
83
|
-
packageDir: candidate.packageDir,
|
|
84
|
-
packageName: candidate.packageName
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Partition tag target candidates into those to tag and those to skip, matching
|
|
89
|
-
* each candidate's package name against `skipPackages` as glob patterns.
|
|
90
|
-
* Candidates without a package name (e.g. an explicit-target path) are never skipped.
|
|
91
|
-
*
|
|
92
|
-
* @since 0.5.0-canary.0
|
|
93
|
-
*/
|
|
94
|
-
function filterSkippedCandidates(targetCandidates, skipPackages) {
|
|
95
|
-
if (!skipPackages || skipPackages.length === 0) return {
|
|
96
|
-
includedCandidates: targetCandidates,
|
|
97
|
-
skippedPackages: []
|
|
98
|
-
};
|
|
99
|
-
const isSkipped = createAnyGlobMatcher(skipPackages);
|
|
100
|
-
const includedCandidates = [];
|
|
101
|
-
const skippedPackages = [];
|
|
102
|
-
for (const candidate of targetCandidates) {
|
|
103
|
-
const packageName = candidate.packageName;
|
|
104
|
-
if (packageName && isSkipped(packageName)) {
|
|
105
|
-
skippedPackages.push(packageName);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
includedCandidates.push(candidate);
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
includedCandidates,
|
|
112
|
-
skippedPackages
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
async function runOnResolvedTarget(fs, resolvedTarget, write, listener) {
|
|
116
|
-
listener?.onTargetStarted(resolvedTarget);
|
|
117
|
-
const absoluteTargetPath = path.resolve(resolvedTarget.targetPath);
|
|
118
|
-
if (!fs.existsSync(absoluteTargetPath)) {
|
|
119
|
-
const missingTargetResult = {
|
|
120
|
-
target: resolvedTarget,
|
|
121
|
-
targetExists: false,
|
|
122
|
-
runError: `Not found: ${absoluteTargetPath}`,
|
|
123
|
-
result: null
|
|
124
|
-
};
|
|
125
|
-
listener?.onTargetCompleted(resolvedTarget, missingTargetResult);
|
|
126
|
-
return missingTargetResult;
|
|
127
|
-
}
|
|
128
|
-
try {
|
|
129
|
-
const targetRunResult = {
|
|
130
|
-
target: resolvedTarget,
|
|
131
|
-
targetExists: true,
|
|
132
|
-
runError: null,
|
|
133
|
-
result: runTagOnTarget(fs, absoluteTargetPath, { write })
|
|
134
|
-
};
|
|
135
|
-
listener?.onTargetCompleted(resolvedTarget, targetRunResult);
|
|
136
|
-
return targetRunResult;
|
|
137
|
-
} catch (caughtRunError) {
|
|
138
|
-
const failedTargetRunResult = {
|
|
139
|
-
target: resolvedTarget,
|
|
140
|
-
targetExists: true,
|
|
141
|
-
runError: messageFrom(caughtRunError),
|
|
142
|
-
result: null
|
|
143
|
-
};
|
|
144
|
-
listener?.onTargetCompleted(resolvedTarget, failedTargetRunResult);
|
|
145
|
-
return failedTargetRunResult;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
//#endregion
|
|
149
|
-
export { filterSkippedCandidates, runTagSync };
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { listWorkspacePackageDirectories } from "../core/workspace/resolver.mjs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
//#region src/tag/target-candidates.ts
|
|
5
|
-
const packageJsonFileName = "package.json";
|
|
6
|
-
const packageJsonNameSchema = z.looseObject({ name: z.string().min(1).optional() });
|
|
7
|
-
function toPosix(filePath) {
|
|
8
|
-
return filePath.split(path.sep).join("/");
|
|
9
|
-
}
|
|
10
|
-
function readPackageName(fs, packageDir) {
|
|
11
|
-
const packageJsonPath = path.join(packageDir, packageJsonFileName);
|
|
12
|
-
if (!fs.existsSync(packageJsonPath)) return null;
|
|
13
|
-
try {
|
|
14
|
-
const rawPackageJson = fs.readFileSync(packageJsonPath, "utf8");
|
|
15
|
-
const parsedPackageJson = JSON.parse(rawPackageJson);
|
|
16
|
-
const parsedPackageName = packageJsonNameSchema.safeParse(parsedPackageJson);
|
|
17
|
-
if (!parsedPackageName.success) return null;
|
|
18
|
-
return parsedPackageName.data.name ?? null;
|
|
19
|
-
} catch {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function toRootRelativePath(rootDir, absolutePath) {
|
|
24
|
-
const relativePath = path.relative(rootDir, absolutePath);
|
|
25
|
-
return relativePath ? toPosix(relativePath) : ".";
|
|
26
|
-
}
|
|
27
|
-
function toPackageTargetCandidate(fs, rootDir, packageDir) {
|
|
28
|
-
const packageName = readPackageName(fs, packageDir);
|
|
29
|
-
return {
|
|
30
|
-
candidatePath: packageDir,
|
|
31
|
-
rootRelativeCandidatePath: toRootRelativePath(rootDir, packageDir),
|
|
32
|
-
source: "workspace-package",
|
|
33
|
-
packageDir,
|
|
34
|
-
packageName
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @since 0.3.16-canary.0
|
|
39
|
-
*/
|
|
40
|
-
async function resolveTagTargetCandidates(fs, rootDir, explicitTarget) {
|
|
41
|
-
if (explicitTarget) {
|
|
42
|
-
const resolvedExplicitTarget = path.resolve(explicitTarget);
|
|
43
|
-
return [{
|
|
44
|
-
candidatePath: resolvedExplicitTarget,
|
|
45
|
-
rootRelativeCandidatePath: toRootRelativePath(rootDir, resolvedExplicitTarget),
|
|
46
|
-
source: "explicit-target",
|
|
47
|
-
packageDir: null,
|
|
48
|
-
packageName: null
|
|
49
|
-
}];
|
|
50
|
-
}
|
|
51
|
-
const outcome = await listWorkspacePackageDirectories(rootDir, fs, true);
|
|
52
|
-
const packageDirs = [...outcome.packageDirectoryPathsAbsolute];
|
|
53
|
-
const hasWorkspaceFile = outcome.hasPnpmWorkspaceYamlFile;
|
|
54
|
-
if (packageDirs.length === 0) {
|
|
55
|
-
if (hasWorkspaceFile) return [];
|
|
56
|
-
const repoSourceDir = path.join(rootDir, "src");
|
|
57
|
-
return [{
|
|
58
|
-
candidatePath: repoSourceDir,
|
|
59
|
-
rootRelativeCandidatePath: toRootRelativePath(rootDir, repoSourceDir),
|
|
60
|
-
source: "repo-src-fallback",
|
|
61
|
-
packageDir: null,
|
|
62
|
-
packageName: null
|
|
63
|
-
}];
|
|
64
|
-
}
|
|
65
|
-
return packageDirs.map((packageDir) => toPackageTargetCandidate(fs, rootDir, packageDir));
|
|
66
|
-
}
|
|
67
|
-
//#endregion
|
|
68
|
-
export { resolveTagTargetCandidates };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { walkTsxFiles } from "../core/workspace/typescript-walk.mjs";
|
|
2
|
-
import { TagSinceWriter } from "./since-writer.mjs";
|
|
3
|
-
import { resolveNearestPackageVersion } from "./version-resolver.mjs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
//#region src/tag/target-runner.ts
|
|
6
|
-
/**
|
|
7
|
-
* @since 0.3.16-canary.0
|
|
8
|
-
*/
|
|
9
|
-
function runTagOnTarget(fs, targetPath, opts) {
|
|
10
|
-
const resolvedTarget = path.resolve(targetPath);
|
|
11
|
-
const version = resolveNearestPackageVersion(fs, resolvedTarget);
|
|
12
|
-
const tsFiles = (fs.statSync(resolvedTarget).isDirectory() ? walkTsxFiles(resolvedTarget, fs) : [resolvedTarget]).filter((filePath) => filePath.endsWith(".ts") || filePath.endsWith(".tsx"));
|
|
13
|
-
const sinceWriter = new TagSinceWriter(fs);
|
|
14
|
-
const fileResults = tsFiles.map((filePath) => sinceWriter.applySinceTagsToFile(filePath, version, opts.write));
|
|
15
|
-
const filesChanged = fileResults.filter((result) => result.changed).length;
|
|
16
|
-
const taggedDeclarations = fileResults.reduce((sum, result) => sum + result.taggedDeclarations, 0);
|
|
17
|
-
return {
|
|
18
|
-
version,
|
|
19
|
-
filesScanned: tsFiles.length,
|
|
20
|
-
filesChanged,
|
|
21
|
-
taggedDeclarations,
|
|
22
|
-
fileResults
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { runTagOnTarget };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
//#region src/tag/version-resolver.ts
|
|
3
|
-
const packageJsonFileName = "package.json";
|
|
4
|
-
/**
|
|
5
|
-
* @since 0.3.16-canary.0
|
|
6
|
-
*/
|
|
7
|
-
function resolveNearestPackageVersion(fs, targetPath) {
|
|
8
|
-
const resolved = path.resolve(targetPath);
|
|
9
|
-
let current = fs.statSync(resolved).isDirectory() ? resolved : path.dirname(resolved);
|
|
10
|
-
while (true) {
|
|
11
|
-
const packageJsonPath = path.join(current, packageJsonFileName);
|
|
12
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
13
|
-
const raw = fs.readFileSync(packageJsonPath, "utf8");
|
|
14
|
-
const version = JSON.parse(raw).version;
|
|
15
|
-
if (typeof version === "string" && version.length > 0) return version;
|
|
16
|
-
throw new Error(`Missing or invalid version in ${packageJsonPath}`);
|
|
17
|
-
}
|
|
18
|
-
const parent = path.dirname(current);
|
|
19
|
-
if (parent === current) break;
|
|
20
|
-
current = parent;
|
|
21
|
-
}
|
|
22
|
-
throw new Error(`Unable to locate ${packageJsonFileName} from target: ${targetPath}`);
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
export { resolveNearestPackageVersion };
|