liferay-npm-build-tools-common
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -5,2 +5,23 @@ 'use strict'; | ||
it('normalizeImportsConfig works', function () { | ||
var imports = (0, _imports.normalizeImportsConfig)({ | ||
'provider1': { | ||
dep1: '^1.0.0', | ||
dep2: '^2.0.0' | ||
}, | ||
'provider2': { | ||
dep9: '^9.0.0', | ||
dep8: '^8.0.0' | ||
}, | ||
'': { | ||
depA: '3.0.0' | ||
}, | ||
'depB': { | ||
'/': '4.0.0' | ||
} | ||
}); | ||
expect(imports).toMatchSnapshot(); | ||
}); | ||
it('unrollImportsConfig works', function () { | ||
@@ -7,0 +28,0 @@ var imports = (0, _imports.unrollImportsConfig)({ |
@@ -6,13 +6,12 @@ 'use strict'; | ||
}); | ||
exports.normalizeImportsConfig = normalizeImportsConfig; | ||
exports.unrollImportsConfig = unrollImportsConfig; | ||
/** | ||
* Unrolls the imports configuration section of .npmbundlerrc file. | ||
* Normalize an imports configuration to canonicalize all syntactic sugar. | ||
* @param {Object} importsConfig the configuration in its original format | ||
* @return {Object} the unrolled configuration with one entry per module name | ||
* @return {Object} the normalized configuration after resolving all syntactic sugar | ||
*/ | ||
function unrollImportsConfig(importsConfig) { | ||
importsConfig = importsConfig || {}; | ||
function normalizeImportsConfig(importsConfig) { | ||
var normalized = {}; | ||
var imports = {}; | ||
Object.keys(importsConfig).forEach(function (namespace) { | ||
@@ -27,2 +26,22 @@ Object.keys(importsConfig[namespace]).forEach(function (pkgName) { | ||
normalized[namespace] = normalized[namespace] || {}; | ||
normalized[namespace][pkgName] = version; | ||
}); | ||
}); | ||
return normalized; | ||
} | ||
/** | ||
* Unrolls the imports configuration section of .npmbundlerrc file. | ||
* @param {Object} importsConfig the configuration in its original format | ||
* @return {Object} the unrolled configuration with one entry per module name | ||
*/ | ||
function unrollImportsConfig(importsConfig) { | ||
importsConfig = normalizeImportsConfig(importsConfig || {}); | ||
var imports = {}; | ||
Object.keys(importsConfig).forEach(function (namespace) { | ||
Object.keys(importsConfig[namespace]).forEach(function (pkgName) { | ||
if (imports[pkgName]) { | ||
@@ -34,3 +53,3 @@ throw new Error('Package ' + pkgName + ' is mapped to more than one import'); | ||
name: namespace, | ||
version: version | ||
version: importsConfig[namespace][pkgName] | ||
}; | ||
@@ -37,0 +56,0 @@ }); |
{ | ||
"name": "liferay-npm-build-tools-common", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Utility library for Liferay NPM Build Tools.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -1,3 +0,24 @@ | ||
import {unrollImportsConfig} from '../imports'; | ||
import {normalizeImportsConfig, unrollImportsConfig} from '../imports'; | ||
it('normalizeImportsConfig works', () => { | ||
const imports = normalizeImportsConfig({ | ||
'provider1': { | ||
dep1: '^1.0.0', | ||
dep2: '^2.0.0', | ||
}, | ||
'provider2': { | ||
dep9: '^9.0.0', | ||
dep8: '^8.0.0', | ||
}, | ||
'': { | ||
depA: '3.0.0', | ||
}, | ||
'depB': { | ||
'/': '4.0.0', | ||
}, | ||
}); | ||
expect(imports).toMatchSnapshot(); | ||
}); | ||
it('unrollImportsConfig works', () => { | ||
@@ -4,0 +25,0 @@ const imports = unrollImportsConfig({ |
/** | ||
* Unrolls the imports configuration section of .npmbundlerrc file. | ||
* Normalize an imports configuration to canonicalize all syntactic sugar. | ||
* @param {Object} importsConfig the configuration in its original format | ||
* @return {Object} the unrolled configuration with one entry per module name | ||
* @return {Object} the normalized configuration after resolving all syntactic sugar | ||
*/ | ||
export function unrollImportsConfig(importsConfig) { | ||
importsConfig = importsConfig || {}; | ||
export function normalizeImportsConfig(importsConfig) { | ||
let normalized = {}; | ||
let imports = {}; | ||
Object.keys(importsConfig).forEach(namespace => { | ||
@@ -20,2 +18,22 @@ Object.keys(importsConfig[namespace]).forEach(pkgName => { | ||
normalized[namespace] = normalized[namespace] || {}; | ||
normalized[namespace][pkgName] = version; | ||
}); | ||
}); | ||
return normalized; | ||
} | ||
/** | ||
* Unrolls the imports configuration section of .npmbundlerrc file. | ||
* @param {Object} importsConfig the configuration in its original format | ||
* @return {Object} the unrolled configuration with one entry per module name | ||
*/ | ||
export function unrollImportsConfig(importsConfig) { | ||
importsConfig = normalizeImportsConfig(importsConfig || {}); | ||
let imports = {}; | ||
Object.keys(importsConfig).forEach(namespace => { | ||
Object.keys(importsConfig[namespace]).forEach(pkgName => { | ||
if (imports[pkgName]) { | ||
@@ -29,3 +47,3 @@ throw new Error( | ||
name: namespace, | ||
version, | ||
version: importsConfig[namespace][pkgName], | ||
}; | ||
@@ -32,0 +50,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
123827
51
1985