susee 1.6.2 → 2.0.1
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 +290 -119
- package/bin/susee +2 -2
- package/index.d.ts +140 -0
- package/index.js +708 -0
- package/package.json +13 -41
- package/dist/index.cjs +0 -3476
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -95
- package/dist/index.d.mts +0 -95
- package/dist/index.mjs +0 -3436
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
[![NPM][nodei_img]][nodei_url]
|
|
10
10
|
|
|
11
|
-
[![npm version][npm_v_img]][npm_v_url] [![license][license_img]](LICENSE)
|
|
11
|
+
[![npm version][npm_v_img]][npm_v_url] [![license][license_img]](LICENSE)[![publish to npm][publish_npm_svg]][publish_npm][](https://www.bestpractices.dev/projects/13115) [](https://www.bestpractices.dev/projects/13115)
|
|
12
12
|
|
|
13
13
|
## About
|
|
14
14
|
|
|
@@ -16,30 +16,29 @@ A **TypeScript-first** bundler designed specifically for **library packages** th
|
|
|
16
16
|
|
|
17
17
|
> [!NOTE]
|
|
18
18
|
>
|
|
19
|
-
> - Susee
|
|
20
|
-
> -
|
|
21
|
-
> -
|
|
22
|
-
> - For the best compatibility with this setup, use `Susee v1.6.0` or newer.
|
|
19
|
+
> - Starting with **v2.0.0**, Susee's core is written in **Rust** and compiled to a native Node.js addon via **N-API** (`@napi-rs/cli`). The compiler, bundler, and minifier all run in native code for maximum performance.
|
|
20
|
+
> - The output JavaScript is minified with the **[oxc](https://oxc.rs) minifier** when `minify` is enabled.
|
|
21
|
+
> - Config files use the **JSONC** format (`susee.config.jsonc`).
|
|
23
22
|
|
|
24
23
|
---
|
|
25
24
|
|
|
26
25
|
## Key Features
|
|
27
26
|
|
|
28
|
-
✅ **
|
|
27
|
+
✅ **Rust-powered core** — Bundler, compiler, and minifier run natively via N-API
|
|
29
28
|
|
|
30
|
-
✅ **
|
|
29
|
+
✅ **TypeScript-first** — Built for maximum type safety
|
|
31
30
|
|
|
32
|
-
✅ **
|
|
31
|
+
✅ **Dual Output** — Generate both ESM and CommonJS formats automatically
|
|
33
32
|
|
|
34
|
-
✅ **
|
|
33
|
+
✅ **Duplicate Declaration Detection** — Fails fast when bundled files contain conflicting top-level declarations
|
|
35
34
|
|
|
36
|
-
✅ **
|
|
35
|
+
✅ **Fast Builds** — Optimized for library packages with minimal overhead
|
|
37
36
|
|
|
38
|
-
✅ **
|
|
37
|
+
✅ **Built-in Minification** — Minify output JavaScript with the oxc minifier
|
|
39
38
|
|
|
40
|
-
✅ **
|
|
39
|
+
✅ **Package.json Management** — Automatic updates to package.json fields based on the build results
|
|
41
40
|
|
|
42
|
-
✅ **
|
|
41
|
+
✅ **CLI & Programmatic API** — Use as a CLI tool or integrate directly
|
|
43
42
|
|
|
44
43
|
---
|
|
45
44
|
|
|
@@ -81,7 +80,7 @@ npx susee --version
|
|
|
81
80
|
|
|
82
81
|
### Using config file
|
|
83
82
|
|
|
84
|
-
The easiest way to start is using the built-in initialization command which generates a configuration template at your project root.This command creates a `susee.config.
|
|
83
|
+
The easiest way to start is using the built-in initialization command which generates a configuration template at your project root. This command creates a `susee.config.jsonc` file.
|
|
85
84
|
|
|
86
85
|
```bash
|
|
87
86
|
npx susee init
|
|
@@ -93,14 +92,14 @@ Build your project by running:
|
|
|
93
92
|
npx susee
|
|
94
93
|
```
|
|
95
94
|
|
|
96
|
-
### Using Programmatic API
|
|
95
|
+
### Using Programmatic API (Node.js)
|
|
97
96
|
|
|
98
|
-
You can trigger the build process within a TypeScript
|
|
97
|
+
You can trigger the build process within a JavaScript/TypeScript script using the `suseeBuild()` N-API function.
|
|
99
98
|
|
|
100
99
|
```typescript
|
|
101
|
-
import {
|
|
100
|
+
import { suseeBuild } from "susee";
|
|
102
101
|
|
|
103
|
-
|
|
102
|
+
suseeBuild({
|
|
104
103
|
entryPoints: [
|
|
105
104
|
{
|
|
106
105
|
entry: "src/index.ts",
|
|
@@ -110,15 +109,16 @@ await build({
|
|
|
110
109
|
],
|
|
111
110
|
outDir: "dist",
|
|
112
111
|
allowUpdatePackageJson: true,
|
|
112
|
+
minify: true,
|
|
113
113
|
});
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
### Using CLI (Direct Build)
|
|
117
117
|
|
|
118
|
-
Build a single entry directly without a config file.This method uses default values for options not explicitly provided.
|
|
118
|
+
Build a single entry directly without a config file. This method uses default values for options not explicitly provided.
|
|
119
119
|
|
|
120
120
|
```bash
|
|
121
|
-
npx susee build src/index.ts --outdir dist --format esm
|
|
121
|
+
npx susee build src/index.ts --outdir dist --format esm --minify
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
### Contributor Setup (Repository)
|
|
@@ -142,20 +142,233 @@ Do not open public issues for security reports.
|
|
|
142
142
|
|
|
143
143
|
---
|
|
144
144
|
|
|
145
|
-
## API
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
145
|
+
## N-API (Node.js) Exports
|
|
146
|
+
|
|
147
|
+
Susee's Rust core is exposed to Node.js via N-API (`@napi-rs/cli`). The following functions and types are available:
|
|
148
|
+
|
|
149
|
+
### `suseeBuild(config?)`
|
|
150
|
+
|
|
151
|
+
Build from the provided config object or from a discovered `susee.config.jsonc` file. If neither exists, Susee logs an error and exits with code `1`.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { suseeBuild, type SuSeeConfig } from "susee";
|
|
155
|
+
|
|
156
|
+
// Build from an explicit config object
|
|
157
|
+
suseeBuild({
|
|
158
|
+
entryPoints: [
|
|
159
|
+
{
|
|
160
|
+
entry: "src/index.ts",
|
|
161
|
+
exportPath: ".",
|
|
162
|
+
format: ["esm", "commonjs"],
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
outDir: "dist",
|
|
166
|
+
allowUpdatePackageJson: false,
|
|
167
|
+
minify: true,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Build from susee.config.jsonc (config omitted)
|
|
171
|
+
suseeBuild();
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
| Parameter | Type | Required | Default | Description |
|
|
175
|
+
| --------------- | --------------------------- | -------- | ------- | ------------------------------------------------ |
|
|
176
|
+
| `config` | `SuSeeConfig \| undefined` | No | — | Build options. If omitted, loads config file. |
|
|
177
|
+
|
|
178
|
+
### `cliBuild(args)`
|
|
179
|
+
|
|
180
|
+
Run the CLI dispatcher programmatically. Pass `process.argv.slice(2)` from the JavaScript side.
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import { cliBuild } from "susee";
|
|
184
|
+
|
|
185
|
+
cliBuild(process.argv.slice(2));
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
| Parameter | Type | Required | Description |
|
|
189
|
+
| --------- | ------------ | -------- | ------------------------------------------------------------------ |
|
|
190
|
+
| `args` | `string[]` | Yes | CLI arguments (typically `process.argv.slice(2)`). |
|
|
191
|
+
|
|
192
|
+
### `suseeBundler(entry)`
|
|
193
|
+
|
|
194
|
+
Bundle a single entry and return the merged source string. This export does not expose plugin or warning options.
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { suseeBundler } from "susee";
|
|
198
|
+
|
|
199
|
+
const bundled = suseeBundler("src/index.ts");
|
|
200
|
+
console.log(bundled);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
| Parameter | Type | Required | Description |
|
|
204
|
+
| --------- | -------- | -------- | ----------------------------------------- |
|
|
205
|
+
| `entry` | `string` | Yes | Entry file path relative to project root. |
|
|
206
|
+
|
|
207
|
+
**Returns:** `string` — the bundled source code.
|
|
208
|
+
|
|
209
|
+
### `OutputFormat` (enum)
|
|
210
|
+
|
|
211
|
+
N-API enum representing the output module format.
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
enum OutputFormat {
|
|
215
|
+
Esm = "esm",
|
|
216
|
+
Commonjs = "commonjs",
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### `SuSeeConfig` (object)
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
interface SuSeeConfig {
|
|
224
|
+
entryPoints: EntryPoint[];
|
|
225
|
+
outDir?: string; // default: "dist"
|
|
226
|
+
allowUpdatePackageJson?: boolean; // default: false
|
|
227
|
+
minify?: boolean; // default: false
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### `EntryPoint` (object)
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
interface EntryPoint {
|
|
235
|
+
entry: string;
|
|
236
|
+
exportPath: string; // "." or "./sub/path"
|
|
237
|
+
format?: OutputFormat[]; // default: ["esm"]
|
|
238
|
+
tsconfigFilePath?: string | null; // default: null
|
|
239
|
+
warning?: boolean; // default: false
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Rust API
|
|
246
|
+
|
|
247
|
+
The Rust core library exposes the following public functions and types via the `susee` crate:
|
|
248
|
+
|
|
249
|
+
### `core::build(config: Option<&SuSeeConfig>)`
|
|
250
|
+
|
|
251
|
+
Top-level build entry point. When `config` is `None`, the config is loaded from `susee.config.jsonc` in the current directory.
|
|
252
|
+
|
|
253
|
+
```rust
|
|
254
|
+
use susee::{SuSeeConfig,susee_build};
|
|
255
|
+
|
|
256
|
+
// Build from config file
|
|
257
|
+
core::build(None);
|
|
258
|
+
|
|
259
|
+
// Build from explicit config
|
|
260
|
+
let config = SuSeeConfig {
|
|
261
|
+
entry_points: vec![susee::core::EntryPoint {
|
|
262
|
+
entry: "src/index.ts".to_string(),
|
|
263
|
+
export_path: ".".to_string(),
|
|
264
|
+
format: Some(vec![susee::core::OutputFormat::Esm]),
|
|
265
|
+
tsconfig_file_path: None,
|
|
266
|
+
warning: Some(false),
|
|
267
|
+
}],
|
|
268
|
+
out_dir: Some("dist".to_string()),
|
|
269
|
+
allow_update_package_json: Some(false),
|
|
270
|
+
minify: Some(true),
|
|
271
|
+
};
|
|
272
|
+
susee_build(Some(&config));
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### `core::susee_build(config: &SuSeeConfig) -> Result<(), String>`
|
|
276
|
+
|
|
277
|
+
Build from a config reference. Returns `Ok(())` on success or an error string on failure.
|
|
278
|
+
|
|
279
|
+
```rust
|
|
280
|
+
use susee::{susee_build, SuSeeConfig, EntryPoint, OutputFormat};
|
|
281
|
+
|
|
282
|
+
let config = SuSeeConfig {
|
|
283
|
+
entry_points: vec![EntryPoint {
|
|
284
|
+
entry: "src/index.ts".to_string(),
|
|
285
|
+
export_path: ".".to_string(),
|
|
286
|
+
format: Some(vec![OutputFormat::Esm, OutputFormat::Commonjs]),
|
|
287
|
+
tsconfig_file_path: None,
|
|
288
|
+
warning: Some(false),
|
|
289
|
+
}],
|
|
290
|
+
out_dir: Some("dist".to_string()),
|
|
291
|
+
allow_update_package_json: Some(false),
|
|
292
|
+
minify: Some(true),
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
susee_build(&config).expect("build failed");
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### `core::bundler(entry: &str, cwd: &str) -> std::io::Result<BundleResult>`
|
|
299
|
+
|
|
300
|
+
Bundle a single entry and return the merged source string along with project type metadata.
|
|
301
|
+
|
|
302
|
+
```rust
|
|
303
|
+
use susee::core::bundler;
|
|
304
|
+
|
|
305
|
+
let result = bundler("src/index.ts", ".")?;
|
|
306
|
+
println!("{}", result.bundled_code);
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### `core::susee_cli_build_with_args(args: Vec<String>)`
|
|
310
|
+
|
|
311
|
+
CLI dispatcher with explicit args. Reads `std::env::args_os().skip(1)` for the standalone binary, or accepts args passed from the N-API layer.
|
|
312
|
+
|
|
313
|
+
```rust
|
|
314
|
+
use susee::core::susee_cli_build_with_args;
|
|
315
|
+
|
|
316
|
+
susee_cli_build_with_args(vec!["build".to_string(), "src/index.ts".to_string()]);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Rust Types
|
|
320
|
+
|
|
321
|
+
#### `SuSeeConfig`
|
|
322
|
+
|
|
323
|
+
```rust
|
|
324
|
+
pub struct SuSeeConfig {
|
|
325
|
+
pub entry_points: Vec<EntryPoint>,
|
|
326
|
+
pub out_dir: Option<String>,
|
|
327
|
+
pub allow_update_package_json: Option<bool>,
|
|
328
|
+
pub minify: Option<bool>,
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### `EntryPoint`
|
|
333
|
+
|
|
334
|
+
```rust
|
|
335
|
+
pub struct EntryPoint {
|
|
336
|
+
pub entry: String,
|
|
337
|
+
pub export_path: String,
|
|
338
|
+
pub format: Option<Vec<OutputFormat>>,
|
|
339
|
+
pub tsconfig_file_path: Option<String>,
|
|
340
|
+
pub warning: Option<bool>,
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
#### `OutputFormat`
|
|
345
|
+
|
|
346
|
+
```rust
|
|
347
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
348
|
+
#[serde(rename_all = "lowercase")]
|
|
349
|
+
pub enum OutputFormat {
|
|
350
|
+
Commonjs, // serialized as "commonjs"
|
|
351
|
+
Esm, // serialized as "esm"
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
#### `BuildOptions` (internal)
|
|
356
|
+
|
|
357
|
+
```rust
|
|
358
|
+
pub struct BuildOptions {
|
|
359
|
+
pub build_entry_points: Vec<BuildEntryPoint>,
|
|
360
|
+
pub update_package: bool,
|
|
361
|
+
pub out_dir: String,
|
|
362
|
+
pub minify: bool,
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### Cargo.toml
|
|
367
|
+
|
|
368
|
+
```toml
|
|
369
|
+
[dependencies]
|
|
370
|
+
susee = "2"
|
|
371
|
+
```
|
|
159
372
|
|
|
160
373
|
---
|
|
161
374
|
|
|
@@ -165,8 +378,8 @@ Do not open public issues for security reports.
|
|
|
165
378
|
Susee CLI.
|
|
166
379
|
|
|
167
380
|
Usage:
|
|
168
|
-
susee Build using susee.config.
|
|
169
|
-
susee init Generate susee.config.
|
|
381
|
+
susee Build using susee.config.jsonc
|
|
382
|
+
susee init Generate susee.config.jsonc
|
|
170
383
|
susee --version | -v Check susee version
|
|
171
384
|
susee --help | -h Show this message
|
|
172
385
|
susee build <entry> [options] Build from a single entry file
|
|
@@ -181,7 +394,7 @@ Usage:
|
|
|
181
394
|
--tsconfig <path> Custom tsconfig path
|
|
182
395
|
--allow-update[=true|false] Allow package.json updates (default: false)
|
|
183
396
|
--warning[=true|false] Treat dependency graph warnings as fatal (default: false)
|
|
184
|
-
--
|
|
397
|
+
--minify[=true|false] Minify output JavaScript code (default: false)
|
|
185
398
|
```
|
|
186
399
|
|
|
187
400
|
### CLI Examples
|
|
@@ -190,106 +403,61 @@ Usage:
|
|
|
190
403
|
npx susee build src/index.ts --outdir dist
|
|
191
404
|
npx susee build src/index.ts --format commonjs
|
|
192
405
|
npx susee build --entry src/index.ts --format esm
|
|
193
|
-
npx susee build src/index.ts --profile
|
|
194
406
|
```
|
|
195
407
|
|
|
196
408
|
Notes:
|
|
197
409
|
|
|
198
410
|
1. `susee build` accepts either a positional `<entry>` or `--entry <path>`.
|
|
199
411
|
2. `--profile` is also accepted on plain `susee` config-driven builds.
|
|
200
|
-
3.
|
|
412
|
+
3. `--minify` enables the oxc minifier on the emitted JavaScript output.
|
|
413
|
+
4. The CLI clears the target `outDir` before writing new output.
|
|
201
414
|
|
|
202
415
|
---
|
|
203
416
|
|
|
204
417
|
## Config File
|
|
205
418
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
1. `susee.config.ts`
|
|
209
|
-
2. `susee.config.js`
|
|
210
|
-
3. `susee.config.mjs`
|
|
211
|
-
|
|
212
|
-
### `SuSeeConfig` shape
|
|
213
|
-
|
|
214
|
-
```ts
|
|
215
|
-
type OutputFormat = ("commonjs" | "esm")[];
|
|
216
|
-
|
|
217
|
-
interface EntryPoint {
|
|
218
|
-
entry: string;
|
|
219
|
-
exportPath: "." | `./${string}`;
|
|
220
|
-
format?: OutputFormat; // default: ["esm"]
|
|
221
|
-
tsconfigFilePath?: string | undefined; // default: undefined
|
|
222
|
-
plugins?: unknown[]; // default: []
|
|
223
|
-
warning?: boolean; // default: false
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
interface SuSeeConfig {
|
|
227
|
-
entryPoints: EntryPoint[];
|
|
228
|
-
outDir?: string; // default: "dist"
|
|
229
|
-
allowUpdatePackageJson?: boolean; // default: false
|
|
230
|
-
}
|
|
231
|
-
```
|
|
419
|
+
The config file uses the **JSONC** format (JSON with comments) and must be named:
|
|
232
420
|
|
|
233
|
-
|
|
421
|
+
- `susee.config.jsonc`
|
|
234
422
|
|
|
235
|
-
|
|
236
|
-
import type { SuSeeConfig } from "susee";
|
|
423
|
+
### `susee.config.jsonc` example
|
|
237
424
|
|
|
238
|
-
|
|
239
|
-
|
|
425
|
+
```jsonc
|
|
426
|
+
{
|
|
427
|
+
// Entry points to bundle
|
|
428
|
+
"entryPoints": [
|
|
240
429
|
{
|
|
241
|
-
entry: "src/index.ts",
|
|
242
|
-
exportPath: ".",
|
|
243
|
-
format: ["esm", "commonjs"],
|
|
244
|
-
|
|
430
|
+
"entry": "src/index.ts",
|
|
431
|
+
"exportPath": ".",
|
|
432
|
+
"format": ["esm", "commonjs"],
|
|
433
|
+
"tsconfigFilePath": null,
|
|
434
|
+
"warning": false
|
|
435
|
+
}
|
|
245
436
|
],
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
## Programmatic API
|
|
254
|
-
|
|
255
|
-
### `build(options?)`
|
|
256
|
-
|
|
257
|
-
Signature:
|
|
258
|
-
|
|
259
|
-
```ts
|
|
260
|
-
function build(options?: SuSeeConfig): Promise<void>;
|
|
437
|
+
// Output directory (default: "dist")
|
|
438
|
+
"outDir": "dist",
|
|
439
|
+
// Update package.json fields from build output (default: false)
|
|
440
|
+
"allowUpdatePackageJson": false,
|
|
441
|
+
// Minify output JS with the oxc minifier (default: false)
|
|
442
|
+
"minify": true
|
|
443
|
+
}
|
|
261
444
|
```
|
|
262
445
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
1. `options` (optional): Build options passed directly from code.
|
|
266
|
-
|
|
267
|
-
Returns:
|
|
268
|
-
|
|
269
|
-
1. `Promise<void>` that resolves when compilation completes.
|
|
270
|
-
|
|
271
|
-
Runtime behavior:
|
|
446
|
+
### Config schema
|
|
272
447
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
448
|
+
| Field | Type | Required | Default | Description |
|
|
449
|
+
| ----------------------- | ------------ | -------- | ----------- | -------------------------------------------- |
|
|
450
|
+
| `entryPoints` | `EntryPoint[]` | Yes | — | List of entry points to build. |
|
|
451
|
+
| `outDir` | `string` | No | `"dist"` | Root output directory. |
|
|
452
|
+
| `allowUpdatePackageJson`| `boolean` | No | `false` | Update package.json from build output. |
|
|
453
|
+
| `minify` | `boolean` | No | `false` | Minify emitted JS with the oxc minifier. |
|
|
454
|
+
| `entryPoints[].entry` | `string` | Yes | — | Entry file path. |
|
|
455
|
+
| `entryPoints[].exportPath` | `string` | Yes | — | Package export path (`.` or `./sub`). |
|
|
456
|
+
| `entryPoints[].format` | `string[]` | No | `["esm"]` | Output formats: `"esm"`, `"commonjs"`. |
|
|
457
|
+
| `entryPoints[].tsconfigFilePath` | `string\|null` | No | `null` | Custom tsconfig path. |
|
|
458
|
+
| `entryPoints[].warning` | `boolean` | No | `false` | Treat dependency warnings as fatal. |
|
|
277
459
|
|
|
278
|
-
|
|
279
|
-
import { build, type SuSeeConfig } from "susee";
|
|
280
|
-
|
|
281
|
-
const options: SuSeeConfig = {
|
|
282
|
-
entryPoints: [
|
|
283
|
-
{
|
|
284
|
-
entry: "src/index.ts",
|
|
285
|
-
exportPath: ".",
|
|
286
|
-
format: ["esm", "commonjs"],
|
|
287
|
-
},
|
|
288
|
-
],
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
await build(options);
|
|
292
|
-
```
|
|
460
|
+
---
|
|
293
461
|
|
|
294
462
|
## Output Notes
|
|
295
463
|
|
|
@@ -297,7 +465,10 @@ For an entry like `src/index.ts` with both formats enabled, output includes:
|
|
|
297
465
|
|
|
298
466
|
1. ESM: `dist/index.mjs`
|
|
299
467
|
2. CommonJS: `dist/index.cjs`
|
|
300
|
-
3.
|
|
468
|
+
3. Type declarations: `dist/index.d.mts` and `dist/index.d.cts`
|
|
469
|
+
4. Sourcemaps: `dist/index.mjs.map` and `dist/index.cjs.map`
|
|
470
|
+
|
|
471
|
+
When `minify` is enabled, the ESM and CommonJS output files are minified using the **oxc** minifier.
|
|
301
472
|
|
|
302
473
|
Declaration files are emitted by the compiler when available.
|
|
303
474
|
|
|
@@ -364,7 +535,7 @@ Violations print an error and exit with code `1`.
|
|
|
364
535
|
[npm_v_img]: https://img.shields.io/npm/v/susee
|
|
365
536
|
[npm_v_url]: https://www.npmjs.com/package/susee
|
|
366
537
|
[license_img]: https://img.shields.io/npm/l/susee
|
|
367
|
-
[publish_npm]: https://github.com/phothinmg/susee/actions/workflows/
|
|
538
|
+
[publish_npm]: https://github.com/phothinmg/susee/actions/workflows/ci.yml
|
|
368
539
|
[publish_npm_svg]: https://github.com/phothinmg/susee/actions/workflows/npm-publish.yml/badge.svg?event=release
|
|
369
540
|
[mmcov_svg]: https://img.shields.io/badge/mmcov-85.01%25-green?style=flat&labelColor=%232c3e50
|
|
370
541
|
[mmcov_url]: https://suseejs.org/coverage
|
package/bin/susee
CHANGED
package/index.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Run full dependency-graph analysis and return the result as a JSON string.
|
|
5
|
+
*
|
|
6
|
+
* This is the simplest call site: the JS side can `JSON.parse()` the result
|
|
7
|
+
* and inspect any field of [`crate::graph::GraphObject`].
|
|
8
|
+
*
|
|
9
|
+
* Available in both the cargo crate (as a plain Rust function) and the
|
|
10
|
+
* napi Node.js binding (as a JS function).
|
|
11
|
+
*
|
|
12
|
+
* # Errors
|
|
13
|
+
*
|
|
14
|
+
* Returns a napi `Error` (thrown as a JS `Error`) if the project cannot be
|
|
15
|
+
* read or traversal fails.
|
|
16
|
+
*/
|
|
17
|
+
export declare function analyze(entry: string, root: string): string
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Run analysis and return a structured [`GraphResult`] object.
|
|
21
|
+
*
|
|
22
|
+
* Prefer this over [`analyze`] when you want typed access to individual
|
|
23
|
+
* views without parsing JSON on the JS side.
|
|
24
|
+
*
|
|
25
|
+
* Available in both the cargo crate (as a plain Rust function) and the
|
|
26
|
+
* napi Node.js binding (as a JS function).
|
|
27
|
+
*/
|
|
28
|
+
export declare function graph(entry: string, root: string): GraphResult
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A structured projection of [`crate::graph::GraphObject`].
|
|
32
|
+
*
|
|
33
|
+
* Exposes the most useful derived views as typed fields. Available in both
|
|
34
|
+
* the cargo crate (as a plain Rust struct) and the napi Node.js binding
|
|
35
|
+
* (as a JS object).
|
|
36
|
+
*/
|
|
37
|
+
export interface GraphResult {
|
|
38
|
+
/** Topologically sorted files (dependencies first). */
|
|
39
|
+
sort: Array<string>
|
|
40
|
+
/** NPM package specifiers found in the project (e.g. `"react"`). */
|
|
41
|
+
npm: Array<string>
|
|
42
|
+
/** Node.js built-in module specifiers (e.g. `"node:fs"`). */
|
|
43
|
+
node: Array<string>
|
|
44
|
+
/** Warnings collected during traversal. */
|
|
45
|
+
warn: Array<string>
|
|
46
|
+
/** Leaf files — files with no local-file dependencies. */
|
|
47
|
+
leaf: Array<string>
|
|
48
|
+
/** Mutual dependency pairs (files that depend on each other). */
|
|
49
|
+
mutual: Array<Array<string>>
|
|
50
|
+
/** The graph rendered as a text tree. */
|
|
51
|
+
textGraph: string
|
|
52
|
+
/** The raw dependency map: file → its local imports. */
|
|
53
|
+
deps: Record<string, Array<string>>
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Runs the SuSee CLI build from Node.js with an explicit argument list.
|
|
57
|
+
*
|
|
58
|
+
* `args` should be `process.argv.slice(2)` — the user-supplied CLI arguments
|
|
59
|
+
* with the Node executable and script path already stripped. The standalone
|
|
60
|
+
* Rust binary reads `std::env::args_os().skip(1)`, which is correct for the
|
|
61
|
+
* binary but wrong under Node (where `argv[0]` is `node` and `argv[1]` is the
|
|
62
|
+
* bin script), so the arguments are passed explicitly here.
|
|
63
|
+
*
|
|
64
|
+
* After the build completes, the elapsed time is logged via
|
|
65
|
+
* [`core::susee_log::build_time`].
|
|
66
|
+
*
|
|
67
|
+
* # Panics
|
|
68
|
+
*
|
|
69
|
+
* Propagates any panic originating from [`core::susee_cli_build_with_args`].
|
|
70
|
+
*/
|
|
71
|
+
export declare function cliBuild(args: Array<string>): void
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A single entry point in the raw config, mirroring `EntryPoint` from
|
|
75
|
+
* `src/nodejs/config/index.ts`.
|
|
76
|
+
*
|
|
77
|
+
* JSON field names use camelCase to match the TS `SuSeeConfig` interface
|
|
78
|
+
* (e.g. `entryPoints`, `exportPath`).
|
|
79
|
+
*/
|
|
80
|
+
export interface EntryPoint {
|
|
81
|
+
entry: string
|
|
82
|
+
exportPath: string
|
|
83
|
+
format?: Array<OutputFormat>
|
|
84
|
+
tsconfigFilePath?: string
|
|
85
|
+
warning?: boolean
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Output module formats supported by the compiler.
|
|
90
|
+
*
|
|
91
|
+
* Mirrors `OutputFormat = ("commonjs" | "esm")[]` from the TS config.
|
|
92
|
+
* Serialized as lowercase strings to match the JSON config form.
|
|
93
|
+
*/
|
|
94
|
+
export declare const enum OutputFormat {
|
|
95
|
+
Commonjs = 0,
|
|
96
|
+
Esm = 1
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Runs the full SuSee build pipeline and exposes it to Node.js.
|
|
101
|
+
*
|
|
102
|
+
* When `config` is `None`, the configuration is loaded from
|
|
103
|
+
* `susee.config.jsonc` in the current working directory. When a
|
|
104
|
+
* [`SuSeeConfig`] is provided, it overrides the file-based configuration.
|
|
105
|
+
*
|
|
106
|
+
* After the build completes, the elapsed time is logged via
|
|
107
|
+
* [`core::susee_log::build_time`].
|
|
108
|
+
*
|
|
109
|
+
* # Panics
|
|
110
|
+
*
|
|
111
|
+
* Propagates any panic originating from [`core::build`]; the caller (Node.js)
|
|
112
|
+
* is responsible for converting such panics into rejected promises.
|
|
113
|
+
*/
|
|
114
|
+
export declare function suseeBuild(config?: SuSeeConfig | undefined | null): void
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Bundles an entry module into a single string and exposes it to Node.js.
|
|
118
|
+
*
|
|
119
|
+
* `entry` is resolved relative to the current working directory (`.`). The
|
|
120
|
+
* resulting [`bundler`] output is unwrapped and the bundled JavaScript code is
|
|
121
|
+
* returned as a [`String`]. On failure, the error is printed in magenta via
|
|
122
|
+
* the [`colored`] crate and the process panics.
|
|
123
|
+
*
|
|
124
|
+
* After bundling completes, the elapsed time is logged via
|
|
125
|
+
* [`core::susee_log::bundle_time`].
|
|
126
|
+
*
|
|
127
|
+
* # Panics
|
|
128
|
+
*
|
|
129
|
+
* Panics if [`bundler`] returns an error, printing the message
|
|
130
|
+
* `"Error when bundling"` in magenta before unwinding.
|
|
131
|
+
*/
|
|
132
|
+
export declare function suseeBundler(entry: string): string
|
|
133
|
+
|
|
134
|
+
/** The raw susee config, mirroring `SuSeeConfig`. */
|
|
135
|
+
export interface SuSeeConfig {
|
|
136
|
+
entryPoints: Array<EntryPoint>
|
|
137
|
+
outDir?: string
|
|
138
|
+
allowUpdatePackageJson?: boolean
|
|
139
|
+
minify?: boolean
|
|
140
|
+
}
|