@rollup/plugin-babel 5.2.3 → 5.3.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/CHANGELOG.md +14 -0
- package/README.md +16 -1
- package/dist/index.es.js +11 -4
- package/dist/index.js +11 -4
- package/package.json +1 -1
- package/types/index.d.ts +42 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @rollup/plugin-babel ChangeLog
|
|
2
2
|
|
|
3
|
+
## v5.3.0
|
|
4
|
+
|
|
5
|
+
_2021-02-14_
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- feat: add custom filter option (#767)
|
|
10
|
+
- feat: pass rollup context as this context into override config function (#784)
|
|
11
|
+
|
|
12
|
+
### Updates
|
|
13
|
+
|
|
14
|
+
- docs: typo in README.md (#800)
|
|
15
|
+
- chore: commit updated readme format (bfda6d8)
|
|
16
|
+
|
|
3
17
|
## v5.2.3
|
|
4
18
|
|
|
5
19
|
_2021-01-29_
|
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ All options are as per the [Babel documentation](https://babeljs.io/docs/en/opti
|
|
|
84
84
|
|
|
85
85
|
Type: `String | RegExp | Array[...String|RegExp]`<br>
|
|
86
86
|
|
|
87
|
-
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. When
|
|
87
|
+
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. When relying on Babel configuration files you can only exclude additional files with this option, you cannot override what you have configured for Babel itself.
|
|
88
88
|
|
|
89
89
|
### `include`
|
|
90
90
|
|
|
@@ -92,6 +92,21 @@ Type: `String | RegExp | Array[...String|RegExp]`<br>
|
|
|
92
92
|
|
|
93
93
|
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should operate on. When relying on Babel configuration files you cannot include files already excluded there.
|
|
94
94
|
|
|
95
|
+
### `filter`
|
|
96
|
+
|
|
97
|
+
Type: (id: string) => boolean<br>
|
|
98
|
+
|
|
99
|
+
Custom [filter function](https://github.com/rollup/plugins/tree/master/packages/pluginutils#createfilter) can be used to determine whether or not certain modules should be operated upon.
|
|
100
|
+
|
|
101
|
+
Usage:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
105
|
+
const include = 'include/**.js';
|
|
106
|
+
const exclude = 'exclude/**.js';
|
|
107
|
+
const filter = createFilter(include, exclude, {});
|
|
108
|
+
```
|
|
109
|
+
|
|
95
110
|
### `extensions`
|
|
96
111
|
|
|
97
112
|
Type: `Array[...String]`<br>
|
package/dist/index.es.js
CHANGED
|
@@ -211,7 +211,7 @@ async function transformCode(inputCode, babelOptions, overrides, customOptions,
|
|
|
211
211
|
return null;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
let transformOptions = !overrides.config ? config.options : await overrides.config.call(
|
|
214
|
+
let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {
|
|
215
215
|
code: inputCode,
|
|
216
216
|
customOptions
|
|
217
217
|
});
|
|
@@ -363,6 +363,7 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
363
363
|
let exclude;
|
|
364
364
|
let include;
|
|
365
365
|
let extensions;
|
|
366
|
+
let customFilter;
|
|
366
367
|
|
|
367
368
|
var _unpackInputPluginOpt = unpackInputPluginOptions(pluginOptionsWithOverrides, this.meta.rollupVersion);
|
|
368
369
|
|
|
@@ -371,13 +372,19 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
371
372
|
extensions,
|
|
372
373
|
babelHelpers,
|
|
373
374
|
include,
|
|
375
|
+
filter: customFilter,
|
|
374
376
|
skipPreflightCheck
|
|
375
377
|
} = _unpackInputPluginOpt);
|
|
376
|
-
babelOptions = _objectWithoutProperties(_unpackInputPluginOpt, ["exclude", "extensions", "babelHelpers", "include", "skipPreflightCheck"]);
|
|
378
|
+
babelOptions = _objectWithoutProperties(_unpackInputPluginOpt, ["exclude", "extensions", "babelHelpers", "include", "filter", "skipPreflightCheck"]);
|
|
377
379
|
const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})$`);
|
|
378
|
-
const includeExcludeFilter = createFilter(include, exclude);
|
|
379
380
|
|
|
380
|
-
|
|
381
|
+
if (customFilter && (include || exclude)) {
|
|
382
|
+
throw new Error('Could not handle include or exclude with custom filter together');
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : createFilter(include, exclude);
|
|
386
|
+
|
|
387
|
+
filter = id => extensionRegExp.test(stripQuery(id).bareId) && userDefinedFilter(id);
|
|
381
388
|
|
|
382
389
|
return null;
|
|
383
390
|
},
|
package/dist/index.js
CHANGED
|
@@ -236,7 +236,7 @@ async function transformCode(inputCode, babelOptions, overrides, customOptions,
|
|
|
236
236
|
return null;
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
let transformOptions = !overrides.config ? config.options : await overrides.config.call(
|
|
239
|
+
let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {
|
|
240
240
|
code: inputCode,
|
|
241
241
|
customOptions
|
|
242
242
|
});
|
|
@@ -388,6 +388,7 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
388
388
|
let exclude;
|
|
389
389
|
let include;
|
|
390
390
|
let extensions;
|
|
391
|
+
let customFilter;
|
|
391
392
|
|
|
392
393
|
var _unpackInputPluginOpt = unpackInputPluginOptions(pluginOptionsWithOverrides, this.meta.rollupVersion);
|
|
393
394
|
|
|
@@ -396,13 +397,19 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
396
397
|
extensions,
|
|
397
398
|
babelHelpers,
|
|
398
399
|
include,
|
|
400
|
+
filter: customFilter,
|
|
399
401
|
skipPreflightCheck
|
|
400
402
|
} = _unpackInputPluginOpt);
|
|
401
|
-
babelOptions = _objectWithoutProperties(_unpackInputPluginOpt, ["exclude", "extensions", "babelHelpers", "include", "skipPreflightCheck"]);
|
|
403
|
+
babelOptions = _objectWithoutProperties(_unpackInputPluginOpt, ["exclude", "extensions", "babelHelpers", "include", "filter", "skipPreflightCheck"]);
|
|
402
404
|
const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})$`);
|
|
403
|
-
const includeExcludeFilter = pluginutils.createFilter(include, exclude);
|
|
404
405
|
|
|
405
|
-
|
|
406
|
+
if (customFilter && (include || exclude)) {
|
|
407
|
+
throw new Error('Could not handle include or exclude with custom filter together');
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : pluginutils.createFilter(include, exclude);
|
|
411
|
+
|
|
412
|
+
filter = id => extensionRegExp.test(stripQuery(id).bareId) && userDefinedFilter(id);
|
|
406
413
|
|
|
407
414
|
return null;
|
|
408
415
|
},
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Plugin } from 'rollup';
|
|
2
|
-
import { FilterPattern } from '@rollup/pluginutils';
|
|
1
|
+
import { Plugin, PluginContext, TransformPluginContext } from 'rollup';
|
|
2
|
+
import { FilterPattern, CreateFilter } from '@rollup/pluginutils';
|
|
3
3
|
import * as babelCore from '@babel/core';
|
|
4
4
|
|
|
5
5
|
export interface RollupBabelInputPluginOptions
|
|
@@ -14,6 +14,16 @@ export interface RollupBabelInputPluginOptions
|
|
|
14
14
|
* @default undefined;
|
|
15
15
|
*/
|
|
16
16
|
exclude?: FilterPattern;
|
|
17
|
+
/**
|
|
18
|
+
* Custom filter function can be used to determine whether or not certain modules should be operated upon.
|
|
19
|
+
* Example:
|
|
20
|
+
* import { createFilter } from '@rollup/pluginutils';
|
|
21
|
+
* const include = 'include/**.js';
|
|
22
|
+
* const exclude = 'exclude/**.js';
|
|
23
|
+
* const filter = createFilter(include, exclude, {});
|
|
24
|
+
* @default undefined;
|
|
25
|
+
*/
|
|
26
|
+
filter?: ReturnType<CreateFilter>;
|
|
17
27
|
/**
|
|
18
28
|
* An array of file extensions that Babel should transpile. If you want to transpile TypeScript files with this plugin it's essential to include .ts and .tsx in this option.
|
|
19
29
|
* @default ['.js', '.jsx', '.es6', '.es', '.mjs']
|
|
@@ -52,28 +62,45 @@ export type RollupBabelCustomOutputPluginOptions = (
|
|
|
52
62
|
customOptions: Record<string, any>;
|
|
53
63
|
pluginOptions: RollupBabelOutputPluginOptions;
|
|
54
64
|
};
|
|
55
|
-
export
|
|
65
|
+
export interface RollupBabelCustomPluginConfigOptions {
|
|
66
|
+
code: string;
|
|
67
|
+
customOptions: Record<string, any>;
|
|
68
|
+
}
|
|
69
|
+
export interface RollupBabelCustomPluginResultOptions {
|
|
70
|
+
code: string;
|
|
71
|
+
customOptions: Record<string, any>;
|
|
72
|
+
config: babelCore.PartialConfig;
|
|
73
|
+
transformOptions: babelCore.TransformOptions;
|
|
74
|
+
}
|
|
75
|
+
export type RollupBabelCustomInputPluginConfig = (
|
|
76
|
+
this: TransformPluginContext,
|
|
77
|
+
cfg: babelCore.PartialConfig,
|
|
78
|
+
options: RollupBabelCustomPluginConfigOptions
|
|
79
|
+
) => babelCore.TransformOptions;
|
|
80
|
+
export type RollupBabelCustomInputPluginResult = (
|
|
81
|
+
this: TransformPluginContext,
|
|
82
|
+
result: babelCore.BabelFileResult,
|
|
83
|
+
options: RollupBabelCustomPluginResultOptions
|
|
84
|
+
) => babelCore.BabelFileResult;
|
|
85
|
+
export type RollupBabelCustomOutputPluginConfig = (
|
|
86
|
+
this: PluginContext,
|
|
56
87
|
cfg: babelCore.PartialConfig,
|
|
57
|
-
options:
|
|
88
|
+
options: RollupBabelCustomPluginConfigOptions
|
|
58
89
|
) => babelCore.TransformOptions;
|
|
59
|
-
export type
|
|
90
|
+
export type RollupBabelCustomOutputPluginResult = (
|
|
91
|
+
this: PluginContext,
|
|
60
92
|
result: babelCore.BabelFileResult,
|
|
61
|
-
options:
|
|
62
|
-
code: string;
|
|
63
|
-
customOptions: Record<string, any>;
|
|
64
|
-
config: babelCore.PartialConfig;
|
|
65
|
-
transformOptions: babelCore.TransformOptions;
|
|
66
|
-
}
|
|
93
|
+
options: RollupBabelCustomPluginResultOptions
|
|
67
94
|
) => babelCore.BabelFileResult;
|
|
68
95
|
export interface RollupBabelCustomInputPlugin {
|
|
69
96
|
options?: RollupBabelCustomInputPluginOptions;
|
|
70
|
-
config?:
|
|
71
|
-
result?:
|
|
97
|
+
config?: RollupBabelCustomInputPluginConfig;
|
|
98
|
+
result?: RollupBabelCustomInputPluginResult;
|
|
72
99
|
}
|
|
73
100
|
export interface RollupBabelCustomOutputPlugin {
|
|
74
101
|
options?: RollupBabelCustomOutputPluginOptions;
|
|
75
|
-
config?:
|
|
76
|
-
result?:
|
|
102
|
+
config?: RollupBabelCustomOutputPluginConfig;
|
|
103
|
+
result?: RollupBabelCustomOutputPluginResult;
|
|
77
104
|
}
|
|
78
105
|
export type RollupBabelCustomInputPluginBuilder = (
|
|
79
106
|
babel: typeof babelCore
|