rolldown-require 1.0.4 → 1.0.6

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/dist/index.d.cts 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
- declare function loadFromBundledFile(fileName: string, bundledCode: string, options: InternalOptions): Promise<any>;
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[];
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
- declare function loadFromBundledFile(fileName: string, bundledCode: string, options: InternalOptions): Promise<any>;
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[];