From aecab7627c110683ec3c42e020db436974abe342 Mon Sep 17 00:00:00 2001 From: Andrey Epifancev Date: Sun, 27 Sep 2026 20:08:57 +0400 Subject: [PATCH] fix: typecheck src/core without Node types; pin exact dependency versions (T1.1, O-2) T1.1: tsconfig.core.json (types: []) covers src/core; typecheck runs both passes, so process/Buffer in core fail compilation. tests/core-types.test.ts compiles a fixture with Node globals under both configs and rejects config errors as false positives. The fixture is excluded from the root tsconfig. O-2: devDependencies pinned to the locked versions, .npmrc save-exact=true. Lock updated only in the root specifiers: npm install on macOS would prune optional rolldown binaries for other platforms. Refs #3 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QKHeGuAYh4W1jNdjMConZa --- .npmrc | 1 + CLAUDE.md | 2 + package-lock.json | 10 ++--- package.json | 14 +++--- tests/core-types.test.ts | 45 +++++++++++++++++++ .../core-globals/uses-node-globals.ts | 4 ++ tsconfig.core.json | 8 ++++ tsconfig.json | 3 +- 8 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 .npmrc create mode 100644 tests/core-types.test.ts create mode 100644 tests/fixtures/core-globals/uses-node-globals.ts create mode 100644 tsconfig.core.json diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..cffe8cd --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +save-exact=true diff --git a/CLAUDE.md b/CLAUDE.md index eb9e070..b59fc18 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,6 +19,8 @@ - `npm run dev` — сборка в watch-режиме в тестовый vault. - `npm test` — vitest, вся папка `tests/`. Зелёным считается весь набор. - `npm run build` — продакшн-сборка `main.js`. +- `npm run typecheck` — два прохода: весь проект с Node-типами и `src/core` через `tsconfig.core.json` без Node-типов (`process`, `Buffer` в core — ошибка компиляции). +- Версии зависимостей точные (`.npmrc`: `save-exact=true`). Lock-файл не перегенерировать через `npm install` на одной ОС: npm вычищает опциональные бинарники других платформ. ## Тесты - Golden-тесты: `tests/fixtures/.m4a` + `tests/fixtures/.txt` (эталонный транскрипт). Провайдер в тестах мокается; golden-файлы проверяют формирование заметки и обработку ответа, а не сам сервис. diff --git a/package-lock.json b/package-lock.json index 7560dc0..dcdb461 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,11 +8,11 @@ "name": "obsidian-voice-note", "version": "0.1.0", "devDependencies": { - "@types/node": "^26.6.3", - "esbuild": "^0.28.2", - "obsidian": "^1.13.1", - "typescript": "^7.0.2", - "vitest": "^5.0.2" + "@types/node": "26.6.3", + "esbuild": "0.28.2", + "obsidian": "1.13.1", + "typescript": "7.0.2", + "vitest": "5.0.2" } }, "node_modules/@codemirror/state": { diff --git a/package.json b/package.json index f025eaa..e79b9bb 100644 --- a/package.json +++ b/package.json @@ -5,15 +5,15 @@ "type": "module", "scripts": { "dev": "node esbuild.config.mjs", - "build": "tsc --noEmit && node esbuild.config.mjs production", - "typecheck": "tsc --noEmit", + "build": "npm run typecheck && node esbuild.config.mjs production", + "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.core.json", "test": "vitest run" }, "devDependencies": { - "@types/node": "^26.6.3", - "esbuild": "^0.28.2", - "obsidian": "^1.13.1", - "typescript": "^7.0.2", - "vitest": "^5.0.2" + "@types/node": "26.6.3", + "esbuild": "0.28.2", + "obsidian": "1.13.1", + "typescript": "7.0.2", + "vitest": "5.0.2" } } diff --git a/tests/core-types.test.ts b/tests/core-types.test.ts new file mode 100644 index 0000000..c3740fb --- /dev/null +++ b/tests/core-types.test.ts @@ -0,0 +1,45 @@ +import { spawnSync } from 'node:child_process'; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { afterAll, describe, expect, it } from 'vitest'; + +const ROOT = fileURLToPath(new URL('../', import.meta.url)); +const TSC = join(ROOT, 'node_modules/.bin/tsc'); +const FIXTURE = join(ROOT, 'tests/fixtures/core-globals/uses-node-globals.ts'); +// Внутри проекта, чтобы типы (@types/node) резолвились из node_modules проекта. +const CACHE = join(ROOT, 'node_modules/.cache'); +mkdirSync(CACHE, { recursive: true }); +const TMP = mkdtempSync(join(CACHE, 'core-types-')); +// Ошибки конфигурации (нет файла в extends, нет библиотеки типов) не должны +// выдаваться за срабатывание core-конфига. +const CONFIG_ERROR = /error TS(?:5\d{3}|6053|2688)/; + +afterAll(() => rmSync(TMP, { recursive: true, force: true })); + +// Компилирует фикстуру с настройками указанного конфига проекта. +function typecheckFixture(config: string): { status: number | null; output: string } { + const project = join(TMP, `${config}.fixture.json`); + writeFileSync( + project, + JSON.stringify({ extends: join(ROOT, config), include: [], files: [FIXTURE] }), + ); + const r = spawnSync(TSC, ['--noEmit', '-p', project], { encoding: 'utf8' }); + return { status: r.status, output: `${r.stdout}${r.stderr}` }; +} + +describe('src/core type environment', () => { + it('fixture is valid TypeScript under the Node-typed root config', () => { + const r = typecheckFixture('tsconfig.json'); + expect(r.output).toBe(''); + expect(r.status).toBe(0); + }); + + it('core config rejects Node globals (process, Buffer)', () => { + const r = typecheckFixture('tsconfig.core.json'); + expect(r.output).not.toMatch(CONFIG_ERROR); + expect(r.status).not.toBe(0); + expect(r.output).toMatch(/Cannot find name 'process'/); + expect(r.output).toMatch(/Cannot find name 'Buffer'/); + }); +}); diff --git a/tests/fixtures/core-globals/uses-node-globals.ts b/tests/fixtures/core-globals/uses-node-globals.ts new file mode 100644 index 0000000..60b8434 --- /dev/null +++ b/tests/fixtures/core-globals/uses-node-globals.ts @@ -0,0 +1,4 @@ +// Фикстура для tests/core-types.test.ts: core-конфиг обязан отвергать Node-глобалы. +// Исключена из tsconfig.json, проверяется только тестом. +export const env = process.env.NODE_ENV; +export const bytes = Buffer.from('x'); diff --git a/tsconfig.core.json b/tsconfig.core.json new file mode 100644 index 0000000..0247368 --- /dev/null +++ b/tsconfig.core.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "types": [] + }, + "include": ["src/core/**/*.ts"], + "exclude": [] +} diff --git a/tsconfig.json b/tsconfig.json index 72f87ae..e94c205 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,5 +11,6 @@ "skipLibCheck": true, "noImplicitOverride": true }, - "include": ["src/**/*.ts", "tests/**/*.ts", "vitest.config.ts"] + "include": ["src/**/*.ts", "tests/**/*.ts", "vitest.config.ts"], + "exclude": ["tests/fixtures/core-globals/**"] }