Skip to content

Commit

Permalink
refactor(core): rewrite core architecture
Browse files Browse the repository at this point in the history
Closes #124

When using the `workspace` dependency type, packages installing that dependency no longer have to exactly match the `version` property of the package.json of origin.

If the version or version range used by every dependent package matches, it is considered valid.

Closes #130
Closes #131

JavaScript config files now have support for TypeScript IntelliSense.

https://jamiemason.github.io/syncpack/config-file#typescript-intellisense

Closes #114
Refs #109
Refs #125

Unsupported versions can now at least be managed via `pinVersion`, where previously anything which was not valid semver would be ignored.

Refs #111
Refs #132

TypeScript IntelliSense support helps catch invalid config, but more work is needed to display useful error messages at runtime.

Refs #48
Refs #3

Syncpack's internals are now better organised, so providing a Node.js API and general lint and fix CLI commands are now closer to being released.

BREAKING CHANGES:

- `fix-mismatches` will now exit with a status code of 1 if there are mismatches among unsupported versions which syncpack cannot auto-fix.
- Although they are still not auto-fixable, unsupported versions which were previously ignored are now acknowledged, which may introduce mismatches which previously would have been considered valid.
- This release was also a huge rewrite of Syncpack's internals and, while there is a large amount of tests, some scenarios may have been missed.
- If you run into any problems, please create an issue.
  • Loading branch information
JamieMason committed May 28, 2023
1 parent 2c5cd7f commit 6ca61cc
Show file tree
Hide file tree
Showing 194 changed files with 6,498 additions and 4,936 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ module.exports = {
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/consistent-type-imports': [
'error',
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- master
- dev
- refactor

jobs:
all:
Expand Down
17 changes: 16 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,20 @@
"proseWrap": "always",
"quoteProps": "consistent",
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "all",
"overrides": [
{
"files": ["**/*.spec.*"],
"options": {
"printWidth": 100
}
},
{
"files": ["**/*.md"],
"options": {
"printWidth": 100,
"proseWrap": "always"
}
}
]
}
22 changes: 0 additions & 22 deletions .syncpackrc

This file was deleted.

19 changes: 19 additions & 0 deletions .syncpackrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-check

/** @type {import("./src").RcFile} */
const config = {
versionGroups: [
{
dependencies: ['@types/node'],
packages: ['**'],
pinVersion: '14.18.36',
},
{
dependencies: ['chalk'],
packages: ['**'],
pinVersion: '4.1.2',
},
],
};

module.exports = config;
55 changes: 55 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"version": "2.0.0",
"tasks": [
{
"args": [
"${workspaceFolder}/${relativeFileDirname}/${fileBasenameNoExtension}.spec.ts"
],
"command": "scripts/upsert-test.sh",
"group": "test",
"label": "Upsert test for current file",
"presentation": {
"panel": "dedicated",
"reveal": "silent"
},
"problemMatcher": [],
"type": "shell"
},
{
"args": ["src", "test"],
"command": "${workspaceFolder}/node_modules/.bin/jest",
"group": "test",
"label": "Run tests",
"presentation": {
"panel": "dedicated",
"reveal": "always"
},
"problemMatcher": [],
"type": "shell"
},
{
"args": ["--watch", "--no-coverage", "src", "test"],
"command": "${workspaceFolder}/node_modules/.bin/jest",
"group": "test",
"label": "Watch tests",
"presentation": {
"panel": "dedicated",
"reveal": "always"
},
"problemMatcher": [],
"type": "shell"
},
{
"args": ["--watch", "--no-coverage", "${relativeFile}"],
"command": "${workspaceFolder}/node_modules/.bin/jest",
"group": "test",
"label": "Watch tests for current .spec.ts file",
"presentation": {
"panel": "dedicated",
"reveal": "always"
},
"problemMatcher": [],
"type": "shell"
}
]
}
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,47 @@ npm install --save-dev syncpack

## Documentation

Full information can be found in the documentation at
https://jamiemason.github.io/syncpack/.
Full information can be found in the documentation at https://jamiemason.github.io/syncpack/.

## Commands

### [fix-mismatches](https://jamiemason.github.io/syncpack/fix-mismatches)

Ensure that multiple packages requiring the same dependency define the same
version, so that every package requires eg. `react@16.4.2`, instead of a
combination of `react@16.4.2`, `react@0.15.9`, and `react@16.0.0`.
Ensure that multiple packages requiring the same dependency define the same version, so that every
package requires eg. `react@16.4.2`, instead of a combination of `react@16.4.2`, `react@0.15.9`, and
`react@16.0.0`.

### [format](https://jamiemason.github.io/syncpack/format)

Organise package.json files according to a conventional format, where fields
appear in a predictable order and nested fields are ordered alphabetically.
Shorthand properties are used where available, such as the `"repository"` and
`"bugs"` fields.
Organise package.json files according to a conventional format, where fields appear in a predictable
order and nested fields are ordered alphabetically. Shorthand properties are used where available,
such as the `"repository"` and `"bugs"` fields.

### [lint-semver-ranges](https://jamiemason.github.io/syncpack/lint-semver-ranges)

Check whether dependency versions used within "dependencies", "devDependencies",
etc follow a consistent format.
Check whether dependency versions used within "dependencies", "devDependencies", etc follow a
consistent format.

### [list](https://jamiemason.github.io/syncpack/list)

List all dependencies required by your packages.

### [list-mismatches](https://jamiemason.github.io/syncpack/list-mismatches)

