1 | import type { FilterPattern } from '@rollup/pluginutils';
|
2 | import type { Plugin } from 'rollup';
|
3 |
|
4 | type RequireReturnsDefaultOption = boolean | 'auto' | 'preferred' | 'namespace';
|
5 | type DefaultIsModuleExportsOption = boolean | 'auto';
|
6 |
|
7 | interface RollupCommonJSOptions {
|
8 | |
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | include?: FilterPattern;
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | exclude?: FilterPattern;
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | extensions?: ReadonlyArray<string>;
|
33 | |
34 |
|
35 |
|
36 |
|
37 | ignoreGlobal?: boolean;
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | sourceMap?: boolean;
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | ignoreDynamicRequires?: boolean;
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | transformMixedEsModules?: boolean;
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | strictRequires?: boolean | FilterPattern;
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 | ignore?: ReadonlyArray<string> | ((id: string) => boolean);
|
107 | /**
|
108 | * In most cases, where `require` calls are inside a `try-catch` clause,
|
109 | * they should be left unconverted as it requires an optional dependency
|
110 | * that may or may not be installed beside the rolled up package.
|
111 | * Due to the conversion of `require` to a static `import` - the call is
|
112 | * hoisted to the top of the file, outside the `try-catch` clause.
|
113 | *
|
114 | * - `true`: Default. All `require` calls inside a `try` will be left unconverted.
|
115 | * - `false`: All `require` calls inside a `try` will be converted as if the
|
116 | * `try-catch` clause is not there.
|
117 | * - `remove`: Remove all `require` calls from inside any `try` block.
|
118 | * - `string[]`: Pass an array containing the IDs to left unconverted.
|
119 | * - `((id: string) => boolean|'remove')`: Pass a function that controls
|
120 | * individual IDs.
|
121 | *
|
122 | * @default true
|
123 | */
|
124 | ignoreTryCatch?:
|
125 | | boolean
|
126 | | 'remove'
|
127 | | ReadonlyArray<string>
|
128 | | ((id: string) => boolean | 'remove');
|
129 | /**
|
130 | * Controls how to render imports from external dependencies. By default,
|
131 | * this plugin assumes that all external dependencies are CommonJS. This
|
132 | * means they are rendered as default imports to be compatible with e.g.
|
133 | * NodeJS where ES modules can only import a default export from a CommonJS
|
134 | * dependency.
|
135 | *
|
136 | * If you set `esmExternals` to `true`, this plugin assumes that all
|
137 | * external dependencies are ES modules and respect the
|
138 | * `requireReturnsDefault` option. If that option is not set, they will be
|
139 | * rendered as namespace imports.
|
140 | *
|
141 | * You can also supply an array of ids to be treated as ES modules, or a
|
142 | * function that will be passed each external id to determine whether it is
|
143 | * an ES module.
|
144 | * @default false
|
145 | */
|
146 | esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean);
|
147 | /**
|
148 | * Controls what is returned when requiring an ES module from a CommonJS file.
|
149 | * When using the `esmExternals` option, this will also apply to external
|
150 | * modules. By default, this plugin will render those imports as namespace
|
151 | * imports i.e.
|
152 | *
|
153 | * ```js
|
154 | * // input
|
155 | * const foo = require('foo');
|
156 | *
|
157 | * // output
|
158 | * import * as foo from 'foo';
|
159 | * ```
|
160 | *
|
161 | * However, there are some situations where this may not be desired.
|
162 | * For these situations, you can change Rollup's behaviour either globally or
|
163 | * per module. To change it globally, set the `requireReturnsDefault` option
|
164 | * to one of the following values:
|
165 | *
|
166 | * - `false`: This is the default, requiring an ES module returns its
|
167 | * namespace. This is the only option that will also add a marker
|
168 | * `__esModule: true` to the namespace to support interop patterns in
|
169 | * CommonJS modules that are transpiled ES modules.
|
170 | * - `"namespace"`: Like `false`, requiring an ES module returns its
|
171 | * namespace, but the plugin does not add the `__esModule` marker and thus
|
172 | * creates more efficient code. For external dependencies when using
|
173 | * `esmExternals: true`, no additional interop code is generated.
|
174 | * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
|
175 | * Rollup: If a module has a default export and no named exports, requiring
|
176 | * that module returns the default export. In all other cases, the namespace
|
177 | * is returned. For external dependencies when using `esmExternals: true`, a
|
178 | * corresponding interop helper is added.
|
179 | * - `"preferred"`: If a module has a default export, requiring that module
|
180 | * always returns the default export, no matter whether additional named
|
181 | * exports exist. This is similar to how previous versions of this plugin
|
182 | * worked. Again for external dependencies when using `esmExternals: true`,
|
183 | * an interop helper is added.
|
184 | * - `true`: This will always try to return the default export on require
|
185 | * without checking if it actually exists. This can throw at build time if
|
186 | * there is no default export. This is how external dependencies are handled
|
187 | * when `esmExternals` is not used. The advantage over the other options is
|
188 | * that, like `false`, this does not add an interop helper for external
|
189 | * dependencies, keeping the code lean.
|
190 | *
|
191 | * To change this for individual modules, you can supply a function for
|
192 | * `requireReturnsDefault` instead. This function will then be called once for
|
193 | * each required ES module or external dependency with the corresponding id
|
194 | * and allows you to return different values for different modules.
|
195 | * @default false
|
196 | */
|
197 | requireReturnsDefault?:
|
198 | | RequireReturnsDefaultOption
|
199 | | ((id: string) => RequireReturnsDefaultOption);
|
200 |
|
201 | /**
|
202 | * @default "auto"
|
203 | */
|
204 | defaultIsModuleExports?:
|
205 | | DefaultIsModuleExportsOption
|
206 | | ((id: string) => DefaultIsModuleExportsOption);
|
207 | /**
|
208 | * Some modules contain dynamic `require` calls, or require modules that
|
209 | * contain circular dependencies, which are not handled well by static
|
210 | * imports. Including those modules as `dynamicRequireTargets` will simulate a
|
211 | * CommonJS (NodeJS-like) environment for them with support for dynamic
|
212 | * dependencies. It also enables `strictRequires` for those modules.
|
213 | *
|
214 | * Note: In extreme cases, this feature may result in some paths being
|
215 | * rendered as absolute in the final bundle. The plugin tries to avoid
|
216 | * exposing paths from the local machine, but if you are `dynamicRequirePaths`
|
217 | * with paths that are far away from your project's folder, that may require
|
218 | * replacing strings like `"/Users/John/Desktop/foo-project/"` -> `"/"`.
|
219 | */
|
220 | dynamicRequireTargets?: string | ReadonlyArray<string>;
|
221 | /**
|
222 | * To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
|
223 | * that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
|
224 | * may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
|
225 | * home directory name. By default, it uses the current working directory.
|
226 | */
|
227 | dynamicRequireRoot?: string;
|
228 | }
|
229 |
|
230 | /**
|
231 | * Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
|
232 | */
|
233 | export default function commonjs(options?: RollupCommonJSOptions): Plugin;
|
234 |
|
\ | No newline at end of file |