@reliverse/dler 1.2.3 → 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 CHANGED
@@ -66,14 +66,6 @@ bun dev # bun src/mod.ts --dev
66
66
  bun update --latest
67
67
  ```
68
68
 
69
- **or install globally**:
70
-
71
- ```sh
72
- bun i -g @reliverse/dler
73
- # or update as needed:
74
- bun -g update --latest
75
- ```
76
-
77
69
  2. **prepare your project**:
78
70
 
79
71
  a. **configure `.gitignore`**:
package/bin/app/cmds.js CHANGED
@@ -0,0 +1,6 @@
1
+ export async function getCmdRelifsoInit() {
2
+ return (await import("./relifso/init/cmd.js")).default;
3
+ }
4
+ export async function getCmdInjectTsExpectError() {
5
+ return (await import("./inject/expect/cmd.js")).default;
6
+ }
@@ -1,10 +1,10 @@
1
- # @reliverse/reinject | Reinjection CLI & Core
1
+ # dler inject
2
2
 
3
- [💖 GitHub Sponsors](https://github.com/sponsors/blefnk) • [💬 Discord](https://discord.gg/Pb8uKbwpsJ) • [📦 NPM](https://npmjs.com/@reliverse/reinject) • [📚 Docs](https://blefnk.reliverse.org/blog/my-products/reinject)
3
+ [💖 GitHub Sponsors](https://github.com/sponsors/blefnk) • [💬 Discord](https://discord.gg/Pb8uKbwpsJ) • [📦 NPM](https://npmjs.com/@reliverse/inject) • [📚 Docs](https://blefnk.reliverse.org/blog/my-products/inject)
4
4
 
5
- **@reliverse/reinject** handles the boring parts for you. For example:
5
+ **@reliverse/inject** handles the boring parts for you. For example:
6
6
 
7
- - ✅ Need to insert `// @ts-expect-error` above a TypeScript error? Reinject’s got you.
7
+ - ✅ Need to insert `// @ts-expect-error` above a TypeScript error? Inject’s got you.
8
8
  - 🔜 Fixing repetitive warns, lint suppressions, or compiler nags? One-liner.
9
9
  - 🔜 Even more features to come!
10
10
 
@@ -23,18 +23,18 @@ Make sure you have Git, Node.js, and bun•pnpm•yarn•npm installed.
23
23
  ### Installation
24
24
 
25
25
  ```bash
26
- bun i -g @reliverse/reinject
26
+ bun i -g @reliverse/inject
27
27
  ```
28
28
 
29
29
  Or use with `bun x` (or `npx`):
30
30
 
31
31
  ```bash
32
- bun x @reliverse/reinject
32
+ bun x @reliverse/inject
33
33
  ```
34
34
 
35
35
  ### Basic Usage
36
36
 
37
- **User config** in `reinject.config.ts`:
37
+ **User config** in `inject.config.ts`:
38
38
 
39
39
  ```ts
40
40
  export default {
@@ -47,15 +47,15 @@ export default {
47
47
 
48
48
  ```bash
49
49
  # 1) Automatic mode:
50
- reinject ts-expect-error auto
50
+ inject ts-expect-error auto
51
51
  # => runs `tsc`, finds errors, injects comment above them.
52
52
 
53
53
  # 2) Lines-file mode:
54
- reinject ts-expect-error linesA.txt linesB.txt
54
+ inject ts-expect-error linesA.txt linesB.txt
55
55
  # => no TSC, just parses references from lines files
56
56
 
57
57
  # 3) Mixed:
58
- reinject ts-expect-error auto lines.txt
58
+ inject ts-expect-error auto lines.txt
59
59
  # => merges TSC errors with references in lines.txt
60
60
  ```
61
61
 
@@ -63,41 +63,41 @@ reinject ts-expect-error auto lines.txt
63
63
 
64
64
  ```bash
65
65
  # When you need a custom comment:
66
- reinject ts-expect-error auto --comment="// @ts-expect-error FIXME"
66
+ inject ts-expect-error auto --comment="// @ts-expect-error FIXME"
67
67
  ```
68
68
 
69
69
  Run on a TypeScript file with tsc output:
70
70
 
71
71
  ```bash
