@reliverse/dler 1.2.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 +21 -0
- package/README.md +312 -0
- package/bin/cli/args/agg/main.js +0 -0
- package/bin/cli/args/conv/README.md +3 -0
- package/bin/cli/args/conv/main.js +0 -0
- package/bin/cli/args/deps/analyzer.js +42 -0
- package/bin/cli/args/deps/filesystem.js +42 -0
- package/bin/cli/args/deps/formatter.js +65 -0
- package/bin/cli/args/deps/mod.js +48 -0
- package/bin/cli/args/deps/parser.js +59 -0
- package/bin/cli/args/deps/types.js +0 -0
- package/bin/cli/args/init/README.md +121 -0
- package/bin/cli/args/init/libs/reinit/reinit-main.js +5 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/const.js +26 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/mod.txt +395 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-gitignore.js +9 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-license.js +22 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-readme.js +59 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/types.js +0 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/utils.js +3 -0
- package/bin/cli/args/init/main.txt +121 -0
- package/bin/cli/args/init/types.js +1 -0
- package/bin/cli/args/inject/README.md +148 -0
- package/bin/cli/args/inject/arg-ts-expect-error.txt +49 -0
- package/bin/cli/args/inject/cli-mod.js +32 -0
- package/bin/cli/args/inject/main.txt +28 -0
- package/bin/cli/args/inject/reinject.config.js +4 -0
- package/bin/cli/args/inject/ts-expect-error.txt +277 -0
- package/bin/cli/args/merger/README.md +125 -0
- package/bin/cli/args/merger/main.txt +306 -0
- package/bin/cli/args/mono/main.js +0 -0
- package/bin/cli/args/spells/mod.js +44 -0
- package/bin/cli/args/split/README.md +13 -0
- package/bin/cli/args/split/split-main.js +26 -0
- package/bin/cli/args/split/split-mod.js +117 -0
- package/bin/cli/args/tools/index.js +81 -0
- package/bin/cli/args/tools/tools-impl.js +296 -0
- package/bin/cli.js +111 -0
- package/bin/init.js +157 -0
- package/bin/libs/cfg/cfg-default.js +50 -0
- package/bin/libs/cfg/cfg-main.js +1 -0
- package/bin/libs/cfg/cfg-mod.js +4 -0
- package/bin/libs/cfg/cfg-types.js +1 -0
- package/bin/libs/sdk/sdk-impl/build/build-library.js +865 -0
- package/bin/libs/sdk/sdk-impl/build/build-regular.js +373 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/auto.js +110 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/build.js +322 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/copy.js +62 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist.js +57 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/build.js +104 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/config.js +124 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/cjs.js +48 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/esbuild.js +91 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/json.js +17 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/raw.js +20 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/shebang.js +42 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/stub.js +137 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/utils.js +41 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/watch.js +33 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/types.js +6 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/index.js +125 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/utils.js +158 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/validate.js +68 -0
- package/bin/libs/sdk/sdk-impl/library-flow.js +169 -0
- package/bin/libs/sdk/sdk-impl/pub/pub-library.js +132 -0
- package/bin/libs/sdk/sdk-impl/pub/pub-regular.js +69 -0
- package/bin/libs/sdk/sdk-impl/regular-flow.js +219 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-executors.js +307 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-filesystem.js +72 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-main.js +87 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-parser.js +60 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-types.js +0 -0
- package/bin/libs/sdk/sdk-impl/utils/tools/tools-agg.js +149 -0
- package/bin/libs/sdk/sdk-impl/utils/tools/tools-impl.js +21 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-build.js +102 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-bump.js +238 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-clean.js +35 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-consts.js +17 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-cwd.js +36 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-deps.js +73 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-determine.js +25 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-error.js +17 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-fs.js +202 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-info.js +42 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.js +51 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-paths.js +658 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-perf.js +22 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-libs.js +259 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-reg.js +207 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-tsconfig.js +44 -0
- package/bin/libs/sdk/sdk-main.js +114 -0
- package/bin/libs/sdk/sdk-types.js +1 -0
- package/bin/load.js +27 -0
- package/bin/main.js +46 -0
- package/bin/tools.txt +92 -0
- package/bin/types.js +0 -0
- package/package.json +93 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Nazar Kornienko (blefnk), Reliverse
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
# dler (prev. relidler) • reliverse bundler
|
|
2
|
+
|
|
3
|
+
[💖 github sponsors](https://github.com/sponsors/blefnk) — [💬 discord](https://discord.gg/pb8ukbwpsj) — [✨ repo](https://github.com/reliverse/dler-js-bundler) — [📦 npm](https://npmjs.com/@reliverse/dler) — [📚 docs](https://docs.reliverse.org)
|
|
4
|
+
|
|
5
|
+
> @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.
|
|
6
|
+
|
|
7
|
+
## features
|
|
8
|
+
|
|
9
|
+
- 😘 replacement for `unbuild`
|
|
10
|
+
- ⚡ `dler` works via cli and sdk
|
|
11
|
+
- 📦 automated npm/jsr publishing
|
|
12
|
+
- ✅ ensures reliable js/ts builds
|
|
13
|
+
- 🔄 handles automatic version bumps
|
|
14
|
+
- 🔧 eliminates `package.json` headaches
|
|
15
|
+
- 🎯 optimized for speed and modern workflows
|
|
16
|
+
- ✨ packed with powerful features under the hood
|
|
17
|
+
- 🛠️ converts typescript aliases to relative paths
|
|
18
|
+
- 🔌 plugin system with two built-in plugins included
|
|
19
|
+
- 📝 highly configurable flow via a configuration file
|
|
20
|
+
- 🔜 `libraries` plugin —> dler monorepo implementation
|
|
21
|
+
- 🪄 magic spells (built-in plugin)
|
|
22
|
+
|
|
23
|
+
### supported bundlers
|
|
24
|
+
|
|
25
|
+
- ✅ [mkdist](https://github.com/unjs/mkdist#readme)
|
|
26
|
+
- ✅ jsr
|
|
27
|
+
- 🏗️ copy
|
|
28
|
+
- 🏗️ [bun](https://bun.sh/docs/bundler)
|
|
29
|
+
- 🏗️ [rollup](https://rollupjs.org)
|
|
30
|
+
- 🏗️ [untyped](https://untyped.unjs.io)
|
|
31
|
+
- 🔜 [tsdown](https://rolldown.rs)
|
|
32
|
+
- 🔜 copy (prev. jsr)
|
|
33
|
+
|
|
34
|
+
**legend**:
|
|
35
|
+
|
|
36
|
+
- ✅ well tested with big projects
|
|
37
|
+
- 🏗️ not well tested yet
|
|
38
|
+
- 🔜 coming soon
|
|
39
|
+
|
|
40
|
+
## getting started
|
|
41
|
+
|
|
42
|
+
ensure git, node.js, and bun/pnpm/yarn/npm are installed. then:
|
|
43
|
+
|
|
44
|
+
### playground
|
|
45
|
+
|
|
46
|
+
> **💡 tip**:
|
|
47
|
+
> want to test dler before integrating it into your project?
|
|
48
|
+
> clone the repo and build it using dler itself!
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
git clone https://github.com/reliverse/dler.git
|
|
52
|
+
cd dler
|
|
53
|
+
bun i
|
|
54
|
+
bun dev # bun src/main.ts --dev
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### installation
|
|
58
|
+
|
|
59
|
+
1. **install globally**:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
bun i -g @reliverse/dler
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**or update as needed**:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
bun -g update --latest
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
2. **prepare your project**:
|
|
72
|
+
|
|
73
|
+
a. **configure `.gitignore`**:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
echo "dist*" >> .gitignore
|
|
77
|
+
echo "logs" >> .gitignore
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
b. **install config intellisense**:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
bun add -d @reliverse/dler-cfg
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
c. **initialize config**:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
dler cli
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- the `.config/dler.ts` file is automatically created on first run.
|
|
93
|
+
- **it's recommended to customize this file according to your needs.**
|
|
94
|
+
- you can check an example config here: [.config/dler.ts](https://github.com/reliverse/dler-js-bundler/blob/main/.config/dler.ts)
|
|
95
|
+
|
|
96
|
+
3. **run and enjoy**:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
dler cli
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
absolutely! here’s your improved section, now listing all available spell types:
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## 🔌 plugins
|
|
107
|
+
|
|
108
|
+
dler ships with a flexible plugin system and **10 built-in plugins** (from [@reliverse/addons](https://reliverse.org/addons)).
|
|
109
|
+
|
|
110
|
+
### 1. `magic-spells-dler-plugin`
|
|
111
|
+
|
|
112
|
+
**available spell types:**
|
|
113
|
+
|
|
114
|
+
- `replace-line` — injects contents from one file into another
|
|
115
|
+
- `rename-file` — renames the current file
|
|
116
|
+
- `remove-comment` — removes a specific comment from code
|
|
117
|
+
- `remove-line` — removes a specific line from code
|
|
118
|
+
- `remove-file` — deletes the current file
|
|
119
|
+
- `transform-content` — applies a transformation to the file content
|
|
120
|
+
- `copy-file` — copies the current file to a new location
|
|
121
|
+
- `move-file` — moves the current file to a new location
|
|
122
|
+
- `insert-at` — inserts content at a specific position in the file
|
|
123
|
+
|
|
124
|
+
**params:**
|
|
125
|
+
|
|
126
|
+
params are optional and comma-separated.
|
|
127
|
+
|
|
128
|
+
currently, only the first param is supported:
|
|
129
|
+
|
|
130
|
+
- `hooked` (boolean, default: `false`)
|
|
131
|
+
- `false`: dler handles the spell automatically at postbuild
|
|
132
|
+
- `true`: disables default behavior, so you can trigger the spell yourself (e.g. from your own cli function)
|
|
133
|
+
|
|
134
|
+
more params coming soon...
|
|
135
|
+
|
|
136
|
+
**usage examples:**
|
|
137
|
+
|
|
138
|
+
- `export * from "../../types.js"; // <dler-replace-line-{hooked=false}>` — injects file contents at this line
|
|
139
|
+
- `// @ts-expect-error <dler-remove-comment-{hooked=false}>` — removes just this comment
|
|
140
|
+
- `// <dler-remove-line-{hooked=false}>` — removes this line
|
|
141
|
+
- `// <dler-remove-file-{hooked=false}>` — deletes this file
|
|
142
|
+
- `// <dler-rename-file-"tsconfig.json"-{hooked=false}>` — renames this file (runs at postbuild because `hooked=false`)
|
|
143
|
+
|
|
144
|
+
**using `hooked=true`:**
|
|
145
|
+
|
|
146
|
+
- `// <dler-rename-file-"tsconfig.json"-{hooked=true}>` — renames the file, but only when you trigger it yourself (hooked from your side)
|
|
147
|
+
|
|
148
|
+
**triggering spells:**
|
|
149
|
+
|
|
150
|
+
from dler’s cli:
|
|
151
|
+
|
|
152
|
+
- `dler spells --trigger rename-file,... --files tsconfig.json,...`
|
|
153
|
+
- `dler spells --trigger all`
|
|
154
|
+
- `dler spells`
|
|
155
|
+
|
|
156
|
+
from your own code:
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
await dler.spells({ spells: ["rename-file"], files: [] });
|
|
160
|
+
// await dler.spells({}) // all spells, all files
|
|
161
|
+
// spells: ["all"] // means all spells
|
|
162
|
+
// spells: [] // also means all spells
|
|
163
|
+
// files: [] // means all files
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
p.s. [see how rse cli uses hooked=true](https://github.com/reliverse/rse/blob/main/src/postbuild.ts)
|
|
167
|
+
|
|
168
|
+
here’s an extended and improved section for your readme, keeping your lowercase style and adding clarity, options, and a bit more detail:
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
### 2. `deps-dler-plugin`
|
|
173
|
+
|
|
174
|
+
finds missing dependencies in your project by scanning your code for imports and comparing them to your `package.json`.
|
|
175
|
+
|
|
176
|
+
**what it does:**
|
|
177
|
+
|
|
178
|
+
- traverses all `.js`, `.jsx`, `.ts`, and `.tsx` files in your project (by default, in the current directory)
|
|
179
|
+
- detects all used packages, including scoped ones (`@org/dep-name`)
|
|
180
|
+
- supports both es modules (`import ... from "dep"`) and commonjs (`require("dep")`)
|
|
181
|
+
- normalizes deep imports like `dep/some/file` to just `dep`
|
|
182
|
+
- ignores local/relative imports (`./foo`, `../bar`)
|
|
183
|
+
- skips `node_modules`, `.git`, and common build folders
|
|
184
|
+
- compares all used packages to those listed in your `package.json`
|
|
185
|
+
- shows you which dependencies are missing (not listed)
|
|
186
|
+
- can also show all used dependencies (listed and missing)
|
|
187
|
+
- optionally includes node.js built-in modules in the report
|
|
188
|
+
- outputs results in a readable format or as json
|
|
189
|
+
|
|
190
|
+
**usage examples:**
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# basic usage - scan current directory
|
|
194
|
+
dler deps
|
|
195
|
+
|
|
196
|
+
# scan a specific directory
|
|
197
|
+
dler deps --directory ./my-project
|
|
198
|
+
|
|
199
|
+
# show all dependencies (both listed and missing)
|
|
200
|
+
dler deps --all
|
|
201
|
+
|
|
202
|
+
# ignore specific patterns
|
|
203
|
+
dler deps --ignore "test/**,example/**"
|
|
204
|
+
|
|
205
|
+
# output in json format
|
|
206
|
+
dler deps --json
|
|
207
|
+
|
|
208
|
+
# include node.js built-in modules
|
|
209
|
+
dler deps --include-builtins
|
|
210
|
+
|
|
211
|
+
# combine options
|
|
212
|
+
dler deps --all --directory ./src --include-builtins
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**pro tip:**
|
|
216
|
+
missing dependencies are shown only once, even if used in multiple files.
|
|
217
|
+
deep imports like `dep/some/file` or `@org/dep/some/thing` are always resolved to their root package.
|
|
218
|
+
|
|
219
|
+
### 3. `libraries-dler-plugin`
|
|
220
|
+
|
|
221
|
+
builds and publishes specific subdirectories of your main project as standalone packages.
|
|
222
|
+
|
|
223
|
+
**usage example**:
|
|
224
|
+
using `@reliverse/dler-cfg` to package [src/libs/cfg](https://github.com/reliverse/dler-js-bundler/tree/main/src/libs/cfg):
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
// .config/dler.ts
|
|
228
|
+
libsactmode: "main-and-libs",
|
|
229
|
+
libsdirdist: "dist-libs",
|
|
230
|
+
libsdirsrc: "src/libs",
|
|
231
|
+
libslist: {
|
|
232
|
+
"@reliverse/dler-cfg": {
|
|
233
|
+
libdeclarations: true,
|
|
234
|
+
libdescription: "@reliverse/dler defineconfig",
|
|
235
|
+
libdirname: "cfg",
|
|
236
|
+
libmainfile: "cfg/cfg-main.ts",
|
|
237
|
+
libpkgkeepdeps: false,
|
|
238
|
+
libtranspileminify: true,
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
**dler task commands**:
|
|
244
|
+
|
|
245
|
+
- `// dler-replace-line` tells dler to grab the contents of `../../types.ts` and inject them directly in place of your command definition.
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
export * from "../../types.js"; // dler-replace-line
|
|
249
|
+
// or:
|
|
250
|
+
export type { specificTypeName1, specificTypeName2 } from "../../types.js"; // dler-replace-line
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
- more magic commands coming soon...
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
### 4. `tools-dler-plugin`
|
|
258
|
+
|
|
259
|
+
lets you run standalone dler features directly from the cli:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
dler tools --tool <tool> --input <dir> --out <file> [options]
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**available tools**:
|
|
266
|
+
|
|
267
|
+
- `agg`: generates aggregator file with content like `export { getsomething } from "./utils.js"`. **note**: currently it replaces the file content, not appends.
|
|
268
|
+
|
|
269
|
+
**usage example**: if you're exploring the example [playground](#playground), you can try the following:
|
|
270
|
+
|
|
271
|
+
1. open [src/libs/sdk/sdk-main.ts](https://github.com/reliverse/dler-js-bundler/blob/main/src/libs/sdk/sdk-main.ts) in your ide.
|
|
272
|
+
2. press `ctrl+a`, then `backspace`. run the command below and watch the magic happen:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
bun tools:agg # shortcut for:
|
|
276
|
+
bun src/main.ts tools --dev --tool agg --input src/libs/sdk/sdk-impl --out src/libs/sdk/sdk-main.ts --recursive --named --strip src/libs/sdk
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## api (for advanced users)
|
|
280
|
+
|
|
281
|
+
the sdk lets you build custom dler cli plugins or even extend your own cli tools.
|
|
282
|
+
|
|
283
|
+
```sh
|
|
284
|
+
bun add @reliverse/dler-sdk
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**usage example**: [@reliverse/rse](https://github.com/reliverse/rse-website-builder) leverages this sdk to extend its functionality.
|
|
288
|
+
|
|
289
|
+
## todo
|
|
290
|
+
|
|
291
|
+
- [x] ~~implement stable `regular` build and publish~~
|
|
292
|
+
- [ ] implement stable `library` build and publish
|
|
293
|
+
- [ ] achieve full drop-in replacement for `unbuild`
|
|
294
|
+
- [ ] support auto migration from `build.config.ts`
|
|
295
|
+
- [ ] allow plugins to extend dler's `defineconfig`
|
|
296
|
+
- [ ] support configuration via `.config/rse.{ts,jsonc}`
|
|
297
|
+
- [ ] make config file optional with sensible defaults
|
|
298
|
+
|
|
299
|
+
## related
|
|
300
|
+
|
|
301
|
+
special thanks to the project that inspired `@reliverse/dler`:
|
|
302
|
+
|
|
303
|
+
- [unjs/unbuild](https://github.com/unjs/unbuild#readme)
|
|
304
|
+
|
|
305
|
+
## support
|
|
306
|
+
|
|
307
|
+
- if dler saves you time and effort, please consider supporting its development: [github sponsors](https://github.com/sponsors/blefnk);
|
|
308
|
+
- even a simple star on [github](https://github.com/reliverse/dler) shows your love. thank you!
|
|
309
|
+
|
|
310
|
+
## license
|
|
311
|
+
|
|
312
|
+
🩷 [mit](./license) © 2025 [blefnk nazar kornienko](https://github.com/blefnk)
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile, findSourceFiles, readPackageJson } from "./filesystem.js";
|
|
2
|
+
import {
|
|
3
|
+
extractPackageNames,
|
|
4
|
+
getListedDependencies,
|
|
5
|
+
getBuiltinModules
|
|
6
|
+
} from "./parser.js";
|
|
7
|
+
export const analyzeDependencies = async (options) => {
|
|
8
|
+
const packageJson = await readPackageJson(options.directory);
|
|
9
|
+
const listedDependencies = getListedDependencies(packageJson);
|
|
10
|
+
const sourceFiles = await findSourceFiles(
|
|
11
|
+
options.directory,
|
|
12
|
+
options.ignorePatterns
|
|
13
|
+
);
|
|
14
|
+
const builtinModules = getBuiltinModules();
|
|
15
|
+
const allDependencies = /* @__PURE__ */ new Set();
|
|
16
|
+
for (const filePath of sourceFiles) {
|
|
17
|
+
const fileContent = await readFile(filePath);
|
|
18
|
+
const packageNames = extractPackageNames(fileContent);
|
|
19
|
+
for (const packageName of packageNames) {
|
|
20
|
+
allDependencies.add(packageName);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const missingDependencies = /* @__PURE__ */ new Set();
|
|
24
|
+
const builtinModulesList = [];
|
|
25
|
+
for (const dependency of allDependencies) {
|
|
26
|
+
if (!listedDependencies.has(dependency)) {
|
|
27
|
+
if (builtinModules.has(dependency)) {
|
|
28
|
+
if (options.includeBuiltins) {
|
|
29
|
+
builtinModulesList.push(dependency);
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
missingDependencies.add(dependency);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
missingDependencies: Array.from(missingDependencies).sort(),
|
|
38
|
+
allDependencies: Array.from(allDependencies).sort(),
|
|
39
|
+
listedDependencies: Array.from(listedDependencies).sort(),
|
|
40
|
+
builtinModules: builtinModulesList.sort()
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { glob } from "glob";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import util from "node:util";
|
|
5
|
+
const readFileAsync = util.promisify(fs.readFile);
|
|
6
|
+
export const findSourceFiles = async (directory, ignorePatterns) => {
|
|
7
|
+
const pattern = `${directory}/**/*.{js,jsx,ts,tsx}`;
|
|
8
|
+
const defaultIgnores = [
|
|
9
|
+
"**/node_modules/**",
|
|
10
|
+
"**/.git/**",
|
|
11
|
+
"**/build/**",
|
|
12
|
+
"**/dist/**",
|
|
13
|
+
"**/dist-npm/**",
|
|
14
|
+
"**/dist-jsr/**",
|
|
15
|
+
"**/dist-libs/**",
|
|
16
|
+
"**/coverage/**"
|
|
17
|
+
];
|
|
18
|
+
const allIgnores = [...defaultIgnores, ...ignorePatterns];
|
|
19
|
+
return await glob(pattern, {
|
|
20
|
+
ignore: allIgnores,
|
|
21
|
+
absolute: true,
|
|
22
|
+
nodir: true
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
export const readFile = async (filePath) => {
|
|
26
|
+
try {
|
|
27
|
+
return await readFileAsync(filePath, "utf8");
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error(`Error reading file ${filePath}:`, error);
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export const readPackageJson = async (directory) => {
|
|
34
|
+
const packageJsonPath = path.join(directory, "package.json");
|
|
35
|
+
try {
|
|
36
|
+
const content = await readFile(packageJsonPath);
|
|
37
|
+
return JSON.parse(content);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error("Error reading package.json:", error);
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
export const formatOutput = (result, options) => {
|
|
3
|
+
if (options.json) {
|
|
4
|
+
return JSON.stringify(result, null, 2);
|
|
5
|
+
}
|
|
6
|
+
let output = "";
|
|
7
|
+
output += chalk.bold.blue("\nMissing Dependencies Finder Results\n");
|
|
8
|
+
output += chalk.gray("---------------------------------------\n\n");
|
|
9
|
+
output += chalk.bold("Statistics:\n");
|
|
10
|
+
output += `${chalk.gray("\u2022 ")}Total dependencies found: ${result.allDependencies.length}
|
|
11
|
+
`;
|
|
12
|
+
output += `${chalk.gray("\u2022 ")}Listed in package.json: ${result.listedDependencies.length}
|
|
13
|
+
`;
|
|
14
|
+
output += `${chalk.gray("\u2022 ")}Missing from package.json: ${result.missingDependencies.length}
|
|
15
|
+
`;
|
|
16
|
+
if (options.includeBuiltins) {
|
|
17
|
+
output += `${chalk.gray("\u2022 ")}Node.js built-in modules: ${result.builtinModules.length}
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
output += "\n";
|
|
21
|
+
if (result.missingDependencies.length > 0) {
|
|
22
|
+
output += chalk.bold.red("Missing Dependencies:\n");
|
|
23
|
+
for (const dep of result.missingDependencies) {
|
|
24
|
+
output += `${chalk.gray("\u2022 ")}${chalk.yellow(dep)}
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
output += "\n";
|
|
28
|
+
output += chalk.gray("To install, run:\n");
|
|
29
|
+
output += chalk.cyan(
|
|
30
|
+
`npm install ${result.missingDependencies.join(" ")}
|
|
31
|
+
|
|
32
|
+
`
|
|
33
|
+
);
|
|
34
|
+
} else {
|
|
35
|
+
output += chalk.bold.green("No missing dependencies found! \u{1F389}\n\n");
|
|
36
|
+
}
|
|
37
|
+
if (options.includeBuiltins && result.builtinModules.length > 0) {
|
|
38
|
+
output += chalk.bold.blue("Node.js Built-in Modules Used:\n");
|
|
39
|
+
for (const dep of result.builtinModules) {
|
|
40
|
+
output += `${chalk.gray("\u2022 ")}${chalk.blue(dep)}
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
output += "\n";
|
|
44
|
+
}
|
|
45
|
+
if (options.showAll) {
|
|
46
|
+
output += chalk.bold("All Dependencies:\n");
|
|
47
|
+
output += chalk.gray("(\u2713 = listed in package.json, \u2717 = missing)\n");
|
|
48
|
+
for (const dep of result.allDependencies) {
|
|
49
|
+
const isListed = result.listedDependencies.includes(dep);
|
|
50
|
+
const isBuiltin = result.builtinModules.includes(dep);
|
|
51
|
+
if (isListed) {
|
|
52
|
+
output += `${chalk.gray("\u2022 ") + chalk.green("\u2713 ") + dep}
|
|
53
|
+
`;
|
|
54
|
+
} else if (isBuiltin) {
|
|
55
|
+
output += `${chalk.gray("\u2022 ")}${chalk.blue("\u26A1 ")}${dep}${chalk.gray(" (built-in)")}
|
|
56
|
+
`;
|
|
57
|
+
} else {
|
|
58
|
+
output += `${chalk.gray("\u2022 ")}${chalk.red("\u2717 ")}${chalk.yellow(dep)}
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
output += "\n";
|
|
63
|
+
}
|
|
64
|
+
return output;
|
|
65
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { re } from "@reliverse/relico";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { analyzeDependencies } from "./analyzer.js";
|
|
5
|
+
import { formatOutput } from "./formatter.js";
|
|
6
|
+
export const createCli = () => {
|
|
7
|
+
const program = new Command();
|
|
8
|
+
program.name("deps").description("Find dependencies used but not listed in package.json").version("1.0.0").option(
|
|
9
|
+
"-d, --directory <path>",
|
|
10
|
+
"directory to scan (defaults to current directory)",
|
|
11
|
+
"."
|
|
12
|
+
).option(
|
|
13
|
+
"-a, --all",
|
|
14
|
+
"show all dependencies (both listed and not listed)",
|
|
15
|
+
false
|
|
16
|
+
).option("-i, --ignore <patterns>", "comma-separated patterns to ignore", "").option("-j, --json", "output in JSON format", false).option(
|
|
17
|
+
"-b, --include-builtins",
|
|
18
|
+
"include Node.js built-in modules in the output",
|
|
19
|
+
false
|
|
20
|
+
).action(async (cmdOptions) => {
|
|
21
|
+
try {
|
|
22
|
+
const directory = path.resolve(cmdOptions.directory);
|
|
23
|
+
const ignorePatterns = cmdOptions.ignore ? cmdOptions.ignore.split(",") : [];
|
|
24
|
+
const options = {
|
|
25
|
+
directory,
|
|
26
|
+
showAll: cmdOptions.all,
|
|
27
|
+
ignorePatterns,
|
|
28
|
+
json: cmdOptions.json,
|
|
29
|
+
includeBuiltins: cmdOptions.includeBuiltins
|
|
30
|
+
};
|
|
31
|
+
console.log(re.gray(`Scanning directory: ${directory}`));
|
|
32
|
+
const result = await analyzeDependencies(options);
|
|
33
|
+
const output = formatOutput(result, options);
|
|
34
|
+
console.log(output);
|
|
35
|
+
if (result.missingDependencies.length > 0) {
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error("Error:", error);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return program;
|
|
44
|
+
};
|
|
45
|
+
const cli = createCli();
|
|
46
|
+
if (require.main === module) {
|
|
47
|
+
cli.parse(process.argv);
|
|
48
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { builtinModules } from "node:module";
|
|
2
|
+
const importRegexes = [
|
|
3
|
+
// ES modules
|
|
4
|
+
/import\s+(?:{[^}]*}|\*\s+as\s+[^,]*|[^,{]*)\s+from\s+["']([^"']+)["']/g,
|
|
5
|
+
// Dynamic imports
|
|
6
|
+
/import\(["']([^"']+)["']\)/g,
|
|
7
|
+
// CommonJS requires
|
|
8
|
+
/require\(["']([^"']+)["']\)/g,
|
|
9
|
+
// Export from
|
|
10
|
+
/export\s+(?:{[^}]*}|\*)\s+from\s+["']([^"']+)["']/g
|
|
11
|
+
];
|
|
12
|
+
export const extractPackageNames = (fileContent) => {
|
|
13
|
+
const packageNames = /* @__PURE__ */ new Set();
|
|
14
|
+
for (const regex of importRegexes) {
|
|
15
|
+
let match;
|
|
16
|
+
const clonedRegex = new RegExp(regex.source, regex.flags);
|
|
17
|
+
for (; ; ) {
|
|
18
|
+
match = clonedRegex.exec(fileContent);
|
|
19
|
+
if (match === null) {
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
const importPath = match[1];
|
|
23
|
+
if (importPath) {
|
|
24
|
+
const packageName = normalizePackageName(importPath);
|
|
25
|
+
if (packageName) {
|
|
26
|
+
packageNames.add(packageName);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return packageNames;
|
|
32
|
+
};
|
|
33
|
+
export const normalizePackageName = (importPath) => {
|
|
34
|
+
if (importPath.startsWith(".") || importPath.startsWith("/")) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (importPath.startsWith("@")) {
|
|
38
|
+
const scopedMatch = importPath.match(/^(@[^/]+\/[^/]+)/);
|
|
39
|
+
return scopedMatch ? scopedMatch[1] ?? null : null;
|
|
40
|
+
}
|
|
41
|
+
const match = importPath.match(/^([^/]+)/);
|
|
42
|
+
return match ? match[1] ?? null : null;
|
|
43
|
+
};
|
|
44
|
+
export const getListedDependencies = (packageJson) => {
|
|
45
|
+
const listedDependencies = /* @__PURE__ */ new Set();
|
|
46
|
+
const allDependencies = {
|
|
47
|
+
...packageJson.dependencies,
|
|
48
|
+
...packageJson.devDependencies,
|
|
49
|
+
...packageJson.peerDependencies,
|
|
50
|
+
...packageJson.optionalDependencies
|
|
51
|
+
};
|
|
52
|
+
for (const dep of Object.keys(allDependencies || {})) {
|
|
53
|
+
listedDependencies.add(dep);
|
|
54
|
+
}
|
|
55
|
+
return listedDependencies;
|
|
56
|
+
};
|
|
57
|
+
export const getBuiltinModules = () => {
|
|
58
|
+
return new Set(builtinModules);
|
|
59
|
+
};
|
|
File without changes
|