remove integer error for node, add debug option (#18)
This commit is contained in:
parent
d11c2af388
commit
4903395cbf
@ -20,9 +20,12 @@ The data for this is currently at: [/data/plugins.json](/data/plugins.json) and
|
||||
|
||||
Currently: "chrome, edge, firefox, safari, node"
|
||||
|
||||
* `loose` - Enable "loose" transformations for any plugins in this preset that allow them (Disabled by default).
|
||||
> Some node features are > `6.5`
|
||||
|
||||
* `loose` (boolean) - Enable "loose" transformations for any plugins in this preset that allow them (Disabled by default).
|
||||
* `modules` - Enable transformation of ES6 module syntax to another module type (Enabled by default to `"commonjs"`).
|
||||
* Can be `false` to not transform modules, or one of `["amd", "umd", "systemjs", "commonjs"]`
|
||||
* `debug` (boolean) - `console.log` out the targets and plugins being used as well as the version specified in `/data/plugins.json`
|
||||
|
||||
```js
|
||||
{
|
||||
@ -95,3 +98,18 @@ exports.A = A;
|
||||
|
||||
export class A {}
|
||||
```
|
||||
|
||||
### Example with `debug: true`
|
||||
|
||||
```js
|
||||
Using targets: {
|
||||
"node": 6.5
|
||||
}
|
||||
|
||||
Using plugins:
|
||||
|
||||
module: false
|
||||
transform-exponentiation-operator {}
|
||||
transform-async-to-generator {}
|
||||
syntax-trailing-function-commas {}
|
||||
```
|
||||
|
||||
@ -51,10 +51,6 @@ export const isPluginRequired = (supportedEnvironments, plugin) => {
|
||||
const lowestImplementedVersion = plugin[environment];
|
||||
const lowestTargetedVersion = supportedEnvironments[environment];
|
||||
|
||||
if (environment === "node" && lowestTargetedVersion % 1 === 0) {
|
||||
throw new Error("Please use a minor version when specifying `node`: 6.5, 6.7");
|
||||
}
|
||||
|
||||
if (lowestTargetedVersion < lowestImplementedVersion) {
|
||||
return true;
|
||||
}
|
||||
@ -93,12 +89,32 @@ export default function buildPreset(context, opts) {
|
||||
const loose = validateLooseOption(opts.loose);
|
||||
const moduleType = validateModulesOption(opts.modules);
|
||||
const targets = getTargets(opts.targets);
|
||||
const debug = opts.debug;
|
||||
|
||||
const transformations = Object.keys(pluginList)
|
||||
.filter(pluginName => isPluginRequired(targets, pluginList[pluginName]))
|
||||
.map(pluginName => {
|
||||
return [require(`babel-plugin-${pluginName}`), { loose }];
|
||||
let transformations = Object.keys(pluginList)
|
||||
.filter(pluginName => isPluginRequired(targets, pluginList[pluginName]));
|
||||
|
||||
if (debug) {
|
||||
console.log("");
|
||||
console.log(`Using targets: ${JSON.stringify(targets, null, 2)}`);
|
||||
console.log("");
|
||||
console.log("Using plugins:");
|
||||
console.log("");
|
||||
console.log(`module: ${moduleType}`);
|
||||
transformations.forEach(transform => {
|
||||
let envList = pluginList[transform];
|
||||
let filteredList = Object.keys(targets)
|
||||
.reduce((a, b) => {
|
||||
a[b] = envList[b];
|
||||
return a;
|
||||
}, {});
|
||||
console.log(transform, JSON.stringify(filteredList, null, 2));
|
||||
});
|
||||
}
|
||||
|
||||
transformations = transformations.map(pluginName => {
|
||||
return [require(`babel-plugin-${pluginName}`), { loose }];
|
||||
});
|
||||
|
||||
const modules = [
|
||||
moduleType === "commonjs" && [require("babel-plugin-transform-es2015-modules-commonjs"), { loose }],
|
||||
@ -112,5 +128,5 @@ export default function buildPreset(context, opts) {
|
||||
...modules,
|
||||
...transformations
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -79,21 +79,6 @@ describe("babel-preset-env", () => {
|
||||
babelPresetEnv.isPluginRequired(targets, plugin);
|
||||
}, Error);
|
||||
});
|
||||
|
||||
it("throws when specifiying an integer for node", () => {
|
||||
let targets;
|
||||
const plugin = {
|
||||
node: 6
|
||||
};
|
||||
|
||||
targets = {
|
||||
"node": 6
|
||||
};
|
||||
|
||||
assert.throws(() => {
|
||||
babelPresetEnv.isPluginRequired(targets, plugin);
|
||||
}, Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateLooseOption", () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user