72
- reinject ts-expect-error src
72
+ inject ts-expect-error src
73
73
  ```
74
74
 
75
75
  You can also run on a specific TypeScript file with manually generated tsc output:
76
76
 
77
77
  ```bash
78
78
  tsc --noEmit > tsc.log
79
- reinject tsc.log
79
+ inject tsc.log
80
80
  rm tsc.log
81
81
  ```
82
82
 
83
83
  You can also run it directly on output from stdin:
84
84
 
85
85
  ```bash
86
- tsc --noEmit | reinject
86
+ tsc --noEmit | inject
87
87
  ```
88
88
 
89
89
  Or use with other tools:
90
90
 
91
91
  ```bash
92
- eslint . | reinject
93
- biome check . | reinject
92
+ eslint . | inject
93
+ biome check . | inject
94
94
  ```
95
95
 
96
96
  ### Filter by error code or rule ID
97
97
 
98
98
  ```bash
99
- reinject tsc.log --code TS2322
100
- reinject eslint.log --rule no-unused-vars
99
+ inject tsc.log --code TS2322
100
+ inject eslint.log --rule no-unused-vars
101
101
  ```
102
102
 
103
103
  ## ✨ Examples
@@ -137,9 +137,9 @@ const x: string = 123;
137
137
 
138
138
  ## 🫶 Show some love
139
139
 
140
- If `@reliverse/reinject` saved you time or sanity:
140
+ If `@reliverse/inject` saved you time or sanity:
141
141
 
142
- - ⭐ [Star the repo](https://github.com/reliverse/reinject)
142
+ - ⭐ [Star the repo](https://github.com/reliverse/inject)
143
143
  - 💖 [Sponsor on GitHub](https://github.com/sponsors/blefnk)
144
144
  - 🫶 Share it with a dev friend!
145
145
 
@@ -1,9 +1,10 @@
1
1
  import { relinka } from "@reliverse/relinka";
2
- import { defineCommand, selectPrompt } from "@reliverse/rempts";
2
+ import { defineCommand, runCmd, selectPrompt } from "@reliverse/rempts";
3
+ import { getCmdInjectTsExpectError } from "../cmds.js";
3
4
  export default defineCommand({
4
5
  meta: {
5
6
  name: "cli",
6
- description: "Runs the Reinject CLI interactive menu (displays list of available commands)"
7
+ description: "Runs the Inject command interactive menu (displays list of available commands)"
7
8
  },
8
9
  args: {
9
10
  dev: {
@@ -19,7 +20,7 @@ export default defineCommand({
19
20
  run: async ({ args }) => {
20
21
  const isDev = args.dev;
21
22
  relinka("verbose", `Running in ${isDev ? "dev" : "prod"} mode`);
22
- await selectPrompt({
23
+ const cmd = await selectPrompt({
23
24
  title: "Select a command",
24
25
  options: [
25
26
  {
@@ -28,5 +29,8 @@ export default defineCommand({
28
29
  }
29
30
  ]
30
31
  });
32
+ if (cmd === "ts-expect-error") {
33
+ await runCmd(await getCmdInjectTsExpectError(), []);
34
+ }
31
35
  }
32
36
  });
@@ -0,0 +1,43 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import { defineArgs, defineCommand } from "@reliverse/rempts";
3
+ import { useTsExpectError } from "./impl.js";
4
+ export default defineCommand({
5
+ meta: {
6
+ name: "expect",
7
+ version: "1.0.0",
8
+ description: "Inject `@ts-expect-error` above lines where TS errors occur"
9
+ },
10
+ args: defineArgs({
11
+ dev: {
12
+ type: "boolean",
13
+ description: "Run the CLI in dev mode"
14
+ },
15
+ files: {
16
+ type: "positional",
17
+ description: `'auto' or path(s) to line references file(s)`,
18
+ default: "auto"
19
+ },
20
+ comment: {
21
+ type: "string",
22
+ description: "Override the comment line to insert. Default is `// @ts-expect-error TODO: fix ts`"
23
+ },
24
+ tscPaths: {
25
+ type: "string",
26
+ description: "Optional: specify path(s) to restrict TSC processing (only effective when using 'auto')"
27
+ }
28
+ }),
29
+ async run({ args }) {
30
+ if (args.dev) {
31
+ relinka("verbose", "Using dev mode");
32
+ }
33
+ let pathsTsc = args.tscPaths;
34
+ if (pathsTsc === void 0 && args.files === "auto") {
35
+ pathsTsc = "./tsconfig.json";
36
+ }
37
+ await useTsExpectError({
38
+ files: [args.files],
39
+ comment: args.comment,
40
+ tscPaths: [pathsTsc]
41
+ });
42
+ }
43
+ });
@@ -0,0 +1,162 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import { execa } from "execa";
3
+ import fs from "fs-extra";
4
+ import path from "pathe";
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, "utf-8");
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(
104
+ "log",
105
+ `Injecting into ${absPath} at lines: ${lineNums.join(", ")}`
106
+ );
107
+ try {
108
+ const original = await fs.readFile(absPath, "utf-8");
109
+ const splitted = original.split(/\r?\n/);
110
+ for (const ln of lineNums) {
111
+ if (ln <= splitted.length) {
112
+ splitted.splice(ln - 1, 0, commentText);
113
+ } else {
114
+ relinka("warn", `Line ${ln} exceeds file length for ${absPath}`);
115
+ }
116
+ }
117
+ const newContent = splitted.join("\n");
118
+ await fs.writeFile(absPath, newContent, "utf-8");
119
+ } catch (error) {
120
+ relinka("error", `Failed editing ${filePath}: ${error}`);
121
+ }
122
+ }
123
+ }
124
+ export async function useTsExpectError(args) {
125
+ const finalComment = args.comment ?? "// @ts-expect-error TODO: fix ts";
126
+ const tscCommand = "tsc --project ./tsconfig.json --noEmit";
127
+ const lines = [];
128
+ const usedAuto = args.files.some((item) => item.toLowerCase() === "auto");
129
+ if (usedAuto) {
130
+ relinka("log", "Running TSC to discover error lines...");
131
+ try {
132
+ const discovered = await runTscAndParseErrors(tscCommand, args.tscPaths);
133
+ if (args.tscPaths?.length) {
134
+ const filtered = discovered.filter(
135
+ (rec) => args.tscPaths ? isWithin(rec.filePath, args.tscPaths) : true
136
+ );
137
+ lines.push(...filtered);
138
+ } else {
139
+ lines.push(...discovered);
140
+ }
141
+ } catch (error) {
142
+ relinka("error", `Failed running tsc: ${error}`);
143
+ process.exit(1);
144
+ }
145
+ }
146
+ for (const item of args.files) {
147
+ if (item.toLowerCase() === "auto") continue;
148
+ try {
149
+ const recs = await parseLinesFile(item);
150
+ lines.push(...recs);
151
+ } catch (error) {
152
+ relinka("error", `Failed reading lines file ${item}: ${error}`);
153
+ }
154
+ }
155
+ if (lines.length === 0) {
156
+ relinka("error", "No references found. Nothing to do.");
157
+ relinka("error", "Lines: ", JSON.stringify(lines));
158
+ process.exit(1);
159
+ }
160
+ await injectCommentIntoFiles(lines, finalComment);
161
+ relinka("success", "All lines processed successfully.");
162
+ }
@@ -1,5 +1,36 @@
1
- export { FILE_TYPES } from "./impl/const.js";
2
- export { gitignoreTemplate } from "./impl/templates/t-gitignore.js";
3
- export { licenseTemplate } from "./impl/templates/t-license.js";
4
- export { readmeTemplate } from "./impl/templates/t-readme.js";
5
- export { escapeMarkdownCodeBlocks } from "./impl/utils.js";
1
+ import { relinka } from "@reliverse/relinka";
2
+ import { defineCommand, runCmd, selectPrompt } from "@reliverse/rempts";
3
+ import { getCmdRelifsoInit } from "../cmds.js";
4
+ export default defineCommand({
5
+ meta: {
6
+ name: "cli",
7
+ description: "Runs the Relifso helper interactive menu (displays list of available commands)"
8
+ },
9
+ args: {
10
+ dev: {
11
+ type: "boolean",
12
+ description: "Runs the CLI in dev mode"
13
+ },
14
+ cwd: {
15
+ type: "string",
16
+ description: "The working directory to run the CLI in",
17
+ required: false
18
+ }
19
+ },
20
+ run: async ({ args }) => {
21
+ const isDev = args.dev;
22
+ relinka("verbose", `Running in ${isDev ? "dev" : "prod"} mode`);
23
+ const cmd = await selectPrompt({
24
+ title: "Select a command",
25
+ options: [
26
+ {
27
+ value: "init",
28
+ label: "Initialize files"
29
+ }
30
+ ]
31
+ });
32
+ if (cmd === "init") {
33
+ await runCmd(await getCmdRelifsoInit(), []);
34
+ }
35
+ }
36
+ });
@@ -1,121 +1,93 @@
1
- import { relinka } from "@reliverse/relinka";
2
- import {
3
- defineCommand,
4
- errorHandler,
5
- multiselectPrompt,
6
- runMain,
7
- selectPrompt,
8
- } from "@reliverse/rempts";
9
-
10
- import type {
11
- FileType,
12
- InitFileRequest,
13
- } from "./libs/reinit/reint-impl/types.js";
14
-
15
- import { FILE_TYPES } from "./libs/reinit/reint-impl/const.js";
16
- import { initFile, initFiles } from "./libs/reinit/reint-impl/mod.js";
17
-
18
- const main = defineCommand({
19
- meta: {
20
- name: "reinit",
21
- version: "1.0.0",
22
- description: "@reliverse/reinit-cli",
23
- },
24
- args: {
25
- dev: {
26
- type: "boolean",
27
- description: "Runs the CLI in dev mode",
28
- },
29
- fileType: {
30
- type: "string",
31
- description: "File type to initialize (e.g. 'md:README')",
32
- required: false,
33
- },
34
- destDir: {
35
- type: "string",
36
- description: "Destination directory",
37
- default: ".",
38
- required: false,
39
- },
40
- multiple: {
41
- type: "boolean",
42
- description: "Whether to select multiple file types from the library",
43
- required: false,
44
- default: false,
45
- },
46
- parallel: {
47
- type: "boolean",
48
- description: "Run tasks in parallel",
49
- required: false,
50
- default: false,
51
- },
52
- concurrency: {
53
- type: "string",
54
- description: "Concurrency limit if parallel is true",
55
- required: false,
56
- default: "4",
57
- },
58
- },
59
- async run({ args }) {
60
- const { fileType, destDir, multiple, parallel, concurrency } = args;
61
- const concurrencyNum = Number(concurrency);
62
-
63
- // throw error if fileType doesn't include FILE_TYPES.type
64
- if (fileType && !FILE_TYPES.find((ft) => ft.type === fileType)) {
65
- throw new Error(`Invalid file type: ${fileType}`);
66
- }
67
-
68
- const effectiveFileType: FileType = fileType as FileType;
69
-
70
- if (multiple) {
71
- // Let the user choose multiple file types from a prompt
72
- const possibleTypes = FILE_TYPES.map((ft) => ft.type);
73
- const chosen = await multiselectPrompt({
74
- title: "Select file types to initialize",
75
- options: possibleTypes.map((pt) => ({ label: pt, value: pt })),
76
- });
77
-
78
- if (chosen.length === 0) {
79
- relinka("log", "No file types selected. Exiting...");
80
- return;
81
- }
82
-
83
- // Construct an array of requests
84
- const requests: InitFileRequest[] = chosen.map((ct) => ({
85
- fileType: ct,
86
- destDir,
87
- }));
88
-
89
- const results = await initFiles(requests, {
90
- parallel,
91
- concurrency: concurrencyNum,
92
- });
93
- relinka("verbose", `Multiple files result: ${JSON.stringify(results)}`);
94
- } else {
95
- // Single file approach
96
- let finalFileType = effectiveFileType;
97
- if (!finalFileType) {
98
- // If user didn't specify, prompt for a single file type
99
- const possibleTypes = FILE_TYPES.map((ft) => ft.type);
100
- const picked = await selectPrompt({
101
- title: "Pick a file type to initialize",
102
- options: possibleTypes.map((pt) => ({ label: pt, value: pt })),
103
- });
104
- finalFileType = picked;
105
- }
106
-
107
- const result = await initFile({
108
- fileType: finalFileType,
109
- destDir,
110
- });
111
- relinka("verbose", `Single file result: ${JSON.stringify(result)}`);
112
- }
113
- },
114
- });
115
-
116
- await runMain(main).catch((error: unknown) => {
117
- errorHandler(
118
- error instanceof Error ? error : new Error(String(error)),
119
- "An unhandled error occurred, please report it at https://github.com/reliverse/reinit",
120
- );
121
- });
1
+ import { relinka } from "@reliverse/relinka";
2
+ import {
3
+ defineCommand,
4
+ multiselectPrompt,
5
+ selectPrompt
6
+ } from "@reliverse/rempts";
7
+ import { FILE_TYPES } from "./impl/const.js";
8
+ import { initFile, initFiles } from "./impl/mod.js";
9
+ export default defineCommand({
10
+ meta: {
11
+ name: "relifso",
12
+ version: "1.0.0",
13
+ description: "relifso helper utils"
14
+ },
15
+ args: {
16
+ dev: {
17
+ type: "boolean",
18
+ description: "Runs the CLI in dev mode"
19
+ },
20
+ fileType: {
21
+ type: "string",
22
+ description: "File type to initialize (e.g. 'md:README')",
23
+ required: false
24
+ },
25
+ destDir: {
26
+ type: "string",
27
+ description: "Destination directory",
28
+ default: ".",
29
+ required: false
30
+ },
31
+ multiple: {
32
+ type: "boolean",
33
+ description: "Whether to select multiple file types from the library",
34
+ required: false,
35
+ default: false
36
+ },
37
+ parallel: {
38
+ type: "boolean",
39
+ description: "Run tasks in parallel",
40
+ required: false,
41
+ default: false
42
+ },
43
+ concurrency: {
44
+ type: "string",
45
+ description: "Concurrency limit if parallel is true",
46
+ required: false,
47
+ default: "4"
48
+ }
49
+ },
50
+ async run({ args }) {
51
+ const { fileType, destDir, multiple, parallel, concurrency } = args;
52
+ const concurrencyNum = Number(concurrency);
53
+ if (fileType && !FILE_TYPES.find((ft) => ft.type === fileType)) {
54
+ throw new Error(`Invalid file type: ${fileType}`);
55
+ }
56
+ const effectiveFileType = fileType;
57
+ if (multiple) {
58
+ const possibleTypes = FILE_TYPES.map((ft) => ft.type);
59
+ const chosen = await multiselectPrompt({
60
+ title: "Select file types to initialize",
61
+ options: possibleTypes.map((pt) => ({ label: pt, value: pt }))
62
+ });
63
+ if (chosen.length === 0) {
64
+ relinka("log", "No file types selected. Exiting...");
65
+ return;
66
+ }
67
+ const requests = chosen.map((ct) => ({
68
+ fileType: ct,
69
+ destDir
70
+ }));
71
+ const results = await initFiles(requests, {
72
+ parallel,
73
+ concurrency: concurrencyNum
74
+ });
75
+ relinka("verbose", `Multiple files result: ${JSON.stringify(results)}`);
76
+ } else {
77
+ let finalFileType = effectiveFileType;
78
+ if (!finalFileType) {
79
+ const possibleTypes = FILE_TYPES.map((ft) => ft.type);
80
+ const picked = await selectPrompt({
81
+ title: "Pick a file type to initialize",
82
+ options: possibleTypes.map((pt) => ({ label: pt, value: pt }))
83
+ });
84
+ finalFileType = picked;
85
+ }
86
+ const result = await initFile({
87
+ fileType: finalFileType,
88
+ destDir
89
+ });
90
+ relinka("verbose", `Single file result: ${JSON.stringify(result)}`);
91
+ }
92
+ }
93
+ });