Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize Build... #134

Merged
merged 38 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2d4e811
feat: modernize
lishaduck Nov 30, 2024
16f358c
ci: see if green w/out 16
lishaduck Nov 30, 2024
0016f81
ci: add 22 to matrix
lishaduck Nov 30, 2024
b8a2f78
fix: use tilde ranges for DefinitelyTyped
lishaduck Nov 30, 2024
dbbd72f
fix: constrain engines to eslint-compatible versions
lishaduck Nov 30, 2024
d84285c
chore: use json modules instead of require(json)
lishaduck Nov 30, 2024
ef1e97f
chore: remove redundant mocks
lishaduck Nov 30, 2024
07cc2b9
fix: reset mocks after tests
lishaduck Nov 30, 2024
ee1e104
fix: type mocks
lishaduck Nov 30, 2024
956734b
chore: enable requireAssertions for tests
lishaduck Nov 30, 2024
08f2bea
chore: update coverage ignores
lishaduck Nov 30, 2024
c5add31
chore: enable vitest ui
lishaduck Nov 30, 2024
b629ef8
refactor: array operations
lishaduck Nov 30, 2024
6499bdc
fix: mark methods as pure functions
lishaduck Nov 30, 2024
f08956d
fix: windows root
lishaduck Nov 30, 2024
404de28
fix: race condition
lishaduck Nov 30, 2024
4144051
docs: rephrase comment
lishaduck Nov 30, 2024
278d3bc
refactor: use tinyglobby
lishaduck Nov 30, 2024
1257d5f
style: remove underscore from name
lishaduck Nov 30, 2024
0b055e8
style: remove redundant parameters
lishaduck Nov 30, 2024
ea631a0
refactor: make test more concurrent
lishaduck Nov 30, 2024
88b5ba7
docs: update readme
lishaduck Nov 30, 2024
b1edbb4
fix: re-add coverage ignore for obscure errors
lishaduck Nov 30, 2024
9b50b40
ci: bump actions
lishaduck Nov 30, 2024
aca5fa3
chore: update sindre packages
lishaduck Nov 30, 2024
4107ebd
fix: tinyglobby path
lishaduck Dec 1, 2024
48c3507
fix: use a directory in test
lishaduck Dec 1, 2024
bcb0c28
refactor: clarify glob functionality
lishaduck Dec 1, 2024
ba79fd0
refactor: move ensureWorkspacesArray function to workspace-resolver
lishaduck Dec 1, 2024
0c6af43
chore: add build:watch script to package.json
lishaduck Dec 1, 2024
d0221c4
chore: remove lint-staged configuration from package.json
lishaduck Dec 1, 2024
050746a
fix: handle workspaces when root isn't cwd
lishaduck Dec 1, 2024
61a4cfa
fix: enforce async rules
lishaduck Dec 1, 2024
09a8ed5
perf: tinyglobby takes patterns for ignores
lishaduck Dec 1, 2024
6716a53
refactor: expect rejection
lishaduck Dec 1, 2024
41c380e
ci: don't run fixes in ci
lishaduck Dec 2, 2024
290e888
style: format utils
lishaduck Dec 2, 2024
d526f9d
chore: update es version
lishaduck Dec 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .eslintrc.cjs

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ jobs:
fail-fast: true
matrix:
version:
- 16
- 18
- 20
- 22
- current
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.version }}
cache: 'npm'
Expand All @@ -41,7 +41,7 @@ jobs:
run: npm run lint

- name: Test
run: npm run cover
run: npm run test

- name: Coveralls
uses: coverallsapp/github-action@v2
Expand Down
7 changes: 0 additions & 7 deletions .typesyncrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,3 @@ ignorePackages:
# These packages are dev tools and we don't need their typings.
- nodemon
- prettier
- rimraf
- eslint
# Can't upgrade these libraries yet since they require ESM.
- chalk
- detect-indent
- ora
- eslint-config-prettier
6 changes: 2 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"**/CVS": true,
"**/.DS_Store": true,
"node_modules": true,
"coverage": true,
"lib": true
"coverage": true
},
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.useFlatConfig": false
"typescript.tsdk": "node_modules/typescript/lib"
}
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
# typesync
# TypeSync

Install missing TypeScript typings for dependencies in your `package.json`.

