Skip to content

Commit

Permalink
[WIP] list command working again in refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Aug 26, 2023
1 parent 54c2483 commit cca1997
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
42 changes: 20 additions & 22 deletions src/create-program/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type * as Effect from '@effect/io/Effect';
import type { Ctx } from '../get-context';
import type { AnySemverGroup, SemverGroupReport as SR } from '../get-semver-groups';
import type { AnyVersionGroup, VersionGroupReport as VR } from '../get-version-groups';
import type { Env } from '../io/create-env';
import type { Io } from '../io';

export interface SemverRangeEffectInput<T> {
ctx: Ctx;
Expand All @@ -21,48 +21,46 @@ export interface VersionEffectInput<T> {
export interface SemverRangeEffects<A> {
onFilteredOut: (
input: SemverRangeEffectInput<SR.FilteredOut>,
) => Effect.Effect<Env | never, never, A>;
onIgnored: (input: SemverRangeEffectInput<SR.Ignored>) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onIgnored: (input: SemverRangeEffectInput<SR.Ignored>) => Effect.Effect<Io | never, never, A>;
onSemverRangeMismatch: (
input: SemverRangeEffectInput<SR.SemverRangeMismatch>,
) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onNonSemverVersion: (
input: SemverRangeEffectInput<SR.NonSemverVersion>,
) => Effect.Effect<Env | never, never, A>;
onValid: (input: SemverRangeEffectInput<SR.Valid>) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onValid: (input: SemverRangeEffectInput<SR.Valid>) => Effect.Effect<Io | never, never, A>;
onLocalPackageSemverRangeMismatch: (
input: SemverRangeEffectInput<SR.LocalPackageSemverRangeMismatch>,
) => Effect.Effect<Env | never, never, A>;
onComplete: (ctx: Ctx, results: A[]) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onComplete: (ctx: Ctx, results: A[]) => Effect.Effect<Io | never, never, A>;
}

export interface VersionEffects<A> {
onBanned: (input: VersionEffectInput<VR.Banned>) => Effect.Effect<Env | never, never, A>;
onFilteredOut: (
input: VersionEffectInput<VR.FilteredOut>,
) => Effect.Effect<Env | never, never, A>;
onBanned: (input: VersionEffectInput<VR.Banned>) => Effect.Effect<Io | never, never, A>;
onFilteredOut: (input: VersionEffectInput<VR.FilteredOut>) => Effect.Effect<Io | never, never, A>;
onHighestSemverMismatch: (
input: VersionEffectInput<VR.HighestSemverMismatch>,
) => Effect.Effect<Env | never, never, A>;
onIgnored: (input: VersionEffectInput<VR.Ignored>) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onIgnored: (input: VersionEffectInput<VR.Ignored>) => Effect.Effect<Io | never, never, A>;
onLowestSemverMismatch: (
input: VersionEffectInput<VR.LowestSemverMismatch>,
) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onPinnedMismatch: (
input: VersionEffectInput<VR.PinnedMismatch>,
) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onSameRangeMismatch: (
input: VersionEffectInput<VR.SameRangeMismatch>,
) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onSnappedToMismatch: (
input: VersionEffectInput<VR.SnappedToMismatch>,
) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onNonSemverMismatch: (
input: VersionEffectInput<VR.NonSemverMismatch>,
) => Effect.Effect<Env | never, never, A>;
onValid: (input: VersionEffectInput<VR.Valid>) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onValid: (input: VersionEffectInput<VR.Valid>) => Effect.Effect<Io | never, never, A>;
onLocalPackageMismatch: (
input: VersionEffectInput<VR.LocalPackageMismatch>,
) => Effect.Effect<Env | never, never, A>;
onComplete: (ctx: Ctx, results: A[]) => Effect.Effect<Env | never, never, A>;
) => Effect.Effect<Io | never, never, A>;
onComplete: (ctx: Ctx, results: A[]) => Effect.Effect<Io | never, never, A>;
}
15 changes: 12 additions & 3 deletions src/create-program/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ import { pipe } from '@effect/data/Function';
import { unify } from '@effect/data/Unify';
import * as Effect from '@effect/io/Effect';
import * as Match from '@effect/match';
import type { InvalidCustomTypeError } from '../config/get-custom-types';
import type { DeprecatedTypesError, RenamedWorkspaceTypeError } from '../config/get-enabled-types';
import type { Ctx } from '../get-context';
import type { VersionGroupConfigError, VersionGroupReport } from '../get-version-groups';
import { getVersionGroups } from '../get-version-groups';
import type { Env } from '../io/create-env';
import type { Io } from '../io';
import type { VersionEffects } from './effects';

export function createVersionsProgram<T extends VersionEffects<any>>(
ctx: Ctx,
effects: T,
): Effect.Effect<
Env,
VersionGroupConfigError | DeprecatedTypesError | RenamedWorkspaceTypeError,
Io,
| DeprecatedTypesError
| InvalidCustomTypeError
| RenamedWorkspaceTypeError
| VersionGroupConfigError,
Ctx
> {
return pipe(
Expand Down Expand Up @@ -48,6 +52,11 @@ export function createVersionsProgram<T extends VersionEffects<any>>(
HighestSemverMismatch(report) {
return effects.onHighestSemverMismatch({ ctx, group, index, report });
},
InvalidCustomTypeError(err: any) {
console.info(err);
return Effect.unit;
// return effects.onInvalidCustomTypeError({ ctx, group, index, report });
},
LowestSemverMismatch(report) {
return effects.onLowestSemverMismatch({ ctx, group, index, report });
},
Expand Down
17 changes: 10 additions & 7 deletions src/error-handlers/create-error-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as Effect from '@effect/io/Effect';
import type { InvalidCustomTypeError } from '../config/get-custom-types';
import type { DeprecatedTypesError, RenamedWorkspaceTypeError } from '../config/get-enabled-types';
import type { NoSourcesFoundError } from '../get-package-json-files/get-file-paths';
import type { SemverGroupConfigError } from '../get-semver-groups';
import type { VersionGroupConfigError } from '../get-version-groups';
import type {
GlobError,
JsonParseError,
ReadConfigFileError,
ReadFileError,
WriteFileError
} from '../io/tags';
import type { GlobError } from '../io/glob-sync';
import type { ReadConfigFileError } from '../io/read-config-file-sync';
import type { ReadFileError } from '../io/read-file-sync';
import type { JsonParseError } from '../io/read-json-file-sync';
import type { WriteFileError } from '../io/write-file-sync';

export interface ErrorHandlers<R = Effect.Effect<never, never, void>> {
DeprecatedTypesError(err: DeprecatedTypesError): R;
GlobError(err: GlobError): R;
InvalidCustomTypeError(err: InvalidCustomTypeError): R;
JsonParseError(err: JsonParseError): R;
NoSourcesFoundError(err: NoSourcesFoundError): R;
ReadConfigFileError(err: ReadConfigFileError): R;
Expand All @@ -31,6 +31,9 @@ export const createErrorHandlers = (errorHandlers: ErrorHandlers<void>): ErrorHa
GlobError(err) {
return Effect.sync(() => errorHandlers.GlobError(err));
},
InvalidCustomTypeError(err) {
return Effect.sync(() => errorHandlers.InvalidCustomTypeError(err));
},
JsonParseError(err) {
return Effect.sync(() => errorHandlers.JsonParseError(err));
},
Expand Down
6 changes: 6 additions & 0 deletions src/error-handlers/default-error-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export const defaultErrorHandlers: ErrorHandlers<void> = {
console.log(chalk.red(ICON.panic, 'An error was found when processing your source globs'));
console.log(chalk.red(' Error:', err.error));
},
InvalidCustomTypeError(err) {
console.log(chalk.red(ICON.panic, 'Your syncpack config file contains an invalid custom type'));
console.log(chalk.red(' Error:', err.reason));
console.log(chalk.red(' Config:', err.config));
console.log(chalk.red(' Docs: https://jamiemason.github.io/syncpack/config/custom-types'));
},
JsonParseError(err) {
console.log(chalk.red(ICON.panic, 'An error was found when parsing a JSON file'));
console.log(chalk.red(' File:', err.filePath));
Expand Down
2 changes: 1 addition & 1 deletion src/get-package-json-files/package-json-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Strategy } from '../config/get-custom-types';
import type { Ctx } from '../get-context';
import type { Instance } from '../instance';
import { createInstance } from '../instance/create';
import type { JsonFile } from '../io/tags';
import type { JsonFile } from '../io/read-json-file-sync';
import { logVerbose } from '../lib/log-verbose';

export interface PackageJson {
Expand Down
6 changes: 5 additions & 1 deletion src/get-version-groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { PinnedVersionGroup } from './pinned';
import { SameRangeVersionGroup } from './same-range';
import { SnappedToVersionGroup } from './snapped-to';
import { StandardVersionGroup } from './standard';
import type { InvalidCustomTypeError } from '../config/get-custom-types';

export type AnyVersionGroup = Union.Strict<
| BannedVersionGroup
Expand Down Expand Up @@ -193,7 +194,10 @@ export function getVersionGroups(
ctx: Ctx,
): Effect.Effect<
never,
VersionGroupConfigError | DeprecatedTypesError | RenamedWorkspaceTypeError,
| DeprecatedTypesError
| InvalidCustomTypeError
| RenamedWorkspaceTypeError
| VersionGroupConfigError,
AnyVersionGroup[]
> {
return pipe(
Expand Down

0 comments on commit cca1997

Please sign in to comment.