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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKHeGuAYh4W1jNdjMConZa
This commit is contained in:
parent
9b4ea0a3c9
commit
aecab7627c
@ -19,6 +19,8 @@
|
|||||||
- `npm run dev` — сборка в watch-режиме в тестовый vault.
|
- `npm run dev` — сборка в watch-режиме в тестовый vault.
|
||||||
- `npm test` — vitest, вся папка `tests/`. Зелёным считается весь набор.
|
- `npm test` — vitest, вся папка `tests/`. Зелёным считается весь набор.
|
||||||
- `npm run build` — продакшн-сборка `main.js`.
|
- `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/<name>.m4a` + `tests/fixtures/<name>.txt` (эталонный транскрипт). Провайдер в тестах мокается; golden-файлы проверяют формирование заметки и обработку ответа, а не сам сервис.
|
- Golden-тесты: `tests/fixtures/<name>.m4a` + `tests/fixtures/<name>.txt` (эталонный транскрипт). Провайдер в тестах мокается; golden-файлы проверяют формирование заметки и обработку ответа, а не сам сервис.
|
||||||
|
|||||||
10
package-lock.json
generated
10
package-lock.json
generated
@ -8,11 +8,11 @@
|
|||||||
"name": "obsidian-voice-note",
|
"name": "obsidian-voice-note",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^26.6.3",
|
"@types/node": "26.6.3",
|
||||||
"esbuild": "^0.28.2",
|
"esbuild": "0.28.2",
|
||||||
"obsidian": "^1.13.1",
|
"obsidian": "1.13.1",
|
||||||
"typescript": "^7.0.2",
|
"typescript": "7.0.2",
|
||||||
"vitest": "^5.0.2"
|
"vitest": "5.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@codemirror/state": {
|
"node_modules/@codemirror/state": {
|
||||||
|
|||||||
14
package.json
14
package.json
@ -5,15 +5,15 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node esbuild.config.mjs",
|
"dev": "node esbuild.config.mjs",
|
||||||
"build": "tsc --noEmit && node esbuild.config.mjs production",
|
"build": "npm run typecheck && node esbuild.config.mjs production",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.core.json",
|
||||||
"test": "vitest run"
|
"test": "vitest run"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^26.6.3",
|
"@types/node": "26.6.3",
|
||||||
"esbuild": "^0.28.2",
|
"esbuild": "0.28.2",
|
||||||
"obsidian": "^1.13.1",
|
"obsidian": "1.13.1",
|
||||||
"typescript": "^7.0.2",
|
"typescript": "7.0.2",
|
||||||
"vitest": "^5.0.2"
|
"vitest": "5.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
tests/core-types.test.ts
Normal file
45
tests/core-types.test.ts
Normal file
@ -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'/);
|
||||||
|
});
|
||||||
|
});
|
||||||
4
tests/fixtures/core-globals/uses-node-globals.ts
vendored
Normal file
4
tests/fixtures/core-globals/uses-node-globals.ts
vendored
Normal file
@ -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');
|
||||||
8
tsconfig.core.json
Normal file
8
tsconfig.core.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": []
|
||||||
|
},
|
||||||
|
"include": ["src/core/**/*.ts"],
|
||||||
|
"exclude": []
|
||||||
|
}
|
||||||
@ -11,5 +11,6 @@
|
|||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"noImplicitOverride": true
|
"noImplicitOverride": true
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts", "tests/**/*.ts", "vitest.config.ts"]
|
"include": ["src/**/*.ts", "tests/**/*.ts", "vitest.config.ts"],
|
||||||
|
"exclude": ["tests/fixtures/core-globals/**"]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user