susee 1.5.1 → 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 +1 -1
- package/README.md +161 -114
- package/bin/susee +3 -0
- package/dist/bin/index.d.mts +2 -0
- package/dist/bin/index.mjs +2 -0
- package/dist/bin/index.mjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -26
- package/dist/index.d.mts +13 -26
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +30 -26
- package/bin/index.mjs +0 -18
- package/bin/init.mjs +0 -136
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
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
|
|
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,81 +6,98 @@
|
|
|
6
6
|
</div>
|
|
7
7
|
<!-- markdownlint-enable MD033 -->
|
|
8
8
|
|
|
9
|
-
[![
|
|
9
|
+
[![NPM][nodei_img]][nodei_url]
|
|
10
10
|
|
|
11
|
-
|
|
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
|
-
|
|
13
|
+
TypeScript-first bundler for library packages.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
bundles sources into a single unit, then compiles output for ESM and/or CommonJS with types.
|
|
15
|
+
Susee can be used in two ways:
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
1. Programmatic API from `susee` (`build(options?)`)
|
|
18
|
+
2. CLI (`susee`, `susee init`, `susee build ...`)
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
- `susee.config.ts`
|
|
22
|
-
- `susee.config.js`
|
|
23
|
-
- `susee.config.mjs`
|
|
24
|
-
- Supports multiple entry points with subpath exports (`.` and `./subpath`).
|
|
25
|
-
- Validates and type-checks dependency files before bundling.
|
|
26
|
-
- Runs dependency, pre-process, and post-process plugins (sync or async).
|
|
27
|
-
- Compiles to:
|
|
28
|
-
- ESM (`.mjs`, `.d.mts`, source maps)
|
|
29
|
-
- CommonJS (`.cjs`, `.d.cts`, source maps)
|
|
30
|
-
- Can update `package.json` fields (`type`, `main`, `module`, `types`, `exports`) when `allowUpdatePackageJson` is enabled.
|
|
20
|
+
The sections below are based on the code in `src`.
|
|
31
21
|
|
|
32
|
-
##
|
|
22
|
+
## Install
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
- JSX/TSX dependencies are currently rejected.
|
|
36
|
-
- CLI supports only `susee` and `susee init`.
|
|
37
|
-
|
|
38
|
-
## Installation and Quick Start
|
|
39
|
-
|
|
40
|
-
### Install
|
|
41
|
-
|
|
42
|
-
```sh
|
|
24
|
+
```bash
|
|
43
25
|
npm i -D susee
|
|
44
26
|
```
|
|
45
27
|
|
|
46
|
-
|
|
28
|
+
## Quick Start (CLI)
|
|
29
|
+
|
|
30
|
+
1. Generate config:
|
|
47
31
|
|
|
48
|
-
```
|
|
32
|
+
```bash
|
|
49
33
|
npx susee init
|
|
50
34
|
```
|
|
51
35
|
|
|
52
|
-
|
|
36
|
+
<!-- markdownlint-disable MD029 -->
|
|
53
37
|
|
|
54
|
-
|
|
38
|
+
2. Build using config:
|
|
55
39
|
|
|
56
|
-
```
|
|
40
|
+
```bash
|
|
57
41
|
npx susee
|
|
58
42
|
```
|
|
59
43
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
|
68
69
|
```
|
|
69
70
|
|
|
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
|
+
```
|
|
71
83
|
|
|
72
|
-
|
|
84
|
+
### CLI Examples
|
|
73
85
|
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
plugins?: (SuseePlugin | SuseePluginFunction)[]; // default: []
|
|
79
|
-
allowUpdatePackageJson?: boolean; // default: false
|
|
80
|
-
}
|
|
86
|
+
```bash
|
|
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
|
|
81
90
|
```
|
|
82
91
|
|
|
83
|
-
|
|
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
|
|
84
101
|
|
|
85
102
|
```ts
|
|
86
103
|
type OutputFormat = ("commonjs" | "esm")[];
|
|
@@ -89,96 +106,111 @@ interface EntryPoint {
|
|
|
89
106
|
entry: string;
|
|
90
107
|
exportPath: "." | `./${string}`;
|
|
91
108
|
format?: OutputFormat; // default: ["esm"]
|
|
92
|
-
tsconfigFilePath?: string;
|
|
109
|
+
tsconfigFilePath?: string | undefined; // default: undefined
|
|
93
110
|
renameDuplicates?: boolean; // default: true
|
|
94
|
-
|
|
111
|
+
plugins?: unknown[]; // default: []
|
|
112
|
+
warning?: boolean; // default: false
|
|
95
113
|
}
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Entry Validation Rules
|
|
99
114
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
For each entry point, Susee builds compiler options from:
|
|
115
|
+
interface SuSeeConfig {
|
|
116
|
+
entryPoints: EntryPoint[];
|
|
117
|
+
outDir?: string; // default: "dist"
|
|
118
|
+
allowUpdatePackageJson?: boolean; // default: false
|
|
119
|
+
}
|
|
120
|
+
```
|
|
107
121
|
|
|
108
|
-
|
|
109
|
-
2. project `tsconfig.json`
|
|
110
|
-
3. Susee defaults
|
|
122
|
+
### Example `susee.config.ts`
|
|
111
123
|
|
|
112
|
-
|
|
124
|
+
```ts
|
|
125
|
+
import type { SuSeeConfig } from "susee";
|
|
126
|
+
|
|
127
|
+
const config: SuSeeConfig = {
|
|
128
|
+
entryPoints: [
|
|
129
|
+
{
|
|
130
|
+
entry: "src/index.ts",
|
|
131
|
+
exportPath: ".",
|
|
132
|
+
format: ["esm", "commonjs"],
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
outDir: "dist",
|
|
136
|
+
allowUpdatePackageJson: false,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export default config;
|
|
140
|
+
```
|
|
113
141
|
|
|
114
|
-
|
|
115
|
-
- `allowJs: true`
|
|
116
|
-
- `outDir` set per entry output path
|
|
117
|
-
- `types` includes `node`
|
|
118
|
-
- `lib` includes `ESNext`
|
|
142
|
+
## Programmatic API
|
|
119
143
|
|
|
120
|
-
|
|
144
|
+
```ts
|
|
145
|
+
import { build, type SuSeeConfig } from "susee";
|
|
146
|
+
|
|
147
|
+
const options: SuSeeConfig = {
|
|
148
|
+
entryPoints: [
|
|
149
|
+
{
|
|
150
|
+
entry: "src/index.ts",
|
|
151
|
+
exportPath: ".",
|
|
152
|
+
format: ["esm", "commonjs"],
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
await build(options);
|
|
158
|
+
```
|
|
121
159
|
|
|
122
|
-
|
|
160
|
+
Behavior of `build(options?)`:
|
|
123
161
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
- `pre-process`
|
|
128
|
-
- receives bundled code before compilation
|
|
129
|
-
- `post-process`
|
|
130
|
-
- receives emitted JS output content per file
|
|
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`.
|
|
131
165
|
|
|
132
|
-
|
|
166
|
+
## Output Notes
|
|
133
167
|
|
|
134
|
-
|
|
168
|
+
For an entry like `src/index.ts` with both formats enabled, output includes:
|
|
135
169
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
- emits `.cjs` and `.d.cts`
|
|
140
|
-
- `format: ["esm", "commonjs"]`
|
|
141
|
-
- emits both sets
|
|
170
|
+
1. ESM: `dist/index.mjs`
|
|
171
|
+
2. CommonJS: `dist/index.cjs`
|
|
172
|
+
3. Sourcemaps: `.mjs.map` and `.cjs.map`
|
|
142
173
|
|
|
143
|
-
|
|
174
|
+
Declaration files are emitted by the compiler when available.
|
|
144
175
|
|
|
145
|
-
|
|
146
|
-
- `main`
|
|
147
|
-
- `module`
|
|
148
|
-
- `types`
|
|
149
|
-
- `exports` (including subpath exports from `exportPath`)
|
|
176
|
+
## Build Output Matrix
|
|
150
177
|
|
|
151
|
-
|
|
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` |
|
|
152
182
|
|
|
153
|
-
|
|
154
|
-
susee
|
|
155
|
-
susee init
|
|
156
|
-
```
|
|
183
|
+
Notes:
|
|
157
184
|
|
|
158
|
-
|
|
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.
|
|
159
188
|
|
|
160
|
-
##
|
|
189
|
+
## Package.json Update Matrix
|
|
161
190
|
|
|
162
|
-
|
|
191
|
+
When `allowUpdatePackageJson` (config) or `--allow-update` (CLI build) is enabled, Susee can update package fields.
|
|
163
192
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
npm run hooks:install
|
|
170
|
-
```
|
|
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 |
|
|
171
198
|
|
|
172
199
|
Notes:
|
|
173
200
|
|
|
174
|
-
|
|
175
|
-
|
|
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.
|
|
176
204
|
|
|
177
|
-
##
|
|
205
|
+
## Validation Rules
|
|
178
206
|
|
|
179
|
-
|
|
207
|
+
From config validation logic:
|
|
180
208
|
|
|
181
|
-
|
|
209
|
+
1. At least one `entryPoints` item is required.
|
|
210
|
+
2. Duplicate `exportPath` values are rejected.
|
|
211
|
+
3. Each `entry` path must exist.
|
|
212
|
+
|
|
213
|
+
Violations print an error and exit with code `1`.
|
|
182
214
|
|
|
183
215
|
## License
|
|
184
216
|
|
|
@@ -189,3 +221,18 @@ See detail in [CONTRIBUTING.md][file-contribute]
|
|
|
189
221
|
[license]: LICENSE
|
|
190
222
|
[file-contribute]: CONTRIBUTING.md
|
|
191
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,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,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AA2ErD;;;;;GAKG;AACH,MAAM,aAAa,GAAG,GAAuB,EAAE;IAC3C,MAAM,SAAS,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;IAC7E,IAAI,UAA8B,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,K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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,a){void 0===a&&(a=i);var r=Object.getOwnPropertyDescriptor(t,i);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,a,r)}:function(e,t,i,a){void 0===a&&(a=i),e[a]=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 a=e(t),r=0;r<a.length;r++)"default"!==a[r]&&__createBinding(i,t,a[r]);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 a of e){const e=a.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 a=t.outDir??"dist",r=[];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?a:`${a}${e.exportPath.slice(1)}`};r.push(t)}return{points:r,plugins:t.plugins??[],allowUpdatePackageJson:t.allowUpdatePackageJson??!1,outDir:a}}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),a=await node_fs_1.default.promises.readFile(t,"utf8"),r=node_path_1.default.extname(t),s=await fileSizes(t),n=a.length,o=checkExport(a,t),p=typescript_1.default.createSourceFile(t,a,typescript_1.default.ScriptTarget.Latest,!0),c=utils_1.default.check.moduleType(p,t).isCommonJs?"cjs":"esm",l={file:t,content:a,length:n,includeDefExport:o,size:{logical:s.logical,allocated:s.allocated,utf8:(new TextEncoder).encode(a).length,buffBytes:node_buffer_1.Buffer.byteLength(a,"utf8")},moduleType:c,fileExt:r,isJsx:isJsxContent(a)};i.push(l)}return i}function _typesCheck(e,t){if(!t.noCheck){const i=e.map(e=>e.file);let a=!1;const r=typescript_1.default.createProgram(i,t);for(const e of i){const t=r.getSourceFile(e);t||(console.error(tcolor_1.default.magenta(`File not found: ${e}`)),typescript_1.default.sys.exit(1));const i=[...r.getSyntacticDiagnostics(t),...r.getSemanticDiagnostics(t),...r.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)),a=!0}}if(!a)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 a of t){const t="function"==typeof a?a():a;"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,a=[];for(const e of t){const t=compilerOptions(e);let r=await generateDependencies(e.entry);await typeCheck(r,t.esm)||typescript_1.default.sys.exit(1),r=await depPluginParser(r,i,t.default);const s={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:r,plugins:i};a.push(s)}return{points:a,allowUpdatePackageJson:e.allowUpdatePackageJson}}const exportDefaultExportNameMap=[],exportDefaultImportNameMap=[],prefixKey="AnonymousName",createAnonymousNameGenerator=()=>utils_1.default.uniqueName().setPrefix({key:prefixKey,value:"__anonymous__"});let genName=createAnonymousNameGenerator();const resetAnonymousState=()=>{exportDefaultExportNameMap.length=0,exportDefaultImportNameMap.length=0,genName=createAnonymousNameGenerator()};function anonymousCallExpressionHandler(e){return({file:t,content:i,...a})=>{const r=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),s=(0,transformer_1.default)(e=>{const{factory:i}=e,a=r=>{if(typescript_1.default.isCallExpression(r)){if(typescript_1.default.isIdentifier(r.expression)){const e=r.expression.text,a=exportDefaultImportNameMap.find(i=>i.base===e&&i.file===t);if(a)return i.updateCallExpression(r,i.createIdentifier(a.newName),r.typeArguments,r.arguments)}}else if(typescript_1.default.isPropertyAccessExpression(r)){if(typescript_1.default.isIdentifier(r.expression)){const e=r.expression.text,a=exportDefaultImportNameMap.find(i=>i.base===e&&i.file===t);if(a)return i.updatePropertyAccessExpression(r,i.createIdentifier(a.newName),r.name)}}else if(typescript_1.default.isNewExpression(r)){if(typescript_1.default.isIdentifier(r.expression)){const e=r.expression.text,a=exportDefaultImportNameMap.find(i=>i.base===e&&i.file===t);if(a)return i.updateNewExpression(r,i.createIdentifier(a.newName),r.typeArguments,r.arguments)}}else if(typescript_1.default.isExportSpecifier(r)&&typescript_1.default.isIdentifier(r.name)){const e=r.name.text,a=exportDefaultImportNameMap.find(i=>i.base===e&&i.file===t);if(a)return i.updateExportSpecifier(r,r.isTypeOnly,r.propertyName,i.createIdentifier(a.newName))}return typescript_1.default.visitEachChild(r,a,e)};return e=>typescript_1.default.visitNode(e,a)},r,e);return{file:t,content:s,...a}}}function anonymousExportHandler(e){return({file:t,content:i,...a})=>{const r=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),s=(0,transformer_1.default)(e=>{const{factory:i}=e,a=s=>{const n=node_path_1.default.basename(t).split(".")[0];if((typescript_1.default.isFunctionDeclaration(s)||typescript_1.default.isClassDeclaration(s))&&void 0===s.name){let e=!1,t=!1;if(s.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(s))return i.updateFunctionDeclaration(s,s.modifiers,s.asteriskToken,i.createIdentifier(e),s.typeParameters,s.parameters,s.type,s.body);if(typescript_1.default.isClassDeclaration(s))return i.updateClassDeclaration(s,s.modifiers,i.createIdentifier(e),s.typeParameters,s.heritageClauses,s.members)}}else if(typescript_1.default.isExportAssignment(s)&&!s.name&&!s.isExportEquals){if(typescript_1.default.isArrowFunction(s.expression)){const e=genName.getName(prefixKey,n),t=i.createArrowFunction(s.expression.modifiers,s.expression.typeParameters,s.expression.parameters,s.expression.type,s.expression.equalsGreaterThanToken,s.expression.body),a=i.createVariableDeclaration(i.createIdentifier(e),s.expression.exclamationToken,s.expression.type,t),o=i.createVariableDeclarationList([a],typescript_1.default.NodeFlags.Const),p=i.createVariableStatement(s.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(r,[p,c],r.isDeclarationFile,r.referencedFiles,r.typeReferenceDirectives,r.hasNoDefaultLib,r.libReferenceDirectives)}if(typescript_1.default.isObjectLiteralExpression(s.expression)){const e=genName.getName(prefixKey,n),t=i.createVariableDeclaration(i.createIdentifier(e),void 0,void 0,s.expression),a=i.createVariableDeclarationList([t],typescript_1.default.NodeFlags.Const),o=i.createVariableStatement(void 0,a),p=i.createExportAssignment(void 0,void 0,i.createIdentifier(e));return exportDefaultExportNameMap.push({base:e,file:n,newName:e,isEd:!0}),i.updateSourceFile(r,[o,p],r.isDeclarationFile,r.referencedFiles,r.typeReferenceDirectives,r.hasNoDefaultLib,r.libReferenceDirectives)}if(typescript_1.default.isArrayLiteralExpression(s.expression)){const e=genName.getName(prefixKey,n),t=i.createArrayLiteralExpression(s.expression.elements,!0),a=i.createVariableDeclaration(i.createIdentifier(e),void 0,void 0,t),o=i.createVariableDeclarationList([a],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(r,[p,c],r.isDeclarationFile,r.referencedFiles,r.typeReferenceDirectives,r.hasNoDefaultLib,r.libReferenceDirectives)}if(typescript_1.default.isStringLiteral(s.expression)){const e=genName.getName(prefixKey,n),t=i.createStringLiteral(s.expression.text),a=i.createVariableDeclaration(i.createIdentifier(e),void 0,void 0,t),o=i.createVariableDeclarationList([a],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(r,[p,c],r.isDeclarationFile,r.referencedFiles,r.typeReferenceDirectives,r.hasNoDefaultLib,r.libReferenceDirectives)}if(typescript_1.default.isNumericLiteral(s.expression)){const e=genName.getName(prefixKey,n),t=i.createNumericLiteral(s.expression.text),a=i.createVariableDeclaration(i.createIdentifier(e),void 0,void 0,t),o=i.createVariableDeclarationList([a],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(r,[p,c],r.isDeclarationFile,r.referencedFiles,r.typeReferenceDirectives,r.hasNoDefaultLib,r.libReferenceDirectives)}}return typescript_1.default.visitEachChild(s,a,e)};return e=>typescript_1.default.visitNode(e,a)},r,e);return{file:t,content:s,...a}}}function anonymousImportHandler(e){return({file:t,content:i,...a})=>{const r=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),s=(0,transformer_1.default)(e=>{const{factory:i}=e,a=s=>{if(typescript_1.default.isImportDeclaration(s)){const e=s.moduleSpecifier.getText(r),a=node_path_1.default.basename(e).split(".")[0].trim();if(s.importClause?.name&&typescript_1.default.isIdentifier(s.importClause.name)){const e=s.importClause.name.text.trim(),r=exportDefaultExportNameMap.find(e=>e.file===a);if(r){exportDefaultImportNameMap.push({base:e,file:t,newName:r.newName,isEd:!0});const a=i.updateImportClause(s.importClause,s.importClause.phaseModifier,i.createIdentifier(r.newName),s.importClause.namedBindings);return i.updateImportDeclaration(s,s.modifiers,a,s.moduleSpecifier,s.attributes)}}}return typescript_1.default.visitEachChild(s,a,e)};return e=>typescript_1.default.visitNode(e,a)},r,e);return{file:t,content:s,...a}}}const anonymousHandler=async(e,t)=>{resetAnonymousState();const i=(0,resolves_1.default)([[anonymousExportHandler,t],[anonymousImportHandler,t],[anonymousCallExpressionHandler,t]]),a=await i.concurrent();for(const t of a)e=e.map(t);return e},namesMap=new Map,callNameMap=[],importNameMap=[],exportNameMap=[];function __uniqueName(){const e=new Map;return{setPrefix({key:t,value:i}){const a=[];let r;if(e.has(t))throw console.warn(`${t} already exist`),new Error;return r=i,e.set(t,i),{getName:function(e){const t=a.length,i=r?`${r}${e}_${t+1}`:`$nyein${e}_${t+1}`;return a.push(i),i}}},getPrefix(t){if(e.has(t))return e.get(t)}}}let dupName=__uniqueName().setPrefix({key:"DuplicatesNames",value:"__duplicatesNames__"});const resetDuplicateState=()=>{namesMap.clear(),callNameMap.length=0,importNameMap.length=0,exportNameMap.length=0,dupName=__uniqueName().setPrefix({key:"DuplicatesNames",value:"__duplicatesNames__"})},normalizePathKey=e=>{const t=node_path_1.default.parse(e);let i=node_path_1.default.join(t.dir,t.name);return"index"===t.name&&(i=t.dir),node_path_1.default.normalize(i)},getFileKey=e=>normalizePathKey(e),getModuleKeyFromSpecifier=(e,t,i)=>{let a="";if(a=typescript_1.default.isStringLiteral(e)?e.text:e.getText(t).replace(/^['"]|['"]$/g,""),a.startsWith(".")||a.startsWith("/")){const e=node_path_1.default.dirname(i);return normalizePathKey(node_path_1.default.resolve(e,a))}return a},callExpression=e=>({file:t,content:i,...a})=>{const r=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),s=(0,transformer_1.default)(e=>{const{factory:i}=e,a=e=>{const i=callNameMap.find(i=>i.base===e&&i.file===t),a=importNameMap.find(i=>i.base===e&&i.file===t);return i?i.newName:a?a.newName:null},r=t=>{if(typescript_1.default.isCallExpression(t)){if(typescript_1.default.isIdentifier(t.expression)){const e=a(t.expression.text);if(e)return i.updateCallExpression(t,i.createIdentifier(e),t.typeArguments,t.arguments)}}else if(typescript_1.default.isPropertyAccessExpression(t)){if(typescript_1.default.isIdentifier(t.expression)){const e=a(t.expression.text);if(e)return i.updatePropertyAccessExpression(t,i.createIdentifier(e),t.name)}}else if(typescript_1.default.isNewExpression(t)){if(typescript_1.default.isIdentifier(t.expression)){const e=a(t.expression.text);if(e)return i.updateNewExpression(t,i.createIdentifier(e),t.typeArguments,t.arguments)}}else if(typescript_1.default.isIdentifier(t)&&!(e=>{const t=e.parent;return!!(t&&(typescript_1.default.isVariableDeclaration(t)&&t.name===e||(typescript_1.default.isFunctionDeclaration(t)||typescript_1.default.isClassDeclaration(t)||typescript_1.default.isInterfaceDeclaration(t)||typescript_1.default.isTypeAliasDeclaration(t)||typescript_1.default.isEnumDeclaration(t)||typescript_1.default.isParameter(t)||typescript_1.default.isBindingElement(t)||typescript_1.default.isImportClause(t)||typescript_1.default.isNamespaceImport(t)||typescript_1.default.isImportSpecifier(t)||typescript_1.default.isExportSpecifier(t)||typescript_1.default.isTypeParameterDeclaration(t))&&t.name===e||(typescript_1.default.isPropertyDeclaration(t)||typescript_1.default.isMethodDeclaration(t))&&t.name===e))})(t)){if(typescript_1.default.isPropertyAccessExpression(t.parent)&&t.parent.name===t)return t;if(typescript_1.default.isPropertyAssignment(t.parent)&&t.parent.name===t)return t;const e=a(t.text);if(e)return typescript_1.default.isShorthandPropertyAssignment(t.parent)&&t.parent.name===t?i.createPropertyAssignment(i.createIdentifier(t.text),i.createIdentifier(e)):i.createIdentifier(e)}return typescript_1.default.visitEachChild(t,r,e)};return e=>typescript_1.default.visitNode(e,r)},r,e);return{file:t,content:s,...a}},exportExpression=e=>({file:t,content:i,...a})=>{const r=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),s=(0,transformer_1.default)(e=>{const{factory:i}=e,a=r=>{if(typescript_1.default.isExportSpecifier(r)){if(typescript_1.default.isIdentifier(r.name)){const e=r.name.text;let a=null;const s=callNameMap.find(i=>i.base===e&&i.file===t),n=importNameMap.find(i=>i.base===e&&i.file===t);if(s?(exportNameMap.push({base:e,file:getFileKey(t),newName:s.newName}),a=s.newName):n&&(a=n.newName),a)return i.updateExportSpecifier(r,r.isTypeOnly,r.propertyName,i.createIdentifier(a))}}else if(typescript_1.default.isExportAssignment(r)){const e=r.expression;if(typescript_1.default.isIdentifier(e)){const a=e.text;let s=null;const n=callNameMap.find(e=>e.base===a&&e.file===t),o=importNameMap.find(e=>e.base===a&&e.file===t);if(n?(exportNameMap.push({base:a,file:getFileKey(t),newName:n.newName}),s=n.newName):o&&(s=o.newName),s)return i.updateExportAssignment(r,r.modifiers,i.createIdentifier(s))}}return typescript_1.default.visitEachChild(r,a,e)};return e=>typescript_1.default.visitNode(e,a)},r,e);return{file:t,content:s,...a}},importExpression=e=>({file:t,content:i,...a})=>{const r=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),s=(0,transformer_1.default)(e=>{const{factory:i}=e,a=s=>{if(typescript_1.default.isImportDeclaration(s)){const e=getModuleKeyFromSpecifier(s.moduleSpecifier,r,t);let a=[];if(s.importClause?.namedBindings&&typescript_1.default.isNamedImports(s.importClause.namedBindings)&&(a=s.importClause.namedBindings.elements.map(e=>e.name.text.trim())),s.importClause?.name&&typescript_1.default.isIdentifier(s.importClause.name)){const a=s.importClause.name.text.trim(),r=exportNameMap.find(t=>t.base===a&&t.file===e);if(r){importNameMap.push({base:r.base,file:t,newName:r.newName});const e=i.updateImportClause(s.importClause,s.importClause.phaseModifier,i.createIdentifier(r.newName),s.importClause.namedBindings);return i.updateImportDeclaration(s,s.modifiers,e,s.moduleSpecifier,s.attributes)}}if(a.length>0&&s.importClause&&s.importClause.namedBindings&&typescript_1.default.isNamedImports(s.importClause.namedBindings)){const a=s.importClause.namedBindings.elements.map(a=>{const r=exportNameMap.find(t=>t.base===a.name.text.trim()&&t.file===e);return r?(importNameMap.push({base:r.base,file:t,newName:r.newName}),i.updateImportSpecifier(a,a.isTypeOnly,a.propertyName,i.createIdentifier(r.newName))):a}),r=i.updateNamedImports(s.importClause.namedBindings,a),n=i.updateImportClause(s.importClause,s.importClause.phaseModifier,s.importClause.name,r);return i.updateImportDeclaration(s,s.modifiers,n,s.moduleSpecifier,s.attributes)}}return typescript_1.default.visitEachChild(s,a,e)};return e=>typescript_1.default.visitNode(e,a)},r,e);return{file:t,content:s,...a}},collector=e=>({file:t,content:i,...a})=>{const r=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),s=(0,transformer_1.default)(e=>{function i(a,r=!0){if(r)if(typescript_1.default.isVariableStatement(a))a.declarationList.declarations.forEach(e=>{if(typescript_1.default.isIdentifier(e.name)){const i=e.name.text;namesMap.has(i)?namesMap.get(i).add({file:t}):namesMap.set(i,new Set([{file:t}]))}});else if(typescript_1.default.isFunctionDeclaration(a)||typescript_1.default.isClassDeclaration(a)||typescript_1.default.isEnumDeclaration(a)||typescript_1.default.isInterfaceDeclaration(a)||typescript_1.default.isTypeAliasDeclaration(a)){const e=a.name?.text;e&&(namesMap.has(e)?namesMap.get(e).add({file:t}):namesMap.set(e,new Set([{file:t}])))}return typescript_1.default.isBlock(a)||typescript_1.default.isFunctionDeclaration(a)||typescript_1.default.isFunctionExpression(a)||typescript_1.default.isArrowFunction(a)||typescript_1.default.isMethodDeclaration(a)||typescript_1.default.isClassDeclaration(a)?(typescript_1.default.isBlock(a)?typescript_1.default.visitNodes(a.statements,e=>i(e,!1)):typescript_1.default.forEachChild(a,e=>{i(e,!1)}),a):typescript_1.default.visitEachChild(a,e=>i(e,r),e)}return e=>i(e,!0)},r,e);return{file:t,content:s,...a}},updater=e=>({file:t,content:i,...a})=>{const r=typescript_1.default.createSourceFile(t,i,typescript_1.default.ScriptTarget.Latest,!0),s=(0,transformer_1.default)(e=>{const{factory:i}=e,a=r=>{if(typescript_1.default.isVariableStatement(r)){const e=r.declarationList.declarations.map(e=>{if(typescript_1.default.isIdentifier(e.name)){const a=e.name.text;if(namesMap.has(a)&&namesMap.get(a).size>1){const r=dupName.getName(a);return callNameMap.push({base:a,file:t,newName:r}),i.updateVariableDeclaration(e,i.createIdentifier(r),e.exclamationToken,e.type,e.initializer)}}return e}),a=i.updateVariableDeclarationList(r.declarationList,e);return i.updateVariableStatement(r,r.modifiers,a)}if(typescript_1.default.isFunctionDeclaration(r)){if(r.name&&typescript_1.default.isIdentifier(r.name)){const e=r.name.text;if(namesMap.has(e)&&namesMap.get(e).size>1){const a=dupName.getName(e);return callNameMap.push({base:e,file:t,newName:a}),i.updateFunctionDeclaration(r,r.modifiers,r.asteriskToken,i.createIdentifier(a),r.typeParameters,r.parameters,r.type,r.body)}}}else if(typescript_1.default.isClassDeclaration(r)&&r.name&&typescript_1.default.isIdentifier(r.name)){const e=r.name.text;if(namesMap.has(e)&&namesMap.get(e).size>1){const a=dupName.getName(e);return callNameMap.push({base:e,file:t,newName:a}),i.updateClassDeclaration(r,r.modifiers,i.createIdentifier(a),r.typeParameters,r.heritageClauses,r.members)}}return typescript_1.default.visitEachChild(r,a,e)};return e=>typescript_1.default.visitNode(e,a)},r,e);return{file:t,content:s,...a}},duplicateHandlers={renamed:async(e,t)=>{resetDuplicateState();const i=(0,resolves_1.default)([[collector,t],[updater,t],[callExpression,t],[exportExpression,t],[importExpression,t],[callExpression,t],[exportExpression,t]]),a=await i.concurrent();for(const t of a)e=e.map(t);return e},notRenamed:async(e,t)=>{resetDuplicateState();let i=!1;const a=(0,resolves_1.default)([[collector,namesMap,t]]),r=await a.concurrent();return e.map(r[0]),await utils_1.default.wait(1e3),namesMap.forEach((e,t)=>{e.size>1&&(i=!0,console.warn(`Name -> ${t} declared in multiple files :`),e.forEach(e=>console.warn(` - ${e.file}`)))}),await utils_1.default.wait(500),i&&node_process_1.default.exit(1),e}};function mergeImportsStatement(e){const t=new Map,i=new Map,a=new Map,r=new Map,s=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?r:a;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];s.has(l)||s.set(l,new Set),s.get(l)?.add(t)}}else{const e=c?r:a;e.has(l)||e.set(l,new Set),e.get(l)?.add(o.trim())}}const n=[];for(const[e,a]of t){const t=i.get(e)||new Set,r=new Set([...a]);for(const e of t)a.has(e)||r.add(e);if(r.size>0){const t=Array.from(r).sort().join(", ");n.push(`import { ${t} } from "${e}";`)}}for(const[e,a]of i)if(!t.has(e)&&a.size>0){const t=Array.from(a).sort().join(", ");n.push(`import type { ${t} } from "${e}";`)}for(const[e,t]of a){const i=r.get(e)||new Set,a=new Set([...t]);for(const e of i)t.has(e)||a.add(e);if(a.size>0){const t=Array.from(a).join(", ");n.push(`import ${t} from "${e}";`)}}for(const[e,t]of r)if(!a.has(e)&&t.size>0){const i=Array.from(t).join(", ");n.push(`import type ${i} from "${e}";`)}for(const[e,t]of s)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,...a})=>{const r=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=a=>{if(!utils_1.default.check.isInsideNamespace(a)&&(typescript_1.default.isFunctionDeclaration(a)||typescript_1.default.isClassDeclaration(a)||typescript_1.default.isInterfaceDeclaration(a)||typescript_1.default.isTypeAliasDeclaration(a)||typescript_1.default.isEnumDeclaration(a)||typescript_1.default.isVariableStatement(a))){const e=a.modifiers?.filter(e=>e.kind!==typescript_1.default.SyntaxKind.ExportKeyword&&e.kind!==typescript_1.default.SyntaxKind.DefaultKeyword);if(e?.length!==a.modifiers?.length){if(typescript_1.default.isFunctionDeclaration(a))return t.updateFunctionDeclaration(a,e,a.asteriskToken,a.name,a.typeParameters,a.parameters,a.type,a.body);if(typescript_1.default.isClassDeclaration(a))return t.updateClassDeclaration(a,e,a.name,a.typeParameters,a.heritageClauses,a.members);if(typescript_1.default.isInterfaceDeclaration(a))return t.updateInterfaceDeclaration(a,e,a.name,a.typeParameters,a.heritageClauses,a.members);if(typescript_1.default.isTypeAliasDeclaration(a))return t.updateTypeAliasDeclaration(a,e,a.name,a.typeParameters,a.type);if(typescript_1.default.isEnumDeclaration(a))return t.updateEnumDeclaration(a,e,a.name,a.members);if(typescript_1.default.isVariableStatement(a))return t.updateVariableStatement(a,e,a.declarationList)}}if(typescript_1.default.isExportDeclaration(a))return t.createEmptyStatement();if(typescript_1.default.isExportAssignment(a)){const e=a.expression;if(typescript_1.default.isIdentifier(e))return t.createEmptyStatement()}return typescript_1.default.visitEachChild(a,i,e)};return e=>typescript_1.default.visitNode(e,i)},r,e),...a}}}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:a,...r})=>{const s=typescript_1.default.createSourceFile(i,a,typescript_1.default.ScriptTarget.Latest,!0),n=new Set;for(const e of s.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:a}=t,r=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(s,i).isCommonJs&&"ts"!==e&&!n.has(e))return a.updateTypeReferenceNode(o,a.createIdentifier(t),void 0)}if(typescript_1.default.isImportDeclaration(o)){const t=o.getText(s);return e.push(t),a.createEmptyStatement()}if(typescript_1.default.isImportEqualsDeclaration(o)){const t=o.name.text,i=o.moduleReference;let r;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&&(r=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&&(r=`import { ${p.importedObject.join(", ")} } from "${p.source}";`),r)return e.push(r),a.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 r;if(p.importedString&&!p.importedObject&&(r=p.isNamespace?`import * as ${p.importedString} from "${p.source}";`:`import ${p.importedString} from "${p.source}";`),!p.importedString&&p.importedObject&&(r=`import { ${p.importedObject.join(", ")} } from "${p.source}";`),r)return e.push(r),a.createEmptyStatement()}}}return typescript_1.default.visitEachChild(o,r,t)};return e=>typescript_1.default.visitNode(e,r)},s,t);return{file:i,content:o,...r}}}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,a={treatExportsAsUsed:!0}){const r=typescript_1.default.createSourceFile(t,e,typescript_1.default.ScriptTarget.Latest,!0),s=new Map,n=new Set,o=(e,t=!1)=>{const i=s.get(e);s.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(r);const c=new Set;s.forEach((e,t)=>{n.has(t)||a.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 a;const r=[];e.namedBindings&&(typescript_1.default.isNamedImports(e.namedBindings)?e.namedBindings.elements.forEach(e=>{typescript_1.default.isImportSpecifier(e)&&typescript_1.default.isIdentifier(e.name)&&r.push(e)}):typescript_1.default.isNamespaceImport(e.namedBindings)&&typescript_1.default.isIdentifier(e.namedBindings.name)&&(a=e.namedBindings.name.text));const s=!!t&&!c.has(t),n=!!a&&!c.has(a),o=r.filter(e=>!c.has(e.name.text));if(!s&&!n&&0===o.length)return typescript_1.default.factory.createNotEmittedStatement(i);if(!s&&!!e.name||void 0!==a&&!n||o.length!==r.length){let e;e=o.length>0?typescript_1.default.factory.createNamedImports(o):n&&a?typescript_1.default.factory.createNamespaceImport(typescript_1.default.factory.createIdentifier(a)):void 0;const r=s&&t?typescript_1.default.factory.createIdentifier(t):void 0,p=typescript_1.default.factory.createImportClause(!1,r,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)},r,i)}async function preProcessPluginParser(e,t,i){if(e.length)for(const a of e){const e="function"==typeof a?a():a;"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,a=e.tsOptions.default,r=e.plugins;let s=[];t=await anonymousHandler(t,a),t=i?await duplicateHandlers.renamed(t,a):await duplicateHandlers.notRenamed(t,a);const n=await removeHandlers(s,a);t=t.map(n[0]);const o=t.slice(0,-1).map(n[1]),p=t.slice(-1),c=/["']((?!\.\/|\.\.\/)[^"']+)["']/;s=s.filter(e=>c.test(e)),s=mergeImportsStatement(s);let l=`${s.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(),l=clearUnusedCode(l,e.fileName,a),l=await preProcessPluginParser(r,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={},a={getSourceFile:(i,a)=>{if(i===t)return typescript_1.default.createSourceFile(i,e,a)},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:a}}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 a=typescript_1.default.sys.resolvePath("package.json"),r=node_fs_1.default.readFileSync(a,"utf8"),s=JSON.parse(r);let{name:n,version:o,description:p,main:c,module:l,type:f,types:d,exports:u,...m}=s;f="module";let y={},_={},h={},g={};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)}:{},h=e.types?{types:node_path_1.default.relative(node_process_1.default.cwd(),e.types)}:{},g={exports:{...getExports(e,t)}};else{y=c?{main:c}:{},_=l?{module:l}:{},h=d?{types:d}:{};g={exports:{...u&&"object"==typeof u&&!Array.isArray(u)?{...u}:{},...getExports(e,t)}}}const x={name:n,version:o,description:p,type:f,...y,...h,..._,...g,...m};await utils_1.default.file.writeFile(a,JSON.stringify(x,null,2))}const resolveSourceMappingURL=(e,t,i)=>{const a=node_path_1.default.extname(e),r=node_path_1.default.basename(e).split(".")[0],s=new RegExp(`${r}.js.map`,"gm"),n=new RegExp(`${r}.d.ts.map`,"gm"),o="cjs"===i?`${r}.cjs.map`:`${r}.mjs.map`,p="cjs"===i?`${r}.d.cts.map`:`${r}.d.mts.map`;return".js"===a?t.replace(s,o):t.replace(n,p)},postProcessPluginParser=async(e,t,i)=>{if(".js"===node_path_1.default.extname(i)&&e.length)for(let a of e)a="function"==typeof a?a():a,"post-process"===a.type&&(t=a.async?await a.func(t,i):a.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,a=e.bundledContent,r=[...new Set(e.format)],s=e.tsOptions.cjs,n=createHost(a,i),o=n.createdFiles,p=n.host;typescript_1.default.createProgram([i],s,p).emit(),Object.entries(o).map(async([i,a])=>{a=await postProcessPluginParser(e.plugins,a,i),a=resolveSourceMappingURL(i,a,"cjs"),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&&r.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"),r.includes("commonjs")&&!r.includes("esm")&&await utils_1.default.file.clearFolder(node_path_1.default.dirname(i)),await utils_1.default.file.writeFile(i,a)}),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,a=e.bundledContent,r=e.tsOptions.esm,s=createHost(a,i),n=s.createdFiles,o=s.host;typescript_1.default.createProgram([i],r,o).emit(),Object.entries(n).map(async([i,a])=>{a=resolveSourceMappingURL(i,a,"esm"),a=await postProcessPluginParser(e.plugins,a,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,a)}),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, recommend to 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))},getPagInfo=()=>{const e=node_fs_1.default.readFileSync(node_path_1.default.resolve(node_process_1.default.cwd(),"package.json"),"utf8"),t=JSON.parse(e),i=t.name??"",a=t.version??"";let r="";return r=""!==i&&""!==a?`${i}@${a}`:""!==i&&""===a?`${i}`:""===i&&""!==a?`the project@${a}`:"the project",r};async function susee(){console.time(`susee > ${tcolor_1.default.cyan("Done in")}`);const e=getPagInfo();console.time(`susee > ${tcolor_1.default.cyan(`Initialized ${tcolor_1.default.magenta(e)}`)} `);const t=await initializer();finalCheck(t),console.timeEnd(`susee > ${tcolor_1.default.cyan(`Initialized ${tcolor_1.default.magenta(e)}`)} `);const i=await bundle(t),a=new Compiler(i);await a.compile(),console.timeEnd(`susee > ${tcolor_1.default.cyan("Done in")}`)}
|
|
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] "))}
|