Skip to content

Commit

Permalink
feat(core): refactor and general improvements
Browse files Browse the repository at this point in the history
Closes #140

When linting semver ranges, warn on non-semver versions but don't error

Closes #139

Handle !negated globs

Closes #132

Show more detailed information about errors and warnings

Closes #111

Throw when config is invalid, instead of defaulting
  • Loading branch information
JamieMason committed Jun 18, 2023
1 parent 2801b67 commit f35c486
Show file tree
Hide file tree
Showing 200 changed files with 5,005 additions and 3,711 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ module.exports = {
},
],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports' },
],
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
},
};
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"arrowParens": "always",
"printWidth": 80,
"printWidth": 100,
"proseWrap": "always",
"quoteProps": "consistent",
"singleQuote": true,
Expand Down
5 changes: 5 additions & 0 deletions .syncpackrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const config = {
packages: ['**'],
pinVersion: '4.1.2',
},
{
dependencies: ['globby'],
packages: ['**'],
pinVersion: '11.1.0',
},
],
};

Expand Down
4 changes: 1 addition & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"version": "2.0.0",
"tasks": [
{
"args": [
"${workspaceFolder}/${relativeFileDirname}/${fileBasenameNoExtension}.spec.ts"
],
"args": ["${workspaceFolder}/${relativeFileDirname}/${fileBasenameNoExtension}.spec.ts"],
"command": "scripts/upsert-test.sh",
"group": "test",
"label": "Upsert test for current file",
Expand Down
12 changes: 4 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ module.exports = {
'src/**/*.ts',
'!src/bin.ts',
'!src/bin*/index.ts',
'!src/lib/effects.ts',
'!src/lib/log.ts',
'!src/option.ts',
],
coverageReporters: ['html', 'lcov'],
coverageThreshold: {
global: {
branches: 80,
functions: 95,
lines: 95,
statements: 95,
functions: 90,
lines: 90,
statements: 90,
},
},
moduleFileExtensions: ['ts', 'js'],
setupFiles: ['<rootDir>/test/jest.setup.ts'],
testMatch: [
'<rootDir>/src/**/*.spec.ts',
'<rootDir>/test/scenarios/**/*.spec.ts',
],
testMatch: ['<rootDir>/src/**/*.spec.ts', '<rootDir>/test/scenarios/**/*.spec.ts'],
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
},
Expand Down
25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,30 @@
"Tom Fletcher (https://github.com/tom-fletcher)"
],
"dependencies": {
"@effect/data": "0.12.5",
"@effect/io": "0.26.0",
"@effect/match": "0.24.4",
"chalk": "4.1.2",
"commander": "10.0.1",
"cosmiconfig": "8.1.3",
"commander": "11.0.0",
"cosmiconfig": "8.2.0",
"enquirer": "2.3.6",
"fs-extra": "11.1.1",
"glob": "10.2.6",
"globby": "11.1.0",
"minimatch": "9.0.1",
"read-yaml-file": "2.1.0",
"semver": "7.5.1",
"semver": "7.5.2",
"tightrope": "0.1.0",
"ts-toolbelt": "9.6.0"
},
"devDependencies": {
"@tsconfig/node14": "1.0.3",
"@types/fs-extra": "11.0.1",
"@types/glob": "8.1.0",
"@types/jest": "29.5.2",
"@types/node": "14.18.36",
"@types/semver": "7.5.0",
"@typescript-eslint/eslint-plugin": "5.59.8",
"@typescript-eslint/parser": "5.59.8",
"eslint": "8.42.0",
"@typescript-eslint/eslint-plugin": "5.59.11",
"@typescript-eslint/parser": "5.59.11",
"eslint": "8.43.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jest": "27.2.1",
"expect-more-jest": "5.5.0",
Expand Down Expand Up @@ -94,16 +96,19 @@
"repository": "JamieMason/syncpack",
"resolutions": {
"chalk": "4.1.2",
"globby": "11.1.0",
"string-width": "<5.0.0",
"strip-ansi": "<7.0.0",
"wrap-ansi": "<8.0.0"
},
"scripts": {
"build": "rm -rf ./dist && tsc --project .",
"build": "rm -rf ./dist && tsc --project tsconfig.build.json",
"format": "yarn format:lint && yarn format:source",
"format:lint": "yarn lint --fix",
"format:source": "prettier --write .",
"lint": "eslint --ext .ts .",
"lint": "yarn lint:ts && yarn lint:eslint",
"lint:eslint": "eslint --ext .ts .",
"lint:ts": "tsc --noEmit --project tsconfig.json",
"prepack": "yarn build",
"test": "jest src test"
},
Expand Down
20 changes: 9 additions & 11 deletions site/docs/config-file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ id: config-file
title: Configuration File
---

Creating a configuration file is optional, syncpack will search up the directory
tree in the following places:
Creating a configuration file is optional, syncpack will search up the directory tree in the
following places:

- a `syncpack` property in `package.json`
- a `.syncpackrc` file in JSON or YAML format
- a `.syncpackrc.json`, `.syncpackrc.yaml`, `.syncpackrc.yml`, `.syncpackrc.js`,
or `.syncpackrc.cjs` file
- a `syncpack.config.js` or `syncpack.config.cjs` CommonJS module exporting an
object
- a `.syncpackrc.json`, `.syncpackrc.yaml`, `.syncpackrc.yml`, `.syncpackrc.js`, or
`.syncpackrc.cjs` file
- a `syncpack.config.js` or `syncpack.config.cjs` CommonJS module exporting an object
- a `config.syncpack` property in `package.json`

If you want to specify a path to a configuration file, overriding the discovered
configuration file (if present), you can use the [`--config`](./config-file.mdx)
option.
If you want to specify a path to a configuration file, overriding the discovered configuration file
(if present), you can use the [`--config`](./config-file.mdx) option.

## Default Configuration

Expand Down Expand Up @@ -53,8 +51,8 @@ option.

## TypeScript IntelliSense

If you want intellisense for the configuration file, you can annotate your
javascript config files with the following:
If you want intellisense for the configuration file, you can annotate your javascript config files
with the following:

:::caution

Expand Down
29 changes: 12 additions & 17 deletions site/docs/config/custom-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@ import Pills from '@site/src/components/pill';

<Pills optional />

Extend syncpack to find and fix versions in your packages which are not
available by default. Custom types behave like any other dependency, so can be
included in [versionGroups](./version-groups.mdx) or
[semverGroups](./semver-groups.mdx) etc.
Extend syncpack to find and fix versions in your packages which are not available by default. Custom
types behave like any other dependency, so can be included in [versionGroups](./version-groups.mdx)
or [semverGroups](./semver-groups.mdx) etc.

The example below adds support for synchronising versions found in:

1. The
[`engines`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#engines)
object.
1. The [`packageManager`](https://nodejs.org/api/packages.html#packagemanager)
string.
1. The [`engines`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#engines) object.
1. The [`packageManager`](https://nodejs.org/api/packages.html#packagemanager) string.

```json title=".syncpackrc"
{
Expand Down Expand Up @@ -48,27 +44,26 @@ Syncpack config files also support

<Pills required />

The key of each custom type is its name, this can be used in the following
places to toggle when it is enabled:
The key of each custom type is its name, this can be used in the following places to toggle when it
is enabled:

1. [`--types`](../option/types.mdx) and
[`dependencyTypes`](./dependency-types.mdx).
1. [`--types`](../option/types.mdx) and [`dependencyTypes`](./dependency-types.mdx).
1. [`versionGroup.dependencyTypes`](./version-groups.mdx#dependencytypes)
1. [`semverGroup.dependencyTypes`](./semver-groups.mdx#dependencytypes)

## customTypes\[name\].path

<Pills required />

Where the version can be found in each package.json file, such as `engines`,
`packageManager` or `some.nested.property`.
Where the version can be found in each package.json file, such as `engines`, `packageManager` or
`some.nested.property`.

## customTypes\[name\].strategy

<Pills required />

A strategy defines how syncpack needs to read and write dependency names and
versions, there are 3 to choose from:
A strategy defines how syncpack needs to read and write dependency names and versions, there are 3
to choose from:

| Name | Example |
| ---------------- | -------------------------------------- |
Expand Down
28 changes: 12 additions & 16 deletions site/docs/config/dependency-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import Pills from '@site/src/components/pill';

<Pills optional />

All of the [default dependency types](#default-dependency-types) are enabled by
default, but can be reduced to a smaller list via the `dependencyTypes` property
of your config file.
All of the [default dependency types](#default-dependency-types) are enabled by default, but can be
reduced to a smaller list via the `dependencyTypes` property of your config file.

In this example, only dependencies found in the
[`dependencies`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#dependencies)
and
[`dependencies`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#dependencies) and
[`devDependencies`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#devDependencies)
properties of package.json files will be inspected by syncpack:

Expand All @@ -35,17 +33,16 @@ Syncpack config files also support

:::tip

The [default dependency types](#default-dependency-types) can be extended with
your own [`customTypes`](./custom-types.mdx), so you can find and fix versions
found in other parts of your package.json files.
The [default dependency types](#default-dependency-types) can be extended with your own
[`customTypes`](./custom-types.mdx), so you can find and fix versions found in other parts of your
package.json files.

:::

:::info

Your `dependencyTypes` configuration in your [config file](../config-file.mdx)
can be overridden on an ad hoc basis using the [`--types`](../option/types.mdx)
option.
Your `dependencyTypes` configuration in your [config file](../config-file.mdx) can be overridden on
an ad hoc basis using the [`--types`](../option/types.mdx) option.

:::

Expand All @@ -56,9 +53,8 @@ option.
## The `workspace` type

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.
[`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.

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

Expand All @@ -83,5 +79,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 `@your-repo/fetch`.
When `workspace` is enabled, syncpack will fix `@your-repo/ui` so it depends on version `1.0.2` of
`@your-repo/fetch`.
13 changes: 6 additions & 7 deletions site/docs/config/filter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import Pills from '@site/src/components/pill';

<Pills optional />

A string which will be passed to `new RegExp()` to match against package names
that should be included.
A string which will be passed to `new RegExp()` to match against package names that should be
included.

:::danger

`filter` was originally intended as a convenience to be used from the command
line to filter the output of `syncpack list`, **it is not recommended to add
this to your config file to manage your project more generally**.
`filter` was originally intended as a convenience to be used from the command line to filter the
output of `syncpack list`, **it is not recommended to add this to your config file to manage your
project more generally**.

Instead use [`versionGroups`](./version-groups.mdx) and/or
[`semverGroups`](./semver-groups.mdx).
Instead use [`versionGroups`](./version-groups.mdx) and/or [`semverGroups`](./semver-groups.mdx).

:::
8 changes: 3 additions & 5 deletions site/docs/config/indent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import Pills from '@site/src/components/pill';

<Pills optional />

The character(s) to be used to indent your package.json files when writing to
disk.
The character(s) to be used to indent your package.json files when writing to disk.

```json title=".syncpackrc"
{
Expand All @@ -27,8 +26,7 @@ Syncpack config files also support

:::info

The `indent` configuration in your [config file](../config-file.mdx) can be
overridden on an ad hoc basis using the [`--indent`](../option/indent.mdx)
option.
The `indent` configuration in your [config file](../config-file.mdx) can be overridden on an ad hoc
basis using the [`--indent`](../option/indent.mdx) option.

:::
Loading

0 comments on commit f35c486

Please sign in to comment.