rules editor: the built-in fs module of wb-rules (typed require/import, module preserve) - #1215
Draft
evgeny-boger wants to merge 2 commits into
Draft
rules editor: the built-in fs module of wb-rules (typed require/import, module preserve)#1215evgeny-boger wants to merge 2 commits into
evgeny-boger wants to merge 2 commits into
Conversation
…language service
wb-rules gained a built-in fs module (require("fs"), require("fs/promises")
and the node: aliases), declared in its types/wb-rules.d.ts as ambient
modules plus typed require() overloads ahead of the loose
require(id: string): any. Its transpiler now emits CommonJS with
esModuleInterop and its background check passes --esModuleInterop, so .ts
rule files may write import * as fs from "fs", import fs from "fs" and
export const x = ...
- Sync the vendored wb-rules.d.ts (verbatim copy; the previous vendored
file was byte-identical to wb-rules' quickjs-ts version).
- Language service: add esModuleInterop: true to the compiler options that
mirror the engine's check, so a default import of the module checks clean
regardless of the bundled TypeScript's defaults.
- Completion generator: choose the first overload not specialised on literal
arguments, so the require global keeps its generic
function require(id: string): any detail instead of the fs-specific
overload that now precedes it. Only top-level statements were ever walked,
so the declare module blocks add no globals; globals-generated.ts is
unchanged by regeneration.
- Tests (ts-language-service-fs.test.ts, a sibling like the CRLF one to stay
under max-lines): typed require("fs") flags readFileSync(1) and accepts a
string path, unknown modules stay any, namespace and default imports plus
exports check clean, and member completion after fs. offers readFileSync
and promises.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…eclarations
The engine's background check moved from --module esnext to --module
preserve (still with --esModuleInterop): preserve accepts the CommonJS forms
the transpiler emits and runs - import x = require("m") and export = ... -
which esnext rejects as TS1202/TS1203 syntax errors. Mirror that in the
editor's language service (module: Preserve, moduleDetection force and
esModuleInterop unchanged) so the two verdicts keep agreeing; top-level
await and the ESM import/export forms still check clean.
Re-sync the vendored wb-rules.d.ts: fallback overloads for stat/readdir/
mkdir called with boolean variables, more OpenFlag values and a symlink type
union. The generated completion globals are unchanged by regeneration.
Test: import x = require("fs"); typed use; export = x; in a .ts rule file
yields no diagnostics.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 102 |
| Duplication | 2 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Что происходит; кому и зачем нужно
Редактор правил узнаёт встроенный модуль
fsдвижка wb-rules (wirenboard/wb-rules#231, поверх #1202): типизированныеrequire("fs")/import * as fs from "fs"в language service, автодополнениеfs., и параметры проверки, зеркалящие фоновую проверку движка (module: preserve,esModuleInterop).Что поменялось для пользователей
const fs = require("fs"),import * as fs from "fs",import fs from "fs",import x = require("fs")типизированы: подсказки по функциям и опциям, ошибки типов (fs.readFileSync(1)),require("some.mod")по-прежнемуany.module: Preserve+esModuleInterop: true— как движок; иначеimport x = require()/export =(которые теперь работают в.ts-правилах) подсвечивались бы как синтаксические ошибки, аimport fs from "fs"— как отсутствие default-экспорта.require(раньше взял бы первую, специализированную на литералах"fs" | "node:fs"); результатglobals-generated.tsбайт-в-байт прежний.Как устроено
frontend/src/stores/rules/autocomplete/wb-rules.d.ts— дословная копияtypes/wb-rules.d.tsиз wb-rulesquickjs-fs.ts-language-service.ts—ModuleKind.Preserve,esModuleInterop: true.scripts/generate-wb-rules-completions.mjs— при нескольких перегрузках берётся первая без литеральных параметров.ts-language-service-fs.test.ts(typed require, ESM-импорты + export,import x = require/export =, completions послеfs.).Коммиты:
6d5705e5,b85aa0ee.Как проверял
npx vitest run src/stores/rules/autocomplete/— 13 файлов, 89 тестов;npm run check:types— 0; eslint по затронутым файлам — 0.preserveload-bearing: сESNextпадает («Import assignment cannot be used when targeting ECMAScript modules»).esModuleInterop/allowSyntheticDefaultImportsужеtrueпо умолчанию — опция задана явно ради паритета с движком (tsgo), где это не так.