Skip to content

Commit

Permalink
chore: update repo
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 17, 2024
1 parent 8c508e0 commit f289b3a
Show file tree
Hide file tree
Showing 11 changed files with 3,901 additions and 3,214 deletions.
9 changes: 0 additions & 9 deletions .eslintrc

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/autofix.yml
@@ -0,0 +1,25 @@
name: autofix.ci # needed to securely identify the workflow

on:
pull_request:
push:
branches: ["main"]

permissions:
contents: read

jobs:
autofix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm lint:fix
- uses: autofix-ci/action@ea32e3a12414e6d3183163c3424a7d7a8631ad84
with:
commit-message: "chore: apply automated updates"
22 changes: 4 additions & 18 deletions .github/workflows/ci.yml
Expand Up @@ -9,32 +9,18 @@ on:
- main

jobs:
lint:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm lint

ci:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 16
cache: "pnpm"
- run: pnpm install
- run: pnpm prepack
- run: pnpm test
- run: pnpm test:types
- run: pnpm build
- run: pnpm vitest --coverage
- uses: codecov/codecov-action@v4
87 changes: 55 additions & 32 deletions README.md
@@ -1,96 +1,110 @@
# pkg-types

> Node.js utilities and TypeScript definitions for `package.json` and `tsconfig.json`
<!-- automd:badges color=yellow codecov -->

