@ast-grep/napi
Advanced tools
Comparing version 0.22.4 to 0.22.5
@@ -16,3 +16,3 @@ /* tslint:disable */ | ||
/** Available languages: html, css, js, jsx, ts, tsx */ | ||
language?: FrontEndLanguage | ||
language?: Lang | ||
/** https://ast-grep.github.io/reference/yaml.html#transform */ | ||
@@ -23,9 +23,44 @@ transform?: any | ||
} | ||
export const enum FrontEndLanguage { | ||
Html = 0, | ||
JavaScript = 1, | ||
Tsx = 2, | ||
Css = 3, | ||
TypeScript = 4 | ||
export interface FileOption { | ||
paths: Array<string> | ||
languageGlobs: Record<string, Array<string>> | ||
} | ||
export function parseFiles(paths: Array<string> | FileOption, callback: (err: null | Error, result: SgRoot) => void): Promise<number> | ||
export interface FindConfig { | ||
/** specify the file paths to recursively find files */ | ||
paths: Array<string> | ||
/** a Rule object to find what nodes will match */ | ||
matcher: NapiConfig | ||
/** | ||
* An list of pattern globs to treat of certain files in the specified language. | ||
* eg. ['*.vue', '*.svelte'] for html.findFiles, or ['*.ts'] for tsx.findFiles. | ||
* It is slightly different from https://ast-grep.github.io/reference/sgconfig.html#languageglobs | ||
*/ | ||
languageGlobs?: Array<string> | ||
} | ||
export const enum Lang { | ||
Html = 'Html', | ||
JavaScript = 'JavaScript', | ||
Tsx = 'Tsx', | ||
Css = 'Css', | ||
TypeScript = 'TypeScript', | ||
Bash = 'Bash', | ||
C = 'C', | ||
Cpp = 'Cpp', | ||
CSharp = 'CSharp', | ||
Dart = 'Dart', | ||
Go = 'Go', | ||
Elixir = 'Elixir', | ||
Haskell = 'Haskell', | ||
Java = 'Java', | ||
Json = 'Json', | ||
Kotlin = 'Kotlin', | ||
Lua = 'Lua', | ||
Php = 'Php', | ||
Python = 'Python', | ||
Ruby = 'Ruby', | ||
Rust = 'Rust', | ||
Scala = 'Scala', | ||
Swift = 'Swift' | ||
} | ||
export interface Edit { | ||
@@ -53,19 +88,23 @@ /** The position of the edit */ | ||
} | ||
export interface FileOption { | ||
paths: Array<string> | ||
languageGlobs: Record<string, Array<string>> | ||
} | ||
export function parseFiles(paths: Array<string> | FileOption, callback: (err: null | Error, result: SgRoot) => void): Promise<number> | ||
export interface FindConfig { | ||
/** specify the file paths to recursively find files */ | ||
paths: Array<string> | ||
/** a Rule object to find what nodes will match */ | ||
matcher: NapiConfig | ||
/** | ||
* An list of pattern globs to treat of certain files in the specified language. | ||
* eg. ['*.vue', '*.svelte'] for html.findFiles, or ['*.ts'] for tsx.findFiles. | ||
* It is slightly different from https://ast-grep.github.io/reference/sgconfig.html#languageglobs | ||
*/ | ||
languageGlobs?: Array<string> | ||
} | ||
/** Parse a string to an ast-grep instance */ | ||
export function parse(lang: Lang, src: string): SgRoot | ||
/** | ||
* Parse a string to an ast-grep instance asynchronously in threads. | ||
* It utilize multiple CPU cores when **concurrent processing sources**. | ||
* However, spawning excessive many threads may backfire. | ||
* Please refer to libuv doc, nodejs' underlying runtime | ||
* for its default behavior and performance tuning tricks. | ||
*/ | ||
export function parseAsync(lang: Lang, src: string): Promise<SgRoot> | ||
/** Get the `kind` number from its string name. */ | ||
export function kind(lang: Lang, kindName: string): number | ||
/** Compile a string to ast-grep Pattern. */ | ||
export function pattern(lang: Lang, pattern: string): NapiConfig | ||
/** | ||
* Discover and parse multiple files in Rust. | ||
* `lang` specifies the language. | ||
* `config` specifies the file path and matcher. | ||
* `callback` will receive matching nodes found in a file. | ||
*/ | ||
export function findInFiles(lang: Lang, config: FindConfig, callback: (err: null | Error, result: SgNode[]) => void): Promise<number> | ||
export class SgNode { | ||
@@ -72,0 +111,0 @@ range(): Range |
11
index.js
@@ -284,8 +284,13 @@ /* tslint:disable */ | ||
const { FrontEndLanguage, SgNode, SgRoot, parseFiles, html, js, jsx, ts, tsx, css } = nativeBinding | ||
const { parseFiles, Lang, SgNode, SgRoot, parse, parseAsync, kind, pattern, findInFiles, html, js, jsx, ts, tsx, css } = nativeBinding | ||
module.exports.FrontEndLanguage = FrontEndLanguage | ||
module.exports.parseFiles = parseFiles | ||
module.exports.Lang = Lang | ||
module.exports.SgNode = SgNode | ||
module.exports.SgRoot = SgRoot | ||
module.exports.parseFiles = parseFiles | ||
module.exports.parse = parse | ||
module.exports.parseAsync = parseAsync | ||
module.exports.kind = kind | ||
module.exports.pattern = pattern | ||
module.exports.findInFiles = findInFiles | ||
module.exports.html = html | ||
@@ -292,0 +297,0 @@ module.exports.js = js |
{ | ||
"name": "@ast-grep/napi", | ||
"version": "0.22.4", | ||
"version": "0.22.5", | ||
"description": "Search and Rewrite code at large scale using precise AST pattern", | ||
@@ -69,11 +69,11 @@ "homepage": "https://ast-grep.github.io", | ||
"optionalDependencies": { | ||
"@ast-grep/napi-win32-x64-msvc": "0.22.4", | ||
"@ast-grep/napi-darwin-x64": "0.22.4", | ||
"@ast-grep/napi-linux-x64-gnu": "0.22.4", | ||
"@ast-grep/napi-win32-ia32-msvc": "0.22.4", | ||
"@ast-grep/napi-darwin-arm64": "0.22.4", | ||
"@ast-grep/napi-win32-arm64-msvc": "0.22.4", | ||
"@ast-grep/napi-linux-arm64-gnu": "0.22.4", | ||
"@ast-grep/napi-linux-x64-musl": "0.22.4" | ||
"@ast-grep/napi-win32-x64-msvc": "0.22.5", | ||
"@ast-grep/napi-darwin-x64": "0.22.5", | ||
"@ast-grep/napi-linux-x64-gnu": "0.22.5", | ||
"@ast-grep/napi-win32-ia32-msvc": "0.22.5", | ||
"@ast-grep/napi-darwin-arm64": "0.22.5", | ||
"@ast-grep/napi-win32-arm64-msvc": "0.22.5", | ||
"@ast-grep/napi-linux-arm64-gnu": "0.22.5", | ||
"@ast-grep/napi-linux-x64-musl": "0.22.5" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24217
570