@rollup/plugin-commonjs 21.0.1 → 22.0.0-3
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 +34 -6
- package/dist/index.es.js +898 -795
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +896 -793
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/types/index.d.ts +52 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rollup/plugin-commonjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0-3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"main": "dist/index.js",
|
|
17
17
|
"module": "dist/index.es.js",
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
19
|
+
"node": ">= 12.0.0"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "rollup -c",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"require"
|
|
48
48
|
],
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"rollup": "^2.
|
|
50
|
+
"rollup": "^2.60.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@rollup/pluginutils": "^3.1.0",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@rollup/plugin-json": "^4.1.0",
|
|
63
|
-
"@rollup/plugin-node-resolve": "^
|
|
63
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
64
64
|
"locate-character": "^2.0.5",
|
|
65
65
|
"require-relative": "^0.8.7",
|
|
66
|
-
"rollup": "^2.
|
|
66
|
+
"rollup": "^2.60.0",
|
|
67
67
|
"shx": "^0.3.2",
|
|
68
68
|
"source-map": "^0.7.3",
|
|
69
69
|
"source-map-support": "^0.5.19",
|
package/types/index.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ interface RollupCommonJSOptions {
|
|
|
7
7
|
/**
|
|
8
8
|
* A minimatch pattern, or array of patterns, which specifies the files in
|
|
9
9
|
* the build the plugin should operate on. By default, all files with
|
|
10
|
-
* extension `".cjs"` or those in `extensions` are included, but you can
|
|
11
|
-
* this list by only including specific files. These files will be
|
|
12
|
-
* and transpiled if either the analysis does not find ES module
|
|
13
|
-
* statements or `transformMixedEsModules` is `true`.
|
|
10
|
+
* extension `".cjs"` or those in `extensions` are included, but you can
|
|
11
|
+
* narrow this list by only including specific files. These files will be
|
|
12
|
+
* analyzed and transpiled if either the analysis does not find ES module
|
|
13
|
+
* specific statements or `transformMixedEsModules` is `true`.
|
|
14
14
|
* @default undefined
|
|
15
15
|
*/
|
|
16
16
|
include?: FilterPattern;
|
|
@@ -64,6 +64,39 @@ interface RollupCommonJSOptions {
|
|
|
64
64
|
* @default false
|
|
65
65
|
*/
|
|
66
66
|
transformMixedEsModules?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* By default, this plugin will try to hoist `require` statements as imports
|
|
69
|
+
* to the top of each file. While this works well for many code bases and
|
|
70
|
+
* allows for very efficient ESM output, it does not perfectly capture
|
|
71
|
+
* CommonJS semantics as the order of side effects like log statements may
|
|
72
|
+
* change. But it is especially problematic when there are circular `require`
|
|
73
|
+
* calls between CommonJS modules as those often rely on the lazy execution of
|
|
74
|
+
* nested `require` calls.
|
|
75
|
+
*
|
|
76
|
+
* Setting this option to `true` will wrap all CommonJS files in functions
|
|
77
|
+
* which are executed when they are required for the first time, preserving
|
|
78
|
+
* NodeJS semantics. Note that this can have an impact on the size and
|
|
79
|
+
* performance of the generated code.
|
|
80
|
+
*
|
|
81
|
+
* The default value of `"auto"` will only wrap CommonJS files when they are
|
|
82
|
+
* part of a CommonJS dependency cycle, e.g. an index file that is required by
|
|
83
|
+
* many of its dependencies. All other CommonJS files are hoisted. This is the
|
|
84
|
+
* recommended setting for most code bases.
|
|
85
|
+
*
|
|
86
|
+
* `false` will entirely prevent wrapping and hoist all files. This may still
|
|
87
|
+
* work depending on the nature of cyclic dependencies but will often cause
|
|
88
|
+
* problems.
|
|
89
|
+
*
|
|
90
|
+
* You can also provide a minimatch pattern, or array of patterns, to only
|
|
91
|
+
* specify a subset of files which should be wrapped in functions for proper
|
|
92
|
+
* `require` semantics.
|
|
93
|
+
*
|
|
94
|
+
* `"debug"` works like `"auto"` but after bundling, it will display a warning
|
|
95
|
+
* containing a list of ids that have been wrapped which can be used as
|
|
96
|
+
* minimatch pattern for fine-tuning.
|
|
97
|
+
* @default "auto"
|
|
98
|
+
*/
|
|
99
|
+
strictRequires?: boolean | FilterPattern;
|
|
67
100
|
/**
|
|
68
101
|
* Sometimes you have to leave require statements unconverted. Pass an array
|
|
69
102
|
* containing the IDs or a `id => boolean` function.
|
|
@@ -74,14 +107,16 @@ interface RollupCommonJSOptions {
|
|
|
74
107
|
* In most cases, where `require` calls are inside a `try-catch` clause,
|
|
75
108
|
* they should be left unconverted as it requires an optional dependency
|
|
76
109
|
* 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
|
|
78
|
-
* to the top of the file, outside of the `try-catch` clause.
|
|
110
|
+
* Due to the conversion of `require` to a static `import` - the call is
|
|
111
|
+
* hoisted to the top of the file, outside of the `try-catch` clause.
|
|
79
112
|
*
|
|
80
113
|
* - `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
|
|
114
|
+
* - `false`: All `require` calls inside a `try` will be converted as if the
|
|
115
|
+
* `try-catch` clause is not there.
|
|
82
116
|
* - `remove`: Remove all `require` calls from inside any `try` block.
|
|
83
117
|
* - `string[]`: Pass an array containing the IDs to left unconverted.
|
|
84
|
-
* - `((id: string) => boolean|'remove')`: Pass a function that control
|
|
118
|
+
* - `((id: string) => boolean|'remove')`: Pass a function that control
|
|
119
|
+
* individual IDs.
|
|
85
120
|
*
|
|
86
121
|
* @default false
|
|
87
122
|
*/
|
|
@@ -165,8 +200,8 @@ interface RollupCommonJSOptions {
|
|
|
165
200
|
* Some modules contain dynamic `require` calls, or require modules that
|
|
166
201
|
* contain circular dependencies, which are not handled well by static
|
|
167
202
|
* imports. Including those modules as `dynamicRequireTargets` will simulate a
|
|
168
|
-
* CommonJS (NodeJS-like) environment for them with support for dynamic
|
|
169
|
-
*
|
|
203
|
+
* CommonJS (NodeJS-like) environment for them with support for dynamic
|
|
204
|
+
* dependencies. It also enables `strictRequires` for those modules.
|
|
170
205
|
*
|
|
171
206
|
* Note: In extreme cases, this feature may result in some paths being
|
|
172
207
|
* rendered as absolute in the final bundle. The plugin tries to avoid
|
|
@@ -175,6 +210,13 @@ interface RollupCommonJSOptions {
|
|
|
175
210
|
* replacing strings like `"/Users/John/Desktop/foo-project/"` -> `"/"`.
|
|
176
211
|
*/
|
|
177
212
|
dynamicRequireTargets?: string | ReadonlyArray<string>;
|
|
213
|
+
/**
|
|
214
|
+
* To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
|
|
215
|
+
* that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
|
|
216
|
+
* may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
|
|
217
|
+
* home directory name. By default it uses the current working directory.
|
|
218
|
+
*/
|
|
219
|
+
dynamicRequireRoot?: string;
|
|
178
220
|
}
|
|
179
221
|
|
|
180
222
|
/**
|