@reliverse/dler 1.7.22 → 1.7.23

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.
Files changed (31) hide show
  1. package/bin/app/cmds.d.ts +1 -1
  2. package/bin/app/cmds.js +1 -1
  3. package/bin/app/inject/cmd.d.ts +0 -24
  4. package/bin/app/inject/cmd.js +0 -47
  5. package/bin/app/{spell → magic}/cmd.d.ts +2 -0
  6. package/bin/app/magic/cmd.js +101 -0
  7. package/bin/app/pub/impl.js +4 -2
  8. package/bin/libs/cfg/cfg-mod.d.ts +1 -1
  9. package/bin/libs/cfg/cfg-mod.js +1 -1
  10. package/bin/libs/cfg/rse/rse-impl/rse-create.js +1 -1
  11. package/bin/libs/cfg/rse/rse-impl/rse-define.d.ts +10 -10
  12. package/bin/libs/cfg/rse/rse-mod.d.ts +1 -1
  13. package/bin/libs/cfg/rse/rse-mod.js +1 -1
  14. package/bin/libs/sdk/sdk-impl/cmds/inject/inject-impl-mod.d.ts +63 -0
  15. package/bin/libs/sdk/sdk-impl/cmds/inject/inject-impl-mod.js +237 -0
  16. package/bin/libs/sdk/sdk-impl/config/info.js +1 -1
  17. package/bin/libs/sdk/sdk-impl/magic/apply.d.ts +63 -0
  18. package/bin/libs/sdk/sdk-impl/{spell/applyMagicSpells.js → magic/apply.js} +223 -70
  19. package/bin/libs/sdk/sdk-impl/{spell → magic}/spells.d.ts +16 -1
  20. package/bin/libs/sdk/sdk-impl/{spell → magic}/spells.js +41 -1
  21. package/bin/libs/sdk/sdk-mod.d.ts +4 -4
  22. package/bin/libs/sdk/sdk-mod.js +2 -2
  23. package/package.json +2 -2
  24. package/bin/app/inject/impl.d.ts +0 -5
  25. package/bin/app/inject/impl.js +0 -159
  26. package/bin/app/spell/cmd.js +0 -47
  27. package/bin/libs/sdk/sdk-impl/spell/applyMagicSpells.d.ts +0 -38
  28. /package/bin/app/{spell → magic}/old.d.ts +0 -0
  29. /package/bin/app/{spell → magic}/old.js +0 -0
  30. /package/bin/libs/cfg/rse/rse-impl/{rse-inject.d.ts → rse-comments.d.ts} +0 -0
  31. /package/bin/libs/cfg/rse/rse-impl/{rse-inject.js → rse-comments.js} +0 -0
