diff --git a/e2e/commands/status.e2e.2.ts b/e2e/commands/status.e2e.2.ts index bd4fbeb35d46..b0cdfeeae982 100644 --- a/e2e/commands/status.e2e.2.ts +++ b/e2e/commands/status.e2e.2.ts @@ -350,7 +350,7 @@ describe('bit status command', function () { expect(output).to.have.string('component files were deleted'); }); describe('running bit diff', () => { - it('should throw an exception MissingFilesFromComponent', () => { + it('should throw an exception ComponentNotFoundInPath', () => { const diffFunc = () => helper.command.diff('bar/foo'); const error = new ComponentNotFoundInPath('bar'); helper.general.expectToThrow(diffFunc, error); diff --git a/e2e/functionalities/auto-tagging.e2e.2.ts b/e2e/functionalities/auto-tagging.e2e.2.ts index 09aad0da94f4..7b603a004be9 100644 --- a/e2e/functionalities/auto-tagging.e2e.2.ts +++ b/e2e/functionalities/auto-tagging.e2e.2.ts @@ -1,5 +1,5 @@ import chai, { expect } from 'chai'; -import { AUTO_TAGGED_MSG } from '../../src/api/consumer/lib/tag'; +import { AUTO_TAGGED_MSG } from '@teambit/snapping'; import Helper from '../../src/e2e-helper/e2e-helper'; chai.use(require('chai-fs')); diff --git a/scopes/component/snapping/index.ts b/scopes/component/snapping/index.ts index 9b3d4db239be..223c3f4c7312 100644 --- a/scopes/component/snapping/index.ts +++ b/scopes/component/snapping/index.ts @@ -5,3 +5,4 @@ export type { SnappingMain, TagResults, SnapResults } from './snapping.main.runt export default SnappingAspect; export { SnappingAspect }; export type { onTagIdTransformer } from './tag-model-component'; +export { AUTO_TAGGED_MSG, NOTHING_TO_TAG_MSG } from './tag-cmd'; diff --git a/scopes/component/snapping/tag-cmd.ts b/scopes/component/snapping/tag-cmd.ts index ef723e4d4423..de451d41c0f6 100644 --- a/scopes/component/snapping/tag-cmd.ts +++ b/scopes/component/snapping/tag-cmd.ts @@ -1,7 +1,6 @@ import chalk from 'chalk'; import { ComponentIdList, ComponentID } from '@teambit/component-id'; import { Command, CommandOptions } from '@teambit/cli'; -import { NOTHING_TO_TAG_MSG, AUTO_TAGGED_MSG } from '@teambit/legacy/dist/api/consumer/lib/tag'; import ConsumerComponent from '@teambit/legacy/dist/consumer/component/consumer-component'; import { DEFAULT_BIT_RELEASE_TYPE, @@ -16,6 +15,9 @@ import { Logger } from '@teambit/logger'; import { TagResults, SnappingMain } from './snapping.main.runtime'; import { BasicTagParams } from './tag-model-component'; +export const NOTHING_TO_TAG_MSG = 'nothing to tag'; +export const AUTO_TAGGED_MSG = 'auto-tagged dependents'; + const RELEASE_TYPES = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease']; export class TagCmd implements Command { diff --git a/scopes/component/snapping/tag-from-scope.cmd.ts b/scopes/component/snapping/tag-from-scope.cmd.ts index 93c09c08d991..f3cf0cb7ccac 100644 --- a/scopes/component/snapping/tag-from-scope.cmd.ts +++ b/scopes/component/snapping/tag-from-scope.cmd.ts @@ -1,6 +1,6 @@ import chalk from 'chalk'; import { Command, CommandOptions } from '@teambit/cli'; -import { NOTHING_TO_TAG_MSG, AUTO_TAGGED_MSG } from '@teambit/legacy/dist/api/consumer/lib/tag'; +import { NOTHING_TO_TAG_MSG, AUTO_TAGGED_MSG } from './tag-cmd'; import { DEFAULT_BIT_RELEASE_TYPE } from '@teambit/legacy/dist/constants'; import { getHarmonyVersion } from '@teambit/legacy/dist/bootstrap'; import { IssuesClasses } from '@teambit/component-issues'; diff --git a/scopes/pipelines/builder/artifact/artifact-factory.ts b/scopes/pipelines/builder/artifact/artifact-factory.ts index 583135de3a13..88e59c9e2950 100644 --- a/scopes/pipelines/builder/artifact/artifact-factory.ts +++ b/scopes/pipelines/builder/artifact/artifact-factory.ts @@ -4,6 +4,7 @@ import { flatten } from 'lodash'; import { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files'; import { Component, ComponentMap } from '@teambit/component'; import { pathNormalizeToLinux } from '@teambit/legacy/dist/utils'; +import { PathLinux } from '@teambit/legacy/dist/utils/path'; import { ArtifactDefinition } from './artifact-definition'; import { DefaultResolver } from '../storage'; import { ArtifactList } from './artifact-list'; @@ -18,7 +19,7 @@ export type ArtifactMap = ComponentMap>; export class ArtifactFactory { resolvePaths(root: string, def: ArtifactDefinition): string[] { const patternsFlattened = flatten(def.globPatterns); - const patternsFlattenedLinux = patternsFlattened.map(pathNormalizeToLinux); + const patternsFlattenedLinux: PathLinux[] = patternsFlattened.map(pathNormalizeToLinux); const paths = globby.sync(patternsFlattenedLinux, { cwd: root }); return paths; } diff --git a/scopes/scope/importer/import.cmd.ts b/scopes/scope/importer/import.cmd.ts index 868ee46cdd3b..8386979d822f 100644 --- a/scopes/scope/importer/import.cmd.ts +++ b/scopes/scope/importer/import.cmd.ts @@ -10,7 +10,6 @@ import { import { ComponentIdList, ComponentID } from '@teambit/component-id'; import { BitError } from '@teambit/bit-error'; import { immutableUnshift } from '@teambit/legacy/dist/utils'; -import { formatPlainComponentItem } from '@teambit/legacy/dist/cli/chalk-box'; import { ImporterMain } from './importer.main.runtime'; import { ImportOptions, ImportDetails, ImportStatus, ImportResult } from './import-components'; @@ -291,6 +290,14 @@ Also, check that the requested version exists on main or the checked out lane`; return `${title}\n${subTitle}\n${body}`; } +function formatPlainComponentItem({ scope, name, version, deprecated }: any) { + return chalk.cyan( + `- ${scope ? `${scope}/` : ''}${name}@${version ? version.toString() : 'latest'} ${ + deprecated ? chalk.yellow('[deprecated]') : '' + }` + ); +} + function formatPlainComponentItemWithVersions(bitId: ComponentID, importDetails: ImportDetails) { const status: ImportStatus = importDetails.status; const id = bitId.toStringWithoutVersion(); diff --git a/scopes/scope/scope/scope.main.runtime.ts b/scopes/scope/scope/scope.main.runtime.ts index 87e1788e6b33..82476617a83e 100644 --- a/scopes/scope/scope/scope.main.runtime.ts +++ b/scopes/scope/scope/scope.main.runtime.ts @@ -26,7 +26,6 @@ import LegacyScope, { LegacyOnTagResult } from '@teambit/legacy/dist/scope/scope import { LegacyComponentLog as ComponentLog } from '@teambit/legacy-component-log'; import { loadScopeIfExist } from '@teambit/legacy/dist/scope/scope-loader'; import { getDivergeData } from '@teambit/legacy/dist/scope/component-ops/get-diverge-data'; -import { PersistOptions } from '@teambit/legacy/dist/scope/types'; import { ExportPersist, PostSign } from '@teambit/legacy/dist/scope/actions'; import { DependencyResolverAspect, DependencyResolverMain, NodeLinker } from '@teambit/dependency-resolver'; import { getScopeRemotes } from '@teambit/legacy/dist/scope/scope-remotes'; @@ -433,14 +432,6 @@ export class ScopeMain implements ComponentFactory { */ fetch(ids: ComponentIdList) {} // eslint-disable-line @typescript-eslint/no-unused-vars - /** - * This function will get a component and sealed it's current state into the scope - * - * @param {Component[]} components A list of components to seal with specific persist options (such as message and version number) - * @param {PersistOptions} persistGeneralOptions General persistence options such as verbose - */ - persist(components: Component[], options: PersistOptions) {} // eslint-disable-line @typescript-eslint/no-unused-vars - async delete( { ids, force, lanes }: { ids: string[]; force: boolean; lanes: boolean }, headers?: Record diff --git a/scopes/workspace/workspace/workspace-component/component-status-loader.ts b/scopes/workspace/workspace/workspace-component/component-status-loader.ts index 316ec938cc33..c83d83799e52 100644 --- a/scopes/workspace/workspace/workspace-component/component-status-loader.ts +++ b/scopes/workspace/workspace/workspace-component/component-status-loader.ts @@ -8,7 +8,6 @@ import { ModelComponent } from '@teambit/legacy/dist/scope/models'; import { MissingBitMapComponent } from '@teambit/legacy/dist/consumer/bit-map/exceptions'; import ComponentsPendingImport from '@teambit/legacy/dist/consumer/component-ops/exceptions/components-pending-import'; import ComponentNotFoundInPath from '@teambit/legacy/dist/consumer/component/exceptions/component-not-found-in-path'; -import MissingFilesFromComponent from '@teambit/legacy/dist/consumer/component/exceptions/missing-files-from-component'; import ComponentOutOfSync from '@teambit/legacy/dist/consumer/exceptions/component-out-of-sync'; import { Workspace } from '..'; @@ -82,11 +81,7 @@ export class ComponentStatusLoader { } componentFromFileSystem = components[0]; } catch (err: any) { - if ( - err instanceof MissingFilesFromComponent || - err instanceof ComponentNotFoundInPath || - err instanceof MissingBitMapComponent - ) { + if (err instanceof ComponentNotFoundInPath || err instanceof MissingBitMapComponent) { // the file/s have been deleted or the component doesn't exist in bit.map file if (componentFromModel) status.deleted = true; else status.notExist = true; diff --git a/scopes/workspace/workspace/workspace.ts b/scopes/workspace/workspace/workspace.ts index e959388db984..dc6557f79a94 100644 --- a/scopes/workspace/workspace/workspace.ts +++ b/scopes/workspace/workspace/workspace.ts @@ -38,7 +38,6 @@ import { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map import { getMaxSizeForComponents, InMemoryCache } from '@teambit/legacy/dist/cache/in-memory-cache'; import { createInMemoryCache } from '@teambit/legacy/dist/cache/cache-factory'; import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list'; -import { NoComponentDir } from '@teambit/legacy/dist/consumer/component/exceptions/no-component-dir'; import { ExtensionDataList, ExtensionDataEntry } from '@teambit/legacy/dist/consumer/config/extension-data'; import { pathIsInside } from '@teambit/legacy/dist/utils'; import { @@ -1207,9 +1206,6 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`); ): PathOsBased { const componentMap = this.consumer.bitMap.getComponent(bitId, bitMapOptions); const relativeComponentDir = componentMap.getComponentDir(); - if (!relativeComponentDir) { - throw new NoComponentDir(bitId.toString()); - } if (options.relative) { return relativeComponentDir; } diff --git a/src/api/consumer/index.ts b/src/api/consumer/index.ts index f9bdbfe44478..c06abf14d3e1 100644 --- a/src/api/consumer/index.ts +++ b/src/api/consumer/index.ts @@ -1,8 +1,6 @@ import getComponentLogs from './lib/get-component-logs'; import getConsumerComponent from './lib/get-consumer-component'; import getScopeComponent from './lib/get-scope-component'; -// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! -import config from './lib/global-config'; import init from './lib/init'; import { listScope } from './lib/list-scope'; import { add as remoteAdd, list as remoteList, remove as remoteRm } from './lib/remote'; @@ -11,7 +9,6 @@ import { clearCache } from './lib/clear-cache'; export { init, - config, listScope, getConsumerComponent, getScopeComponent, diff --git a/src/api/consumer/lib/exceptions/config-key-not-found.ts b/src/api/consumer/lib/exceptions/config-key-not-found.ts deleted file mode 100644 index 1d5bbad2b87a..000000000000 --- a/src/api/consumer/lib/exceptions/config-key-not-found.ts +++ /dev/null @@ -1,10 +0,0 @@ -import AbstractError from '../../../../error/abstract-error'; - -export default class ConfigKeyNotFound extends AbstractError { - key: string; - - constructor(key: string) { - super(); - this.key = key; - } -} diff --git a/src/api/consumer/lib/exceptions/id-exported-already.ts b/src/api/consumer/lib/exceptions/id-exported-already.ts deleted file mode 100644 index 601e0bb8e25d..000000000000 --- a/src/api/consumer/lib/exceptions/id-exported-already.ts +++ /dev/null @@ -1,12 +0,0 @@ -import AbstractError from '../../../../error/abstract-error'; - -export default class IdExportedAlready extends AbstractError { - id: string; - remote: string; - - constructor(id: string, remote: string) { - super(); - this.id = id; - this.remote = remote; - } -} diff --git a/src/api/consumer/lib/exceptions/invalid-version.ts b/src/api/consumer/lib/exceptions/invalid-version.ts deleted file mode 100644 index f62f69054975..000000000000 --- a/src/api/consumer/lib/exceptions/invalid-version.ts +++ /dev/null @@ -1,10 +0,0 @@ -import AbstractError from '../../../../error/abstract-error'; - -export default class InvalidVersion extends AbstractError { - version: string; - - constructor(version: string) { - super(); - this.version = version; - } -} diff --git a/src/api/consumer/lib/tag.ts b/src/api/consumer/lib/tag.ts deleted file mode 100644 index 9d108cf53413..000000000000 --- a/src/api/consumer/lib/tag.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const NOTHING_TO_TAG_MSG = 'nothing to tag'; -export const AUTO_TAGGED_MSG = 'auto-tagged dependents'; diff --git a/src/cli/chalk-box.ts b/src/cli/chalk-box.ts deleted file mode 100644 index 9c6b6905d2a8..000000000000 --- a/src/cli/chalk-box.ts +++ /dev/null @@ -1,13 +0,0 @@ -import c from 'chalk'; - -export const formatPlainComponentItem = ({ scope, name, version, deprecated }: any) => - c.cyan( - `- ${scope ? `${scope}/` : ''}${name}@${version ? version.toString() : 'latest'} ${ - deprecated ? c.yellow('[deprecated]') : '' - }` - ); - -export const paintHeader = (value: string) => { - if (!value) return ''; - return `${c.underline(value)}\n`; -}; diff --git a/src/cli/commands/exceptions/remote-undefined.ts b/src/cli/commands/exceptions/remote-undefined.ts deleted file mode 100644 index c6270f20669c..000000000000 --- a/src/cli/commands/exceptions/remote-undefined.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class RemoteUndefined extends AbstractError {} diff --git a/src/cli/commands/public-cmds/init-cmd.ts b/src/cli/commands/public-cmds/init-cmd.ts index 5f2340687483..89edb2f0e674 100644 --- a/src/cli/commands/public-cmds/init-cmd.ts +++ b/src/cli/commands/public-cmds/init-cmd.ts @@ -50,7 +50,6 @@ export default class Init implements LegacyCommand { 'set the default directory pattern to import/create components into', ], ['', 'default-scope ', 'set the default scope for components in the workspace'], - ['p', 'package-manager ', 'set the package manager (npm or yarn) to be used in the workspace'], ['f', 'force', 'force workspace initialization without clearing local objects'], ] as CommandOptions; @@ -68,7 +67,6 @@ export default class Init implements LegacyCommand { force, defaultDirectory, defaultScope, - packageManager, } = flags; if (path) path = pathlib.resolve(path); if (bare) { @@ -88,7 +86,6 @@ export default class Init implements LegacyCommand { const workspaceConfigFileProps: WorkspaceConfigProps = { componentsDefaultDirectory: defaultDirectory ?? getSync(CFG_INIT_DEFAULT_DIRECTORY), defaultScope: defaultScope ?? getSync(CFG_INIT_DEFAULT_SCOPE), - packageManager, }; return init( path, diff --git a/src/cli/commands/public-cmds/remote-cmd.ts b/src/cli/commands/public-cmds/remote-cmd.ts index 66361e55055f..2f3ce701530e 100644 --- a/src/cli/commands/public-cmds/remote-cmd.ts +++ b/src/cli/commands/public-cmds/remote-cmd.ts @@ -7,7 +7,6 @@ import { forEach, isEmpty } from 'lodash'; import { remoteAdd, remoteList, remoteRm } from '../../../api/consumer'; import { Group } from '../../command-groups'; import { CommandOptions, LegacyCommand } from '../../legacy-command'; -import RemoteUndefined from '../exceptions/remote-undefined'; class RemoteAdd implements LegacyCommand { name = 'add '; @@ -18,12 +17,7 @@ for example: "http://localhost:3000", "file:///tmp/local-scope"`; opts = [['g', 'global', 'configure a remote bit scope']] as CommandOptions; action([url]: [string], { global }: { global: boolean }): Promise { - try { - if (!url) return Promise.reject(new RemoteUndefined()); - return remoteAdd(url, global); - } catch (err: any) { - return Promise.reject(err); - } + return remoteAdd(url, global); } report({ name, host }: { name: string; host: string }): string { diff --git a/src/cli/default-error-handler.ts b/src/cli/default-error-handler.ts index b7ba553f1f81..ead77000aac6 100644 --- a/src/cli/default-error-handler.ts +++ b/src/cli/default-error-handler.ts @@ -3,14 +3,12 @@ import chalk from 'chalk'; import { BitError } from '@teambit/bit-error'; import { Analytics, LEVEL } from '../analytics/analytics'; -import ConfigKeyNotFound from '../api/consumer/lib/exceptions/config-key-not-found'; import DiagnosisNotFound from '../api/consumer/lib/exceptions/diagnosis-not-found'; -import IdExportedAlready from '../api/consumer/lib/exceptions/id-exported-already'; import MissingDiagnosisName from '../api/consumer/lib/exceptions/missing-diagnosis-name'; import NoIdMatchWildcard from '../api/consumer/lib/exceptions/no-id-match-wildcard'; import NothingToCompareTo from '../api/consumer/lib/exceptions/nothing-to-compare-to'; import ObjectsWithoutConsumer from '../api/consumer/lib/exceptions/objects-without-consumer'; -import { BASE_DOCS_DOMAIN, BASE_LEGACY_DOCS_DOMAIN } from '../constants'; +import { BASE_DOCS_DOMAIN } from '../constants'; import { InvalidBitMap, MissingMainFile } from '../consumer/bit-map/exceptions'; import OutsideRootDir from '../consumer/bit-map/exceptions/outside-root-dir'; import { @@ -25,56 +23,33 @@ import { } from '../consumer/component-ops/add-components/exceptions'; import { AddingIndividualFiles } from '../consumer/component-ops/add-components/exceptions/adding-individual-files'; import ComponentsPendingMerge from '../consumer/component-ops/exceptions/components-pending-merge'; -import EjectNoDir from '../consumer/component-ops/exceptions/eject-no-dir'; import ComponentNotFoundInPath from '../consumer/component/exceptions/component-not-found-in-path'; -import ExternalBuildErrors from '../consumer/component/exceptions/external-build-errors'; -import ExternalTestErrors from '../consumer/component/exceptions/external-test-errors'; import FileSourceNotFound from '../consumer/component/exceptions/file-source-not-found'; -import InjectNonEjected from '../consumer/component/exceptions/inject-non-ejected'; import MainFileRemoved from '../consumer/component/exceptions/main-file-removed'; -import MissingFilesFromComponent from '../consumer/component/exceptions/missing-files-from-component'; -import { NoComponentDir } from '../consumer/component/exceptions/no-component-dir'; import InvalidPackageJson from '../consumer/config/exceptions/invalid-package-json'; import InvalidPackageManager from '../consumer/config/exceptions/invalid-package-manager'; -import { - ComponentOutOfSync, - ConsumerAlreadyExists, - ConsumerNotFound, - LoginFailed, - NewerVersionFound, - NothingToImport, -} from '../consumer/exceptions'; -import { LanesIsDisabled } from '../consumer/lanes/exceptions/lanes-is-disabled'; -import { PathToNpmrcNotExist, WriteToNpmrcError } from '../consumer/login/exceptions'; +import { ComponentOutOfSync, ConsumerNotFound, NewerVersionFound } from '../consumer/exceptions'; import hashErrorIfNeeded from '../error/hash-error-object'; import ValidationError from '../error/validation-error'; import PromptCanceled from '../prompts/exceptions/prompt-canceled'; import RemoteNotFound from '../remotes/exceptions/remote-not-found'; import { ComponentNotFound, - CorruptedComponent, - CyclicDependencies, - HashMismatch, HashNotFound, InvalidIndexJson, OutdatedIndexJson, ParentNotFound, - ResolutionException, ScopeJsonNotFound, ScopeNotFound, VersionAlreadyExists, } from '../scope/exceptions'; import { - AuthenticationFailed, NetworkError, ProtocolNotSupported, RemoteScopeNotFound, UnexpectedNetworkError, } from '../scope/network/exceptions'; -import ExportAnotherOwnerPrivate from '../scope/network/exceptions/export-another-owner-private'; -import RemoteResolverError from '../scope/network/exceptions/remote-resolver-error'; import GitNotFound from '../utils/git/exceptions/git-not-found'; -import RemoteUndefined from './commands/exceptions/remote-undefined'; import newerVersionTemplate from './templates/newer-version-template'; import GeneralError from '../error/general-error'; @@ -83,21 +58,11 @@ const reportIssueToGithubMsg = // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! const errorsMap: Array<[Class, (err: Class) => string]> = [ - [ - RemoteUndefined, - () => - chalk.red( - 'error: remote url must be defined. please use: `file://` or `http(s)://` protocols to define remote access' - ), - ], - [ConsumerAlreadyExists, () => 'workspace already exists'], [GeneralError, (err) => `${err.msg}`], [VersionAlreadyExists, (err) => `error: version ${err.version} already exists for ${err.componentId}`], [ConsumerNotFound, () => 'workspace not found. to initiate a new workspace, please use `bit init`'], - [LoginFailed, () => 'error: there was a problem with web authentication'], [FileSourceNotFound, (err) => `file or directory "${err.path}" was not found`], - [LanesIsDisabled, () => `lanes/snaps features are disabled. upgrade your workspace to Harmony to enable them`], [ OutsideRootDir, (err) => `unable to add file ${err.filePath} because it's located outside the component root dir ${err.rootDir}`, @@ -111,7 +76,6 @@ const errorsMap: Array<[Class, (err: Class) => string]> = [ () => 'error: remote scope protocol is not supported, please use: `file://`, `http://`, `https://`', ], [RemoteScopeNotFound, (err) => `error: remote scope "${chalk.bold(err.name)}" was not found.`], - [InjectNonEjected, () => 'error: could not inject config for already injected component'], // TODO: improve error [ ComponentsPendingMerge, @@ -127,11 +91,6 @@ const errorsMap: Array<[Class, (err: Class) => string]> = [ return `the local and remote history of the following component(s) have diverged\n${componentsStr}\nPlease use --merge to merge them`; }, ], - [ - EjectNoDir, - (err) => - `error: could not eject config for ${chalk.bold(err.compId)}, please make sure it's under a track directory`, - ], [ ComponentNotFound, (err) => { @@ -142,48 +101,20 @@ const errorsMap: Array<[Class, (err: Class) => string]> = [ : `error: component "${chalk.bold(err.id)}" was not found`; }, ], - [ - CorruptedComponent, - (err) => - `error: the model representation of "${chalk.bold(err.id)}" is corrupted, the object of version ${ - err.version - } is missing.\n${reportIssueToGithubMsg}`, - ], [ValidationError, (err) => `${err.message}\n${reportIssueToGithubMsg}`], [ComponentNotFoundInPath, (err) => `error: component in path "${chalk.bold(err.path)}" was not found`], [RemoteNotFound, (err) => `error: remote "${chalk.bold(err.name)}" was not found`], [NetworkError, (err) => `error: remote failed with error the following error:\n "${chalk.bold(err.remoteErr)}"`], - [ - HashMismatch, - (err) => `found hash mismatch of ${chalk.bold(err.id)}, version ${chalk.bold(err.version)}. - originalHash: ${chalk.bold(err.originalHash)}. - currentHash: ${chalk.bold(err.currentHash)} - this usually happens when a component is old and the migration script was not running or interrupted`, - ], [HashNotFound, (err) => `hash ${chalk.bold(err.hash)} not found`], [ OutdatedIndexJson, (err) => `error: ${chalk.bold(err.id)} found in the index.json file, however, is missing from the scope. the cache is deleted and will be rebuilt on the next command. please re-run the command.`, ], - [CyclicDependencies, (err) => `${err.msg.toString().toLocaleLowerCase()}`], [ UnexpectedNetworkError, (err) => `unexpected network error has occurred. ${err.message ? `server responded with: "${err.message}"` : ''}`, - ], - [ - RemoteResolverError, - (err) => `error: ${err.message ? `${err.message}` : 'unexpected remote resolver error has occurred'}`, - ], - [ - ExportAnotherOwnerPrivate, - ( - err - ) => `error: unable to export components to ${err.destinationScope} because they have dependencies on components in ${err.sourceScope}. -bit does not allow setting dependencies between components in private collections managed by different owners. - -see troubleshooting at ${BASE_DOCS_DOMAIN}docs/bit-dev#permissions-for-collections`, ], [ InvalidIndexJson, @@ -208,7 +139,6 @@ if it is originated from another git branch, go back to that branch to continue if possible, remove the component using "bit remove" and re-import or re-create it. to re-start Bit from scratch, deleting all objects from the scope, use "bit init --reset-hard"`, ], - [NothingToImport, () => chalk.yellow('nothing to import. please use `bit import [component_id]`')], [ InvalidPackageManager, (err) => `error: the package manager provided ${chalk.bold(err.packageManager)} is not a valid package manager. @@ -226,11 +156,6 @@ please fix the file in order to run bit commands`, err.componentId )} does not contain a main file.\nplease either use --id to group all added files as one component or use our DSL to define the main file dynamically.\nsee troubleshooting at ${BASE_DOCS_DOMAIN}components/component-main-file`, ], - [ - NoComponentDir, - (err) => `"${err.id}" doesn't have a component directory, which is invalid. -please run "bit status" to get more info.\nLearn more at https:/BASE_DOCS_DOMAIN/reference/workspace/component-directory`, - ], [ MissingMainFileMultipleComponents, (err) => @@ -263,20 +188,11 @@ please use "bit remove" to delete the component or "bit add" with "--main" and " err.mainFile )} is a directory, please specify a file or a pattern DSL`, ], - [ - MissingFilesFromComponent, - (err) => { - return `component ${err.id} is invalid as part or all of the component files were deleted. please use 'bit remove' to resolve the issue`; - }, - ], [PathsNotExist, (err) => `error: file or directory "${chalk.bold(err.paths.join(', '))}" was not found.`], [ PathOutsideConsumer, (err) => `error: file or directory "${chalk.bold(err.path)}" is located outside of the workspace.`, ], - [ConfigKeyNotFound, (err) => `unable to find a key "${chalk.bold(err.key)}" in your bit config`], - [WriteToNpmrcError, (err) => `unable to add @bit as a scoped registry at "${chalk.bold(err.path)}"`], - [PathToNpmrcNotExist, (err) => `error: file or directory "${chalk.bold(err.path)}" was not found.`], [ ParentNotFound, (err) => @@ -301,11 +217,6 @@ please use "bit remove" to delete the component or "bit add" with "--main" and " }) .join(' '), ], - - [ - IdExportedAlready, - (err) => `component ${chalk.bold(err.id)} has been already exported to ${chalk.bold(err.remote)}`, - ], [ NoIdMatchWildcard, (err) => `unable to find component ids that match the following: ${err.idsWithWildcards.join(', ')}`, @@ -317,37 +228,11 @@ please use "bit remove" to delete the component or "bit add" with "--main" and " (err) => newerVersionTemplate(err.newerVersions), ], [PromptCanceled, () => chalk.yellow('operation aborted')], - [ - ExternalTestErrors, - (err) => - `error: bit failed to test ${err.id} with the following exception:\n${getExternalErrorsMessageAndStack( - err.originalErrors - )}`, - ], - [ - ExternalBuildErrors, - (err) => - `error: bit failed to build ${err.id} with the following exception:\n${getExternalErrorsMessageAndStack( - err.originalErrors - )}`, - ], - [ - ResolutionException, - (err) => - `error: bit failed to require ${err.filePath} due to the following exception:\n${getExternalErrorMessage( - err.originalError - )}.\n${err.originalError.stack}`, - ], [ GitNotFound, () => "error: unable to run command because git executable not found. please ensure git is installed and/or git_path is configured using the 'bit config set git_path '", ], - [ - AuthenticationFailed, - (err) => - `authentication failed. see troubleshooting at https://${BASE_LEGACY_DOCS_DOMAIN}/setup-authentication#autentication-issues.html\n\n${err.debugInfo}`, - ], [ ObjectsWithoutConsumer, (err) => `error: unable to initialize a bit workspace. bit has found undeleted local objects at ${chalk.bold( @@ -384,34 +269,6 @@ run 'bit doctor' to get detailed workspace diagnosis and issue resolution.`; return errorMessage; } -function getExternalErrorMessage(externalError: Error | null | undefined): string { - if (!externalError) return ''; - - // In case an error is not a real error - if (!(externalError instanceof Error)) { - return externalError; - } - // In case it's not a bit error - if (externalError.message) { - return externalError.message; - } - const errorDefinition = findErrorDefinition(externalError); - const func = getErrorFunc(errorDefinition); - const errorMessage = getErrorMessage(externalError, func); - return errorMessage; -} - -function getExternalErrorsMessageAndStack(errors: Error[]): string { - const result = errors - .map((e) => { - const msg = getExternalErrorMessage(e); - const stack = e.stack || ''; - return `${msg}\n${stack}\n`; - }) - .join('~~~~~~~~~~~~~\n'); - return result; -} - /** * if err.userError is set, it inherits from AbstractError, which are user errors not Bit errors * and should not be reported to Sentry. diff --git a/src/cli/templates/component-issues-template.ts b/src/cli/templates/component-issues-template.ts index 0cf37b1662ed..08c9f98f76f1 100644 --- a/src/cli/templates/component-issues-template.ts +++ b/src/cli/templates/component-issues-template.ts @@ -7,7 +7,6 @@ export function getInvalidComponentLabel(error: Error) { switch (error.name) { case 'MainFileRemoved': return 'main-file was removed (use "bit add" with "--main" and "--id" flags to add a main file)'; - case 'MissingFilesFromComponent': case 'ComponentNotFoundInPath': return 'component files were deleted (use "bit remove [component_id]") or moved (use "bit move "). to restore use "bit checkout reset [component_id]"'; case 'ExtensionFileNotFound': diff --git a/src/cli/templates/docs-template.ts b/src/cli/templates/docs-template.ts index f9f942834335..9832395ae164 100644 --- a/src/cli/templates/docs-template.ts +++ b/src/cli/templates/docs-template.ts @@ -3,12 +3,16 @@ import R from 'ramda'; import Table from 'cli-table'; import { Doclet } from '../../jsdoc/types'; -import { paintHeader } from '../chalk-box'; const paintExample = (example) => { return example.raw; }; +const paintHeader = (value: string) => { + if (!value) return ''; + return `${c.underline(value)}\n`; +}; + const paintExamples = (examples) => { if (R.isEmpty(examples) || R.isNil(examples)) { return ''; diff --git a/src/consumer/bit-map/exceptions/index.ts b/src/consumer/bit-map/exceptions/index.ts index 52dd90cc4a03..0a56156afdf0 100644 --- a/src/consumer/bit-map/exceptions/index.ts +++ b/src/consumer/bit-map/exceptions/index.ts @@ -1,6 +1,5 @@ import InvalidBitMap from './invalid-bit-map'; import MissingBitMapComponent from './missing-bit-map-component'; import MissingMainFile from './missing-main-file'; -import MultipleMatches from './multiple-matches'; -export { InvalidBitMap, MissingBitMapComponent, MissingMainFile, MultipleMatches }; +export { InvalidBitMap, MissingBitMapComponent, MissingMainFile }; diff --git a/src/consumer/bit-map/exceptions/multiple-matches.ts b/src/consumer/bit-map/exceptions/multiple-matches.ts deleted file mode 100644 index f590312c388c..000000000000 --- a/src/consumer/bit-map/exceptions/multiple-matches.ts +++ /dev/null @@ -1,10 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class MultipleMatches extends AbstractError { - id: string; - - constructor(id: string) { - super(); - this.id = id; - } -} diff --git a/src/consumer/component-ops/exceptions/eject-no-dir.ts b/src/consumer/component-ops/exceptions/eject-no-dir.ts deleted file mode 100644 index b9f3201a45b2..000000000000 --- a/src/consumer/component-ops/exceptions/eject-no-dir.ts +++ /dev/null @@ -1,10 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class EjectNoDir extends AbstractError { - compId: string; - - constructor(compId: string) { - super(); - this.compId = compId; - } -} diff --git a/src/consumer/component/consumer-component.ts b/src/consumer/component/consumer-component.ts index 154c390d500b..473b5ead3c3e 100644 --- a/src/consumer/component/consumer-component.ts +++ b/src/consumer/component/consumer-component.ts @@ -28,8 +28,6 @@ import { CURRENT_SCHEMA, isSchemaSupport, SchemaFeature, SchemaName } from './co import { Dependencies, Dependency } from './dependencies'; import ComponentNotFoundInPath from './exceptions/component-not-found-in-path'; import MainFileRemoved from './exceptions/main-file-removed'; -import MissingFilesFromComponent from './exceptions/missing-files-from-component'; -import { NoComponentDir } from './exceptions/no-component-dir'; import PackageJsonFile from './package-json-file'; import DataToPersist from './sources/data-to-persist'; import { ModelComponent } from '../../scope/models'; @@ -423,11 +421,9 @@ export default class Component { static isComponentInvalidByErrorType(err: Error): boolean { const invalidComponentErrors = [ MainFileRemoved, - MissingFilesFromComponent, ComponentNotFoundInPath, ComponentOutOfSync, ComponentsPendingImport, - NoComponentDir, IgnoredDirectory, ]; return invalidComponentErrors.some((errorType) => err instanceof errorType); @@ -490,13 +486,6 @@ export default class Component { const object = JSON.parse(str); object.files = SourceFile.loadFromParsedStringArray(object.files); - // added if statement to support new and old version of remote ls - // old version of bit returns from server array of dists and new version return object - if (object.dists && Array.isArray(object.dists)) { - object.dists = Dist.loadFromParsedStringArray(object.dists); - } else if (object.dists && object.dists.dists) { - object.dists = Dist.loadFromParsedStringArray(object.dists.dists); - } return this.fromObject(object); } diff --git a/src/consumer/component/exceptions/bit-already-exist-externaly.ts b/src/consumer/component/exceptions/bit-already-exist-externaly.ts deleted file mode 100644 index d929ae0942e7..000000000000 --- a/src/consumer/component/exceptions/bit-already-exist-externaly.ts +++ /dev/null @@ -1,10 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class BitAlreadyExistExternalyError extends AbstractError { - bitName: string; - - constructor(bitName: string) { - super(); - this.bitName = bitName; - } -} diff --git a/src/consumer/component/exceptions/external-build-errors.ts b/src/consumer/component/exceptions/external-build-errors.ts deleted file mode 100644 index e482026d736c..000000000000 --- a/src/consumer/component/exceptions/external-build-errors.ts +++ /dev/null @@ -1,10 +0,0 @@ -import ExternalErrors from '../../../error/external-errors'; - -export default class ExternalBuildErrors extends ExternalErrors { - id: string; - - constructor(id: string, errors: Error[]) { - super(errors); - this.id = id; - } -} diff --git a/src/consumer/component/exceptions/external-test-errors.ts b/src/consumer/component/exceptions/external-test-errors.ts deleted file mode 100644 index 604880b931ee..000000000000 --- a/src/consumer/component/exceptions/external-test-errors.ts +++ /dev/null @@ -1,9 +0,0 @@ -import ExternalErrors from '../../../error/external-errors'; - -export default class ExternalTestErrors extends ExternalErrors { - id: string; - constructor(id: string, errors: Error[]) { - super(errors); - this.id = id; - } -} diff --git a/src/consumer/component/exceptions/inject-non-ejected.ts b/src/consumer/component/exceptions/inject-non-ejected.ts deleted file mode 100644 index 7dbeae034374..000000000000 --- a/src/consumer/component/exceptions/inject-non-ejected.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class InjectNonEjected extends AbstractError {} diff --git a/src/consumer/component/exceptions/invalid-bit.ts b/src/consumer/component/exceptions/invalid-bit.ts deleted file mode 100644 index 30f4bb7acb1d..000000000000 --- a/src/consumer/component/exceptions/invalid-bit.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class InvalidBit extends AbstractError {} diff --git a/src/consumer/component/exceptions/missing-files-from-component.ts b/src/consumer/component/exceptions/missing-files-from-component.ts deleted file mode 100644 index 4caacef4cd37..000000000000 --- a/src/consumer/component/exceptions/missing-files-from-component.ts +++ /dev/null @@ -1,10 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class MissingFilesFromComponent extends AbstractError { - id: string; - - constructor(id: string) { - super(); - this.id = id; - } -} diff --git a/src/consumer/component/exceptions/no-component-dir.ts b/src/consumer/component/exceptions/no-component-dir.ts deleted file mode 100644 index 99b29e5d84b8..000000000000 --- a/src/consumer/component/exceptions/no-component-dir.ts +++ /dev/null @@ -1,9 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export class NoComponentDir extends AbstractError { - id: string; - constructor(id: string) { - super(); - this.id = id; - } -} diff --git a/src/consumer/component/sources/dist.ts b/src/consumer/component/sources/dist.ts index 2a1fb22e3e3c..5b445a831596 100644 --- a/src/consumer/component/sources/dist.ts +++ b/src/consumer/component/sources/dist.ts @@ -1,18 +1,6 @@ import AbstractVinyl from './abstract-vinyl'; export default class Dist extends AbstractVinyl { - static loadFromParsedString(parsedString: Record): Dist | null { - if (!parsedString) return null; - const opts = super.loadFromParsedStringBase(parsedString); - return new Dist(opts); - } - - static loadFromParsedStringArray(arr: Record[]): Dist[] | null | undefined { - if (!arr) return null; - // @ts-ignore - return arr.map(this.loadFromParsedString); - } - // eslint-disable-next-line @typescript-eslint/no-unused-vars clone(opts?: { contents?: boolean; deep?: boolean } | boolean): this { // @ts-ignore diff --git a/src/consumer/config/exceptions/bit-config-not-found.ts b/src/consumer/config/exceptions/bit-config-not-found.ts deleted file mode 100644 index 5112a1b56f68..000000000000 --- a/src/consumer/config/exceptions/bit-config-not-found.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class BitConfigNotFound extends AbstractError {} diff --git a/src/consumer/config/exceptions/index.ts b/src/consumer/config/exceptions/index.ts index f9c5ee5204d5..a0896850352c 100644 --- a/src/consumer/config/exceptions/index.ts +++ b/src/consumer/config/exceptions/index.ts @@ -1,4 +1,3 @@ -import BitConfigNotFound from './bit-config-not-found'; import InvalidPackageJson from './invalid-package-json'; -export { BitConfigNotFound, InvalidPackageJson }; +export { InvalidPackageJson }; diff --git a/src/consumer/exceptions/consumer-already-exists.ts b/src/consumer/exceptions/consumer-already-exists.ts deleted file mode 100644 index cabeeddf34e7..000000000000 --- a/src/consumer/exceptions/consumer-already-exists.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class ConsumerAlreadyExists extends AbstractError {} diff --git a/src/consumer/exceptions/index.ts b/src/consumer/exceptions/index.ts index 7048e1156e43..28b40c2516bb 100644 --- a/src/consumer/exceptions/index.ts +++ b/src/consumer/exceptions/index.ts @@ -1,8 +1,5 @@ import ComponentOutOfSync from './component-out-of-sync'; -import ConsumerAlreadyExists from './consumer-already-exists'; import ConsumerNotFound from './consumer-not-found'; -import LoginFailed from './login-failed'; import NewerVersionFound from './newer-version-found'; -import NothingToImport from './nothing-to-import'; -export { ConsumerNotFound, ConsumerAlreadyExists, NothingToImport, NewerVersionFound, LoginFailed, ComponentOutOfSync }; +export { ConsumerNotFound, NewerVersionFound, ComponentOutOfSync }; diff --git a/src/consumer/exceptions/login-failed.ts b/src/consumer/exceptions/login-failed.ts deleted file mode 100644 index 4ccd20fbe10d..000000000000 --- a/src/consumer/exceptions/login-failed.ts +++ /dev/null @@ -1,10 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class LoginFailed extends AbstractError { - showDoctorMessage: boolean; - - constructor() { - super(); - this.showDoctorMessage = true; - } -} diff --git a/src/consumer/exceptions/nothing-to-import.ts b/src/consumer/exceptions/nothing-to-import.ts deleted file mode 100644 index ab638a37640d..000000000000 --- a/src/consumer/exceptions/nothing-to-import.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class NothingToImport extends AbstractError {} diff --git a/src/consumer/lanes/exceptions/lanes-is-disabled.ts b/src/consumer/lanes/exceptions/lanes-is-disabled.ts deleted file mode 100644 index f5df8cefe392..000000000000 --- a/src/consumer/lanes/exceptions/lanes-is-disabled.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export class LanesIsDisabled extends AbstractError {} diff --git a/src/consumer/login/exceptions/index.ts b/src/consumer/login/exceptions/index.ts deleted file mode 100644 index 818062986442..000000000000 --- a/src/consumer/login/exceptions/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import PathToNpmrcNotExist from './path-to-npmrc-not-exist'; -import WriteToNpmrcError from './write-to-npmrc-error'; - -export { PathToNpmrcNotExist, WriteToNpmrcError }; diff --git a/src/consumer/login/exceptions/path-to-npmrc-not-exist.ts b/src/consumer/login/exceptions/path-to-npmrc-not-exist.ts deleted file mode 100644 index 59724d43e644..000000000000 --- a/src/consumer/login/exceptions/path-to-npmrc-not-exist.ts +++ /dev/null @@ -1,12 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class PathToNpmrcNotExist extends AbstractError { - path: string; - showDoctorMessage: boolean; - - constructor(path: string) { - super(); - this.path = path; - this.showDoctorMessage = true; - } -} diff --git a/src/consumer/login/exceptions/write-to-npmrc-error.ts b/src/consumer/login/exceptions/write-to-npmrc-error.ts deleted file mode 100644 index 42a909646437..000000000000 --- a/src/consumer/login/exceptions/write-to-npmrc-error.ts +++ /dev/null @@ -1,12 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class WriteToNpmrcError extends AbstractError { - path: string; - showDoctorMessage: boolean; - - constructor(path: string) { - super(); - this.path = path; - this.showDoctorMessage = true; - } -} diff --git a/src/e2e-helper/e2e-command-helper.ts b/src/e2e-helper/e2e-command-helper.ts index 30a3b4c22296..8e4dcc0d3c2d 100644 --- a/src/e2e-helper/e2e-command-helper.ts +++ b/src/e2e-helper/e2e-command-helper.ts @@ -7,8 +7,8 @@ import rightpad from 'pad-right'; import * as path from 'path'; import tar from 'tar'; import { LANE_REMOTE_DELIMITER } from '@teambit/lane-id'; +import { NOTHING_TO_TAG_MSG } from '@teambit/snapping'; import { ENV_VAR_FEATURE_TOGGLE } from '../api/consumer/lib/feature-toggle'; -import { NOTHING_TO_TAG_MSG } from '../api/consumer/lib/tag'; import { Extensions, NOTHING_TO_SNAP_MSG } from '../constants'; import { removeChalkCharacters } from '../utils'; import ScopesData from './e2e-scopes'; diff --git a/src/error/external-errors.ts b/src/error/external-errors.ts deleted file mode 100644 index cdba452ccf00..000000000000 --- a/src/error/external-errors.ts +++ /dev/null @@ -1,12 +0,0 @@ -import AbstractError from './abstract-error'; - -/** - * A class to represent multiple external errors - */ -export default class ExternalErrors extends AbstractError { - originalErrors: Error[]; - constructor(originalErrors: Error[]) { - super(); - this.originalErrors = originalErrors; - } -} diff --git a/src/prompts/index.ts b/src/prompts/index.ts index e224fbaffb33..335be9438099 100644 --- a/src/prompts/index.ts +++ b/src/prompts/index.ts @@ -1,14 +1,12 @@ import prompt from './prompt'; import analyticsSchema from './schemas/analytics-reporting'; import errorReportingSchema from './schemas/error-reporting'; -import removeSchema from './schemas/remote-remove'; import resolveConflictSchema from './schemas/resolve-conflict'; import approveOperationSchema from './schemas/approve-operation'; const approveOperation = prompt(approveOperationSchema); -const removePrompt = (deleteFiles: boolean, remote: boolean) => prompt(removeSchema(deleteFiles, remote)); const resolveConflictPrompt = prompt(resolveConflictSchema); const analyticsPrompt = prompt(analyticsSchema); const errorReportingPrompt = prompt(errorReportingSchema); -export { approveOperation, removePrompt, resolveConflictPrompt, analyticsPrompt, errorReportingPrompt }; +export { approveOperation, resolveConflictPrompt, analyticsPrompt, errorReportingPrompt }; diff --git a/src/prompts/schemas/remote-remove.ts b/src/prompts/schemas/remote-remove.ts deleted file mode 100644 index cd140914ecb5..000000000000 --- a/src/prompts/schemas/remote-remove.ts +++ /dev/null @@ -1,30 +0,0 @@ -/** - * schema for remote remove. - */ -export default function (deleteFiles: boolean, remote: boolean) { - const filesDeletionStr = deleteFiles - ? ' and the files will be deleted from the filesystem (can be avoided by entering --keep-files)' - : ''; - const remoteOrLocalOutput = remote - ? `the component(s) will be permanently deleted from the remote. prefer using --delete to only mark the component as deleted` - : `the component(s) will be untracked${filesDeletionStr}`; - return { - properties: { - shouldRemove: { - required: true, - description: `${remoteOrLocalOutput}. -are you sure you would like to proceed with this operation? (yes[y]/no[n])`, - message: 'please type yes or no.', - type: 'string', - conform(value: string) { - return ( - value.toLowerCase() === 'y' || - value.toLowerCase() === 'n' || - value.toLowerCase() === 'yes' || - value.toLowerCase() === 'no' - ); - }, - }, - }, - }; -} diff --git a/src/remotes/exceptions/index.ts b/src/remotes/exceptions/index.ts index 4f4eb3a5bbdc..0b5f12277d51 100644 --- a/src/remotes/exceptions/index.ts +++ b/src/remotes/exceptions/index.ts @@ -1,7 +1,6 @@ import InvalidRemote from './invalid-remote'; -import PrimaryNotFound from './primary-not-found'; import PrimaryOverloaded from './primary-overloaded'; import RemoteNotFound from './remote-not-found'; import { ScopeNotFoundOrDenied } from './scope-not-found-or-denied'; -export { PrimaryNotFound, PrimaryOverloaded, InvalidRemote, RemoteNotFound, ScopeNotFoundOrDenied }; +export { PrimaryOverloaded, InvalidRemote, RemoteNotFound, ScopeNotFoundOrDenied }; diff --git a/src/remotes/exceptions/primary-not-found.ts b/src/remotes/exceptions/primary-not-found.ts deleted file mode 100644 index e9a3dbbf7303..000000000000 --- a/src/remotes/exceptions/primary-not-found.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class PrimaryNotFound extends AbstractError {} diff --git a/src/scope/comps-and-lanes-objects.ts b/src/scope/comps-and-lanes-objects.ts deleted file mode 100644 index fd42100338e0..000000000000 --- a/src/scope/comps-and-lanes-objects.ts +++ /dev/null @@ -1,68 +0,0 @@ -import R from 'ramda'; - -import ComponentObjects from './component-objects'; -import LaneObjects from './lane-objects'; -import { BitObject } from './objects'; -import { ObjectList } from './objects/object-list'; - -export default class CompsAndLanesObjects { - componentsObjects: ComponentObjects[]; - laneObjects: LaneObjects[]; - - constructor(componentsObjects: ComponentObjects[], laneObjects: LaneObjects[]) { - this.componentsObjects = componentsObjects; - this.laneObjects = laneObjects; - } - - toString() { - const components = this.componentsObjects.map((componentAndObject) => componentAndObject.toString()); - if (!this.laneObjects.length) { - // @todo: delete this `if` block before releasing v15 - // backward compatibility, before v15, it used to be an array of component-objects - // this makes sure that old clients could run "bit import" - return JSON.stringify(components); - } - return JSON.stringify({ - components, - lanes: this.laneObjects.map((laneObj) => laneObj.toString()), - }); - } - - toObjectList(): ObjectList { - const objectList = new ObjectList(); - this.componentsObjects.forEach((compObj) => { - const buffers = [compObj.component, ...compObj.objects]; - const objItems = buffers.map((buffer) => { - const obj = BitObject.parseSync(buffer); - return { ref: obj.hash(), buffer }; - }); - objectList.addIfNotExist(objItems); - }); - return objectList; - } - - static fromString(str: string) { - const parsed = JSON.parse(str); - let components; - let lanes = []; - if (Array.isArray(parsed)) { - // @todo: delete this `if` block before releasing v15 - // backward compatibility, before v15, it used to be an array of component-objects - // this makes sure that old clients could run "bit export" - components = parsed; - } else { - components = parsed.components; - lanes = parsed.lanes; - } - const componentsObjects = components.map((componentObject) => ComponentObjects.fromString(componentObject)); - const laneObjects = lanes.map((laneObj) => LaneObjects.fromString(laneObj)); - return new CompsAndLanesObjects(componentsObjects, laneObjects); - } - - static flatten(manyCompsAndLanesObjects: CompsAndLanesObjects[]): CompsAndLanesObjects { - return new CompsAndLanesObjects( - R.flatten(manyCompsAndLanesObjects.map((m) => m.componentsObjects)), - R.flatten(manyCompsAndLanesObjects.map((m) => m.laneObjects)) - ); - } -} diff --git a/src/scope/exceptions/bit-not-in-scope.ts b/src/scope/exceptions/bit-not-in-scope.ts deleted file mode 100644 index a97937e88d15..000000000000 --- a/src/scope/exceptions/bit-not-in-scope.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class BitNotInScope extends AbstractError {} diff --git a/src/scope/exceptions/corrupted-component.ts b/src/scope/exceptions/corrupted-component.ts deleted file mode 100644 index 9fa88c616178..000000000000 --- a/src/scope/exceptions/corrupted-component.ts +++ /dev/null @@ -1,14 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class CorruptedComponent extends AbstractError { - id: string; - version: string; - showDoctorMessage: boolean; - - constructor(id: string, version: string) { - super(); - this.id = id; - this.version = version; - this.showDoctorMessage = true; - } -} diff --git a/src/scope/exceptions/cyclic-dependencie.ts b/src/scope/exceptions/cyclic-dependencie.ts deleted file mode 100644 index 0ca420d4bc0c..000000000000 --- a/src/scope/exceptions/cyclic-dependencie.ts +++ /dev/null @@ -1,9 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class CyclicDependencies extends AbstractError { - msg: string; - constructor(msg: string) { - super(); - this.msg = msg; - } -} diff --git a/src/scope/exceptions/hash-mismatch.ts b/src/scope/exceptions/hash-mismatch.ts deleted file mode 100644 index 1f3277bf0dc4..000000000000 --- a/src/scope/exceptions/hash-mismatch.ts +++ /dev/null @@ -1,18 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class HashMismatch extends AbstractError { - id: string; - version: string; - originalHash: string; - currentHash: string; - showDoctorMessage: boolean; - - constructor(id: string, version: string, originalHash: string, currentHash: string) { - super(); - this.id = id; - this.version = version; - this.originalHash = originalHash; - this.currentHash = currentHash; - this.showDoctorMessage = true; - } -} diff --git a/src/scope/exceptions/index.ts b/src/scope/exceptions/index.ts index 01e75effa509..3d599a75b9d6 100644 --- a/src/scope/exceptions/index.ts +++ b/src/scope/exceptions/index.ts @@ -1,8 +1,4 @@ -import BitNotInScope from './bit-not-in-scope'; import ComponentNotFound from './component-not-found'; -import CorruptedComponent from './corrupted-component'; -import CyclicDependencies from './cyclic-dependencie'; -import HashMismatch from './hash-mismatch'; import HashNotFound from './hash-not-found'; import HeadNotFound from './head-not-found'; import InvalidIndexJson from './invalid-index-json'; @@ -10,11 +6,8 @@ import MergeConflict from './merge-conflict'; import MergeConflictOnRemote from './merge-conflict-on-remote'; import OutdatedIndexJson from './outdated-index-json'; import ParentNotFound from './parent-not-found'; -import ResolutionException from './resolution-exception'; -import ScopeAlreadyExists from './scope-already-exists'; import ScopeJsonNotFound from './scope-json-not-found'; import ScopeNotFound from './scope-not-found'; -import SourceNotFound from './source-not-found'; import VersionAlreadyExists from './version-already-exists'; import VersionNotFound from './version-not-found'; import { VersionNotFoundOnFS } from './version-not-found-on-fs'; @@ -23,19 +16,12 @@ export { ScopeNotFound, ScopeJsonNotFound, ComponentNotFound, - SourceNotFound, HashNotFound, MergeConflict, MergeConflictOnRemote, VersionNotFound, ParentNotFound, VersionAlreadyExists, - ScopeAlreadyExists, - BitNotInScope, - HashMismatch, - ResolutionException, - CorruptedComponent, - CyclicDependencies, InvalidIndexJson, OutdatedIndexJson, HeadNotFound, diff --git a/src/scope/exceptions/resolution-exception.ts b/src/scope/exceptions/resolution-exception.ts deleted file mode 100644 index be39137b9946..000000000000 --- a/src/scope/exceptions/resolution-exception.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ExternalError from '../../error/external-error'; - -export default class ResolutionException extends ExternalError { - filePath: string; - showDoctorMessage: boolean; - constructor(originalError: Error, filePath: string) { - super(originalError); - this.filePath = filePath; - this.showDoctorMessage = true; - } -} diff --git a/src/scope/exceptions/scope-already-exists.ts b/src/scope/exceptions/scope-already-exists.ts deleted file mode 100644 index 37aba2a6c929..000000000000 --- a/src/scope/exceptions/scope-already-exists.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class ScopeAlreadyExists extends AbstractError {} diff --git a/src/scope/exceptions/source-not-found.ts b/src/scope/exceptions/source-not-found.ts deleted file mode 100644 index b1163f76d3fd..000000000000 --- a/src/scope/exceptions/source-not-found.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AbstractError from '../../error/abstract-error'; - -export default class SourceNotFound extends AbstractError {} diff --git a/src/scope/flatten-dependencies.ts b/src/scope/flatten-dependencies.ts deleted file mode 100644 index ee08f06ca590..000000000000 --- a/src/scope/flatten-dependencies.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ComponentWithDependencies from './component-dependencies'; - -export function flattenDependencies(dependencies: ComponentWithDependencies[]) { - return Object.values( - dependencies - .map((dep) => dep.allDependencies.concat(dep.component)) - .flat() - .reduce((components, component) => { - components[component.id.toString()] = component; - return components; - }, {}) - ); -} diff --git a/src/scope/lane-objects.ts b/src/scope/lane-objects.ts deleted file mode 100644 index 59278354d87c..000000000000 --- a/src/scope/lane-objects.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { toBase64ArrayBuffer } from '../utils'; -import { Lane } from './models'; -import BitObject from './objects/object'; - -export default class LaneObjects { - lane: Buffer; - objects: Buffer[]; - - constructor(lane: Buffer, objects: Buffer[]) { - this.lane = lane; - this.objects = objects; - } - - toString(): string { - return JSON.stringify({ - lane: toBase64ArrayBuffer(this.lane), - objects: this.objects.map(toBase64ArrayBuffer), - }); - } - - static fromString(str: string): LaneObjects { - return LaneObjects.fromObject(JSON.parse(str)); - } - - static fromObject(object: Record): LaneObjects { - const { lane, objects } = object; - return new LaneObjects(_from64Buffer(lane), objects.map(_from64Buffer)); - } - - /** - * prefer using `this.toObjectsAsync()` if not must to be sync. - */ - toObjects(): { lane: Lane; objects: BitObject[] } { - return { - // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! - lane: BitObject.parseSync(this.lane), - objects: this.objects.map((obj) => BitObject.parseSync(obj)), - }; - } - /** - * see `this.toObject()` for the sync version - */ - async toObjectsAsync(): Promise<{ lane: Lane; objects: BitObject[] }> { - return { - // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX! - lane: await BitObject.parseObject(this.lane), - objects: await Promise.all(this.objects.map((obj) => BitObject.parseObject(obj))), - }; - } -} - -function _from64Buffer(val): Buffer { - return Buffer.from(val, 'base64'); -} diff --git a/src/scope/network/exceptions/authentication-failed.ts b/src/scope/network/exceptions/authentication-failed.ts deleted file mode 100644 index 9d27376ba377..000000000000 --- a/src/scope/network/exceptions/authentication-failed.ts +++ /dev/null @@ -1,12 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class AuthenticationFailed extends AbstractError { - debugInfo: string; - showDoctorMessage: boolean; - - constructor(debugInfo: string) { - super(); - this.debugInfo = debugInfo; - this.showDoctorMessage = true; - } -} diff --git a/src/scope/network/exceptions/export-another-owner-private.ts b/src/scope/network/exceptions/export-another-owner-private.ts deleted file mode 100644 index a7f57a9dab59..000000000000 --- a/src/scope/network/exceptions/export-another-owner-private.ts +++ /dev/null @@ -1,13 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class ExportAnotherOwnerPrivate extends AbstractError { - message: string; - sourceScope: string; - destinationScope: string; - constructor(message: string, sourceScope: string, destinationScope: string) { - super(); - this.message = message; - this.sourceScope = sourceScope; - this.destinationScope = destinationScope; - } -} diff --git a/src/scope/network/exceptions/index.ts b/src/scope/network/exceptions/index.ts index 910aab583946..6f1ac20c990c 100644 --- a/src/scope/network/exceptions/index.ts +++ b/src/scope/network/exceptions/index.ts @@ -1,4 +1,3 @@ -import AuthenticationFailed from './authentication-failed'; import FsScopeNotLoaded from './fs-scope-not-loaded'; import NetworkError from './network-error'; import OldClientVersion from './old-client-version'; @@ -8,7 +7,6 @@ import RemoteScopeNotFound from './remote-scope-not-found'; import UnexpectedNetworkError from './unexpected-network-error'; export { - AuthenticationFailed, ProtocolNotSupported, NetworkError, UnexpectedNetworkError, diff --git a/src/scope/network/exceptions/remote-resolver-error.ts b/src/scope/network/exceptions/remote-resolver-error.ts deleted file mode 100644 index c573a94e9d71..000000000000 --- a/src/scope/network/exceptions/remote-resolver-error.ts +++ /dev/null @@ -1,12 +0,0 @@ -import AbstractError from '../../../error/abstract-error'; - -export default class RemoteResolverError extends AbstractError { - message: string; - showDoctorMessage: boolean; - - constructor(message: string) { - super(); - this.message = message; - this.showDoctorMessage = true; - } -} diff --git a/src/scope/network/remote-error-handler.ts b/src/scope/network/remote-error-handler.ts index 2f1dc71f04ba..eca7bf299bcd 100644 --- a/src/scope/network/remote-error-handler.ts +++ b/src/scope/network/remote-error-handler.ts @@ -4,7 +4,6 @@ import ActionNotFound from '../exceptions/action-not-found'; import ClientIdInUse from '../exceptions/client-id-in-use'; import ServerIsBusy from '../exceptions/server-is-busy'; import { OldClientVersion, PermissionDenied, RemoteScopeNotFound, UnexpectedNetworkError } from './exceptions'; -import ExportAnotherOwnerPrivate from './exceptions/export-another-owner-private'; import { LaneNotFound } from '../../api/scope/lib/exceptions/lane-not-found'; // eslint-disable-next-line complexity export function remoteErrorHandler(code: number, parsedError: Record, remotePath: string, err) { @@ -28,12 +27,6 @@ export function remoteErrorHandler(code: number, parsedError: Record !h.isEqual(version.hash())); - const parentVersions = await pMapSeries(missingParentsHashes, (parentHash) => parentHash.load(this.repo)); - allVersions.push(...(parentVersions as Version[])); - // note: don't bring the head. otherwise, component-delta of the head won't bring all history of this comp. - } - allVersions.push(version); - await pMapSeries(allVersions, async (ver) => { - const versionObjects = await collectVersionObjects(ver); - this.pushManyObjects(versionObjects); + if (!this.pushed.includes(component.hash().toString())) { + const componentData = { + ref: component.hash(), + buffer: await component.asRaw(this.repo), + type: component.getType(), + }; + this.push(componentData); + } + const allVersions: Version[] = []; + if (includeVersionHistory) { + const versionHistory = await component.getAndPopulateVersionHistory(this.repo, version.hash()); + const versionHistoryData = { + ref: versionHistory.hash(), + buffer: await versionHistory.asRaw(this.repo), + type: versionHistory.getType(), + }; + this.push(versionHistoryData); + } + if (collectParents) { + const allParentsHashes = await getAllVersionHashesMemoized({ + modelComponent: component, + repo: this.repo, + startFrom: version.hash(), + stopAt: collectParentsUntil ? [collectParentsUntil] : undefined, }); - } catch (err: any) { - logger.error(`component-version.toObjects ${componentWithOptions.component.id()} got an error`, err); - // @ts-ignore - const originalVersionHash = component.getRef(componentWithOptions.version).toString(); - const currentVersionHash = version.hash().toString(); - if (originalVersionHash !== currentVersionHash) { - throw new HashMismatch(component.id(), componentWithOptions.version, originalVersionHash, currentVersionHash); - } - throw err; + const missingParentsHashes = allParentsHashes.filter((h) => !h.isEqual(version.hash())); + const parentVersions = await pMapSeries(missingParentsHashes, (parentHash) => parentHash.load(this.repo)); + allVersions.push(...(parentVersions as Version[])); + // note: don't bring the head. otherwise, component-delta of the head won't bring all history of this comp. } + allVersions.push(version); + await pMapSeries(allVersions, async (ver) => { + const versionObjects = await collectVersionObjects(ver); + this.pushManyObjects(versionObjects); + }); } } diff --git a/src/scope/types.ts b/src/scope/types.ts deleted file mode 100644 index 20e4d199db34..000000000000 --- a/src/scope/types.ts +++ /dev/null @@ -1,15 +0,0 @@ -export interface PersistOptions { - message?: string; - version?: string; - force?: boolean; -} - -export interface ComponentToPersist { - // TODO: change to real component instance - component: any; - persistOptions: PersistOptions; -} - -export interface PersistComponentsGeneralOptions { - verbose?: boolean; -}