@atlaspack/reporter-cli 2.15.1-canary.35 → 2.15.1-canary.351

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.default = bundleReport;
40
+ const utils_1 = require("@atlaspack/utils");
41
+ const filesize_1 = __importDefault(require("filesize"));
42
+ const chalk_1 = __importDefault(require("chalk"));
43
+ const nullthrows_1 = __importDefault(require("nullthrows"));
44
+ const emoji = __importStar(require("./emoji"));
45
+ const render_1 = require("./render");
46
+ const utils_2 = require("./utils");
47
+ const LARGE_BUNDLE_SIZE = 1024 * 1024;
48
+ const COLUMNS = [
49
+ { align: 'left' }, // name
50
+ { align: 'right' }, // size
51
+ { align: 'right' }, // time
52
+ ];
53
+ async function bundleReport(bundleGraph, fs, projectRoot, assetCount = 0) {
54
+ let bundleList = bundleGraph.getBundles();
55
+ // Get a list of bundles sorted by size
56
+ let { bundles } = assetCount > 0
57
+ ? await (0, utils_1.generateBuildMetrics)(bundleList, fs, projectRoot)
58
+ : {
59
+ bundles: bundleList.map((b) => {
60
+ return {
61
+ filePath: (0, nullthrows_1.default)(b.filePath),
62
+ size: b.stats.size,
63
+ time: b.stats.time,
64
+ assets: [],
65
+ };
66
+ }),
67
+ };
68
+ let rows = [];
69
+ for (let bundle of bundles) {
70
+ // Add a row for the bundle
71
+ rows.push([
72
+ (0, utils_2.formatFilename)(bundle.filePath || '', chalk_1.default.cyan.bold),
73
+ chalk_1.default.bold(prettifySize(bundle.size, bundle.size > LARGE_BUNDLE_SIZE)),
74
+ chalk_1.default.green.bold((0, utils_1.prettifyTime)(bundle.time)),
75
+ ]);
76
+ if (assetCount > 0) {
77
+ let largestAssets = bundle.assets.slice(0, assetCount);
78
+ for (let asset of largestAssets) {
79
+ let columns = [
80
+ asset == largestAssets[largestAssets.length - 1] ? '└── ' : '├── ',
81
+ // @ts-expect-error TS2554
82
+ chalk_1.default.dim(prettifySize(asset.size)),
83
+ chalk_1.default.dim(chalk_1.default.green((0, utils_1.prettifyTime)(asset.time))),
84
+ ];
85
+ if (asset.filePath !== '') {
86
+ columns[0] += (0, utils_2.formatFilename)(asset.filePath, chalk_1.default.reset);
87
+ }
88
+ else {
89
+ columns[0] += 'Code from unknown sourcefiles';
90
+ }
91
+ // Add a row for the asset.
92
+ rows.push(columns);
93
+ }
94
+ if (bundle.assets.length > largestAssets.length) {
95
+ rows.push([
96
+ '└── ' +
97
+ chalk_1.default.dim(`+ ${bundle.assets.length - largestAssets.length} more assets`),
98
+ ]);
99
+ }
100
+ // If this isn't the last bundle, add an empty row before the next one
101
+ if (bundle !== bundles[bundles.length - 1]) {
102
+ rows.push([]);
103
+ }
104
+ }
105
+ }
106
+ // Render table
107
+ (0, render_1.writeOut)('');
108
+ // @ts-expect-error TS2345
109
+ (0, render_1.table)(COLUMNS, rows);
110
+ }
111
+ function prettifySize(size, isLarge) {
112
+ let res = (0, filesize_1.default)(size);
113
+ if (isLarge) {
114
+ return chalk_1.default.yellow(emoji.warning + ' ' + res);
115
+ }
116
+ return chalk_1.default.magenta(res);
117
+ }
package/dist/emoji.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.docs = exports.hint = exports.info = exports.warning = exports.error = exports.success = exports.progress = void 0;
4
+ // From https://github.com/sindresorhus/is-unicode-supported/blob/8f123916d5c25a87c4f966dcc248b7ca5df2b4ca/index.js
5
+ // This package is ESM-only so it has to be vendored
6
+ function isUnicodeSupported() {
7
+ if (process.platform !== 'win32') {
8
+ return process.env.TERM !== 'linux'; // Linux console (kernel)
9
+ }
10
+ return (Boolean(process.env.CI) ||
11
+ Boolean(process.env.WT_SESSION) || // Windows Terminal
12
+ process.env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder
13
+ process.env.TERM_PROGRAM === 'vscode' ||
14
+ process.env.TERM === 'xterm-256color' ||
15
+ process.env.TERM === 'alacritty');
16
+ }
17
+ const supportsEmoji = isUnicodeSupported();
18
+ // Fallback symbols for Windows from https://en.wikipedia.org/wiki/Code_page_437
19
+ exports.progress = supportsEmoji ? '⏳' : '∞';
20
+ exports.success = supportsEmoji ? '✨' : '√';
21
+ exports.error = supportsEmoji ? '🚨' : '×';
22
+ exports.warning = supportsEmoji ? '⚠️' : '‼';
23
+ exports.info = supportsEmoji ? 'ℹ️' : 'ℹ';
24
+ exports.hint = supportsEmoji ? '💡' : 'ℹ';
25
+ exports.docs = supportsEmoji ? '📝' : 'ℹ';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const logLevels = {
4
+ none: 0,
5
+ error: 1,
6
+ warn: 2,
7
+ info: 3,
8
+ progress: 3,
9
+ success: 3,
10
+ verbose: 4,
11
+ };
12
+ exports.default = logLevels;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = phaseReport;
7
+ const utils_1 = require("@atlaspack/utils");
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const render_1 = require("./render");
10
+ const assert_1 = __importDefault(require("assert"));
11
+ function phaseReport(phaseStartTimes) {
12
+ let phaseTimes = {};
13
+ if (phaseStartTimes['transforming'] && phaseStartTimes['bundling']) {
14
+ phaseTimes['Transforming'] =
15
+ phaseStartTimes['bundling'] - phaseStartTimes['transforming'];
16
+ }
17
+ let packagingAndOptimizing = phaseStartTimes['packaging'] && phaseStartTimes['optimizing']
18
+ ? Math.min(phaseStartTimes['packaging'], phaseStartTimes['optimizing'])
19
+ : phaseStartTimes['packaging'] || phaseStartTimes['optimizing'];
20
+ if (phaseStartTimes['bundling'] && packagingAndOptimizing) {
21
+ phaseTimes['Bundling'] =
22
+ packagingAndOptimizing - phaseStartTimes['bundling'];
23
+ }
24
+ if (packagingAndOptimizing && phaseStartTimes['buildSuccess']) {
25
+ phaseTimes['Packaging & Optimizing'] =
26
+ phaseStartTimes['buildSuccess'] - packagingAndOptimizing;
27
+ }
28
+ for (let [phase, time] of Object.entries(phaseTimes)) {
29
+ (0, assert_1.default)(typeof time === 'number');
30
+ (0, render_1.writeOut)(chalk_1.default.green.bold(`${phase} finished in ${(0, utils_1.prettifyTime)(time)}`));
31
+ }
32
+ }
package/dist/render.js ADDED
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.isTTY = void 0;
40
+ exports._setStdio = _setStdio;
41
+ exports.writeOut = writeOut;
42
+ exports.persistMessage = persistMessage;
43
+ exports.updateSpinner = updateSpinner;
44
+ exports.persistSpinner = persistSpinner;
45
+ exports.resetWindow = resetWindow;
46
+ exports.table = table;
47
+ const readline_1 = __importDefault(require("readline"));
48
+ const ora_1 = __importDefault(require("ora"));
49
+ const string_width_1 = __importDefault(require("string-width"));
50
+ const utils_1 = require("./utils");
51
+ const emoji = __importStar(require("./emoji"));
52
+ exports.isTTY = process.env.NODE_ENV !== 'test' && process.stdout.isTTY;
53
+ let stdout = process.stdout;
54
+ let stderr = process.stderr;
55
+ // We pipe worker output to the process. If you
56
+ // have more than 10 threads then Nodejs will
57
+ // print warnings indicating you exceed the max
58
+ // listener count.
59
+ stdout.setMaxListeners(100);
60
+ stderr.setMaxListeners(100);
61
+ // Some state so we clear the output properly
62
+ let lineCount = 0;
63
+ let errorLineCount = 0;
64
+ let statusPersisted = false;
65
+ function _setStdio(stdoutLike, stderrLike) {
66
+ // @ts-expect-error TS2322
67
+ stdout = stdoutLike;
68
+ // @ts-expect-error TS2322
69
+ stderr = stderrLike;
70
+ }
71
+ let spinner = (0, ora_1.default)({
72
+ color: 'green',
73
+ stream: stdout,
74
+ discardStdin: false,
75
+ });
76
+ let persistedMessages = [];
77
+ function writeOut(message, isError = false) {
78
+ let processedMessage = message + '\n';
79
+ let hasSpinner = spinner.isSpinning;
80
+ // Stop spinner so we don't duplicate it
81
+ if (hasSpinner) {
82
+ spinner.stop();
83
+ }
84
+ let lines = (0, utils_1.countLines)(message);
85
+ if (isError) {
86
+ stderr.write(processedMessage);
87
+ errorLineCount += lines;
88
+ }
89
+ else {
90
+ stdout.write(processedMessage);
91
+ lineCount += lines;
92
+ }
93
+ // Restart the spinner
94
+ if (hasSpinner) {
95
+ spinner.start();
96
+ }
97
+ }
98
+ function persistMessage(message) {
99
+ if (persistedMessages.includes(message))
100
+ return;
101
+ persistedMessages.push(message);
102
+ writeOut(message);
103
+ }
104
+ function updateSpinner(message) {
105
+ // This helps the spinner play well with the tests
106
+ if (!exports.isTTY) {
107
+ writeOut(message);
108
+ return;
109
+ }
110
+ spinner.text = message + '\n';
111
+ if (!spinner.isSpinning) {
112
+ spinner.start();
113
+ }
114
+ }
115
+ function persistSpinner(name, status, message) {
116
+ spinner.stopAndPersist({
117
+ symbol: emoji[status],
118
+ text: message,
119
+ });
120
+ statusPersisted = true;
121
+ }
122
+ function clearStream(stream, lines) {
123
+ if (!exports.isTTY)
124
+ return;
125
+ readline_1.default.moveCursor(stream, 0, -lines);
126
+ readline_1.default.clearScreenDown(stream);
127
+ }
128
+ // Reset the window's state
129
+ function resetWindow() {
130
+ if (!exports.isTTY)
131
+ return;
132
+ // If status has been persisted we add a line
133
+ // Otherwise final states would remain in the terminal for rebuilds
134
+ if (statusPersisted) {
135
+ lineCount++;
136
+ statusPersisted = false;
137
+ }
138
+ clearStream(stderr, errorLineCount);
139
+ errorLineCount = 0;
140
+ clearStream(stdout, lineCount);
141
+ lineCount = 0;
142
+ for (let m of persistedMessages) {
143
+ writeOut(m);
144
+ }
145
+ }
146
+ function table(columns, table) {
147
+ // Measure column widths
148
+ let colWidths = [];
149
+ for (let row of table) {
150
+ let i = 0;
151
+ for (let item of row) {
152
+ colWidths[i] = Math.max(colWidths[i] || 0, (0, string_width_1.default)(item));
153
+ i++;
154
+ }
155
+ }
156
+ // Render rows
157
+ for (let row of table) {
158
+ let items = row.map((item, i) => {
159
+ // Add padding between columns unless the alignment is the opposite to the
160
+ // next column and pad to the column width.
161
+ let padding = !columns[i + 1] || columns[i + 1].align === columns[i].align ? 4 : 0;
162
+ return (0, utils_1.pad)(item, colWidths[i] + padding, columns[i].align);
163
+ });
164
+ writeOut(items.join(''));
165
+ }
166
+ }
package/dist/utils.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getTerminalWidth = getTerminalWidth;
7
+ exports.pad = pad;
8
+ exports.formatFilename = formatFilename;
9
+ exports.countLines = countLines;
10
+ const path_1 = __importDefault(require("path"));
11
+ const chalk_1 = __importDefault(require("chalk"));
12
+ const string_width_1 = __importDefault(require("string-width"));
13
+ const term_size_1 = __importDefault(require("term-size"));
14
+ const utils_1 = require("@atlaspack/utils");
15
+ let terminalSize = (0, term_size_1.default)();
16
+ process.stdout.on('resize', function () {
17
+ terminalSize = (0, term_size_1.default)();
18
+ });
19
+ function getTerminalWidth() {
20
+ return terminalSize;
21
+ }
22
+ // Pad a string with spaces on either side
23
+ function pad(text, length, align = 'left') {
24
+ let pad = ' '.repeat(length - (0, string_width_1.default)(text));
25
+ if (align === 'right') {
26
+ return pad + text;
27
+ }
28
+ return text + pad;
29
+ }
30
+ function formatFilename(filename, color = chalk_1.default.reset) {
31
+ let dir = path_1.default.relative(process.cwd(), path_1.default.dirname(filename));
32
+ return (chalk_1.default.dim(dir + (dir ? path_1.default.sep : '')) + color(path_1.default.basename(filename)));
33
+ }
34
+ function countLines(message) {
35
+ let { columns } = terminalSize;
36
+ return (0, utils_1.stripAnsi)(message)
37
+ .split('\n')
38
+ .reduce((p, line) => p + Math.ceil(((0, string_width_1.default)(line) || 1) / columns), 0);
39
+ }