@reliverse/dler 1.2.2 → 1.2.4
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 +126 -69
- package/bin/app/build/cmd.js +17 -0
- package/bin/app/cmds.js +6 -0
- package/bin/{cli/args → app}/inject/README.md +20 -20
- package/bin/{cli/args/inject/inject-mod.js → app/inject/cmd.js} +7 -3
- package/bin/app/inject/expect/cmd.js +43 -0
- package/bin/app/inject/expect/impl.js +162 -0
- package/bin/app/libs/cmd.js +0 -0
- package/bin/app/mono/cmd.js +0 -0
- package/bin/app/pub/cmd.js +17 -0
- package/bin/app/relifso/cmd.js +36 -0
- package/bin/{cli/args/init/init-mod.txt → app/relifso/init/cmd.js} +93 -121
- package/bin/app/relifso/init/impl/mod.js +248 -0
- package/bin/app/relifso/init/impl/types.js +0 -0
- package/bin/app/relinka/cmd.js +0 -0
- package/bin/{cli/args/init/cmd/index.js → app/rempts/init/cmd/cmd.js} +3 -2
- package/bin/app/rempts/init/cmds/cmd.js +80 -0
- package/bin/app/spell/cmd.js +0 -0
- package/bin/app/split/cmd.js +0 -0
- package/bin/{cli/args/tools/index.js → app/tools/cmd.js} +1 -1
- package/bin/cli.js +101 -1
- package/bin/init.js +22 -2
- package/bin/libs/cfg/cfg-default.js +4 -1
- package/bin/libs/sdk/sdk-impl/build/build-library.js +57 -25
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist.js +3 -1
- package/bin/mod.js +7 -39
- package/package.json +6 -7
- package/bin/cli/args/deps/deps-mod.js +0 -48
- package/bin/cli/args/init/libs/reinit/reinit-mod.js +0 -5
- package/bin/cli/args/init/libs/reinit/reint-impl/reinit-mod.txt +0 -395
- package/bin/cli/args/init/types.js +0 -1
- package/bin/cli/args/inject/arg-ts-expect-error.txt +0 -49
- package/bin/cli/args/inject/inject-mod.txt +0 -28
- package/bin/cli/args/inject/reinject.config.js +0 -4
- package/bin/cli/args/inject/ts-expect-error.txt +0 -277
- package/bin/cli/args/spell/spell-mod.js +0 -44
- package/bin/cli/args/split/split-mod.js +0 -26
- /package/bin/{cli/args/agg/agg-mod.js → app/agg/cmd.js} +0 -0
- /package/bin/{cli/args/conv/conv-mod.js → app/auth/cmd.js} +0 -0
- /package/bin/{cli/args → app}/conv/README.md +0 -0
- /package/bin/{cli/args/deps/types.js → app/conv/cmd.js} +0 -0
- /package/bin/{cli/args/init/libs/reinit/reint-impl/types.js → app/deps/cmd.js} +0 -0
- /package/bin/{cli/args/deps → app/deps/impl}/analyzer.js +0 -0
- /package/bin/{cli/args/deps → app/deps/impl}/filesystem.js +0 -0
- /package/bin/{cli/args/deps → app/deps/impl}/formatter.js +0 -0
- /package/bin/{cli/args/deps → app/deps/impl}/parser.js +0 -0
- /package/bin/{cli/args/mono/mono-mod.js → app/deps/impl/types.js} +0 -0
- /package/bin/{cli/args/merger → app/merge}/README.md +0 -0
- /package/bin/{cli/args/merger/merger-mod.txt → app/merge/cmd.txt} +0 -0
- /package/bin/{cli/args/init/libs/reinit/reint-impl → app/relifso/init/impl}/const.js +0 -0
- /package/bin/{cli/args/init/libs/reinit/reint-impl → app/relifso/init/impl}/templates/t-gitignore.js +0 -0
- /package/bin/{cli/args/init/libs/reinit/reint-impl → app/relifso/init/impl}/templates/t-license.js +0 -0
- /package/bin/{cli/args/init/libs/reinit/reint-impl → app/relifso/init/impl}/templates/t-readme.js +0 -0
- /package/bin/{cli/args/init/libs/reinit/reint-impl → app/relifso/init/impl}/utils.js +0 -0
- /package/bin/{cli/args/init → app/rempts}/README.md +0 -0
- /package/bin/{cli/args → app}/split/README.md +0 -0
- /package/bin/{cli/args/split/split-impl.js → app/split/impl.js} +0 -0
- /package/bin/{cli/args/tools/tools-impl.js → app/tools/impl.js} +0 -0
- /package/bin/{tools.txt → app/tools/tools.txt} +0 -0
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import { relinka } from "@reliverse/relinka";
|
|
2
|
-
import { loadConfig } from "c12";
|
|
3
|
-
import { execa } from "execa";
|
|
4
|
-
import fs from "fs-extra";
|
|
5
|
-
import path from "pathe";
|
|
6
|
-
|
|
7
|
-
//-------------------------------------
|
|
8
|
-
// 1) c12 config interface
|
|
9
|
-
//-------------------------------------
|
|
10
|
-
type ReinjectUserConfig = {
|
|
11
|
-
// The comment to inject above each error line
|
|
12
|
-
injectComment?: string;
|
|
13
|
-
// The command used to spawn tsc (e.g. "tsc --noEmit --project tsconfig.json")
|
|
14
|
-
tscCommand?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//-------------------------------------
|
|
18
|
-
// 2) Load c12 configs
|
|
19
|
-
//-------------------------------------
|
|
20
|
-
async function loadReinjectConfig(): Promise<ReinjectUserConfig> {
|
|
21
|
-
const { config } = await loadConfig<ReinjectUserConfig>({
|
|
22
|
-
name: "reinject", // tries reinject.config.*, .reinjectrc, etc.
|
|
23
|
-
defaults: {},
|
|
24
|
-
overrides: {},
|
|
25
|
-
dotenv: false,
|
|
26
|
-
packageJson: false,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
injectComment: config.injectComment ?? "// @ts-expect-error TODO: fix ts",
|
|
31
|
-
tscCommand: config.tscCommand ?? "tsc --noEmit",
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//-------------------------------------
|
|
36
|
-
// Helper: Parse command string into command and arguments
|
|
37
|
-
//-------------------------------------
|
|
38
|
-
function parseCommand(command: string): { cmd: string; args: string[] } {
|
|
39
|
-
// This parser splits the command by whitespace while handling double or single quotes.
|
|
40
|
-
const regex = /"([^"]+)"|'([^']+)'|(\S+)/g;
|
|
41
|
-
const args: string[] = [];
|
|
42
|
-
let match: RegExpExecArray | null;
|
|
43
|
-
while ((match = regex.exec(command)) !== null) {
|
|
44
|
-
args.push(match[1] || match[2] || match[3]);
|
|
45
|
-
}
|
|
46
|
-
const cmd = args.shift() || "";
|
|
47
|
-
return { cmd, args };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
//-------------------------------------
|
|
51
|
-
// 3) parseLineRefs from a lines file
|
|
52
|
-
//-------------------------------------
|
|
53
|
-
async function parseLinesFile(linesFile: string) {
|
|
54
|
-
const fileContents = await fs.readFile(linesFile, "utf-8");
|
|
55
|
-
const splitted = fileContents.split(/\r?\n/);
|
|
56
|
-
const results: { filePath: string; lineNumber: number }[] = [];
|
|
57
|
-
|
|
58
|
-
for (const rawLine of splitted) {
|
|
59
|
-
const trimmed = rawLine.trim();
|
|
60
|
-
if (!trimmed) continue;
|
|
61
|
-
|
|
62
|
-
// Could match "N path.ts:line"
|
|
63
|
-
let match = trimmed.match(/^(\d+)\s+(.+?):(\d+)$/);
|
|
64
|
-
if (match) {
|
|
65
|
-
results.push({
|
|
66
|
-
filePath: match[2],
|
|
67
|
-
lineNumber: Number.parseInt(match[3], 10),
|
|
68
|
-
});
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Or "path.ts:line"
|
|
73
|
-
match = trimmed.match(/^(.+?):(\d+)$/);
|
|
74
|
-
if (match) {
|
|
75
|
-
results.push({
|
|
76
|
-
filePath: match[1],
|
|
77
|
-
lineNumber: Number.parseInt(match[2], 10),
|
|
78
|
-
});
|
|
79
|
-
} else {
|
|
80
|
-
relinka("warn", `Line doesn't match expected format: ${trimmed}`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return results;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
//-------------------------------------
|
|
87
|
-
// 4) runTscAndParseErrors: run tsc with execa, parse error lines
|
|
88
|
-
// Example TSC error line format:
|
|
89
|
-
// src/foo.ts(12,5): error TS2322:
|
|
90
|
-
// We'll capture `src/foo.ts` and `12` as the error line number
|
|
91
|
-
//-------------------------------------
|
|
92
|
-
async function runTscAndParseErrors(
|
|
93
|
-
tscCommand: string,
|
|
94
|
-
tscPaths?: string[],
|
|
95
|
-
): Promise<{ filePath: string; lineNumber: number }[]> {
|
|
96
|
-
const linesRefs: { filePath: string; lineNumber: number }[] = [];
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
// Parse the TSC command into the command and its arguments.
|
|
100
|
-
const { cmd, args: cmdArgs } = parseCommand(tscCommand);
|
|
101
|
-
// Append any additional paths (if provided) as extra arguments.
|
|
102
|
-
if (tscPaths && tscPaths.length > 0) {
|
|
103
|
-
cmdArgs.push(...tscPaths);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Run TSC.
|
|
107
|
-
const subprocess = await execa(cmd, cmdArgs, { all: true, reject: false });
|
|
108
|
-
const combinedOutput = subprocess.all || "";
|
|
109
|
-
const splitted = combinedOutput.split(/\r?\n/);
|
|
110
|
-
const regex = /^(.+?)\((\d+),(\d+)\): error TS\d+: /;
|
|
111
|
-
|
|
112
|
-
for (const line of splitted) {
|
|
113
|
-
const trimmed = line.trim();
|
|
114
|
-
const m = trimmed.match(regex);
|
|
115
|
-
if (m) {
|
|
116
|
-
let file = m[1];
|
|
117
|
-
const row = Number.parseInt(m[2], 10);
|
|
118
|
-
if (row > 0) {
|
|
119
|
-
// Normalize Windows paths.
|
|
120
|
-
file = file.replace(/\\/g, "/");
|
|
121
|
-
linesRefs.push({
|
|
122
|
-
filePath: file,
|
|
123
|
-
lineNumber: row,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
} catch (error: any) {
|
|
129
|
-
// In case of error, try to extract the output.
|
|
130
|
-
const combined = (error.all as string) || "";
|
|
131
|
-
if (!combined) {
|
|
132
|
-
relinka("log", `TSC returned no error lines. Possibly no TS errors?`);
|
|
133
|
-
return [];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const splitted = combined.split(/\r?\n/);
|
|
137
|
-
const regex = /^(.+?)\((\d+),(\d+)\): error TS\d+: /;
|
|
138
|
-
|
|
139
|
-
for (const line of splitted) {
|
|
140
|
-
const m = line.trim().match(regex);
|
|
141
|
-
if (m) {
|
|
142
|
-
let file = m[1];
|
|
143
|
-
const row = Number.parseInt(m[2], 10);
|
|
144
|
-
if (row > 0) {
|
|
145
|
-
file = file.replace(/\\/g, "/");
|
|
146
|
-
linesRefs.push({ filePath: file, lineNumber: row });
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return linesRefs;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
//-------------------------------------
|
|
156
|
-
// Helper: Check if file is within any of the provided directories
|
|
157
|
-
//-------------------------------------
|
|
158
|
-
function isWithin(filePath: string, dirs: string[]): boolean {
|
|
159
|
-
const absFile = path.resolve(filePath);
|
|
160
|
-
for (const dir of dirs) {
|
|
161
|
-
const absDir = path.resolve(dir);
|
|
162
|
-
// Ensure trailing separator for accurate prefix matching
|
|
163
|
-
const normalizedDir = absDir.endsWith(path.sep)
|
|
164
|
-
? absDir
|
|
165
|
-
: absDir + path.sep;
|
|
166
|
-
if (absFile.startsWith(normalizedDir)) {
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
//-------------------------------------
|
|
174
|
-
// 5) The injection logic
|
|
175
|
-
//-------------------------------------
|
|
176
|
-
async function injectCommentIntoFiles(
|
|
177
|
-
linesRecords: { filePath: string; lineNumber: number }[],
|
|
178
|
-
commentText: string,
|
|
179
|
-
) {
|
|
180
|
-
// Group error lines by file
|
|
181
|
-
const byFile = new Map<string, number[]>();
|
|
182
|
-
for (const rec of linesRecords) {
|
|
183
|
-
if (!byFile.has(rec.filePath)) {
|
|
184
|
-
byFile.set(rec.filePath, []);
|
|
185
|
-
}
|
|
186
|
-
byFile.get(rec.filePath)!.push(rec.lineNumber);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
for (const [filePath, lineNums] of byFile.entries()) {
|
|
190
|
-
// Sort descending so injections don't affect subsequent line numbers
|
|
191
|
-
lineNums.sort((a, b) => b - a);
|
|
192
|
-
const absPath = path.resolve(filePath);
|
|
193
|
-
relinka(
|
|
194
|
-
"log",
|
|
195
|
-
`Injecting into ${absPath} at lines: ${lineNums.join(", ")}`,
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
try {
|
|
199
|
-
const original = await fs.readFile(absPath, "utf-8");
|
|
200
|
-
const splitted = original.split(/\r?\n/);
|
|
201
|
-
for (const ln of lineNums) {
|
|
202
|
-
if (ln <= splitted.length) {
|
|
203
|
-
splitted.splice(ln - 1, 0, commentText);
|
|
204
|
-
} else {
|
|
205
|
-
relinka("warn", `Line ${ln} exceeds file length for ${absPath}`);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
const newContent = splitted.join("\n");
|
|
209
|
-
await fs.writeFile(absPath, newContent, "utf-8");
|
|
210
|
-
} catch (error) {
|
|
211
|
-
relinka("error", `Failed editing ${filePath}: ${error}`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
//-------------------------------------
|
|
217
|
-
// 6) The main usage function
|
|
218
|
-
//-------------------------------------
|
|
219
|
-
export async function useTsExpectError(args: {
|
|
220
|
-
files: string[];
|
|
221
|
-
comment?: string;
|
|
222
|
-
tscPaths?: string[];
|
|
223
|
-
}) {
|
|
224
|
-
// 1) load c12 config
|
|
225
|
-
const userConfig = await loadReinjectConfig();
|
|
226
|
-
const finalComment = args.comment || userConfig.injectComment!;
|
|
227
|
-
|
|
228
|
-
// Gather references
|
|
229
|
-
const lines: { filePath: string; lineNumber: number }[] = [];
|
|
230
|
-
let usedAuto = false;
|
|
231
|
-
for (const item of args.files) {
|
|
232
|
-
if (item.toLowerCase() === "auto") {
|
|
233
|
-
usedAuto = true;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (usedAuto) {
|
|
238
|
-
relinka("log", "Running TSC to discover error lines...");
|
|
239
|
-
const tscCommand = userConfig.tscCommand!;
|
|
240
|
-
try {
|
|
241
|
-
const discovered = await runTscAndParseErrors(tscCommand, args.tscPaths);
|
|
242
|
-
// If tscPaths are provided, filter discovered errors to include only files within those paths.
|
|
243
|
-
if (args.tscPaths && args.tscPaths.length > 0) {
|
|
244
|
-
const filtered = discovered.filter((rec) =>
|
|
245
|
-
isWithin(rec.filePath, args.tscPaths!),
|
|
246
|
-
);
|
|
247
|
-
lines.push(...filtered);
|
|
248
|
-
} else {
|
|
249
|
-
lines.push(...discovered);
|
|
250
|
-
}
|
|
251
|
-
} catch (error) {
|
|
252
|
-
relinka("error", `Failed running tsc: ${error}`);
|
|
253
|
-
process.exit(1);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Parse lines from each file that isn't "auto"
|
|
258
|
-
for (const item of args.files) {
|
|
259
|
-
if (item.toLowerCase() === "auto") continue;
|
|
260
|
-
|
|
261
|
-
try {
|
|
262
|
-
const recs = await parseLinesFile(item);
|
|
263
|
-
lines.push(...recs);
|
|
264
|
-
} catch (error) {
|
|
265
|
-
relinka("error", `Failed reading lines file ${item}: ${error}`);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (lines.length === 0) {
|
|
270
|
-
relinka("error", "No references found. Nothing to do.");
|
|
271
|
-
relinka("error", "Lines: ", JSON.stringify(lines));
|
|
272
|
-
process.exit(1);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
await injectCommentIntoFiles(lines, finalComment);
|
|
276
|
-
relinka("success", "All lines processed successfully.");
|
|
277
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { spells } from "../../../libs/sdk/sdk-impl/spell/spell-mod.js";
|
|
3
|
-
export const createCli = () => {
|
|
4
|
-
const program = new Command();
|
|
5
|
-
program.name("dler-spells").description("Execute magic spells in your codebase").version("1.0.0");
|
|
6
|
-
program.command("trigger").description("Trigger magic spells").option(
|
|
7
|
-
"--spells <spells>",
|
|
8
|
-
'Comma-separated list of spells to execute (or "all")',
|
|
9
|
-
"all"
|
|
10
|
-
).option(
|
|
11
|
-
"--files <files>",
|
|
12
|
-
"Comma-separated list of files to process (or all if not specified)"
|
|
13
|
-
).option("--dry-run", "Preview changes without applying them", false).action(async (options) => {
|
|
14
|
-
const requestedSpells = options.spells ? options.spells.split(",") : ["all"];
|
|
15
|
-
const files = options.files ? options.files.split(",") : [];
|
|
16
|
-
console.log(`Triggering spells: ${requestedSpells.join(", ")}`);
|
|
17
|
-
if (files.length) {
|
|
18
|
-
console.log(`On files: ${files.join(", ")}`);
|
|
19
|
-
} else {
|
|
20
|
-
console.log("On all files");
|
|
21
|
-
}
|
|
22
|
-
if (options.dryRun) {
|
|
23
|
-
console.log("DRY RUN - No changes will be applied");
|
|
24
|
-
}
|
|
25
|
-
const results = await spells({
|
|
26
|
-
spells: requestedSpells,
|
|
27
|
-
files,
|
|
28
|
-
dryRun: options.dryRun
|
|
29
|
-
});
|
|
30
|
-
console.log("\nResults:");
|
|
31
|
-
for (const result of results) {
|
|
32
|
-
const status = result.success ? "\u2713" : "\u2717";
|
|
33
|
-
console.log(
|
|
34
|
-
`${status} ${result.file}: ${result.spell.type} - ${result.message}`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
return program;
|
|
39
|
-
};
|
|
40
|
-
const cli = createCli();
|
|
41
|
-
async function main() {
|
|
42
|
-
cli.parse(process.argv);
|
|
43
|
-
}
|
|
44
|
-
await main();
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import fs from "fs-extra";
|
|
2
|
-
import {
|
|
3
|
-
getAllSourceFiles,
|
|
4
|
-
parseCommandLineArgs,
|
|
5
|
-
splitLargeFileByLines,
|
|
6
|
-
splitLargeFunctions
|
|
7
|
-
} from "./split-impl.js";
|
|
8
|
-
async function main() {
|
|
9
|
-
const { directory, fileLineThreshold, funcLineThreshold } = parseCommandLineArgs();
|
|
10
|
-
const allFiles = getAllSourceFiles(directory);
|
|
11
|
-
for (const filePath of allFiles) {
|
|
12
|
-
const lineCount = fs.readFileSync(filePath, "utf8").split("\n").length;
|
|
13
|
-
if (lineCount > fileLineThreshold) {
|
|
14
|
-
const newSplits = splitLargeFileByLines(filePath, fileLineThreshold);
|
|
15
|
-
newSplits.forEach((splitFilePath) => {
|
|
16
|
-
splitLargeFunctions(splitFilePath, funcLineThreshold);
|
|
17
|
-
});
|
|
18
|
-
} else {
|
|
19
|
-
splitLargeFunctions(filePath, funcLineThreshold);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
main().catch((err) => {
|
|
24
|
-
console.error(err);
|
|
25
|
-
process.exit(1);
|
|
26
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/bin/{cli/args/init/libs/reinit/reint-impl → app/relifso/init/impl}/templates/t-gitignore.js
RENAMED
|
File without changes
|
/package/bin/{cli/args/init/libs/reinit/reint-impl → app/relifso/init/impl}/templates/t-license.js
RENAMED
|
File without changes
|
/package/bin/{cli/args/init/libs/reinit/reint-impl → app/relifso/init/impl}/templates/t-readme.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|