From 8ab986927d9e2cde1b7011809cb85ba114631739 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 1 Jul 2022 00:34:27 +0200 Subject: [PATCH] Require Node.js 14 --- .github/workflows/main.yaml | 7 ++++--- package.json | 14 +++++++------- readme.md | 38 ++++++++++++++++--------------------- source/lib/config.ts | 4 ++-- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d36e1a87..d50ada65 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -10,11 +10,12 @@ jobs: fail-fast: false matrix: node-version: + - 18 + - 16 - 14 - - 12 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/package.json b/package.json index 7665e7e1..d01c7223 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,11 @@ "email": "sam.verschueren@gmail.com", "url": "https://github.com/SamVerschueren" }, - "main": "dist/index.js", - "typings": "dist/index.d.ts", - "bin": "dist/cli.js", + "exports": "./dist/index.js", + "types": "./dist/index.d.ts", + "bin": "./dist/cli.js", "engines": { - "node": ">=12" + "node": ">=14.16" }, "scripts": { "prepublishOnly": "npm run build", @@ -39,7 +39,7 @@ "typedefinitions" ], "dependencies": { - "@tsd/typescript": "~4.7.3", + "@tsd/typescript": "~4.7.4", "eslint-formatter-pretty": "^4.1.0", "globby": "^11.0.1", "meow": "^9.0.0", @@ -48,7 +48,7 @@ }, "devDependencies": { "@ava/typescript": "^1.1.1", - "@types/node": "^14.0.0", + "@types/node": "^14.18.21", "@types/react": "^16.9.2", "@typescript-eslint/eslint-plugin": "^4.26.0", "@typescript-eslint/parser": "^4.26.0", @@ -61,7 +61,7 @@ "execa": "^5.0.0", "react": "^16.9.0", "rxjs": "^6.5.3", - "typescript": "^4.3.2" + "typescript": "~4.7.4" }, "ava": { "timeout": "2m", diff --git a/readme.md b/readme.md index a6a0f30d..eea49872 100644 --- a/readme.md +++ b/readme.md @@ -2,21 +2,18 @@ > Check TypeScript type definitions - ## Install -``` -$ npm install tsd +```sh +npm install tsd ``` - ## Overview This tool lets you write tests for your type definitions (i.e. your `.d.ts` files) by creating files with the `.test-d.ts` extension. These `.test-d.ts` files will not be executed, and not even compiled in the standard way. Instead, these files will be parsed for special constructs such as `expectError(bar)` and then statically analyzed against your type definitions. - ## Usage Let's assume we wrote a `index.d.ts` type definition for our concat module. @@ -132,8 +129,12 @@ By default, `tsd` applies the following configuration: { "strict": true, "jsx": "react", - "target": "es2017", - "lib": ["es2017"], + "target": "es2020", + "lib": [ + "es2020", + "dom", + "dom.iterable" + ], "module": "commonjs", // The following option is set and is not overridable. // It is set to `nodenext` if `module` is `nodenext`, `node16` if `module` is `node16` or `node` otherwise. @@ -154,7 +155,7 @@ These options will be overridden if a `tsconfig.json` file is found in your proj } ``` -*Default options will apply if you don't override them explicitly.* You can't override the `moduleResolution` option. +*Default options will apply if you don't override them explicitly.* You can't override the `moduleResolution` option. ## Assertions @@ -196,7 +197,6 @@ Print the type of `value` as a warning. Useful if you don't know the exact type of the expression passed to `printType()` or the type is too complex to write out by hand. - ## Programmatic API You can use the programmatic API to retrieve the diagnostics and do something with them. This can be useful to run the tests with AVA, Jest or any other testing framework. @@ -204,15 +204,13 @@ You can use the programmatic API to retrieve the diagnostics and do something wi ```ts import tsd from 'tsd'; -(async () => { - const diagnostics = await tsd(); +const diagnostics = await tsd(); - console.log(diagnostics.length); - //=> 2 -})(); +console.log(diagnostics.length); +//=> 2 ``` -### tsd([options]) +### tsd(options?) Retrieve the type definition diagnostics of the project. @@ -222,25 +220,21 @@ Type: `object` ##### cwd -Type: `string`
+Type: `string`\ Default: `process.cwd()` Current working directory of the project to retrieve the diagnostics for. ##### typingsFile -Type: `string`
+Type: `string`\ Default: The `types` property in `package.json`. Path to the type definition file you want to test. This can be useful when using a test runner to test specific type definitions per test. ##### testFiles -Type: `string[]`
+Type: `string[]`\ Default: Finds files with `.test-d.ts` or `.test-d.tsx` extension. An array of test files with their path. Uses [globby](https://github.com/sindresorhus/globby) under the hood so that you can fine tune test file discovery. - -## License - -MIT © [Sam Verschueren](https://github.com/SamVerschueren) diff --git a/source/lib/config.ts b/source/lib/config.ts index 93d19d89..5f076f3f 100644 --- a/source/lib/config.ts +++ b/source/lib/config.ts @@ -40,9 +40,9 @@ export default (pkg: PackageJsonWithTsdConfig, cwd: string): Config => { compilerOptions: { strict: true, jsx: JsxEmit.React, - lib: parseRawLibs(['es2017', 'dom', 'dom.iterable'], cwd), + lib: parseRawLibs(['es2020', 'dom', 'dom.iterable'], cwd), module, - target: ScriptTarget.ES2017, + target: ScriptTarget.ES2020, esModuleInterop: true, ...combinedCompilerOptions, moduleResolution: module === ModuleKind.NodeNext ?