List dependencies which are required by multiple packages, where the version is
not the same across every package.
List dependencies which are required by multiple packages, where the version is not the same across
every package.

### [set-semver-ranges](https://jamiemason.github.io/syncpack/set-semver-ranges)

Ensure dependency versions used within `"dependencies"`, `"devDependencies"` etc
follow a consistent format.
Ensure dependency versions used within `"dependencies"`, `"devDependencies"` etc follow a consistent
format.

## Breaking Changes

Version [9.0.0](https://github.com/JamieMason/syncpack/releases/tag/9.0.0)
required some breaking API changes to add support for a new
[`customTypes`](https://jamiemason.github.io/syncpack/config/custom-types)
feature, but they are very simple to make.
Version [9.0.0](https://github.com/JamieMason/syncpack/releases/tag/9.0.0) required some breaking
API changes to add support for a new
[`customTypes`](https://jamiemason.github.io/syncpack/config/custom-types) feature, but they are
very simple to make.

## Badges

Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Aparajita Fishman (https://github.com/aparajita)",
"Artur Wierzbicki (https://github.com/ArturWierzbicki)",
"Daniel Silva (https://github.com/dsilvasc)",
"Jamie Haywood (https://github.com/jamiehaywood)",
"Jamie Mason (https://github.com/JamieMason)",
"Jody Heavener (https://github.com/jodyheavener)",
"Luis Vieira (https://github.com/luisvieiragmr)",
Expand All @@ -35,7 +36,7 @@
"read-yaml-file": "2.1.0",
"semver": "7.5.0",
"tightrope": "0.1.0",
"zod": "3.21.4"
"ts-toolbelt": "9.6.0"
},
"devDependencies": {
"@tsconfig/node14": "1.0.3",
Expand Down Expand Up @@ -85,6 +86,7 @@
"yarn"
],
"license": "MIT",
"main": "dist/index.js",
"repository": "JamieMason/syncpack",
"resolutions": {
"chalk": "4.1.2"
Expand All @@ -97,5 +99,6 @@
"lint": "eslint --ext .ts .",
"prepack": "yarn build",
"test": "jest src test"
}
},
"types": "dist/index.d.ts"
}
5 changes: 5 additions & 0 deletions scripts/upsert-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

filepath="$1"
touch "$filepath"
code "$filepath"
16 changes: 8 additions & 8 deletions site/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Website

This website is built using [Docusaurus 2](https://docusaurus.io/), a modern
static website generator.
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website
generator.

### Installation

Expand All @@ -15,17 +15,17 @@ $ yarn
$ yarn start
```

This command starts a local development server and opens up a browser window.
Most changes are reflected live without having to restart the server.
This command starts a local development server and opens up a browser window. Most changes are
reflected live without having to restart the server.

### Build

```
$ yarn build
```

This command generates static content into the `build` directory and can be
served using any static contents hosting service.
This command generates static content into the `build` directory and can be served using any static
contents hosting service.

### Deployment

Expand All @@ -41,5 +41,5 @@ Not using SSH:
$ GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to
build the website and push to the `gh-pages` branch.
If you are using GitHub pages for hosting, this command is a convenient way to build the website and
push to the `gh-pages` branch.
34 changes: 34 additions & 0 deletions site/docs/config-file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,37 @@ option.
"versionGroups": []
}
```

## TypeScript IntelliSense

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

:::caution

Ensure that `"javascript.validate.enable": false` is NOT set in
[VS Code](https://code.visualstudio.com/docs/getstarted/settings).

:::

```js title=".syncpackrc.js"
// @ts-check

/** @type {import("syncpack").RcFile} */
const config = {
versionGroups: [
{
dependencies: ['@types/node'],
packages: ['**'],
pinVersion: '14.18.36',
},
{
dependencies: ['chalk'],
packages: ['**'],
pinVersion: '4.1.2',
},
],
};

module.exports = config;
```
9 changes: 8 additions & 1 deletion site/docs/config/custom-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The example below adds support for synchronising versions found in:
1. The [`packageManager`](https://nodejs.org/api/packages.html#packagemanager)
string.

```json
```json title=".syncpackrc"
{
"customTypes": {
"engines": {
Expand All @@ -37,6 +37,13 @@ The example below adds support for synchronising versions found in:
}
```

:::tip

Syncpack config files also support
[TypeScript IntelliSense](https://jamiemason.github.io/syncpack/config-file#typescript-intellisense).

:::

## customTypes\[name\]

<Pills required />
Expand Down
9 changes: 8 additions & 1 deletion site/docs/config/dependency-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ and
[`devDependencies`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#devDependencies)
properties of package.json files will be inspected by syncpack:

```json
```json title=".syncpackrc"
{
"dependencyTypes": ["dev", "prod"]
}
```

:::tip

Syncpack config files also support
[TypeScript IntelliSense](https://jamiemason.github.io/syncpack/config-file#typescript-intellisense).

:::

:::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.
Expand Down
9 changes: 8 additions & 1 deletion site/docs/config/indent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ import Pills from '@site/src/components/pill';
The character(s) to be used to indent your package.json files when writing to
disk.

```json
```json title=".syncpackrc"
{
"indent": " "
}
```

:::tip

Syncpack config files also support
[TypeScript IntelliSense](https://jamiemason.github.io/syncpack/config-file#typescript-intellisense).

:::

:::info

The `indent` configuration in your [config file](../config-file.mdx) can be
Expand Down
Loading

0 comments on commit 6ca61cc

Please sign in to comment.