From 7839f46e073fa034346decb16760bfd400d0dc32 Mon Sep 17 00:00:00 2001 From: Tony133 Date: Mon, 11 May 2026 09:42:56 +0200 Subject: [PATCH] refactor(types): migrate from tsd to tstyche --- generate-plugin.js | 14 +++++++------- package.json | 9 +++------ .../plugin/test/{index.test-d.ts => index.tst.ts} | 4 ++-- test/generate-plugin.test.js | 6 +++--- 4 files changed, 15 insertions(+), 18 deletions(-) rename templates/plugin/test/{index.test-d.ts => index.tst.ts} (73%) diff --git a/generate-plugin.js b/generate-plugin.js index 237706e7..07efb919 100755 --- a/generate-plugin.js +++ b/generate-plugin.js @@ -22,7 +22,7 @@ const pluginTemplate = { lint: 'standard && npm run lint:typescript', 'lint:typescript': 'ts-standard', test: 'npm run lint && npm run unit && npm run test:typescript', - 'test:typescript': 'tsd', + 'test:typescript': 'tstyche', unit: 'node --test' }, dependencies: { @@ -34,16 +34,16 @@ const pluginTemplate = { 'fastify-tsconfig': cliPkg.devDependencies['fastify-tsconfig'], standard: cliPkg.devDependencies.standard, 'ts-standard': cliPkg.devDependencies['ts-standard'], - tsd: cliPkg.devDependencies.tsd, + tstyche: cliPkg.devDependencies.tstyche, typescript: cliPkg.devDependencies.typescript }, - tsd: { - directory: 'test' - }, logInstructions: function (pkg) { log('debug', 'saved package.json') log('info', `project ${pkg.name} generated successfully`) - log('debug', `run '${chalk.bold('npm install')}' to install the dependencies`) + log( + 'debug', + `run '${chalk.bold('npm install')}' to install the dependencies` + ) log('debug', `run '${chalk.bold('npm test')}' to execute the tests`) } } @@ -69,7 +69,7 @@ async function generate (dir, template) { pkg.scripts = Object.assign(pkg.scripts || {}, template.scripts) pkg.dependencies = Object.assign(pkg.dependencies || {}, template.dependencies) pkg.devDependencies = Object.assign(pkg.devDependencies || {}, template.devDependencies) - pkg.tsd = Object.assign(pkg.tsd || {}, template.tsd) + pkg.tstyche = Object.assign(pkg.tstyche || {}, template.tstyche) log('debug', 'edited package.json, saving') diff --git a/package.json b/package.json index 0bb917d7..8718c2f9 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "unit:cli-ts": "cross-env TS_NODE_PROJECT=./test/configs/ts-cjs.tsconfig.json node -r ts-node/register suite-runner.js \"test/**/*.test.ts\"", "unit:cli": "npm run unit:cli-js && npm run unit:cli-ts && npm run unit:cli-js-esm", "test:cli-and-typescript": "npm run unit:cli && npm run test:typescript", - "test:typescript": "tsd templates/plugin -t ./../../index.d.ts && tsc --project templates/app-ts/tsconfig.json --noEmit && tsc --project templates/app-ts-esm/tsconfig.json --noEmit" + "test:typescript": "tstyche" }, "keywords": [ "fastify", @@ -80,11 +80,8 @@ "strip-ansi": "^6.0.1", "ts-node": "^10.4.0", "ts-standard": "^12.0.1", - "tsd": "^0.33.0", + "tstyche": "^7.0.0", "typescript": "~6.0.2", "walker": "^1.0.8" - }, - "tsd": { - "directory": "test" } -} +} \ No newline at end of file diff --git a/templates/plugin/test/index.test-d.ts b/templates/plugin/test/index.tst.ts similarity index 73% rename from templates/plugin/test/index.test-d.ts rename to templates/plugin/test/index.tst.ts index 8c30185a..defa8f95 100644 --- a/templates/plugin/test/index.test-d.ts +++ b/templates/plugin/test/index.tst.ts @@ -1,6 +1,6 @@ import fastify from 'fastify' import example from '..' -import { expectType } from 'tsd' +import { expect } from 'tstyche' let app try { @@ -9,7 +9,7 @@ try { void app.ready() // eslint-disable-next-line no-void void app.register(example) - expectType<() => string>(app.exampleDecorator) + expect(app.exampleDecorator).type.toBe<() => string>() } catch (err) { console.error(err) } diff --git a/test/generate-plugin.test.js b/test/generate-plugin.test.js index 3fd73b4c..cbe17282 100644 --- a/test/generate-plugin.test.js +++ b/test/generate-plugin.test.js @@ -147,15 +147,15 @@ function define (t) { t.assert.strictEqual(pkg.scripts.lint, 'standard && npm run lint:typescript') t.assert.strictEqual(pkg.scripts['lint:typescript'], 'ts-standard') t.assert.strictEqual(pkg.scripts.test, 'npm run lint && npm run unit && npm run test:typescript') - t.assert.strictEqual(pkg.scripts['test:typescript'], 'tsd') + t.assert.strictEqual(pkg.scripts['test:typescript'], 'tstyche') t.assert.strictEqual(pkg.scripts.unit, 'node --test') t.assert.strictEqual(pkg.dependencies['fastify-plugin'], cliPkg.dependencies['fastify-plugin']) t.assert.strictEqual(pkg.devDependencies['@types/node'], cliPkg.devDependencies['@types/node']) t.assert.strictEqual(pkg.devDependencies.fastify, cliPkg.devDependencies.fastify) t.assert.strictEqual(pkg.devDependencies.standard, cliPkg.devDependencies.standard) - t.assert.strictEqual(pkg.devDependencies.tsd, cliPkg.devDependencies.tsd) + t.assert.strictEqual(pkg.devDependencies.tstyche, cliPkg.devDependencies.tstyche) t.assert.strictEqual(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript) - t.assert.deepStrictEqual(pkg.tsd, pluginTemplate.tsd) + t.assert.deepStrictEqual(pkg.tstyche, pluginTemplate.tstyche) resolve() })