[![npm](https://img.shields.io/npm/v/typesync.svg?maxAge=1000)](https://www.npmjs.com/package/typesync)
[![dependency Status](https://img.shields.io/david/jeffijoe/typesync.svg?maxAge=1000)](https://david-dm.org/jeffijoe/typesync)
[![devDependency Status](https://img.shields.io/david/dev/jeffijoe/typesync.svg?maxAge=1000)](https://david-dm.org/jeffijoe/typesync)
[![Build Status](https://img.shields.io/travis/jeffijoe/typesync.svg?maxAge=1000)](https://travis-ci.com/jeffijoe/typesync)
[![Build Status](https://github.com/jeffijoe/typesync/workflows/ci.yml/badge.svg?branch=master)](https://github.com/jeffijoe/typesync/actions)
[![Coveralls](https://img.shields.io/coveralls/jeffijoe/typesync.svg?maxAge=1000)](https://coveralls.io/github/jeffijoe/typesync)
[![npm](https://img.shields.io/npm/dt/typesync.svg?maxAge=1000)](https://www.npmjs.com/package/typesync)
[![npm](https://img.shields.io/npm/l/typesync.svg?maxAge=1000)](https://github.com/jeffijoe/typesync/blob/master/LICENSE.md)
[![license](https://img.shields.io/npm/l/typesync.svg?maxAge=1000)](https://github.com/jeffijoe/typesync/blob/master/LICENSE.md)
[![node](https://img.shields.io/node/v/typesync.svg?maxAge=1000)](https://www.npmjs.com/package/typesync)

![TypeSync](/typesync.gif)

# Install
## Install

```
```sh
npm install -g typesync
```

You can also use it directly with `npx` which will install it for you:

```
```sh
npx typesync
```

# Usage
## Usage

```
```sh
typesync [path/to/package.json] [--dry]
```

Path is relative to the current working directory. If omitted, defaults to `package.json`.

**Note**: `typesync` only modifies your `package.json` - you still need to run `npm install`, or — if drinking the k00laid — `yarn`.
**Note**: TypeSync only modifies your `package.json` - you still need to run an installer.

## `--dry[=fail]`
### `--dry[=fail]`

If `--dry` is specified, will not actually write to the file, it only prints added/removed typings.

The same is true for `--dry=fail`, with the additional effect of failing the command in case there are changes.
This is useful for CI scenarios.

## `--ignoredeps`
### `--ignoredeps`

To ignore certain sections, you can use the `--ignoredeps=` flag. For example, to ignore `devDependencies`, use `--ignoredeps=dev`. To ignore multiple, comma-separate them, like this: `--ignoredeps=deps,peer` (ignores `dependencies` and `peerDependencies`).

Expand All @@ -51,12 +49,12 @@ To ignore certain sections, you can use the `--ignoredeps=` flag. For example, t
- `--ignoredeps=peer` — ignores `peerDependencies`
- `--ignoredeps=optional` — ignores `optionalDependencies`

## `--ignorepackages`
### `--ignorepackages`

To ignore certain packages, you can use the `--ignorepackages=` flag. For example, to ignore `nodemon`, use `--ignorepackages=nodemon`.
To ignore multiple, comma-separate them, like this: `--ignorepackages=nodemon,whatever` (ignores `nodemon` and `whatever`).

## Using a config file
### Using a config file

Alternatively, you can use a TypeSync config file: `.typesyncrc` or a `"typesync"` section in your `package.json`. TypeSync will **automatically** search for configuration files. See [cosmiconfig][cosmiconfig] for details.

Expand All @@ -68,7 +66,7 @@ Alternatively, you can use a TypeSync config file: `.typesyncrc` or a `"typesync
}
```

## Run TypeSync Automatically After Every Install
### Run TypeSync automatically after every install

To run TypeSync and install packages automatically after every package install, create a file called `install-with-types.sh` with the following content:

Expand Down Expand Up @@ -104,39 +102,39 @@ Add the following to `package.json`:

Then install packages like this:

```bash
```sh
npm run i <pkg name>

# Or, with yarn:
# Or with Yarn:
yarn i <pkg name>
```

# Typings packages
## Typings packages

TypeSync will add typings for packages that:

- have a `@types/package` available
- don't already provide typings internally (the `typings` and `types` field in `package.json`)

TypeSync will try to respect semver parity for the code and typings packages, and will fall back to the latest available typings package.
TypeSync will try to respect SemVer parity for the code and typings packages, and will fall back to the latest available typings package.

When writing the typings package version to `package.json`, the `~` semver range is used. This is because typings published via [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped#how-do-definitely-typed-package-versions-relate-to-versions-of-the-corresponding-library) align typings versions with library versions using major and minor only.
When writing the typings package version to `package.json`, the `~` SemVer range is used. This is because typings published via [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped#how-do-definitely-typed-package-versions-relate-to-versions-of-the-corresponding-library) align typings versions with library versions using major and minor only.

For example, if you depend on `react@^16.14.0`, then TypeSync will only look for typings packages that match `16.14.*`.

# Monorepos
## Monorepos

TypeSync added support for monorepos in v0.4.0. It will look at `packages`/`workspaces` globs in `package.json` and sync every matching file in one fell swoop.

# Why?
## Why?

Installing typings manually sucks. Flow has `flow-typed` which installs type definitions by looking at a `package.json`, which would be cool to have for TypeScript. Now we do!

# Changelog
## Changelog

See [CHANGELOG.md](/CHANGELOG.md)

# Author
## Author

Jeff Hansen - [@Jeffijoe](https://twitter.com/jeffijoe)

Expand Down
4 changes: 2 additions & 2 deletions bin/typesync
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
const { startCli } = require('../lib/cli')
import { startCli } from '../dist/cli.js'

startCli()
await startCli()
78 changes: 78 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// @ts-check
import * as path from 'node:path'
import { fileURLToPath } from 'node:url'
import pluginJs from '@eslint/js'
import globals from 'globals'
import tseslint from 'typescript-eslint'

const dirname = path.dirname(fileURLToPath(import.meta.url))

const extensions = '{js,mjs,cjs,ts}'

export default tseslint.config(
{
files: [`src/*.${extensions}`, `bin/*`, `*.${extensions}`],
},
{
ignores: [`dist/`, 'coverage/'],
},
{
languageOptions: {
globals: globals.node,
parserOptions: {
projectService: {
allowDefaultProject: [`*.config.${extensions}`],
},
tsconfigRootDir: dirname,
},
},
linterOptions: { reportUnusedDisableDirectives: 'error' },
},
pluginJs.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
rules: {
// Only disabling these because this code is very old but also battle-tested,
// and coming up with clever typings may break for consumers.
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',

'@typescript-eslint/return-await': ['error', 'always'],
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/no-confusing-void-expression': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',

// We prefer generic arrays.
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
// We should ignore unused vars with underscores.
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/prefer-nullish-coalescing': [
'error',
{ ignoreConditionalTests: false },
],
},
},
{
files: [`src/__tests__/**/*.${extensions}`],
rules: {
// In tests, sometimes we need to make things asynchronous.
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/no-empty-function': 'off',
},
},
)
Loading