susee 1.5.0 → 1.5.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/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright [yyyy] [name of copyright owner]
189
+ Copyright 2025 Pho Thin Maung
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -6,53 +6,120 @@
6
6
  </div>
7
7
  <!-- markdownlint-enable MD033 -->
8
8
 
9
- [![npm version](https://img.shields.io/npm/v/susee)](https://www.npmjs.com/package/susee) [![license](https://img.shields.io/npm/l/susee)](LICENSE) [![Socket Badge](https://badge.socket.dev/npm/package/susee/1.0.1)](https://badge.socket.dev/npm/package/susee/1.0.1) [![codecov](https://codecov.io/gh/phothinmg/susee/graph/badge.svg?token=6240Y3L0V1)](https://codecov.io/gh/phothinmg/susee)
9
+ [![NPM][nodei_img]][nodei_url]
10
10
 
11
- ## Overview
11
+ [![npm version][npm_v_img]][npm_v_url] [![license][license_img]](LICENSE) [![Socket Badge][sb_img]][sb_url] [![codecov][codecov_img]][codecov_url]
12
12
 
13
- Susee is a simple TypeScript bundler for library packages.
13
+ TypeScript-first bundler for library packages.
14
14
 
15
- It reads your project entry points from `susee.config.*`, builds a dependency graph,
16
- bundles each entry into a single source unit, and compiles outputs to ESM and/or CommonJS
17
- with declaration files.
15
+ Susee can be used in two ways:
18
16
 
19
- ### What It Does
17
+ 1. Programmatic API from `susee` (`build(options?)`)
18
+ 2. CLI (`susee`, `susee init`, `susee build ...`)
20
19
 
21
- - Loads config from one of:
22
- - `susee.config.ts`
23
- - `susee.config.js`
24
- - `susee.config.mjs`
25
- - Resolves dependencies from each configured `entry`.
26
- - Validates code with TypeScript before bundling.
27
- - Bundles dependency files + entry file in dependency order.
28
- - Compiles to:
29
- - ESM (`.mjs`, `.d.mts`, source maps)
30
- - CommonJS (`.cjs`, `.d.cts`, source maps)
31
- - Optionally updates `package.json` fields (`main`, `module`, `types`, `exports`).
20
+ The sections below are based on the code in `src`.
32
21
 
33
- ### Current Constraints
22
+ ## Install
34
23
 
35
- - CommonJS dependencies inside the source graph are rejected unless handled by a plugin.
36
- - JSX/TSX dependencies are currently rejected.
37
- - CLI supports only:
38
- - `susee`
39
- - `susee --init`
24
+ ```bash
25
+ npm i -D susee
26
+ ```
27
+
28
+ ## Quick Start (CLI)
40
29
 
41
- ## Installation
30
+ 1. Generate config:
42
31
 
43
32
  ```bash
44
- npm i -D susee typescript
33
+ npx susee init
34
+ ```
35
+
36
+ <!-- markdownlint-disable MD029 -->
37
+
38
+ 2. Build using config:
39
+
40
+ ```bash
41
+ npx susee
45
42
  ```
46
43
 
47
- ## Quick Start
44
+ ## API Quick Reference
45
+
46
+ | Surface | Command / API | Purpose | Defaults |
47
+ | ------------ | -------------------------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
48
+ | Programmatic | `build(options?)` | Build from provided options or discovered config file | Exits with code 1 when options and config are both missing |
49
+ | CLI | `susee` | Build using `susee.config.ts/js/mjs` in project root | Uses resolved config |
50
+ | CLI | `susee init` | Create config template in project root | Prompts for TypeScript project |
51
+ | CLI | `susee build <entry> [options]` | Build a single entry directly from CLI args | `--outdir dist`, `--format esm`, `--rename true`, `--allow-update false`, `--minify false`, `--warning false` |
52
+ | Config | `entryPoints[].format` | Output module format(s) | `["esm"]` |
53
+ | Config | `entryPoints[].renameDuplicates` | Rename duplicate declarations | `true` |
54
+ | Config | `entryPoints[].tsconfigFilePath` | Custom tsconfig path | `undefined` |
55
+ | Config | `entryPoints[].plugins` | Post-process plugin list | `[]` |
56
+ | Config | `outDir` | Root output directory | `"dist"` |
57
+ | Config | `allowUpdatePackageJson` | Update package fields based on output | `false` |
58
+
59
+ ## CLI Usage
60
+
61
+ ```txt
62
+ Susee CLI.
63
+
64
+ Usage:
65
+ susee Build using susee.config.{ts,js,mjs}
66
+ susee init Generate susee.config.{ts,js,mjs}
67
+ susee --help Show this message
68
+ susee build <entry> [options] Build from a single entry file
69
+ ```
70
+
71
+ ### CLI Options
72
+
73
+ ```txt
74
+ --entry <path> Entry file (optional if provided as positional <entry>)
75
+ --outdir <path> Output directory (default: dist)
76
+ --format <cjs|commonjs|esm> Output format (default: esm)
77
+ --tsconfig <path> Custom tsconfig path
78
+ --rename[=true|false] Rename duplicate declarations (default: true)
79
+ --allow-update[=true|false] Allow package.json updates (default: false)
80
+ --minify[=true|false] Minify output (default: false)
81
+ --warning[=true|false] Enable warnings (default: false)
82
+ ```
48
83
 
49
- 1. Create config:
84
+ ### CLI Examples
50
85
 
51
86
  ```bash
52
- npx susee --init
87
+ npx susee build src/index.ts --outdir dist
88
+ npx susee build src/index.ts --format commonjs
89
+ npx susee build --entry src/index.ts --format esm --minify
53
90
  ```
54
91
 
55
- 1. Edit `susee.config.ts`:
92
+ ## Config File
93
+
94
+ Supported config filenames at project root:
95
+
96
+ 1. `susee.config.ts`
97
+ 2. `susee.config.js`
98
+ 3. `susee.config.mjs`
99
+
100
+ ### `SuSeeConfig` shape
101
+
102
+ ```ts
103
+ type OutputFormat = ("commonjs" | "esm")[];
104
+
105
+ interface EntryPoint {
106
+ entry: string;
107
+ exportPath: "." | `./${string}`;
108
+ format?: OutputFormat; // default: ["esm"]
109
+ tsconfigFilePath?: string | undefined; // default: undefined
110
+ renameDuplicates?: boolean; // default: true
111
+ plugins?: unknown[]; // default: []
112
+ warning?: boolean; // default: false
113
+ }
114
+
115
+ interface SuSeeConfig {
116
+ entryPoints: EntryPoint[];
117
+ outDir?: string; // default: "dist"
118
+ allowUpdatePackageJson?: boolean; // default: false
119
+ }
120
+ ```
121
+
122
+ ### Example `susee.config.ts`
56
123
 
57
124
  ```ts
58
125
  import type { SuSeeConfig } from "susee";
@@ -66,106 +133,84 @@ const config: SuSeeConfig = {
66
133
  },
67
134
  ],
68
135
  outDir: "dist",
69
- allowUpdatePackageJson: true,
136
+ allowUpdatePackageJson: false,
70
137
  };
71
138
 
72
139
  export default config;
73
140
  ```
74
141
 
75
- 1. Run build:
76
-
77
- ```bash
78
- npx susee
79
- ```
80
-
81
- ## Config Reference
82
-
83
- `SuSeeConfig`
142
+ ## Programmatic API
84
143
 
85
144
  ```ts
86
- interface SuSeeConfig {
87
- entryPoints: EntryPoint[];
88
- outDir?: string; // default: "dist"
89
- plugins?: (SuseePlugin | SuseePluginFunction)[]; // default: []
90
- allowUpdatePackageJson?: boolean; // default: false
91
- }
92
- ```
93
-
94
- `EntryPoint`
145
+ import { build, type SuSeeConfig } from "susee";
95
146
 
96
- ```ts
97
- type OutputFormat = ("commonjs" | "esm")[];
147
+ const options: SuSeeConfig = {
148
+ entryPoints: [
149
+ {
150
+ entry: "src/index.ts",
151
+ exportPath: ".",
152
+ format: ["esm", "commonjs"],
153
+ },
154
+ ],
155
+ };
98
156
 
99
- interface EntryPoint {
100
- entry: string;
101
- exportPath: "." | `./${string}`;
102
- format?: OutputFormat; // default: ["esm"]
103
- tsconfigFilePath?: string;
104
- renameDuplicates?: boolean; // default: true
105
- }
157
+ await build(options);
106
158
  ```
107
159
 
108
- ### Entry Validation Rules
160
+ Behavior of `build(options?)`:
109
161
 
110
- - At least one `entryPoint` is required.
111
- - Duplicate `exportPath` values are rejected.
112
- - Each `entry` file must exist.
162
+ 1. If `options` is provided, Susee builds from that object.
163
+ 2. If `options` is omitted, Susee tries to load a config file from root.
164
+ 3. If both are missing, Susee prints an error and exits with code `1`.
113
165
 
114
- ### TypeScript Options Behavior
166
+ ## Output Notes
115
167
 
116
- For each entry point, Susee builds compiler options from:
168
+ For an entry like `src/index.ts` with both formats enabled, output includes:
117
169
 
118
- 1. `tsconfigFilePath` (if provided)
119
- 2. project `tsconfig.json`
120
- 3. Susee defaults
170
+ 1. ESM: `dist/index.mjs`
171
+ 2. CommonJS: `dist/index.cjs`
172
+ 3. Sourcemaps: `.mjs.map` and `.cjs.map`
121
173
 
122
- Susee enforces/adjusts key options internally:
174
+ Declaration files are emitted by the compiler when available.
123
175
 
124
- - `moduleResolution: "NodeNext"`
125
- - `allowJs: true`
126
- - `outDir` set per entry output path
127
- - ensures `types` includes `node`
128
- - ensures `lib` includes `ESNext`
176
+ ## Build Output Matrix
129
177
 
130
- ## Plugin Hooks
178
+ | Input | Output Directory Rule | ESM Files | CommonJS Files |
179
+ | -------------------------------------------- | --------------------- | ------------------------------------------- | ------------------------------------------- |
180
+ | `entry: "src/index.ts"`, `exportPath: "."` | `<outDir>` | `index.mjs`, `index.mjs.map`, `index.d.mts` | `index.cjs`, `index.cjs.map`, `index.d.cts` |
181
+ | `entry: "src/foo.ts"`, `exportPath: "./foo"` | `<outDir>/foo` | `foo.mjs`, `foo.mjs.map`, `foo.d.mts` | `foo.cjs`, `foo.cjs.map`, `foo.d.cts` |
131
182
 
132
- Susee supports plugin stages used in the pipeline:
183
+ Notes:
133
184
 
134
- - `dependency`
135
- - receives resolved dependency files and compiler options
136
- - can transform dependency metadata/content before bundling
137
- - `pre-process`
138
- - receives bundled code (string) before compilation
139
- - `post-process`
140
- - receives emitted JS file content per output file
185
+ 1. Default `outDir` is `dist` when not set.
186
+ 2. For subpath exports, output directory is computed as `outDir + exportPath.slice(1)`.
187
+ 3. Declarations (`.d.mts` / `.d.cts`) are emitted when provided by the underlying compiler result.
141
188
 
142
- Both sync and async plugins are supported.
189
+ ## Package.json Update Matrix
143
190
 
144
- ## Output Behavior
191
+ When `allowUpdatePackageJson` (config) or `--allow-update` (CLI build) is enabled, Susee can update package fields.
145
192
 
146
- - `format: ["esm"]`
147
- - emits `.mjs` and `.d.mts`
148
- - `format: ["commonjs"]`
149
- - emits `.cjs` and `.d.cts`
150
- - `format: ["esm", "commonjs"]`
151
- - emits both sets
193
+ | Context | Condition | Updated Fields | Observed Result |
194
+ | -------------------- | --------------------------------------------- | --------------------------- | ----------------------------------------------------------- |
195
+ | Main export build | `exportPath: "."` with ESM + CommonJS outputs | `main`, `module` | `main: "dist/index.cjs"`, `module: "dist/index.mjs"` |
196
+ | Main export build | `exportPath: "."` with declarations | `types` | Set from generated CommonJS declaration path when available |
197
+ | Subpath export build | `exportPath: "./foo"` | `exports` (subpath mapping) | Currently remains `{}` in tested behavior |
152
198
 
153
- When `allowUpdatePackageJson` is `true`, Susee can update:
199
+ Notes:
154
200
 
155
- - `type` (set to `module`)
156
- - `main`
157
- - `module`
158
- - `types`
159
- - `exports` (including subpath exports from `exportPath`)
201
+ 1. Package update requires a `package.json` file in the project root.
202
+ 2. With update disabled, package fields are left unchanged.
203
+ 3. Existing tests in this repo currently assert `exports` remains `{}` for the tested update flows.
160
204
 
161
- ## CLI
205
+ ## Validation Rules
162
206
 
163
- ```bash
164
- susee
165
- susee --init
166
- ```
207
+ From config validation logic:
208
+
209
+ 1. At least one `entryPoints` item is required.
210
+ 2. Duplicate `exportPath` values are rejected.
211
+ 3. Each `entry` path must exist.
167
212
 
168
- Any other argument combination exits with an error.
213
+ Violations print an error and exit with code `1`.
169
214
 
170
215
  ## License
171
216
 
@@ -174,4 +219,20 @@ Any other argument combination exits with an error.
174
219
  <!-- markdownlint-disable MD053 -->
175
220
 
176
221
  [license]: LICENSE
177
- [ptm]: https://github.com/phothinmg
222
+ [file-contribute]: CONTRIBUTING.md
223
+ [ptm]: https://github.com/phothinmg
224
+
225
+ <!-- Need to update version -->
226
+
227
+ [sb_img]: https://badge.socket.dev/npm/package/susee/1.5.1
228
+ [sb_url]: https://badge.socket.dev/npm/package/susee/1.5.1
229
+
230
+ <!-- -->
231
+
232
+ [codecov_img]: https://codecov.io/gh/phothinmg/susee/graph/badge.svg?token=6240Y3L0V1
233
+ [codecov_url]: https://codecov.io/gh/phothinmg/susee
234
+ [nodei_img]: https://nodei.co/npm/susee.svg?color=red
235
+ [nodei_url]: https://nodei.co/npm/susee/
236
+ [npm_v_img]: https://img.shields.io/npm/v/susee
237
+ [npm_v_url]: https://www.npmjs.com/package/susee
238
+ [license_img]: https://img.shields.io/npm/l/susee
package/bin/susee ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import("../dist/bin/index.mjs");
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import fs from"node:fs";import path from"node:path";import process from"node:process";import readline from"node:readline/promises";import tcolor from"@suseejs/color";import ts from"typescript";import{bundler}from"@suseejs/bundler";import{files}from"@suseejs/files";import{getCompilerOptions}from"@suseejs/tsoptions";import{suseeCompiler}from"@suseejs/compiler";import{suseeTerser}from"@suseejs/terser-plugin";const getConfigPath=()=>{const e=["susee.config.ts","susee.config.js","susee.config.mjs"];let t;for(const s of e){const e=ts.sys.resolvePath(s);if(ts.sys.fileExists(e)){t=e;break}}return t};function checkEntries(e){e.length<1&&(console.error(tcolor.magenta("No entry found in susee.config file or build options, at least one entry required")),ts.sys.exit(1));const t={},s=[];for(const n of e){const e=n.exportPath;t[e]?s.push(`"${e}"`):t[e]=!0}s.length>0&&(console.error(tcolor.magenta(`Duplicate export paths/path (${s.join(",")}) found in your susee.config file or build options , that will error for bundled output`)),ts.sys.exit(1));for(const t of e)ts.sys.fileExists(ts.sys.resolvePath(t.entry))||(console.error(tcolor.magenta(`Entry file ${t.entry} dose not exists.`)),ts.sys.exit(1))}function generateBuildOptions(e){const t=e.outDir??"dist",s=[];checkEntries(e.entryPoints);for(const n of e.entryPoints){const e=n.entry,i=n.exportPath,o=n.tsconfigFilePath??void 0,a=n.format?[...new Set(n.format)]:["esm"],l=n.warning??!1,r=n.renameDuplicates??!0,c=n.plugins??[],f="."===n.exportPath?t:`${t}${n.exportPath.slice(1)}`;s.push({entry:e,exportPath:i,format:a,tsconfigFilePath:o,rename:r,plugins:c,warning:l,outputDirectoryPath:f})}return{buildEntryPoints:s,updatePackage:e.allowUpdatePackageJson??!1,outDir:t}}async function finalSuseeConfig(){const e=getConfigPath();if(e){return generateBuildOptions((await import(e)).default)}}class Compiler{_files;_object;constructor(e){this._object=e,this._files={commonjs:void 0,commonjsTypes:void 0,esm:void 0,esmTypes:void 0,main:void 0,module:void 0,types:void 0}}_update(){return this._object.updatePackage}async _commonjs(e){const t="."===e.exportPath,s=getCompilerOptions(e.tsconfigFilePath).commonjs(e.outputDirectoryPath),n=await bundler(e.entry,e.plugins,e.warning,e.rename),i=suseeCompiler({sourceCode:n,fileName:e.entry,compilerOptions:s});let o=i.code;const a=files.joinPath(i.out_dir,`${i.file_name}.cjs`),l=files.joinPath(i.out_dir,`${i.file_name}.d.cts`),r=files.joinPath(i.out_dir,`${i.file_name}.cjs.map`);if(o=o.replace(new RegExp(`${i.file_name}.js.map`,"gm"),`${i.file_name}.cjs.map`),e.plugins.length>0)for(const t of e.plugins){const s="function"==typeof t?t():t;"post-process"===s.type&&(o=s.async?await s.func(o,e.entry):s.func(o,e.entry))}this._update()&&(this._files.commonjs=a,i.dts&&(this._files.commonjsTypes=l),t&&e.format.includes("commonjs")&&(this._files.commonjs&&(this._files.main=this._files.commonjs),this._files.commonjsTypes&&(this._files.types=this._files.commonjsTypes))),await files.writeFile(a,o),i.dts&&await files.writeFile(l,i.dts),i.map&&await files.writeFile(r,i.map)}async _esm(e){const t="."===e.exportPath,s=getCompilerOptions(e.tsconfigFilePath).esm(e.outputDirectoryPath),n=await bundler(e.entry,e.plugins,e.warning,e.rename),i=suseeCompiler({sourceCode:n,fileName:e.entry,compilerOptions:s});let o=i.code;const a=files.joinPath(i.out_dir,`${i.file_name}.mjs`),l=files.joinPath(i.out_dir,`${i.file_name}.d.mts`),r=files.joinPath(i.out_dir,`${i.file_name}.mjs.map`);if(o=o.replace(new RegExp(`${i.file_name}.js.map`,"gm"),`${i.file_name}.mjs.map`),e.plugins.length>0)for(const t of e.plugins){const s="function"==typeof t?t():t;"post-process"===s.type&&(o=s.async?await s.func(o,e.entry):s.func(o,e.entry))}this._update()&&(this._files.esm=a,i.dts&&(this._files.esmTypes=l),t&&this._files.esm&&(this._files.module=this._files.esm)),await files.writeFile(a,o),i.dts&&await files.writeFile(l,i.dts),i.map&&await files.writeFile(r,i.map)}async compile(){await files.clearFolder(this._object.outDir);for(const e of this._object.buildEntryPoints)for(const t of e.format)switch(t){case"commonjs":await this._commonjs(e),this._update()&&files.writePackageJson(this._files,e.exportPath);break;case"esm":await this._esm(e),this._update()&&files.writePackageJson(this._files,e.exportPath)}}}async function cliBuild(){console.time(tcolor.cyan("[Build] "));const e=await finalSuseeConfig();e||(console.error(tcolor.magenta('No susee.config file ("susee.config.ts", "susee.config.js", "susee.config.mjs") found')),ts.sys.exit(1));const t=new Compiler(e);await t.compile(),console.timeEnd(tcolor.cyan("[Build] "))}function fail(e){console.error(`${tcolor.magenta("[Error]")} : ${tcolor.gray(e)}`),process.exit(1)}function isFile(e){return[".js",".ts",".mts",".mjs",".cjs",".cts"].includes(path.extname(e))}function isEmptyObject(e){return"object"==typeof e&&!Array.isArray(e)&&0===Object.keys(e).length}function parseBooleanFlag(e,t){return"true"===t||"false"!==t&&void fail(`Type of ${e} must be boolean.`)}function parseArgs(e){const t={entry:""};for(let s=0;s<e.length;s+=1){const n=e[s];if(0===s&&!n.startsWith("--")&&isFile(n)){t.entry=n;continue}const[i,o]=n.split("=",2),a=e[s+1],l=o??a;switch(i){case"--entry":l&&!l.startsWith("--")||fail("Entry point required."),""!==t.entry&&isFile(t.entry)&&fail("Entry point already exists."),t.entry=l,void 0===o&&(s+=1);break;case"--outdir":l&&!l.startsWith("--")||fail("Output directory required."),t.outDir=l,void 0===o&&(s+=1);break;case"--format":"cjs"!==l&&"commonjs"!==l&&"esm"!==l&&fail("Format must be cjs, commonjs, or esm."),t.format="cjs"===l?"commonjs":l,void 0===o&&(s+=1);break;case"--tsconfig":l&&!l.startsWith("--")||fail("Tsconfig path required."),t.tsconfig=l,void 0===o&&(s+=1);break;case"--rename":void 0!==o?t.rename=parseBooleanFlag("rename",o):"true"===a||"false"===a?(t.rename=parseBooleanFlag("rename",a),s+=1):t.rename=!0;break;case"--allow-update":void 0!==o?t.allowUpdate=parseBooleanFlag("allow update",o):"true"===a||"false"===a?(t.allowUpdate=parseBooleanFlag("allow update",a),s+=1):t.allowUpdate=!0;break;case"--minify":void 0!==o?t.minify=parseBooleanFlag("minify",o):"true"===a||"false"===a?(t.minify=parseBooleanFlag("minify",a),s+=1):t.minify=!0;break;case"--warning":void 0!==o?t.warning=parseBooleanFlag("warning",o):"true"===a||"false"===a?(t.warning=parseBooleanFlag("warning",a),s+=1):t.warning=!0}}return(isEmptyObject(t)||""===t.entry)&&fail("Entry point required"),t}function getDefaultOptions(e){return{entry:e.entry,outDir:e.outDir??"dist",format:e.format??"esm",tsconfig:e.tsconfig??void 0,rename:e.rename??!0,allowUpdate:e.allowUpdate??!1,minify:e.minify??!1,warning:e.warning??!1,plugins:[]}}class CliCompiler{_files;_update;constructor(){this._files={commonjs:void 0,commonjsTypes:void 0,esm:void 0,esmTypes:void 0,main:void 0,module:void 0,types:void 0},this._update=!1}async _commonjs(e){this._update=e.allowUpdate;const t=getCompilerOptions(e.tsconfig).commonjs(e.outDir),s=await bundler(e.entry,e.plugins,e.warning,e.rename),n=suseeCompiler({sourceCode:s,fileName:e.entry,compilerOptions:t});let i=n.code;const o=files.joinPath(n.out_dir,`${n.file_name}.cjs`),a=files.joinPath(n.out_dir,`${n.file_name}.d.cts`),l=files.joinPath(n.out_dir,`${n.file_name}.cjs.map`);if(i=i.replace(new RegExp(`${n.file_name}.js.map`,"gm"),`${n.file_name}.cjs.map`),e.minify&&(e.plugins=[suseeTerser,...e.plugins],e.plugins=[...new Set(e.plugins)]),e.plugins.length>0)for(const t of e.plugins){const s="function"==typeof t?t():t;"post-process"===s.type&&(i=s.async?await s.func(i,e.entry):s.func(i,e.entry))}this._update&&(this._files.commonjs=o,n.dts&&(this._files.commonjsTypes=a),e.format.includes("commonjs")&&(this._files.commonjs&&(this._files.main=this._files.commonjs),this._files.commonjsTypes&&(this._files.types=this._files.commonjsTypes))),await files.writeFile(o,i),n.dts&&await files.writeFile(a,n.dts),n.map&&await files.writeFile(l,n.map)}async _esm(e){this._update=e.allowUpdate;const t=getCompilerOptions(e.tsconfig).esm(e.outDir),s=await bundler(e.entry,e.plugins,e.warning,e.rename),n=suseeCompiler({sourceCode:s,fileName:e.entry,compilerOptions:t});let i=n.code;const o=files.joinPath(n.out_dir,`${n.file_name}.mjs`),a=files.joinPath(n.out_dir,`${n.file_name}.d.mts`),l=files.joinPath(n.out_dir,`${n.file_name}.mjs.map`);if(i=i.replace(new RegExp(`${n.file_name}.js.map`,"gm"),`${n.file_name}.mjs.map`),e.minify&&(e.plugins=[suseeTerser,...e.plugins],e.plugins=[...new Set(e.plugins)]),e.plugins.length>0)for(const t of e.plugins){const s="function"==typeof t?t():t;"post-process"===s.type&&(i=s.async?await s.func(i,e.entry):s.func(i,e.entry))}this._update&&(this._files.esm=o,n.dts&&(this._files.esmTypes=a),this._files.esm&&(this._files.module=this._files.esm)),await files.writeFile(o,i),n.dts&&await files.writeFile(a,n.dts),n.map&&await files.writeFile(l,n.map)}async compile(e){switch(await files.clearFolder(e.outDir),e.format){case"commonjs":await this._commonjs(e),this._update&&files.writePackageJson(this._files,".");break;case"esm":await this._esm(e),this._update&&files.writePackageJson(this._files,".")}}}const cliCompiler=new CliCompiler;function printHelp(){console.log("Susee CLI.\n\nUsage:\n susee Build using susee.config.{ts,js,mjs}\n susee init Generate susee.config.{ts,js,mjs}\n susee --help Show this message\n susee build <entry> [options] Build from a single entry file\n\nOptions:\n --entry <path> Entry file (optional if provided as positional <entry>)\n --outdir <path> Output directory\n --format <cjs|commonjs|esm> Output module format\n --tsconfig <path> Custom tsconfig path\n --rename[=true|false] Enable/disable renaming\n --allow-update[=true|false] Enable/disable dependency update\n --minify[=true|false] Enable/disable minification\n\nExamples:\n susee build src/index.ts --outdir dist\n susee build src/index.ts --format commonjs\n susee build --entry src/index.ts --format esm --minify\n \n")}const tsFileText='\nimport type { SuSeeConfig } from "susee";\n\nconst config: SuSeeConfig = {\n // Array of entry point objects.\n // ----------------------------\n entryPoints: [\n // You can add more entry points for different export paths.\n // NOTE: duplicate export paths are not allowed.\n // --------------------------------------------\n {\n // (required) Entry file path.\n entry: "src/index.ts", // replace with your entry file\n // (required) Export path for this entry.\n exportPath: ".", // "." stands for the main export path and can be set to "./foo", "./bar", etc.\n // (optional) Output module formats ["commonjs"] or ["esm", "commonjs"], default: ["esm"].\n // Uncomment the following line to edit.\n //format: ["esm"],\n // (optional) Rename duplicate declarations, default: true.\n // Uncomment the following line to edit.\n //renameDuplicates: true,\n // (optional) Custom tsconfig.json path, default: undefined.\n // Uncomment the following line to edit.\n //tsconfigFilePath: undefined,\n // (optional) Array of susee plugins, default: [].\n // Uncomment the following line to edit.\n //plugins: [],\n // (optional) Warning messages, if it true and warning message exist(1), default: false.\n // Uncomment the following line to edit.\n //warning: false,\n },\n ],\n // NOTE: the following options apply to all entry points.\n // ----------------------------------------------------------\n // (optional) Output directory, default: dist.\n // Uncomment the following line to edit.\n //outDir: "dist",\n // (optional) Allow susee to update your package.json, default: false.\n // Uncomment the following line to edit.\n //allowUpdatePackageJson: false,\n};\n\nexport default config;\n'.trim(),jsFileText='\n/**\n * @type {import("susee").SuSeeConfig}\n */\nconst config = {\n // Array of entry point objects.\n // ----------------------------\n entryPoints: [\n // You can add more entry points for different export paths.\n // NOTE: duplicate export paths are not allowed.\n // --------------------------------------------\n {\n // (required) Entry file path.\n entry: "src/index.ts", // replace with your entry file\n // (required) Export path for this entry.\n exportPath: ".", // "." stands for the main export path and can be set to "./foo", "./bar", etc.\n // (optional) Output module formats ["commonjs"] or ["esm", "commonjs"], default: ["esm"].\n // Uncomment the following line to edit.\n //format: ["esm"],\n // (optional) Rename duplicate declarations, default: true.\n // Uncomment the following line to edit.\n //renameDuplicates: true,\n // (optional) Custom tsconfig.json path, default: undefined.\n // Uncomment the following line to edit.\n //tsconfigFilePath: undefined,\n // (optional) Array of susee plugins, default: [].\n // Uncomment the following line to edit.\n //plugins: [],\n // (optional) Warning messages, if it true and warning message exist(1), default: false.\n // Uncomment the following line to edit.\n //warning: false,\n },\n ],\n // NOTE: the following options apply to all entry points.\n // ----------------------------------------------------------\n // (optional) Output directory, default: dist.\n // Uncomment the following line to edit.\n //outDir: "dist",\n // (optional) Allow susee to update your package.json, default: false.\n // Uncomment the following line to edit.\n //allowUpdatePackageJson: false,\n};\n\nexport default config;\n'.trim();async function getPackageType(){const e=path.resolve(process.cwd(),"package.json"),t=await fs.promises.readFile(e,"utf8");return"module"===JSON.parse(t).type?"esm":"commonjs"}async function cliInit(){const e=readline.createInterface({input:process.stdin,output:process.stdout}),t=await e.question(tcolor.cyan("Is TypeScript project(y/n) : ")),s=!("y"!==t&&"Y"!==t&&""!==t);e.close();let n="",i="";if(s)n="susee.config.ts",i=tsFileText;else{i=jsFileText;switch(await getPackageType()){case"commonjs":n="susee.config.mjs";break;case"esm":n="susee.config.js"}}const o=path.resolve(process.cwd(),n);fs.existsSync(o)&&await fs.promises.unlink(o),await fs.promises.writeFile(o,i),console.info(tcolor.cyan(`Susee config file ${n} is created at project root`))}async function suseeCliBuild(){const e=process.argv.slice(2);if(0===e.length)await cliBuild();else if(1===e.length)"--help"===e[0]&&printHelp(),"init"===e[0]&&await cliInit(),"build"===e[0]&&printHelp();else if(e.length>1&&"build"===e[0]&&("--help"===e[1]||"-h"===e[1]))printHelp();else if(e.length>1&&"build"===e[0]){const t=getDefaultOptions(parseArgs(e.slice(1)));await cliCompiler.compile(t)}else console.error("Unknown CLI usage"),process.exit(1)}suseeCliBuild().catch(e=>{console.error(e),process.exit(1)});
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,MAAM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,CAAC;SACI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QACpB,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO;QACnB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC;QAC7C,SAAS,EAAE,CAAC;IAChB,CAAC;SACI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;QAC9C,MAAM,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,OAAO,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;QACtC,MAAM,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;SACI,CAAC;QACF,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC;AACD,KAAK,aAAa,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACjC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
package/dist/index.cjs CHANGED
@@ -5,4 +5,4 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
5
5
  this file except in compliance with the License. You may obtain a copy of the
6
6
  License at http://www.apache.org/licenses/LICENSE-2.0
7
7
  ***************************************************************************** */
8
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,s,a)}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var s=e(t),a=0;a<s.length;a++)"default"!==s[a]&&__createBinding(i,t,s[a]);return __setModuleDefault(i,t),i}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.susee=susee;const tsconfig_1=__importDefault(require("@suseejs/tsconfig")),node_fs_1=__importDefault(require("node:fs")),mhaehko_1=__importDefault(require("mhaehko")),node_path_1=__importDefault(require("node:path")),node_process_1=__importDefault(require("node:process")),resolves_1=__importDefault(require("@suseejs/resolves")),tcolor_1=__importDefault(require("@suseejs/tcolor")),transformer_1=__importDefault(require("@suseejs/transformer")),typescript_1=__importDefault(require("typescript")),utils_1=__importDefault(require("@suseejs/utils")),node_buffer_1=require("node:buffer"),getConfigPath=()=>{const e=["susee.config.ts","susee.config.js","susee.config.mjs"];let t;for(const i of e){const e=typescript_1.default.sys.resolvePath(i);if(typescript_1.default.sys.fileExists(e)){t=e;break}}return t};function checkEntries(e){e.length<1&&(console.error(tcolor_1.default.magenta("No entry found in susee.config file, at least one entry required")),typescript_1.default.sys.exit(1));const t={},i=[];for(const s of e){const e=s.exportPath;t[e]?i.push(`"${e}"`):t[e]=!0}i.length>0&&(console.error(tcolor_1.default.magenta(`Duplicate export paths/path (${i.join(",")}) found in your susee.config file , that will error for bundled output`)),typescript_1.default.sys.exit(1));for(const t of e)typescript_1.default.sys.fileExists(typescript_1.default.sys.resolvePath(t.entry))||(console.error(tcolor_1.default.magenta(`Entry file ${t.entry} dose not exists.`)),typescript_1.default.sys.exit(1))}async function finalSuseeConfig(){const e=getConfigPath();void 0===e&&(console.error(tcolor_1.default.magenta('No susee.config file ("susee.config.ts", "susee.config.js", "susee.config.mjs") found')),typescript_1.default.sys.exit(1));const t=(await Promise.resolve(`${e}`).then(e=>__importStar(require(e)))).default,i=(0,resolves_1.default)([[checkEntries,t.entryPoints]]);await i.series();const s=t.outDir??"dist",a=[];for(const e of t.entryPoints){const t={entry:e.entry,exportPath:e.exportPath,format:e.format??["esm"],tsconfigFilePath:e.tsconfigFilePath??void 0,renameDuplicates:e.renameDuplicates??!0,outDirPath:"."===e.exportPath?s:`${s}${e.exportPath.slice(1)}`};a.push(t)}return{points:a,plugins:t.plugins??[],allowUpdatePackageJson:t.allowUpdatePackageJson??!1,outDir:s}}class CompilerOptions{constructor(e){this._point=e,this._options={}}__init(){const e=new tsconfig_1.default(this._point.tsconfigFilePath);e.removeCompilerOption("rootDir"),e.removeCompilerOption("module"),e.editCompilerOptions({moduleResolution:typescript_1.default.ModuleResolutionKind.NodeNext,outDir:this._point.outDirPath,allowJs:!0}),this._options=e.getCompilerOptions()}__init2(){this.__init();let{types:e,lib:t,...i}=this._options;return e?e.includes("node")||(e=["node",...e]):e=["node"],t=t?[...new Set(["ESNext",...t])]:["ESNext"],{types:e,lib:t,...i}}get commonjs(){const e=this.__init2(),{module:t,...i}=e;return{module:typescript_1.default.ModuleKind.CommonJS,...i}}get esm(){const e=this.__init2(),{module:t,...i}=e;return{module:typescript_1.default.ModuleKind.ES2020,...i}}get default(){return this.__init2()}}function compilerOptions(e){return new CompilerOptions(e)}async function fileSizes(e){const t=await node_fs_1.default.promises.stat(e);return{logical:t.size,allocated:null!==t.blocks?512*t.blocks:null}}const checkExport=(e,t)=>!!(e.match(/export default .*/gm)||e.match(/export = .*/gm)&&t.match(/.cts/g));function isJsxContent(e){const t=typescript_1.default.createSourceFile("file.tsx",e,typescript_1.default.ScriptTarget.Latest,!0,typescript_1.default.ScriptKind.TSX);let i=!1;return function e(t){typescript_1.default.isJsxElement(t)||typescript_1.default.isJsxSelfClosingElement(t)||typescript_1.default.isJsxFragment(t)?i=!0:typescript_1.default.forEachChild(t,e)}(t),i}async function generateDependencies(e){const t=(await(0,mhaehko_1.default)(e)).sort(),i=[];for(const e of t){const t=typescript_1.default.sys.resolvePath(e),s=await node_fs_1.default.promises.readFile(t,"utf8"),a=node_path_1.default.extname(t),r=await fileSizes(t),n=s.length,o=checkExport(s,t),p=typescript_1.default.createSourceFile(t,s,typescript_1.default.ScriptTarget.Latest,!0),c=utils_1.default.check.moduleType(p,t).isCommonJs?"cjs":"esm",l={file:t,content:s,length:n,includeDefExport:o,size:{logical:r.logical,allocated:r.allocated,utf8:(new TextEncoder).encode(s).length,buffBytes:node_buffer_1.Buffer.byteLength(s,"utf8")},moduleType:c,fileExt:a,isJsx:isJsxContent(s)};i.push(l)}return i}function _typesCheck(e,t){if(!t.noCheck){const i=e.map(e=>e.file);let s=!1;const a=typescript_1.default.createProgram(i,t);for(const e of i){const t=a.getSourceFile(e);t||(console.error(tcolor_1.default.magenta(`File not found: ${e}`)),typescript_1.default.sys.exit(1));const i=[...a.getSyntacticDiagnostics(t),...a.getSemanticDiagnostics(t),...a.getDeclarationDiagnostics(t)];if(i.length>0){const e={getCurrentDirectory:()=>node_process_1.default.cwd(),getCanonicalFileName:e=>e,getNewLine:()=>typescript_1.default.sys.newLine};console.error(typescript_1.default.formatDiagnosticsWithColorAndContext(i,e)),s=!0}}if(!s)return!0;typescript_1.default.sys.exit(1)}}async function typeCheck(e,t){const i=(0,resolves_1.default)([[_typesCheck,e,t]]);return(await i.series())[0]}async function depPluginParser(e,t,i){if(t.length)for(const s of t){const t="function"==typeof s?s():s;"dependency"===t.type&&(e=t.async?await t.func(e,i):t.func(e,i))}return e}async function initializer(){const e=await finalSuseeConfig(),t=e.points,i=e.plugins,s=[];for(const e of t){const t=compilerOptions(e);let a=await generateDependencies(e.entry);await typeCheck(a,t.esm)||typescript_1.default.sys.exit(1),a=await depPluginParser(a,i,t.default);const r={fileName:e.entry,exportPath:e.exportPath,format:e.format,rename:e.renameDuplicates,outDir:e.outDirPath,tsOptions:{cjs:t.commonjs,esm:t.esm,default:t.default},depFiles:a,plugins:i};s.push(r)}return{points:s,allowUpdatePackageJson:e.allowUpdatePackageJson}}const exportDefaultExportNameMap=[],exportDefaultImportNameMap=[],prefixKey="AnonymousName",genName=utils_1.default.uniqueName().setPrefix({key:prefixKey,value:"__anonymous__"});function anonymousCallExpressionHandler(e){return({file:t,content:i,...s})=>{const a=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),r=(0,transformer_1.default)(e=>{const{factory:i}=e,s=a=>{if(typescript_1.default.isCallExpression(a)){if(typescript_1.default.isIdentifier(a.expression)){const e=a.expression.text,s=exportDefaultImportNameMap.find(i=>i.base===e&&i.file===t);if(s)return i.updateCallExpression(a,i.createIdentifier(s.newName),a.typeArguments,a.arguments)}}else if(typescript_1.default.isPropertyAccessExpression(a)){if(typescript_1.default.isIdentifier(a.expression)){const e=a.expression.text,s=exportDefaultImportNameMap.find(i=>i.base===e&&i.file===t);if(s)return i.updatePropertyAccessExpression(a,i.createIdentifier(s.newName),a.name)}}else if(typescript_1.default.isNewExpression(a)){if(typescript_1.default.isIdentifier(a.expression)){const e=a.expression.text,s=exportDefaultImportNameMap.find(i=>i.base===e&&i.file===t);if(s)return i.updateNewExpression(a,i.createIdentifier(s.newName),a.typeArguments,a.arguments)}}else if(typescript_1.default.isExportSpecifier(a)&&typescript_1.default.isIdentifier(a.name)){const e=a.name.text,s=exportDefaultImportNameMap.find(i=>i.base===e&&i.file===t);if(s)return i.updateExportSpecifier(a,a.isTypeOnly,a.propertyName,i.createIdentifier(s.newName))}return typescript_1.default.visitEachChild(a,s,e)};return e=>typescript_1.default.visitNode(e,s)},a,e);return{file:t,content:r,...s}}}function anonymousExportHandler(e){return({file:t,content:i,...s})=>{const a=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),r=(0,transformer_1.default)(e=>{const{factory:i}=e,s=r=>{const n=node_path_1.default.basename(t).split(".")[0];if((typescript_1.default.isFunctionDeclaration(r)||typescript_1.default.isClassDeclaration(r))&&void 0===r.name){let e=!1,t=!1;if(r.modifiers?.forEach(i=>{i.kind===typescript_1.default.SyntaxKind.ExportKeyword&&(e=!0),i.kind===typescript_1.default.SyntaxKind.DefaultKeyword&&(t=!0)}),e&&t){const e=genName.getName(prefixKey,n);if(exportDefaultExportNameMap.push({base:e,file:n,newName:e,isEd:!0}),typescript_1.default.isFunctionDeclaration(r))return i.updateFunctionDeclaration(r,r.modifiers,r.asteriskToken,i.createIdentifier(e),r.typeParameters,r.parameters,r.type,r.body);if(typescript_1.default.isClassDeclaration(r))return i.updateClassDeclaration(r,r.modifiers,i.createIdentifier(e),r.typeParameters,r.heritageClauses,r.members)}}else if(typescript_1.default.isExportAssignment(r)&&!r.name&&!r.isExportEquals){if(typescript_1.default.isArrowFunction(r.expression)){const e=genName.getName(prefixKey,n),t=i.createArrowFunction(r.expression.modifiers,r.expression.typeParameters,r.expression.parameters,r.expression.type,r.expression.equalsGreaterThanToken,r.expression.body),s=i.createVariableDeclaration(i.createIdentifier(e),r.expression.exclamationToken,r.expression.type,t),o=i.createVariableDeclarationList([s],typescript_1.default.NodeFlags.Const),p=i.createVariableStatement(r.expression.modifiers,o),c=i.createExportAssignment(void 0,void 0,i.createIdentifier(e));return exportDefaultExportNameMap.push({base:e,file:n,newName:e,isEd:!0}),i.updateSourceFile(a,[p,c],a.isDeclarationFile,a.referencedFiles,a.typeReferenceDirectives,a.hasNoDefaultLib,a.libReferenceDirectives)}if(typescript_1.default.isObjectLiteralExpression(r.expression)){const e=genName.getName(prefixKey,n),t=i.createVariableDeclaration(i.createIdentifier(e),void 0,void 0,r.expression),s=i.createVariableDeclarationList([t],typescript_1.default.NodeFlags.Const),o=i.createVariableStatement(void 0,s),p=i.createExportAssignment(void 0,void 0,i.createIdentifier(e));return exportDefaultExportNameMap.push({base:e,file:n,newName:e,isEd:!0}),i.updateSourceFile(a,[o,p],a.isDeclarationFile,a.referencedFiles,a.typeReferenceDirectives,a.hasNoDefaultLib,a.libReferenceDirectives)}if(typescript_1.default.isArrayLiteralExpression(r.expression)){const e=genName.getName(prefixKey,n),t=i.createArrayLiteralExpression(r.expression.elements,!0),s=i.createVariableDeclaration(i.createIdentifier(e),void 0,void 0,t),o=i.createVariableDeclarationList([s],typescript_1.default.NodeFlags.Const),p=i.createVariableStatement(void 0,o),c=i.createExportAssignment(void 0,void 0,i.createIdentifier(e));return exportDefaultExportNameMap.push({base:e,file:n,newName:e,isEd:!0}),i.updateSourceFile(a,[p,c],a.isDeclarationFile,a.referencedFiles,a.typeReferenceDirectives,a.hasNoDefaultLib,a.libReferenceDirectives)}if(typescript_1.default.isStringLiteral(r.expression)){const e=genName.getName(prefixKey,n),t=i.createStringLiteral(r.expression.text),s=i.createVariableDeclaration(i.createIdentifier(e),void 0,void 0,t),o=i.createVariableDeclarationList([s],typescript_1.default.NodeFlags.Const),p=i.createVariableStatement(void 0,o),c=i.createExportAssignment(void 0,void 0,i.createIdentifier(e));return exportDefaultExportNameMap.push({base:e,file:n,newName:e,isEd:!0}),i.updateSourceFile(a,[p,c],a.isDeclarationFile,a.referencedFiles,a.typeReferenceDirectives,a.hasNoDefaultLib,a.libReferenceDirectives)}if(typescript_1.default.isNumericLiteral(r.expression)){const e=genName.getName(prefixKey,n),t=i.createNumericLiteral(r.expression.text),s=i.createVariableDeclaration(i.createIdentifier(e),void 0,void 0,t),o=i.createVariableDeclarationList([s],typescript_1.default.NodeFlags.Const),p=i.createVariableStatement(void 0,o),c=i.createExportAssignment(void 0,void 0,i.createIdentifier(e));return exportDefaultExportNameMap.push({base:e,file:n,newName:e,isEd:!0}),i.updateSourceFile(a,[p,c],a.isDeclarationFile,a.referencedFiles,a.typeReferenceDirectives,a.hasNoDefaultLib,a.libReferenceDirectives)}}return typescript_1.default.visitEachChild(r,s,e)};return e=>typescript_1.default.visitNode(e,s)},a,e);return{file:t,content:r,...s}}}function anonymousImportHandler(e){return({file:t,content:i,...s})=>{const a=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),r=(0,transformer_1.default)(e=>{const{factory:i}=e,s=r=>{if(typescript_1.default.isImportDeclaration(r)){const e=r.moduleSpecifier.getText(a),s=node_path_1.default.basename(e).split(".")[0].trim();if(r.importClause?.name&&typescript_1.default.isIdentifier(r.importClause.name)){const e=r.importClause.name.text.trim(),a=exportDefaultExportNameMap.find(e=>e.file===s);if(a){exportDefaultImportNameMap.push({base:e,file:t,newName:a.newName,isEd:!0});const s=i.updateImportClause(r.importClause,r.importClause.phaseModifier,i.createIdentifier(a.newName),r.importClause.namedBindings);return i.updateImportDeclaration(r,r.modifiers,s,r.moduleSpecifier,r.attributes)}}}return typescript_1.default.visitEachChild(r,s,e)};return e=>typescript_1.default.visitNode(e,s)},a,e);return{file:t,content:r,...s}}}const anonymousHandler=async(e,t)=>{const i=(0,resolves_1.default)([[anonymousExportHandler,t],[anonymousImportHandler,t],[anonymousCallExpressionHandler,t]]),s=await i.concurrent();for(const t of s)e=e.map(t);return e};function duplicates(e,t,i){const s=typescript_1.default.createSourceFile(t,e,typescript_1.default.ScriptTarget.Latest,!0),a=new Map;for(const e of s.statements){if(!typescript_1.default.isImportDeclaration(e)||!e.importClause)continue;const t=e.importClause;if(t.name&&typescript_1.default.isIdentifier(t.name)){const e=t.name.text;a.set(e,(a.get(e)||[]).concat({name:e,node:t}))}else if(t.namedBindings&&typescript_1.default.isNamespaceImport(t.namedBindings)&&typescript_1.default.isIdentifier(t.namedBindings.name)){const e=t.namedBindings.name.text;a.set(e,(a.get(e)||[]).concat({name:e,node:t.namedBindings}))}else if(t.namedBindings&&typescript_1.default.isNamedImports(t.namedBindings))for(const e of t.namedBindings.elements)if(typescript_1.default.isIdentifier(e.name)){const t=e.name.text;a.set(t,(a.get(t)||[]).concat({name:t,node:e}))}}const r=new Map,n=utils_1.default.uniqueName();n.setPrefix({key:"DuplicateImport",value:"__dup__"});for(const[e,t]of a.entries())if(t.length>1)for(let i=1;i<t.length;i++){const t=n.getName("DuplicateImport",`${e}_`);r.set(`${e}::${i}`,t),r.set(`${e}::occurrence_${i}`,t)}const o=new Map;for(const[e,t]of a.entries())if(t.length>1)for(let i=1;i<t.length;i++){const s=t[i];s?.node&&o.set(s.node.pos,r.get(`${e}::${i}`))}return(0,transformer_1.default)(e=>{const{factory:t}=e,i=s=>{if(typescript_1.default.isImportDeclaration(s)&&s.importClause){const e=s.importClause;let i=!1,a=e;if(e.name&&typescript_1.default.isIdentifier(e.name)){e.pos;const s=o.get(e.pos);s&&(a=t.updateImportClause(e,e.isTypeOnly,t.createIdentifier(s),e.namedBindings),i=!0)}if(e.namedBindings&&typescript_1.default.isNamespaceImport(e.namedBindings)&&typescript_1.default.isIdentifier(e.namedBindings.name)){const s=o.get(e.namedBindings.pos);if(s){const e=t.createNamespaceImport(t.createIdentifier(s));a=t.updateImportClause(a,a.isTypeOnly,a.name,e),i=!0}}if(e.namedBindings&&typescript_1.default.isNamedImports(e.namedBindings)){const s=e.namedBindings.elements.map(e=>{if(typescript_1.default.isIdentifier(e.name)){const s=o.get(e.pos);if(s)return i=!0,t.updateImportSpecifier(e,e.isTypeOnly,e.propertyName,t.createIdentifier(s))}return e});if(i){const e=t.createNamedImports(s);a=t.updateImportClause(a,a.isTypeOnly,a.name,e)}}if(i)return t.updateImportDeclaration(s,s.modifiers,a,s.moduleSpecifier,s.assertClause)}if(typescript_1.default.isIdentifier(s)){const e=s.text;if(!(e=>{const t=e.parent;if(!t)return!1;switch(t.kind){case typescript_1.default.SyntaxKind.ImportSpecifier:case typescript_1.default.SyntaxKind.NamespaceImport:case typescript_1.default.SyntaxKind.ImportClause:case typescript_1.default.SyntaxKind.VariableDeclaration:case typescript_1.default.SyntaxKind.FunctionDeclaration:case typescript_1.default.SyntaxKind.ClassDeclaration:case typescript_1.default.SyntaxKind.InterfaceDeclaration:case typescript_1.default.SyntaxKind.TypeAliasDeclaration:case typescript_1.default.SyntaxKind.EnumDeclaration:case typescript_1.default.SyntaxKind.Parameter:case typescript_1.default.SyntaxKind.PropertyDeclaration:case typescript_1.default.SyntaxKind.MethodDeclaration:case typescript_1.default.SyntaxKind.BindingElement:return!0;default:return!1}})(s)){if(s.parent&&typescript_1.default.isPropertyAccessExpression(s.parent)&&s.parent.name===s)return s;const i=a.get(e);if(i&&i.length>1)for(let s=1;s<i.length;s++){const i=r.get(`${e}::occurrence_${s}`)||r.get(`${e}::${s}`);if(i)return t.createIdentifier(i)}}}return typescript_1.default.visitEachChild(s,i,e)};return e=>typescript_1.default.visitNode(e,i)},s,i)}function mergeImportsStatement(e){const t=new Map,i=new Map,s=new Map,a=new Map,r=new Map;for(const n of e){const e=n.match(/import\s+(?:type\s+)?(?:(.*?)\s+from\s+)?["']([^"']+)["'];?/);if(!e)continue;const[,o,p]=e,c=n.includes("import type"),l=p;if(!o){const e=n.match(/import\s+(?:type\s+)?(\w+)/);if(e){const t=e[1],i=c?a:s;i.has(l)||i.set(l,new Set),i.get(l)?.add(t)}continue}if(o.startsWith("{")){const e=c?i:t;e.has(l)||e.set(l,new Set);o.replace(/[{}]/g,"").split(",").map(e=>e.trim()).filter(Boolean).forEach(t=>e.get(l)?.add(t))}else if(o.startsWith("* as")){const e=o.match(/\*\s+as\s+(\w+)/);if(e){const t=e[1];r.has(l)||r.set(l,new Set),r.get(l)?.add(t)}}else{const e=c?a:s;e.has(l)||e.set(l,new Set),e.get(l)?.add(o.trim())}}const n=[];for(const[e,s]of t){const t=i.get(e)||new Set,a=new Set([...s]);for(const e of t)s.has(e)||a.add(e);if(a.size>0){const t=Array.from(a).sort().join(", ");n.push(`import { ${t} } from "${e}";`)}}for(const[e,s]of i)if(!t.has(e)&&s.size>0){const t=Array.from(s).sort().join(", ");n.push(`import type { ${t} } from "${e}";`)}for(const[e,t]of s){const i=a.get(e)||new Set,s=new Set([...t]);for(const e of i)t.has(e)||s.add(e);if(s.size>0){const t=Array.from(s).join(", ");n.push(`import ${t} from "${e}";`)}}for(const[e,t]of a)if(!s.has(e)&&t.size>0){const i=Array.from(t).join(", ");n.push(`import type ${i} from "${e}";`)}for(const[e,t]of r)if(t.size>0){const i=Array.from(t).join(", ");n.push(`import * as ${i} from "${e}";`)}return n.sort()}function esmExportRemoveHandler(e){return({file:t,content:i,...s})=>{const a=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0);return{file:t,content:(0,transformer_1.default)(e=>{const{factory:t}=e,i=s=>{if(!utils_1.default.check.isInsideNamespace(s)&&(typescript_1.default.isFunctionDeclaration(s)||typescript_1.default.isClassDeclaration(s)||typescript_1.default.isInterfaceDeclaration(s)||typescript_1.default.isTypeAliasDeclaration(s)||typescript_1.default.isEnumDeclaration(s)||typescript_1.default.isVariableStatement(s))){const e=s.modifiers?.filter(e=>e.kind!==typescript_1.default.SyntaxKind.ExportKeyword&&e.kind!==typescript_1.default.SyntaxKind.DefaultKeyword);if(e?.length!==s.modifiers?.length){if(typescript_1.default.isFunctionDeclaration(s))return t.updateFunctionDeclaration(s,e,s.asteriskToken,s.name,s.typeParameters,s.parameters,s.type,s.body);if(typescript_1.default.isClassDeclaration(s))return t.updateClassDeclaration(s,e,s.name,s.typeParameters,s.heritageClauses,s.members);if(typescript_1.default.isInterfaceDeclaration(s))return t.updateInterfaceDeclaration(s,e,s.name,s.typeParameters,s.heritageClauses,s.members);if(typescript_1.default.isTypeAliasDeclaration(s))return t.updateTypeAliasDeclaration(s,e,s.name,s.typeParameters,s.type);if(typescript_1.default.isEnumDeclaration(s))return t.updateEnumDeclaration(s,e,s.name,s.members);if(typescript_1.default.isVariableStatement(s))return t.updateVariableStatement(s,e,s.declarationList)}}if(typescript_1.default.isExportDeclaration(s))return t.createEmptyStatement();if(typescript_1.default.isExportAssignment(s)){const e=s.expression;if(typescript_1.default.isIdentifier(e))return t.createEmptyStatement()}return typescript_1.default.visitEachChild(s,i,e)};return e=>typescript_1.default.visitNode(e,i)},a,e),...s}}}let properties=[];const typeObj={},typesNames=[];function findProperty(e){const t=[];return typescript_1.default.isPropertyAccessExpression(e)&&typescript_1.default.isIdentifier(e.expression)&&t.push(e.expression.text),e.forEachChild(e=>findProperty(e)),t}function importAllRemoveHandler(e,t){return({file:i,content:s,...a})=>{const r=typescript_1.default.createSourceFile(i,s,typescript_1.default.ScriptTarget.Latest,!0),n=new Set;for(const e of r.statements)if(typescript_1.default.isImportEqualsDeclaration(e)&&e.isTypeOnly){const t=e.moduleReference;typescript_1.default.isExternalModuleReference(t)&&typescript_1.default.isStringLiteral(t.expression)&&n.add(e.name.text)}const o=(0,transformer_1.default)(t=>{const{factory:s}=t,a=o=>{properties=[...properties,...findProperty(o)];const p={isNamespace:!1,isTypeOnly:!1,isTypeNamespace:!1,source:"",importedString:void 0,importedObject:void 0};if(typescript_1.default.isTypeReferenceNode(o)&&typescript_1.default.isQualifiedName(o.typeName)&&typescript_1.default.isIdentifier(o.typeName.left)&&typescript_1.default.isIdentifier(o.typeName.right)){const e=o.typeName.left.text,t=o.typeName.right.text;if(typesNames.push(e),e in typeObj?typeObj[e]?.push(t):typeObj[e]=[t],utils_1.default.check.moduleType(r,i).isCommonJs&&"ts"!==e&&!n.has(e))return s.updateTypeReferenceNode(o,s.createIdentifier(t),void 0)}if(typescript_1.default.isImportDeclaration(o)){const t=o.getText(r);return e.push(t),s.createEmptyStatement()}if(typescript_1.default.isImportEqualsDeclaration(o)){const t=o.name.text,i=o.moduleReference;let a;if(o.isTypeOnly&&(p.isTypeOnly=!0),p.importedString=t,p.isTypeOnly||properties.includes(t)&&(p.isNamespace=!0),typescript_1.default.isExternalModuleReference(i)&&typescript_1.default.isStringLiteral(i.expression)&&(p.source=i.expression.text),p.importedString&&!p.importedObject&&(a=p.isTypeOnly?n.has(p.importedString)?`import type * as ${p.importedString} from "${p.source}";`:typesNames.includes(p.importedString)?`import type { ${typeObj[p.importedString]?.join(",")} } from "${p.source}";`:`import type ${p.importedString} from "${p.source}";`:p.isNamespace&&p.source&&"typescript"!==p.source?`import * as ${p.importedString} from "${p.source}";`:`import ${p.importedString} from "${p.source}";`),!p.importedString&&p.importedObject&&(a=`import { ${p.importedObject.join(", ")} } from "${p.source}";`),a)return e.push(a),s.createEmptyStatement()}if(typescript_1.default.isVariableStatement(o)){const t=o.declarationList.declarations;if(1===t.length){const i=t[0];if(i.initializer&&typescript_1.default.isCallExpression(i.initializer)&&typescript_1.default.isIdentifier(i.initializer.expression)&&"require"===i.initializer.expression.escapedText){const t=i.initializer.arguments[0];if(typescript_1.default.isStringLiteral(t)&&(p.source=t.text),typescript_1.default.isIdentifier(i.name)){const e=i.name.text;p.importedString=e,properties.includes(e)&&(p.isNamespace=!0)}else if(typescript_1.default.isObjectBindingPattern(i.name)){const e=[];for(const t of i.name.elements)typescript_1.default.isIdentifier(t.name)&&e.push(t.name.text);e.length>0&&(p.importedObject=e)}let a;if(p.importedString&&!p.importedObject&&(a=p.isNamespace?`import * as ${p.importedString} from "${p.source}";`:`import ${p.importedString} from "${p.source}";`),!p.importedString&&p.importedObject&&(a=`import { ${p.importedObject.join(", ")} } from "${p.source}";`),a)return e.push(a),s.createEmptyStatement()}}}return typescript_1.default.visitEachChild(o,a,t)};return e=>typescript_1.default.visitNode(e,a)},r,t);return{file:i,content:o,...a}}}const removeHandlers=async(e,t)=>{const i=(0,resolves_1.default)([[importAllRemoveHandler,e,t],[esmExportRemoveHandler,t]]);return await i.series()};function collectBindingNames(e,t){typescript_1.default.isIdentifier(e)?t.push(e.text):(typescript_1.default.isObjectBindingPattern(e)||typescript_1.default.isArrayBindingPattern(e))&&e.elements.forEach(e=>{typescript_1.default.isBindingElement(e)&&e.name&&collectBindingNames(e.name,t)})}function clearUnusedCode(e,t,i,s={treatExportsAsUsed:!0}){const a=typescript_1.default.createSourceFile(t,e,typescript_1.default.ScriptTarget.Latest,!0),r=new Map,n=new Set,o=(e,t=!1)=>{const i=r.get(e);r.set(e,{exported:!!i?.exported||t})},p=e=>{if(typescript_1.default.isImportDeclaration(e)&&e.importClause){const t=e.importClause;t.name&&typescript_1.default.isIdentifier(t.name)&&o(t.name.text,!1),t.namedBindings&&(typescript_1.default.isNamedImports(t.namedBindings)?t.namedBindings.elements.forEach(e=>{typescript_1.default.isImportSpecifier(e)&&typescript_1.default.isIdentifier(e.name)&&o(e.name.text,!1)}):typescript_1.default.isNamespaceImport(t.namedBindings)&&typescript_1.default.isIdentifier(t.namedBindings.name)&&o(t.namedBindings.name.text,!1))}else if(typescript_1.default.isImportEqualsDeclaration(e)&&typescript_1.default.isIdentifier(e.name))o(e.name.text,!1);else if(typescript_1.default.isVariableStatement(e)){const t=e.modifiers?.some(e=>e.kind===typescript_1.default.SyntaxKind.ExportKeyword)??!1;e.declarationList.declarations.forEach(e=>{collectBindingNames(e.name,[]);const i=[];collectBindingNames(e.name,i),i.forEach(e=>o(e,t))})}else if(typescript_1.default.isFunctionDeclaration(e)&&e.name&&typescript_1.default.isIdentifier(e.name)){const t=e.modifiers?.some(e=>e.kind===typescript_1.default.SyntaxKind.ExportKeyword)??!1;o(e.name.text,t)}else if(typescript_1.default.isClassDeclaration(e)&&e.name&&typescript_1.default.isIdentifier(e.name)){const t=e.modifiers?.some(e=>e.kind===typescript_1.default.SyntaxKind.ExportKeyword)??!1;o(e.name.text,t)}if(typescript_1.default.isIdentifier(e)){const t=e.parent;typescript_1.default.isVariableDeclaration(t)&&t.name===e||typescript_1.default.isFunctionDeclaration(t)&&t.name===e||typescript_1.default.isClassDeclaration(t)&&t.name===e||typescript_1.default.isImportClause(t)&&t.name===e||typescript_1.default.isImportSpecifier(t)&&t.name===e||typescript_1.default.isNamespaceImport(t)&&t.name===e||typescript_1.default.isBindingElement(t)&&t.name===e||typescript_1.default.isParameter(t)&&t.name===e||n.add(e.text)}typescript_1.default.forEachChild(e,p)};p(a);const c=new Set;r.forEach((e,t)=>{n.has(t)||s.treatExportsAsUsed&&e.exported||c.add(t)});return(0,transformer_1.default)(e=>{const t=i=>{if(typescript_1.default.isImportDeclaration(i)&&i.importClause){const e=i.importClause,t=e.name&&typescript_1.default.isIdentifier(e.name)?e.name.text:void 0;let s;const a=[];e.namedBindings&&(typescript_1.default.isNamedImports(e.namedBindings)?e.namedBindings.elements.forEach(e=>{typescript_1.default.isImportSpecifier(e)&&typescript_1.default.isIdentifier(e.name)&&a.push(e)}):typescript_1.default.isNamespaceImport(e.namedBindings)&&typescript_1.default.isIdentifier(e.namedBindings.name)&&(s=e.namedBindings.name.text));const r=!!t&&!c.has(t),n=!!s&&!c.has(s),o=a.filter(e=>!c.has(e.name.text));if(!r&&!n&&0===o.length)return typescript_1.default.factory.createNotEmittedStatement(i);if(!r&&!!e.name||void 0!==s&&!n||o.length!==a.length){let e;e=o.length>0?typescript_1.default.factory.createNamedImports(o):n&&s?typescript_1.default.factory.createNamespaceImport(typescript_1.default.factory.createIdentifier(s)):void 0;const a=r&&t?typescript_1.default.factory.createIdentifier(t):void 0,p=typescript_1.default.factory.createImportClause(!1,a,e);return typescript_1.default.factory.updateImportDeclaration(i,i.modifiers,p,i.moduleSpecifier,i.assertClause)}return i}if((typescript_1.default.isFunctionDeclaration(i)||typescript_1.default.isClassDeclaration(i))&&i.name&&typescript_1.default.isIdentifier(i.name))return c.has(i.name.text)?typescript_1.default.factory.createNotEmittedStatement(i):i;if(typescript_1.default.isVariableStatement(i)){const e=[];i.declarationList.declarations.forEach(t=>collectBindingNames(t.name,e));return e.some(e=>!c.has(e))?i:typescript_1.default.factory.createNotEmittedStatement(i)}return typescript_1.default.visitEachChild(i,t,e)};return e=>typescript_1.default.visitNode(e,t)},a,i)}async function preProcessPluginParser(e,t,i){if(e.length)for(const s of e){const e="function"==typeof s?s():s;"pre-process"===e.type&&(t=e.async?await e.func(t,i):e.func(t,i))}return t}async function bundler(e){"."===e.exportPath||utils_1.default.str.splitCamelCase(e.exportPath.slice(2));console.time(` > ${tcolor_1.default.cyan("Bundled")} -> ${tcolor_1.default.cyan(`export path(${tcolor_1.default.magenta(`"${e.exportPath}"`)})`)} `);let t=e.depFiles;const i=e.rename,s=e.tsOptions.default,a=e.plugins;let r=[];t=await anonymousHandler(t,s);const n=await removeHandlers(r,s);t=t.map(n[0]);const o=t.slice(0,-1).map(n[1]),p=t.slice(-1),c=/["']((?!\.\/|\.\.\/)[^"']+)["']/;r=r.filter(e=>c.test(e)),r=mergeImportsStatement(r);let l=`${r.join("\n").trim()}\n${o.map(e=>`${`//${node_path_1.default.relative(node_process_1.default.cwd(),e.file)}`}\n${e.content}`).join("\n").trim()}\n${p.map(e=>`${`//${node_path_1.default.relative(node_process_1.default.cwd(),e.file)}`}\n${e.content}`).join("\n").trim()}`;return l=l.replace(/^s*;\s*$/gm,"").trim(),i&&(l=duplicates(l,e.fileName,s)),l=clearUnusedCode(l,e.fileName,s),l=await preProcessPluginParser(a,l),console.timeEnd(` > ${tcolor_1.default.cyan("Bundled")} -> ${tcolor_1.default.cyan(`export path(${tcolor_1.default.magenta(`"${e.exportPath}"`)})`)} `),{bundledContent:l,...e}}async function bundle(e){const t=[];for(const i of e.points){const e=await bundler(i);t.push(e)}return{points:t,allowUpdatePackageJson:e.allowUpdatePackageJson}}function createHost(e,t){const i={},s={getSourceFile:(i,s)=>{if(i===t)return typescript_1.default.createSourceFile(i,e,s)},writeFile:(e,t)=>{i[e]=t},getDefaultLibFileName:e=>typescript_1.default.getDefaultLibFilePath(e),getCurrentDirectory:()=>"",getDirectories:()=>[],fileExists:e=>e===t,readFile:i=>i===t?e:void 0,getCanonicalFileName:e=>e,useCaseSensitiveFileNames:()=>!0,getNewLine:()=>"\n"};return{createdFiles:i,host:s}}const isCjs=e=>e.commonjs&&e.commonjsTypes,isEsm=e=>e.esm&&e.esmTypes;function getExports(e,t){return isCjs(e)&&isEsm(e)?{[t]:{import:{types:`./${node_path_1.default.relative(node_process_1.default.cwd(),e.esmTypes)}`,default:`./${node_path_1.default.relative(node_process_1.default.cwd(),e.esm)}`},require:{types:`./${node_path_1.default.relative(node_process_1.default.cwd(),e.commonjsTypes)}`,default:`./${node_path_1.default.relative(node_process_1.default.cwd(),e.commonjs)}`}}}:isCjs(e)&&!isEsm(e)?{[t]:{require:{types:`./${node_path_1.default.relative(node_process_1.default.cwd(),e.commonjsTypes)}`,default:`./${node_path_1.default.relative(node_process_1.default.cwd(),e.commonjs)}`}}}:!isCjs(e)&&isEsm(e)?{[t]:{import:{types:`./${node_path_1.default.relative(node_process_1.default.cwd(),e.esmTypes)}`,default:`./${node_path_1.default.relative(node_process_1.default.cwd(),e.esm)}`}}}:{}}async function writePackage(e,t){let i=!0;"."!==t&&(i=!1);const s=typescript_1.default.sys.resolvePath("package.json"),a=node_fs_1.default.readFileSync(s,"utf8"),r=JSON.parse(a);let{name:n,version:o,description:p,main:c,module:l,type:d,types:f,exports:u,...m}=r;d="module";let y={},_={},g={},h={};if(i)y=e.main?{main:node_path_1.default.relative(node_process_1.default.cwd(),e.main)}:{},_=e.module?{module:node_path_1.default.relative(node_process_1.default.cwd(),e.module)}:{},g=e.types?{types:node_path_1.default.relative(node_process_1.default.cwd(),e.types)}:{},h={exports:{...getExports(e,t)}};else{y=c?{main:c}:{},_=l?{module:l}:{},g=f?{types:f}:{};h={exports:{...u&&"object"==typeof u&&!Array.isArray(u)?{...u}:{},...getExports(e,t)}}}const x={name:n,version:o,description:p,type:d,...y,...g,..._,...h,...m};await utils_1.default.file.writeFile(s,JSON.stringify(x,null,2))}const resolveSourceMappingURL=(e,t,i)=>{const s=node_path_1.default.extname(e),a=node_path_1.default.basename(e).split(".")[0],r=new RegExp(`${a}.js.map`,"gm"),n=new RegExp(`${a}.d.ts.map`,"gm"),o="cjs"===i?`${a}.cjs.map`:`${a}.mjs.map`,p="cjs"===i?`${a}.d.cts.map`:`${a}.d.mts.map`;return".js"===s?t.replace(r,o):t.replace(n,p)},postProcessPluginParser=async(e,t,i)=>{if(".js"===node_path_1.default.extname(i)&&e.length)for(let s of e)s="function"==typeof s?s():s,"post-process"===s.type&&(t=s.async?await s.func(t,i):s.func(t,i));return t};class Compiler{constructor(e){this.object=e,this.files={commonjs:void 0,commonjsTypes:void 0,esm:void 0,esmTypes:void 0,main:void 0,module:void 0,types:void 0}}_isUpdate(){return this.object.allowUpdatePackageJson}async _commonjs(e){const t="."===e.exportPath;console.time(` ${tcolor_1.default.cyan("Compiled commonjs")} -> ${tcolor_1.default.cyan(`export path(${tcolor_1.default.magenta(`"${e.exportPath}"`)})`)} `);const i=e.fileName,s=e.bundledContent,a=[...new Set(e.format)],r=e.tsOptions.cjs,n=createHost(s,i),o=n.createdFiles,p=n.host;typescript_1.default.createProgram([i],r,p).emit(),Object.entries(o).map(async([i,s])=>{s=resolveSourceMappingURL(i,s,"cjs"),s=await postProcessPluginParser(e.plugins,s,i),this._isUpdate()&&(i.match(/.js/g)&&(this.files.commonjs=i.replace(/.js/g,".cjs")),i.match(/.d.ts/g)&&(this.files.commonjsTypes=i.replace(/.d.ts/g,".d.cts")),t&&a.includes("commonjs")&&(this.files.commonjs&&(this.files.main=this.files.commonjs),this.files.commonjsTypes&&(this.files.types=this.files.commonjsTypes))),i=(i=(i=i.replace(/.js/g,".cjs")).replace(/.map.js/g,".map.cjs")).replace(/.d.ts/g,".d.cts"),a.includes("commonjs")&&!a.includes("esm")&&await utils_1.default.file.clearFolder(node_path_1.default.dirname(i)),await utils_1.default.file.writeFile(i,s)}),console.timeEnd(` ${tcolor_1.default.cyan("Compiled commonjs")} -> ${tcolor_1.default.cyan(`export path(${tcolor_1.default.magenta(`"${e.exportPath}"`)})`)} `)}async _esm(e){const t="."===e.exportPath;console.time(` ${tcolor_1.default.cyan("Compiled esm")} -> ${tcolor_1.default.cyan(`export path(${tcolor_1.default.magenta(`"${e.exportPath}"`)})`)} `);const i=e.fileName,s=e.bundledContent,a=e.tsOptions.esm,r=createHost(s,i),n=r.createdFiles,o=r.host;typescript_1.default.createProgram([i],a,o).emit(),Object.entries(n).map(async([i,s])=>{s=resolveSourceMappingURL(i,s,"esm"),s=await postProcessPluginParser(e.plugins,s,i),this._isUpdate()&&(i.match(/.js/g)&&(this.files.esm=i.replace(/.js/g,".mjs")),i.match(/.d.ts/g)&&(this.files.esmTypes=i.replace(/.d.ts/g,".d.mts")),t&&this.files.esm&&(this.files.module=this.files.esm)),i=(i=(i=i.replace(/.js/g,".mjs")).replace(/.map.js/g,".map.mjs")).replace(/.d.ts/g,".d.mts"),await utils_1.default.file.clearFolder(node_path_1.default.dirname(i)),await utils_1.default.file.writeFile(i,s)}),console.timeEnd(` ${tcolor_1.default.cyan("Compiled esm")} -> ${tcolor_1.default.cyan(`export path(${tcolor_1.default.magenta(`"${e.exportPath}"`)})`)} `)}async compile(){for(const e of this.object.points){const t=[...new Set(e.format)];for(const i of t)switch(i){case"commonjs":await this._commonjs(e),this._isUpdate()&&await writePackage(this.files,e.exportPath);break;case"esm":await this._esm(e),this._isUpdate()&&await writePackage(this.files,e.exportPath)}}}}const finalCheck=e=>{const t=e.points;for(const e of t)for(const t of e.depFiles)"cjs"===t.moduleType||".cjs"===t.fileExt?(console.error(`> ${tcolor_1.default.cyan(`Unsupported CommonJS dependency: ${tcolor_1.default.magenta(t.file)}\n To resolve that, use @suseejs/plugin-commonjs`)}`),typescript_1.default.sys.exit(1)):(t.isJsx||".jsx"===t.fileExt||".tsx"===t.fileExt)&&(console.error(`> ${tcolor_1.default.cyan(`Unsupported JSX/TSX dependency: ${tcolor_1.default.magenta(t.file)}\n That will be fix in future versions`)}`),typescript_1.default.sys.exit(1))},packageContent=node_fs_1.default.readFileSync(node_path_1.default.resolve(node_process_1.default.cwd(),"package.json"),"utf8"),pkg=JSON.parse(packageContent),name=pkg.name??"",version=pkg.version??"";let pkg_nv="";async function susee(){console.time(`susee > ${tcolor_1.default.cyan("Done in")}`),console.time(`susee > ${tcolor_1.default.cyan(`Initialized ${tcolor_1.default.magenta(pkg_nv)}`)} `);const e=await initializer();finalCheck(e),console.timeEnd(`susee > ${tcolor_1.default.cyan(`Initialized ${tcolor_1.default.magenta(pkg_nv)}`)} `);const t=await bundle(e),i=new Compiler(t);await i.compile(),console.timeEnd(`susee > ${tcolor_1.default.cyan("Done in")}`)}pkg_nv=""!==name&&""!==version?`${name}@${version}`:""!==name&&""===version?`${name}`:""===name&&""!==version?`the project@${version}`:"the project";
8
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i);var o=Object.getOwnPropertyDescriptor(t,i);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,s,o)}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var s=e(t),o=0;o<s.length;o++)"default"!==s[o]&&__createBinding(i,t,s[o]);return __setModuleDefault(i,t),i}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.build=build;const color_1=__importDefault(require("@suseejs/color")),typescript_1=__importDefault(require("typescript")),bundler_1=require("@suseejs/bundler"),files_1=require("@suseejs/files"),tsoptions_1=require("@suseejs/tsoptions"),compiler_1=require("@suseejs/compiler"),getConfigPath=()=>{const e=["susee.config.ts","susee.config.js","susee.config.mjs"];let t;for(const i of e){const e=typescript_1.default.sys.resolvePath(i);if(typescript_1.default.sys.fileExists(e)){t=e;break}}return t};function checkEntries(e){e.length<1&&(console.error(color_1.default.magenta("No entry found in susee.config file or build options, at least one entry required")),typescript_1.default.sys.exit(1));const t={},i=[];for(const s of e){const e=s.exportPath;t[e]?i.push(`"${e}"`):t[e]=!0}i.length>0&&(console.error(color_1.default.magenta(`Duplicate export paths/path (${i.join(",")}) found in your susee.config file or build options , that will error for bundled output`)),typescript_1.default.sys.exit(1));for(const t of e)typescript_1.default.sys.fileExists(typescript_1.default.sys.resolvePath(t.entry))||(console.error(color_1.default.magenta(`Entry file ${t.entry} dose not exists.`)),typescript_1.default.sys.exit(1))}function generateBuildOptions(e){const t=e.outDir??"dist",i=[];checkEntries(e.entryPoints);for(const s of e.entryPoints){const e=s.entry,o=s.exportPath,n=s.tsconfigFilePath??void 0,r=s.format?[...new Set(s.format)]:["esm"],l=s.warning??!1,a=s.renameDuplicates??!0,f=s.plugins??[],c="."===s.exportPath?t:`${t}${s.exportPath.slice(1)}`;i.push({entry:e,exportPath:o,format:r,tsconfigFilePath:n,rename:a,plugins:f,warning:l,outputDirectoryPath:c})}return{buildEntryPoints:i,updatePackage:e.allowUpdatePackageJson??!1,outDir:t}}async function finalSuseeConfig(){const e=getConfigPath();if(e){return generateBuildOptions((await Promise.resolve(`${e}`).then(e=>__importStar(require(e)))).default)}}class Compiler{_files;_object;constructor(e){this._object=e,this._files={commonjs:void 0,commonjsTypes:void 0,esm:void 0,esmTypes:void 0,main:void 0,module:void 0,types:void 0}}_update(){return this._object.updatePackage}async _commonjs(e){const t="."===e.exportPath,i=(0,tsoptions_1.getCompilerOptions)(e.tsconfigFilePath).commonjs(e.outputDirectoryPath),s=await(0,bundler_1.bundler)(e.entry,e.plugins,e.warning,e.rename),o=(0,compiler_1.suseeCompiler)({sourceCode:s,fileName:e.entry,compilerOptions:i});let n=o.code;const r=files_1.files.joinPath(o.out_dir,`${o.file_name}.cjs`),l=files_1.files.joinPath(o.out_dir,`${o.file_name}.d.cts`),a=files_1.files.joinPath(o.out_dir,`${o.file_name}.cjs.map`);if(n=n.replace(new RegExp(`${o.file_name}.js.map`,"gm"),`${o.file_name}.cjs.map`),e.plugins.length>0)for(const t of e.plugins){const i="function"==typeof t?t():t;"post-process"===i.type&&(n=i.async?await i.func(n,e.entry):i.func(n,e.entry))}this._update()&&(this._files.commonjs=r,o.dts&&(this._files.commonjsTypes=l),t&&e.format.includes("commonjs")&&(this._files.commonjs&&(this._files.main=this._files.commonjs),this._files.commonjsTypes&&(this._files.types=this._files.commonjsTypes))),await files_1.files.writeFile(r,n),o.dts&&await files_1.files.writeFile(l,o.dts),o.map&&await files_1.files.writeFile(a,o.map)}async _esm(e){const t="."===e.exportPath,i=(0,tsoptions_1.getCompilerOptions)(e.tsconfigFilePath).esm(e.outputDirectoryPath),s=await(0,bundler_1.bundler)(e.entry,e.plugins,e.warning,e.rename),o=(0,compiler_1.suseeCompiler)({sourceCode:s,fileName:e.entry,compilerOptions:i});let n=o.code;const r=files_1.files.joinPath(o.out_dir,`${o.file_name}.mjs`),l=files_1.files.joinPath(o.out_dir,`${o.file_name}.d.mts`),a=files_1.files.joinPath(o.out_dir,`${o.file_name}.mjs.map`);if(n=n.replace(new RegExp(`${o.file_name}.js.map`,"gm"),`${o.file_name}.mjs.map`),e.plugins.length>0)for(const t of e.plugins){const i="function"==typeof t?t():t;"post-process"===i.type&&(n=i.async?await i.func(n,e.entry):i.func(n,e.entry))}this._update()&&(this._files.esm=r,o.dts&&(this._files.esmTypes=l),t&&this._files.esm&&(this._files.module=this._files.esm)),await files_1.files.writeFile(r,n),o.dts&&await files_1.files.writeFile(l,o.dts),o.map&&await files_1.files.writeFile(a,o.map)}async compile(){await files_1.files.clearFolder(this._object.outDir);for(const e of this._object.buildEntryPoints)for(const t of e.format)switch(t){case"commonjs":await this._commonjs(e),this._update()&&files_1.files.writePackageJson(this._files,e.exportPath);break;case"esm":await this._esm(e),this._update()&&files_1.files.writePackageJson(this._files,e.exportPath)}}}async function build(e){console.time(color_1.default.cyan("[Build] "));let t={};const i=await finalSuseeConfig();e||i||(console.error(`${color_1.default.magenta("[Error]")} : Required build options or susee config file at root.\n Use ${color_1.default.bold("npx susee init")} to create config file.`),process.exit(1)),e?t=generateBuildOptions(e):i&&(t=i);const s=new Compiler(t);await s.compile(),console.timeEnd(color_1.default.cyan("[Build] "))}