-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget-registrations.js
32 lines (25 loc) · 1.17 KB
/
get-registrations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var fs = require("fs");
var path = require("path");
var getPresetOptions = require("./get-preset-options");
module.exports = function getRegistrations(targetNodeVersion, packageDescriptions, presetPath)
{
var registrationsByKey = Object.keys(packageDescriptions)
.reduce(function toRegistrations(registrations, name)
{
// Easier to just always skip this for now.
if (name === "@isomorphic/babel-preset" || name === "generic-jsx")
return registrations;
var description = packageDescriptions[name];
var fullPath = description.path;
var options = getPresetOptions(targetNodeVersion, description.packagePath);
var key = JSON.stringify(options);
var babelOptions = { presets: [ [presetPath, options ] ] };
if (!registrations[key])
registrations[key] = { sources: [fullPath], options: babelOptions };
else
registrations[key].sources.push(fullPath);
return registrations;
}, Object.create(null));
return Object.keys(registrationsByKey)
.map(function (key) { return registrationsByKey[key] });
}