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