liferay-npm-build-tools-common
Advanced tools
Comparing version 1.7.0-alpha.e4d06b30 to 1.7.0
@@ -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 () { | ||
@@ -48,2 +69,24 @@ var imports = (0, _imports.unrollImportsConfig)({ | ||
}); | ||
describe('unrollImportsConfig handles null namespaces correctly', function () { | ||
it('when described the canonical way', function () { | ||
var imports = (0, _imports.unrollImportsConfig)({ | ||
'': { | ||
dep: '^1.0.0' | ||
} | ||
}); | ||
expect(imports['dep']).toMatchObject({ name: '', version: '^1.0.0' }); | ||
}); | ||
it('when described the sweet way', function () { | ||
var imports = (0, _imports.unrollImportsConfig)({ | ||
dep: { | ||
'/': '^1.0.0' | ||
} | ||
}); | ||
expect(imports['dep']).toMatchObject({ name: '', version: '^1.0.0' }); | ||
}); | ||
}); | ||
//# sourceMappingURL=imports.test.js.map |
@@ -42,2 +42,3 @@ 'use strict'; | ||
expect(mod.isExternalDependency('a-module')).toBe(true); | ||
expect(mod.isExternalDependency('fs')).toBe(true); | ||
@@ -47,3 +48,2 @@ expect(mod.isExternalDependency('./a-module')).toBe(false); | ||
expect(mod.isExternalDependency('/a-module')).toBe(false); | ||
expect(mod.isExternalDependency('fs')).toBe(false); | ||
}); | ||
@@ -50,0 +50,0 @@ |
@@ -31,2 +31,32 @@ 'use strict'; | ||
}); | ||
describe('when using PlugginLogger registration', function () { | ||
it('set and gets a registered PluginLogger correctly', function () { | ||
var logger = new _pluginLogger2.default(); | ||
_pluginLogger2.default.set('a-key', logger); | ||
expect(_pluginLogger2.default.get('a-key')).toBe(logger); | ||
}); | ||
it('deletes a registered PluginLogger correctly', function () { | ||
var logger = new _pluginLogger2.default(); | ||
_pluginLogger2.default.set('a-key', logger); | ||
logger.info('source', 'hi'); | ||
expect(_pluginLogger2.default.get('a-key').messages.length).toBe(1); | ||
_pluginLogger2.default.delete('a-key'); | ||
expect(_pluginLogger2.default.get('a-key').messages.length).toBe(0); | ||
}); | ||
it('returns a dummy logger if no loggers are registered', function () { | ||
_pluginLogger2.default.delete('a-key'); | ||
expect(_pluginLogger2.default.get('a-key')).toBeDefined(); | ||
}); | ||
}); | ||
//# sourceMappingURL=plugin-logger.test.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -6,4 +6,30 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.normalizeImportsConfig = normalizeImportsConfig; | ||
exports.unrollImportsConfig = unrollImportsConfig; | ||
/** | ||
* Normalize an imports configuration to canonicalize all syntactic sugar. | ||
* @param {Object} importsConfig the configuration in its original format | ||
* @return {Object} the normalized configuration after resolving all syntactic sugar | ||
*/ | ||
function normalizeImportsConfig(importsConfig) { | ||
var normalized = {}; | ||
Object.keys(importsConfig).forEach(function (namespace) { | ||
Object.keys(importsConfig[namespace]).forEach(function (pkgName) { | ||
var version = importsConfig[namespace][pkgName]; | ||
if (pkgName === '/') { | ||
pkgName = namespace; | ||
namespace = ''; | ||
} | ||
normalized[namespace] = normalized[namespace] || {}; | ||
normalized[namespace][pkgName] = version; | ||
}); | ||
}); | ||
return normalized; | ||
} | ||
/** | ||
* Unrolls the imports configuration section of .npmbundlerrc file. | ||
@@ -14,3 +40,3 @@ * @param {Object} importsConfig the configuration in its original format | ||
function unrollImportsConfig(importsConfig) { | ||
importsConfig = importsConfig || {}; | ||
importsConfig = normalizeImportsConfig(importsConfig || {}); | ||
@@ -22,3 +48,3 @@ var imports = {}; | ||
if (imports[pkgName]) { | ||
throw new Error("Package " + pkgName + " is mapped to more than one import"); | ||
throw new Error('Package ' + pkgName + ' is mapped to more than one import'); | ||
} | ||
@@ -25,0 +51,0 @@ |
@@ -53,3 +53,3 @@ 'use strict'; | ||
function isExternalDependency(modulePath) { | ||
return !isLocalModule(modulePath) && !isReservedDependency(modulePath) && !isNodeCoreModule(modulePath); | ||
return !isLocalModule(modulePath) && !isReservedDependency(modulePath); | ||
} | ||
@@ -56,0 +56,0 @@ |
@@ -48,23 +48,2 @@ 'use strict'; | ||
/** | ||
* Log a warn message | ||
* @param {String} source the identifier for the source of the message | ||
* @param {Array} things the objects or strings to print | ||
* @return {void} | ||
*/ | ||
}, { | ||
key: 'warn', | ||
value: function warn(source) { | ||
for (var _len2 = arguments.length, things = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
things[_key2 - 1] = arguments[_key2]; | ||
} | ||
this._msgs.push({ | ||
source: source, | ||
level: 'warn', | ||
things: things | ||
}); | ||
} | ||
/** | ||
* Log an error message | ||
@@ -79,4 +58,4 @@ * @param {String} source the identifier for the source of the message | ||
value: function error(source) { | ||
for (var _len3 = arguments.length, things = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
things[_key3 - 1] = arguments[_key3]; | ||
for (var _len2 = arguments.length, things = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
things[_key2 - 1] = arguments[_key2]; | ||
} | ||
@@ -133,34 +112,50 @@ | ||
} | ||
}]); | ||
/** | ||
* Test if there are warn messages. | ||
* @return {boolean} if at least one warn message is registered in the logger | ||
*/ | ||
return PluginLogger; | ||
}(); | ||
}, { | ||
key: 'warnsPresent', | ||
get: function get() { | ||
return this._msgs.filter(function (msg) { | ||
return msg.level === 'warn'; | ||
}).length > 0; | ||
} | ||
exports.default = PluginLogger; | ||
/** | ||
* Test if there are error messages. | ||
* @return {boolean} if at least one error message is registered in the logger | ||
*/ | ||
}, { | ||
key: 'errorsPresent', | ||
get: function get() { | ||
return this._msgs.filter(function (msg) { | ||
return msg.level === 'error'; | ||
}).length > 0; | ||
} | ||
}]); | ||
global._PluginLogger_ = global._PluginLogger_ || {}; | ||
return PluginLogger; | ||
}(); | ||
/** | ||
* Set the logger for a given key. This is used to pass loggers from the | ||
* liferay-npm-bundler core to the Babel plugins because Babel's API doesn't | ||
* allow any way to pass per-file custom values to plugins. | ||
* @param {String} key the key to identify the logger (usually a file path) | ||
* @param {PluginLogger} logger the logger | ||
* @return {void} | ||
*/ | ||
PluginLogger.set = function (key, logger) { | ||
global._PluginLogger_[key] = logger; | ||
}; | ||
exports.default = PluginLogger; | ||
/** | ||
* Get the logger for a given key. This is used to pass loggers from the | ||
* liferay-npm-bundler core to the Babel plugins because Babel's API doesn't | ||
* allow any way to pass per-file custom values to plugins. | ||
* @param {String|Object} key the key to identify the logger (usually a file path). You can also pass the state object | ||
* passed to Babel plugins and it will be automatically dereferenced. | ||
* @return {PluginLogger} the logger | ||
*/ | ||
PluginLogger.get = function (key) { | ||
if (key.file && key.file.opts && key.file.opts.filenameRelative) { | ||
key = key.file.opts.filenameRelative; | ||
} | ||
return global._PluginLogger_[key] || new PluginLogger(); | ||
}; | ||
/** | ||
* Delete the logger for a given key. This is used to pass loggers from the | ||
* liferay-npm-bundler core to the Babel plugins because Babel's API doesn't | ||
* allow any way to pass per-file custom values to plugins. | ||
* @param {String} key the key to identify the logger (usually a file path) | ||
* @return {void} | ||
*/ | ||
PluginLogger.delete = function (key) { | ||
delete global._PluginLogger_[key]; | ||
}; | ||
//# sourceMappingURL=plugin-logger.js.map |
{ | ||
"name": "liferay-npm-build-tools-common", | ||
"version": "1.7.0-alpha.e4d06b30", | ||
"version": "1.7.0", | ||
"description": "Utility library for Liferay NPM Build Tools.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -25,1 +25,31 @@ import PluginLogger from '../plugin-logger'; | ||
}); | ||
describe('when using PlugginLogger registration', () => { | ||
it('set and gets a registered PluginLogger correctly', () => { | ||
const logger = new PluginLogger(); | ||
PluginLogger.set('a-key', logger); | ||
expect(PluginLogger.get('a-key')).toBe(logger); | ||
}); | ||
it('deletes a registered PluginLogger correctly', () => { | ||
const logger = new PluginLogger(); | ||
PluginLogger.set('a-key', logger); | ||
logger.info('source', 'hi'); | ||
expect(PluginLogger.get('a-key').messages.length).toBe(1); | ||
PluginLogger.delete('a-key'); | ||
expect(PluginLogger.get('a-key').messages.length).toBe(0); | ||
}); | ||
it('returns a dummy logger if no loggers are registered', () => { | ||
PluginLogger.delete('a-key'); | ||
expect(PluginLogger.get('a-key')).toBeDefined(); | ||
}); | ||
}); |
@@ -28,16 +28,2 @@ /** | ||
/** | ||
* Log a warn message | ||
* @param {String} source the identifier for the source of the message | ||
* @param {Array} things the objects or strings to print | ||
* @return {void} | ||
*/ | ||
warn(source, ...things) { | ||
this._msgs.push({ | ||
source: source, | ||
level: 'warn', | ||
things: things, | ||
}); | ||
} | ||
/** | ||
* Log an error message | ||
@@ -65,18 +51,2 @@ * @param {String} source the identifier for the source of the message | ||
/** | ||
* Test if there are warn messages. | ||
* @return {boolean} if at least one warn message is registered in the logger | ||
*/ | ||
get warnsPresent() { | ||
return this._msgs.filter(msg => msg.level === 'warn').length > 0; | ||
} | ||
/** | ||
* Test if there are error messages. | ||
* @return {boolean} if at least one error message is registered in the logger | ||
*/ | ||
get errorsPresent() { | ||
return this._msgs.filter(msg => msg.level === 'error').length > 0; | ||
} | ||
/** | ||
* Return a printable string representation of the messages logged till now | ||
@@ -105,1 +75,42 @@ * @return {String} a string containing one line per message | ||
} | ||
global._PluginLogger_ = global._PluginLogger_ || {}; | ||
/** | ||
* Set the logger for a given key. This is used to pass loggers from the | ||
* liferay-npm-bundler core to the Babel plugins because Babel's API doesn't | ||
* allow any way to pass per-file custom values to plugins. | ||
* @param {String} key the key to identify the logger (usually a file path) | ||
* @param {PluginLogger} logger the logger | ||
* @return {void} | ||
*/ | ||
PluginLogger.set = function(key, logger) { | ||
global._PluginLogger_[key] = logger; | ||
}; | ||
/** | ||
* Get the logger for a given key. This is used to pass loggers from the | ||
* liferay-npm-bundler core to the Babel plugins because Babel's API doesn't | ||
* allow any way to pass per-file custom values to plugins. | ||
* @param {String|Object} key the key to identify the logger (usually a file path). You can also pass the state object | ||
* passed to Babel plugins and it will be automatically dereferenced. | ||
* @return {PluginLogger} the logger | ||
*/ | ||
PluginLogger.get = function(key) { | ||
if (key.file && key.file.opts && key.file.opts.filenameRelative) { | ||
key = key.file.opts.filenameRelative; | ||
} | ||
return global._PluginLogger_[key] || new PluginLogger(); | ||
}; | ||
/** | ||
* Delete the logger for a given key. This is used to pass loggers from the | ||
* liferay-npm-bundler core to the Babel plugins because Babel's API doesn't | ||
* allow any way to pass per-file custom values to plugins. | ||
* @param {String} key the key to identify the logger (usually a file path) | ||
* @return {void} | ||
*/ | ||
PluginLogger.delete = function(key) { | ||
delete global._PluginLogger_[key]; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
0
104880
38
1223