@atlaspack/reporter-cli 2.15.1-canary.138 → 2.15.1-canary.139

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,5 @@
1
+ import type { ReporterEvent, PluginOptions } from '@atlaspack/types';
2
+ import { Reporter } from '@atlaspack/plugin';
3
+ export declare function _report(event: ReporterEvent, options: PluginOptions): Promise<void>;
4
+ declare const _default: Reporter;
5
+ export default _default;
@@ -49,6 +49,8 @@ function _wrapAnsi() {
49
49
  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); }
50
50
  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; }
51
51
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
52
+ // @ts-expect-error TS7016
53
+
52
54
  const THROTTLE_DELAY = 100;
53
55
  const seenWarnings = new Set();
54
56
  const seenPhases = new Set();
@@ -208,12 +210,15 @@ async function _report(event, options) {
208
210
  await writeDiagnostic(options, event.diagnostics, 'red', true);
209
211
  break;
210
212
  default:
213
+ // @ts-expect-error TS2339
211
214
  throw new Error('Unknown log level ' + event.level);
212
215
  }
213
216
  }
214
217
  }
215
218
  }
216
- async function writeDiagnostic(options, diagnostics, color, isError = false) {
219
+ async function writeDiagnostic(options, diagnostics,
220
+ // @ts-expect-error TS2749
221
+ color, isError = false) {
217
222
  let columns = (0, _utils2.getTerminalWidth)().columns;
218
223
  let indent = 2;
219
224
  let spaceAfter = isError;
@@ -225,7 +230,7 @@ async function writeDiagnostic(options, diagnostics, color, isError = false) {
225
230
  hints,
226
231
  documentation
227
232
  } = await (0, _utils().prettyDiagnostic)(diagnostic, options, columns - indent);
228
- // $FlowFixMe[incompatible-use]
233
+ // @ts-expect-error TS7053
229
234
  message = _chalk().default[color](message);
230
235
  if (spaceAfter) {
231
236
  (0, _render.writeOut)('');
@@ -254,6 +259,8 @@ async function writeDiagnostic(options, diagnostics, color, isError = false) {
254
259
  if (documentation) {
255
260
  (0, _render.writeOut)(wrapWithIndent(`${emoji.docs} ${_chalk().default.magenta.bold(documentation)}`, hintIndent + 3, hintIndent));
256
261
  }
262
+
263
+ // @ts-expect-error TS2322
257
264
  spaceAfter = stack || codeframe || hints.length > 0 || documentation;
258
265
  }
259
266
  if (spaceAfter) {
@@ -266,6 +273,8 @@ function wrapWithIndent(string, indent = 0, initialIndent = indent) {
266
273
  trim: false
267
274
  }), indent, initialIndent);
268
275
  }
276
+
277
+ // @ts-expect-error TS7006
269
278
  function indentString(string, indent = 0, initialIndent = indent) {
270
279
  return ' '.repeat(initialIndent) + string.replace(/\n/g, '\n' + ' '.repeat(indent));
271
280
  }
@@ -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>;
@@ -75,7 +75,9 @@ async function bundleReport(bundleGraph, fs, projectRoot, assetCount = 0) {
75
75
  if (assetCount > 0) {
76
76
  let largestAssets = bundle.assets.slice(0, assetCount);
77
77
  for (let asset of largestAssets) {
78
- let columns = [asset == largestAssets[largestAssets.length - 1] ? '└── ' : '├── ', _chalk().default.dim(prettifySize(asset.size)), _chalk().default.dim(_chalk().default.green((0, _utils().prettifyTime)(asset.time)))];
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)))];
79
81
  if (asset.filePath !== '') {
80
82
  columns[0] += (0, _utils2.formatFilename)(asset.filePath, _chalk().default.reset);
81
83
  } else {
@@ -98,6 +100,7 @@ async function bundleReport(bundleGraph, fs, projectRoot, assetCount = 0) {
98
100
 
99
101
  // Render table
100
102
  (0, _render.writeOut)('');
103
+ // @ts-expect-error TS2345
101
104
  (0, _render.table)(COLUMNS, rows);
102
105
  }
103
106
  function prettifySize(size, isLarge) {
package/lib/emoji.d.ts ADDED
@@ -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 {};
package/lib/render.js CHANGED
@@ -37,9 +37,7 @@ var emoji = _interopRequireWildcard(require("./emoji"));
37
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
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
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
- const isTTY = exports.isTTY =
41
- // $FlowFixMe
42
- process.env.NODE_ENV !== 'test' && process.stdout.isTTY;
40
+ const isTTY = exports.isTTY = process.env.NODE_ENV !== 'test' && process.stdout.isTTY;
43
41
  let stdout = process.stdout;
44
42
  let stderr = process.stderr;
45
43
 
@@ -55,7 +53,9 @@ let lineCount = 0;
55
53
  let errorLineCount = 0;
56
54
  let statusPersisted = false;
57
55
  function _setStdio(stdoutLike, stderrLike) {
56
+ // @ts-expect-error TS2322
58
57
  stdout = stdoutLike;
58
+ // @ts-expect-error TS2322
59
59
  stderr = stderrLike;
60
60
  }
61
61
  let spinner = (0, _ora().default)({
package/lib/utils.d.ts ADDED
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/reporter-cli",
3
- "version": "2.15.1-canary.138+eda07caaf",
3
+ "version": "2.15.1-canary.139+d2fd84977",
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/CLIReporter.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
@@ -26,9 +27,9 @@
26
27
  }
27
28
  },
28
29
  "dependencies": {
29
- "@atlaspack/plugin": "2.14.5-canary.138+eda07caaf",
30
- "@atlaspack/types": "2.14.5-canary.138+eda07caaf",
31
- "@atlaspack/utils": "2.14.5-canary.138+eda07caaf",
30
+ "@atlaspack/plugin": "2.14.5-canary.139+d2fd84977",
31
+ "@atlaspack/types": "2.14.5-canary.139+d2fd84977",
32
+ "@atlaspack/utils": "2.14.5-canary.139+d2fd84977",
32
33
  "chalk": "^4.1.0",
33
34
  "filesize": "^6.1.0",
34
35
  "nullthrows": "^1.1.1",
@@ -38,8 +39,11 @@
38
39
  "wrap-ansi": "^7.0.0"
39
40
  },
40
41
  "devDependencies": {
41
- "@atlaspack/feature-flags": "2.14.1-canary.206+eda07caaf"
42
+ "@atlaspack/feature-flags": "2.14.1-canary.207+d2fd84977"
42
43
  },
43
44
  "type": "commonjs",
44
- "gitHead": "eda07caafd2ebb814bbdbfd0ec12fa63124e213f"
45
- }
45
+ "scripts": {
46
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
47
+ },
48
+ "gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
49
+ }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {ReporterEvent, PluginOptions} from '@atlaspack/types';
3
2
  import type {Diagnostic} from '@atlaspack/diagnostic';