```
\⍩⃝/
```
[![npm version](https://img.shields.io/npm/v/pkg-types?color=yellow)](https://npmjs.com/package/pkg-types)
[![npm downloads](https://img.shields.io/npm/dm/pkg-types?color=yellow)](https://npmjs.com/package/pkg-types)
[![codecov](https://img.shields.io/codecov/c/gh/unjs/pkg-types?color=yellow)](https://codecov.io/gh/unjs/pkg-types)

<!-- /automd -->

Node.js utilities and TypeScript definitions for `package.json` and `tsconfig.json`.

## Install

<!-- automd:pm-i -->

```sh
# ✨ Auto-detect
npx nypm install pkg-types

# npm
npm i pkg-types
npm install pkg-types

# yarn
yarn add pkg-types

# pnpm
pnpm add pkg-types
pnpm install pkg-types

# bun
bun install pkg-types
```

<!-- /automd -->

## Usage

### `readPackageJSON`

```js
import { readPackageJSON } from 'pkg-types'
const localPackageJson = await readPackageJSON()
import { readPackageJSON } from "pkg-types";
const localPackageJson = await readPackageJSON();
// or
const packageJson = await readPackageJSON('/fully/resolved/path/to/folder')
const packageJson = await readPackageJSON("/fully/resolved/path/to/folder");
```

### `writePackageJSON`

```js
import { writePackageJSON } from 'pkg-types'
import { writePackageJSON } from "pkg-types";

await writePackageJSON('path/to/package.json', pkg)
await writePackageJSON("path/to/package.json", pkg);
```

### `resolvePackageJSON`

```js
import { resolvePackageJSON } from 'pkg-types'
const filename = await resolvePackageJSON()
import { resolvePackageJSON } from "pkg-types";
const filename = await resolvePackageJSON();
// or
const packageJson = await resolvePackageJSON('/fully/resolved/path/to/folder')
const packageJson = await resolvePackageJSON("/fully/resolved/path/to/folder");
```

### `readTSConfig`

```js
import { readTSConfig } from 'pkg-types'
const tsconfig = await readTSConfig()
import { readTSConfig } from "pkg-types";
const tsconfig = await readTSConfig();
// or
const tsconfig = await readTSConfig('/fully/resolved/path/to/folder')
const tsconfig2 = await readTSConfig("/fully/resolved/path/to/folder");
```

### `writeTSConfig`

```js
import { writeTSConfig } from 'pkg-types'
import { writeTSConfig } from "pkg-types";

await writeTSConfig('path/to/tsconfig.json', tsconfig)
await writeTSConfig("path/to/tsconfig.json", tsconfig);
```

### `resolveTSConfig`

```js
import { resolveTSConfig } from 'pkg-types'
const filename = await resolveTSConfig()
import { resolveTSConfig } from "pkg-types";
const filename = await resolveTSConfig();
// or
const tsconfig = await resolveTSConfig('/fully/resolved/path/to/folder')
const tsconfig = await resolveTSConfig("/fully/resolved/path/to/folder");
```

### `resolveFile`

```js
import { resolveFile } from 'pkg-types'
const filename = await resolveFile('README.md', {
import { resolveFile } from "pkg-types";
const filename = await resolveFile("README.md", {
startingFrom: id,
rootPattern: /^node_modules$/,
matcher: filename => filename.endsWith('.md'),
})
matcher: (filename) => filename.endsWith(".md"),
});
```

### `resolveLockFile`

Find path to the lock file (`yarn.lock`, `package-lock.json`, `pnpm-lock.yaml`, `npm-shrinkwrap.json`) or throws an error.

```js
import { resolveLockFile } from 'pkg-types'
const lockfile = await resolveLockFile('.')
import { resolveLockFile } from "pkg-types";
const lockfile = await resolveLockFile(".");
```

### `findWorkspaceDir`
Expand All @@ -104,8 +118,8 @@ Try to detect workspace dir by in order:
If fails, throws an error.

```js
import { findWorkspaceDir } from 'pkg-types'
const workspaceDir = await findWorkspaceDir('.')
import { findWorkspaceDir } from "pkg-types";
const workspaceDir = await findWorkspaceDir(".");
```

## Types
Expand All @@ -115,7 +129,7 @@ const workspaceDir = await findWorkspaceDir('.')
You can directly use typed interfaces:

```ts
import type { TSConfig, PackageJSON } from 'pkg-types'
import type { TSConfig, PackageJSON } from "pkg-types";
```

You can also use define utils for type support for using in plain `.js` files and auto-complete in IDE.
Expand All @@ -138,4 +152,13 @@ const pkg = defineTSConfig({})

## License

MIT - Made with 💛
<!-- automd:contributors license=MIT author="pi0,danielroe" -->

Published under the [MIT](https://github.com/unjs/pkg-types/blob/main/LICENSE) license.
Made by [@pi0](https://github.com/pi0), [@danielroe](https://github.com/danielroe) and [community](https://github.com/unjs/pkg-types/graphs/contributors) 💛
<br><br>
<a href="https://github.com/unjs/pkg-types/graphs/contributors">
<img src="https://contrib.rocks/image?repo=unjs/pkg-types" />
</a>

<!-- /automd -->
11 changes: 11 additions & 0 deletions eslint.config.mjs
@@ -0,0 +1,11 @@
import unjs from 'eslint-config-unjs';

export default unjs(
{
ignores: [
]
},
{
rules: {}
}
);
21 changes: 11 additions & 10 deletions package.json
Expand Up @@ -19,8 +19,8 @@
"prepack": "unbuild",
"dev": "vitest",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
"lint:fix": "eslint --fix --ext .ts,.js,.mjs,.cjs . && prettier -w src test",
"lint": "eslint && prettier -c src test",
"lint:fix": "automd && eslint --fix . && prettier -w src test",
"test": "vitest run --coverage",
"test:types": "tsc --noEmit --module esnext --skipLibCheck --moduleResolution node ./test/*.test.ts"
},
Expand All @@ -30,17 +30,18 @@
"pathe": "^1.1.2"
},
"devDependencies": {
"@types/node": "^20.12.4",
"@vitest/coverage-v8": "^1.4.0",
"@types/node": "^20.12.7",
"@vitest/coverage-v8": "^1.5.0",
"automd": "^0.3.7",
"changelogen": "^0.5.5",
"eslint": "^8.57.0",
"eslint-config-unjs": "^0.2.1",
"eslint": "^9.0.0",
"eslint-config-unjs": "^0.3.0-rc.6",
"expect-type": "^0.19.0",
"jiti": "^1.21.0",
"prettier": "^2.8.8",
"typescript": "^5.4.4",
"prettier": "^3.2.5",
"typescript": "^5.4.5",
"unbuild": "^2.0.0",
"vitest": "^1.4.0"
"vitest": "^1.5.0"
},
"packageManager": "pnpm@8.15.6"
"packageManager": "pnpm@9.0.1"
}

0 comments on commit f289b3a

Please sign in to comment.