@atlaspack/reporter-cli 2.15.1-canary.36 → 2.15.1-canary.360

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,112 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = bundleReport;
7
+ function _utils() {
8
+ const data = require("@atlaspack/utils");
9
+ _utils = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _filesize() {
15
+ const data = _interopRequireDefault(require("filesize"));
16
+ _filesize = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _chalk() {
22
+ const data = _interopRequireDefault(require("chalk"));
23
+ _chalk = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _nullthrows() {
29
+ const data = _interopRequireDefault(require("nullthrows"));
30
+ _nullthrows = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ var emoji = _interopRequireWildcard(require("./emoji"));
36
+ var _render = require("./render");
37
+ var _utils2 = require("./utils");
38
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
39
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
40
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
41
+ const LARGE_BUNDLE_SIZE = 1024 * 1024;
42
+ const COLUMNS = [{
43
+ align: 'left'
44
+ },
45
+ // name
46
+ {
47
+ align: 'right'
48
+ },
49
+ // size
50
+ {
51
+ align: 'right'
52
+ } // time
53
+ ];
54
+
55
+ async function bundleReport(bundleGraph, fs, projectRoot, assetCount = 0) {
56
+ let bundleList = bundleGraph.getBundles();
57
+
58
+ // Get a list of bundles sorted by size
59
+ let {
60
+ bundles
61
+ } = assetCount > 0 ? await (0, _utils().generateBuildMetrics)(bundleList, fs, projectRoot) : {
62
+ bundles: bundleList.map(b => {
63
+ return {
64
+ filePath: (0, _nullthrows().default)(b.filePath),
65
+ size: b.stats.size,
66
+ time: b.stats.time,
67
+ assets: []
68
+ };
69
+ })
70
+ };
71
+ let rows = [];
72
+ for (let bundle of bundles) {
73
+ // Add a row for the bundle
74
+ rows.push([(0, _utils2.formatFilename)(bundle.filePath || '', _chalk().default.cyan.bold), _chalk().default.bold(prettifySize(bundle.size, bundle.size > LARGE_BUNDLE_SIZE)), _chalk().default.green.bold((0, _utils().prettifyTime)(bundle.time))]);
75
+ if (assetCount > 0) {
76
+ let largestAssets = bundle.assets.slice(0, assetCount);
77
+ for (let asset of largestAssets) {
78
+ let columns = [asset == largestAssets[largestAssets.length - 1] ? '└── ' : '├── ',
79
+ // @ts-expect-error TS2554
80
+ _chalk().default.dim(prettifySize(asset.size)), _chalk().default.dim(_chalk().default.green((0, _utils().prettifyTime)(asset.time)))];
81
+ if (asset.filePath !== '') {
82
+ columns[0] += (0, _utils2.formatFilename)(asset.filePath, _chalk().default.reset);
83
+ } else {
84
+ columns[0] += 'Code from unknown sourcefiles';
85
+ }
86
+
87
+ // Add a row for the asset.
88
+ rows.push(columns);
89
+ }
90
+ if (bundle.assets.length > largestAssets.length) {
91
+ rows.push(['└── ' + _chalk().default.dim(`+ ${bundle.assets.length - largestAssets.length} more assets`)]);
92
+ }
93
+
94
+ // If this isn't the last bundle, add an empty row before the next one
95
+ if (bundle !== bundles[bundles.length - 1]) {
96
+ rows.push([]);
97
+ }
98
+ }
99
+ }
100
+
101
+ // Render table
102
+ (0, _render.writeOut)('');
103
+ // @ts-expect-error TS2345
104
+ (0, _render.table)(COLUMNS, rows);
105
+ }
106
+ function prettifySize(size, isLarge) {
107
+ let res = (0, _filesize().default)(size);
108
+ if (isLarge) {
109
+ return _chalk().default.yellow(emoji.warning + ' ' + res);
110
+ }
111
+ return _chalk().default.magenta(res);
112
+ }
package/lib/emoji.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.warning = exports.success = exports.progress = exports.info = exports.hint = exports.error = exports.docs = void 0;
7
+ // From https://github.com/sindresorhus/is-unicode-supported/blob/8f123916d5c25a87c4f966dcc248b7ca5df2b4ca/index.js
8
+ // This package is ESM-only so it has to be vendored
9
+ function isUnicodeSupported() {
10
+ if (process.platform !== 'win32') {
11
+ return process.env.TERM !== 'linux'; // Linux console (kernel)
12
+ }
13
+
14
+ return Boolean(process.env.CI) || Boolean(process.env.WT_SESSION) ||
15
+ // Windows Terminal
16
+ process.env.ConEmuTask === '{cmd::Cmder}' ||
17
+ // ConEmu and cmder
18
+ process.env.TERM_PROGRAM === 'vscode' || process.env.TERM === 'xterm-256color' || process.env.TERM === 'alacritty';
19
+ }
20
+ const supportsEmoji = isUnicodeSupported();
21
+
22
+ // Fallback symbols for Windows from https://en.wikipedia.org/wiki/Code_page_437
23
+ const progress = exports.progress = supportsEmoji ? '⏳' : '∞';
24
+ const success = exports.success = supportsEmoji ? '✨' : '√';
25
+ const error = exports.error = supportsEmoji ? '🚨' : '×';
26
+ const warning = exports.warning = supportsEmoji ? '⚠️' : '‼';
27
+ const info = exports.info = supportsEmoji ? 'ℹ️' : 'ℹ';
28
+ const hint = exports.hint = supportsEmoji ? '💡' : 'ℹ';
29
+ const docs = exports.docs = supportsEmoji ? '📝' : 'ℹ';
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const logLevels = {
8
+ none: 0,
9
+ error: 1,
10
+ warn: 2,
11
+ info: 3,
12
+ progress: 3,
13
+ success: 3,
14
+ verbose: 4
15
+ };
16
+ var _default = exports.default = logLevels;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = phaseReport;
7
+ function _utils() {
8
+ const data = require("@atlaspack/utils");
9
+ _utils = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _chalk() {
15
+ const data = _interopRequireDefault(require("chalk"));
16
+ _chalk = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ var _render = require("./render");
22
+ function _assert() {
23
+ const data = _interopRequireDefault(require("assert"));
24
+ _assert = function () {
25
+ return data;
26
+ };
27
+ return data;
28
+ }
29
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
+ function phaseReport(phaseStartTimes) {
31
+ let phaseTimes = {};
32
+ if (phaseStartTimes['transforming'] && phaseStartTimes['bundling']) {
33
+ phaseTimes['Transforming'] = phaseStartTimes['bundling'] - phaseStartTimes['transforming'];
34
+ }
35
+ let packagingAndOptimizing = phaseStartTimes['packaging'] && phaseStartTimes['optimizing'] ? Math.min(phaseStartTimes['packaging'], phaseStartTimes['optimizing']) : phaseStartTimes['packaging'] || phaseStartTimes['optimizing'];
36
+ if (phaseStartTimes['bundling'] && packagingAndOptimizing) {
37
+ phaseTimes['Bundling'] = packagingAndOptimizing - phaseStartTimes['bundling'];
38
+ }
39
+ if (packagingAndOptimizing && phaseStartTimes['buildSuccess']) {
40
+ phaseTimes['Packaging & Optimizing'] = phaseStartTimes['buildSuccess'] - packagingAndOptimizing;
41
+ }
42
+ for (let [phase, time] of Object.entries(phaseTimes)) {
43
+ (0, _assert().default)(typeof time === 'number');
44
+ (0, _render.writeOut)(_chalk().default.green.bold(`${phase} finished in ${(0, _utils().prettifyTime)(time)}`));
45
+ }
46
+ }
package/lib/render.js ADDED
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._setStdio = _setStdio;
7
+ exports.isTTY = void 0;
8
+ exports.persistMessage = persistMessage;
9
+ exports.persistSpinner = persistSpinner;
10
+ exports.resetWindow = resetWindow;
11
+ exports.table = table;
12
+ exports.updateSpinner = updateSpinner;
13
+ exports.writeOut = writeOut;
14
+ function _readline() {
15
+ const data = _interopRequireDefault(require("readline"));
16
+ _readline = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _ora() {
22
+ const data = _interopRequireDefault(require("ora"));
23
+ _ora = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _stringWidth() {
29
+ const data = _interopRequireDefault(require("string-width"));
30
+ _stringWidth = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ var _utils = require("./utils");
36
+ var emoji = _interopRequireWildcard(require("./emoji"));
37
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
38
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
39
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
+ const isTTY = exports.isTTY = process.env.NODE_ENV !== 'test' && process.stdout.isTTY;
41
+ let stdout = process.stdout;
42
+ let stderr = process.stderr;
43
+
44
+ // We pipe worker output to the process. If you
45
+ // have more than 10 threads then Nodejs will
46
+ // print warnings indicating you exceed the max
47
+ // listener count.
48
+ stdout.setMaxListeners(100);
49
+ stderr.setMaxListeners(100);
50
+
51
+ // Some state so we clear the output properly
52
+ let lineCount = 0;
53
+ let errorLineCount = 0;
54
+ let statusPersisted = false;
55
+ function _setStdio(stdoutLike, stderrLike) {
56
+ // @ts-expect-error TS2322
57
+ stdout = stdoutLike;
58
+ // @ts-expect-error TS2322
59
+ stderr = stderrLike;
60
+ }
61
+ let spinner = (0, _ora().default)({
62
+ color: 'green',
63
+ stream: stdout,
64
+ discardStdin: false
65
+ });
66
+ let persistedMessages = [];
67
+ function writeOut(message, isError = false) {
68
+ let processedMessage = message + '\n';
69
+ let hasSpinner = spinner.isSpinning;
70
+
71
+ // Stop spinner so we don't duplicate it
72
+ if (hasSpinner) {
73
+ spinner.stop();
74
+ }
75
+ let lines = (0, _utils.countLines)(message);
76
+ if (isError) {
77
+ stderr.write(processedMessage);
78
+ errorLineCount += lines;
79
+ } else {
80
+ stdout.write(processedMessage);
81
+ lineCount += lines;
82
+ }
83
+
84
+ // Restart the spinner
85
+ if (hasSpinner) {
86
+ spinner.start();
87
+ }
88
+ }
89
+ function persistMessage(message) {
90
+ if (persistedMessages.includes(message)) return;
91
+ persistedMessages.push(message);
92
+ writeOut(message);
93
+ }
94
+ function updateSpinner(message) {
95
+ // This helps the spinner play well with the tests
96
+ if (!isTTY) {
97
+ writeOut(message);
98
+ return;
99
+ }
100
+ spinner.text = message + '\n';
101
+ if (!spinner.isSpinning) {
102
+ spinner.start();
103
+ }
104
+ }
105
+ function persistSpinner(name, status, message) {
106
+ spinner.stopAndPersist({
107
+ symbol: emoji[status],
108
+ text: message
109
+ });
110
+ statusPersisted = true;
111
+ }
112
+ function clearStream(stream, lines) {
113
+ if (!isTTY) return;
114
+ _readline().default.moveCursor(stream, 0, -lines);
115
+ _readline().default.clearScreenDown(stream);
116
+ }
117
+
118
+ // Reset the window's state
119
+ function resetWindow() {
120
+ if (!isTTY) return;
121
+
122
+ // If status has been persisted we add a line
123
+ // Otherwise final states would remain in the terminal for rebuilds
124
+ if (statusPersisted) {
125
+ lineCount++;
126
+ statusPersisted = false;
127
+ }
128
+ clearStream(stderr, errorLineCount);
129
+ errorLineCount = 0;
130
+ clearStream(stdout, lineCount);
131
+ lineCount = 0;
132
+ for (let m of persistedMessages) {
133
+ writeOut(m);
134
+ }
135
+ }
136
+ function table(columns, table) {
137
+ // Measure column widths
138
+ let colWidths = [];
139
+ for (let row of table) {
140
+ let i = 0;
141
+ for (let item of row) {
142
+ colWidths[i] = Math.max(colWidths[i] || 0, (0, _stringWidth().default)(item));
143
+ i++;
144
+ }
145
+ }
146
+
147
+ // Render rows
148
+ for (let row of table) {
149
+ let items = row.map((item, i) => {
150
+ // Add padding between columns unless the alignment is the opposite to the
151
+ // next column and pad to the column width.
152
+ let padding = !columns[i + 1] || columns[i + 1].align === columns[i].align ? 4 : 0;
153
+ return (0, _utils.pad)(item, colWidths[i] + padding, columns[i].align);
154
+ });
155
+ writeOut(items.join(''));
156
+ }
157
+ }
@@ -0,0 +1,5 @@
1
+ import type { ReporterEvent, PluginOptions, PluginLogger } from '@atlaspack/types';
2
+ import { Reporter } from '@atlaspack/plugin';
3
+ export declare function _report(event: ReporterEvent, options: PluginOptions, logger: PluginLogger): Promise<void>;
4
+ declare const _default: Reporter;
5
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type { BundleGraph, FilePath, PackagedBundle } from '@atlaspack/types';
2
+ import type { FileSystem } from '@atlaspack/fs';
3
+ export default function bundleReport(bundleGraph: BundleGraph<PackagedBundle>, fs: FileSystem, projectRoot: FilePath, assetCount?: number): Promise<void>;
@@ -0,0 +1,7 @@
1
+ export declare const progress: string;
2
+ export declare const success: string;
3
+ export declare const error: string;
4
+ export declare const warning: string;
5
+ export declare const info: string;
6
+ export declare const hint: string;
7
+ export declare const docs: string;
@@ -0,0 +1,10 @@
1
+ declare const logLevels: {
2
+ readonly none: 0;
3
+ readonly error: 1;
4
+ readonly warn: 2;
5
+ readonly info: 3;
6
+ readonly progress: 3;
7
+ readonly success: 3;
8
+ readonly verbose: 4;
9
+ };
10
+ export default logLevels;
@@ -0,0 +1,3 @@
1
+ export default function phaseReport(phaseStartTimes: {
2
+ [key: string]: number;
3
+ }): void;
@@ -0,0 +1,14 @@
1
+ import type { Writable } from 'stream';
2
+ import type { PadAlign } from './utils';
3
+ type ColumnType = {
4
+ align: PadAlign;
5
+ };
6
+ export declare const isTTY: any | boolean | true;
7
+ export declare function _setStdio(stdoutLike: Writable, stderrLike: Writable): void;
8
+ export declare function writeOut(message: string, isError?: boolean): void;
9
+ export declare function persistMessage(message: string): void;
10
+ export declare function updateSpinner(message: string): void;
11
+ export declare function persistSpinner(name: string, status: 'success' | 'error', message: string): void;
12
+ export declare function resetWindow(): void;
13
+ export declare function table(columns: Array<ColumnType>, table: Array<Array<string>>): void;
14
+ export {};
@@ -0,0 +1,5 @@
1
+ export type PadAlign = 'left' | 'right';
2
+ export declare function getTerminalWidth(): any;
3
+ export declare function pad(text: string, length: number, align?: PadAlign): string;
4
+ export declare function formatFilename(filename: string, color?: (s: string) => string): string;
5
+ export declare function countLines(message: string): number;
package/lib/utils.js ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.countLines = countLines;
7
+ exports.formatFilename = formatFilename;
8
+ exports.getTerminalWidth = getTerminalWidth;
9
+ exports.pad = pad;
10
+ function _path() {
11
+ const data = _interopRequireDefault(require("path"));
12
+ _path = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _chalk() {
18
+ const data = _interopRequireDefault(require("chalk"));
19
+ _chalk = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _stringWidth() {
25
+ const data = _interopRequireDefault(require("string-width"));
26
+ _stringWidth = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ function _termSize() {
32
+ const data = _interopRequireDefault(require("term-size"));
33
+ _termSize = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ function _utils() {
39
+ const data = require("@atlaspack/utils");
40
+ _utils = function () {
41
+ return data;
42
+ };
43
+ return data;
44
+ }
45
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
46
+ let terminalSize = (0, _termSize().default)();
47
+ process.stdout.on('resize', function () {
48
+ terminalSize = (0, _termSize().default)();
49
+ });
50
+ function getTerminalWidth() {
51
+ return terminalSize;
52
+ }
53
+
54
+ // Pad a string with spaces on either side
55
+ function pad(text, length, align = 'left') {
56
+ let pad = ' '.repeat(length - (0, _stringWidth().default)(text));
57
+ if (align === 'right') {
58
+ return pad + text;
59
+ }
60
+ return text + pad;
61
+ }
62
+ function formatFilename(filename, color = _chalk().default.reset) {
63
+ let dir = _path().default.relative(process.cwd(), _path().default.dirname(filename));
64
+ return _chalk().default.dim(dir + (dir ? _path().default.sep : '')) + color(_path().default.basename(filename));
65
+ }
66
+ function countLines(message) {
67
+ let {
68
+ columns
69
+ } = terminalSize;
70
+ return (0, _utils().stripAnsi)(message).split('\n').reduce((p, line) => p + Math.ceil(((0, _stringWidth().default)(line) || 1) / columns), 0);
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/reporter-cli",
3
- "version": "2.15.1-canary.36+2d10c6656",
3
+ "version": "2.15.1-canary.360+fc3adc098",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,8 +9,9 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
- "main": "lib/CLIReporter.js",
13
- "source": "src/CLIReporter.js",
12
+ "main": "./lib/CLIReporter.js",
13
+ "source": "./src/CLIReporter.ts",
14
+ "types": "./lib/types/CLIReporter.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
@@ -26,20 +27,23 @@
26
27
  }
27
28
  },
28
29
  "dependencies": {
29
- "@atlaspack/plugin": "2.14.5-canary.36+2d10c6656",
30
- "@atlaspack/types": "2.14.5-canary.36+2d10c6656",
31
- "@atlaspack/utils": "2.14.5-canary.36+2d10c6656",
30
+ "@atlaspack/plugin": "2.14.5-canary.360+fc3adc098",
31
+ "@atlaspack/types": "2.14.5-canary.360+fc3adc098",
32
+ "@atlaspack/utils": "2.14.5-canary.360+fc3adc098",
32
33
  "chalk": "^4.1.0",
33
- "term-size": "^2.2.1"
34
- },
35
- "devDependencies": {
36
- "@atlaspack/feature-flags": "2.14.1-canary.104+2d10c6656",
37
34
  "filesize": "^6.1.0",
38
35
  "nullthrows": "^1.1.1",
39
36
  "ora": "^5.2.0",
40
37
  "string-width": "^4.2.0",
38
+ "term-size": "^2.2.1",
41
39
  "wrap-ansi": "^7.0.0"
42
40
  },
41
+ "devDependencies": {
42
+ "@atlaspack/feature-flags": "2.14.1-canary.428+fc3adc098"
43
+ },
43
44
  "type": "commonjs",
44
- "gitHead": "2d10c6656fc58743c5dbed1d2b6c5666887f9fe4"
45
- }
45
+ "scripts": {
46
+ "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
47
+ },
48
+ "gitHead": "fc3adc098f583e40d6d7687412cac6dde7cbb3f3"
49
+ }