4
3
  import type {Color} from 'chalk';
@@ -28,6 +27,7 @@ import {
28
27
  persistMessage,
29
28
  } from './render';
30
29
  import * as emoji from './emoji';
30
+ // @ts-expect-error TS7016
31
31
  import wrapAnsi from 'wrap-ansi';
32
32
 
33
33
  const THROTTLE_DELAY = 100;
@@ -35,7 +35,7 @@ const seenWarnings = new Set();
35
35
  const seenPhases = new Set();
36
36
  const seenPhasesGen = new Set();
37
37
 
38
- let phaseStartTimes = {};
38
+ let phaseStartTimes: Record<string, any> = {};
39
39
  let pendingIncrementalBuild = false;
40
40
  let packagingProgress = 0;
41
41
 
@@ -63,9 +63,9 @@ let statusThrottle = throttle((message: string) => {
63
63
  updateSpinner(message);
64
64
  }, THROTTLE_DELAY);
65
65
 
66
- const cacheWriteState: {|
67
- startTime: number | null,
68
- |} = {
66
+ const cacheWriteState: {
67
+ startTime: number | null;
68
+ } = {
69
69
  startTime: null,
70
70
  };
71
71
 
@@ -247,6 +247,7 @@ export async function _report(
247
247
  await writeDiagnostic(options, event.diagnostics, 'red', true);
248
248
  break;
249
249
  default:
250
+ // @ts-expect-error TS2339
250
251
  throw new Error('Unknown log level ' + event.level);
251
252
  }
252
253
  }
