@codefast/cli 0.3.7-canary.0 → 0.3.13-canary.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 +178 -262
- package/dist/analyze-DvtJ3j9m.mjs +92 -0
- package/dist/arrange-Bbh62DrU.mjs +107 -0
- package/dist/arrange-BqP2DI3w.mjs +8 -0
- package/dist/ast-helpers-MDRYuIAk.mjs +115 -0
- package/dist/bin.mjs +8 -0
- package/dist/caught-unknown-message-CRhkDWO7.mjs +20 -0
- package/dist/collectors-cn-BS8TTQ8O.mjs +61 -0
- package/dist/collectors-jsx-D9tL2ZPM.mjs +20 -0
- package/dist/collectors-tv-D2PXZaRt.mjs +170 -0
- package/dist/colors-BjdkCfGK.mjs +12 -0
- package/dist/commands/arrange.mjs +2 -0
- package/dist/commands/mirror.mjs +2 -0
- package/dist/commands/mirror.test.mjs +48 -0
- package/dist/commands/tag.mjs +2 -0
- package/dist/config-DVia_f9a.mjs +3 -0
- package/dist/config-reporter-SCcWDZc1.mjs +10 -0
- package/dist/constants-AtPhF-Ct.mjs +169 -0
- package/dist/constants-Bq5wdyLC.mjs +8 -0
- package/dist/dirent-list-BSDeRG5i.mjs +14 -0
- package/dist/engine-CcWEHSCq.mjs +287 -0
- package/dist/engine-DRTdkc5u.mjs +236 -0
- package/dist/errors-CFH4w6ic.mjs +15 -0
- package/dist/errors-CpU1ogfA.mjs +19 -0
- package/dist/formatters-DGE8jJ53.mjs +52 -0
- package/dist/group-file-ClW7XdD6.mjs +113 -0
- package/dist/grouping-c1grpCQT.mjs +235 -0
- package/dist/imports-DSVq1xhB.mjs +54 -0
- package/dist/lib/arrange/application/analyze.mjs +2 -0
- package/dist/lib/arrange/application/analyze.test.mjs +171 -0
- package/dist/lib/arrange/application/group-file.mjs +2 -0
- package/dist/lib/arrange/application/group-file.test.mjs +273 -0
- package/dist/lib/arrange/application/run-target.mjs +2 -0
- package/dist/lib/arrange/application/run-target.test.mjs +97 -0
- package/dist/lib/arrange/domain/ast/ast-helpers.mjs +2 -0
- package/dist/lib/arrange/domain/ast/ast-helpers.test.mjs +148 -0
- package/dist/lib/arrange/domain/ast/collectors-cn.mjs +2 -0
- package/dist/lib/arrange/domain/ast/collectors-cn.test.mjs +58 -0
- package/dist/lib/arrange/domain/ast/collectors-jsx.mjs +2 -0
- package/dist/lib/arrange/domain/ast/collectors-jsx.test.mjs +20 -0
- package/dist/lib/arrange/domain/ast/collectors-tv.mjs +2 -0
- package/dist/lib/arrange/domain/ast/collectors-tv.test.mjs +145 -0
- package/dist/lib/arrange/domain/ast/targets.mjs +2 -0
- package/dist/lib/arrange/domain/ast/targets.test.mjs +50 -0
- package/dist/lib/arrange/domain/constants.mjs +2 -0
- package/dist/lib/arrange/domain/errors.mjs +2 -0
- package/dist/lib/arrange/domain/grouping.mjs +2 -0
- package/dist/lib/arrange/domain/grouping.test.mjs +186 -0
- package/dist/lib/arrange/domain/imports.mjs +2 -0
- package/dist/lib/arrange/domain/imports.test.mjs +48 -0
- package/dist/lib/arrange/domain/tokenizer.mjs +2 -0
- package/dist/lib/arrange/domain/tokenizer.test.mjs +165 -0
- package/dist/lib/arrange/domain/types.mjs +1 -0
- package/dist/lib/arrange/index.mjs +16 -0
- package/dist/lib/arrange/infra/walk.mjs +2 -0
- package/dist/lib/arrange/infra/walk.test.mjs +50 -0
- package/dist/lib/arrange/presentation/formatters.mjs +2 -0
- package/dist/lib/arrange/presentation/formatters.test.mjs +73 -0
- package/dist/lib/arrange/presentation/report.mjs +2 -0
- package/dist/lib/config/domain/schema.mjs +2 -0
- package/dist/lib/config/index.mjs +4 -0
- package/dist/lib/config/infra/loader.mjs +2 -0
- package/dist/lib/config/infra/loader.test.mjs +116 -0
- package/dist/lib/infra/caught-unknown-message.mjs +2 -0
- package/dist/lib/infra/config-reporter.mjs +2 -0
- package/dist/lib/infra/fs-contract.mjs +1 -0
- package/dist/lib/infra/node-io.mjs +2 -0
- package/dist/lib/infra/workspace/repo-root.mjs +2 -0
- package/dist/lib/infra/workspace/repo-root.test.mjs +45 -0
- package/dist/lib/mirror/application/engine.mjs +2 -0
- package/dist/lib/mirror/application/sync.mjs +2 -0
- package/dist/lib/mirror/application/sync.test.mjs +482 -0
- package/dist/lib/mirror/domain/constants.mjs +2 -0
- package/dist/lib/mirror/domain/errors.mjs +2 -0
- package/dist/lib/mirror/domain/types.mjs +1 -0
- package/dist/lib/mirror/index.mjs +3 -0
- package/dist/lib/mirror/infra/dirent-list.mjs +2 -0
- package/dist/lib/mirror/infra/dirent-list.test.mjs +18 -0
- package/dist/lib/mirror/infra/package-filter.mjs +2 -0
- package/dist/lib/mirror/infra/package-filter.test.mjs +32 -0
- package/dist/lib/mirror/infra/path-normalizer.mjs +2 -0
- package/dist/lib/mirror/infra/update-pkg.mjs +2 -0
- package/dist/lib/mirror/infra/workspace-packages.mjs +2 -0
- package/dist/lib/mirror/infra/workspace-packages.test.mjs +167 -0
- package/dist/lib/mirror/presentation/reporter.mjs +2 -0
- package/dist/lib/tag/application/engine.mjs +2 -0
- package/dist/lib/tag/application/engine.test.mjs +159 -0
- package/dist/lib/tag/domain/types.mjs +1 -0
- package/dist/lib/tag/index.mjs +5 -0
- package/dist/lib/tag/infra/target-resolver.mjs +2 -0
- package/dist/lib/tag/presentation/colors.mjs +2 -0
- package/dist/lib/tag/presentation/tag-presenter.mjs +2 -0
- package/dist/lib/tag/presentation/tag-presenter.test.mjs +29 -0
- package/dist/loader-DpN-zl5g.mjs +78 -0
- package/dist/mirror-CbGiLXKT.mjs +2 -0
- package/dist/mirror-DqJE3ejL.mjs +66 -0
- package/dist/node-io-DFRbHO6m.mjs +30 -0
- package/dist/package-filter-C_8ryqvz.mjs +26 -0
- package/dist/path-normalizer-D4ceBO3l.mjs +7 -0
- package/dist/program-DR-H4tH3.mjs +34 -0
- package/dist/program.mjs +2 -0
- package/dist/repo-root-HmtIEm6J.mjs +22 -0
- package/dist/report-DYxvw34T.mjs +24 -0
- package/dist/reporter-CwIe_tAM.mjs +108 -0
- package/dist/run-target-CJWrqNT4.mjs +65 -0
- package/dist/schema-Or8RAARd.mjs +25 -0
- package/dist/sync-e1Sp-shi.mjs +157 -0
- package/dist/tag-Cd9JujU5.mjs +2 -0
- package/dist/tag-hEKVZ_-7.mjs +58 -0
- package/dist/tag-presenter-Cs66UBsH.mjs +63 -0
- package/dist/target-resolver-CR3FXMTy.mjs +170 -0
- package/dist/targets-pCTslnFh.mjs +106 -0
- package/dist/tokenizer-CeZx73Zu.mjs +216 -0
- package/dist/update-pkg-CnGfjWBy.mjs +37 -0
- package/dist/walk-DjgQn66n.mjs +33 -0
- package/dist/workspace-packages-K2NYTHJq.mjs +159 -0
- package/package.json +42 -53
- package/CHANGELOG.md +0 -15
- package/dist/cjs/index.cjs +0 -2
- package/dist/cjs/src/index.d.ts +0 -3
- package/dist/cjs/src/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/src/index.d.ts +0 -3
- package/dist/esm/src/index.d.ts.map +0 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { t as createNodeCliFs } from "../../../node-io-DFRbHO6m.mjs";
|
|
2
|
+
import { i as workspacePatternToPackageJsonGlob, n as parsePnpmWorkspaceDocument, r as splitWorkspacePackageEntries, t as findWorkspacePackageRelPaths } from "../../../workspace-packages-K2NYTHJq.mjs";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
//#region src/lib/mirror/infra/workspace-packages.test.ts
|
|
7
|
+
function createTestLogger() {
|
|
8
|
+
const lines = [];
|
|
9
|
+
return {
|
|
10
|
+
lines,
|
|
11
|
+
out: (line) => {
|
|
12
|
+
lines.push(line);
|
|
13
|
+
},
|
|
14
|
+
err: (line) => {
|
|
15
|
+
lines.push(`[err] ${line}`);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
describe("splitWorkspacePackageEntries", () => {
|
|
20
|
+
it("splits include and exclude entries", () => {
|
|
21
|
+
expect(splitWorkspacePackageEntries([
|
|
22
|
+
"packages/*",
|
|
23
|
+
"!packages/playground",
|
|
24
|
+
"apps/*"
|
|
25
|
+
])).toEqual({
|
|
26
|
+
include: ["packages/*", "apps/*"],
|
|
27
|
+
exclude: ["packages/playground"]
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it("ignores non-strings", () => {
|
|
31
|
+
expect(splitWorkspacePackageEntries([
|
|
32
|
+
"a",
|
|
33
|
+
1,
|
|
34
|
+
null,
|
|
35
|
+
"b"
|
|
36
|
+
])).toEqual({
|
|
37
|
+
include: ["a", "b"],
|
|
38
|
+
exclude: []
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe("parsePnpmWorkspaceDocument", () => {
|
|
43
|
+
it("throws on non-object root", () => {
|
|
44
|
+
expect(() => parsePnpmWorkspaceDocument([])).toThrow(/root must be a mapping/);
|
|
45
|
+
expect(() => parsePnpmWorkspaceDocument("x")).toThrow(/root must be a mapping/);
|
|
46
|
+
});
|
|
47
|
+
it("throws when packages is not an array", () => {
|
|
48
|
+
expect(() => parsePnpmWorkspaceDocument({ packages: "nope" })).toThrow(/must be an array/);
|
|
49
|
+
});
|
|
50
|
+
it("marks missing packages key", () => {
|
|
51
|
+
expect(parsePnpmWorkspaceDocument({ catalog: {} })).toEqual({
|
|
52
|
+
include: [],
|
|
53
|
+
exclude: [],
|
|
54
|
+
hasPackagesKey: false,
|
|
55
|
+
isEmptyPackagesArray: false
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it("marks explicit empty array", () => {
|
|
59
|
+
expect(parsePnpmWorkspaceDocument({ packages: [] })).toEqual({
|
|
60
|
+
include: [],
|
|
61
|
+
exclude: [],
|
|
62
|
+
hasPackagesKey: true,
|
|
63
|
+
isEmptyPackagesArray: true
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe("workspacePatternToPackageJsonGlob", () => {
|
|
68
|
+
it("appends /package.json with POSIX slashes", () => {
|
|
69
|
+
expect(workspacePatternToPackageJsonGlob("packages/*")).toBe("packages/*/package.json");
|
|
70
|
+
expect(workspacePatternToPackageJsonGlob("packages/**")).toBe("packages/**/package.json");
|
|
71
|
+
expect(workspacePatternToPackageJsonGlob("apps/*")).toBe("apps/*/package.json");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe("findWorkspacePackageRelPaths", () => {
|
|
75
|
+
const cliFs = createNodeCliFs();
|
|
76
|
+
it("falls back to packages/* when pnpm-workspace.yaml is missing", async () => {
|
|
77
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ws-missing-"));
|
|
78
|
+
const logger = createTestLogger();
|
|
79
|
+
try {
|
|
80
|
+
fs.mkdirSync(path.join(root, "packages", "a"), { recursive: true });
|
|
81
|
+
fs.writeFileSync(path.join(root, "packages", "a", "package.json"), "{}", "utf8");
|
|
82
|
+
const { relPaths, multiSource } = await findWorkspacePackageRelPaths(root, cliFs, logger);
|
|
83
|
+
expect(relPaths).toEqual(["packages/a"]);
|
|
84
|
+
expect(multiSource).toBe("default-patterns");
|
|
85
|
+
} finally {
|
|
86
|
+
fs.rmSync(root, {
|
|
87
|
+
recursive: true,
|
|
88
|
+
force: true
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
it("reads globs from pnpm-workspace.yaml", async () => {
|
|
93
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ws-yaml-"));
|
|
94
|
+
const logger = createTestLogger();
|
|
95
|
+
try {
|
|
96
|
+
fs.writeFileSync(path.join(root, "pnpm-workspace.yaml"), `packages:
|
|
97
|
+
- 'tooling/*'
|
|
98
|
+
- 'packages/*'
|
|
99
|
+
`, "utf8");
|
|
100
|
+
fs.mkdirSync(path.join(root, "tooling", "eslint"), { recursive: true });
|
|
101
|
+
fs.writeFileSync(path.join(root, "tooling", "eslint", "package.json"), "{}", "utf8");
|
|
102
|
+
fs.mkdirSync(path.join(root, "packages", "ui"), { recursive: true });
|
|
103
|
+
fs.writeFileSync(path.join(root, "packages", "ui", "package.json"), "{}", "utf8");
|
|
104
|
+
const { relPaths, multiSource } = await findWorkspacePackageRelPaths(root, cliFs, logger);
|
|
105
|
+
expect(relPaths).toEqual(["packages/ui", "tooling/eslint"]);
|
|
106
|
+
expect(multiSource).toBe("pnpm-workspace-yaml");
|
|
107
|
+
} finally {
|
|
108
|
+
fs.rmSync(root, {
|
|
109
|
+
recursive: true,
|
|
110
|
+
force: true
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
it("applies negated workspace patterns", async () => {
|
|
115
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ws-neg-"));
|
|
116
|
+
const logger = createTestLogger();
|
|
117
|
+
try {
|
|
118
|
+
fs.writeFileSync(path.join(root, "pnpm-workspace.yaml"), `packages:
|
|
119
|
+
- 'packages/*'
|
|
120
|
+
- '!packages/skip'
|
|
121
|
+
`, "utf8");
|
|
122
|
+
for (const name of ["keep", "skip"]) {
|
|
123
|
+
fs.mkdirSync(path.join(root, "packages", name), { recursive: true });
|
|
124
|
+
fs.writeFileSync(path.join(root, "packages", name, "package.json"), "{}", "utf8");
|
|
125
|
+
}
|
|
126
|
+
const { relPaths, multiSource } = await findWorkspacePackageRelPaths(root, cliFs, logger);
|
|
127
|
+
expect(relPaths).toEqual(["packages/keep"]);
|
|
128
|
+
expect(multiSource).toBe("pnpm-workspace-yaml");
|
|
129
|
+
} finally {
|
|
130
|
+
fs.rmSync(root, {
|
|
131
|
+
recursive: true,
|
|
132
|
+
force: true
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
it("returns empty paths when packages is an explicit empty array", async () => {
|
|
137
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ws-empty-arr-"));
|
|
138
|
+
const logger = createTestLogger();
|
|
139
|
+
try {
|
|
140
|
+
fs.writeFileSync(path.join(root, "pnpm-workspace.yaml"), `packages: []
|
|
141
|
+
`, "utf8");
|
|
142
|
+
const { relPaths, multiSource } = await findWorkspacePackageRelPaths(root, cliFs, logger);
|
|
143
|
+
expect(relPaths).toEqual([]);
|
|
144
|
+
expect(multiSource).toBe("declared-empty");
|
|
145
|
+
} finally {
|
|
146
|
+
fs.rmSync(root, {
|
|
147
|
+
recursive: true,
|
|
148
|
+
force: true
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
it("rejects invalid YAML document when file exists", async () => {
|
|
153
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ws-bad-yaml-"));
|
|
154
|
+
const logger = createTestLogger();
|
|
155
|
+
try {
|
|
156
|
+
fs.writeFileSync(path.join(root, "pnpm-workspace.yaml"), "{ not yaml", "utf8");
|
|
157
|
+
await expect(findWorkspacePackageRelPaths(root, cliFs, logger)).rejects.toThrow(/Failed to parse pnpm-workspace.yaml/);
|
|
158
|
+
} finally {
|
|
159
|
+
fs.rmSync(root, {
|
|
160
|
+
recursive: true,
|
|
161
|
+
force: true
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
//#endregion
|
|
167
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as mirrorBanner, c as mirrorNoPackages, d as mirrorSummarySeparator, f as printMirrorConfigWarnings, i as logSkippedWorkspacePackage, l as mirrorProcessingMode, n as logPackageError, o as mirrorFatalError, r as logPackageSuccess, s as mirrorGlobWarning, t as configureMirrorColors, u as mirrorSummary } from "../../../reporter-CwIe_tAM.mjs";
|
|
2
|
+
export { configureMirrorColors, logPackageError, logPackageSuccess, logSkippedWorkspacePackage, mirrorBanner, mirrorFatalError, mirrorGlobWarning, mirrorNoPackages, mirrorProcessingMode, mirrorSummary, mirrorSummarySeparator, printMirrorConfigWarnings };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { t as createNodeCliFs } from "../../../node-io-DFRbHO6m.mjs";
|
|
2
|
+
import { n as runTagOnTarget, r as runTagSync, t as resolveNearestPackageVersion } from "../../../engine-CcWEHSCq.mjs";
|
|
3
|
+
import "../../../tag-Cd9JujU5.mjs";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
//#region src/lib/tag/application/engine.test.ts
|
|
8
|
+
const tagFs = createNodeCliFs();
|
|
9
|
+
function withTempPackage(fileName, source, fn) {
|
|
10
|
+
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "tag-engine-"));
|
|
11
|
+
const srcDir = path.join(rootDir, "src");
|
|
12
|
+
const sourceFile = path.join(srcDir, fileName);
|
|
13
|
+
try {
|
|
14
|
+
fs.mkdirSync(srcDir, { recursive: true });
|
|
15
|
+
fs.writeFileSync(path.join(rootDir, "package.json"), "{\"name\":\"demo\",\"version\":\"1.2.3\"}", "utf8");
|
|
16
|
+
fs.writeFileSync(sourceFile, source, "utf8");
|
|
17
|
+
fn({
|
|
18
|
+
rootDir,
|
|
19
|
+
sourceFile
|
|
20
|
+
});
|
|
21
|
+
} finally {
|
|
22
|
+
fs.rmSync(rootDir, {
|
|
23
|
+
recursive: true,
|
|
24
|
+
force: true
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
describe("resolveNearestPackageVersion", () => {
|
|
29
|
+
it("loads version from nearest package.json", () => {
|
|
30
|
+
withTempPackage("index.ts", "export const foo = 1;\n", ({ sourceFile }) => {
|
|
31
|
+
expect(resolveNearestPackageVersion(sourceFile, tagFs)).toBe("1.2.3");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe("runTagOnTarget", () => {
|
|
36
|
+
it("adds @since for exported declarations and preserves existing @since tags", () => {
|
|
37
|
+
withTempPackage("index.ts", `/** Existing docs */
|
|
38
|
+
export function a() {
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @since 0.0.1 */
|
|
43
|
+
export const b = 2;
|
|
44
|
+
|
|
45
|
+
const c = 3;
|
|
46
|
+
export { c };
|
|
47
|
+
`, ({ sourceFile, rootDir }) => {
|
|
48
|
+
const result = runTagOnTarget(path.join(rootDir, "src"), { write: true }, tagFs);
|
|
49
|
+
const after = fs.readFileSync(sourceFile, "utf8");
|
|
50
|
+
expect(result.version).toBe("1.2.3");
|
|
51
|
+
expect(result.filesChanged).toBe(1);
|
|
52
|
+
expect(result.taggedDeclarations).toBe(2);
|
|
53
|
+
expect(after).toContain("* @since 1.2.3");
|
|
54
|
+
expect(after).toContain("/** @since 0.0.1 */");
|
|
55
|
+
expect(after).toContain("/**\n * @since 1.2.3\n */\nconst c = 3;");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it("normalizes single-line JSDoc to multiline before appending @since", () => {
|
|
59
|
+
withTempPackage("types.ts", `/** String or no-substitution template literal used as a Tailwind class blob. */
|
|
60
|
+
export type TailwindClassBlob = string;
|
|
61
|
+
`, ({ sourceFile, rootDir }) => {
|
|
62
|
+
runTagOnTarget(path.join(rootDir, "src"), { write: true }, tagFs);
|
|
63
|
+
const after = fs.readFileSync(sourceFile, "utf8");
|
|
64
|
+
expect(after).toContain(`/**
|
|
65
|
+
* String or no-substitution template literal used as a Tailwind class blob.
|
|
66
|
+
*
|
|
67
|
+
* @since 1.2.3
|
|
68
|
+
*/`);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
it("supports dry-run mode without changing files", () => {
|
|
72
|
+
const before = "export interface User { id: string }\n";
|
|
73
|
+
withTempPackage("types.ts", before, ({ sourceFile, rootDir }) => {
|
|
74
|
+
const result = runTagOnTarget(path.join(rootDir, "src"), { write: false }, tagFs);
|
|
75
|
+
const after = fs.readFileSync(sourceFile, "utf8");
|
|
76
|
+
expect(result.filesChanged).toBe(1);
|
|
77
|
+
expect(result.taggedDeclarations).toBe(1);
|
|
78
|
+
expect(after).toBe(before);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe("runTagSync", () => {
|
|
83
|
+
it("auto-discovers workspace package src directories when no target is provided", async () => {
|
|
84
|
+
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "tag-workspace-"));
|
|
85
|
+
const packageOneDir = path.join(rootDir, "packages", "one");
|
|
86
|
+
const packageTwoDir = path.join(rootDir, "packages", "two");
|
|
87
|
+
const packageOneSrcDir = path.join(packageOneDir, "src");
|
|
88
|
+
const packageTwoSrcDir = path.join(packageTwoDir, "src");
|
|
89
|
+
try {
|
|
90
|
+
fs.mkdirSync(packageOneSrcDir, { recursive: true });
|
|
91
|
+
fs.mkdirSync(packageTwoSrcDir, { recursive: true });
|
|
92
|
+
fs.writeFileSync(path.join(rootDir, "pnpm-workspace.yaml"), "packages:\n - 'packages/*'\n", "utf8");
|
|
93
|
+
fs.writeFileSync(path.join(packageOneDir, "package.json"), "{\"name\":\"one\",\"version\":\"1.0.0\"}", "utf8");
|
|
94
|
+
fs.writeFileSync(path.join(packageTwoDir, "package.json"), "{\"name\":\"two\",\"version\":\"2.0.0\"}", "utf8");
|
|
95
|
+
fs.writeFileSync(path.join(packageOneSrcDir, "index.ts"), "export const one = 1;\n", "utf8");
|
|
96
|
+
fs.writeFileSync(path.join(packageTwoSrcDir, "index.ts"), "export const two = 2;\n", "utf8");
|
|
97
|
+
const startedTargets = [];
|
|
98
|
+
const completedTargets = [];
|
|
99
|
+
const runResult = await runTagSync({
|
|
100
|
+
rootDir,
|
|
101
|
+
write: true,
|
|
102
|
+
fs: tagFs,
|
|
103
|
+
listener: {
|
|
104
|
+
onTargetStarted: (target) => startedTargets.push(target.rootRelativeTargetPath),
|
|
105
|
+
onTargetCompleted: (target) => completedTargets.push(target.rootRelativeTargetPath)
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
expect(runResult.selectedTargets.length).toBe(2);
|
|
109
|
+
expect(runResult.targetResults.every((entry) => entry.runError === null)).toBe(true);
|
|
110
|
+
expect(fs.readFileSync(path.join(packageOneSrcDir, "index.ts"), "utf8")).toContain("* @since 1.0.0");
|
|
111
|
+
expect(fs.readFileSync(path.join(packageTwoSrcDir, "index.ts"), "utf8")).toContain("* @since 2.0.0");
|
|
112
|
+
expect(runResult.versionSummary).toBe("mixed");
|
|
113
|
+
expect(runResult.distinctVersions).toEqual(["1.0.0", "2.0.0"]);
|
|
114
|
+
expect(runResult.skippedPackages).toEqual([]);
|
|
115
|
+
expect(runResult.filesChanged).toBe(2);
|
|
116
|
+
expect(startedTargets.sort((left, right) => left.localeCompare(right))).toEqual(["packages/one/src", "packages/two/src"]);
|
|
117
|
+
expect(completedTargets.sort((left, right) => left.localeCompare(right))).toEqual(["packages/one/src", "packages/two/src"]);
|
|
118
|
+
} finally {
|
|
119
|
+
fs.rmSync(rootDir, {
|
|
120
|
+
recursive: true,
|
|
121
|
+
force: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
it("skips workspace packages listed in skipPackages", async () => {
|
|
126
|
+
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "tag-workspace-skip-"));
|
|
127
|
+
const packageOneDir = path.join(rootDir, "packages", "one");
|
|
128
|
+
const packageTwoDir = path.join(rootDir, "packages", "two");
|
|
129
|
+
const packageOneSrcDir = path.join(packageOneDir, "src");
|
|
130
|
+
const packageTwoSrcDir = path.join(packageTwoDir, "src");
|
|
131
|
+
try {
|
|
132
|
+
fs.mkdirSync(packageOneSrcDir, { recursive: true });
|
|
133
|
+
fs.mkdirSync(packageTwoSrcDir, { recursive: true });
|
|
134
|
+
fs.writeFileSync(path.join(rootDir, "pnpm-workspace.yaml"), "packages:\n - 'packages/*'\n", "utf8");
|
|
135
|
+
fs.writeFileSync(path.join(packageOneDir, "package.json"), "{\"name\":\"@scope/one\",\"version\":\"1.0.0\"}", "utf8");
|
|
136
|
+
fs.writeFileSync(path.join(packageTwoDir, "package.json"), "{\"name\":\"@scope/two\",\"version\":\"2.0.0\"}", "utf8");
|
|
137
|
+
fs.writeFileSync(path.join(packageOneSrcDir, "index.ts"), "export const one = 1;\n", "utf8");
|
|
138
|
+
fs.writeFileSync(path.join(packageTwoSrcDir, "index.ts"), "export const two = 2;\n", "utf8");
|
|
139
|
+
const runResult = await runTagSync({
|
|
140
|
+
rootDir,
|
|
141
|
+
write: true,
|
|
142
|
+
fs: tagFs,
|
|
143
|
+
skipPackages: ["@scope/two"]
|
|
144
|
+
});
|
|
145
|
+
expect(runResult.skippedPackages).toEqual(["@scope/two"]);
|
|
146
|
+
expect(runResult.selectedTargets).toHaveLength(1);
|
|
147
|
+
expect(runResult.selectedTargets[0]?.packageName).toBe("@scope/one");
|
|
148
|
+
expect(fs.readFileSync(path.join(packageOneSrcDir, "index.ts"), "utf8")).toContain("* @since 1.0.0");
|
|
149
|
+
expect(fs.readFileSync(path.join(packageTwoSrcDir, "index.ts"), "utf8")).not.toContain("* @since 2.0.0");
|
|
150
|
+
} finally {
|
|
151
|
+
fs.rmSync(rootDir, {
|
|
152
|
+
recursive: true,
|
|
153
|
+
force: true
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
//#endregion
|
|
159
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { n as createNodeCliLogger, t as createNodeCliFs } from "../../node-io-DFRbHO6m.mjs";
|
|
2
|
+
import { n as runTagOnTarget, r as runTagSync, t as resolveNearestPackageVersion } from "../../engine-CcWEHSCq.mjs";
|
|
3
|
+
import { a as formatWarningsAndErrors, i as formatTargetTable, n as formatProgress, r as formatSummary, t as createTagProgressListener } from "../../tag-presenter-Cs66UBsH.mjs";
|
|
4
|
+
import "../../tag-Cd9JujU5.mjs";
|
|
5
|
+
export { createNodeCliFs, createNodeCliLogger, createTagProgressListener, formatProgress, formatSummary, formatTargetTable, formatWarningsAndErrors, resolveNearestPackageVersion, runTagOnTarget, runTagSync };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as formatWarningsAndErrors, i as formatTargetTable, n as formatProgress, r as formatSummary, t as createTagProgressListener } from "../../../tag-presenter-Cs66UBsH.mjs";
|
|
2
|
+
export { createTagProgressListener, formatProgress, formatSummary, formatTargetTable, formatWarningsAndErrors };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { i as formatTargetTable } from "../../../tag-presenter-Cs66UBsH.mjs";
|
|
2
|
+
//#region src/lib/tag/presentation/tag-presenter.test.ts
|
|
3
|
+
describe("formatTargetTable", () => {
|
|
4
|
+
it("aligns columns using longest package and path values", () => {
|
|
5
|
+
const lines = formatTargetTable([{
|
|
6
|
+
packageName: "@codefast/core",
|
|
7
|
+
packageDir: "/repo/packages/core",
|
|
8
|
+
rootRelativeTargetPath: "packages/core/src",
|
|
9
|
+
targetPath: "/repo/packages/core/src",
|
|
10
|
+
source: "workspace-package-selected-src"
|
|
11
|
+
}, {
|
|
12
|
+
packageName: "@codefast/benchmark-tailwind-variants",
|
|
13
|
+
packageDir: "/repo/benchmarks/tailwind-variants",
|
|
14
|
+
rootRelativeTargetPath: "benchmarks/tailwind-variants/src",
|
|
15
|
+
targetPath: "/repo/benchmarks/tailwind-variants/src",
|
|
16
|
+
source: "workspace-package-selected-src"
|
|
17
|
+
}], "/repo").split("\n");
|
|
18
|
+
const headerLine = lines[3];
|
|
19
|
+
const firstDataLine = lines[5];
|
|
20
|
+
const secondDataLine = lines[6];
|
|
21
|
+
const pathHeaderIndex = headerLine.indexOf("path");
|
|
22
|
+
const firstPathIndex = firstDataLine.indexOf("packages/core/src");
|
|
23
|
+
const secondPathIndex = secondDataLine.indexOf("benchmarks/tailwind-variants/src");
|
|
24
|
+
expect(firstPathIndex).toBe(pathHeaderIndex);
|
|
25
|
+
expect(secondPathIndex).toBe(pathHeaderIndex);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { n as codefastConfigSchema } from "./schema-Or8RAARd.mjs";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import jiti from "jiti";
|
|
5
|
+
import { ZodError } from "zod";
|
|
6
|
+
//#region src/lib/config/infra/loader.ts
|
|
7
|
+
const CONFIG_JS_PRIORITY = [
|
|
8
|
+
"codefast.config.mjs",
|
|
9
|
+
"codefast.config.js",
|
|
10
|
+
"codefast.config.cjs"
|
|
11
|
+
];
|
|
12
|
+
const CONFIG_JSON = "codefast.config.json";
|
|
13
|
+
const cachedLoads = /* @__PURE__ */ new Map();
|
|
14
|
+
function formatZodError(error, filePath) {
|
|
15
|
+
const formatted = error.issues.map((issue) => {
|
|
16
|
+
return ` - ${issue.path.length > 0 ? issue.path.join(".") : "<root>"}: ${issue.message}`;
|
|
17
|
+
}).join("\n");
|
|
18
|
+
return `Invalid config schema in ${path.basename(filePath)}:\n${formatted}`;
|
|
19
|
+
}
|
|
20
|
+
function parseLoadedConfig(raw, filePath) {
|
|
21
|
+
try {
|
|
22
|
+
return codefastConfigSchema.parse(raw);
|
|
23
|
+
} catch (caughtError) {
|
|
24
|
+
if (caughtError instanceof ZodError) throw new Error(formatZodError(caughtError, filePath));
|
|
25
|
+
throw caughtError;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function listConfigCandidates(startDir, fs) {
|
|
29
|
+
const candidates = [];
|
|
30
|
+
let current = path.resolve(startDir);
|
|
31
|
+
while (true) {
|
|
32
|
+
for (const name of CONFIG_JS_PRIORITY) {
|
|
33
|
+
const candidate = path.join(current, name);
|
|
34
|
+
if (fs.existsSync(candidate)) candidates.push(candidate);
|
|
35
|
+
}
|
|
36
|
+
const jsonCandidate = path.join(current, CONFIG_JSON);
|
|
37
|
+
if (fs.existsSync(jsonCandidate)) candidates.push(jsonCandidate);
|
|
38
|
+
const parent = path.dirname(current);
|
|
39
|
+
if (parent === current) break;
|
|
40
|
+
current = parent;
|
|
41
|
+
}
|
|
42
|
+
return candidates;
|
|
43
|
+
}
|
|
44
|
+
async function readConfigFromPath(filePath, fs) {
|
|
45
|
+
if (path.extname(filePath) === ".json") {
|
|
46
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
47
|
+
return parseLoadedConfig(JSON.parse(content), filePath);
|
|
48
|
+
}
|
|
49
|
+
const moduleConfig = jiti(process.cwd(), {
|
|
50
|
+
interopDefault: true,
|
|
51
|
+
moduleCache: false
|
|
52
|
+
})(filePath);
|
|
53
|
+
return parseLoadedConfig(typeof moduleConfig === "object" && moduleConfig !== null && "default" in moduleConfig ? moduleConfig.default : moduleConfig, filePath);
|
|
54
|
+
}
|
|
55
|
+
async function loadOnce(fs, startDir) {
|
|
56
|
+
const warnings = [];
|
|
57
|
+
const configPaths = listConfigCandidates(startDir, fs);
|
|
58
|
+
if (configPaths.length === 0) return {
|
|
59
|
+
config: {},
|
|
60
|
+
warnings
|
|
61
|
+
};
|
|
62
|
+
const configPath = configPaths[0];
|
|
63
|
+
return {
|
|
64
|
+
config: await readConfigFromPath(configPath, fs),
|
|
65
|
+
warnings,
|
|
66
|
+
configPath
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
async function loadConfig(fs, startDir = process.cwd()) {
|
|
70
|
+
const cacheKey = path.resolve(startDir);
|
|
71
|
+
if (!cachedLoads.has(cacheKey)) cachedLoads.set(cacheKey, loadOnce(fs, cacheKey));
|
|
72
|
+
return cachedLoads.get(cacheKey);
|
|
73
|
+
}
|
|
74
|
+
function resetConfigLoaderCacheForTests() {
|
|
75
|
+
cachedLoads.clear();
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { resetConfigLoaderCacheForTests as n, loadConfig as t };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { t as messageFromCaughtUnknown } from "./caught-unknown-message-CRhkDWO7.mjs";
|
|
2
|
+
import { t as loadConfig } from "./loader-DpN-zl5g.mjs";
|
|
3
|
+
import "./config-DVia_f9a.mjs";
|
|
4
|
+
import { t as printConfigSchemaWarnings } from "./config-reporter-SCcWDZc1.mjs";
|
|
5
|
+
import { n as createNodeCliLogger, t as createNodeCliFs } from "./node-io-DFRbHO6m.mjs";
|
|
6
|
+
import { t as findRepoRoot } from "./repo-root-HmtIEm6J.mjs";
|
|
7
|
+
import { t as runMirrorSync } from "./sync-e1Sp-shi.mjs";
|
|
8
|
+
import "./mirror-CbGiLXKT.mjs";
|
|
9
|
+
import process from "node:process";
|
|
10
|
+
import { realpathSync } from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
//#region src/commands/mirror.ts
|
|
13
|
+
function tryRealpath(entryPath) {
|
|
14
|
+
try {
|
|
15
|
+
return realpathSync.native(entryPath);
|
|
16
|
+
} catch {
|
|
17
|
+
return path.resolve(entryPath);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function normalizePath(relPath) {
|
|
21
|
+
return relPath.split(path.sep).join("/").replace(/\\/g, "/");
|
|
22
|
+
}
|
|
23
|
+
function packageArgToRelative(rootDir, arg) {
|
|
24
|
+
if (!arg) return void 0;
|
|
25
|
+
const rootReal = tryRealpath(path.resolve(rootDir));
|
|
26
|
+
const cwdReal = tryRealpath(process.cwd());
|
|
27
|
+
const targetReal = tryRealpath(path.isAbsolute(arg) ? path.resolve(arg) : path.resolve(cwdReal, arg));
|
|
28
|
+
const normalized = normalizePath(path.relative(rootReal, targetReal));
|
|
29
|
+
if (normalized.startsWith("..") || path.isAbsolute(normalized) || normalized === "" || normalized === ".") throw new Error(`Package path must be a subdirectory under monorepo root: ${rootDir}`);
|
|
30
|
+
return normalized;
|
|
31
|
+
}
|
|
32
|
+
function registerMirrorCommand(program) {
|
|
33
|
+
program.command("mirror").description("Keep package manifests aligned with what you ship").command("sync").description("Write package.json exports from dist/ for workspace packages").argument("[package]", "Optional package path relative to repo root (e.g. packages/ui)").option("-v, --verbose", "Print extra diagnostics", false).action(async function(pkg, options) {
|
|
34
|
+
const globals = this.optsWithGlobals();
|
|
35
|
+
const fs = createNodeCliFs();
|
|
36
|
+
const logger = createNodeCliLogger();
|
|
37
|
+
const rootDir = findRepoRoot(fs);
|
|
38
|
+
let packageFilter;
|
|
39
|
+
try {
|
|
40
|
+
packageFilter = packageArgToRelative(rootDir, pkg);
|
|
41
|
+
} catch (caughtPathError) {
|
|
42
|
+
this.error(messageFromCaughtUnknown(caughtPathError));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let mirrorConfig = {};
|
|
46
|
+
try {
|
|
47
|
+
const { config, warnings } = await loadConfig(fs, rootDir);
|
|
48
|
+
printConfigSchemaWarnings(logger, warnings);
|
|
49
|
+
mirrorConfig = config.mirror ?? {};
|
|
50
|
+
} catch (caughtConfigError) {
|
|
51
|
+
this.error(messageFromCaughtUnknown(caughtConfigError));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
process.exitCode = await runMirrorSync({
|
|
55
|
+
rootDir,
|
|
56
|
+
config: mirrorConfig,
|
|
57
|
+
verbose: options.verbose,
|
|
58
|
+
noColor: globals.color === false,
|
|
59
|
+
packageFilter,
|
|
60
|
+
fs,
|
|
61
|
+
logger
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { registerMirrorCommand as n, packageArgToRelative as t };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import fsPromises from "node:fs/promises";
|
|
4
|
+
//#region src/lib/infra/node-io.ts
|
|
5
|
+
function createNodeCliFs() {
|
|
6
|
+
return {
|
|
7
|
+
existsSync: fs.existsSync,
|
|
8
|
+
statSync: fs.statSync,
|
|
9
|
+
readFileSync: fs.readFileSync,
|
|
10
|
+
writeFileSync: fs.writeFileSync,
|
|
11
|
+
readdirSync: fs.readdirSync,
|
|
12
|
+
readFile: (p, enc) => fsPromises.readFile(p, enc),
|
|
13
|
+
writeFile: (p, data, enc) => fsPromises.writeFile(p, data, enc),
|
|
14
|
+
readdir: (p, opts) => fsPromises.readdir(p, opts),
|
|
15
|
+
rename: (oldPath, newPath) => fsPromises.rename(oldPath, newPath),
|
|
16
|
+
unlink: (p) => fsPromises.unlink(p)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function createNodeCliLogger() {
|
|
20
|
+
return {
|
|
21
|
+
out: (line) => {
|
|
22
|
+
process.stdout.write(`${line}\n`);
|
|
23
|
+
},
|
|
24
|
+
err: (line) => {
|
|
25
|
+
process.stderr.write(`${line}\n`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createNodeCliLogger as n, createNodeCliFs as t };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { t as normalizePath } from "./path-normalizer-D4ceBO3l.mjs";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/lib/mirror/infra/package-filter.ts
|
|
5
|
+
function tryRealpath(entryPath) {
|
|
6
|
+
try {
|
|
7
|
+
return realpathSync.native(entryPath);
|
|
8
|
+
} catch {
|
|
9
|
+
return path.resolve(entryPath);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve `packageFilter` to a POSIX-ish path relative to `rootDir`, without using
|
|
14
|
+
* `process.cwd()`. Use for programmatic `runMirrorSync` calls.
|
|
15
|
+
*
|
|
16
|
+
* @throws If the resolved path is not a strict subdirectory of `rootDir`.
|
|
17
|
+
*/
|
|
18
|
+
function resolvePackageFilterUnderRoot(rootDir, packageFilter) {
|
|
19
|
+
const rootReal = tryRealpath(path.resolve(rootDir));
|
|
20
|
+
const resolved = path.isAbsolute(packageFilter) ? tryRealpath(path.resolve(packageFilter)) : tryRealpath(path.join(rootReal, packageFilter));
|
|
21
|
+
const normalized = normalizePath(path.relative(rootReal, resolved));
|
|
22
|
+
if (normalized.startsWith("..") || path.isAbsolute(normalized) || normalized === "" || normalized === ".") throw new Error(`Package path must be a subdirectory under monorepo root: ${rootDir}`);
|
|
23
|
+
return normalized;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { resolvePackageFilterUnderRoot as t };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { t as registerArrangeCommand } from "./arrange-Bbh62DrU.mjs";
|
|
2
|
+
import { n as registerMirrorCommand } from "./mirror-DqJE3ejL.mjs";
|
|
3
|
+
import { t as registerTagCommand } from "./tag-hEKVZ_-7.mjs";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
//#region src/program.ts
|
|
10
|
+
function readVersion() {
|
|
11
|
+
try {
|
|
12
|
+
const dir = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const raw = readFileSync(path.join(dir, "..", "package.json"), "utf-8");
|
|
14
|
+
const pkgVersion = JSON.parse(raw).version;
|
|
15
|
+
return typeof pkgVersion === "string" && pkgVersion.length > 0 ? pkgVersion : "unknown";
|
|
16
|
+
} catch {
|
|
17
|
+
return "unknown";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function createProgram() {
|
|
21
|
+
const program = new Command();
|
|
22
|
+
program.name("codefast").description("Codefast monorepo developer CLI").version(readVersion()).option("--no-color", "Disable ANSI color output").configureHelp({ sortSubcommands: true }).showHelpAfterError("(use --help for usage)");
|
|
23
|
+
registerMirrorCommand(program);
|
|
24
|
+
registerArrangeCommand(program);
|
|
25
|
+
registerTagCommand(program);
|
|
26
|
+
return program;
|
|
27
|
+
}
|
|
28
|
+
async function runCli(argv) {
|
|
29
|
+
await createProgram().parseAsync(argv, { from: "node" });
|
|
30
|
+
const code = process.exitCode ?? 0;
|
|
31
|
+
return typeof code === "number" ? code : Number(code) || 0;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { runCli as n, createProgram as t };
|
package/dist/program.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
//#region src/lib/infra/workspace/repo-root.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the monorepo root (directory containing `pnpm-workspace.yaml`).
|
|
6
|
+
* Tries the compiled package location first, then `process.cwd()`.
|
|
7
|
+
*/
|
|
8
|
+
function findRepoRoot(fs) {
|
|
9
|
+
const candidates = [path.dirname(fileURLToPath(import.meta.url)), process.cwd()];
|
|
10
|
+
for (const start of candidates) {
|
|
11
|
+
let dir = path.resolve(start);
|
|
12
|
+
for (;;) {
|
|
13
|
+
if (fs.existsSync(path.join(dir, "pnpm-workspace.yaml"))) return dir;
|
|
14
|
+
const parent = path.dirname(dir);
|
|
15
|
+
if (parent === dir) break;
|
|
16
|
+
dir = parent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Could not locate monorepo root (missing pnpm-workspace.yaml). Searched from: ${candidates.join(", ")}`);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { findRepoRoot as t };
|