susee 0.1.1 → 0.1.2

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
@@ -1,128 +1,109 @@
1
1
  <div align="center">
2
- <img src="https://pub-d94f06e647584b8496cac0d43a6fecfb.r2.dev/susee/susee.webp" width="160" height="160" alt="susee" />
3
- <h1>susee</h1>
2
+ <img src="https://pub-d94f06e647584b8496cac0d43a6fecfb.r2.dev/susee/susee.webp" width="160" height="160" alt="susee" />
3
+ <h1>susee</h1>
4
4
  </div>
5
5
 
6
- A minimal bundler for TypeScript projects that emits CommonJS, ESM, and type declarations in one pass. It streamlines package exports and auto-updates `package.json`.
6
+ susee is a small TypeScript bundler that collates a package's local dependency tree, then emits compiled artifacts for ESM and/or CommonJS along with type definitions. It can also update `package.json` exports automatically for main and subpath exports.
7
7
 
8
- ## Features
9
-
10
- - Bundles a TypeScript entry with its dependency tree
11
- - Outputs CommonJS (.cjs) and ESM (.mjs) builds with type declarations
12
- - Auto-writes `package.json` fields (`main`, `module`, `types`, `exports`) and change `type` force to `module`.
13
- - You can create post-process hooks (sync/async) for code that bundled and transformed by Typescript API.
14
- - Limitations: Only supports esm entry and typescript extensions.
15
- - Does not remove exports from the entry file and does not bundle packages from `node_modules`.
8
+ **Key points**
9
+ - Produces ESM (`.mjs`) and/or CommonJS (`.cjs`) outputs and corresponding type files (`.d.mts` / `.d.cts`).
10
+ - Merges local dependency files into a single bundled input for the TypeScript compiler.
11
+ - Supports simple plugin hooks at multiple stages: `dependency`, `pre-process`, and `post-process`.
12
+ - When enabled, updates `package.json` fields (`type`, `main`, `module`, `types`, `exports`) for the main export and merges subpath exports.
16
13
 
17
14
  ## Installation
18
15
 
19
16
  ```bash
20
- npm i susee
17
+ npm install susee
21
18
  ```
22
19
 
23
20
  ## Usage
24
21
 
25
- `susee.config.ts` at root of project
22
+ CLI (global or npx):
23
+
24
+ ```bash
25
+ npx susee
26
+ ```
27
+
28
+ programmatic (exports):
26
29
 
27
30
  ```ts
28
- import type { SuSeeConfig } from "susee";
29
- import bannerTextHook from "@suseejs/banner-text";
31
+ import { susee } from "susee";
30
32
 
31
- const license = "/*! My Library */";
33
+ await susee();
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ Place a `susee.config.ts` at your project root. The config defines entry points and optional hooks.
39
+
40
+ Example `susee.config.ts`:
41
+
42
+ ```ts
43
+ import type { SuSeeConfig } from "susee";
32
44
 
