rolldown-require 1.0.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/index.d.ts +37 -1
- package/dist/index.mjs +627 -244
- package/package.json +6 -6
- package/dist/index.cjs +0 -1190
- package/dist/index.d.cts +0 -80
package/README.md
CHANGED
|
@@ -119,6 +119,39 @@ This library is published as part of [weapp-vite](https://github.com/weapp-vite/
|
|
|
119
119
|
|
|
120
120
|
The library is under active development. If you encounter any issues or have suggestions, please feel free to open an issue on [GitHub Issues](https://github.com/weapp-vite/weapp-vite/issues).
|
|
121
121
|
|
|
122
|
+
## Benchmarks
|
|
123
|
+
|
|
124
|
+
`pnpm --filter rolldown-require-bench benchmark` (10 cold iterations, local M3, Node 22.21.1):
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
Scenario: tiny-static (25 modules)
|
|
128
|
+
rolldown-require | avg 60.52ms | median 58.36ms | deps 26 | rssΔ median 1.02 MB
|
|
129
|
+
unrun | avg 61.16ms | median 61.32ms | deps 26 | rssΔ median 0.64 MB
|
|
130
|
+
|
|
131
|
+
Scenario: medium-mixed (100 modules, dynamic import every 10)
|
|
132
|
+
rolldown-require | avg 49.85ms | median 46.38ms | deps 102 | rssΔ median 2.29 MB
|
|
133
|
+
unrun | avg 52.30ms | median 30.49ms | deps 101 | rssΔ median 1.44 MB
|
|
134
|
+
|
|
135
|
+
Scenario: large-static (200 modules)
|
|
136
|
+
rolldown-require | avg 55.47ms | median 45.89ms | deps 201 | rssΔ median 2.86 MB
|
|
137
|
+
unrun | avg 64.54ms | median 50.02ms | deps 201 | rssΔ median 1.33 MB
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Notes:
|
|
141
|
+
|
|
142
|
+
- Fixtures are synthetic TS module graphs (static and mixed dynamic imports) generated in `packages/rolldown-require-bench/benchmark/index.mjs`.
|
|
143
|
+
- Each unrun iteration clears `.unrun` caches to force cold runs. Use `BENCH_ITERATIONS` to change repetitions.
|
|
144
|
+
|
|
145
|
+
### Takeaways
|
|
146
|
+
|
|
147
|
+
- With 10 cold iterations on synthetic graphs, rolldown-require remains generally faster (avg/median) across scenarios; unrun shows lower RSS deltas.
|
|
148
|
+
- Dependency counts align (same or near-same), indicating comparable graph coverage.
|
|
149
|
+
- Numbers come from `packages/rolldown-require-bench/benchmark/index.mjs` on M3/Node 22.21.1; rerun on your workloads for final decisions.
|
|
150
|
+
|
|
151
|
+
### Cache
|
|
152
|
+
|
|
153
|
+
- `cache: true` or `{ enabled: true, dir?, reset?, onEvent? }` enables persistent bundled output (default dir: nearest `node_modules/.rolldown-require-cache` or OS tmp). Validates mtime/size of entry + deps before reuse; falls back to rebuild when stale.
|
|
154
|
+
|
|
122
155
|
## License
|
|
123
156
|
|
|
124
157
|
MIT © [sonofmagic](https://github.com/sonofmagic)
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,35 @@ import { InputOptions, OutputOptions, ExternalOption } from 'rolldown';
|
|
|
3
3
|
type RequireFunction = (outfile: string, ctx: {
|
|
4
4
|
format: 'cjs' | 'esm';
|
|
5
5
|
}) => any;
|
|
6
|
+
interface CacheEvent {
|
|
7
|
+
type: 'hit' | 'miss' | 'store' | 'skip-invalid';
|
|
8
|
+
key: string;
|
|
9
|
+
reason?: string;
|
|
10
|
+
}
|
|
11
|
+
interface CacheOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Enable persistent cache. Pass an object to configure.
|
|
14
|
+
*/
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Optional cache directory. Defaults to nearest `node_modules/.rolldown-require-cache`
|
|
18
|
+
* or `os.tmpdir()/rolldown-require-cache`.
|
|
19
|
+
*/
|
|
20
|
+
dir?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Clear any existing cache entry before writing a new one.
|
|
23
|
+
*/
|
|
24
|
+
reset?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Also keep a process-local in-memory cache to skip filesystem hits.
|
|
27
|
+
* Defaults to true when persistent cache is enabled.
|
|
28
|
+
*/
|
|
29
|
+
memory?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Receive cache events for debugging/metrics.
|
|
32
|
+
*/
|
|
33
|
+
onEvent?: (event: CacheEvent) => void;
|
|
34
|
+
}
|
|
6
35
|
type GetOutputFile = (filepath: string, format: 'esm' | 'cjs') => string;
|
|
7
36
|
interface Options {
|
|
8
37
|
cwd?: string;
|
|
@@ -55,6 +84,10 @@ interface Options {
|
|
|
55
84
|
* to skip the default format inference
|
|
56
85
|
*/
|
|
57
86
|
format?: 'cjs' | 'esm';
|
|
87
|
+
/**
|
|
88
|
+
* Persistent cache for bundled output to speed up repeated loads.
|
|
89
|
+
*/
|
|
90
|
+
cache?: boolean | CacheOptions;
|
|
58
91
|
}
|
|
59
92
|
interface InternalOptions extends Omit<Options, 'cwd' | 'filepath'> {
|
|
60
93
|
isESM: boolean;
|
|
@@ -67,11 +100,14 @@ declare const configDefaults: Readonly<{
|
|
|
67
100
|
extensions: string[];
|
|
68
101
|
};
|
|
69
102
|
}>;
|
|
103
|
+
|
|
70
104
|
declare function bundleFile(fileName: string, options: InternalOptions): Promise<{
|
|
71
105
|
code: string;
|
|
72
106
|
dependencies: string[];
|
|
73
107
|
}>;
|
|
74
|
-
|
|
108
|
+
|
|
109
|
+
declare function loadFromBundledFile(fileName: string, bundledCode: string, options: InternalOptions, dependencies?: string[]): Promise<any>;
|
|
110
|
+
|
|
75
111
|
declare function bundleRequire<T = any>(options: Options): Promise<{
|
|
76
112
|
mod: T;
|
|
77
113
|
dependencies: string[];
|