UNPKG

syncpack

Version:

Consistent dependency versions in large JavaScript Monorepos

53 lines (52 loc) 2.49 kB
import chalk from 'chalk-template'; import { Context, Effect, pipe } from 'effect'; import { pipeline as format } from '../bin-format/format.js'; import { pipeline as lintSemverRanges } from '../bin-lint-semver-ranges/lint-semver-ranges.js'; import { pipeline as listMismatches } from '../bin-list-mismatches/list-mismatches.js'; import { CliConfigTag } from '../config/tag.js'; import { ICON } from '../constants.js'; import { defaultErrorHandlers } from '../error-handlers/default-error-handlers.js'; import { getContext } from '../get-context/index.js'; import { exitIfInvalid } from '../io/exit-if-invalid.js'; import { IoTag } from '../io/index.js'; import { toFormattedJson } from '../io/to-formatted-json.js'; import { withLogger } from '../lib/with-logger.js'; export function lint({ io, cli, errorHandlers = defaultErrorHandlers }) { return pipe(getContext({ io, cli, errorHandlers }), // Formatting Effect.flatMap(ctx => Effect.gen(function* ($) { if (ctx.config.rcFile.lintFormatting !== false) { yield* $(Effect.logInfo(chalk `{yellow Formatting}`)); yield* $(format(ctx)); for (const file of ctx.packageJsonFiles) { const shortPath = file.jsonFile.shortPath; const formattedJson = toFormattedJson(ctx, file); const isFormatted = file.jsonFile.json === formattedJson; if (isFormatted) { yield* $(Effect.logInfo(chalk `{green ${ICON.tick}} ${shortPath}`)); } else { ctx.isInvalid = true; yield* $(Effect.logInfo(chalk `{red ${ICON.cross}} ${shortPath}`)); } } } return ctx; })), // Versions Effect.flatMap(ctx => Effect.gen(function* ($) { if (ctx.config.rcFile.lintVersions !== false) { yield* $(Effect.logInfo(chalk `{yellow Versions}`)); yield* $(listMismatches(ctx, io, errorHandlers)); } return ctx; })), // Semver Ranges Effect.flatMap(ctx => Effect.gen(function* ($) { if (ctx.config.rcFile.lintSemverRanges !== false) { yield* $(Effect.logInfo(chalk `{yellow Semver Ranges}`)); yield* $(lintSemverRanges(ctx, io, errorHandlers)); } return ctx; })), Effect.flatMap(exitIfInvalid), Effect.provide(pipe(Context.empty(), Context.add(CliConfigTag, cli), Context.add(IoTag, io))), withLogger); }