33
- export default {
45
+ const config: SuSeeConfig = {
34
46
  entryPoints: [
35
47
  {
36
48
  entry: "src/index.ts",
37
49
  exportPath: ".",
38
- moduleType: "both",
50
+ format: "both", // "esm" | "commonjs" | "both"
51
+ renameDuplicates: true,
52
+ outDir: "dist",
39
53
  },
40
54
  ],
41
- postProcessHooks: [bannerTextHook(licenseText)],
42
- } as SuSeeConfig;
55
+ postProcessHooks: [], // optional plugins
56
+ allowUpdatePackageJson: true,
57
+ };
58
+
59
+ export default config;
43
60
  ```
44
61
 
45
- ### Bundle in terminal
62
+ Config summary:
63
+ - `entryPoints`: array of entry definitions
64
+ - `entry` — path to entry file (required)
65
+ - `exportPath` — `.` or a subpath like `./feature`
66
+ - `format` — `esm` | `commonjs` | `both` (defaults to `esm`)
67
+ - `tsconfigFilePath` — optional custom tsconfig for that entry
68
+ - `renameDuplicates` — whether to auto-rename duplicate identifiers
69
+ - `outDir` — where compiled files will be written (e.g. `dist`)
70
+ - `postProcessHooks` — array of `post-process` plugins (sync or async)
71
+ - `allowUpdatePackageJson` — when true, `package.json` is updated with produced entry points
46
72
 
47
- ```bash
48
- npx susee
49
- ```
73
+ ## Plugins
50
74
 
51
- ### `package.json`
75
+ Plugins in the ecosystem have three common types:
76
+ - `dependency` — transform dependency list before bundling
77
+ - `pre-process` — modify the joined bundle text before compilation
78
+ - `post-process` — modify emitted output files
52
79
 
53
- ```json
54
- {
55
- "scripts": {
56
- "build": "susee"
57
- }
58
- }
59
- ```
80
+ Plugins may be provided as objects or factories (functions returning the plugin). They may be synchronous or async — the bundler handles both.
60
81
 
61
- ## Configuration for Susee Bundler
82
+ ## package.json updates
62
83
 
63
- ```ts
64
- interface EntryPoint {
65
- /**
66
- * Entry of file path of package
67
- *
68
- * required
69
- */
70
- entry: string;
71
- /**
72
- * Export path for package
73
- *
74
- * required
75
- */
76
- exportPath: "." | `./${string}`;
77
- /**
78
- * Output module type of package , commonjs,esm or both esm and commonjs
79
- *
80
- * default - esm
81
- */
82
- moduleType?: "commonjs" | "esm" | "both";
83
- /**
84
- * Custom tsconfig.json path for package typescript compiler options
85
- *
86
- * Priority -
87
- * 1. this custom tsconfig.json
88
- * 2. tsconfig.json at root directory
89
- * 3. default compiler options of susee
90
- *
91
- * default - undefined
92
- */
93
- tsconfigFilePath?: string | undefined;
94
- }
95
-
96
- /**
97
- * Configuration for Susee Bundler
98
- */
99
- interface SuSeeConfig {
100
- /**
101
- * Array of entry points object
102
- *
103
- * required
104
- */
105
- entryPoints: EntryPoint[];
106
- /**
107
- * Array of hooks to handle bundled and compiled code
108
- *
109
- * default - []
110
- */
111
- postProcessHooks?: SuSee.PostProcessHook[];
112
- /**
113
- * Allow bundler to update your package.json.
114
- *
115
- * default - true
116
- */
117
- allowUpdatePackageJson?: boolean;
118
- /**
119
- * Your package run on NodeJs env or not
120
- *
121
- * default - true
122
- */
123
- nodeEnv?: boolean;
124
- renameDuplicates?: boolean;
125
- }
84
+ When `allowUpdatePackageJson` is enabled, susee will:
85
+ - set `type` to `module` (to ensure ESM compatibility)
86
+ - add/update `main`, `module`, `types` and `exports` for the main export when building the package root
87
+ - merge subpath exports for non-root `exportPath`s without overwriting unrelated exports
88
+
89
+ Output file name hints (produced by the compiler):
90
+ - ESM JS -> `.mjs`
91
+ - ESM types -> `.d.mts`
92
+ - CJS JS -> `.cjs`
93
+ - CJS types -> `.d.cts`
94
+
95
+ ## Limitations & notes
96
+ - The bundler only processes local TypeScript files and does not bundle `node_modules` packages.
97
+ - The entry file should be an ESM-compatible TypeScript file.
98
+ - Exports from the entry file are not removed — only dependency exports may be stripped during bundling.
99
+
100
+ ## Contributing and tests
101
+
102
+ - Build and run tests with the repo scripts (see `package.json`):
103
+
104
+ ```bash
105
+ npm run build
106
+ npm test
126
107
  ```
127
108
 
128
109
  ## License
package/bin/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import { susee } from "../dist/index.mjs";
2
+ import {susee} from "../dist/index.mjs";
3
3
  await susee();