Skip to content

Commit

Permalink
feat(depTypes): rename 'workspace' to 'local'
Browse files Browse the repository at this point in the history
BREAKING CHANGES:

In command line options:

```diff
- syncpack list --types prod,workspace
+ syncpack list --types prod,local
```

In configuration files:

```diff
- dependencyTypes: ['prod', workspace'],
+ dependencyTypes: ['prod', local'],
```

Docs: https://jamiemason.github.io/syncpack/config/dependency-types

Closes #154
  • Loading branch information
JamieMason committed Aug 14, 2023
1 parent c2cf817 commit 463c936
Show file tree
Hide file tree
Showing 31 changed files with 81 additions and 55 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
coverageThreshold: {
global: {
branches: 79,
functions: 81,
functions: 79,
lines: 86,
statements: 85,
},
Expand Down
10 changes: 1 addition & 9 deletions site/docs/config-file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@ If you want to specify a path to a configuration file, overriding the discovered
```json
{
"customTypes": [],
"dependencyTypes": [
"dev",
"overrides",
"peer",
"pnpmOverrides",
"prod",
"resolutions",
"workspace"
],
"dependencyTypes": ["dev", "local", "overrides", "peer", "pnpmOverrides", "prod", "resolutions"],
"filter": ".",
"indent": " ",
"semverGroups": [],
Expand Down
8 changes: 5 additions & 3 deletions site/docs/config/dependency-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ an ad hoc basis using the [`--types`](../option/types.mdx) option.

<DefaultDependencyTypes />

## The `workspace` type
## The `local` type

<i id="the-workspace-type">{/* support old deep links for this type's previous name */}</i>

This option synchronises the versions of your dependencies with the
[`version`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#version) properties of the
package.json files developed in your own local workspace/project, when they relate to eachother.
package.json files developed in your own local project, when they relate to eachother.

Take this example, `@your-repo/fetch` is developed in your repo:

Expand All @@ -79,5 +81,5 @@ and another package developed in your repo depends on it:
}
```

When `workspace` is enabled, syncpack will fix `@your-repo/ui` so it depends on version `1.0.2` of
When `local` is enabled, syncpack will fix `@your-repo/ui` so it depends on version `1.0.2` of
`@your-repo/fetch`.
2 changes: 1 addition & 1 deletion site/docs/config/semver-groups.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ can be broader.
"semverGroups": [
{
"range": "",
"dependencyTypes": ["prod", "resolutions", "overrides", "pnpmOverrides", "workspace"],
"dependencyTypes": ["prod", "resolutions", "overrides", "pnpmOverrides", "local"],
"dependencies": ["**"],
"packages": ["**"]
},
Expand Down
2 changes: 1 addition & 1 deletion site/src/partials/default-dependency-types.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
| Value | Property in package.json |
| :-------------- | :------------------------------------------------------------------------------------------------ |
| `dev` | [`devDependencies`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#devDependencies) |
| `local` | [`version`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#version) |
| `overrides` | [`overrides`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides) |
| `peer` | [`peerDependencies`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#peerDependencies) |
| `pnpmOverrides` | [`pnpm.overrides`](https://pnpm.io/package_json#pnpmoverrides) |
| `prod` | [`dependencies`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#dependencies) |
| `resolutions` | [`resolutions`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#resolutions) |
| `workspace` | [`version`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#version) |
2 changes: 1 addition & 1 deletion src/bin-fix-mismatches/fix-mismatches.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Context from '@effect/data/Context';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import { type CliConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig } from '../config/types';
import { createVersionsProgram } from '../create-program/versions';
import { createEnv } from '../env/create-env';
import type { DefaultEnv } from '../env/default-env';
Expand Down
2 changes: 1 addition & 1 deletion src/bin-format/format-cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Context from '@effect/data/Context';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import { type CliConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig } from '../config/types';
import { createEnv } from '../env/create-env';
import type { DefaultEnv } from '../env/default-env';
import { exitIfInvalid } from '../env/exit-if-invalid';
Expand Down
2 changes: 1 addition & 1 deletion src/bin-lint-semver-ranges/lint-semver-ranges.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Context from '@effect/data/Context';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import { type CliConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig } from '../config/types';
import { createSemverRangesProgram } from '../create-program/semver-ranges';
import { createEnv } from '../env/create-env';
import type { DefaultEnv } from '../env/default-env';
Expand Down
2 changes: 1 addition & 1 deletion src/bin-lint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import { lintSemverRangesEffects } from '../bin-lint-semver-ranges/effects';
import { listMismatchesEffects } from '../bin-list-mismatches/effects';
import { type CliConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig } from '../config/types';
import { createSemverRangesProgram } from '../create-program/semver-ranges';
import { createVersionsProgram } from '../create-program/versions';
import { createEnv } from '../env/create-env';
Expand Down
2 changes: 1 addition & 1 deletion src/bin-list-mismatches/list-mismatches.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Context from '@effect/data/Context';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import { type CliConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig } from '../config/types';
import { createVersionsProgram } from '../create-program/versions';
import { createEnv } from '../env/create-env';
import type { DefaultEnv } from '../env/default-env';
Expand Down
2 changes: 1 addition & 1 deletion src/bin-list/list.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Context from '@effect/data/Context';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import { type CliConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig } from '../config/types';
import { createVersionsProgram } from '../create-program/versions';
import { createEnv } from '../env/create-env';
import type { DefaultEnv } from '../env/default-env';
Expand Down
2 changes: 1 addition & 1 deletion src/bin-prompt/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Context from '@effect/data/Context';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import { type CliConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig } from '../config/types';
import { createVersionsProgram } from '../create-program/versions';
import { createEnv } from '../env/create-env';
import type { DefaultEnv } from '../env/default-env';
Expand Down
2 changes: 1 addition & 1 deletion src/bin-set-semver-ranges/set-semver-ranges.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Context from '@effect/data/Context';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import { type CliConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig } from '../config/types';
import { createSemverRangesProgram } from '../create-program/semver-ranges';
import { createEnv } from '../env/create-env';
import type { DefaultEnv } from '../env/default-env';
Expand Down
2 changes: 1 addition & 1 deletion src/bin-update/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as Context from '@effect/data/Context';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
// import { setSemverRangesEffects } from '../bin-set-semver-ranges/effects';
import { type CliConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig } from '../config/types';
// import { createSemverRangesProgram } from '../create-program/semver-ranges';
import { createVersionsProgram } from '../create-program/versions';
import { createEnv } from '../env/create-env';
Expand Down
16 changes: 14 additions & 2 deletions src/config/get-enabled-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ export class DeprecatedTypesError extends Data.TaggedClass('DeprecatedTypesError
readonly types: string[];
}> {}

export class RenamedWorkspaceTypeError extends Data.TaggedClass('RenamedWorkspaceTypeError')<
Record<string, never>
> {}

// @TODO accept `dependencyTypes: ['**']`
// @TODO support `dependencyTypes: ['!dev']`
export function getEnabledTypes({
cli,
rcFile,
}: Ctx['config']): Effect.Effect<never, DeprecatedTypesError, Strategy.Any[]> {
}: Ctx['config']): Effect.Effect<
never,
DeprecatedTypesError | RenamedWorkspaceTypeError,
Strategy.Any[]
> {
const enabledTypes: Strategy.Any[] = [];
const enabledTypeNames = (
isNonEmptyString(cli.types)
Expand All @@ -39,6 +47,10 @@ export function getEnabledTypes({
return Effect.fail(new DeprecatedTypesError({ types: deprecatedTypes }));
}

if (enabledTypeNames.includes('workspace')) {
return Effect.fail(new RenamedWorkspaceTypeError({}));
}

if (useDefaults || enabledTypeNames.includes('dev')) {
enabledTypes.push(new VersionsByNameStrategy('dev', 'devDependencies'));
}
Expand All @@ -57,7 +69,7 @@ export function getEnabledTypes({
if (useDefaults || enabledTypeNames.includes('resolutions')) {
enabledTypes.push(new VersionsByNameStrategy('resolutions', 'resolutions'));
}
if (useDefaults || enabledTypeNames.includes('workspace')) {
if (useDefaults || enabledTypeNames.includes('local')) {
enabledTypes.push(new NameAndVersionPropsStrategy('localPackage', 'version', 'name'));
}

Expand Down
10 changes: 1 addition & 9 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ export const RANGE = {
} as const;

export const DEFAULT_CONFIG = {
dependencyTypes: [
'dev',
'overrides',
'peer',
'pnpmOverrides',
'prod',
'resolutions',
'workspace',
],
dependencyTypes: ['dev', 'local', 'overrides', 'peer', 'pnpmOverrides', 'prod', 'resolutions'],
filter: '.',
indent: ' ',
semverGroups: [],
Expand Down
8 changes: 6 additions & 2 deletions src/create-program/semver-ranges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 { DeprecatedTypesError } from '../config/get-enabled-types';
import type { DeprecatedTypesError, RenamedWorkspaceTypeError } from '../config/get-enabled-types';
import type { Env } from '../env/create-env';
import type { Ctx } from '../get-context';
import type { SemverGroupConfigError, SemverGroupReport } from '../get-semver-groups';
Expand All @@ -12,7 +12,11 @@ import type { SemverRangeEffects } from './effects';
export function createSemverRangesProgram<T extends SemverRangeEffects<any>>(
ctx: Ctx,
effects: T,
): Effect.Effect<Env, SemverGroupConfigError | DeprecatedTypesError, Ctx> {
): Effect.Effect<
Env,
SemverGroupConfigError | DeprecatedTypesError | RenamedWorkspaceTypeError,
Ctx
> {
return pipe(
getSemverGroups(ctx),
Effect.flatMap((semverGroups) =>
Expand Down
8 changes: 6 additions & 2 deletions src/create-program/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 { DeprecatedTypesError } from '../config/get-enabled-types';
import type { DeprecatedTypesError, RenamedWorkspaceTypeError } from '../config/get-enabled-types';
import type { Env } from '../env/create-env';
import type { Ctx } from '../get-context';
import type { VersionGroupConfigError, VersionGroupReport } from '../get-version-groups';
Expand All @@ -12,7 +12,11 @@ import type { VersionEffects } from './effects';
export function createVersionsProgram<T extends VersionEffects<any>>(
ctx: Ctx,
effects: T,
): Effect.Effect<Env, VersionGroupConfigError | DeprecatedTypesError, Ctx> {
): Effect.Effect<
Env,
VersionGroupConfigError | DeprecatedTypesError | RenamedWorkspaceTypeError,
Ctx
> {
return pipe(
getVersionGroups(ctx),
Effect.flatMap((versionGroups) =>
Expand Down
6 changes: 5 additions & 1 deletion src/error-handlers/create-error-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Effect from '@effect/io/Effect';
import type { DeprecatedTypesError } from '../config/get-enabled-types';
import type { DeprecatedTypesError, RenamedWorkspaceTypeError } from '../config/get-enabled-types';
import type { GlobError, ReadConfigFileError, ReadFileError, WriteFileError } from '../env/tags';
import type { NoSourcesFoundError } from '../get-package-json-files/get-file-paths';
import type { JsonParseError } from '../get-package-json-files/get-patterns/read-json-safe';
Expand All @@ -13,6 +13,7 @@ export interface ErrorHandlers<R = Effect.Effect<never, never, void>> {
NoSourcesFoundError(err: NoSourcesFoundError): R;
ReadConfigFileError(err: ReadConfigFileError): R;
ReadFileError(err: ReadFileError): R;
RenamedWorkspaceTypeError(err: RenamedWorkspaceTypeError): R;
SemverGroupConfigError(err: SemverGroupConfigError): R;
VersionGroupConfigError(err: VersionGroupConfigError): R;
WriteFileError(err: WriteFileError): R;
Expand All @@ -37,6 +38,9 @@ export const createErrorHandlers = (errorHandlers: ErrorHandlers<void>): ErrorHa
ReadFileError(err) {
return Effect.sync(() => errorHandlers.ReadFileError(err));
},
RenamedWorkspaceTypeError(err) {
return Effect.sync(() => errorHandlers.RenamedWorkspaceTypeError(err));
},
SemverGroupConfigError(err) {
return Effect.sync(() => errorHandlers.SemverGroupConfigError(err));
},
Expand Down
7 changes: 7 additions & 0 deletions src/error-handlers/default-error-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export const defaultErrorHandlers: ErrorHandlers<void> = {
console.log(chalk.red(' File:', err.filePath));
console.log(chalk.red(' Error:', err.error));
},
RenamedWorkspaceTypeError() {
const url = 'https://github.com/JamieMason/syncpack/releases/tag/11.2.1';
console.log(
chalk.red(ICON.panic, `The "workspace" dependency type was renamed to "local" in ${url}`),
);
console.log(chalk.red(' Docs: https://jamiemason.github.io/syncpack/config/dependency-types'));
},
SemverGroupConfigError(err) {
console.log(chalk.red(ICON.panic, 'Your semver group config contains an error'));
console.log(chalk.red(' Error:', err.error));
Expand Down
2 changes: 1 addition & 1 deletion src/get-context/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import type { O } from 'ts-toolbelt';
import { type CliConfig, type RcConfig } from '../config/types';
import { CliConfigTag } from '../config/tag';
import { type CliConfig, type RcConfig } from '../config/types';
import type { Env } from '../env/create-env';
import type { GlobError, ReadConfigFileError, ReadFileError } from '../env/tags';
import { EnvTag } from '../env/tags';
Expand Down
2 changes: 1 addition & 1 deletion src/get-package-json-files/get-file-paths.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CWD } from '../constants';
import { createEnv } from '../env/create-env';
import { EnvTag } from '../env/tags';
import type { Ctx } from '../get-context';
import { NoSourcesFoundError, getFilePaths } from './get-file-paths';
import { getFilePaths, NoSourcesFoundError } from './get-file-paths';

function runSync(config: Ctx['config'], mockedEffects: MockEnv, onValue: (value: any) => void) {
Effect.runSync(
Expand Down
8 changes: 6 additions & 2 deletions src/get-semver-groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isNonEmptyArray } from 'tightrope/guard/is-non-empty-array';
import { isNonEmptyString } from 'tightrope/guard/is-non-empty-string';
import { isObject } from 'tightrope/guard/is-object';
import type { Union } from 'ts-toolbelt';
import type { DeprecatedTypesError } from '../config/get-enabled-types';
import type { DeprecatedTypesError, RenamedWorkspaceTypeError } from '../config/get-enabled-types';
import { getEnabledTypes } from '../config/get-enabled-types';
import { getSemverRange } from '../config/get-semver-range';
import type { Ctx } from '../get-context';
Expand Down Expand Up @@ -83,7 +83,11 @@ export class SemverGroupConfigError extends Data.TaggedClass('SemverGroupConfigE

export function getSemverGroups(
ctx: Ctx,
): Effect.Effect<never, SemverGroupConfigError | DeprecatedTypesError, AnySemverGroup[]> {
): Effect.Effect<
never,
SemverGroupConfigError | DeprecatedTypesError | RenamedWorkspaceTypeError,
AnySemverGroup[]
> {
return pipe(
Effect.Do,
Effect.bind('enabledTypes', () => getEnabledTypes(ctx.config)),
Expand Down
8 changes: 6 additions & 2 deletions src/get-version-groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isNonEmptyArray } from 'tightrope/guard/is-non-empty-array';
import { isNonEmptyString } from 'tightrope/guard/is-non-empty-string';
import { isObject } from 'tightrope/guard/is-object';
import type { Union } from 'ts-toolbelt';
import type { DeprecatedTypesError } from '../config/get-enabled-types';
import type { DeprecatedTypesError, RenamedWorkspaceTypeError } from '../config/get-enabled-types';
import { getEnabledTypes } from '../config/get-enabled-types';
import type { Ctx } from '../get-context';
import { canAddToGroup } from '../guards/can-add-to-group';
Expand Down Expand Up @@ -191,7 +191,11 @@ export class VersionGroupConfigError extends Data.TaggedClass('VersionGroupConfi

export function getVersionGroups(
ctx: Ctx,
): Effect.Effect<never, VersionGroupConfigError | DeprecatedTypesError, AnyVersionGroup[]> {
): Effect.Effect<
never,
VersionGroupConfigError | DeprecatedTypesError | RenamedWorkspaceTypeError,
AnyVersionGroup[]
> {
return pipe(
Effect.Do,
Effect.bind('enabledTypes', () => getEnabledTypes(ctx.config)),
Expand Down
1 change: 1 addition & 0 deletions test/mock-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function createMockErrorHandlers(): ErrorHandlers<jest.Mock<any, any>> {
NoSourcesFoundError: jest.fn(),
ReadConfigFileError: jest.fn(),
ReadFileError: jest.fn(),
RenamedWorkspaceTypeError: jest.fn(),
SemverGroupConfigError: jest.fn(),
VersionGroupConfigError: jest.fn(),
WriteFileError: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion test/run-context-sync.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Context from '@effect/data/Context';
import { pipe } from '@effect/data/Function';
import * as Effect from '@effect/io/Effect';
import type { CliConfig } from '../src/config/types';
import { CliConfigTag } from '../src/config/tag';
import type { CliConfig } from '../src/config/types';
import { createEnv } from '../src/env/create-env';
import { EnvTag } from '../src/env/tags';
import { getContext } from '../src/get-context';
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/semver-groups/issue-84-reproduction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('Issue 84 reproduction', () => {
'peer',
'prod',
'resolutions',
'workspace',
'local',
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('semverGroups', () => {
),
].forEach((getScenario) => {
describe('semverGroup.inspect()', () => {
test("should identify as a workspace mismatch as a package's version must be exact", () => {
test("should identify as a local mismatch as a package's version must be exact", () => {
const scenario = getScenario();
expect(scenario.report.semverGroups).toEqual([
[
Expand Down

0 comments on commit 463c936

Please sign in to comment.