@@ -256,6 +257,7 @@ export async function _report(
256
257
  async function writeDiagnostic(
257
258
  options: PluginOptions,
258
259
  diagnostics: Array<Diagnostic>,
260
+ // @ts-expect-error TS2749
259
261
  color: Color,
260
262
  isError: boolean = false,
261
263
  ) {
@@ -265,7 +267,7 @@ async function writeDiagnostic(
265
267
  for (let diagnostic of diagnostics) {
266
268
  let {message, stack, codeframe, hints, documentation} =
267
269
  await prettyDiagnostic(diagnostic, options, columns - indent);
268
- // $FlowFixMe[incompatible-use]
270
+ // @ts-expect-error TS7053
269
271
  message = chalk[color](message);
270
272
 
271
273
  if (spaceAfter) {
@@ -314,6 +316,7 @@ async function writeDiagnostic(
314
316
  );
315
317
  }
316
318
 
319
+ // @ts-expect-error TS2322
317
320
  spaceAfter = stack || codeframe || hints.length > 0 || documentation;
318
321
  }
319
322
 
@@ -322,7 +325,7 @@ async function writeDiagnostic(
322
325
  }
323
326
  }
324
327
 
325
- function wrapWithIndent(string, indent = 0, initialIndent = indent) {
328
+ function wrapWithIndent(string: string, indent = 0, initialIndent = indent) {
326
329
  let width = getTerminalWidth().columns;
327
330
  return indentString(
328
331
  wrapAnsi(string.trimEnd(), width - indent, {trim: false}),
@@ -331,14 +334,15 @@ function wrapWithIndent(string, indent = 0, initialIndent = indent) {
331
334
  );
332
335
  }
333
336
 
337
+ // @ts-expect-error TS7006
334
338
  function indentString(string, indent = 0, initialIndent = indent) {
335
339
  return (
336
340
  ' '.repeat(initialIndent) + string.replace(/\n/g, '\n' + ' '.repeat(indent))
337
341
  );
338
342
  }
339
343
 
340
- export default (new Reporter({
344
+ export default new Reporter({
341
345
  report({event, options}) {
342
346
  return _report(event, options);
343
347
  },
344
- }): Reporter);
348
+ }) as Reporter;
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {BundleGraph, FilePath, PackagedBundle} from '@atlaspack/types';
3
2
  import type {FileSystem} from '@atlaspack/fs';
4
3
 
@@ -40,7 +39,7 @@ export default async function bundleReport(
40
39
  };
41
40
  }),
42
41
  };
43
- let rows = [];
42
+ let rows: Array<Array<string>> = [];
44
43
 
45
44
  for (let bundle of bundles) {
46
45
  // Add a row for the bundle
@@ -55,6 +54,7 @@ export default async function bundleReport(
55
54
  for (let asset of largestAssets) {
56
55
  let columns: Array<string> = [
57
56
  asset == largestAssets[largestAssets.length - 1] ? '└── ' : '├── ',
57
+ // @ts-expect-error TS2554
58
58
  chalk.dim(prettifySize(asset.size)),
59
59
  chalk.dim(chalk.green(prettifyTime(asset.time))),
60
60
  ];
@@ -87,10 +87,11 @@ export default async function bundleReport(
87
87
 
88
88
  // Render table
89
89
  writeOut('');
90
+ // @ts-expect-error TS2345
90
91
  table(COLUMNS, rows);
91
92
  }
92
93
 
93
- function prettifySize(size, isLarge) {
94
+ function prettifySize(size: number, isLarge: undefined | boolean) {
94
95
  let res = filesize(size);
95
96
  if (isLarge) {
96
97
  return chalk.yellow(emoji.warning + ' ' + res);
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  // From https://github.com/sindresorhus/is-unicode-supported/blob/8f123916d5c25a87c4f966dcc248b7ca5df2b4ca/index.js
4
2
  // This package is ESM-only so it has to be vendored
5
3
  function isUnicodeSupported() {
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  const logLevels = {
4
2
  none: 0,
5
3
  error: 1,
@@ -8,6 +6,6 @@ const logLevels = {
8
6
  progress: 3,
9
7
  success: 3,
10
8
  verbose: 4,
11
- };
9
+ } as const;
12
10
 
13
11
  export default logLevels;
@@ -1,11 +1,10 @@
1
- // @flow
2
1
  import {prettifyTime} from '@atlaspack/utils';
3
2
  import chalk from 'chalk';
4
3
  import {writeOut} from './render';
5
4
  import invariant from 'assert';
6
5
 
7
- export default function phaseReport(phaseStartTimes: {[string]: number}) {
8
- let phaseTimes = {};
6
+ export default function phaseReport(phaseStartTimes: {[key: string]: number}) {
7
+ let phaseTimes: Record<string, any> = {};
9
8
  if (phaseStartTimes['transforming'] && phaseStartTimes['bundling']) {
10
9
  phaseTimes['Transforming'] =
11
10
  phaseStartTimes['bundling'] - phaseStartTimes['transforming'];
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {Writable} from 'stream';
3
2
 
4
3
  import readline from 'readline';
@@ -9,12 +8,11 @@ import type {PadAlign} from './utils';
9
8
  import {pad, countLines} from './utils';
10
9
  import * as emoji from './emoji';
11
10
 
12
- type ColumnType = {|
13
- align: PadAlign,
14
- |};
11
+ type ColumnType = {
12
+ align: PadAlign;
13
+ };
15
14
 
16
15
  export const isTTY: any | boolean | true =
17
- // $FlowFixMe
18
16
  process.env.NODE_ENV !== 'test' && process.stdout.isTTY;
19
17
 
20
18
  let stdout = process.stdout;
@@ -33,7 +31,9 @@ let errorLineCount = 0;
33
31
  let statusPersisted = false;
34
32
 
35
33
  export function _setStdio(stdoutLike: Writable, stderrLike: Writable) {
34
+ // @ts-expect-error TS2322
36
35
  stdout = stdoutLike;
36
+ // @ts-expect-error TS2322
37
37
  stderr = stderrLike;
38
38
  }
39
39
 
@@ -42,7 +42,7 @@ let spinner = ora({
42
42
  stream: stdout,
43
43
  discardStdin: false,
44
44
  });
45
- let persistedMessages = [];
45
+ let persistedMessages: Array<string> = [];
46
46
 
47
47
  export function writeOut(message: string, isError: boolean = false) {
48
48
  let processedMessage = message + '\n';
@@ -132,7 +132,7 @@ export function resetWindow() {
132
132
 
133
133
  export function table(columns: Array<ColumnType>, table: Array<Array<string>>) {
134
134
  // Measure column widths
135
- let colWidths = [];
135
+ let colWidths: Array<number> = [];
136
136
  for (let row of table) {
137
137
  let i = 0;
138
138
  for (let item of row) {
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import path from 'path';
3
2
  import chalk from 'chalk';
4
3
  import stringWidth from 'string-width';
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import sinon from 'sinon';
5
3
  import {PassThrough} from 'stream';
@@ -39,13 +37,13 @@ const EMPTY_OPTIONS = {
39
37
  assetsPerBundle: 10,
40
38
  },
41
39
  featureFlags: DEFAULT_FEATURE_FLAGS,
42
- };
40
+ } as const;
43
41
 
44
42
  describe('CLIReporter', () => {
45
- let originalStdout;
46
- let originalStderr;
47
- let stdoutOutput;
48
- let stderrOutput;
43
+ let originalStdout: any;
44
+ let originalStderr: any;
45
+ let stdoutOutput: any;
46
+ let stderrOutput: any;
49
47
 
50
48
  beforeEach(async () => {
51
49
  // Stub these out to avoid writing noise to real stdio and to read from these
@@ -57,9 +55,15 @@ describe('CLIReporter', () => {
57
55
  stderrOutput = '';
58
56
 
59
57
  let mockStdout = new PassThrough();
60
- mockStdout.on('data', (d) => (stdoutOutput += stripAnsi(d.toString())));
58
+ mockStdout.on(
59
+ 'data',
60
+ (d: any) => (stdoutOutput += stripAnsi(d.toString())),
61
+ );
61
62
  let mockStderr = new PassThrough();
62
- mockStderr.on('data', (d) => (stderrOutput += stripAnsi(d.toString())));
63
+ mockStderr.on(
64
+ 'data',
65
+ (d: any) => (stderrOutput += stripAnsi(d.toString())),
66
+ );
63
67
  _setStdio(mockStdout, mockStderr);
64
68
 
65
69
  await _report(
@@ -200,7 +204,6 @@ describe('CLIReporter', () => {
200
204
  // emit a buildSuccess event to reset the timings and seen phases
201
205
  // from the previous test
202
206
  process.env['ATLASPACK_SHOW_PHASE_TIMES'] = undefined;
203
- // $FlowFixMe
204
207
  await _report({type: 'buildSuccess'}, EMPTY_OPTIONS);
205
208
 
206
209
  process.env['ATLASPACK_SHOW_PHASE_TIMES'] = 'true';
@@ -210,17 +213,16 @@ describe('CLIReporter', () => {
210
213
  );
211
214
  await _report({type: 'buildProgress', phase: 'bundling'}, EMPTY_OPTIONS);
212
215
  await _report(
213
- // $FlowFixMe
214
216
  {
215
217
  type: 'buildProgress',
216
218
  phase: 'packaging',
219
+
217
220
  bundle: {
218
221
  displayName: 'test',
219
222
  },
220
223
  },
221
224
  EMPTY_OPTIONS,
222
225
  );
223
- // $FlowFixMe
224
226
  await _report({type: 'buildSuccess'}, EMPTY_OPTIONS);
225
227
  const expected =
226
228
  /Building...\nBundling...\nPackaging & Optimizing...\nTransforming finished in [0-9]ms\nBundling finished in [0-9]ms\nPackaging & Optimizing finished in [0-9]ms/;
@@ -235,17 +237,16 @@ describe('CLIReporter', () => {
235
237
  );
236
238
  await _report({type: 'buildProgress', phase: 'bundling'}, EMPTY_OPTIONS);
237
239
  await _report(
238
- // $FlowFixMe
239
240
  {
240
241
  type: 'buildProgress',
241
242
  phase: 'packaging',
243
+
242
244
  bundle: {
243
245
  displayName: 'test',
244
246
  },
245
247
  },
246
248
  EMPTY_OPTIONS,
247
249
  );
248
- // $FlowFixMe
249
250
  await _report({type: 'buildSuccess'}, EMPTY_OPTIONS);
250
251
 
251
252
  assert.equal(
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }