Skip to content

Commit

Permalink
update deps, remove index.d.ts rule, style updates, bundle types
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Feb 23, 2024
1 parent 9c0a79a commit 13e610c
Show file tree
Hide file tree
Showing 53 changed files with 258 additions and 498 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
node_modules
yarn.lock
dist/
.tsimp
56 changes: 32 additions & 24 deletions package.json
Expand Up @@ -10,16 +10,18 @@
"url": "https://github.com/SamVerschueren"
},
"type": "module",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"bin": "./dist/cli.js",
"engines": {
"node": ">=18"
},
"scripts": {
"prepublishOnly": "npm run build",
"test": "xo && tsc --project tsconfig.tsd.json --noEmit && ava",
"build": "del-cli dist && tsc --project tsconfig.tsd.json && chmod +x dist/cli.js"
"build": "tsc --project tsconfig.build.json && chmod +x dist/cli.js && tsup"
},
"files": [
"dist/**/*.js",
Expand All @@ -37,40 +39,38 @@
],
"dependencies": {
"@tsd/typescript": "~5.3.3",
"eslint-formatter-pretty": "^5.0.0",
"globby": "^13.1.3",
"jest-diff": "^29.5.0",
"meow": "^11.0.0",
"p-map": "^5.5.0",
"eslint-formatter-pretty": "^6.0.1",
"globby": "^14.0.1",
"jest-diff": "^29.7.0",
"meow": "^13.2.0",
"p-map": "^7.0.1",
"path-exists": "^5.0.0",
"read-pkg-up": "^9.1.0"
"read-package-up": "^11.0.0"
},
"devDependencies": {
"@types/common-tags": "^1.8.1",
"@types/node": "^16",
"@types/react": "^16.9.2",
"ava": "^5.2.0",
"@sindresorhus/tsconfig": "^5.0.0",
"@types/common-tags": "^1.8.4",
"@types/node": "^18",
"@types/react": "^18",
"ava": "^6.1.1",
"common-tags": "^1.8.2",
"del-cli": "^3.0.0",
"execa": "^7.1.1",
"eslint": "^8.56.0",
"execa": "^8.0.1",
"react": "^16.9.0",
"resolve-from": "^5.0.0",
"rxjs": "^6.5.3",
"tsx": "^3.12.6",
"typescript": "~5.0.3",
"xo": "^0.53.1"
"tsimp": "^2.0.11",
"tsup": "^8.0.2",
"typescript": "~5.3.3",
"xo": "^0.57.0"
},
"ava": {
"timeout": "2m",
"files": [
"source/test/**/*",
"!source/test/fixtures/**/*"
],
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=tsx"
"--import=tsimp"
],
"environmentVariables": {
"ESBK_TSCONFIG_PATH": "tsconfig.tsd.json"
Expand All @@ -81,7 +81,15 @@
"source/test/fixtures"
],
"rules": {
"no-bitwise": "off"
"no-bitwise": "off",
"unicorn/prevent-abbreviations": [
"error",
{
"replacements": {
"doc": false
}
}
]
}
}
}
25 changes: 10 additions & 15 deletions source/cli.ts 100644 → 100755
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env tsimp
import process from 'node:process';
import meow from 'meow';
import {TsdError} from './lib/interfaces.js';
Expand All @@ -9,21 +9,20 @@ const cli = meow(`
Usage
$ tsd [path]
The given directory must contain a package.json and a typings file.
The given directory must contain a package.json.
Info
--help Display help text
--version Display version info
Options
--typings -t Type definition file to test [Default: "types" property in package.json]
--files -f Glob of files to test [Default: '/path/test-d/**/*.test-d.ts' or '.tsx']
--show-diff Show type error diffs [Default: don't show]
--files -f Glob of files to test [Default: 'path/test-d/**/*.test-d.ts']
--show-diff Show type error diffs [Default: don't show]
Examples
$ tsd /path/to/project
$ tsd path/to/project
$ tsd --files /test/some/folder/*.ts --files /test/other/folder/*.tsx
$ tsd --files test/some/folder/*.ts --files test/other/folder/*.tsx
$ tsd
Expand All @@ -32,13 +31,9 @@ const cli = meow(`
`, {
importMeta: import.meta,
flags: {
typings: {
type: 'string',
alias: 't',
},
files: {
type: 'string',
alias: 'f',
shortFlag: 'f',
isMultiple: true,
},
showDiff: {
Expand All @@ -65,17 +60,17 @@ const exit = (message: string, {isError = true}: {isError?: boolean} = {}) => {

try {
const cwd = cli.input.at(0) ?? process.cwd();

Check failure on line 62 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 20

Unsafe assignment of an `any` value.

Check failure on line 62 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 20

Unsafe call of an `any` typed value.

Check failure on line 62 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 20

Unsafe call of an `any` typed value.

Check failure on line 62 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Unsafe assignment of an `any` value.

Check failure on line 62 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Unsafe call of an `any` typed value.

Check failure on line 62 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Unsafe call of an `any` typed value.
const {typings: typingsFile, files: testFiles, showDiff} = cli.flags;
const {files: testFiles, showDiff} = cli.flags;

Check failure on line 63 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 20

Unsafe assignment of an `any` value.

Check failure on line 63 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Unsafe assignment of an `any` value.

const diagnostics = await tsd({cwd, typingsFile, testFiles});
const diagnostics = await tsd({cwd, testFiles});

Check failure on line 65 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 20

Unsafe assignment of an `any` value.

Check failure on line 65 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 20

Unsafe assignment of an `any` value.

Check failure on line 65 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Unsafe assignment of an `any` value.

Check failure on line 65 in source/cli.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Unsafe assignment of an `any` value.

if (diagnostics.length > 0) {
const hasErrors = diagnostics.some(diagnostic => diagnostic.severity === 'error');
const formattedDiagnostics = formatter(diagnostics, showDiff);

exit(formattedDiagnostics, {isError: hasErrors});
}
} catch (error: unknown) {
} catch (error) {
const potentialError = error as Error | undefined;

if (potentialError instanceof TsdError) {
Expand Down
51 changes: 12 additions & 39 deletions source/lib/assertions/assert.ts
Expand Up @@ -3,72 +3,51 @@
*
* @param expression - Expression that should be identical to type `T`.
*/
// @ts-expect-error: "expression is never read"
export const expectType = <T>(expression: T) => {
// Do nothing, the TypeScript compiler handles this for us
};
export declare const expectType: <T>(expression: T) => void;

/**
* Asserts that the type of `expression` is not identical to type `T`.
*
* @param expression - Expression that should not be identical to type `T`.
*/
// @ts-expect-error: "expression is never read"
export const expectNotType = <T>(expression: any) => {
// eslint-disable-next-line no-warning-comments
// TODO Use a `not T` type when possible https://github.com/microsoft/TypeScript/pull/29317
// Do nothing, the TypeScript compiler handles this for us
};
*/
// eslint-disable-next-line no-warning-comments
// TODO Use a `not T` type when possible https://github.com/microsoft/TypeScript/pull/29317
export declare const expectNotType: <T>(expression: any) => void;

/**
* Asserts that the type of `expression` is assignable to type `T`.
*
* @param expression - Expression that should be assignable to type `T`.
*/
// @ts-expect-error: "expression is never read"
export const expectAssignable = <T>(expression: T) => {
// Do nothing, the TypeScript compiler handles this for us
};
export declare const expectAssignable: <T>(expression: T) => void;

/**
* Asserts that the type of `expression` is not assignable to type `T`.
*
* @param expression - Expression that should not be assignable to type `T`.
*/
// @ts-expect-error: "expression is never read"
export const expectNotAssignable = <T>(expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};
export declare const expectNotAssignable: <T>(expression: any) => void;

/**
* Asserts that `expression` throws an error. Will not ignore syntax errors.
*
* @param expression - Expression that should throw an error.
*/
// @ts-expect-error: "expression is never read"
export const expectError = <T = any>(expression: T) => {
// Do nothing, the TypeScript compiler handles this for us
};
export declare const expectError: <T = any>(expression: T) => void;

/**
* Asserts that `expression` is marked as `@deprecated`.
*
* @param expression - Expression that should be marked as `@deprecated`.
*/
// @ts-expect-error: "expression is never read"
export const expectDeprecated = (expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};
export declare const expectDeprecated: (expression: any) => void;

/**
* Asserts that `expression` is not marked as `@deprecated`.
*
* @param expression - Expression that should not be marked as `@deprecated`.
*/
// @ts-expect-error: "expression is never read"
export const expectNotDeprecated = (expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};
export declare const expectNotDeprecated: (expression: any) => void;

/**
* Asserts that the type and return type of `expression` is `never`.
Expand All @@ -84,17 +63,11 @@ export const expectNever = (expression: never): never => expression;
*
* @param expression - Expression whose type should be printed as a warning.
*/
// @ts-expect-error: "expression is never read"
export const printType = (expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};
export declare const printType: (expression: any) => void;

/**
* Asserts that the documentation comment of `expression` includes string literal type `T`.
*
* @param expression - Expression whose documentation comment should include string literal type `T`.
*/
// @ts-expect-error: "expression is never read"
export const expectDocCommentIncludes = <T>(expression: any) => {
// Do nothing, the TypeScript compiler handles this for us
};
export declare const expectDocCommentIncludes: <T>(expression: any) => void;
7 changes: 6 additions & 1 deletion source/lib/compiler.ts
@@ -1,6 +1,11 @@
import ts, {type Diagnostic as TSDiagnostic} from '@tsd/typescript';
import {type ExpectedError, extractAssertions, parseErrorAssertionToLocation} from './parser.js';
import {type Diagnostic, DiagnosticCode, type Context, type Location} from './interfaces.js';
import {
DiagnosticCode,
type Diagnostic,
type Context,
type Location,
} from './interfaces.js';
import {handle} from './assertions/index.js';

// List of diagnostic codes that should be ignored in general
Expand Down
10 changes: 6 additions & 4 deletions source/lib/config.ts
@@ -1,18 +1,20 @@
import ts, {type CompilerOptions} from '@tsd/typescript';
import type {Config, PackageJsonWithTsdConfig, RawCompilerOptions} from './interfaces.js';

// TODO: update this

/**
* Load the configuration settings.
*
* @param pkg - The package.json object.
* @returns The config object.
*/
const loadConfig = (pkg: PackageJsonWithTsdConfig, cwd: string): Config => {
const pkgConfig = pkg.tsd ?? {};
const loadConfig = (package_: PackageJsonWithTsdConfig, cwd: string): Config => {
const packageConfig = package_.tsd ?? {};

const tsConfigCompilerOptions = getOptionsFromTsConfig(cwd);
const packageJsonCompilerOptions = parseCompilerConfigObject(
pkgConfig.compilerOptions ?? {},
packageConfig.compilerOptions ?? {},
cwd,
);

Expand All @@ -25,7 +27,7 @@ const loadConfig = (pkg: PackageJsonWithTsdConfig, cwd: string): Config => {

return {
directory: 'test-d',
...pkgConfig,
...packageConfig,
compilerOptions: {
strict: true,
jsx: ts.JsxEmit.React,
Expand Down
1 change: 1 addition & 0 deletions source/lib/formatter.ts
Expand Up @@ -59,6 +59,7 @@ const formatter = (diagnostics: Diagnostic[], showDiff = false): string => {
entry.messages.push(diagnostic);
}

// @ts-expect-error
return String(prettyFormatter([...fileMap.values()]));
};

Expand Down

0 comments on commit 13e610c

Please sign in to comment.