diff --git a/packages/gatsby-reporter/lib/catch-exit-signals.d.ts b/packages/gatsby-reporter/lib/catch-exit-signals.d.ts deleted file mode 100644 index d6cff1927be77..0000000000000 --- a/packages/gatsby-reporter/lib/catch-exit-signals.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export declare const prematureEnd: () => void; -export declare const catchExitSignals: () => void; diff --git a/packages/gatsby-reporter/lib/catch-exit-signals.js b/packages/gatsby-reporter/lib/catch-exit-signals.js deleted file mode 100644 index 936f3b8c891df..0000000000000 --- a/packages/gatsby-reporter/lib/catch-exit-signals.js +++ /dev/null @@ -1,54 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.catchExitSignals = exports.prematureEnd = void 0; - -var _signalExit = _interopRequireDefault(require("signal-exit")); - -var _redux = require("./redux"); - -var _actions = require("./redux/actions"); - -var _constants = require("./constants"); - -var _reporter = require("./reporter"); - -/* - * This module is used to catch if the user kills the gatsby process via cmd+c - * When this happens, there is some clean up logic we need to fire offf - */ -const interruptActivities = () => { - const { - activities - } = (0, _redux.getStore)().getState().logs; - Object.keys(activities).forEach(activityId => { - const activity = activities[activityId]; - - if (activity.status === _constants.ActivityStatuses.InProgress || activity.status === _constants.ActivityStatuses.NotStarted) { - _reporter.reporter.completeActivity(activityId, _constants.ActivityStatuses.Interrupted); - } - }); -}; - -const prematureEnd = () => { - // hack so at least one activity is surely failed, so - // we are guaranteed to generate FAILED status - // if none of activity did explicitly fail - (0, _actions.createPendingActivity)({ - id: `panic`, - status: _constants.ActivityStatuses.Failed - }); - interruptActivities(); -}; - -exports.prematureEnd = prematureEnd; - -const catchExitSignals = () => { - (0, _signalExit.default)((code, signal) => { - if (code !== 0 && signal !== `SIGINT` && signal !== `SIGTERM`) prematureEnd();else interruptActivities(); - }); -}; - -exports.catchExitSignals = catchExitSignals; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/constants.d.ts b/packages/gatsby-reporter/lib/constants.d.ts deleted file mode 100644 index 5216469ee7068..0000000000000 --- a/packages/gatsby-reporter/lib/constants.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -export declare enum Actions { - LogAction = "LOG_ACTION", - SetStatus = "SET_STATUS", - Log = "LOG", - SetLogs = "SET_LOGS", - StartActivity = "ACTIVITY_START", - EndActivity = "ACTIVITY_END", - UpdateActivity = "ACTIVITY_UPDATE", - PendingActivity = "ACTIVITY_PENDING", - CancelActivity = "ACTIVITY_CANCEL", - ActivityErrored = "ACTIVITY_ERRORED" -} -export declare enum LogLevels { - Debug = "DEBUG", - Success = "SUCCESS", - Info = "INFO", - Warning = "WARNING", - Log = "LOG", - Error = "ERROR" -} -export declare enum ActivityLogLevels { - Success = "ACTIVITY_SUCCESS", - Failed = "ACTIVITY_FAILED", - Interrupted = "ACTIVITY_INTERRUPTED" -} -export declare enum ActivityStatuses { - InProgress = "IN_PROGRESS", - NotStarted = "NOT_STARTED", - Interrupted = "INTERRUPTED", - Failed = "FAILED", - Success = "SUCCESS", - Cancelled = "CANCELLED" -} -export declare enum ActivityTypes { - Spinner = "spinner", - Hidden = "hidden", - Progress = "progress", - Pending = "pending" -} diff --git a/packages/gatsby-reporter/lib/constants.js b/packages/gatsby-reporter/lib/constants.js deleted file mode 100644 index 45a269a0c472a..0000000000000 --- a/packages/gatsby-reporter/lib/constants.js +++ /dev/null @@ -1,62 +0,0 @@ -"use strict"; - -exports.__esModule = true; -exports.ActivityTypes = exports.ActivityStatuses = exports.ActivityLogLevels = exports.LogLevels = exports.Actions = void 0; -let Actions; -exports.Actions = Actions; - -(function (Actions) { - Actions["LogAction"] = "LOG_ACTION"; - Actions["SetStatus"] = "SET_STATUS"; - Actions["Log"] = "LOG"; - Actions["SetLogs"] = "SET_LOGS"; - Actions["StartActivity"] = "ACTIVITY_START"; - Actions["EndActivity"] = "ACTIVITY_END"; - Actions["UpdateActivity"] = "ACTIVITY_UPDATE"; - Actions["PendingActivity"] = "ACTIVITY_PENDING"; - Actions["CancelActivity"] = "ACTIVITY_CANCEL"; - Actions["ActivityErrored"] = "ACTIVITY_ERRORED"; -})(Actions || (exports.Actions = Actions = {})); - -let LogLevels; -exports.LogLevels = LogLevels; - -(function (LogLevels) { - LogLevels["Debug"] = "DEBUG"; - LogLevels["Success"] = "SUCCESS"; - LogLevels["Info"] = "INFO"; - LogLevels["Warning"] = "WARNING"; - LogLevels["Log"] = "LOG"; - LogLevels["Error"] = "ERROR"; -})(LogLevels || (exports.LogLevels = LogLevels = {})); - -let ActivityLogLevels; -exports.ActivityLogLevels = ActivityLogLevels; - -(function (ActivityLogLevels) { - ActivityLogLevels["Success"] = "ACTIVITY_SUCCESS"; - ActivityLogLevels["Failed"] = "ACTIVITY_FAILED"; - ActivityLogLevels["Interrupted"] = "ACTIVITY_INTERRUPTED"; -})(ActivityLogLevels || (exports.ActivityLogLevels = ActivityLogLevels = {})); - -let ActivityStatuses; -exports.ActivityStatuses = ActivityStatuses; - -(function (ActivityStatuses) { - ActivityStatuses["InProgress"] = "IN_PROGRESS"; - ActivityStatuses["NotStarted"] = "NOT_STARTED"; - ActivityStatuses["Interrupted"] = "INTERRUPTED"; - ActivityStatuses["Failed"] = "FAILED"; - ActivityStatuses["Success"] = "SUCCESS"; - ActivityStatuses["Cancelled"] = "CANCELLED"; -})(ActivityStatuses || (exports.ActivityStatuses = ActivityStatuses = {})); - -let ActivityTypes; -exports.ActivityTypes = ActivityTypes; - -(function (ActivityTypes) { - ActivityTypes["Spinner"] = "spinner"; - ActivityTypes["Hidden"] = "hidden"; - ActivityTypes["Progress"] = "progress"; - ActivityTypes["Pending"] = "pending"; -})(ActivityTypes || (exports.ActivityTypes = ActivityTypes = {})); \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/get-error-formater.d.ts b/packages/gatsby-reporter/lib/get-error-formater.d.ts deleted file mode 100644 index 8de727c96a591..0000000000000 --- a/packages/gatsby-reporter/lib/get-error-formater.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import PrettyError from "pretty-error"; -export declare function getErrorFormatter(): PrettyError; diff --git a/packages/gatsby-reporter/lib/get-error-formater.js b/packages/gatsby-reporter/lib/get-error-formater.js deleted file mode 100644 index a55c5411a238e..0000000000000 --- a/packages/gatsby-reporter/lib/get-error-formater.js +++ /dev/null @@ -1,49 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.getErrorFormatter = getErrorFormatter; - -var _prettyError = _interopRequireDefault(require("pretty-error")); - -function getErrorFormatter() { - const prettyError = new _prettyError.default(); - const baseRender = prettyError.render; - prettyError.skipNodeFiles(); - prettyError.skipPackage(`regenerator-runtime`, `graphql`, `core-js` // `static-site-generator-webpack-plugin`, - // `tapable`, // webpack - ); // @ts-ignore the type defs in prettyError are wrong - - prettyError.skip(traceLine => { - if (traceLine && traceLine.file === `asyncToGenerator.js`) return true; - return false; - }); - prettyError.appendStyle({ - "pretty-error": { - marginTop: 1 - }, - "pretty-error > header": { - background: `red` - }, - "pretty-error > header > colon": { - color: `white` - } - }); - - if (process.env.FORCE_COLOR === `0`) { - prettyError.withoutColors(); - } - - prettyError.render = err => { - if (Array.isArray(err)) { - return err.map(e => prettyError.render(e)).join(`\n`); - } - - let rendered = baseRender.call(prettyError, err); - if (`codeFrame` in err) rendered = `\n${err.codeFrame}\n${rendered}`; - return rendered; - }; - - return prettyError; -} \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/index.d.ts b/packages/gatsby-reporter/lib/index.d.ts deleted file mode 100644 index 84ebe9969e52a..0000000000000 --- a/packages/gatsby-reporter/lib/index.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { reporter } from "./reporter"; -import { setStore } from "./redux"; -import { IGatsbyCLIState } from "./redux/types"; -import { IActivityArgs, IPhantomReporter, IProgressReporter } from "./types"; -export { reporter }; -export { setStore }; -export declare const reduxLogReducer: (state: IGatsbyCLIState | undefined, action: import("./redux/types").ActionsUnion) => IGatsbyCLIState; -export { IActivityArgs, IPhantomReporter, IProgressReporter, IGatsbyCLIState }; -export declare type IGatsbyReporter = typeof reporter; diff --git a/packages/gatsby-reporter/lib/index.js b/packages/gatsby-reporter/lib/index.js deleted file mode 100644 index 0482b3741fcf7..0000000000000 --- a/packages/gatsby-reporter/lib/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; - -exports.__esModule = true; -exports.reduxLogReducer = void 0; - -var _startLogger = require("./start-logger"); - -var _patchConsole = require("./patch-console"); - -var _catchExitSignals = require("./catch-exit-signals"); - -var _reporter = require("./reporter"); - -exports.reporter = _reporter.reporter; - -var _redux = require("./redux"); - -exports.setStore = _redux.setStore; - -var _reducer = require("./redux/reducer"); - -var _types = require("./redux/types"); - -exports.IGatsbyCLIState = _types.IGatsbyCLIState; - -var _types2 = require("./types"); - -exports.IActivityArgs = _types2.IActivityArgs; -exports.IPhantomReporter = _types2.IPhantomReporter; -exports.IProgressReporter = _types2.IProgressReporter; -(0, _catchExitSignals.catchExitSignals)(); -(0, _startLogger.startLogger)(); -(0, _patchConsole.patchConsole)(_reporter.reporter); -const reduxLogReducer = _reducer.reducer; // Types - -exports.reduxLogReducer = reduxLogReducer; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ink/cli.d.ts b/packages/gatsby-reporter/lib/loggers/ink/cli.d.ts deleted file mode 100644 index cbea1dbc5f3c6..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/cli.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import React from "react"; -import { IGatsbyCLIState } from "../../redux/types"; -interface ICLIProps { - logs: IGatsbyCLIState; - showStatusBar: boolean; -} -interface ICLIState { - hasError: boolean; - error?: Error; -} -declare class CLI extends React.Component { - readonly state: ICLIState; - memoizedReactElementsForMessages: React.ReactElement[]; - componentDidCatch(error: Error, info: React.ErrorInfo): void; - static getDerivedStateFromError(error: Error): ICLIState; - render(): React.ReactElement; -} -export default CLI; diff --git a/packages/gatsby-reporter/lib/loggers/ink/cli.js b/packages/gatsby-reporter/lib/loggers/ink/cli.js deleted file mode 100644 index 5528193cfd77c..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/cli.js +++ /dev/null @@ -1,143 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.default = void 0; - -var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); - -var _react = _interopRequireDefault(require("react")); - -var _ink = require("ink"); - -var _gatsbyTelemetry = require("gatsby-telemetry"); - -var _spinner = require("./components/spinner"); - -var _progressBar = require("./components/progress-bar"); - -var _messages = require("./components/messages"); - -var _error = require("./components/error"); - -var _develop = _interopRequireDefault(require("./components/develop")); - -var _constants = require("../../constants"); - -var _gatsbyCoreUtils = require("gatsby-core-utils"); - -// Some CI pipelines incorrectly report process.stdout.isTTY status, -// which causes unwanted lines in the output. An additional check for isCI helps. -// @see https://github.com/prettier/prettier/blob/36aeb4ce4f620023c8174e826d7208c0c64f1a0b/src/utils/is-tty.js -const showProgress = process.stdout.isTTY && !(0, _gatsbyCoreUtils.isCI)(); - -class CLI extends _react.default.Component { - constructor(...args) { - super(...args); - this.state = { - hasError: false - }; - this.memoizedReactElementsForMessages = []; - } - - componentDidCatch(error, info) { - (0, _gatsbyTelemetry.trackBuildError)(`INK`, { - error: { - stack: info.componentStack, - text: error.message, - context: {} - } - }); - } - - static getDerivedStateFromError(error) { - return { - hasError: true, - error - }; - } - - render() { - const { - logs: { - messages, - activities - }, - showStatusBar - } = this.props; - const { - hasError, - error - } = this.state; - - if (hasError && error) { - // You can render any custom fallback UI - return /*#__PURE__*/_react.default.createElement(_ink.Box, { - flexDirection: "row" - }, /*#__PURE__*/_react.default.createElement(_messages.Message, { - level: _constants.ActivityLogLevels.Failed, - text: `We've encountered an error: ${error.message}` - })); - } - /* - Only operation on messages array is to push new message into it. Once - message is there it can't change. Because of that we can do single - transform from message object to react element and store it. - This will avoid calling React.createElement completely for every message - that can't change. - */ - - - if (messages.length > this.memoizedReactElementsForMessages.length) { - for (let index = this.memoizedReactElementsForMessages.length; index < messages.length; index++) { - const msg = messages[index]; - this.memoizedReactElementsForMessages.push(msg.level === `ERROR` ? /*#__PURE__*/_react.default.createElement(_error.Error, { - details: msg, - key: index - }) : /*#__PURE__*/_react.default.createElement(_messages.Message, (0, _extends2.default)({ - key: index - }, msg))); - } - } - - const spinners = []; - const progressBars = []; - - if (showProgress) { - Object.keys(activities).forEach(activityName => { - const activity = activities[activityName]; - - if (activity.status !== `IN_PROGRESS`) { - return; - } - - if (activity.type === `spinner`) { - spinners.push(activity); - } - - if (activity.type === `progress` && activity.startTime) { - progressBars.push(activity); - } - }); - } - - return /*#__PURE__*/_react.default.createElement(_ink.Box, { - flexDirection: "column" - }, /*#__PURE__*/_react.default.createElement(_ink.Box, { - flexDirection: "column" - }, /*#__PURE__*/_react.default.createElement(_ink.Static, null, this.memoizedReactElementsForMessages), spinners.map(activity => /*#__PURE__*/_react.default.createElement(_spinner.Spinner, (0, _extends2.default)({ - key: activity.id - }, activity))), progressBars.map(activity => /*#__PURE__*/_react.default.createElement(_progressBar.ProgressBar, { - key: activity.id, - message: activity.text, - total: activity.total || 0, - current: activity.current || 0, - startTime: activity.startTime || [0, 0] - }))), showStatusBar && /*#__PURE__*/_react.default.createElement(_develop.default, null)); - } - -} - -var _default = CLI; -exports.default = _default; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/develop.d.ts b/packages/gatsby-reporter/lib/loggers/ink/components/develop.d.ts deleted file mode 100644 index 17a178402773b..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/develop.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import React from "react"; -declare const ConnectedDevelop: React.FC; -export default ConnectedDevelop; diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/develop.js b/packages/gatsby-reporter/lib/loggers/ink/components/develop.js deleted file mode 100644 index cc6f288cc9765..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/develop.js +++ /dev/null @@ -1,92 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); - -exports.__esModule = true; -exports.default = void 0; - -var _react = _interopRequireWildcard(require("react")); - -var _ink = require("ink"); - -var _context = _interopRequireDefault(require("../context")); - -var _constants = require("../../../constants"); - -var _utils = require("./utils"); - -const getLabel = level => { - switch (level) { - case _constants.ActivityStatuses.InProgress: - return (0, _utils.createLabel)(`In Progress`, `white`); - - case _constants.ActivityStatuses.Interrupted: - return (0, _utils.createLabel)(`Interrupted`, `gray`); - - case _constants.ActivityStatuses.Failed: - return (0, _utils.createLabel)(`Failed`, `red`); - - case _constants.ActivityStatuses.Success: - return (0, _utils.createLabel)(`Success`, `green`); - - default: - return (0, _utils.createLabel)(level, `white`); - } -}; // Track the width and height of the terminal. Responsive app design baby! - - -const useTerminalResize = () => { - const { - stdout - } = (0, _react.useContext)(_ink.StdoutContext); - const [sizes, setSizes] = (0, _react.useState)([stdout.columns, stdout.rows]); - (0, _react.useEffect)(() => { - const resizeListener = () => { - setSizes([stdout.columns, stdout.rows]); - }; - - stdout.on(`resize`, resizeListener); - return () => { - stdout.off(`resize`, resizeListener); - }; - }, [stdout]); - return sizes; -}; - -const Develop = ({ - pagesCount, - appName, - status -}) => { - const [width] = useTerminalResize(); - const StatusLabel = getLabel(status); - return /*#__PURE__*/_react.default.createElement(_ink.Box, { - flexDirection: "column", - marginTop: 2 - }, /*#__PURE__*/_react.default.createElement(_ink.Box, { - textWrap: `truncate` - }, `—`.repeat(width)), /*#__PURE__*/_react.default.createElement(_ink.Box, { - height: 1, - flexDirection: "row" - }, /*#__PURE__*/_react.default.createElement(StatusLabel, null), /*#__PURE__*/_react.default.createElement(_ink.Box, { - flexGrow: 1 - }), /*#__PURE__*/_react.default.createElement(_ink.Color, null, appName), /*#__PURE__*/_react.default.createElement(_ink.Box, { - flexGrow: 1 - }), /*#__PURE__*/_react.default.createElement(_ink.Color, null, pagesCount, " pages"))); -}; - -const ConnectedDevelop = () => { - var _state$pages, _state$program, _state$logs; - - const state = (0, _react.useContext)(_context.default); - return /*#__PURE__*/_react.default.createElement(Develop, { - pagesCount: ((_state$pages = state.pages) === null || _state$pages === void 0 ? void 0 : _state$pages.size) || 0, - appName: ((_state$program = state.program) === null || _state$program === void 0 ? void 0 : _state$program.sitePackageJson.name) || ``, - status: ((_state$logs = state.logs) === null || _state$logs === void 0 ? void 0 : _state$logs.status) || `` - }); -}; - -var _default = ConnectedDevelop; -exports.default = _default; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/error.d.ts b/packages/gatsby-reporter/lib/loggers/ink/components/error.d.ts deleted file mode 100644 index 0c940e8f388ba..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/error.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { FunctionComponent } from "react"; -import { IStructuredError } from "../../../structured-errors/types"; -export interface IErrorProps { - details: IStructuredError; -} -export declare const Error: FunctionComponent; diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/error.js b/packages/gatsby-reporter/lib/loggers/ink/components/error.js deleted file mode 100644 index 814c3f88b95c8..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/error.js +++ /dev/null @@ -1,76 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.Error = void 0; - -var _react = _interopRequireDefault(require("react")); - -var _path = _interopRequireDefault(require("path")); - -var _ink = require("ink"); - -const File = ({ - filePath, - location -}) => { - const lineNumber = location === null || location === void 0 ? void 0 : location.start.line; - let locString = ``; - - if (typeof lineNumber !== `undefined`) { - locString += `:${lineNumber}`; - const columnNumber = location === null || location === void 0 ? void 0 : location.start.column; - - if (typeof columnNumber !== `undefined`) { - locString += `:${columnNumber}`; - } - } - - return /*#__PURE__*/_react.default.createElement(_ink.Color, { - blue: true - }, _path.default.relative(process.cwd(), filePath), locString); -}; - -const DocsLink = ({ - docsUrl -}) => { - // TODO: when there's no specific docsUrl, add helpful message describing how - // to submit an issue - if (docsUrl === `https://gatsby.dev/issue-how-to`) return null; - return /*#__PURE__*/_react.default.createElement(_ink.Box, { - marginTop: 1 - }, "See our docs page for more info on this error: ", docsUrl); -}; - -const Error = /*#__PURE__*/_react.default.memo(({ - details -}) => -/*#__PURE__*/ -// const stackLength = get(details, `stack.length`, 0 -_react.default.createElement(_ink.Box, { - marginY: 1, - flexDirection: "column" -}, /*#__PURE__*/_react.default.createElement(_ink.Box, { - flexDirection: "column" -}, /*#__PURE__*/_react.default.createElement(_ink.Box, { - flexDirection: "column" -}, /*#__PURE__*/_react.default.createElement(_ink.Box, null, /*#__PURE__*/_react.default.createElement(_ink.Box, { - marginRight: 1 -}, /*#__PURE__*/_react.default.createElement(_ink.Color, { - black: true, - bgRed: true -}, ` ${details.level} `, details.code ? `#${details.code} ` : ``), /*#__PURE__*/_react.default.createElement(_ink.Color, { - red: true -}, details.type ? ` ` + details.type : ``))), /*#__PURE__*/_react.default.createElement(_ink.Box, { - marginTop: 1 -}, details.text), details.filePath && /*#__PURE__*/_react.default.createElement(_ink.Box, { - marginTop: 1 -}, "File:", ` `, /*#__PURE__*/_react.default.createElement(File, { - filePath: details.filePath, - location: details.location -}))), /*#__PURE__*/_react.default.createElement(DocsLink, { - docsUrl: details.docsUrl -})))); - -exports.Error = Error; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/messages.d.ts b/packages/gatsby-reporter/lib/loggers/ink/components/messages.d.ts deleted file mode 100644 index 339e132ef4ba7..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/messages.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import React from "react"; -import { ActivityLogLevels, LogLevels } from "../../../constants"; -export interface IMessageProps { - level: ActivityLogLevels | LogLevels; - text: string; - duration?: number; - statusText?: string; -} -export declare const Message: React.NamedExoticComponent; diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/messages.js b/packages/gatsby-reporter/lib/loggers/ink/components/messages.js deleted file mode 100644 index 1078ae67ee386..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/messages.js +++ /dev/null @@ -1,69 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.Message = void 0; - -var _react = _interopRequireDefault(require("react")); - -var _ink = require("ink"); - -var _utils = require("./utils"); - -var _constants = require("../../../constants"); - -const getLabel = level => { - switch (level) { - case _constants.ActivityLogLevels.Success: - case _constants.LogLevels.Success: - return (0, _utils.createLabel)(`success`, `green`); - - case _constants.LogLevels.Warning: - return (0, _utils.createLabel)(`warn`, `yellow`); - - case _constants.LogLevels.Debug: - return (0, _utils.createLabel)(`verbose`, `gray`); - - case _constants.LogLevels.Info: - return (0, _utils.createLabel)(`info`, `blue`); - - case _constants.ActivityLogLevels.Failed: - return (0, _utils.createLabel)(`failed`, `red`); - - case _constants.ActivityLogLevels.Interrupted: - return (0, _utils.createLabel)(`not finished`, `gray`); - - default: - return (0, _utils.createLabel)(level, `blue`); - } -}; - -const Message = /*#__PURE__*/_react.default.memo(({ - level, - text, - duration, - statusText -}) => { - let message = text; - - if (duration) { - message += ` - ${duration.toFixed(3)}s`; - } - - if (statusText) { - message += ` - ${statusText}`; - } - - if (!level || level === `LOG`) { - return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, message); - } - - const TextLabel = getLabel(level); - return /*#__PURE__*/_react.default.createElement(_ink.Box, { - textWrap: "wrap", - flexDirection: "row" - }, /*#__PURE__*/_react.default.createElement(TextLabel, null), ` `, message); -}); - -exports.Message = Message; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/progress-bar.d.ts b/packages/gatsby-reporter/lib/loggers/ink/components/progress-bar.d.ts deleted file mode 100644 index 2d81c021e0dfb..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/progress-bar.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/// -export interface IProgressbarProps { - message: string; - current: number; - total: number; - startTime: [number, number]; -} -export declare function ProgressBar({ message, current, total, startTime, }: IProgressbarProps): JSX.Element; diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/progress-bar.js b/packages/gatsby-reporter/lib/loggers/ink/components/progress-bar.js deleted file mode 100644 index f23667a95cbdd..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/progress-bar.js +++ /dev/null @@ -1,51 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.ProgressBar = ProgressBar; - -var _react = _interopRequireDefault(require("react")); - -var _ink = require("ink"); - -var _convertHrtime = _interopRequireDefault(require("convert-hrtime")); - -function calcElapsedTime(startTime) { - const elapsed = process.hrtime(startTime); - return (0, _convertHrtime.default)(elapsed)[`seconds`].toFixed(3); -} - -const maxWidth = 30; -const minWidth = 10; - -const getLength = prop => String(prop).length; - -function ProgressBar({ - message, - current, - total, - startTime -}) { - const percentage = total ? Math.round(current / total * 100) : 0; - const terminalWidth = process.stdout.columns || 80; - const availableWidth = terminalWidth - getLength(message) - getLength(current) - getLength(total) - getLength(percentage) - 11; // margins + extra characters - - const progressBarWidth = Math.max(minWidth, Math.min(maxWidth, availableWidth)); - return /*#__PURE__*/_react.default.createElement(_ink.Box, { - flexDirection: "row" - }, /*#__PURE__*/_react.default.createElement(_ink.Box, { - marginRight: 3, - width: progressBarWidth - }, "[", /*#__PURE__*/_react.default.createElement(_ink.Box, { - width: progressBarWidth - 2 - }, `=`.repeat((progressBarWidth - 2) * percentage / 100)), "]"), /*#__PURE__*/_react.default.createElement(_ink.Box, { - marginRight: 1 - }, calcElapsedTime(startTime), " s"), /*#__PURE__*/_react.default.createElement(_ink.Box, { - marginRight: 1 - }, current, "/", total), /*#__PURE__*/_react.default.createElement(_ink.Box, { - marginRight: 1 - }, `` + percentage, "%"), /*#__PURE__*/_react.default.createElement(_ink.Box, { - textWrap: "truncate" - }, message)); -} \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/spinner.d.ts b/packages/gatsby-reporter/lib/loggers/ink/components/spinner.d.ts deleted file mode 100644 index 0fb6c7b111404..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/spinner.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// -interface ISpinnerProps { - text: string; - statusText?: string; -} -export declare function Spinner({ text, statusText }: ISpinnerProps): JSX.Element; -export {}; diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/spinner.js b/packages/gatsby-reporter/lib/loggers/ink/components/spinner.js deleted file mode 100644 index 0d9ecf7f11822..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/spinner.js +++ /dev/null @@ -1,27 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.Spinner = Spinner; - -var _react = _interopRequireDefault(require("react")); - -var _ink = require("ink"); - -var _inkSpinner = _interopRequireDefault(require("ink-spinner")); - -function Spinner({ - text, - statusText -}) { - let label = text; - - if (statusText) { - label += ` — ${statusText}`; - } - - return /*#__PURE__*/_react.default.createElement(_ink.Box, null, /*#__PURE__*/_react.default.createElement(_inkSpinner.default, { - type: "dots" - }), " ", label); -} \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/utils.d.ts b/packages/gatsby-reporter/lib/loggers/ink/components/utils.d.ts deleted file mode 100644 index 59a5e9fca02c5..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/utils.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { FunctionComponent } from "react"; -import { ColorProps } from "ink"; -export declare const ColorSwitcher: FunctionComponent; -export declare const createLabel: (text: string, color: string) => FunctionComponent; diff --git a/packages/gatsby-reporter/lib/loggers/ink/components/utils.js b/packages/gatsby-reporter/lib/loggers/ink/components/utils.js deleted file mode 100644 index 92128a7f7ce13..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/components/utils.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.createLabel = exports.ColorSwitcher = void 0; - -var _react = _interopRequireDefault(require("react")); - -var _ink = require("ink"); - -const ColorSwitcher = ({ - children, - ...props -}) => /*#__PURE__*/_react.default.createElement(_ink.Color, props, children); - -exports.ColorSwitcher = ColorSwitcher; - -const createLabel = (text, color) => (...props) => /*#__PURE__*/_react.default.createElement(ColorSwitcher, { - [color]: true, - ...props -}, text); - -exports.createLabel = createLabel; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ink/context.d.ts b/packages/gatsby-reporter/lib/loggers/ink/context.d.ts deleted file mode 100644 index 86b9bef4c63a1..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/context.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import React from "react"; -import { IGatsbyState } from "gatsby/src/redux/types"; -declare const StoreStateContext: React.Context; -export declare const StoreStateProvider: React.FC; -export default StoreStateContext; diff --git a/packages/gatsby-reporter/lib/loggers/ink/context.js b/packages/gatsby-reporter/lib/loggers/ink/context.js deleted file mode 100644 index 0a643a08d86a7..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/context.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; - -var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); - -exports.__esModule = true; -exports.default = exports.StoreStateProvider = void 0; - -var _react = _interopRequireWildcard(require("react")); - -var _redux = require("../../redux"); - -// These weird castings we are doing in this file is because the way gatsby-cli works is that it starts with it's own store -// but then quickly swaps it out with the store from the installed gatsby. This would benefit from a refactor later on -// to not use it's own store temporarily. -// By the time this is actually running, it will become an `IGatsbyState` -const StoreStateContext = (0, _react.createContext)((0, _redux.getStore)().getState()); - -const StoreStateProvider = ({ - children -}) => { - const [state, setState] = (0, _react.useState)((0, _redux.getStore)().getState()); - (0, _react.useEffect)(() => (0, _redux.onLogAction)(() => { - setState((0, _redux.getStore)().getState()); - }), []); - return /*#__PURE__*/_react.default.createElement(StoreStateContext.Provider, { - value: state - }, children); -}; - -exports.StoreStateProvider = StoreStateProvider; -var _default = StoreStateContext; -exports.default = _default; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ink/index.d.ts b/packages/gatsby-reporter/lib/loggers/ink/index.d.ts deleted file mode 100644 index 0e5254266a499..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function initializeINKLogger(): void; diff --git a/packages/gatsby-reporter/lib/loggers/ink/index.js b/packages/gatsby-reporter/lib/loggers/ink/index.js deleted file mode 100644 index 928f500658483..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ink/index.js +++ /dev/null @@ -1,31 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); - -exports.__esModule = true; -exports.initializeINKLogger = initializeINKLogger; - -var _react = _interopRequireWildcard(require("react")); - -var _ink = require("ink"); - -var _context = _interopRequireWildcard(require("./context")); - -var _cli = _interopRequireDefault(require("./cli")); - -const ConnectedCLI = () => { - var _state$program, _state$program$_, _state$program2; - - const state = (0, _react.useContext)(_context.default); - const showStatusBar = ((_state$program = state.program) === null || _state$program === void 0 ? void 0 : (_state$program$_ = _state$program._) === null || _state$program$_ === void 0 ? void 0 : _state$program$_[0]) === `develop` && ((_state$program2 = state.program) === null || _state$program2 === void 0 ? void 0 : _state$program2.status) === `BOOTSTRAP_FINISHED`; - return /*#__PURE__*/_react.default.createElement(_cli.default, { - showStatusBar: Boolean(showStatusBar), - logs: state.logs - }); -}; - -function initializeINKLogger() { - (0, _ink.render)( /*#__PURE__*/_react.default.createElement(_context.StoreStateProvider, null, /*#__PURE__*/_react.default.createElement(ConnectedCLI, null))); -} \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/ipc/index.d.ts b/packages/gatsby-reporter/lib/loggers/ipc/index.d.ts deleted file mode 100644 index 6662d62898407..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ipc/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const initializeIPCLogger: () => void; diff --git a/packages/gatsby-reporter/lib/loggers/ipc/index.js b/packages/gatsby-reporter/lib/loggers/ipc/index.js deleted file mode 100644 index 1a1e0013d446d..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/ipc/index.js +++ /dev/null @@ -1,65 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.initializeIPCLogger = void 0; - -var _index = require("../../redux/index"); - -var _constants = require("../../constants"); - -var _stripAnsi = _interopRequireDefault(require("strip-ansi")); - -var _lodash = require("lodash"); - -const isStringPayload = action => typeof action.payload === `string`; -/** - * Payload can either be a String or an Object - * See more at integration-tests/structured-logging/__tests__/to-do.js - */ - - -const sanitizeAction = action => { - const copiedAction = (0, _lodash.cloneDeep)(action); - - if (isStringPayload(copiedAction)) { - return copiedAction; - } - - if (`text` in copiedAction.payload && copiedAction.payload.text) { - copiedAction.payload.text = (0, _stripAnsi.default)(copiedAction.payload.text); - } - - if (`statusText` in copiedAction.payload && copiedAction.payload.statusText) { - copiedAction.payload.statusText = (0, _stripAnsi.default)(copiedAction.payload.statusText); - } - - return copiedAction; -}; - -const initializeIPCLogger = () => { - (0, _index.onLogAction)(action => { - if (!process.send) return; - const sanitizedAction = sanitizeAction(action); // we mutate sanitizedAction but this is already deep copy of action so we should be good - - if (sanitizedAction.type === _constants.Actions.Log) { - // Don't emit Debug over IPC - if ([_constants.LogLevels.Debug].includes(sanitizedAction.payload.level)) { - return; - } // Override Success and Log types to Info over IPC - - - if ([_constants.LogLevels.Success, _constants.LogLevels.Log].includes(sanitizedAction.payload.level)) { - sanitizedAction.payload.level = _constants.LogLevels.Info; - } - } - - process.send({ - type: _constants.Actions.LogAction, - action: sanitizedAction - }); - }); -}; - -exports.initializeIPCLogger = initializeIPCLogger; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/json/index.d.ts b/packages/gatsby-reporter/lib/loggers/json/index.d.ts deleted file mode 100644 index 70a1ae461e46d..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/json/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function initializeJSONLogger(): void; diff --git a/packages/gatsby-reporter/lib/loggers/json/index.js b/packages/gatsby-reporter/lib/loggers/json/index.js deleted file mode 100644 index bcccbfed46f26..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/json/index.js +++ /dev/null @@ -1,39 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.initializeJSONLogger = initializeJSONLogger; - -var _index = require("../../redux/index"); - -var _stripAnsi = _interopRequireDefault(require("strip-ansi")); - -var _lodash = require("lodash"); - -const isStringPayload = action => typeof action.payload === `string`; - -const sanitizeAction = action => { - const copiedAction = (0, _lodash.cloneDeep)(action); - - if (isStringPayload(copiedAction)) { - return copiedAction; - } - - if (`text` in copiedAction.payload && copiedAction.payload.text) { - copiedAction.payload.text = (0, _stripAnsi.default)(copiedAction.payload.text); - } - - if (`statusText` in copiedAction.payload && copiedAction.payload.statusText) { - copiedAction.payload.statusText = (0, _stripAnsi.default)(copiedAction.payload.statusText); - } - - return copiedAction; -}; - -function initializeJSONLogger() { - (0, _index.onLogAction)(action => { - const sanitizedAction = sanitizeAction(action); - process.stdout.write(JSON.stringify(sanitizedAction) + `\n`); - }); -} \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/loggers/yurnalist/index.d.ts b/packages/gatsby-reporter/lib/loggers/yurnalist/index.d.ts deleted file mode 100644 index 43f087adbfffb..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/yurnalist/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function initializeYurnalistLogger(): void; diff --git a/packages/gatsby-reporter/lib/loggers/yurnalist/index.js b/packages/gatsby-reporter/lib/loggers/yurnalist/index.js deleted file mode 100644 index 99a6dd5aa9419..0000000000000 --- a/packages/gatsby-reporter/lib/loggers/yurnalist/index.js +++ /dev/null @@ -1,153 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.initializeYurnalistLogger = initializeYurnalistLogger; - -var _redux = require("../../redux"); - -var _constants = require("../../constants"); - -var _yurnalist = require("yurnalist"); - -var _progress = _interopRequireDefault(require("progress")); - -var _chalk = _interopRequireDefault(require("chalk")); - -function initializeYurnalistLogger() { - const activities = {}; - const yurnalist = (0, _yurnalist.createReporter)({ - emoji: true, - verbose: true - }); - const levelToYurnalist = { - [_constants.LogLevels.Log]: yurnalist.log.bind(yurnalist), - [_constants.LogLevels.Warning]: yurnalist.warn.bind(yurnalist), - [_constants.LogLevels.Error]: yurnalist.error.bind(yurnalist), - [_constants.LogLevels.Info]: yurnalist.info.bind(yurnalist), - [_constants.LogLevels.Success]: yurnalist.success.bind(yurnalist), - [_constants.ActivityLogLevels.Success]: yurnalist.success.bind(yurnalist), - [_constants.ActivityLogLevels.Failed]: text => { - yurnalist.log(`${_chalk.default.red(`failed`)} ${text}`); - }, - [_constants.ActivityLogLevels.Interrupted]: text => { - yurnalist.log(`${_chalk.default.gray(`not finished`)} ${text}`); - } - }; - (0, _redux.onLogAction)(action => { - switch (action.type) { - case _constants.Actions.Log: - { - const yurnalistMethod = levelToYurnalist[action.payload.level]; - - if (!yurnalistMethod) { - process.stdout.write(`NO "${action.payload.level}" method\n`); - } else { - let message = action.payload.text; - - if (action.payload.duration) { - message += ` - ${action.payload.duration.toFixed(3)}s`; - } - - if (action.payload.statusText) { - message += ` - ${action.payload.statusText}`; - } - - yurnalistMethod(message); - } - - break; - } - - case _constants.Actions.StartActivity: - { - if (action.payload.type === _constants.ActivityTypes.Spinner) { - const spinner = yurnalist.activity(); - spinner.tick(action.payload.text); - const activity = { - text: action.payload.text, - statusText: action.payload.statusText, - - update(payload) { - // TODO: I'm not convinced that this is ever called with a text property. - // From searching the codebase it appears that we do not ever assign a text - // property during the IUpdateActivity action. - if (payload.text) { - activity.text = payload.text; - } - - if (payload.statusText) { - activity.statusText = payload.statusText; - } - - let message = activity.text; - - if (activity.statusText) { - message += ` - ${activity.statusText}`; - } - - message += ` id:"${action.payload.id}"`; - spinner.tick(message); - }, - - end() { - spinner.end(); - } - - }; - activities[action.payload.id] = activity; - } else if (action.payload.type === _constants.ActivityTypes.Progress) { - const bar = new _progress.default(` [:bar] :current/:total :elapsed s :percent ${action.payload.text}`, { - total: action.payload.total, - curr: action.payload.current, - width: 30, - clear: true - }); - activities[action.payload.id] = { - text: undefined, - statusText: undefined, - - update(payload) { - if (payload.total) { - bar.total = payload.total; - } - - if (payload.current) { - bar.curr = payload.current; - } - - bar.tick(0); - }, - - end() {} - - }; - } - - break; - } - - case _constants.Actions.UpdateActivity: - { - const activity = activities[action.payload.id]; - - if (activity) { - activity.update(action.payload); - } - - break; - } - - case _constants.Actions.EndActivity: - { - const activity = activities[action.payload.id]; - - if (activity) { - activity.end(); - delete activities[action.payload.id]; - } - } - } - }); -} \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/patch-console.d.ts b/packages/gatsby-reporter/lib/patch-console.d.ts deleted file mode 100644 index bccc24dbf9de5..0000000000000 --- a/packages/gatsby-reporter/lib/patch-console.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { reporter as gatsbyReporter } from "./reporter"; -export declare function patchConsole(reporter: typeof gatsbyReporter): void; diff --git a/packages/gatsby-reporter/lib/patch-console.js b/packages/gatsby-reporter/lib/patch-console.js deleted file mode 100644 index 025e52efefc53..0000000000000 --- a/packages/gatsby-reporter/lib/patch-console.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.patchConsole = patchConsole; - -var _util = _interopRequireDefault(require("util")); - -/* - * This module is used to patch console through our reporter so we can track - * these logs - */ -function patchConsole(reporter) { - console.log = (...args) => { - const [format, ...rest] = args; - reporter.log(_util.default.format(format === undefined ? `` : format, ...rest)); - }; - - console.warn = (...args) => { - const [format, ...rest] = args; - reporter.warn(_util.default.format(format === undefined ? `` : format, ...rest)); - }; - - console.info = (...args) => { - const [format, ...rest] = args; - reporter.info(_util.default.format(format === undefined ? `` : format, ...rest)); - }; - - console.error = (format, ...args) => { - reporter.error(_util.default.format(format === undefined ? `` : format, ...args)); - }; -} \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/redux/actions.d.ts b/packages/gatsby-reporter/lib/redux/actions.d.ts deleted file mode 100644 index bddff0843607b..0000000000000 --- a/packages/gatsby-reporter/lib/redux/actions.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { Dispatch } from "redux"; -export declare const createLog: ({ level, text, statusText, duration, group, code, type, filePath, location, docsUrl, context, activity_current, activity_total, activity_type, activity_uuid, stack, }: { - level: string; - text?: string | undefined; - statusText?: string | undefined; - duration?: number | undefined; - group?: string | undefined; - code?: string | undefined; - type?: string | undefined; - filePath?: string | undefined; - location?: { - start: import("../structured-errors/types").ILocationPosition; - end?: import("../structured-errors/types").ILocationPosition | undefined; - } | undefined; - docsUrl?: string | undefined; - context?: string | undefined; - activity_current?: number | undefined; - activity_total?: number | undefined; - activity_type?: string | undefined; - activity_uuid?: string | undefined; - stack?: import("../structured-errors/types").IStructuredStackFrame[] | undefined; -}) => import("./types").ICreateLog; -export declare const createPendingActivity: ({ id, status, }: { - id: string; - status?: import("../constants").ActivityStatuses | undefined; -}) => (import("./types").IPendingActivity | ((dispatch: Dispatch) => void))[]; -export declare const setStatus: (status: "" | import("../constants").ActivityStatuses, force?: boolean) => (dispatch: Dispatch) => void; -export declare const startActivity: ({ id, text, type, status, current, total, }: { - id: string; - text: string; - type: import("../constants").ActivityTypes; - status?: import("../constants").ActivityStatuses | undefined; - current?: number | undefined; - total?: number | undefined; -}) => (import("./types").IStartActivity | ((dispatch: Dispatch) => void))[]; -export declare const endActivity: ({ id, status, }: { - id: string; - status: import("../constants").ActivityStatuses; -}) => (import("./types").ICreateLog | import("./types").IEndActivity | import("./types").ICancelActivity | ((dispatch: Dispatch) => void))[] | null; -export declare const updateActivity: ({ id, ...rest }: { - id: string; - statusText?: string | undefined; - total?: number | undefined; - current?: number | undefined; -}) => import("./types").IUpdateActivity | null; -export declare const setActivityErrored: ({ id, }: { - id: string; -}) => import("./types").IActivityErrored | null; -export declare const setActivityStatusText: ({ id, statusText, }: { - id: string; - statusText: string; -}) => import("./types").IUpdateActivity | null; -export declare const setActivityTotal: ({ id, total, }: { - id: string; - total: number; -}) => import("./types").IUpdateActivity | null; -export declare const activityTick: ({ id, increment, }: { - id: string; - increment: number; -}) => import("./types").IUpdateActivity | null; diff --git a/packages/gatsby-reporter/lib/redux/actions.js b/packages/gatsby-reporter/lib/redux/actions.js deleted file mode 100644 index 62a6302b724e5..0000000000000 --- a/packages/gatsby-reporter/lib/redux/actions.js +++ /dev/null @@ -1,44 +0,0 @@ -"use strict"; - -exports.__esModule = true; -exports.activityTick = exports.setActivityTotal = exports.setActivityStatusText = exports.setActivityErrored = exports.updateActivity = exports.endActivity = exports.startActivity = exports.setStatus = exports.createPendingActivity = exports.createLog = void 0; - -var _redux = require("redux"); - -var _ = require("./"); - -var _internalActions = require("./internal-actions"); - -const actions = { - createLog: _internalActions.createLog, - createPendingActivity: _internalActions.createPendingActivity, - setStatus: _internalActions.setStatus, - startActivity: _internalActions.startActivity, - endActivity: _internalActions.endActivity, - updateActivity: _internalActions.updateActivity, - setActivityErrored: _internalActions.setActivityErrored, - setActivityStatusText: _internalActions.setActivityStatusText, - setActivityTotal: _internalActions.setActivityTotal, - activityTick: _internalActions.activityTick -}; -const boundActions = (0, _redux.bindActionCreators)(actions, _.dispatch); -const createLog = boundActions.createLog; -exports.createLog = createLog; -const createPendingActivity = boundActions.createPendingActivity; -exports.createPendingActivity = createPendingActivity; -const setStatus = boundActions.setStatus; -exports.setStatus = setStatus; -const startActivity = boundActions.startActivity; -exports.startActivity = startActivity; -const endActivity = boundActions.endActivity; -exports.endActivity = endActivity; -const updateActivity = boundActions.updateActivity; -exports.updateActivity = updateActivity; -const setActivityErrored = boundActions.setActivityErrored; -exports.setActivityErrored = setActivityErrored; -const setActivityStatusText = boundActions.setActivityStatusText; -exports.setActivityStatusText = setActivityStatusText; -const setActivityTotal = boundActions.setActivityTotal; -exports.setActivityTotal = setActivityTotal; -const activityTick = boundActions.activityTick; -exports.activityTick = activityTick; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/redux/index.d.ts b/packages/gatsby-reporter/lib/redux/index.d.ts deleted file mode 100644 index 4f7e0ecbf8a58..0000000000000 --- a/packages/gatsby-reporter/lib/redux/index.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ActionsUnion } from "./types"; -declare let store: import("redux").Store, ActionsUnion>; -declare type GatsbyCLIStore = typeof store; -declare type StoreListener = (store: GatsbyCLIStore) => void; -declare type ActionLogListener = (action: ActionsUnion) => any; -declare type Thunk = (...args: any[]) => ActionsUnion; -export declare const getStore: () => typeof store; -export declare const dispatch: (action: ActionsUnion | Thunk) => void; -export declare const onStoreSwap: (fn: StoreListener) => void; -export declare const onLogAction: (fn: ActionLogListener) => (() => void); -export declare const setStore: (s: GatsbyCLIStore) => void; -export {}; diff --git a/packages/gatsby-reporter/lib/redux/index.js b/packages/gatsby-reporter/lib/redux/index.js deleted file mode 100644 index 2fca2549d4a8f..0000000000000 --- a/packages/gatsby-reporter/lib/redux/index.js +++ /dev/null @@ -1,84 +0,0 @@ -"use strict"; - -exports.__esModule = true; -exports.setStore = exports.onLogAction = exports.onStoreSwap = exports.dispatch = exports.getStore = void 0; - -var _redux = require("redux"); - -var _reducer = require("./reducer"); - -var _utils = require("./utils"); - -var _constants = require("../constants"); - -let store = (0, _redux.createStore)((0, _redux.combineReducers)({ - logs: _reducer.reducer -}), {}); -const storeSwapListeners = []; -const onLogActionListeners = new Set(); - -const getStore = () => store; - -exports.getStore = getStore; - -const dispatch = action => { - if (!action) { - return; - } - - if (Array.isArray(action)) { - action.forEach(item => dispatch(item)); - return; - } else if (typeof action === `function`) { - action(dispatch); - return; - } - - action = { ...action, - // eslint-disable-next-line @typescript-eslint/ban-ts-ignore - // @ts-ignore this is a typescript no-no.. - // And i'm pretty sure this timestamp isn't used anywhere. - // but for now, the structured logs integration tests expect it - // so it's easier to leave it and then explore as a follow up - timestamp: new Date().toJSON() - }; - store.dispatch(action); - - if ((0, _utils.isInternalAction)(action)) { - // consumers (ipc, yurnalist, json logger) shouldn't have to - // deal with actions needed just for internal tracking of status - return; - } - - for (const fn of onLogActionListeners) { - fn(action); - } -}; - -exports.dispatch = dispatch; - -const onStoreSwap = fn => { - storeSwapListeners.push(fn); -}; - -exports.onStoreSwap = onStoreSwap; - -const onLogAction = fn => { - onLogActionListeners.add(fn); - return () => { - onLogActionListeners.delete(fn); - }; -}; - -exports.onLogAction = onLogAction; - -const setStore = s => { - s.dispatch({ - type: _constants.Actions.SetLogs, - payload: store.getState().logs - }); - store = s; - storeSwapListeners.forEach(fn => fn(store)); -}; - -exports.setStore = setStore; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/redux/internal-actions.d.ts b/packages/gatsby-reporter/lib/redux/internal-actions.d.ts deleted file mode 100644 index 5a2189297de56..0000000000000 --- a/packages/gatsby-reporter/lib/redux/internal-actions.d.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Dispatch } from "redux"; -import { ActivityStatuses, ActivityTypes } from "../constants"; -import { IPendingActivity, ICreateLog, ISetStatus, IStartActivity, ICancelActivity, IEndActivity, IUpdateActivity, IActivityErrored, IGatsbyCLIState, ISetLogs } from "./types"; -import { IStructuredError } from "../structured-errors/types"; -export declare const setStatus: (status: ActivityStatuses | "", force?: boolean) => (dispatch: Dispatch) => void; -export declare const createLog: ({ level, text, statusText, duration, group, code, type, filePath, location, docsUrl, context, activity_current, activity_total, activity_type, activity_uuid, stack, }: { - level: string; - text?: string | undefined; - statusText?: string | undefined; - duration?: number | undefined; - group?: string | undefined; - code?: string | undefined; - type?: string | undefined; - filePath?: string | undefined; - location?: IStructuredError["location"]; - docsUrl?: string | undefined; - context?: string | undefined; - activity_current?: number | undefined; - activity_total?: number | undefined; - activity_type?: string | undefined; - activity_uuid?: string | undefined; - stack?: import("../structured-errors/types").IStructuredStackFrame[] | undefined; -}) => ICreateLog; -declare type ActionsToEmit = Array>; -export declare const createPendingActivity: ({ id, status, }: { - id: string; - status?: ActivityStatuses | undefined; -}) => ActionsToEmit; -declare type QueuedStartActivityActions = Array>; -export declare const startActivity: ({ id, text, type, status, current, total, }: { - id: string; - text: string; - type: ActivityTypes; - status?: ActivityStatuses | undefined; - current?: number | undefined; - total?: number | undefined; -}) => QueuedStartActivityActions; -declare type QueuedEndActivity = Array>; -export declare const endActivity: ({ id, status, }: { - id: string; - status: ActivityStatuses; -}) => QueuedEndActivity | null; -export declare const updateActivity: ({ id, ...rest }: { - id: string; - statusText?: string | undefined; - total?: number | undefined; - current?: number | undefined; -}) => IUpdateActivity | null; -export declare const setActivityErrored: ({ id, }: { - id: string; -}) => IActivityErrored | null; -export declare const setActivityStatusText: ({ id, statusText, }: { - id: string; - statusText: string; -}) => IUpdateActivity | null; -export declare const setActivityTotal: ({ id, total, }: { - id: string; - total: number; -}) => IUpdateActivity | null; -export declare const activityTick: ({ id, increment, }: { - id: string; - increment: number; -}) => IUpdateActivity | null; -export declare const setLogs: (logs: IGatsbyCLIState) => ISetLogs; -export {}; diff --git a/packages/gatsby-reporter/lib/redux/internal-actions.js b/packages/gatsby-reporter/lib/redux/internal-actions.js deleted file mode 100644 index 5a98669f341e0..0000000000000 --- a/packages/gatsby-reporter/lib/redux/internal-actions.js +++ /dev/null @@ -1,317 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.setLogs = exports.activityTick = exports.setActivityTotal = exports.setActivityStatusText = exports.setActivityErrored = exports.updateActivity = exports.endActivity = exports.startActivity = exports.createPendingActivity = exports.createLog = exports.setStatus = void 0; - -var _v = _interopRequireDefault(require("uuid/v4")); - -var _gatsbyTelemetry = require("gatsby-telemetry"); - -var _signalExit = _interopRequireDefault(require("signal-exit")); - -var _ = require("./"); - -var _constants = require("../constants"); - -var _utils = require("./utils"); - -/* eslint-disable @typescript-eslint/camelcase */ -const ActivityStatusToLogLevel = { - [_constants.ActivityStatuses.Interrupted]: _constants.ActivityLogLevels.Interrupted, - [_constants.ActivityStatuses.Failed]: _constants.ActivityLogLevels.Failed, - [_constants.ActivityStatuses.Success]: _constants.ActivityLogLevels.Success -}; -let weShouldExit = false; -(0, _signalExit.default)(() => { - weShouldExit = true; -}); -let cancelDelayedSetStatus; // TODO: THIS IS NOT WORKING ATM - -const setStatus = (status, force = false) => dispatch => { - const currentStatus = (0, _.getStore)().getState().logs.status; - - if (cancelDelayedSetStatus) { - cancelDelayedSetStatus(); - cancelDelayedSetStatus = null; - } - - if (status !== currentStatus) { - if (status === `IN_PROGRESS` || force || weShouldExit) { - dispatch({ - type: _constants.Actions.SetStatus, - payload: status - }); - } else { - cancelDelayedSetStatus = (0, _utils.delayedCall)(() => { - setStatus(status, true)(dispatch); - }, 1000); - } - } -}; - -exports.setStatus = setStatus; - -const createLog = ({ - level, - text, - statusText, - duration, - group, - code, - type, - filePath, - location, - docsUrl, - context, - activity_current, - activity_total, - activity_type, - activity_uuid, - stack -}) => { - return { - type: _constants.Actions.Log, - payload: { - level, - text, - statusText, - duration, - group, - code, - type, - filePath, - location, - docsUrl, - context, - activity_current, - activity_total, - activity_type, - activity_uuid, - timestamp: new Date().toJSON(), - stack - } - }; -}; - -exports.createLog = createLog; - -const createPendingActivity = ({ - id, - status = _constants.ActivityStatuses.NotStarted -}) => { - const actionsToEmit = []; - const logsState = (0, _.getStore)().getState().logs; - const globalStatus = (0, _utils.getGlobalStatus)(id, status); - - if (globalStatus !== logsState.status) { - actionsToEmit.push(setStatus(globalStatus)); - } - - actionsToEmit.push({ - type: _constants.Actions.PendingActivity, - payload: { - id, - type: _constants.ActivityTypes.Pending, - status - } - }); - return actionsToEmit; -}; - -exports.createPendingActivity = createPendingActivity; - -const startActivity = ({ - id, - text, - type, - status = _constants.ActivityStatuses.InProgress, - current, - total -}) => { - const actionsToEmit = []; - const logsState = (0, _.getStore)().getState().logs; - const globalStatus = (0, _utils.getGlobalStatus)(id, status); - - if (globalStatus !== logsState.status) { - actionsToEmit.push(setStatus(globalStatus)); - } - - actionsToEmit.push({ - type: _constants.Actions.StartActivity, - payload: { - id, - uuid: (0, _v.default)(), - text, - type, - status, - startTime: process.hrtime(), - statusText: ``, - current, - total - } - }); - return actionsToEmit; -}; - -exports.startActivity = startActivity; - -const endActivity = ({ - id, - status -}) => { - const activity = (0, _utils.getActivity)(id); - - if (!activity) { - return null; - } - - const actionsToEmit = []; - const durationMS = (0, _utils.getElapsedTimeMS)(activity); - const durationS = durationMS / 1000; - - if (activity.type === _constants.ActivityTypes.Pending) { - actionsToEmit.push({ - type: _constants.Actions.CancelActivity, - payload: { - id, - status: _constants.ActivityStatuses.Cancelled, - type: activity.type, - duration: durationS - } - }); - } else if (activity.status === _constants.ActivityStatuses.InProgress) { - (0, _gatsbyTelemetry.trackCli)(`ACTIVITY_DURATION`, { - name: activity.text, - duration: Math.round(durationMS) - }); - - if (activity.errored) { - status = _constants.ActivityStatuses.Failed; - } - - actionsToEmit.push({ - type: _constants.Actions.EndActivity, - payload: { - uuid: activity.uuid, - id, - status, - duration: durationS, - type: activity.type - } - }); - - if (activity.type !== _constants.ActivityTypes.Hidden) { - actionsToEmit.push(createLog({ - text: activity.text, - level: ActivityStatusToLogLevel[status], - duration: durationS, - statusText: activity.statusText || (status === _constants.ActivityStatuses.Success && activity.type === _constants.ActivityTypes.Progress ? `${activity.current}/${activity.total} ${((activity.total || 0) / durationS).toFixed(2)}/s` : undefined), - activity_uuid: activity.uuid, - activity_current: activity.current, - activity_total: activity.total, - activity_type: activity.type - })); - } - } - - const logsState = (0, _.getStore)().getState().logs; - const globalStatus = (0, _utils.getGlobalStatus)(id, status); - - if (globalStatus !== logsState.status) { - actionsToEmit.push(setStatus(globalStatus)); - } - - return actionsToEmit; -}; - -exports.endActivity = endActivity; - -const updateActivity = ({ - id = ``, - ...rest -}) => { - const activity = (0, _utils.getActivity)(id); - - if (!activity) { - return null; - } - - return { - type: _constants.Actions.UpdateActivity, - payload: { - uuid: activity.uuid, - id, - ...rest - } - }; -}; - -exports.updateActivity = updateActivity; - -const setActivityErrored = ({ - id -}) => { - const activity = (0, _utils.getActivity)(id); - - if (!activity) { - return null; - } - - return { - type: _constants.Actions.ActivityErrored, - payload: { - id - } - }; -}; - -exports.setActivityErrored = setActivityErrored; - -const setActivityStatusText = ({ - id, - statusText -}) => updateActivity({ - id, - statusText -}); - -exports.setActivityStatusText = setActivityStatusText; - -const setActivityTotal = ({ - id, - total -}) => updateActivity({ - id, - total -}); - -exports.setActivityTotal = setActivityTotal; - -const activityTick = ({ - id, - increment = 1 -}) => { - const activity = (0, _utils.getActivity)(id); - - if (!activity) { - return null; - } - - return updateActivity({ - id, - current: (activity.current || 0) + increment - }); -}; - -exports.activityTick = activityTick; - -const setLogs = logs => { - return { - type: _constants.Actions.SetLogs, - payload: logs - }; -}; - -exports.setLogs = setLogs; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/redux/reducer.d.ts b/packages/gatsby-reporter/lib/redux/reducer.d.ts deleted file mode 100644 index ed534e65aa57f..0000000000000 --- a/packages/gatsby-reporter/lib/redux/reducer.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { ActionsUnion, IGatsbyCLIState, ISetLogs } from "./types"; -export declare const reducer: (state: IGatsbyCLIState | undefined, action: ActionsUnion | ISetLogs) => IGatsbyCLIState; diff --git a/packages/gatsby-reporter/lib/redux/reducer.js b/packages/gatsby-reporter/lib/redux/reducer.js deleted file mode 100644 index 6ebd2ec5df830..0000000000000 --- a/packages/gatsby-reporter/lib/redux/reducer.js +++ /dev/null @@ -1,111 +0,0 @@ -"use strict"; - -exports.__esModule = true; -exports.reducer = void 0; - -var _constants = require("../constants"); - -const reducer = (state = { - messages: [], - activities: {}, - status: `` -}, action) => { - switch (action.type) { - case _constants.Actions.SetStatus: - { - return { ...state, - status: action.payload - }; - } - - case _constants.Actions.Log: - { - if (!action.payload.text) { - // set empty character to fix ink - action.payload.text = `\u2800`; - } - - return { ...state, - messages: [...state.messages, action.payload] - }; - } - - case _constants.Actions.StartActivity: - { - const { - id - } = action.payload; - return { ...state, - activities: { ...state.activities, - [id]: action.payload - } - }; - } - - case _constants.Actions.UpdateActivity: - case _constants.Actions.PendingActivity: - { - const { - id, - ...rest - } = action.payload; - const activity = state.activities[id]; - return { ...state, - activities: { ...state.activities, - [id]: { ...activity, - ...rest - } - } - }; - } - - case _constants.Actions.ActivityErrored: - { - const { - id - } = action.payload; - const activity = state.activities[id]; - return { ...state, - activities: { ...state.activities, - [id]: { ...activity, - errored: true - } - } - }; - } - - case _constants.Actions.EndActivity: - case _constants.Actions.CancelActivity: - { - const { - id, - status, - duration - } = action.payload; - const activity = state.activities[id]; - - if (!activity) { - return state; - } - - const activities = { ...state.activities - }; - activities[id] = { ...activity, - status, - duration - }; - return { ...state, - activities - }; - } - - case _constants.Actions.SetLogs: - { - return action.payload; - } - } - - return state; -}; - -exports.reducer = reducer; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/redux/types.d.ts b/packages/gatsby-reporter/lib/redux/types.d.ts deleted file mode 100644 index 8c09a78eeac8a..0000000000000 --- a/packages/gatsby-reporter/lib/redux/types.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { Actions, ActivityStatuses, ActivityTypes } from "../constants"; -import { IStructuredError } from "../structured-errors/types"; -export interface IGatsbyCLIState { - messages: ILog[]; - activities: { - [id: string]: IActivity; - }; - status: ActivityStatuses | ""; -} -export declare type ActionsUnion = ICreateLog | ISetStatus | IEndActivity | IPendingActivity | IStartActivity | ICancelActivity | IUpdateActivity | IActivityErrored | ISetLogs; -export interface IActivity { - startTime?: [number, number]; - id: string; - uuid: string; - text: string; - type: ActivityTypes; - status: ActivityStatuses; - statusText: string; - current?: number; - total?: number; - duration?: number; - errored?: boolean; -} -interface ILog { - level: string; - text: string | undefined; - statusText: string | undefined; - duration: number | undefined; - group: string | undefined; - code: string | undefined; - type: string | undefined; - filePath: string | undefined; - location: IStructuredError["location"] | undefined; - docsUrl: string | undefined; - context: string | undefined; - activity_current: number | undefined; - activity_total: number | undefined; - activity_type: string | undefined; - activity_uuid: string | undefined; - timestamp: string; - stack: IStructuredError["stack"] | undefined; -} -export interface ICreateLog { - type: Actions.Log; - payload: ILog; -} -export interface ISetStatus { - type: Actions.SetStatus; - payload: ActivityStatuses | ""; -} -export interface IPendingActivity { - type: Actions.PendingActivity; - payload: { - id: string; - type: ActivityTypes; - status: ActivityStatuses; - }; -} -export interface IStartActivity { - type: Actions.StartActivity; - payload: IActivity; -} -export interface ICancelActivity { - type: Actions.CancelActivity; - payload: { - id: string; - status: ActivityStatuses.Cancelled; - duration: number; - type: ActivityTypes; - }; -} -export interface IEndActivity { - type: Actions.EndActivity; - payload: { - uuid: string; - id: string; - status: ActivityStatuses; - duration: number; - type: ActivityTypes; - }; -} -export interface IUpdateActivity { - type: Actions.UpdateActivity; - payload: { - uuid: string; - id: string; - statusText?: string; - total?: number; - current?: number; - }; -} -export interface IActivityErrored { - type: Actions.ActivityErrored; - payload: { - id: string; - }; -} -export interface ISetLogs { - type: Actions.SetLogs; - payload: IGatsbyCLIState; -} -export {}; diff --git a/packages/gatsby-reporter/lib/redux/types.js b/packages/gatsby-reporter/lib/redux/types.js deleted file mode 100644 index 9a390c31f71bc..0000000000000 --- a/packages/gatsby-reporter/lib/redux/types.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/redux/utils.d.ts b/packages/gatsby-reporter/lib/redux/utils.d.ts deleted file mode 100644 index 4816dac5bbc14..0000000000000 --- a/packages/gatsby-reporter/lib/redux/utils.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ActivityStatuses } from "../constants"; -import { ActionsUnion, IActivity } from "./types"; -export declare const getGlobalStatus: (id: string, status: ActivityStatuses) => ActivityStatuses; -export declare const getActivity: (id: string) => IActivity | null; -/** - * @returns {Number} Milliseconds from activity start - */ -export declare const getElapsedTimeMS: (activity: IActivity) => number; -export declare const isInternalAction: (action: ActionsUnion) => boolean; -/** - * Like setTimeout, but also handle signalExit - */ -export declare const delayedCall: (fn: () => void, timeout: number) => (() => void); diff --git a/packages/gatsby-reporter/lib/redux/utils.js b/packages/gatsby-reporter/lib/redux/utils.js deleted file mode 100644 index 4b70032beee4f..0000000000000 --- a/packages/gatsby-reporter/lib/redux/utils.js +++ /dev/null @@ -1,93 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.delayedCall = exports.isInternalAction = exports.getElapsedTimeMS = exports.getActivity = exports.getGlobalStatus = void 0; - -var _index = require("./index"); - -var _convertHrtime = _interopRequireDefault(require("convert-hrtime")); - -var _constants = require("../constants"); - -var _signalExit = _interopRequireDefault(require("signal-exit")); - -const getGlobalStatus = (id, status) => { - const { - logs - } = (0, _index.getStore)().getState(); - const currentActivities = [id, ...Object.keys(logs.activities)]; - return currentActivities.reduce((generatedStatus, activityId) => { - const activityStatus = activityId === id ? status : logs.activities[activityId].status; - - if (activityStatus === _constants.ActivityStatuses.InProgress || activityStatus === _constants.ActivityStatuses.NotStarted) { - return _constants.ActivityStatuses.InProgress; - } else if (activityStatus === _constants.ActivityStatuses.Failed && generatedStatus !== _constants.ActivityStatuses.InProgress) { - return _constants.ActivityStatuses.Failed; - } else if (activityStatus === _constants.ActivityStatuses.Interrupted && generatedStatus !== _constants.ActivityStatuses.InProgress) { - return _constants.ActivityStatuses.Interrupted; - } - - return generatedStatus; - }, _constants.ActivityStatuses.Success); -}; - -exports.getGlobalStatus = getGlobalStatus; - -const getActivity = id => (0, _index.getStore)().getState().logs.activities[id]; -/** - * @returns {Number} Milliseconds from activity start - */ - - -exports.getActivity = getActivity; - -const getElapsedTimeMS = activity => { - const elapsed = process.hrtime(activity.startTime); - return (0, _convertHrtime.default)(elapsed).milliseconds; -}; - -exports.getElapsedTimeMS = getElapsedTimeMS; - -const isInternalAction = action => { - switch (action.type) { - case _constants.Actions.PendingActivity: - case _constants.Actions.CancelActivity: - case _constants.Actions.ActivityErrored: - return true; - - case _constants.Actions.StartActivity: - case _constants.Actions.EndActivity: - return action.payload.type === _constants.ActivityTypes.Hidden; - - default: - return false; - } -}; -/** - * Like setTimeout, but also handle signalExit - */ - - -exports.isInternalAction = isInternalAction; - -const delayedCall = (fn, timeout) => { - const fnWrap = () => { - fn(); // eslint-disable-next-line @typescript-eslint/no-use-before-define - - clear(); - }; - - const timeoutID = setTimeout(fnWrap, timeout); - const cancelSignalExit = (0, _signalExit.default)(fnWrap); - - const clear = () => { - clearTimeout(timeoutID); - cancelSignalExit(); - }; - - return clear; -}; - -exports.delayedCall = delayedCall; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/reporter-phantom.d.ts b/packages/gatsby-reporter/lib/reporter-phantom.d.ts deleted file mode 100644 index a98a61c4968f0..0000000000000 --- a/packages/gatsby-reporter/lib/reporter-phantom.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Span } from "opentracing"; -import { IPhantomReporter } from "./types"; -interface ICreatePhantomReporterArguments { - text: string; - id: string; - span: Span; -} -export declare const createPhantomReporter: ({ text, id, span, }: ICreatePhantomReporterArguments) => IPhantomReporter; -export {}; diff --git a/packages/gatsby-reporter/lib/reporter-phantom.js b/packages/gatsby-reporter/lib/reporter-phantom.js deleted file mode 100644 index 97da120b6e095..0000000000000 --- a/packages/gatsby-reporter/lib/reporter-phantom.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; - -var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); - -exports.__esModule = true; -exports.createPhantomReporter = void 0; - -var reporterActions = _interopRequireWildcard(require("./redux/actions")); - -var _constants = require("./constants"); - -const createPhantomReporter = ({ - text, - id, - span -}) => { - return { - start() { - reporterActions.startActivity({ - id, - text, - type: _constants.ActivityTypes.Hidden - }); - }, - - end() { - span.finish(); - reporterActions.endActivity({ - id, - status: _constants.ActivityStatuses.Success - }); - }, - - span - }; -}; - -exports.createPhantomReporter = createPhantomReporter; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/reporter-progress.d.ts b/packages/gatsby-reporter/lib/reporter-progress.d.ts deleted file mode 100644 index 73de921a5cb29..0000000000000 --- a/packages/gatsby-reporter/lib/reporter-progress.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Span } from "opentracing"; -import { reporter as gatsbyReporter } from "./reporter"; -import { IProgressReporter } from "./types"; -interface ICreateProgressReporterArguments { - id: string; - text: string; - start: number; - total: number; - span: Span; - reporter: typeof gatsbyReporter; -} -export declare const createProgressReporter: ({ id, text, start, total, span, reporter, }: ICreateProgressReporterArguments) => IProgressReporter; -export {}; diff --git a/packages/gatsby-reporter/lib/reporter-progress.js b/packages/gatsby-reporter/lib/reporter-progress.js deleted file mode 100644 index 27e74c734c2e4..0000000000000 --- a/packages/gatsby-reporter/lib/reporter-progress.js +++ /dev/null @@ -1,117 +0,0 @@ -"use strict"; - -var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); - -exports.__esModule = true; -exports.createProgressReporter = void 0; - -var reporterActions = _interopRequireWildcard(require("./redux/actions")); - -var _constants = require("./constants"); - -const createProgressReporter = ({ - id, - text, - start, - total, - span, - reporter -}) => { - let lastUpdateTime = 0; - let unflushedProgress = 0; - let unflushedTotal = 0; - const progressUpdateDelay = Math.round(1000 / 10); // 10 fps *shrug* - - const updateProgress = (forced = false) => { - const t = Date.now(); - if (!forced && t - lastUpdateTime <= progressUpdateDelay) return; - - if (unflushedTotal > 0) { - reporterActions.setActivityTotal({ - id, - total: unflushedTotal - }); - unflushedTotal = 0; - } - - if (unflushedProgress > 0) { - reporterActions.activityTick({ - id, - increment: unflushedProgress - }); - unflushedProgress = 0; - } - - lastUpdateTime = t; - }; - - return { - start() { - reporterActions.startActivity({ - id, - text, - type: _constants.ActivityTypes.Progress, - current: start, - total - }); - }, - - setStatus(statusText) { - reporterActions.setActivityStatusText({ - id, - statusText - }); - }, - - tick(increment = 1) { - unflushedProgress += increment; // Have to manually track this :/ - - updateProgress(); - }, - - panicOnBuild(errorMeta, error) { - span.finish(); - reporterActions.setActivityErrored({ - id - }); - return reporter.panicOnBuild(errorMeta, error); - }, - - panic(errorMeta, error) { - span.finish(); - reporterActions.endActivity({ - id, - status: _constants.ActivityStatuses.Failed - }); - return reporter.panic(errorMeta, error); - }, - - end() { - updateProgress(true); - span.finish(); - reporterActions.endActivity({ - id, - status: _constants.ActivityStatuses.Success - }); - }, - - // @deprecated - use end() - done() { - updateProgress(true); - span.finish(); - reporterActions.endActivity({ - id, - status: _constants.ActivityStatuses.Success - }); - }, - - set total(value) { - unflushedTotal = value; - updateProgress(); - }, - - span - }; -}; - -exports.createProgressReporter = createProgressReporter; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/reporter-timer.d.ts b/packages/gatsby-reporter/lib/reporter-timer.d.ts deleted file mode 100644 index 1aa89a6670ec6..0000000000000 --- a/packages/gatsby-reporter/lib/reporter-timer.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Span } from "opentracing"; -import { reporter as gatsbyReporter } from "./reporter"; -import { ITimerReporter } from "./types"; -interface ICreateTimerReporterArguments { - text: string; - id: string; - span: Span; - reporter: typeof gatsbyReporter; -} -export declare const createTimerReporter: ({ text, id, span, reporter, }: ICreateTimerReporterArguments) => ITimerReporter; -export {}; diff --git a/packages/gatsby-reporter/lib/reporter-timer.js b/packages/gatsby-reporter/lib/reporter-timer.js deleted file mode 100644 index 153aad4d70bd5..0000000000000 --- a/packages/gatsby-reporter/lib/reporter-timer.js +++ /dev/null @@ -1,67 +0,0 @@ -"use strict"; - -var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); - -exports.__esModule = true; -exports.createTimerReporter = void 0; - -var reporterActions = _interopRequireWildcard(require("./redux/actions")); - -var _constants = require("./constants"); - -/* - * This module is used when calling reporter. - * these logs - */ -const createTimerReporter = ({ - text, - id, - span, - reporter -}) => { - return { - start() { - reporterActions.startActivity({ - id, - text: text || `__timer__`, - type: _constants.ActivityTypes.Spinner - }); - }, - - setStatus(statusText) { - reporterActions.setActivityStatusText({ - id, - statusText - }); - }, - - panicOnBuild(errorMeta, error) { - span.finish(); - reporterActions.setActivityErrored({ - id - }); - return reporter.panicOnBuild(errorMeta, error); - }, - - panic(errorMeta, error) { - span.finish(); - reporterActions.endActivity({ - id, - status: _constants.ActivityStatuses.Failed - }); - return reporter.panic(errorMeta, error); - }, - - end() { - span.finish(); - reporterActions.endActivity({ - id, - status: _constants.ActivityStatuses.Success - }); - }, - - span - }; -}; - -exports.createTimerReporter = createTimerReporter; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/reporter.d.ts b/packages/gatsby-reporter/lib/reporter.d.ts deleted file mode 100644 index 3699b77e5e04e..0000000000000 --- a/packages/gatsby-reporter/lib/reporter.d.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { ActivityStatuses } from "./constants"; -import { IStructuredError } from "./structured-errors/types"; -import { ErrorMeta, IActivityArgs, IPhantomReporter, IProgressReporter, ITimerReporter } from "./types"; -import { ICreateLog } from "./redux/types"; -/** - * Reporter module. - * @module reporter - */ -export declare class Reporter { - /** - * Strip initial indentation template function. - */ - stripIndent: import("common-tags").TemplateTag; - format: import("chalk").Chalk & { - supportsColor: import("chalk").ColorSupport; - }; - /** - * Toggle verbosity. - */ - setVerbose: (_isVerbose?: boolean) => void; - /** - * Turn off colors in error output. - */ - setNoColor: (isNoColor?: boolean) => void; - /** - * Log arguments and exit process with status 1. - */ - panic: (errorMeta: ErrorMeta, error?: Error | Error[] | undefined) => never; - panicOnBuild: (errorMeta: ErrorMeta, error?: Error | Error[] | undefined) => IStructuredError | IStructuredError[]; - error: (errorMeta: ErrorMeta | ErrorMeta[], error?: Error | Error[] | undefined) => IStructuredError | IStructuredError[]; - /** - * Set prefix on uptime. - */ - uptime: (prefix: string) => void; - verbose: (text: string) => void; - success: (text?: string | undefined) => ICreateLog; - info: (text?: string | undefined) => ICreateLog; - warn: (text?: string | undefined) => ICreateLog; - log: (text?: string | undefined) => ICreateLog; - pendingActivity: ({ id, status, }: { - id: string; - status?: ActivityStatuses | undefined; - }) => (import("./redux/types").IPendingActivity | ((dispatch: import("redux").Dispatch) => void))[]; - completeActivity: (id: string, status?: ActivityStatuses) => void; - /** - * Time an activity. - */ - activityTimer: (text: string, activityArgs?: IActivityArgs) => ITimerReporter; - /** - * Create an Activity that is not visible to the user - * - * During the lifecycle of the Gatsby process, sometimes we need to do some - * async work and wait for it to complete. A typical example of this is a job. - * This work should set the status of the process to `in progress` while running and - * `complete` (or `failure`) when complete. Activities do just this! However, they - * are visible to the user. So this function can be used to create a _hidden_ activity - * that while not displayed in the CLI, still triggers a change in process status. - */ - phantomActivity: (text: string, activityArgs?: IActivityArgs) => IPhantomReporter; - /** - * Create a progress bar for an activity - */ - createProgress: (text: string, total?: number, start?: number, activityArgs?: IActivityArgs) => IProgressReporter; - _setStage: () => void; -} -export declare const reporter: Reporter; diff --git a/packages/gatsby-reporter/lib/reporter.js b/packages/gatsby-reporter/lib/reporter.js deleted file mode 100644 index ac8b402ffbbbb..0000000000000 --- a/packages/gatsby-reporter/lib/reporter.js +++ /dev/null @@ -1,273 +0,0 @@ -"use strict"; - -var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.reporter = exports.Reporter = void 0; - -var _commonTags = require("common-tags"); - -var _chalk = _interopRequireDefault(require("chalk")); - -var _gatsbyTelemetry = require("gatsby-telemetry"); - -var _opentracing = require("opentracing"); - -var _getErrorFormater = require("./get-error-formater"); - -var reporterActions = _interopRequireWildcard(require("./redux/actions")); - -var _constants = require("./constants"); - -var _constructError = _interopRequireDefault(require("./structured-errors/construct-error")); - -var _catchExitSignals = require("./catch-exit-signals"); - -var _reporterTimer = require("./reporter-timer"); - -var _reporterPhantom = require("./reporter-phantom"); - -var _reporterProgress = require("./reporter-progress"); - -const errorFormatter = (0, _getErrorFormater.getErrorFormatter)(); -const tracer = (0, _opentracing.globalTracer)(); -let isVerbose = false; -/** - * Reporter module. - * @module reporter - */ - -class Reporter { - constructor() { - this.stripIndent = _commonTags.stripIndent; - this.format = _chalk.default; - - this.setVerbose = (_isVerbose = true) => { - isVerbose = _isVerbose; - }; - - this.setNoColor = (isNoColor = false) => { - if (isNoColor) { - errorFormatter.withoutColors(); - } // disables colors in popular terminal output coloring packages - // - chalk: see https://www.npmjs.com/package/chalk#chalksupportscolor - // - ansi-colors: see https://github.com/doowb/ansi-colors/blob/8024126c7115a0efb25a9a0e87bc5e29fd66831f/index.js#L5-L7 - - - if (isNoColor) { - process.env.FORCE_COLOR = `0`; // chalk determines color level at import time. Before we reach this point, - // chalk was already imported, so we need to retroactively adjust level - - _chalk.default.level = 0; - } - }; - - this.panic = (errorMeta, error) => { - const reporterError = this.error(errorMeta, error); - (0, _gatsbyTelemetry.trackError)(`GENERAL_PANIC`, { - error: reporterError - }); - (0, _catchExitSignals.prematureEnd)(); - return process.exit(1); - }; - - this.panicOnBuild = (errorMeta, error) => { - const reporterError = this.error(errorMeta, error); - (0, _gatsbyTelemetry.trackError)(`BUILD_PANIC`, { - error: reporterError - }); - - if (process.env.gatsby_executing_command === `build`) { - (0, _catchExitSignals.prematureEnd)(); - process.exit(1); - } - - return reporterError; - }; - - this.error = (errorMeta, error) => { - let details = { - context: {} - }; // Many paths to retain backcompat :scream: - // 1. - // reporter.error(any, Error); - // reporter.error(any, [Error]); - - if (error) { - if (Array.isArray(error)) { - return error.map(errorItem => this.error(errorMeta, errorItem)); - } - - details.error = error; - details.context = { - sourceMessage: errorMeta + ` ` + error.message - }; // 2. - // reporter.error(Error); - } else if (errorMeta instanceof Error) { - details.error = errorMeta; - details.context = { - sourceMessage: errorMeta.message - }; // 3. - // reporter.error([Error]); - } else if (Array.isArray(errorMeta)) { - // when we get an array of messages, call this function once for each error - return errorMeta.map(errorItem => this.error(errorItem)); // 4. - // reporter.error(errorMeta); - } else if (typeof errorMeta === `object`) { - details = { ...errorMeta - }; // 5. - // reporter.error('foo'); - } else if (typeof errorMeta === `string`) { - details.context = { - sourceMessage: errorMeta - }; - } - - const structuredError = (0, _constructError.default)({ - details - }); - - if (structuredError) { - reporterActions.createLog(structuredError); - } // TODO: remove this once Error component can render this info - // log formatted stacktrace - - - if (structuredError.error) { - this.log(errorFormatter.render(structuredError.error)); - } - - return structuredError; - }; - - this.uptime = prefix => { - this.verbose(`${prefix}: ${(process.uptime() * 1000).toFixed(3)}ms`); - }; - - this.verbose = text => { - if (isVerbose) { - reporterActions.createLog({ - level: _constants.LogLevels.Debug, - text - }); - } - }; - - this.success = text => reporterActions.createLog({ - level: _constants.LogLevels.Success, - text - }); - - this.info = text => reporterActions.createLog({ - level: _constants.LogLevels.Info, - text - }); - - this.warn = text => reporterActions.createLog({ - level: _constants.LogLevels.Warning, - text - }); - - this.log = text => reporterActions.createLog({ - level: _constants.LogLevels.Log, - text - }); - - this.pendingActivity = reporterActions.createPendingActivity; - - this.completeActivity = (id, status = _constants.ActivityStatuses.Success) => { - reporterActions.endActivity({ - id, - status - }); - }; - - this.activityTimer = (text, activityArgs = {}) => { - let { - parentSpan, - id, - tags - } = activityArgs; - const spanArgs = parentSpan ? { - childOf: parentSpan, - tags - } : { - tags - }; - - if (!id) { - id = text; - } - - const span = tracer.startSpan(text, spanArgs); - return (0, _reporterTimer.createTimerReporter)({ - text, - id, - span, - reporter: this - }); - }; - - this.phantomActivity = (text, activityArgs = {}) => { - let { - parentSpan, - id, - tags - } = activityArgs; - const spanArgs = parentSpan ? { - childOf: parentSpan, - tags - } : { - tags - }; - - if (!id) { - id = text; - } - - const span = tracer.startSpan(text, spanArgs); - return (0, _reporterPhantom.createPhantomReporter)({ - id, - text, - span - }); - }; - - this.createProgress = (text, total = 0, start = 0, activityArgs = {}) => { - let { - parentSpan, - id, - tags - } = activityArgs; - const spanArgs = parentSpan ? { - childOf: parentSpan, - tags - } : { - tags - }; - - if (!id) { - id = text; - } - - const span = tracer.startSpan(text, spanArgs); - return (0, _reporterProgress.createProgressReporter)({ - id, - text, - total, - start, - span, - reporter: this - }); - }; - - this._setStage = () => {}; - } - -} - -exports.Reporter = Reporter; -const reporter = new Reporter(); -exports.reporter = reporter; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/start-logger.d.ts b/packages/gatsby-reporter/lib/start-logger.d.ts deleted file mode 100644 index 90a4f27d28d1d..0000000000000 --- a/packages/gatsby-reporter/lib/start-logger.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const startLogger: () => void; diff --git a/packages/gatsby-reporter/lib/start-logger.js b/packages/gatsby-reporter/lib/start-logger.js deleted file mode 100644 index 7f8a26b0d8b50..0000000000000 --- a/packages/gatsby-reporter/lib/start-logger.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.startLogger = void 0; - -var _semver = _interopRequireDefault(require("semver")); - -var _gatsbyCoreUtils = require("gatsby-core-utils"); - -var _ipc = require("./loggers/ipc"); - -var _json = require("./loggers/json"); - -var _yurnalist = require("./loggers/yurnalist"); - -var _ink = require("./loggers/ink"); - -/* - * This module is a side-effect filled module to load in the proper logger. - */ -const startLogger = () => { - let inkExists = false; - - try { - inkExists = !!require.resolve(`ink`); // eslint-disable-next-line no-empty - } catch (err) {} - - if (!process.env.GATSBY_LOGGER) { - if (inkExists && _semver.default.satisfies(process.version, `>=8`) && !(0, _gatsbyCoreUtils.isCI)() && typeof jest === `undefined`) { - process.env.GATSBY_LOGGER = `ink`; - } else { - process.env.GATSBY_LOGGER = `yurnalist`; - } - } // if child process - use ipc logger - - - if (process.send) { - // process.env.FORCE_COLOR = `0` - (0, _ipc.initializeIPCLogger)(); - } - - if (process.env.GATSBY_LOGGER.includes(`json`)) { - (0, _json.initializeJSONLogger)(); - } else if (process.env.GATSBY_LOGGER.includes(`yurnalist`)) { - (0, _yurnalist.initializeYurnalistLogger)(); - } else { - (0, _ink.initializeINKLogger)(); - } -}; - -exports.startLogger = startLogger; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/structured-errors/__tests__/construct-error.d.ts b/packages/gatsby-reporter/lib/structured-errors/__tests__/construct-error.d.ts deleted file mode 100644 index cb0ff5c3b541f..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/__tests__/construct-error.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/gatsby-reporter/lib/structured-errors/__tests__/error-map.d.ts b/packages/gatsby-reporter/lib/structured-errors/__tests__/error-map.d.ts deleted file mode 100644 index cb0ff5c3b541f..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/__tests__/error-map.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/gatsby-reporter/lib/structured-errors/__tests__/error-schema.d.ts b/packages/gatsby-reporter/lib/structured-errors/__tests__/error-schema.d.ts deleted file mode 100644 index cb0ff5c3b541f..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/__tests__/error-schema.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/packages/gatsby-reporter/lib/structured-errors/construct-error.d.ts b/packages/gatsby-reporter/lib/structured-errors/construct-error.d.ts deleted file mode 100644 index d25be75509876..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/construct-error.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { IConstructError, IStructuredError } from "./types"; -declare const constructError: ({ details: { id, ...otherDetails }, }: IConstructError) => IStructuredError; -export default constructError; diff --git a/packages/gatsby-reporter/lib/structured-errors/construct-error.js b/packages/gatsby-reporter/lib/structured-errors/construct-error.js deleted file mode 100644 index eb8b6645ef512..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/construct-error.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.default = void 0; - -var _stackTrace = _interopRequireDefault(require("stack-trace")); - -var _errorSchema = require("./error-schema"); - -var _errorMap = require("./error-map"); - -var _sanitizeStructuredStackTrace = require("./sanitize-structured-stack-trace"); - -// Merge partial error details with information from the errorMap -// Validate the constructed object against an error schema -const constructError = ({ - details: { - id, - ...otherDetails - } -}) => { - const result = id && _errorMap.errorMap[id] || _errorMap.defaultError; // merge - - const structuredError = { - context: {}, - ...otherDetails, - ...result, - text: result.text(otherDetails.context), - stack: otherDetails.error ? (0, _sanitizeStructuredStackTrace.sanitizeStructuredStackTrace)(_stackTrace.default.parse(otherDetails.error)) : [], - docsUrl: result.docsUrl || `https://gatsby.dev/issue-how-to` - }; - - if (id) { - structuredError.code = id; - } // validate - - - const { - error - } = _errorSchema.errorSchema.validate(structuredError); - - if (error !== null) { - console.log(`Failed to validate error`, error); - process.exit(1); - } - - return structuredError; -}; - -var _default = constructError; -exports.default = _default; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/structured-errors/error-map.d.ts b/packages/gatsby-reporter/lib/structured-errors/error-map.d.ts deleted file mode 100644 index 4d43e42c9dfeb..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/error-map.d.ts +++ /dev/null @@ -1,259 +0,0 @@ -import { ErrorLevel, ErrorType } from "./types"; -declare const errors: { - "": { - text: (context: any) => string; - level: ErrorLevel; - }; - 95312: { - text: (context: any) => string; - level: ErrorLevel; - docsUrl: string; - }; - 95313: { - text: (context: any) => string; - level: ErrorLevel; - docsUrl: string; - }; - 98123: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 98124: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85901: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85907: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85908: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85909: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85910: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - docsUrl: string; - }; - 85911: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85912: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85913: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85914: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85915: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85916: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85917: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85918: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85919: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85920: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85921: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85922: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85923: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85924: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85925: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85926: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 85927: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 10122: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 10123: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 10124: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 10125: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 10126: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 10226: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 11321: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 11322: { - text: (context: any) => string; - level: ErrorLevel; - }; - 11323: { - text: (context: any) => string; - level: ErrorLevel; - }; - 11324: { - text: (context: any) => string; - level: ErrorLevel; - }; - 11325: { - text: (context: any) => string; - level: ErrorLevel; - }; - 11326: { - text: (context: any) => string; - level: ErrorLevel; - }; - 11327: { - text: (context: any) => string; - level: ErrorLevel; - }; - 11328: { - text: (context: any) => string; - level: ErrorLevel; - }; - 11329: { - text: (context: any) => string; - level: ErrorLevel; - }; - 11330: { - text: (context: any) => string; - type: ErrorType; - level: ErrorLevel; - }; - 11331: { - text: (context: any) => string; - level: ErrorLevel; - }; - 11467: { - text: (context: any) => string; - level: ErrorLevel; - docsUrl: string; - }; - 11521: { - text: () => string; - level: ErrorLevel; - docsUrl: string; - }; - 11522: { - text: () => string; - level: ErrorLevel; - docsUrl: string; - }; - 11610: { - text: (context: any) => string; - level: ErrorLevel; - docsUrl: string; - }; - 11611: { - text: (context: any) => string; - level: ErrorLevel; - docsUrl: string; - }; - 11612: { - text: (context: any) => string; - level: ErrorLevel; - docsUrl: string; - }; - 11613: { - text: (context: any) => string; - level: ErrorLevel; - docsUrl: string; - }; -}; -export declare type ErrorId = keyof typeof errors; -export declare const errorMap: Record; -export declare const defaultError: IErrorMapEntry; -export interface IErrorMapEntry { - text: (context: any) => string; - level: ErrorLevel; - type?: ErrorType; - docsUrl?: string; -} -export {}; diff --git a/packages/gatsby-reporter/lib/structured-errors/error-map.js b/packages/gatsby-reporter/lib/structured-errors/error-map.js deleted file mode 100644 index e7e5e30309330..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/error-map.js +++ /dev/null @@ -1,342 +0,0 @@ -"use strict"; - -exports.__esModule = true; -exports.defaultError = exports.errorMap = void 0; - -var _commonTags = require("common-tags"); - -var _types = require("./types"); - -const optionalGraphQLInfo = context => `${context.codeFrame ? `\n\n${context.codeFrame}` : ``}${context.filePath ? `\n\nFile path: ${context.filePath}` : ``}${context.urlPath ? `\nUrl path: ${context.urlPath}` : ``}${context.plugin ? `\nPlugin: ${context.plugin}` : ``}`; - -const errors = { - "": { - text: context => { - const sourceMessage = context.sourceMessage ? context.sourceMessage : `There was an error`; - return sourceMessage; - }, - level: _types.ErrorLevel.ERROR - }, - "95312": { - text: context => `"${context.ref}" is not available during server side rendering.`, - level: _types.ErrorLevel.ERROR, - docsUrl: `https://gatsby.dev/debug-html` - }, - "95313": { - text: context => `Building static HTML failed${context.errorPath ? ` for path "${context.errorPath}"` : ``}`, - level: _types.ErrorLevel.ERROR, - docsUrl: `https://gatsby.dev/debug-html` - }, - "98123": { - text: context => { - var _context$sourceMessag; - - return `${context.stageLabel} failed\n\n${(_context$sourceMessag = context.sourceMessage) !== null && _context$sourceMessag !== void 0 ? _context$sourceMessag : context.message}`; - }, - type: _types.ErrorType.WEBPACK, - level: _types.ErrorLevel.ERROR - }, - "98124": { - text: context => `${context.stageLabel} failed\n\n${context.sourceMessage}\n\nIf you're trying to use a package make sure that '${context.packageName}' is installed. If you're trying to use a local file make sure that the path is correct.`, - type: _types.ErrorType.WEBPACK, - level: _types.ErrorLevel.ERROR - }, - "85901": { - text: context => (0, _commonTags.stripIndent)(` - There was an error in your GraphQL query:\n\n${context.sourceMessage}${optionalGraphQLInfo(context)}`), - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - // Deprecated - "85907": { - text: context => `There was an error in your GraphQL query:\n\n${context.message}`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85908": { - text: context => { - const closestFragment = context.closestFragment ? `\n\nDid you mean to use ` + `"${context.closestFragment}"?` : ``; - return `There was an error in your GraphQL query:\n\nThe fragment "${context.fragmentName}" does not exist.\n\n${context.codeFrame}${closestFragment}`; - }, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - // Deprecated - "85909": { - text: context => context.sourceMessage, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85910": { - text: context => (0, _commonTags.stripIndents)(` - Multiple "root" queries found: "${context.name}" and "${context.otherName}". - Only the first ("${context.otherName}") will be registered. - - Instead of: - - ${context.beforeCodeFrame} - - Do: - - ${context.afterCodeFrame} - - This can happen when you use two page/static queries in one file. Please combine those into one query. - If you're defining multiple components (each with a static query) in one file, you'll need to move each component to its own file. - `), - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR, - docsUrl: `https://www.gatsbyjs.org/docs/graphql/` - }, - "85911": { - text: context => (0, _commonTags.stripIndent)(` - There was a problem parsing "${context.filePath}"; any GraphQL - fragments or queries in this file were not processed. - - This may indicate a syntax error in the code, or it may be a file type - that Gatsby does not know how to parse. - `), - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85912": { - text: context => `Failed to parse preprocessed file ${context.filePath}`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85913": { - text: context => `There was a problem reading the file: ${context.filePath}`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85914": { - text: context => `There was a problem reading the file: ${context.filePath}`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - // default parsing error - "85915": { - text: context => `There was a problem parsing the GraphQL query in file: ${context.filePath}`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85916": { - text: context => `String interpolation is not allowed in graphql tag:\n\n${context.codeFrame}`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85917": { - text: context => `Unexpected empty graphql tag${context.codeFrame ? `\n\n${context.codeFrame}` : ``}`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85918": { - text: context => (0, _commonTags.stripIndent)(` - GraphQL syntax error in query:\n\n${context.sourceMessage}${context.codeFrame ? `\n\n${context.codeFrame}` : ``}`), - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - // Duplicate fragment - "85919": { - text: context => (0, _commonTags.stripIndent)(` - Found two different GraphQL fragments with identical name "${context.fragmentName}". Fragment names must be unique - - File: ${context.leftFragment.filePath} - ${context.leftFragment.codeFrame} - - File: ${context.rightFragment.filePath} - ${context.rightFragment.codeFrame} - `), - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - // Undefined variables in Queries - "85920": { - text: context => { - const staticQueryMessage = (0, _commonTags.stripIndents)(`Suggestion 1: - - If you're not using a page query but a useStaticQuery / StaticQuery you see this error because they currently don't support variables. To learn more about the limitations of useStaticQuery / StaticQuery, please visit these docs: - - https://www.gatsbyjs.org/docs/use-static-query/ - https://www.gatsbyjs.org/docs/static-query/`); - const generalMessage = (0, _commonTags.stripIndents)(`Suggestion 2: - - You might have a typo in the variable name "${context.variableName}" or you didn't provide the variable via context to this page query. Have a look at the docs to learn how to add data to context: - - https://www.gatsbyjs.org/docs/page-query/#how-to-add-query-variables-to-a-page-query`); - return (0, _commonTags.stripIndent)(` - There was an error in your GraphQL query:\n\n${context.sourceMessage}${optionalGraphQLInfo(context)}\n\n${staticQueryMessage}\n\n${generalMessage}`); - }, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85921": { - text: context => `There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nIf you're e.g. filtering for specific nodes make sure that you choose the correct field (that has the same type "${context.inputType}") or adjust the context variable to the type "${context.expectedType}".`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85922": { - text: context => `There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nThis can happen if you e.g. accidentally added { } to the field "${context.fieldName}". If you didn't expect "${context.fieldName}" to be of type "${context.fieldType}" make sure that your input source and/or plugin is correct.`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85923": { - text: context => `There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nIf you don't expect "${context.field}" to exist on the type "${context.type}" it is most likely a typo.\nHowever, if you expect "${context.field}" to exist there are a couple of solutions to common problems:\n\n- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server\n- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have\n- You want to optionally use your field "${context.field}" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")\n\nIt is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "${context.type}":\nhttps://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85924": { - text: context => `There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nThis can happen when you or a plugin/theme explicitly defined the GraphQL schema for this GraphQL object type via the schema customization API and "${context.value}" doesn't match the (scalar) type of "${context.type}".${optionalGraphQLInfo(context)}`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85925": { - text: context => `There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nThe field "${context.field}" was explicitly defined as non-nullable via the schema customization API (by yourself or a plugin/theme). This means that this field is not optional and you have to define a value. If this is not your desired behavior and you defined the schema yourself, go to "createTypes" in gatsby-node.js. If you're using a plugin/theme, you can learn more here on how to fix field types:\nhttps://www.gatsbyjs.org/docs/schema-customization/#fixing-field-types${optionalGraphQLInfo(context)}`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85926": { - text: context => `There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nThis can happen when you used graphql\`{ ...yourQuery }\` instead of graphql(\`{ ...yourQuery }\`) inside gatsby-node.js\n\nYou can't use the template literal function you're used to (from page queries) and rather have to call graphql() as a normal function.`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - "85927": { - text: context => `There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nSee if ${context.variable} has a typo or ${context.operation} doesn't actually require this variable.`, - type: _types.ErrorType.GRAPHQL, - level: _types.ErrorLevel.ERROR - }, - // Config errors - "10122": { - text: context => `The site's gatsby-config.js failed validation:\n\n${context.sourceMessage}`, - type: _types.ErrorType.CONFIG, - level: _types.ErrorLevel.ERROR - }, - "10123": { - text: context => `We encountered an error while trying to load your site's ${context.configName}. Please fix the error and try again.`, - type: _types.ErrorType.CONFIG, - level: _types.ErrorLevel.ERROR - }, - "10124": { - text: context => `It looks like you were trying to add the config file? Please rename "${context.nearMatch}" to "${context.configName}.js"`, - type: _types.ErrorType.CONFIG, - level: _types.ErrorLevel.ERROR - }, - "10125": { - text: context => `Your ${context.configName} file is in the wrong place. You've placed it in the src/ directory. It must instead be at the root of your site next to your package.json file.`, - type: _types.ErrorType.CONFIG, - level: _types.ErrorLevel.ERROR - }, - "10126": { - text: context => `${context.path}/${context.configName} cannot export a function.` + `\n\nA ${context.configName} exported as a Function can only be used as a theme and not run directly.` + `\nIf you are trying to run a theme directly, use the theme in an example site or starter instead and run that site to test.` + `\nIf you are in the root gatsby-config.js for your site, change the export to be an object and not a function as functions` + `\nare not supported in the root gatsby-config.`, - type: _types.ErrorType.CONFIG, - level: _types.ErrorLevel.ERROR - }, - "10226": { - text: context => [`Couldn't find the "${context.themeName}" plugin declared in "${context.configFilePath}".`, context.pathToLocalTheme && `Tried looking for a local plugin in ${context.pathToLocalTheme}.`, `Tried looking for an installed package in the following paths:\n${context.nodeResolutionPaths.map(potentialLocationPath => ` - ${potentialLocationPath}`).join(`\n`)}`].filter(Boolean).join(`\n\n`), - type: _types.ErrorType.CONFIG, - level: _types.ErrorLevel.ERROR - }, - // Plugin errors - "11321": { - text: context => { - var _context$sourceMessag2; - - return `"${context.pluginName}" threw an error while running the ${context.api} lifecycle:\n\n${(_context$sourceMessag2 = context.sourceMessage) !== null && _context$sourceMessag2 !== void 0 ? _context$sourceMessag2 : context.message}${optionalGraphQLInfo(context)}`; - }, - type: _types.ErrorType.PLUGIN, - level: _types.ErrorLevel.ERROR - }, - "11322": { - text: context => `${context.pluginName} created a page and didn't pass the path to the component.\n\nThe page object passed to createPage:\n${JSON.stringify(context.pageObject, null, 4)}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`, - level: _types.ErrorLevel.ERROR - }, - "11323": { - text: context => `${context.pluginName} must set the page path when creating a page.\n\nThe page object passed to createPage:\n${JSON.stringify(context.pageObject, null, 4)}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`, - level: _types.ErrorLevel.ERROR - }, - "11324": { - text: context => `${context.message}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`, - level: _types.ErrorLevel.ERROR - }, - "11325": { - text: context => `${context.pluginName} created a page with a component that doesn't exist.\n\nThe path to the missing component is "${context.component}"\n\nThe page object passed to createPage:\n${JSON.stringify(context.pageObject, null, 4)}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`, - level: _types.ErrorLevel.ERROR - }, - "11326": { - text: context => `${context.pluginName} must set the absolute path to the page component when create creating a page.\n\nThe (relative) path you used for the component is "${context.component}"\n\nYou can convert a relative path to an absolute path by requiring the path module and calling path.resolve() e.g.\n\nconst path = require("path")\npath.resolve("${context.component}")\n\nThe page object passed to createPage:\n${JSON.stringify(context.pageObject, null, 4)}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`, - level: _types.ErrorLevel.ERROR - }, - "11327": { - text: context => `You have an empty file in the "src/pages" directory at "${context.relativePath}". Please remove it or make it a valid component`, - level: _types.ErrorLevel.ERROR - }, - "11328": { - text: context => `A page component must export a React component for it to be valid. Please make sure this file exports a React component:\n\n${context.fileName}`, - level: _types.ErrorLevel.ERROR - }, - // invalid or deprecated APIs - "11329": { - text: context => [(0, _commonTags.stripIndent)(` - Your plugins must export known APIs from their gatsby-${context.exportType}.js. - - See https://www.gatsbyjs.org/docs/${context.exportType}-apis/ for the list of Gatsby ${context.exportType} APIs. - `)].concat([``].concat(context.errors)).concat(context.fixes.length > 0 ? [``, `Some of the following may help fix the error(s):`, ``, ...context.fixes.map(fix => `- ${fix}`)] : []).join(`\n`), - level: _types.ErrorLevel.ERROR - }, - // "X" is not defined in Gatsby's node APIs - "11330": { - text: context => { - var _context$sourceMessag3; - - return `"${context.pluginName}" threw an error while running the ${context.api} lifecycle:\n\n${(_context$sourceMessag3 = context.sourceMessage) !== null && _context$sourceMessag3 !== void 0 ? _context$sourceMessag3 : context.message}\n\n${context.codeFrame}\n\nMake sure that you don't have a typo somewhere and use valid arguments in ${context.api} lifecycle.\nLearn more about ${context.api} here: https://www.gatsbyjs.org/docs/node-apis/#${context.api}`; - }, - type: _types.ErrorType.PLUGIN, - level: _types.ErrorLevel.ERROR - }, - // Directory/file name exceeds OS character limit - "11331": { - text: context => [`One or more path segments are too long - they exceed OS filename length limit.\n`, `Page path: "${context.path}"`, `Invalid segments:\n${context.invalidPathSegments.map(segment => ` - "${segment}"`).join(`\n`)}`, ...(!context.isProduction ? [`\nThis will fail production builds, please adjust your paths.`, `\nIn development mode gatsby truncated to: "${context.truncatedPath}"`] : [])].filter(Boolean).join(`\n`), - level: _types.ErrorLevel.ERROR - }, - // node object didn't pass validation - "11467": { - text: context => [`The new node didn't pass validation: ${context.validationErrorMessage}`, `Failing node:`, JSON.stringify(context.node, null, 4), `Note: there might be more nodes that failed validation. Output is limited to one node per type of validation failure to limit terminal spam.`, context.codeFrame].filter(Boolean).join(`\n\n`), - level: _types.ErrorLevel.ERROR, - docsUrl: `https://www.gatsbyjs.org/docs/actions/#createNode` - }, - // local SSL certificate errors - "11521": { - text: () => `for custom ssl --https, --cert-file, and --key-file must be used together`, - level: _types.ErrorLevel.ERROR, - docsUrl: `https://www.gatsbyjs.org/docs/local-https/#custom-key-and-certificate-files` - }, - "11522": { - text: () => `Failed to generate dev SSL certificate`, - level: _types.ErrorLevel.ERROR, - docsUrl: `https://www.gatsbyjs.org/docs/local-https/#setup` - }, - // cli new command errors - "11610": { - text: context => `It looks like you gave wrong argument orders . Try running instead "gatsby new ${context.starter} ${context.rootPath}"`, - level: _types.ErrorLevel.ERROR, - docsUrl: `https://www.gatsbyjs.org/docs/gatsby-cli/#new` - }, - "11611": { - text: context => `It looks like you passed a URL to your project name. Try running instead "gatsby new new-gatsby-project ${context.rootPath}"`, - level: _types.ErrorLevel.ERROR, - docsUrl: `https://www.gatsbyjs.org/docs/gatsby-cli/#new` - }, - "11612": { - text: context => `Could not create a project in "${context.path}" because it's not a valid path`, - level: _types.ErrorLevel.ERROR, - docsUrl: `https://www.gatsbyjs.org/docs/gatsby-cli/#new` - }, - "11613": { - text: context => `Directory ${context.rootPath} is already an npm project`, - level: _types.ErrorLevel.ERROR, - docsUrl: `https://www.gatsbyjs.org/docs/gatsby-cli/#new` - } -}; -const errorMap = errors; -exports.errorMap = errorMap; -const defaultError = errorMap[``]; -exports.defaultError = defaultError; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/structured-errors/error-schema.d.ts b/packages/gatsby-reporter/lib/structured-errors/error-schema.d.ts deleted file mode 100644 index 83fd5cc4b7b28..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/error-schema.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/// -import Joi from "@hapi/joi"; -import { ILocationPosition, IStructuredError } from "./types"; -export declare const Position: Joi.ObjectSchema; -export declare const errorSchema: Joi.ObjectSchema; diff --git a/packages/gatsby-reporter/lib/structured-errors/error-schema.js b/packages/gatsby-reporter/lib/structured-errors/error-schema.js deleted file mode 100644 index 4a8dbfc0ba5b6..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/error-schema.js +++ /dev/null @@ -1,43 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -exports.__esModule = true; -exports.errorSchema = exports.Position = void 0; - -var _joi = _interopRequireDefault(require("@hapi/joi")); - -const Position = _joi.default.object().keys({ - line: _joi.default.number(), - column: _joi.default.number() -}); - -exports.Position = Position; - -const errorSchema = _joi.default.object().keys({ - code: _joi.default.string(), - text: _joi.default.string(), - stack: _joi.default.array().items(_joi.default.object().keys({ - fileName: _joi.default.string(), - functionName: _joi.default.string().allow(null), - lineNumber: _joi.default.number().allow(null), - columnNumber: _joi.default.number().allow(null) - })).allow(null), - level: _joi.default.string().valid([`ERROR`, `WARNING`, `INFO`, `DEBUG`]), - type: _joi.default.string().valid([`GRAPHQL`, `CONFIG`, `WEBPACK`, `PLUGIN`]), - filePath: _joi.default.string(), - location: _joi.default.object({ - start: Position.required(), - end: Position - }), - docsUrl: _joi.default.string().uri({ - allowRelative: false, - relativeOnly: false - }), - error: _joi.default.object({}).unknown(), - context: _joi.default.object({}).unknown(), - group: _joi.default.string(), - panicOnBuild: _joi.default.boolean() -}); - -exports.errorSchema = errorSchema; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/structured-errors/sanitize-structured-stack-trace.d.ts b/packages/gatsby-reporter/lib/structured-errors/sanitize-structured-stack-trace.d.ts deleted file mode 100644 index a2a984de67ed0..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/sanitize-structured-stack-trace.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import stackTrace from "stack-trace"; -import { IStructuredStackFrame } from "./types"; -export declare const sanitizeStructuredStackTrace: (stack: stackTrace.StackFrame[]) => IStructuredStackFrame[]; diff --git a/packages/gatsby-reporter/lib/structured-errors/sanitize-structured-stack-trace.js b/packages/gatsby-reporter/lib/structured-errors/sanitize-structured-stack-trace.js deleted file mode 100644 index a69dca89805f2..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/sanitize-structured-stack-trace.js +++ /dev/null @@ -1,45 +0,0 @@ -"use strict"; - -exports.__esModule = true; -exports.sanitizeStructuredStackTrace = void 0; - -var _gatsbyCoreUtils = require("gatsby-core-utils"); - -const packagesToSkip = [`core-js`, `bluebird`, `regenerator-runtime`, `graphql`]; -const packagesToSkipTest = new RegExp(`node_modules[\\/](${packagesToSkip.join(`|`)})`); // TO-DO: move this this out of this file (and probably delete this file completely) -// it's here because it re-implements similar thing as `pretty-error` already does - -const sanitizeStructuredStackTrace = stack => { - // first filter out not useful call sites - stack = stack.filter(callSite => { - if (!callSite.getFileName()) { - return false; - } - - if (packagesToSkipTest.test(callSite.getFileName())) { - return false; - } - - if (callSite.getFileName().includes(`asyncToGenerator.js`)) { - return false; - } - - if ((0, _gatsbyCoreUtils.isNodeInternalModulePath)(callSite.getFileName())) { - return false; - } - - return true; - }); // then sanitize individual call site objects to make sure we don't - // emit objects with extra fields that won't be handled by consumers - - return stack.map(callSite => { - return { - fileName: callSite.getFileName(), - functionName: callSite.getFunctionName(), - columnNumber: callSite.getColumnNumber(), - lineNumber: callSite.getLineNumber() - }; - }); -}; - -exports.sanitizeStructuredStackTrace = sanitizeStructuredStackTrace; \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/structured-errors/types.d.ts b/packages/gatsby-reporter/lib/structured-errors/types.d.ts deleted file mode 100644 index 27c4ba7e83e38..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/types.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { IErrorMapEntry, ErrorId } from "./error-map"; -export interface IConstructError { - details: { - id?: ErrorId; - context?: Record; - error?: Error; - [key: string]: unknown; - }; -} -export interface ILocationPosition { - line: number; - column: number; -} -export interface IStructuredStackFrame { - fileName: string; - functionName?: string; - lineNumber?: number; - columnNumber?: number; -} -export interface IStructuredError { - code?: string; - text: string; - stack: IStructuredStackFrame[]; - filePath?: string; - location?: { - start: ILocationPosition; - end?: ILocationPosition; - }; - error?: Error; - group?: string; - level: IErrorMapEntry["level"]; - type?: IErrorMapEntry["type"]; - docsUrl?: string; -} -export interface IOptionalGraphQLInfoContext { - codeFrame?: string; - filePath?: string; - urlPath?: string; - plugin?: string; -} -export declare enum ErrorLevel { - ERROR = "ERROR", - WARNING = "WARNING", - INFO = "INFO", - DEBUG = "DEBUG" -} -export declare enum ErrorType { - GRAPHQL = "GRAPHQL", - CONFIG = "CONFIG", - WEBPACK = "WEBPACK", - PLUGIN = "PLUGIN" -} diff --git a/packages/gatsby-reporter/lib/structured-errors/types.js b/packages/gatsby-reporter/lib/structured-errors/types.js deleted file mode 100644 index 7518fef00bd8c..0000000000000 --- a/packages/gatsby-reporter/lib/structured-errors/types.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; - -exports.__esModule = true; -exports.ErrorType = exports.ErrorLevel = void 0; -let ErrorLevel; -exports.ErrorLevel = ErrorLevel; - -(function (ErrorLevel) { - ErrorLevel["ERROR"] = "ERROR"; - ErrorLevel["WARNING"] = "WARNING"; - ErrorLevel["INFO"] = "INFO"; - ErrorLevel["DEBUG"] = "DEBUG"; -})(ErrorLevel || (exports.ErrorLevel = ErrorLevel = {})); - -let ErrorType; -exports.ErrorType = ErrorType; - -(function (ErrorType) { - ErrorType["GRAPHQL"] = "GRAPHQL"; - ErrorType["CONFIG"] = "CONFIG"; - ErrorType["WEBPACK"] = "WEBPACK"; - ErrorType["PLUGIN"] = "PLUGIN"; -})(ErrorType || (exports.ErrorType = ErrorType = {})); \ No newline at end of file diff --git a/packages/gatsby-reporter/lib/types.d.ts b/packages/gatsby-reporter/lib/types.d.ts deleted file mode 100644 index ea28f9a255084..0000000000000 --- a/packages/gatsby-reporter/lib/types.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Span } from "opentracing"; -import { IStructuredError } from "./structured-errors/types"; -export declare type ErrorMeta = { - id: string; - error?: Error; - context: Record; - [id: string]: any; -} | string | Error | ErrorMeta[]; -export interface IActivityArgs { - id?: string; - parentSpan?: Span; - tags?: { - [key: string]: any; - }; -} -export interface IPhantomReporter { - start(): void; - end(): void; - span: Span; -} -export interface IProgressReporter { - start(): void; - setStatus(statusText: string): void; - tick(increment?: number): void; - panicOnBuild(arg: any, ...otherArgs: any[]): IStructuredError | IStructuredError[]; - panic(arg: any, ...otherArgs: any[]): never; - end(): void; - done(): void; - total: number; - span: Span; -} -export interface ITimerReporter { - start(): void; - setStatus(statusText: string): void; - panicOnBuild(arg: any, ...otherArgs: any[]): IStructuredError | IStructuredError[]; - panic(arg: any, ...otherArgs: any[]): never; - end(): void; - span: Span; -} diff --git a/packages/gatsby-reporter/lib/types.js b/packages/gatsby-reporter/lib/types.js deleted file mode 100644 index 9a390c31f71bc..0000000000000 --- a/packages/gatsby-reporter/lib/types.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; \ No newline at end of file