source: trip-planner-front/node_modules/adjust-sourcemap-loader/lib/process/debug-message.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3var PACKAGE_NAME = require('../../package.json').name,
4 PADDING = (new Array(11)).join(' ');
5
6/**
7 * Format a debug message
8 * @param {{resourcePath:string, loaders:Array, loaderIndex:number}} context A loader or compilation
9 * @param {{input:Array.<string>, absolute:Array.<string>, output:Array.<string>, root:string}} info Source-map info
10 * @returns {string} An encoded debug string
11 */
12function debugMessage(context, info) {
13 return [
14 ' ',
15 PACKAGE_NAME + ':',
16 ' ' + context.resourcePath,
17 formatField('@', precedingRequest(context)),
18 formatField('INPUT', info.input || '(source-map absent)'),
19 formatField('ABSOLUTE', info.absolute),
20 formatField('OUTPUT', info.output),
21 formatField('ROOT', info.root)
22 ]
23 .filter(Boolean)
24 .join('\n');
25}
26
27module.exports = debugMessage;
28
29/**
30 * Find the request that precedes this loader in the loader chain
31 * @param {{loaders:Array, loaderIndex:number}} loader The loader context
32 * @returns {string} The request of the preceding loader
33 */
34function precedingRequest(loader) {
35 var isLoader = ('loaderIndex' in loader) && ('loaders' in loader) && Array.isArray(loader.loaders);
36 if (isLoader) {
37 var index = loader.loaderIndex + 1;
38 return (index in loader.loaders) ? loader.loaders[index].request : '(no preceding loader)';
39 }
40}
41
42/**
43 * Where the data is truthy then format it with a right-aligned title.
44 * @param {string} title
45 * @param {*} data The data to display
46 * @returns {boolean|string} False where data is falsey, else formatted message
47 */
48function formatField(title, data) {
49 return !!data && (rightAlign(title) + formatData(data));
50
51 function rightAlign(text) {
52 return (PADDING + text + ' ').slice(-PADDING.length);
53 }
54
55 function formatData(data) {
56 return Array.isArray(data) ? data.join('\n' + PADDING) : data;
57 }
58}
Note: See TracBrowser for help on using the repository browser.