Add language tools package

This commit is contained in:
2026-07-09 18:34:41 +09:00
parent ac99c4cb4e
commit 0e2a7b35d2
20 changed files with 1434 additions and 16 deletions
@@ -0,0 +1,76 @@
import { writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
const packageDir = resolve(import.meta.dirname, '../../../packages/decodal-language-tools');
writeFileSync(
resolve(packageDir, '.gitignore'),
'# wasm-pack output is committed for the browser language tools package.\n',
);
writeFileSync(
resolve(packageDir, 'README.md'),
`# decodal-language-tools
Source-level language tooling for Decodal.
This package is generated from the Rust crate in \`crates/decodal-language-tools\` with \`wasm-pack\`.
It currently exposes a comment-preserving formatter that is shared by the official playground and future editor/LSP tooling.
Use \`decodal-codemirror\` separately when you need CodeMirror 6 language support.
Use \`decodal-wasm\` separately when you need to evaluate Decodal in a browser.
## Install
\`\`\`sh
npm install decodal-language-tools
\`\`\`
JSR:
\`\`\`sh
deno add jsr:@hare/decodal-language-tools
\`\`\`
## Usage
\`\`\`js
import init, { formatSource } from 'decodal-language-tools';
await init();
const result = JSON.parse(formatSource('Server={# host\\nhost=String default "localhost";};'));
if (result.ok) {
console.log(result.source);
} else {
console.error(result.error);
}
\`\`\`
The exported functions return JSON strings so callers can handle diagnostics without depending on Rust data structures.
`,
);
writeFileSync(
resolve(packageDir, 'jsr.json'),
JSON.stringify(
{
name: '@hare/decodal-language-tools',
version: '0.1.2',
license: 'MIT',
exports: './decodal_language_tools.js',
publish: {
include: [
'README.md',
'decodal_language_tools.js',
'decodal_language_tools.d.ts',
'decodal_language_tools_bg.wasm',
'package.json',
],
},
},
null,
2,
) + '\n',
);