@@ -1,159 +0,0 @@
1
- import path from "@reliverse/pathkit";
2
- import fs from "@reliverse/relifso";
3
- import { relinka } from "@reliverse/relinka";
4
- import { execa } from "execa";
5
- function parseCommand(command) {
6
- const regex = /"([^"]+)"|'([^']+)'|(\S+)/g;
7
- const args = [];
8
- let match;
9
- while (regex.exec(command) !== null) {
10
- match = regex.exec(command);
11
- if (match) {
12
- const value = match[1] ?? match[2] ?? match[3];
13
- if (value) {
14
- args.push(value);
15
- }
16
- }
17
- }
18
- const cmd = args.shift() ?? "";
19
- return { cmd, args };
20
- }
21
- async function parseLinesFile(linesFile) {
22
- const fileContents = await fs.readFile(linesFile, "utf8");
23
- const splitted = fileContents.split(/\r?\n/);
24
- const results = [];
25
- for (const rawLine of splitted) {
26
- const trimmed = rawLine.trim();
27
- if (!trimmed) continue;
28
- const firstMatch = trimmed.match(/^(\d+)\s+(.+?):(\d+)$/);
29
- if (firstMatch?.[2] && firstMatch?.[3]) {
30
- results.push({
31
- filePath: firstMatch[2],
32
- lineNumber: Number.parseInt(firstMatch[3], 10)
33
- });
34
- continue;
35
- }
36
- const secondMatch = trimmed.match(/^(.+?):(\d+)$/);
37
- if (secondMatch?.[1] && secondMatch?.[2]) {
38
- results.push({
39
- filePath: secondMatch[1],
40
- lineNumber: Number.parseInt(secondMatch[2], 10)
41
- });
42
- } else {
43
- relinka("warn", `Line doesn't match expected format: ${trimmed}`);
44
- }
45
- }
46
- return results;
47
- }
48
- async function runTscAndParseErrors(tscCommand, tscPaths) {
49
- try {
50
- const { cmd, args: cmdArgs } = parseCommand(tscCommand);
51
- if (tscPaths?.length) {
52
- cmdArgs.push(...tscPaths);
53
- }
54
- const subprocess = await execa(cmd, cmdArgs, { all: true, reject: false });
55
- const combinedOutput = subprocess.all ?? "";
56
- return parseErrorOutput(combinedOutput);
57
- } catch (error) {
58
- if (error && typeof error === "object" && "all" in error) {
59
- const combined = error.all ?? "";
60
- if (!combined) {
61
- relinka("log", "TSC returned no error lines. Possibly no TS errors?");
62
- return [];
63
- }
64
- return parseErrorOutput(combined);
65
- }
66
- return [];
67
- }
68
- }
69
- function parseErrorOutput(output) {
70
- const results = [];
71
- const splitted = output.split(/\r?\n/);
72
- const regex = /^(.+?)\((\d+),(\d+)\): error TS\d+: /;
73
- for (const line of splitted) {
74
- const match = line.trim().match(regex);
75
- if (match?.[1] && match?.[2]) {
76
- const file = match[1].replace(/\\/g, "/");
77
- const row = Number.parseInt(match[2], 10);
78
- if (row > 0) {
79
- results.push({ filePath: file, lineNumber: row });
80
- }
81
- }
82
- }
83
- return results;
84
- }
85
- function isWithin(filePath, dirs) {
86
- const absFile = path.resolve(filePath);
87
- return dirs.some((dir) => {
88
- const absDir = path.resolve(dir);
89
- const normalizedDir = absDir.endsWith(path.sep) ? absDir : absDir + path.sep;
90
- return absFile.startsWith(normalizedDir);
91
- });
92
- }
93
- async function injectCommentIntoFiles(linesRecords, commentText) {
94
- const byFile = /* @__PURE__ */ new Map();
95
- for (const rec of linesRecords) {
96
- const lines = byFile.get(rec.filePath) ?? [];
97
- lines.push(rec.lineNumber);
98
- byFile.set(rec.filePath, lines);
99
- }
100
- for (const [filePath, lineNums] of byFile.entries()) {
101
- lineNums.sort((a, b) => b - a);
102
- const absPath = path.resolve(filePath);
103
- relinka("log", `Injecting into ${absPath} at lines: ${lineNums.join(", ")}`);
104
- try {
105
- const original = await fs.readFile(absPath, "utf8");
106
- const splitted = original.split(/\r?\n/);
107
- for (const ln of lineNums) {
108
- if (ln <= splitted.length) {
109
- splitted.splice(ln - 1, 0, commentText);
110
- } else {
111
- relinka("warn", `Line ${ln} exceeds file length for ${absPath}`);
112
- }
113
- }
114
- const newContent = splitted.join("\n");
115
- await fs.writeFile(absPath, newContent, "utf8");
116
- } catch (error) {
117
- relinka("error", `Failed editing ${filePath}: ${error}`);
118
- }
119
- }
120
- }
121
- export async function useTsExpectError(args) {
122
- const finalComment = args.comment ?? "// @ts-expect-error TODO: fix ts";
123
- const tscCommand = "tsc --project ./tsconfig.json --noEmit";
124
- const lines = [];
125
- const usedAuto = args.files.some((item) => item.toLowerCase() === "auto");
126
- if (usedAuto) {
127
- relinka("log", "Running TSC to discover error lines...");
128
- try {
129
- const discovered = await runTscAndParseErrors(tscCommand, args.tscPaths);
130
- if (args.tscPaths?.length) {
131
- const filtered = discovered.filter(
132
- (rec) => args.tscPaths ? isWithin(rec.filePath, args.tscPaths) : true
133
- );
134
- lines.push(...filtered);
135
- } else {
136
- lines.push(...discovered);
137
- }
138
- } catch (error) {
139
- relinka("error", `Failed running tsc: ${error}`);
140
- process.exit(1);
141
- }
142
- }
143
- for (const item of args.files) {
144
- if (item.toLowerCase() === "auto") continue;
145
- try {
146
- const recs = await parseLinesFile(item);
147
- lines.push(...recs);
148
- } catch (error) {
149
- relinka("error", `Failed reading lines file ${item}: ${error}`);
150
- }
151
- }
152
- if (lines.length === 0) {
153
- relinka("error", "No references found. Nothing to do.");
154
- relinka("error", "Lines: ", JSON.stringify(lines));
155
- process.exit(1);
156
- }
157
- await injectCommentIntoFiles(lines, finalComment);
158
- relinka("success", "All lines processed successfully.");
159
- }
@@ -1,47 +0,0 @@
1
- import { defineArgs, defineCommand } from "@reliverse/rempts";
2
- import { applyMagicSpells } from "../../libs/sdk/sdk-impl/spell/applyMagicSpells.js";
3
- import { formatError } from "../../libs/sdk/sdk-impl/utils/utils-error-cwd.js";
4
- export default defineCommand({
5
- args: defineArgs({
6
- targets: {
7
- type: "array",
8
- description: "Distribution types to process",
9
- required: true
10
- },
11
- lib: {
12
- type: "string",
13
- description: "Library to process (e.g. cfg, sdk, etc) (for usage with `dist-libs`)"
14
- },
15
- concurrency: {
16
- type: "number",
17
- description: "Number of files to process in parallel"
18
- },
19
- batchSize: {
20
- type: "number",
21
- description: "Number of files to process in each batch"
22
- },
23
- stopOnError: {
24
- type: "boolean",
25
- description: "Stop processing on first error",
26
- default: true
27
- }
28
- }),
29
- async run({ args }) {
30
- const { targets, lib, concurrency, batchSize, stopOnError } = args;
31
- if (lib && !targets?.includes("dist-libs")) {
32
- throw new Error("The 'lib' parameter can only be used with 'dist-libs' target");
33
- }
34
- try {
35
- const finalTargets = targets?.map(
36
- (target) => target === "dist-libs" && lib ? `${target}/${lib}` : target
37
- ) ?? [];
38
- await applyMagicSpells(finalTargets, {
39
- concurrency,
40
- batchSize,
41
- stopOnError
42
- });
43
- } catch (error) {
44
- throw new Error(`\u274C Processing failed: ${formatError(error)}`);
45
- }
46
- }
47
- });
@@ -1,38 +0,0 @@
1
- /**
2
- * Spell runner – walks a directory tree, finds
3
- * magic-comment directives and executes them.
4
- *
5
- * Usage example:
6
- * await applyMagicSpells(["dist-jsr"]);
7
- * await applyMagicSpells(["dist-libs/sdk"]);
8
- * await applyMagicSpells(["dist-npm", "dist-jsr", "dist-libs"]);
9
- */
10
- export interface ApplyMagicSpellsOptions {
11
- /** Absolute or cwd-relative root directory to process */
12
- dir: string;
13
- /** Number of files to process in parallel */
14
- concurrency?: number;
15
- /** Number of files to process in each batch */
16
- batchSize?: number;
17
- /** Whether to stop on first error */
18
- stopOnError?: boolean;
19
- /** Whether to copy files from src before processing */
20
- copyFileWithDirectivesFromSrcBeforeProcessing?: boolean;
21
- }
22
- export interface ApplyMagicSpellsResult {
23
- /** All processed files */
24
- processedFiles: string[];
25
- }
26
- /**
27
- * Processes files in specified distribution directories by applying magic directives
28
- * First scans src directory for files with magic directives, then processes corresponding dist files
29
- * @param targets Array of distribution targets in format "dist-npm", "dist-jsr", "dist-libs" or "dist-libs/lib-name"
30
- * @param options Configuration options for processing
31
- * @returns Object containing arrays of processed files and processed .d.ts files
32
- */
33
- export declare function applyMagicSpells(targets: string[], options?: Partial<ApplyMagicSpellsOptions>): Promise<ApplyMagicSpellsResult>;
34
- /**
35
- * Gets all available registries across all libraries
36
- * @returns Array of unique registry names found across all libraries
37
- */
38
- export declare function getAllAvailableRegistries(): Promise<string[]>;
File without changes
File without changes