Skip to content

Commit

Permalink
[Breaking] v2 implementation, tests, readme, types
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 3, 2024
1 parent 0672041 commit ddec422
Show file tree
Hide file tree
Showing 20 changed files with 525 additions and 115 deletions.
5 changes: 5 additions & 0 deletions .attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"pack": true,

"profile": "esm-only"
}
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"root": true,

"extends": "@ljharb",

"rules": {
"max-statements": 0,
},

"overrides": [
{
"files": "pargs.mjs",
"extends": "@ljharb/eslint-config/node/20",
"rules": {
"max-lines-per-function": 0,
},
},
{
"files": "./bin.mjs",
"extends": "@ljharb/eslint-config/node/20",
},
]
}
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/has-types
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with a single custom sponsorship URL
10 changes: 10 additions & 0 deletions .github/workflows/node-pretest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 'Tests: pretest/posttest'

on: [pull_request, push]

permissions:
contents: read

jobs:
tests:
uses: ljharb/actions/.github/workflows/pretest.yml@main
14 changes: 14 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Tests: node.js >= 22'

on: [pull_request, push]

permissions:
contents: read

jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '^22.11 || >= 23.3'
type: minors
command: npm run tests-only
9 changes: 9 additions & 0 deletions .github/workflows/rebase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Automatic Rebase

on: [pull_request_target]

jobs:
_:
uses: ljharb/actions/.github/workflows/rebase.yml@main
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/require-allow-edits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Require “Allow Edits”

on: [pull_request_target]

permissions:
contents: read

jobs:
_:
permissions:
pull-requests: read # for ljharb/require-allow-edits to check 'allow edits' on PR

name: "Require “Allow Edits”"

runs-on: ubuntu-latest

steps:
- uses: ljharb/require-allow-edits@main
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,5 @@ dist
npm-shrinkwrap.json
package-lock.json
yarn.lock

.npmignore
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package-lock=false
allow-same-version=true
message=v%s
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.0.0 - 2017-11-13

### Commits

- Initial commit [`cafb49b`](https://github.com/elliotblackburn/has-types/commit/cafb49b7292b7a85e4aeeccfd9f0c9425b1be8a1)
- Rename from has-types to hastypes [`8aa23de`](https://github.com/elliotblackburn/has-types/commit/8aa23deb28fbf0ada1bb47b4f1ff70b3c11847ee)
- Force node engine to be 8.9.1 or higher [`bf908d7`](https://github.com/elliotblackburn/has-types/commit/bf908d7a1a0fcab39e22b0f408668df514839ee6)
- Correct bin file [`162fb4a`](https://github.com/elliotblackburn/has-types/commit/162fb4af78f9cad3a2f4176d0595f081ef0143a0)
- 1.0.1 release [`fbcee3a`](https://github.com/elliotblackburn/has-types/commit/fbcee3a04ae4a861a1a6a0d46f8a45dd1a6b4d46)
51 changes: 39 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
# Has types?
# hastypes <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

> Check if an npm package is typescript friendly!
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

Does the given package have TypeScript types?

**Inspired by https://github.com/ofrobots/typescript-friendly**

## Installation
## Example

```
npm i -g hastypes
```sh
$ hastypes hastypes # => integrated
$ hastypes react@19 # => @types/react
$ hastypes mdpdf@1 # => none
```

## Usage
```mjs
import hasTypes from 'hastypes';
import assert from 'assert';

Simply call `hastypes` followed by an npm package name!

```sh
$ hastypes @sindresorhus/is # => integrated
$ hastypes express # => @types/express
$ hastypes mdpdf # => none
hasTypes('hastypes').then(x => assert.equal(x, true));
hasTypes('react@19').then(x => assert.equal(x, '@types/react'));
hasTypes('mdpdf@1').then(x => assert.equal(x, false));
```

## Tests
Simply clone the repo, `npm install`, and run `npm test`

[package-url]: https://npmjs.org/package/hastypes
[npm-version-svg]: https://versionbadg.es/elliotblackburn/has-types.svg
[deps-svg]: https://david-dm.org/elliotblackburn/has-types.svg
[deps-url]: https://david-dm.org/elliotblackburn/has-types
[dev-deps-svg]: https://david-dm.org/elliotblackburn/has-types/dev-status.svg
[dev-deps-url]: https://david-dm.org/elliotblackburn/has-types#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/hastypes.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/hastypes.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/hastypes.svg
[downloads-url]: https://npm-stat.com/charts.html?package=hastypes
[codecov-image]: https://codecov.io/gh/elliotblackburn/has-types/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/elliotblackburn/has-types/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/elliotblackburn/has-types
[actions-url]: https://github.com/elliotblackburn/has-types/actions
63 changes: 63 additions & 0 deletions bin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#! /usr/bin/env node

import { readFileSync } from 'fs';
import { join } from 'path';

import npa from 'npm-package-arg';

import pargs from './pargs.mjs';

const help = readFileSync(join(import.meta.dirname, './help.txt'), 'utf8');

const {
positionals,
values: { before },
} = pargs(help, import.meta.url, {
allowPositionals: true,
options: {
before: {
type: 'string',
},
},
});

const specifiers = positionals.slice(1);

if (specifiers.length !== 1) {
console.error('You must provide exactly one specifier');
process.exit(1);
}

if (typeof before !== 'undefined' && typeof before !== 'string') {
console.error('`before` option must be a valid Date value');
process.exit(1);
}

let name, rawSpec;
try {
({ name, rawSpec } = npa(specifiers[0]));
if (rawSpec === '*') {
rawSpec = 'latest';
}
} catch (e) {
// eslint-disable-next-line no-extra-parens
console.error(/** @type {Error} */ (e)?.message ?? 'Unknown error');
process.exit(1);
}

import hasTypes from './index.mjs';

import mockProperty from 'mock-property';

// eslint-disable-next-line no-empty-function, no-extra-parens
const restore = mockProperty(/** @type {Parameters<typeof mockProperty>[0]} */ (/** @type {unknown} */ (console)), 'error', { value() {} });
const promise = hasTypes(specifiers[0], { before });

promise.finally(() => {
restore();
}).catch((e) => {
console.error(e.message);
process.exit(1);
}).then((r) => {
console.log(`${name}@${rawSpec} ${typeof r === 'string' ? r : r ? 'integrated' : 'none'}`);
});
67 changes: 0 additions & 67 deletions bin/index.js

This file was deleted.

8 changes: 8 additions & 0 deletions help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Usage: has-types [--before=MM/DD/YYYY] <package-specifier>

`package-specifier` must be a valid registry specifier according to `npm-package-arg`.

- see https://www.npmjs.com/package/npm-package-arg

Options:
`--before`: npm‘s `before` option. Must be a valid date.
8 changes: 8 additions & 0 deletions index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare function hasTypes(
specifier: string,
options?: {
before?: string;
},
): Promise<`@types/${string}` | boolean>;

export default hasTypes;
Loading

0 comments on commit ddec422

Please sign in to comment.