UNPKG

11 kBTypeScriptView Raw
1/**
2 * https://github.com/rollup/plugins/blob/master/packages/commonjs/types/index.d.ts
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file at
6 * https://github.com/rollup/plugins/blob/master/LICENSE
7 */
8export interface RollupCommonJSOptions {
9 /**
10 * A minimatch pattern, or array of patterns, which specifies the files in
11 * the build the plugin should operate on. By default, all files with
12 * extension `".cjs"` or those in `extensions` are included, but you can
13 * narrow this list by only including specific files. These files will be
14 * analyzed and transpiled if either the analysis does not find ES module
15 * specific statements or `transformMixedEsModules` is `true`.
16 * @default undefined
17 */
18 include?: string | RegExp | readonly (string | RegExp)[]
19 /**
20 * A minimatch pattern, or array of patterns, which specifies the files in
21 * the build the plugin should _ignore_. By default, all files with
22 * extensions other than those in `extensions` or `".cjs"` are ignored, but you
23 * can exclude additional files. See also the `include` option.
24 * @default undefined
25 */
26 exclude?: string | RegExp | readonly (string | RegExp)[]
27 /**
28 * For extensionless imports, search for extensions other than .js in the
29 * order specified. Note that you need to make sure that non-JavaScript files
30 * are transpiled by another plugin first.
31 * @default [ '.js' ]
32 */
33 extensions?: ReadonlyArray<string>
34 /**
35 * If true then uses of `global` won't be dealt with by this plugin
36 * @default false
37 */
38 ignoreGlobal?: boolean
39 /**
40 * If false, skips source map generation for CommonJS modules. This will
41 * improve performance.
42 * @default true
43 */
44 sourceMap?: boolean
45 /**
46 * Some `require` calls cannot be resolved statically to be translated to
47 * imports.
48 * When this option is set to `false`, the generated code will either
49 * directly throw an error when such a call is encountered or, when
50 * `dynamicRequireTargets` is used, when such a call cannot be resolved with a
51 * configured dynamic require target.
52 * Setting this option to `true` will instead leave the `require` call in the
53 * code or use it as a fallback for `dynamicRequireTargets`.
54 * @default false
55 */
56 ignoreDynamicRequires?: boolean
57 /**
58 * Instructs the plugin whether to enable mixed module transformations. This
59 * is useful in scenarios with modules that contain a mix of ES `import`
60 * statements and CommonJS `require` expressions. Set to `true` if `require`
61 * calls should be transformed to imports in mixed modules, or `false` if the
62 * `require` expressions should survive the transformation. The latter can be
63 * important if the code contains environment detection, or you are coding
64 * for an environment with special treatment for `require` calls such as
65 * ElectronJS. See also the `ignore` option.
66 * @default false
67 */
68 transformMixedEsModules?: boolean
69 /**
70 * By default, this plugin will try to hoist `require` statements as imports
71 * to the top of each file. While this works well for many code bases and
72 * allows for very efficient ESM output, it does not perfectly capture
73 * CommonJS semantics as the order of side effects like log statements may
74 * change. But it is especially problematic when there are circular `require`
75 * calls between CommonJS modules as those often rely on the lazy execution of
76 * nested `require` calls.
77 *
78 * Setting this option to `true` will wrap all CommonJS files in functions
79 * which are executed when they are required for the first time, preserving
80 * NodeJS semantics. Note that this can have an impact on the size and
81 * performance of the generated code.
82 *
83 * The default value of `"auto"` will only wrap CommonJS files when they are
84 * part of a CommonJS dependency cycle, e.g. an index file that is required by
85 * many of its dependencies. All other CommonJS files are hoisted. This is the
86 * recommended setting for most code bases.
87 *
88 * `false` will entirely prevent wrapping and hoist all files. This may still
89 * work depending on the nature of cyclic dependencies but will often cause
90 * problems.
91 *
92 * You can also provide a minimatch pattern, or array of patterns, to only
93 * specify a subset of files which should be wrapped in functions for proper
94 * `require` semantics.
95 *
96 * `"debug"` works like `"auto"` but after bundling, it will display a warning
97 * containing a list of ids that have been wrapped which can be used as
98 * minimatch pattern for fine-tuning.
99 * @default "auto"
100 */
101 strictRequires?: boolean | string | RegExp | readonly (string | RegExp)[]
102 /**
103 * Sometimes you have to leave require statements unconverted. Pass an array
104 * containing the IDs or a `id => boolean` function.
105 * @default []
106 */
107 ignore?: ReadonlyArray<string> | ((id: string) => boolean)
108 /**
109 * In most cases, where `require` calls are inside a `try-catch` clause,
110 * they should be left unconverted as it requires an optional dependency
111 * that may or may not be installed beside the rolled up package.
112 * Due to the conversion of `require` to a static `import` - the call is
113 * hoisted to the top of the file, outside of the `try-catch` clause.
114 *
115 * - `true`: All `require` calls inside a `try` will be left unconverted.
116 * - `false`: All `require` calls inside a `try` will be converted as if the
117 * `try-catch` clause is not there.
118 * - `remove`: Remove all `require` calls from inside any `try` block.
119 * - `string[]`: Pass an array containing the IDs to left unconverted.
120 * - `((id: string) => boolean|'remove')`: Pass a function that control
121 * individual IDs.
122 *
123 * @default false
124 */
125 ignoreTryCatch?:
126 | boolean
127 | 'remove'
128 | ReadonlyArray<string>
129 | ((id: string) => boolean | 'remove')
130 /**
131 * Controls how to render imports from external dependencies. By default,
132 * this plugin assumes that all external dependencies are CommonJS. This
133 * means they are rendered as default imports to be compatible with e.g.
134 * NodeJS where ES modules can only import a default export from a CommonJS
135 * dependency.
136 *
137 * If you set `esmExternals` to `true`, this plugins assumes that all
138 * external dependencies are ES modules and respect the
139 * `requireReturnsDefault` option. If that option is not set, they will be
140 * rendered as namespace imports.
141 *
142 * You can also supply an array of ids to be treated as ES modules, or a
143 * function that will be passed each external id to determine if it is an ES
144 * module.
145 * @default false
146 */
147 esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean)
148 /**
149 * Controls what is returned when requiring an ES module from a CommonJS file.
150 * When using the `esmExternals` option, this will also apply to external
151 * modules. By default, this plugin will render those imports as namespace
152 * imports i.e.
153 *
154 * ```js
155 * // input
156 * const foo = require('foo');
157 *
158 * // output
159 * import * as foo from 'foo';
160 * ```
161 *
162 * However there are some situations where this may not be desired.
163 * For these situations, you can change Rollup's behaviour either globally or
164 * per module. To change it globally, set the `requireReturnsDefault` option
165 * to one of the following values:
166 *
167 * - `false`: This is the default, requiring an ES module returns its
168 * namespace. This is the only option that will also add a marker
169 * `__esModule: true` to the namespace to support interop patterns in
170 * CommonJS modules that are transpiled ES modules.
171 * - `"namespace"`: Like `false`, requiring an ES module returns its
172 * namespace, but the plugin does not add the `__esModule` marker and thus
173 * creates more efficient code. For external dependencies when using
174 * `esmExternals: true`, no additional interop code is generated.
175 * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
176 * Rollup: If a module has a default export and no named exports, requiring
177 * that module returns the default export. In all other cases, the namespace
178 * is returned. For external dependencies when using `esmExternals: true`, a
179 * corresponding interop helper is added.
180 * - `"preferred"`: If a module has a default export, requiring that module
181 * always returns the default export, no matter whether additional named
182 * exports exist. This is similar to how previous versions of this plugin
183 * worked. Again for external dependencies when using `esmExternals: true`,
184 * an interop helper is added.
185 * - `true`: This will always try to return the default export on require
186 * without checking if it actually exists. This can throw at build time if
187 * there is no default export. This is how external dependencies are handled
188 * when `esmExternals` is not used. The advantage over the other options is
189 * that, like `false`, this does not add an interop helper for external
190 * dependencies, keeping the code lean.
191 *
192 * To change this for individual modules, you can supply a function for
193 * `requireReturnsDefault` instead. This function will then be called once for
194 * each required ES module or external dependency with the corresponding id
195 * and allows you to return different values for different modules.
196 * @default false
197 */
198 requireReturnsDefault?:
199 | boolean
200 | 'auto'
201 | 'preferred'
202 | 'namespace'
203 | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')
204
205 /**
206 * @default "auto"
207 */
208 defaultIsModuleExports?: boolean | 'auto' | ((id: string) => boolean | 'auto')
209 /**
210 * Some modules contain dynamic `require` calls, or require modules that
211 * contain circular dependencies, which are not handled well by static
212 * imports. Including those modules as `dynamicRequireTargets` will simulate a
213 * CommonJS (NodeJS-like) environment for them with support for dynamic
214 * dependencies. It also enables `strictRequires` for those modules.
215 *
216 * Note: In extreme cases, this feature may result in some paths being
217 * rendered as absolute in the final bundle. The plugin tries to avoid
218 * exposing paths from the local machine, but if you are `dynamicRequirePaths`
219 * with paths that are far away from your project's folder, that may require
220 * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
221 */
222 dynamicRequireTargets?: string | ReadonlyArray<string>
223 /**
224 * To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
225 * that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
226 * may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
227 * home directory name. By default it uses the current working directory.
228 */
229 dynamicRequireRoot?: string
230}
231
\No newline at end of file