@warpgogol/repo-extract 1.1.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/LICENSE +201 -0
- package/README.md +155 -0
- package/dist/changelog.d.ts +9 -0
- package/dist/changelog.d.ts.map +1 -0
- package/dist/changelog.js +41 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +61 -0
- package/dist/config.d.ts +69 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +90 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +39 -0
- package/dist/extract.d.ts +3 -0
- package/dist/extract.d.ts.map +1 -0
- package/dist/extract.js +407 -0
- package/dist/fs/copy.d.ts +16 -0
- package/dist/fs/copy.d.ts.map +1 -0
- package/dist/fs/copy.js +224 -0
- package/dist/fs/discover.d.ts +2 -0
- package/dist/fs/discover.d.ts.map +1 -0
- package/dist/fs/discover.js +126 -0
- package/dist/fs/git.d.ts +10 -0
- package/dist/fs/git.d.ts.map +1 -0
- package/dist/fs/git.js +252 -0
- package/dist/fs/transform.d.ts +16 -0
- package/dist/fs/transform.d.ts.map +1 -0
- package/dist/fs/transform.js +539 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/log.d.ts +6 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +23 -0
- package/dist/package-manager.d.ts +4 -0
- package/dist/package-manager.d.ts.map +1 -0
- package/dist/package-manager.js +30 -0
- package/dist/postprocess/index.d.ts +4 -0
- package/dist/postprocess/index.d.ts.map +1 -0
- package/dist/postprocess/index.js +70 -0
- package/dist/scan.d.ts +4 -0
- package/dist/scan.d.ts.map +1 -0
- package/dist/scan.js +78 -0
- package/dist/types.d.ts +124 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/package.json +82 -0
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>Package.json and tsconfig transformation utilities for exported repos.</purpose>
|
|
4
|
+
<non-goals>
|
|
5
|
+
<item>Does not copy files (see copy.ts).</item>
|
|
6
|
+
</non-goals>
|
|
7
|
+
</MODULE_CONTRACT>
|
|
8
|
+
<CHANGE_SUMMARY>
|
|
9
|
+
<item>Ported transformPackageJson, fixPackageTsconfigs, fixAppTsconfigs, regenerateTsconfigBase, generateRootFiles from scripts/export-clients-helpers.ts for RFC-0070.</item>
|
|
10
|
+
<item>ADR-0010: added lint step, npm publish --provenance, and id-token: write to generateCiWorkflow()</item>
|
|
11
|
+
<item>RFC-0071: Replaced hardcoded org-specific values with config-driven options (stripScopes, preservePackages, rootPackageName, customConditions, onlyBuiltDependencies, packageManager, gitignoreMode).</item>
|
|
12
|
+
<item>RFC-0072: Parameterized buildRootPackageJson, generateRootFiles, generateCiWorkflow, fixStandalonePackageJson for pnpm/npm/yarn support.</item>
|
|
13
|
+
</CHANGE_SUMMARY>
|
|
14
|
+
*/
|
|
15
|
+
import { readFile, writeFile, rm, access, readdir } from "node:fs/promises";
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
import * as path from "node:path";
|
|
18
|
+
import { isIgnored } from "./copy.js";
|
|
19
|
+
export async function transformPackageJson(dest, relPath, config, logger) {
|
|
20
|
+
const fullPath = path.join(dest, relPath);
|
|
21
|
+
let raw;
|
|
22
|
+
try {
|
|
23
|
+
raw = await readFile(fullPath, "utf-8");
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const pkg = JSON.parse(raw);
|
|
29
|
+
let changed = false;
|
|
30
|
+
const stripScopes = config.stripScopes ?? config.workspacePrefixes ?? [];
|
|
31
|
+
const preservePackages = config.preservePackages ?? [];
|
|
32
|
+
if (pkg.devDependencies) {
|
|
33
|
+
for (const key of Object.keys(pkg.devDependencies)) {
|
|
34
|
+
const shouldStrip = stripScopes.some((scope) => key.startsWith(scope));
|
|
35
|
+
const shouldPreserve = preservePackages.includes(key);
|
|
36
|
+
if (shouldStrip && !shouldPreserve) {
|
|
37
|
+
delete pkg.devDependencies[key];
|
|
38
|
+
changed = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (Object.keys(pkg.devDependencies).length === 0) {
|
|
42
|
+
delete pkg.devDependencies;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (relPath.startsWith("packages/") && pkg.scripts) {
|
|
46
|
+
for (const key of ["build", "typecheck"]) {
|
|
47
|
+
const script = pkg.scripts[key];
|
|
48
|
+
if (typeof script === "string" && script.includes("tsconfig.lib.json")) {
|
|
49
|
+
pkg.scripts[key] = script.replaceAll("tsconfig.lib.json", "tsconfig.build.json");
|
|
50
|
+
changed = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
for (const depField of ["dependencies", "devDependencies", "peerDependencies"]) {
|
|
55
|
+
if (pkg[depField]) {
|
|
56
|
+
for (const key of Object.keys(pkg[depField])) {
|
|
57
|
+
const shouldStrip = stripScopes.some((scope) => key.startsWith(scope));
|
|
58
|
+
const shouldPreserve = preservePackages.includes(key);
|
|
59
|
+
if (shouldStrip && !shouldPreserve) {
|
|
60
|
+
delete pkg[depField][key];
|
|
61
|
+
changed = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (Object.keys(pkg[depField]).length === 0) {
|
|
65
|
+
delete pkg[depField];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (changed) {
|
|
70
|
+
await writeFile(fullPath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
|
|
71
|
+
(logger?.log ?? console.log)(` transformed: ${relPath}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export async function fixPackageTsconfigs(dest, packageDirs) {
|
|
75
|
+
for (const pkgDir of packageDirs) {
|
|
76
|
+
const pkgDest = path.join(dest, pkgDir);
|
|
77
|
+
try {
|
|
78
|
+
await rm(path.join(pkgDest, "tsconfig.lib.json"), { force: true });
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
/* no-op */
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
await rm(path.join(pkgDest, "tsconfig.tsbuildinfo"), { force: true });
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
/* no-op */
|
|
88
|
+
}
|
|
89
|
+
const depth = pkgDir.split("/").length;
|
|
90
|
+
const baseRef = `${"../".repeat(depth)}tsconfig.base.json`;
|
|
91
|
+
const tsconfigPath = path.join(pkgDest, "tsconfig.json");
|
|
92
|
+
try {
|
|
93
|
+
await writeFile(tsconfigPath, JSON.stringify({
|
|
94
|
+
extends: baseRef,
|
|
95
|
+
compilerOptions: {
|
|
96
|
+
rootDir: "src",
|
|
97
|
+
outDir: "dist",
|
|
98
|
+
tsBuildInfoFile: "dist/tsconfig.tsbuildinfo",
|
|
99
|
+
emitDeclarationOnly: false,
|
|
100
|
+
forceConsistentCasingInFileNames: true,
|
|
101
|
+
types: ["node"],
|
|
102
|
+
},
|
|
103
|
+
include: ["src/**/*.ts"],
|
|
104
|
+
}, null, 2) + "\n");
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
/* no-op */
|
|
108
|
+
}
|
|
109
|
+
const tsconfigBuildPath = path.join(pkgDest, "tsconfig.build.json");
|
|
110
|
+
try {
|
|
111
|
+
await writeFile(tsconfigBuildPath, JSON.stringify({
|
|
112
|
+
extends: "./tsconfig.json",
|
|
113
|
+
exclude: ["src/**/*.test.ts", "src/tests/**"],
|
|
114
|
+
}, null, 2) + "\n");
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
/* no-op */
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export async function fixAppTsconfigs(dest, appTsconfigPaths) {
|
|
122
|
+
for (const rel of appTsconfigPaths) {
|
|
123
|
+
const full = path.join(dest, rel);
|
|
124
|
+
try {
|
|
125
|
+
const raw = await readFile(full, "utf-8");
|
|
126
|
+
const cfg = JSON.parse(raw);
|
|
127
|
+
delete cfg.references;
|
|
128
|
+
await writeFile(full, JSON.stringify(cfg, null, 2) + "\n");
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
/* no-op */
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export async function regenerateTsconfigBase(dest, config, logger) {
|
|
136
|
+
const compilerOptions = {
|
|
137
|
+
composite: true,
|
|
138
|
+
declarationMap: true,
|
|
139
|
+
emitDeclarationOnly: true,
|
|
140
|
+
importHelpers: true,
|
|
141
|
+
isolatedModules: true,
|
|
142
|
+
lib: ["es2022"],
|
|
143
|
+
module: "nodenext",
|
|
144
|
+
moduleResolution: "nodenext",
|
|
145
|
+
noEmitOnError: true,
|
|
146
|
+
noFallthroughCasesInSwitch: true,
|
|
147
|
+
noImplicitOverride: true,
|
|
148
|
+
noImplicitReturns: true,
|
|
149
|
+
noUnusedLocals: true,
|
|
150
|
+
skipLibCheck: true,
|
|
151
|
+
strict: true,
|
|
152
|
+
target: "es2022",
|
|
153
|
+
};
|
|
154
|
+
if (config.customConditions && config.customConditions.length > 0) {
|
|
155
|
+
compilerOptions.customConditions = config.customConditions;
|
|
156
|
+
}
|
|
157
|
+
const baseTsconfig = { compilerOptions };
|
|
158
|
+
await writeFile(path.join(dest, "tsconfig.base.json"), JSON.stringify(baseTsconfig, null, 2) + "\n");
|
|
159
|
+
(logger?.log ?? console.log)(" regenerated tsconfig.base.json");
|
|
160
|
+
}
|
|
161
|
+
export async function findAppTsconfigs(dest, appDirs) {
|
|
162
|
+
const results = [];
|
|
163
|
+
for (const appDir of appDirs) {
|
|
164
|
+
const fullDir = path.join(dest, appDir);
|
|
165
|
+
await walkForTsconfigs(fullDir, appDir, results);
|
|
166
|
+
}
|
|
167
|
+
return results;
|
|
168
|
+
}
|
|
169
|
+
async function walkForTsconfigs(dir, relDir, results) {
|
|
170
|
+
let entries;
|
|
171
|
+
try {
|
|
172
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
for (const entry of entries) {
|
|
178
|
+
if (entry.isDirectory()) {
|
|
179
|
+
if (isIgnored(entry.name))
|
|
180
|
+
continue;
|
|
181
|
+
await walkForTsconfigs(path.join(dir, entry.name), path.join(relDir, entry.name), results);
|
|
182
|
+
}
|
|
183
|
+
else if (entry.name === "tsconfig.json") {
|
|
184
|
+
results.push(relDir.replace(/\\/g, "/") + "/tsconfig.json");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export async function findPackageJsonFiles(dest, dirs) {
|
|
189
|
+
const results = [];
|
|
190
|
+
for (const dir of dirs) {
|
|
191
|
+
const fullDir = path.join(dest, dir);
|
|
192
|
+
await walkForPackageJson(fullDir, dir, results);
|
|
193
|
+
}
|
|
194
|
+
return results;
|
|
195
|
+
}
|
|
196
|
+
async function walkForPackageJson(dir, relDir, results) {
|
|
197
|
+
let entries;
|
|
198
|
+
try {
|
|
199
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
for (const entry of entries) {
|
|
205
|
+
if (entry.isDirectory()) {
|
|
206
|
+
if (isIgnored(entry.name))
|
|
207
|
+
continue;
|
|
208
|
+
await walkForPackageJson(path.join(dir, entry.name), path.join(relDir, entry.name), results);
|
|
209
|
+
}
|
|
210
|
+
else if (entry.name === "package.json") {
|
|
211
|
+
results.push(relDir.replace(/\\/g, "/") + "/package.json");
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
export function buildGitignore(extraLines = [], config) {
|
|
216
|
+
const mode = config?.gitignoreMode ?? "extended";
|
|
217
|
+
const base = [
|
|
218
|
+
".env",
|
|
219
|
+
".env.*",
|
|
220
|
+
"",
|
|
221
|
+
"# Build outputs",
|
|
222
|
+
"dist",
|
|
223
|
+
"node_modules",
|
|
224
|
+
"",
|
|
225
|
+
"# Workspace",
|
|
226
|
+
".turbo",
|
|
227
|
+
"",
|
|
228
|
+
"# TypeScript",
|
|
229
|
+
"*.tsbuildinfo",
|
|
230
|
+
"",
|
|
231
|
+
"# OS files",
|
|
232
|
+
".DS_Store",
|
|
233
|
+
"Thumbs.db",
|
|
234
|
+
];
|
|
235
|
+
if (mode === "extended") {
|
|
236
|
+
const extra = extraLines.length > 0 ? ["", ...extraLines] : [];
|
|
237
|
+
return [...base, ...extra].join("\n");
|
|
238
|
+
}
|
|
239
|
+
const extra = extraLines.length > 0 ? ["", ...extraLines] : [];
|
|
240
|
+
return [...base, ...extra].join("\n");
|
|
241
|
+
}
|
|
242
|
+
function rootScripts(pm) {
|
|
243
|
+
if (pm === "npm") {
|
|
244
|
+
return {
|
|
245
|
+
build: "npm run build --workspaces --if-present",
|
|
246
|
+
typecheck: "npm run typecheck --workspaces --if-present",
|
|
247
|
+
lint: "npm run lint --workspaces --if-present",
|
|
248
|
+
test: "npm test --workspaces --if-present",
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
if (pm === "yarn") {
|
|
252
|
+
return {
|
|
253
|
+
build: "yarn workspaces foreach run build",
|
|
254
|
+
typecheck: "yarn workspaces foreach run typecheck",
|
|
255
|
+
lint: "yarn workspaces foreach run lint",
|
|
256
|
+
test: "yarn workspaces foreach run test",
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
build: 'pnpm --recursive --filter "./apps/**" exec pnpm run build',
|
|
261
|
+
typecheck: 'pnpm --recursive --filter "./apps/**" exec pnpm run typecheck',
|
|
262
|
+
lint: 'pnpm --recursive --filter "./apps/**" exec pnpm run lint',
|
|
263
|
+
test: 'pnpm --recursive --filter "./apps/**" exec pnpm run --if-present test',
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function detectSourcePackageManagerVersion(root) {
|
|
267
|
+
try {
|
|
268
|
+
const rootPkg = JSON.parse(readFileSync(path.join(root, "package.json"), "utf-8"));
|
|
269
|
+
return rootPkg.packageManager;
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
export function buildRootPackageJson(destName, config, pm, root) {
|
|
276
|
+
const pkg = {
|
|
277
|
+
name: config.rootPackageName ?? `exported-${destName}`,
|
|
278
|
+
private: true,
|
|
279
|
+
scripts: rootScripts(pm),
|
|
280
|
+
devDependencies: {
|
|
281
|
+
"@eslint/js": "^10.0.1",
|
|
282
|
+
"@types/node": "^22.10.0",
|
|
283
|
+
eslint: "~10.7.0",
|
|
284
|
+
tsx: "^4.22.3",
|
|
285
|
+
typescript: "~6.0.3",
|
|
286
|
+
"typescript-eslint": "^8.64.0",
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
if (pm === "pnpm") {
|
|
290
|
+
const version = root ? detectSourcePackageManagerVersion(root) : undefined;
|
|
291
|
+
if (version) {
|
|
292
|
+
pkg.packageManager = version;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return pkg;
|
|
296
|
+
}
|
|
297
|
+
export async function generateRootFiles(dest, root, config, packageDirs, appDirs, pm, logger) {
|
|
298
|
+
const rootPkg = buildRootPackageJson(config.destName, config, pm, root);
|
|
299
|
+
if (pm === "pnpm") {
|
|
300
|
+
// pnpm: write pnpm-workspace.yaml, add onlyBuiltDependencies if configured
|
|
301
|
+
await writeFile(path.join(dest, "package.json"), JSON.stringify(rootPkg, null, 2) + "\n");
|
|
302
|
+
const workspaceEntries = new Set();
|
|
303
|
+
workspaceEntries.add("packages/*");
|
|
304
|
+
workspaceEntries.add("packages/*/*");
|
|
305
|
+
for (const appDir of appDirs) {
|
|
306
|
+
const parts = appDir.split("/");
|
|
307
|
+
if (parts.length >= 2) {
|
|
308
|
+
workspaceEntries.add(`${parts.slice(0, -1).join("/")}/*`);
|
|
309
|
+
}
|
|
310
|
+
if (parts.length >= 3) {
|
|
311
|
+
workspaceEntries.add(`${appDir}/*`);
|
|
312
|
+
}
|
|
313
|
+
if (parts.length === 2) {
|
|
314
|
+
workspaceEntries.add("apps/*");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const workspaceYamlLines = [
|
|
318
|
+
"packages:",
|
|
319
|
+
...Array.from(workspaceEntries)
|
|
320
|
+
.sort()
|
|
321
|
+
.map((e) => ` - ${e}`),
|
|
322
|
+
"",
|
|
323
|
+
];
|
|
324
|
+
if (config.onlyBuiltDependencies && config.onlyBuiltDependencies.length > 0) {
|
|
325
|
+
workspaceYamlLines.push("onlyBuiltDependencies:");
|
|
326
|
+
for (const dep of config.onlyBuiltDependencies) {
|
|
327
|
+
workspaceYamlLines.push(` - '${dep}'`);
|
|
328
|
+
}
|
|
329
|
+
workspaceYamlLines.push("");
|
|
330
|
+
}
|
|
331
|
+
await writeFile(path.join(dest, "pnpm-workspace.yaml"), workspaceYamlLines.join("\n"));
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
// npm/yarn: add workspaces field to root package.json, no separate workspace file
|
|
335
|
+
const workspaceEntries = ["packages/*", "packages/*/*"];
|
|
336
|
+
for (const appDir of appDirs) {
|
|
337
|
+
const parts = appDir.split("/");
|
|
338
|
+
if (parts.length >= 2) {
|
|
339
|
+
workspaceEntries.push(`${parts.slice(0, -1).join("/")}/*`);
|
|
340
|
+
}
|
|
341
|
+
if (parts.length >= 3) {
|
|
342
|
+
workspaceEntries.push(`${appDir}/*`);
|
|
343
|
+
}
|
|
344
|
+
if (parts.length === 2) {
|
|
345
|
+
workspaceEntries.push("apps/*");
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
rootPkg.workspaces = Array.from(new Set(workspaceEntries)).sort();
|
|
349
|
+
await writeFile(path.join(dest, "package.json"), JSON.stringify(rootPkg, null, 2) + "\n");
|
|
350
|
+
}
|
|
351
|
+
await writeFile(path.join(dest, ".gitignore"), buildGitignore(config.extraGitignore, config));
|
|
352
|
+
const appRefs = [];
|
|
353
|
+
for (const appDir of appDirs) {
|
|
354
|
+
const srcTsconfig = path.join(root, appDir, "tsconfig.json");
|
|
355
|
+
try {
|
|
356
|
+
await access(srcTsconfig);
|
|
357
|
+
appRefs.push({ path: `./${appDir}` });
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
/* no tsconfig.json at this level — skip */
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
const references = [...packageDirs.map((d) => ({ path: `./${d}` })), ...appRefs];
|
|
364
|
+
const tsconfig = {
|
|
365
|
+
extends: "./tsconfig.base.json",
|
|
366
|
+
compileOnSave: false,
|
|
367
|
+
files: [],
|
|
368
|
+
references,
|
|
369
|
+
};
|
|
370
|
+
await writeFile(path.join(dest, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n");
|
|
371
|
+
const workspaceFile = pm === "pnpm" ? "pnpm-workspace.yaml" : "(workspaces in package.json)";
|
|
372
|
+
(logger?.log ?? console.log)(` generated: package.json, ${workspaceFile}, .gitignore, tsconfig.json`);
|
|
373
|
+
}
|
|
374
|
+
export async function cleanStrayArtifacts(dest) {
|
|
375
|
+
for (const name of ["node_modules"]) {
|
|
376
|
+
try {
|
|
377
|
+
await rm(path.join(dest, name), { recursive: true, force: true });
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
/* no-op */
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
async function cleanDeep(dir) {
|
|
384
|
+
let entries;
|
|
385
|
+
try {
|
|
386
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
for (const e of entries) {
|
|
392
|
+
const full = path.join(dir, e.name);
|
|
393
|
+
if (e.isDirectory()) {
|
|
394
|
+
if (e.name === "node_modules" || e.name === ".turbo") {
|
|
395
|
+
await rm(full, { recursive: true, force: true });
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
await cleanDeep(full);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
else if (e.name.endsWith(".tsbuildinfo") || e.name.endsWith(".db")) {
|
|
402
|
+
await rm(full, { force: true });
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
await cleanDeep(dest);
|
|
407
|
+
}
|
|
408
|
+
export function generateCiWorkflow(pm, ci) {
|
|
409
|
+
if (ci?.provider === "none")
|
|
410
|
+
return null;
|
|
411
|
+
const nodeVersion = ci?.nodeVersion ?? 22;
|
|
412
|
+
const publish = ci?.publish ?? true;
|
|
413
|
+
const setupSteps = [];
|
|
414
|
+
const installCmd = pm === "pnpm"
|
|
415
|
+
? "pnpm install --frozen-lockfile"
|
|
416
|
+
: pm === "yarn"
|
|
417
|
+
? "yarn install --frozen-lockfile"
|
|
418
|
+
: "npm ci";
|
|
419
|
+
const runPrefix = pm === "pnpm" ? "pnpm run" : pm === "yarn" ? "yarn" : "npm run";
|
|
420
|
+
const testCmd = pm === "pnpm" ? "pnpm test" : pm === "yarn" ? "yarn test" : "npm test";
|
|
421
|
+
const cacheKey = pm === "pnpm" ? "pnpm" : pm === "yarn" ? "yarn" : "npm";
|
|
422
|
+
setupSteps.push(" - uses: actions/checkout@v5");
|
|
423
|
+
if (pm === "pnpm") {
|
|
424
|
+
setupSteps.push(" - uses: pnpm/action-setup@v6");
|
|
425
|
+
}
|
|
426
|
+
setupSteps.push(" - uses: actions/setup-node@v5");
|
|
427
|
+
setupSteps.push(" with:");
|
|
428
|
+
setupSteps.push(` node-version: ${nodeVersion}`);
|
|
429
|
+
setupSteps.push(` cache: ${cacheKey}`);
|
|
430
|
+
setupSteps.push(` - run: ${installCmd}`);
|
|
431
|
+
const buildSteps = [
|
|
432
|
+
` - run: ${runPrefix} lint`,
|
|
433
|
+
` - run: ${runPrefix} typecheck`,
|
|
434
|
+
` - run: ${runPrefix} build`,
|
|
435
|
+
` - run: ${testCmd}`,
|
|
436
|
+
];
|
|
437
|
+
const publishSteps = [];
|
|
438
|
+
if (publish) {
|
|
439
|
+
publishSteps.push(" - run: npm publish --provenance --access public");
|
|
440
|
+
publishSteps.push(" env:");
|
|
441
|
+
publishSteps.push(" NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}");
|
|
442
|
+
}
|
|
443
|
+
return [
|
|
444
|
+
"name: CI",
|
|
445
|
+
"",
|
|
446
|
+
"on:",
|
|
447
|
+
" push:",
|
|
448
|
+
" branches: [main]",
|
|
449
|
+
" pull_request:",
|
|
450
|
+
"",
|
|
451
|
+
"permissions:",
|
|
452
|
+
" contents: read",
|
|
453
|
+
" id-token: write",
|
|
454
|
+
"",
|
|
455
|
+
"jobs:",
|
|
456
|
+
" ci:",
|
|
457
|
+
" runs-on: ubuntu-latest",
|
|
458
|
+
" timeout-minutes: 15",
|
|
459
|
+
" steps:",
|
|
460
|
+
...setupSteps,
|
|
461
|
+
...buildSteps,
|
|
462
|
+
...publishSteps,
|
|
463
|
+
"",
|
|
464
|
+
].join("\n");
|
|
465
|
+
}
|
|
466
|
+
export async function fixStandalonePackageJson(dest, config, pm, root, logger) {
|
|
467
|
+
const pkgPath = path.join(dest, "package.json");
|
|
468
|
+
let raw;
|
|
469
|
+
try {
|
|
470
|
+
raw = await readFile(pkgPath, "utf-8");
|
|
471
|
+
}
|
|
472
|
+
catch {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const pkg = JSON.parse(raw);
|
|
476
|
+
let changed = false;
|
|
477
|
+
const stripScopes = config.stripScopes ?? config.workspacePrefixes ?? [];
|
|
478
|
+
const preservePackages = config.preservePackages ?? [];
|
|
479
|
+
if (pkg.scripts?.test && typeof pkg.scripts.test === "string") {
|
|
480
|
+
if (pkg.scripts.test.includes("--dir ../../..") ||
|
|
481
|
+
pkg.scripts.test.includes("--config packages/")) {
|
|
482
|
+
pkg.scripts.test = "vitest run";
|
|
483
|
+
changed = true;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
for (const depField of ["dependencies", "devDependencies", "peerDependencies"]) {
|
|
487
|
+
if (pkg[depField]) {
|
|
488
|
+
for (const key of Object.keys(pkg[depField])) {
|
|
489
|
+
if (depField === "peerDependencies") {
|
|
490
|
+
if (pkg[depField][key] === "workspace:*") {
|
|
491
|
+
pkg[depField][key] = "*";
|
|
492
|
+
changed = true;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
const shouldStrip = stripScopes.some((scope) => key.startsWith(scope));
|
|
497
|
+
const shouldPreserve = preservePackages.includes(key);
|
|
498
|
+
if (shouldStrip && !shouldPreserve) {
|
|
499
|
+
delete pkg[depField][key];
|
|
500
|
+
changed = true;
|
|
501
|
+
}
|
|
502
|
+
else if (pkg[depField][key] === "workspace:*") {
|
|
503
|
+
pkg[depField][key] = "*";
|
|
504
|
+
changed = true;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (Object.keys(pkg[depField]).length === 0) {
|
|
509
|
+
delete pkg[depField];
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (pm === "pnpm" && !pkg.packageManager) {
|
|
514
|
+
const version = root ? detectSourcePackageManagerVersion(root) : undefined;
|
|
515
|
+
if (version) {
|
|
516
|
+
pkg.packageManager = version;
|
|
517
|
+
changed = true;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (changed) {
|
|
521
|
+
await writeFile(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
|
|
522
|
+
(logger?.log ?? console.log)(" fixed standalone package.json (test script, workspace deps, packageManager)");
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
export async function fixStandaloneVitestConfig(dest, logger) {
|
|
526
|
+
const configPath = path.join(dest, "vitest.config.ts");
|
|
527
|
+
let raw;
|
|
528
|
+
try {
|
|
529
|
+
raw = await readFile(configPath, "utf-8");
|
|
530
|
+
}
|
|
531
|
+
catch {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
const fixed = raw.replace(/["']packages\/[^/]+\/(tests\/\*\*\/\*\.test\.ts)["']/g, '"$1"');
|
|
535
|
+
if (fixed !== raw) {
|
|
536
|
+
await writeFile(configPath, fixed, "utf-8");
|
|
537
|
+
(logger?.log ?? console.log)(" fixed vitest.config.ts (relative test paths)");
|
|
538
|
+
}
|
|
539
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { loadConfig, ExtractConfigSchema } from "./config.js";
|
|
2
|
+
export { extractProject } from "./extract.js";
|
|
3
|
+
export { detectPackageManager } from "./package-manager.js";
|
|
4
|
+
export { scanForSecrets } from "./scan.js";
|
|
5
|
+
export { transferGitHistory, commitExport, diffSummary } from "./fs/git.js";
|
|
6
|
+
export { generateCiWorkflow, fixStandalonePackageJson, fixStandaloneVitestConfig, buildGitignore, buildRootPackageJson, } from "./fs/transform.js";
|
|
7
|
+
export { isIgnored } from "./fs/copy.js";
|
|
8
|
+
export { SecretScanError, GitOperationError, PackageManagerError } from "./errors.js";
|
|
9
|
+
export type { ExtractConfig, ExtractContext, ExtractOptions, ExtractResult, ExtractProgressEvent, ProgressCallback, PackageManager, CiConfig, PostProcessRule, PostProcessAction, CopyRule, PatchRule, DeleteRule, GitConfig, SecretFinding, } from "./types.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,cAAc,EACd,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACtF,YAAY,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,GACd,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>Public API exports for @warpgogol/repo-extract.</purpose>
|
|
4
|
+
<non-goals>
|
|
5
|
+
<item>Does not implement CLI parsing (see cli.ts).</item>
|
|
6
|
+
<item>Does not implement config loading (see config.ts).</item>
|
|
7
|
+
</non-goals>
|
|
8
|
+
</MODULE_CONTRACT>
|
|
9
|
+
<CHANGE_SUMMARY>
|
|
10
|
+
<item>Initial scaffold for RFC-0070.</item>
|
|
11
|
+
<item>RFC-0074: Added diffSummary, buildGitignore, buildRootPackageJson, isIgnored, ExtractResult, ExtractProgressEvent, ProgressCallback, error class exports.</item>
|
|
12
|
+
</CHANGE_SUMMARY>
|
|
13
|
+
*/
|
|
14
|
+
export { loadConfig, ExtractConfigSchema } from "./config.js";
|
|
15
|
+
export { extractProject } from "./extract.js";
|
|
16
|
+
export { detectPackageManager } from "./package-manager.js";
|
|
17
|
+
export { scanForSecrets } from "./scan.js";
|
|
18
|
+
export { transferGitHistory, commitExport, diffSummary } from "./fs/git.js";
|
|
19
|
+
export { generateCiWorkflow, fixStandalonePackageJson, fixStandaloneVitestConfig, buildGitignore, buildRootPackageJson, } from "./fs/transform.js";
|
|
20
|
+
export { isIgnored } from "./fs/copy.js";
|
|
21
|
+
export { SecretScanError, GitOperationError, PackageManagerError } from "./errors.js";
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,MAAM;IACrB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAStD"}
|
package/dist/log.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>Minimal logging abstraction — gates console output on verbose flag for library-grade use.</purpose>
|
|
4
|
+
<non-goals>
|
|
5
|
+
<item>Does not implement structured logging or log levels beyond log/error.</item>
|
|
6
|
+
<item>Does not depend on external logging libraries.</item>
|
|
7
|
+
</non-goals>
|
|
8
|
+
</MODULE_CONTRACT>
|
|
9
|
+
<CHANGE_SUMMARY>
|
|
10
|
+
<item>RFC-0074: Initial logger — Logger interface and createLogger factory.</item>
|
|
11
|
+
</CHANGE_SUMMARY>
|
|
12
|
+
*/
|
|
13
|
+
export function createLogger(verbose) {
|
|
14
|
+
return {
|
|
15
|
+
log: (msg) => {
|
|
16
|
+
if (verbose)
|
|
17
|
+
console.log(msg);
|
|
18
|
+
},
|
|
19
|
+
error: (msg) => {
|
|
20
|
+
console.error(msg);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../src/package-manager.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,cAAc,CAqBlF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>Detect package manager from lockfile presence in source root.</purpose>
|
|
4
|
+
<non-goals>
|
|
5
|
+
<item>Does not install packages or generate lockfiles (see extract.ts).</item>
|
|
6
|
+
</non-goals>
|
|
7
|
+
</MODULE_CONTRACT>
|
|
8
|
+
<CHANGE_SUMMARY>
|
|
9
|
+
<item>RFC-0072: Initial detectPackageManager() pure function.</item>
|
|
10
|
+
</CHANGE_SUMMARY>
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync } from "node:fs";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
export function detectPackageManager(root, logger) {
|
|
15
|
+
const lockfiles = [
|
|
16
|
+
{ file: "pnpm-lock.yaml", pm: "pnpm" },
|
|
17
|
+
{ file: "yarn.lock", pm: "yarn" },
|
|
18
|
+
{ file: "package-lock.json", pm: "npm" },
|
|
19
|
+
];
|
|
20
|
+
const found = [];
|
|
21
|
+
for (const { file, pm } of lockfiles) {
|
|
22
|
+
if (existsSync(path.join(root, file))) {
|
|
23
|
+
found.push(pm);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (found.length > 1) {
|
|
27
|
+
(logger?.log ?? console.warn)(`Warning: multiple lockfiles found in ${root}, using ${found[0]} (priority: pnpm > yarn > npm)`);
|
|
28
|
+
}
|
|
29
|
+
return found[0] ?? "pnpm";
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PostProcessRule, ExtractContext, ProgressCallback } from "../types.js";
|
|
2
|
+
import type { Logger } from "../log.js";
|
|
3
|
+
export declare function runPostProcess(ctx: ExtractContext, rules: PostProcessRule[], onProgress?: ProgressCallback, logger?: Logger): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/postprocess/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,wBAAsB,cAAc,CAClC,GAAG,EAAE,cAAc,EACnB,KAAK,EAAE,eAAe,EAAE,EACxB,UAAU,CAAC,EAAE,gBAAgB,EAC7B,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAmBf"}
|