rolldown-plugin-require-cjs 0.1.4 → 0.2.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 +38 -0
- package/dist/index.d.ts +11 -4
- package/dist/index.js +24 -10861
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -18,6 +18,44 @@ See more: https://x.com/sanxiaozhizi/status/1968580207322808812
|
|
|
18
18
|
npm i rolldown-plugin-require-cjs
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
## Options
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
export interface Options {
|
|
25
|
+
include?: Array<string | RegExp> | string | RegExp
|
|
26
|
+
exclude?: Array<string | RegExp> | string | RegExp
|
|
27
|
+
order?: 'pre' | 'post' | undefined
|
|
28
|
+
/**
|
|
29
|
+
* A function to determine whether a module should be transformed.
|
|
30
|
+
* Return `true` to force transformation, `false` to skip transformation,
|
|
31
|
+
* or `undefined` to let the plugin decide automatically.
|
|
32
|
+
*/
|
|
33
|
+
shouldTransform?: string[] | TransformFn
|
|
34
|
+
/**
|
|
35
|
+
* Whether to transform Node.js built-in modules (e.g., `fs`, `path`)
|
|
36
|
+
* to `process.getBuiltinModule()` calls, which has the best performance.
|
|
37
|
+
*
|
|
38
|
+
* Note: `process.getBuiltinModule` is available since Node.js 20.16.0 and 22.3.0.
|
|
39
|
+
*/
|
|
40
|
+
builtinNodeModules?: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @returns A boolean or a promise that resolves to a boolean,
|
|
45
|
+
* or `undefined` to let the plugin decide automatically.
|
|
46
|
+
*/
|
|
47
|
+
export type TransformFn = (
|
|
48
|
+
/**
|
|
49
|
+
* The module ID (path) being imported.
|
|
50
|
+
*/
|
|
51
|
+
id: string,
|
|
52
|
+
/**
|
|
53
|
+
* The module ID (path) of the importer.
|
|
54
|
+
*/
|
|
55
|
+
importer: string,
|
|
56
|
+
) => Awaitable<boolean | undefined | void>
|
|
57
|
+
```
|
|
58
|
+
|
|
21
59
|
## Example
|
|
22
60
|
|
|
23
61
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { Plugin } from "rolldown";
|
|
|
3
3
|
//#region src/options.d.ts
|
|
4
4
|
type FilterPattern = Array<string | RegExp> | string | RegExp;
|
|
5
5
|
type Awaitable<T> = T | Promise<T>;
|
|
6
|
+
/**
|
|
7
|
+
* @returns A boolean or a promise that resolves to a boolean,
|
|
8
|
+
* or `undefined` to let the plugin decide automatically.
|
|
9
|
+
*/
|
|
6
10
|
type TransformFn = (id: string, importer: string) => Awaitable<boolean | undefined | void>;
|
|
7
11
|
interface Options {
|
|
8
12
|
include?: FilterPattern;
|
|
@@ -12,12 +16,15 @@ interface Options {
|
|
|
12
16
|
* A function to determine whether a module should be transformed.
|
|
13
17
|
* Return `true` to force transformation, `false` to skip transformation,
|
|
14
18
|
* or `undefined` to let the plugin decide automatically.
|
|
15
|
-
*
|
|
16
|
-
* @param id The module ID (path) being imported.
|
|
17
|
-
* @param importer The module ID (path) of the importer.
|
|
18
|
-
* @returns A boolean or a promise that resolves to a boolean, or `undefined`.
|
|
19
19
|
*/
|
|
20
20
|
shouldTransform?: string[] | TransformFn;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to transform Node.js built-in modules (e.g., `fs`, `path`)
|
|
23
|
+
* to `process.getBuiltinModule()` calls, which has the best performance.
|
|
24
|
+
*
|
|
25
|
+
* Note: `process.getBuiltinModule` is available since Node.js 20.16.0 and 22.3.0.
|
|
26
|
+
*/
|
|
27
|
+
builtinNodeModules?: boolean;
|
|
21
28
|
}
|
|
22
29
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
23
30
|
type OptionsResolved = Overwrite<Required<Options>, Pick<Options, "order"> & {
|