diff --git a/.changeset/green-turtles-jump.md b/.changeset/green-turtles-jump.md new file mode 100644 index 0000000..06ffc38 --- /dev/null +++ b/.changeset/green-turtles-jump.md @@ -0,0 +1,5 @@ +--- +"@ast-grep/all-langs": patch +--- + +New package: @ast-grep/all-langs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 302534e..942dd06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: uses: actions/setup-node@v4 with: cache: pnpm + node-version: ">= 21" - name: Install dependencies run: pnpm install diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d44f181..7c72834 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,6 +41,7 @@ jobs: uses: actions/setup-node@v4 with: cache: pnpm + node-version: ">= 21" registry-url: https://registry.npmjs.org/ - name: Install dependencies run: pnpm install @@ -74,6 +75,7 @@ jobs: uses: actions/setup-node@v4 with: cache: pnpm + node-version: ">= 21" registry-url: https://registry.npmjs.org/ - name: Install dependencies run: pnpm install diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..699ed73 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["biomejs.biome"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..97803f2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[javascript][json][jsonc][typescript]": { + "editor.defaultFormatter": "biomejs.biome", + "editor.minimap.maxColumn": 80 + } +} diff --git a/packages/all/.gitignore b/packages/all/.gitignore new file mode 100644 index 0000000..057ed8b --- /dev/null +++ b/packages/all/.gitignore @@ -0,0 +1 @@ +!src diff --git a/packages/all/package.json b/packages/all/package.json new file mode 100644 index 0000000..e4ac83c --- /dev/null +++ b/packages/all/package.json @@ -0,0 +1,71 @@ +{ + "name": "@ast-grep/all-langs", + "version": "0.0.0", + "description": "Exports all officially supported languages.", + "keywords": ["ast-grep"], + "homepage": "https://github.com/ast-grep/langs/tree/main/packages/all", + "bugs": { + "url": "https://github.com/ast-grep/langs/issues" + }, + "license": "ISC", + "author": { + "name": "CodeRabbit", + "url": "https://www.coderabbit.ai" + }, + "files": ["dist", "!dist/**/*.test.*"], + "main": "dist/index.js", + "repository": "github:ast-grep/langs", + "scripts": { + "build": "tsc", + "clean": "rm -rf dist docs node_modules tsconfig.tsbuildinfo", + "format": "biome format --write", + "format:ci": "biome format", + "lint": "biome lint --fix", + "lint:ci": "biome lint", + "pretest": "tsc", + "test": "node --test './dist/**/*.test.js'" + }, + "dependencies": { + "@ast-grep/lang-angular": "workspace:*", + "@ast-grep/lang-bash": "workspace:*", + "@ast-grep/lang-c": "workspace:*", + "@ast-grep/lang-cpp": "workspace:*", + "@ast-grep/lang-csharp": "workspace:*", + "@ast-grep/lang-css": "workspace:*", + "@ast-grep/lang-dart": "workspace:*", + "@ast-grep/lang-elixir": "workspace:*", + "@ast-grep/lang-go": "workspace:*", + "@ast-grep/lang-haskell": "workspace:*", + "@ast-grep/lang-html": "workspace:*", + "@ast-grep/lang-java": "workspace:*", + "@ast-grep/lang-javascript": "workspace:*", + "@ast-grep/lang-json": "workspace:*", + "@ast-grep/lang-kotlin": "workspace:*", + "@ast-grep/lang-lua": "workspace:*", + "@ast-grep/lang-php": "workspace:*", + "@ast-grep/lang-python": "workspace:*", + "@ast-grep/lang-ruby": "workspace:*", + "@ast-grep/lang-rust": "workspace:*", + "@ast-grep/lang-scala": "workspace:*", + "@ast-grep/lang-sql": "workspace:*", + "@ast-grep/lang-swift": "workspace:*", + "@ast-grep/lang-toml": "workspace:*", + "@ast-grep/lang-tsx": "workspace:*", + "@ast-grep/lang-typescript": "workspace:*", + "@ast-grep/lang-yaml": "workspace:*", + "@ast-grep/napi": "^0.37.0" + }, + "devDependencies": { + "@types/node": "22.14.1", + "typescript": "^5.8.3" + }, + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, + "types": "dist/index.d.ts", + "module": "dist/index.js" +} diff --git a/packages/all/src/index.ts b/packages/all/src/index.ts new file mode 100644 index 0000000..3962071 --- /dev/null +++ b/packages/all/src/index.ts @@ -0,0 +1,2 @@ +export * from "./lang.ts" +export * from "./langs.ts" diff --git a/packages/all/src/lang.test.ts b/packages/all/src/lang.test.ts new file mode 100644 index 0000000..235ce38 --- /dev/null +++ b/packages/all/src/lang.test.ts @@ -0,0 +1,41 @@ +import { Lang as LangNapi } from "@ast-grep/napi" +import test, { describe } from "node:test" +import { Lang } from "./lang.ts" + +/** Languages supported in `@ast-grep/napi@0.33.1`. */ +const previous = Object.freeze({ + Html: "Html", + JavaScript: "JavaScript", + Tsx: "Tsx", + Css: "Css", + TypeScript: "TypeScript", + Bash: "Bash", + C: "C", + Cpp: "Cpp", + CSharp: "CSharp", + Go: "Go", + Elixir: "Elixir", + Haskell: "Haskell", + Java: "Java", + Json: "Json", + Kotlin: "Kotlin", + Lua: "Lua", + Php: "Php", + Python: "Python", + Ruby: "Ruby", + Rust: "Rust", + Scala: "Scala", + Sql: "Sql", + Swift: "Swift", + Yaml: 'Yaml', +}) + +describe("Lang", () => { + test("The new enum is compatible with the old one", ({ assert }) => { + for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang) + }) + + test("The new enum is compatible with the built-in ones", ({ assert }) => { + for (const lang of Object.values(LangNapi)) assert.equal(Lang[lang], lang) + }) +}) diff --git a/packages/all/src/lang.ts b/packages/all/src/lang.ts new file mode 100644 index 0000000..b711f94 --- /dev/null +++ b/packages/all/src/lang.ts @@ -0,0 +1,37 @@ +/** + * An enum of all languages supported by `@ast-grep/langs`. + */ +export const Lang = { + Angular: "Angular", + Bash: "Bash", + C: "C", + Cpp: "Cpp", + CSharp: "CSharp", + Css: "Css", + Dart: "Dart", + Elixir: "Elixir", + Go: "Go", + Haskell: "Haskell", + Html: "Html", + Java: "Java", + JavaScript: "JavaScript", + Json: "Json", + Kotlin: "Kotlin", + Lua: "Lua", + Php: "Php", + Python: "Python", + Ruby: "Ruby", + Rust: "Rust", + Scala: "Scala", + Sql: "Sql", + Swift: "Swift", + Toml: "Toml", + Tsx: "Tsx", + TypeScript: "TypeScript", + Yaml: "Yaml", +} as const + +/** + * An enum of all languages supported by `@ast-grep/langs`. + */ +export type Lang = (typeof Lang)[keyof typeof Lang] diff --git a/packages/all/src/langs.test.ts b/packages/all/src/langs.test.ts new file mode 100644 index 0000000..22d7a8e --- /dev/null +++ b/packages/all/src/langs.test.ts @@ -0,0 +1,31 @@ +import { parse, registerDynamicLanguage } from "@ast-grep/napi" +import { before, describe, test } from "node:test" +import { Lang } from "./lang.ts" +import { langs } from "./langs.ts" + +describe("langs", () => { + // @ts-expect-error Type `StaticLangRegistration` is missing the following + // properties from type `LangRegistration`: `libraryPath`, `extensions`. + before(() => registerDynamicLanguage(langs)) + + // A newly supported language + test(Lang.Dart, ({ assert }) => { + const sg = parse(Lang.Dart, 'var x = "Hello, world!";"') + const kind = sg.root().kind() + assert.equal(kind, "program") + }) + + // A previously supported language + test(Lang.Go, ({ assert }) => { + const sg = parse(Lang.Go, 'x := "Hello, world!"') + const kind = sg.root().kind() + assert.equal(kind, "source_file") + }) + + // A built-in language + test(Lang.TypeScript, ({ assert }) => { + const sg = parse(Lang.TypeScript, 'const x = "Hello, world!"') + const kind = sg.root().kind() + assert.equal(kind, "program") + }) +}) diff --git a/packages/all/src/langs.ts b/packages/all/src/langs.ts new file mode 100644 index 0000000..a0276bf --- /dev/null +++ b/packages/all/src/langs.ts @@ -0,0 +1,128 @@ +import angular from "@ast-grep/lang-angular" +import bash from "@ast-grep/lang-bash" +import c from "@ast-grep/lang-c" +import cpp from "@ast-grep/lang-cpp" +import csharp from "@ast-grep/lang-csharp" +import css from "@ast-grep/lang-css" +import dart from "@ast-grep/lang-dart" +import elixir from "@ast-grep/lang-elixir" +import go from "@ast-grep/lang-go" +import haskell from "@ast-grep/lang-haskell" +import html from "@ast-grep/lang-html" +import java from "@ast-grep/lang-java" +import javascript from "@ast-grep/lang-javascript" +import json from "@ast-grep/lang-json" +import kotlin from "@ast-grep/lang-kotlin" +import lua from "@ast-grep/lang-lua" +import php from "@ast-grep/lang-php" +import python from "@ast-grep/lang-python" +import ruby from "@ast-grep/lang-ruby" +import rust from "@ast-grep/lang-rust" +import scala from "@ast-grep/lang-scala" +import sql from "@ast-grep/lang-sql" +import swift from "@ast-grep/lang-swift" +import toml from "@ast-grep/lang-toml" +import tsx from "@ast-grep/lang-tsx" +import typescript from "@ast-grep/lang-typescript" +import yaml from "@ast-grep/lang-yaml" +import type { + DynamicLangRegistrations, + LangRegistration, +} from "@ast-grep/napi/types/registerDynamicLang.js" +import { Lang } from "./lang.ts" + +type StaticLangRegistration = + | typeof angular + | typeof bash + | typeof c + | typeof cpp + | typeof csharp + | typeof css + | typeof dart + | typeof elixir + | typeof go + | typeof haskell + | typeof html + | typeof java + | typeof javascript + | typeof json + | typeof kotlin + | typeof lua + | typeof php + | typeof python + | typeof ruby + | typeof rust + | typeof scala + | typeof sql + | typeof swift + | typeof toml + | typeof tsx + | typeof typescript + | typeof yaml + | LangRegistration + +interface StaticLangRegistrations { + Angular: typeof angular + Bash: typeof bash + C: typeof c + Cpp: typeof cpp + CSharp: typeof csharp + Css: typeof css + Dart: typeof dart + Elixir: typeof elixir + Go: typeof go + Haskell: typeof haskell + Html: typeof html + Java: typeof java + JavaScript: typeof javascript + Json: typeof json + Kotlin: typeof kotlin + Lua: typeof lua + Php: typeof php + Python: typeof python + Ruby: typeof ruby + Rust: typeof rust + Scala: typeof scala + Sql: typeof sql + Swift: typeof swift + Toml: typeof toml + Tsx: typeof tsx + TypeScript: typeof typescript + Yaml: typeof yaml + + /** To satisfy {@link DynamicLangRegistrations}. */ + [langName: string]: StaticLangRegistration +} + +/** + * Built-in dynamic languages supported by `@ast-grep/langs`. + */ +export const langs: StaticLangRegistrations = { + [Lang.Angular]: angular, + [Lang.Bash]: bash, + [Lang.C]: c, + [Lang.Cpp]: cpp, + [Lang.CSharp]: csharp, + [Lang.Css]: css, + [Lang.Dart]: dart, + [Lang.Elixir]: elixir, + [Lang.Go]: go, + [Lang.Haskell]: haskell, + [Lang.Html]: html, + [Lang.Java]: java, + [Lang.JavaScript]: javascript, + [Lang.Json]: json, + [Lang.Kotlin]: kotlin, + [Lang.Lua]: lua, + [Lang.Php]: php, + [Lang.Python]: python, + [Lang.Ruby]: ruby, + [Lang.Rust]: rust, + [Lang.Scala]: scala, + [Lang.Sql]: sql, + [Lang.Swift]: swift, + [Lang.Toml]: toml, + [Lang.Tsx]: tsx, + [Lang.TypeScript]: typescript, + [Lang.Yaml]: yaml, +} diff --git a/packages/all/tsconfig.json b/packages/all/tsconfig.json new file mode 100644 index 0000000..9e2eef4 --- /dev/null +++ b/packages/all/tsconfig.json @@ -0,0 +1,62 @@ +{ + "compilerOptions": { + /* Projects */ + "incremental": true, + "composite": true, + + /* Language and Environment */ + "target": "ESNext", + "lib": ["DOM", "ESNext"], + "useDefineForClassFields": true, + "moduleDetection": "force", + + /* Modules */ + "module": "NodeNext", + "rootDir": "./src", + "moduleResolution": "NodeNext", + "rewriteRelativeImportExtensions": true, + "resolvePackageJsonExports": true, + "resolvePackageJsonImports": true, + "resolveJsonModule": true, + + /* JavaScript Support */ + + /* Emit */ + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "outDir": "./dist", + + /* Interop Constraints */ + "isolatedModules": true, + "verbatimModuleSyntax": true, + "isolatedDeclarations": true, + "erasableSyntaxOnly": true, + "forceConsistentCasingInFileNames": true, + + /* Type Checking */ + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "useUnknownInCatchVariables": true, + "alwaysStrict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "exactOptionalPropertyTypes": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "allowUnusedLabels": false, + "allowUnreachableCode": false, + + /* Completeness */ + "skipDefaultLibCheck": true, + "skipLibCheck": true + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 74ad380..5f0b024 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,6 +18,100 @@ importers: specifier: 9.1.7 version: 9.1.7 + packages/all: + dependencies: + '@ast-grep/lang-angular': + specifier: workspace:* + version: link:../angular + '@ast-grep/lang-bash': + specifier: workspace:* + version: link:../bash + '@ast-grep/lang-c': + specifier: workspace:* + version: link:../c + '@ast-grep/lang-cpp': + specifier: workspace:* + version: link:../cpp + '@ast-grep/lang-csharp': + specifier: workspace:* + version: link:../csharp + '@ast-grep/lang-css': + specifier: workspace:* + version: link:../css + '@ast-grep/lang-dart': + specifier: workspace:* + version: link:../dart + '@ast-grep/lang-elixir': + specifier: workspace:* + version: link:../elixir + '@ast-grep/lang-go': + specifier: workspace:* + version: link:../go + '@ast-grep/lang-haskell': + specifier: workspace:* + version: link:../haskell + '@ast-grep/lang-html': + specifier: workspace:* + version: link:../html + '@ast-grep/lang-java': + specifier: workspace:* + version: link:../java + '@ast-grep/lang-javascript': + specifier: workspace:* + version: link:../javascript + '@ast-grep/lang-json': + specifier: workspace:* + version: link:../json + '@ast-grep/lang-kotlin': + specifier: workspace:* + version: link:../kotlin + '@ast-grep/lang-lua': + specifier: workspace:* + version: link:../lua + '@ast-grep/lang-php': + specifier: workspace:* + version: link:../php + '@ast-grep/lang-python': + specifier: workspace:* + version: link:../python + '@ast-grep/lang-ruby': + specifier: workspace:* + version: link:../ruby + '@ast-grep/lang-rust': + specifier: workspace:* + version: link:../rust + '@ast-grep/lang-scala': + specifier: workspace:* + version: link:../scala + '@ast-grep/lang-sql': + specifier: workspace:* + version: link:../sql + '@ast-grep/lang-swift': + specifier: workspace:* + version: link:../swift + '@ast-grep/lang-toml': + specifier: workspace:* + version: link:../toml + '@ast-grep/lang-tsx': + specifier: workspace:* + version: link:../tsx + '@ast-grep/lang-typescript': + specifier: workspace:* + version: link:../typescript + '@ast-grep/lang-yaml': + specifier: workspace:* + version: link:../yaml + '@ast-grep/napi': + specifier: ^0.37.0 + version: 0.37.0 + devDependencies: + '@types/node': + specifier: 22.14.1 + version: 22.14.1 + typescript: + specifier: ^5.8.3 + version: 5.8.3 + packages/angular: dependencies: '@ast-grep/setup-lang':