@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
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# dler (prev. relidler) • reliverse bundler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> @reliverse/dler (`/ˈdiː.lər/`, dealer) is a flexible, unified, and fully automated bundler for typescript and javascript projects, as well as an npm and jsr publishing tool. dler is not only a bundler, it also tries to serve as the most powerful codemod toolkit for js/ts.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[sponsor](https://github.com/sponsors/blefnk) — [discord](https://discord.gg/pb8ukbwpsj) — [repo](https://github.com/reliverse/dler) — [npm](https://npmjs.com/@reliverse/dler) — [docs](https://docs.reliverse.org/reliverse/dler)
|
|
6
6
|
|
|
7
7
|
## features
|
|
8
8
|
|
|
9
|
-
- 😘 replacement for `unbuild`
|
|
9
|
+
- 😘 replacement for `unjs/unbuild`
|
|
10
10
|
- ⚡ `dler` works via cli and sdk
|
|
11
11
|
- 📦 automated npm/jsr publishing
|
|
12
12
|
- ✅ ensures reliable js/ts builds
|
|
@@ -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`**:
|
|
@@ -122,77 +114,41 @@ bun dev # bun src/mod.ts --dev
|
|
|
122
114
|
dler [build|pub] # if installed globally
|
|
123
115
|
```
|
|
124
116
|
|
|
125
|
-
absolutely! here’s your improved section, now listing all available spell types:
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
117
|
## 🔌 plugins
|
|
130
118
|
|
|
131
|
-
dler ships with a flexible plugin system and **
|
|
119
|
+
dler ships with a flexible plugin system and **15 built-in plugins** (from [@reliverse/addons](https://reliverse.org/addons)).
|
|
132
120
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
**available spell types:**
|
|
121
|
+
feel free to create your own plugins. plugins can be implemented as built-in directly in `src/app/plugin-name/impl/*` and then imported from `src/app/plugin-name/cmd.ts`; or implemented in your own library and then imported from `src/app/plugin-name/cmd.ts`.
|
|
136
122
|
|
|
137
|
-
|
|
138
|
-
- `rename-file` — renames the current file
|
|
139
|
-
- `remove-comment` — removes a specific comment from code
|
|
140
|
-
- `remove-line` — removes a specific line from code
|
|
141
|
-
- `remove-file` — deletes the current file
|
|
142
|
-
- `transform-content` — applies a transformation to the file content
|
|
143
|
-
- `copy-file` — copies the current file to a new location
|
|
144
|
-
- `move-file` — moves the current file to a new location
|
|
145
|
-
- `insert-at` — inserts content at a specific position in the file
|
|
123
|
+
### 1. `agg`
|
|
146
124
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
params are optional and comma-separated.
|
|
150
|
-
|
|
151
|
-
currently, only the first param is supported:
|
|
152
|
-
|
|
153
|
-
- `hooked` (boolean, default: `false`)
|
|
154
|
-
- `false`: dler handles the spell automatically at postbuild
|
|
155
|
-
- `true`: disables default behavior, so you can trigger the spell yourself (e.g. from your own cli function)
|
|
156
|
-
|
|
157
|
-
more params coming soon...
|
|
158
|
-
|
|
159
|
-
**usage examples:**
|
|
160
|
-
|
|
161
|
-
- `export * from "../../types.js"; // <dler-replace-line-{hooked=false}>` — injects file contents at this line
|
|
162
|
-
- `// @ts-expect-error <dler-remove-comment-{hooked=false}>` — removes just this comment
|
|
163
|
-
- `// <dler-remove-line-{hooked=false}>` — removes this line
|
|
164
|
-
- `// <dler-remove-file-{hooked=false}>` — deletes this file
|
|
165
|
-
- `// <dler-rename-file-"tsconfig.json"-{hooked=false}>` — renames this file (runs at postbuild because `hooked=false`)
|
|
125
|
+
generates aggregator file with content like `import { getsomething } from "./utils.js"`.
|
|
166
126
|
|
|
167
|
-
|
|
127
|
+
```bash
|
|
128
|
+
dler agg ...
|
|
129
|
+
```
|
|
168
130
|
|
|
169
|
-
|
|
131
|
+
### 2. `auth`
|
|
170
132
|
|
|
171
|
-
|
|
133
|
+
best friend of auth+db libs like [better-auth](https://better-auth.com) and [drizzle-orm](https://orm.drizzle.team).
|
|
172
134
|
|
|
173
|
-
|
|
135
|
+
```bash
|
|
136
|
+
dler auth better-auth generate
|
|
137
|
+
```
|
|
174
138
|
|
|
175
|
-
|
|
176
|
-
- `dler spell --trigger all`
|
|
177
|
-
- `dler spell`
|
|
139
|
+
### 3. `build`
|
|
178
140
|
|
|
179
|
-
|
|
141
|
+
since dler is fully modular, build command is separated for its own build-in plugin as well.
|
|
180
142
|
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
// await dler.spell({}) // means all spells and all files
|
|
184
|
-
// spell: ["all"] // means all spells
|
|
185
|
-
// spell: [] // means all spells
|
|
186
|
-
// files: [] // means all files
|
|
143
|
+
```bash
|
|
144
|
+
dler build ...
|
|
187
145
|
```
|
|
188
146
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
here’s an extended and improved section for your readme, keeping your lowercase style and adding clarity, options, and a bit more detail:
|
|
147
|
+
### 4. `conv`
|
|
192
148
|
|
|
193
|
-
|
|
149
|
+
not yet documented.
|
|
194
150
|
|
|
195
|
-
###
|
|
151
|
+
### 5. `deps`
|
|
196
152
|
|
|
197
153
|
finds missing dependencies in your project by scanning your code for imports and comparing them to your `package.json`.
|
|
198
154
|
|
|
@@ -239,7 +195,11 @@ dler deps --all --directory ./src --include-builtins
|
|
|
239
195
|
missing dependencies are shown only once, even if used in multiple files.
|
|
240
196
|
deep imports like `dep/some/file` or `@org/dep/some/thing` are always resolved to their root package.
|
|
241
197
|
|
|
242
|
-
###
|
|
198
|
+
### 6. `inject`
|
|
199
|
+
|
|
200
|
+
not yet documented.
|
|
201
|
+
|
|
202
|
+
### 7. `libs`
|
|
243
203
|
|
|
244
204
|
builds and publishes specific subdirectories of your main project as standalone packages.
|
|
245
205
|
|
|
@@ -275,9 +235,106 @@ libslist: {
|
|
|
275
235
|
|
|
276
236
|
- more magic commands coming soon...
|
|
277
237
|
|
|
278
|
-
|
|
238
|
+
### 8. `merge`
|
|
239
|
+
|
|
240
|
+
not yet documented.
|
|
241
|
+
|
|
242
|
+
### 9. `mono`
|
|
243
|
+
|
|
244
|
+
not yet documented.
|
|
245
|
+
|
|
246
|
+
### 10. `pub`
|
|
247
|
+
|
|
248
|
+
pub command is separated for its own build-in plugin as well.
|
|
249
|
+
|
|
250
|
+
it already calls build command by itself, so you don't need to run `dler build` separately.
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
dler pub ...
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### 11. `relifso`
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
dler relifso init ...
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### 12. `relinka`
|
|
263
|
+
|
|
264
|
+
@reliverse/relinka's best friend. learn more in its [docs](https://github.com/reliverse/relinka).
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
dler relinka --console-to-relinka
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### 13. `rempts`
|
|
271
|
+
|
|
272
|
+
@reliverse/rempts's best friend. learn more in its [docs](https://github.com/reliverse/rempts).
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
dler rempts init --cmd my-cmd-1
|
|
276
|
+
dler rempts init --cmds
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### 14. `spell`
|
|
280
|
+
|
|
281
|
+
**available spell types:**
|
|
282
|
+
|
|
283
|
+
- `replace-line` — injects contents from one file into another
|
|
284
|
+
- `rename-file` — renames the current file
|
|
285
|
+
- `remove-comment` — removes a specific comment from code
|
|
286
|
+
- `remove-line` — removes a specific line from code
|
|
287
|
+
- `remove-file` — deletes the current file
|
|
288
|
+
- `transform-content` — applies a transformation to the file content
|
|
289
|
+
- `copy-file` — copies the current file to a new location
|
|
290
|
+
- `move-file` — moves the current file to a new location
|
|
291
|
+
- `insert-at` — inserts content at a specific position in the file
|
|
292
|
+
|
|
293
|
+
**params:**
|
|
294
|
+
|
|
295
|
+
params are optional and comma-separated.
|
|
296
|
+
|
|
297
|
+
currently, only the first param is supported:
|
|
298
|
+
|
|
299
|
+
- `hooked` (boolean, default: `false`)
|
|
300
|
+
- `false`: dler handles the spell automatically at postbuild
|
|
301
|
+
- `true`: disables default behavior, so you can trigger the spell yourself (e.g. from your own cli function)
|
|
302
|
+
|
|
303
|
+
more params coming soon...
|
|
304
|
+
|
|
305
|
+
**usage examples:**
|
|
306
|
+
|
|
307
|
+
- `export * from "../../types.js"; // <dler-replace-line-{hooked=false}>` — injects file contents at this line
|
|
308
|
+
- `// @ts-expect-error <dler-remove-comment-{hooked=false}>` — removes just this comment
|
|
309
|
+
- `// <dler-remove-line-{hooked=false}>` — removes this line
|
|
310
|
+
- `// <dler-remove-file-{hooked=false}>` — deletes this file
|
|
311
|
+
- `// <dler-rename-file-"tsconfig.json"-{hooked=false}>` — renames this file (runs at postbuild because `hooked=false`)
|
|
312
|
+
|
|
313
|
+
**using `hooked=true`:**
|
|
314
|
+
|
|
315
|
+
- `// <dler-rename-file-"tsconfig.json"-{hooked=true}>` — renames the file, but only when you trigger it yourself (hooked from your side)
|
|
316
|
+
|
|
317
|
+
**triggering spells:**
|
|
318
|
+
|
|
319
|
+
from dler’s cli:
|
|
320
|
+
|
|
321
|
+
- `dler spell --trigger rename-file,... --files tsconfig.json,...`
|
|
322
|
+
- `dler spell --trigger all`
|
|
323
|
+
- `dler spell`
|
|
324
|
+
|
|
325
|
+
from your own code:
|
|
326
|
+
|
|
327
|
+
```ts
|
|
328
|
+
await dler.spell({ spells: ["rename-file"], files: [] });
|
|
329
|
+
// await dler.spell({}) // means all spells and all files
|
|
330
|
+
// spell: ["all"] // means all spells
|
|
331
|
+
// spell: [] // means all spells
|
|
332
|
+
// files: [] // means all files
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
p.s. [see how rse cli uses hooked=true](https://github.com/reliverse/rse/blob/main/src/postbuild.ts)
|
|
279
336
|
|
|
280
|
-
###
|
|
337
|
+
### 15. `tools`
|
|
281
338
|
|
|
282
339
|
lets you run standalone dler features directly from the cli:
|
|
283
340
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
2
|
+
import { dlerBuild } from "../../cli.js";
|
|
3
|
+
export default defineCommand({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "build",
|
|
6
|
+
description: "Build the project"
|
|
7
|
+
},
|
|
8
|
+
args: defineArgs({
|
|
9
|
+
dev: {
|
|
10
|
+
type: "boolean",
|
|
11
|
+
description: "Runs the CLI in dev mode"
|
|
12
|
+
}
|
|
13
|
+
}),
|
|
14
|
+
async run({ args }) {
|
|
15
|
+
await dlerBuild(args.dev);
|
|
16
|
+
}
|
|
17
|
+
});
|
package/bin/app/cmds.js
ADDED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dler inject
|
|
2
2
|
|
|
3
|
-
[💖 GitHub Sponsors](https://github.com/sponsors/blefnk) • [💬 Discord](https://discord.gg/Pb8uKbwpsJ) • [📦 NPM](https://npmjs.com/@reliverse/
|
|
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/
|
|
5
|
+
**@reliverse/inject** handles the boring parts for you. For example:
|
|
6
6
|
|
|
7
|
-
- ✅ Need to insert `// @ts-expect-error` above a TypeScript error?
|
|
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/
|
|
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/
|
|
32
|
+
bun x @reliverse/inject
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
### Basic Usage
|
|
36
36
|
|
|
37
|
-
**User config** in `
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 |
|
|
86
|
+
tsc --noEmit | inject
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Or use with other tools:
|
|
90
90
|
|
|
91
91
|
```bash
|
|
92
|
-
eslint . |
|
|
93
|
-
biome check . |
|
|
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
|
-
|
|
100
|
-
|
|
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/
|
|
140
|
+
If `@reliverse/inject` saved you time or sanity:
|
|
141
141
|
|
|
142
|
-
- ⭐ [Star the repo](https://github.com/reliverse/
|
|
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
|
|
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
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
2
|
+
import { dlerPub } from "../../cli.js";
|
|
3
|
+
export default defineCommand({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "build",
|
|
6
|
+
description: "Build the project"
|
|
7
|
+
},
|
|
8
|
+
args: defineArgs({
|
|
9
|
+
dev: {
|
|
10
|
+
type: "boolean",
|
|
11
|
+
description: "Runs the CLI in dev mode"
|
|
12
|
+
}
|
|
13
|
+
}),
|
|
14
|
+
async run({ args }) {
|
|
15
|
+
await dlerPub(args.dev);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
});
|