@ohos-ports/codemod.com-workflow 0.0.0-stage → 0.0.31-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1 -3
  3. package/dist/PLazy.d.ts +9 -0
  4. package/dist/ai/ai.d.ts +17 -0
  5. package/dist/astGrep/astGrep.d.ts +172 -0
  6. package/dist/astGrep/exists.d.ts +11 -0
  7. package/dist/astGrep/filter.d.ts +35 -0
  8. package/dist/astGrep/getImports.d.ts +13 -0
  9. package/dist/astGrep/map.d.ts +19 -0
  10. package/dist/astGrep/replace.d.ts +43 -0
  11. package/dist/authService.d.ts +6 -0
  12. package/dist/codemod.d.ts +35 -0
  13. package/dist/contexts/Context.d.ts +6 -0
  14. package/dist/contexts/FileContext.d.ts +28 -0
  15. package/dist/contexts/GitContext.d.ts +12 -0
  16. package/dist/contexts.d.ts +55 -0
  17. package/dist/engineHelpers.d.ts +60 -0
  18. package/dist/exec.d.ts +34 -0
  19. package/dist/files.d.ts +47 -0
  20. package/dist/fs/dirs.d.ts +39 -0
  21. package/dist/fs/map.d.ts +7 -0
  22. package/dist/fs/move.d.ts +9 -0
  23. package/dist/fs.d.ts +7 -0
  24. package/dist/git/branch.d.ts +75 -0
  25. package/dist/git/clone.d.ts +125 -0
  26. package/dist/git/commit.d.ts +26 -0
  27. package/dist/git/git.d.ts +6 -0
  28. package/dist/git/helpers.d.ts +16 -0
  29. package/dist/git/push.d.ts +29 -0
  30. package/dist/github/fork.d.ts +25 -0
  31. package/dist/github/github.d.ts +4 -0
  32. package/dist/github/pr.d.ts +46 -0
  33. package/dist/github/utils.d.ts +2 -0
  34. package/dist/helpers.d.ts +19 -0
  35. package/dist/index.d.ts +45 -0
  36. package/dist/index.mjs +70 -0
  37. package/dist/isWorkflowEngineFile.d.ts +1 -0
  38. package/dist/js.d.ts +16 -0
  39. package/dist/jsFam/jscodeshift.d.ts +12 -0
  40. package/dist/jsFam.d.ts +53 -0
  41. package/dist/jsFiles.d.ts +37 -0
  42. package/dist/json/json.d.ts +14 -0
  43. package/dist/json/map.d.ts +10 -0
  44. package/dist/json/update.d.ts +10 -0
  45. package/dist/question.d.ts +10 -0
  46. package/dist/spawn.d.ts +14 -0
  47. package/dist/tsconfig.tsbuildinfo +1 -0
  48. package/dist/yaml/map.d.ts +10 -0
  49. package/dist/yaml/update.d.ts +10 -0
  50. package/dist/yaml/yaml.d.ts +14 -0
  51. package/package.json +55 -4
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 Codemod, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # Workflow
@@ -0,0 +1,9 @@
1
+ export declare class PLazy<ValueType> extends Promise<ValueType> {
2
+ #private;
3
+ constructor(executor: (resolve: (resolvedValue: ValueType) => void, reject: (error: any) => void) => void);
4
+ static from(function_: any): PLazy<unknown>;
5
+ static resolve(value: any): PLazy<unknown>;
6
+ static reject(error: any): PLazy<unknown>;
7
+ then<TResult1 = ValueType, TResult2 = never>(onFulfilled: ((resolvedValue: ValueType) => TResult1 | PromiseLike<TResult1>) | null | undefined, onRejected: ((error: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
8
+ catch(onRejected: any): Promise<ValueType>;
9
+ }
@@ -0,0 +1,17 @@
1
+ import type { PLazy } from "../PLazy.js";
2
+ export type AiReturn = PLazy<AiHelpers> & AiHelpers;
3
+ /**
4
+ * @description Replaces code found with `ast-grep` pattern using instructions provided to LLM. Whole file would be passed as a context. Currently, it only supports OpenAI's GPT-4 Turbo model. You will have to provide your OpenAI API key to use this function when you call codemod in CLI - provide `--OPENAI_API_KEY`.
5
+ * @param prompt - The prompt to be used for LLM.
6
+ * @example
7
+ * ```ts
8
+ * await files()
9
+ * .astGrep('console.log($$$A)')
10
+ * .ai`Convert console.log to console.error`
11
+ * ```
12
+ */
13
+ export declare function aiLogic(rawPrompt: string | readonly string[]): AiReturn;
14
+ export declare const ai: typeof aiLogic;
15
+ declare const aiHelpers: {};
16
+ type AiHelpers = typeof aiHelpers;
17
+ export {};
@@ -0,0 +1,172 @@
1
+ import { type NapiConfig, SgNode } from "@ohos-ports/ast-grep-napi";
2
+ import type { PLazy } from "../PLazy.js";
3
+ export { SgNode };
4
+ type AstGrepPattern = string | {
5
+ selector: string;
6
+ context: string;
7
+ strictness?: "cst" | "smart" | "ast" | "relaxed" | "signature";
8
+ };
9
+ type AstGrepStopBy = "end" | "neighbour" | AstGrepInsideRule;
10
+ type AstGrepInsideRule = {
11
+ pattern: AstGrepPattern;
12
+ stopBy?: AstGrepStopBy;
13
+ field?: string;
14
+ };
15
+ type AstGrepHasRule = {
16
+ kind: string;
17
+ stopBy?: AstGrepStopBy;
18
+ field?: string;
19
+ };
20
+ type AstGrepSiblingRule = {
21
+ kind: string;
22
+ stopBy?: AstGrepStopBy;
23
+ };
24
+ type AstGrepAtomicRule = {
25
+ pattern: AstGrepPattern;
26
+ kind?: string;
27
+ regex?: string;
28
+ inside?: AstGrepInsideRule;
29
+ has?: AstGrepHasRule;
30
+ precedes?: AstGrepSiblingRule;
31
+ follows?: AstGrepSiblingRule;
32
+ };
33
+ type AstGrepAllRule = {
34
+ all: AstGrepRules[];
35
+ };
36
+ type AstGrepAnyRule = {
37
+ any: AstGrepRules[];
38
+ };
39
+ type AstGrepNotRule = {
40
+ not: AstGrepRules;
41
+ };
42
+ type AstGrepMatchRule = {
43
+ match: string;
44
+ };
45
+ type AstGrepRules = AstGrepAtomicRule | AstGrepAllRule | AstGrepAnyRule | AstGrepNotRule | AstGrepMatchRule;
46
+ type AstGrepAPI = {
47
+ id: string;
48
+ language: "Bash" | "C" | "Cpp" | "CSharp" | "Css" | "Dart" | "Elixir" | "Go" | "Html" | "Java" | "JavaScript" | "Json" | "Kotlin" | "Lua" | "Php" | "Python" | "Ruby" | "Rust" | "Scala" | "Swift" | "TypeScript" | "Tsx";
49
+ rule: AstGrepRules;
50
+ utils?: any;
51
+ fix?: any;
52
+ };
53
+ export type AstGrepHelpers = typeof astGrepHelpers;
54
+ export type AstGrepAPIHelpers = typeof astGrepAPIHelpers;
55
+ /**
56
+ * @description Search for a pattern in the file using [ast-grep](https://ast-grep.github.io/). There are 2 ways to use this function: controlled and uncontrolled. If you will provide `id` in the `query` object - it will be passed to ast-grep CLI (`uncontrolled` mode). In all other cases `controlled` mode will be used with Napi (Node.js bindings to Rust).
57
+ * @param query It could be a string, string literal, [NapiConfig object](https://ast-grep.github.io/reference/api.html#napiconfig)
58
+ * @example
59
+ * ```ts
60
+ * // Pass parameter as string
61
+ * await astGrep("import React from 'react'")
62
+ * ```
63
+ * @example
64
+ * ```ts
65
+ * // Pass parameter as string literal
66
+ * await astGrep`import React from 'react'`
67
+ * ```
68
+ * @example
69
+ * ```ts
70
+ * // Pass parameter as NapiConfig
71
+ * await astGrep({
72
+ * rule: {
73
+ * pattern: {
74
+ * context: "import React from 'react'",
75
+ * strictness: "relaxed",
76
+ * },
77
+ * },
78
+ * })
79
+ * ```
80
+ * @example
81
+ * ```ts
82
+ * // Pass parameter as YAML string literal
83
+ * await astGrep`
84
+ * rule:
85
+ * pattern:
86
+ * context: "import React from 'react'"
87
+ * strictness: "relaxed"
88
+ * `
89
+ * ```
90
+ * @see {@link map}
91
+ * @see {@link filter}
92
+ * @see {@link exists}
93
+ * @see {@link replace}
94
+ * @see {@link ai}
95
+ */
96
+ export declare function astGrepLogic(query: string | readonly string[] | NapiConfig): ReturnType;
97
+ /**
98
+ * @description Search for a pattern in the file using [ast-grep](https://ast-grep.github.io/). There are 2 ways to use this function: controlled and uncontrolled. If you will provide `id` in the `query` object - it will be passed to ast-grep CLI (`uncontrolled` mode). In all other cases `controlled` mode will be used with Napi (Node.js bindings to Rust).
99
+ * @description This function is used for `uncontrolled` mode. You can chain call multiple `astGrep` functions to search for multiple patterns in the file using this mode.
100
+ * @param query It could be a string, string literal, [NapiConfig object](https://ast-grep.github.io/reference/api.html#napiconfig)
101
+ * @example
102
+ * ```ts
103
+ * // Pass directly to ast-grep CLI
104
+ * await astGrep({
105
+ * id: "unique-id",
106
+ * rule: {
107
+ * pattern: {
108
+ * context: "import React from 'react'",
109
+ * strictness: "relaxed",
110
+ * },
111
+ * },
112
+ * fix: "import * as React from 'react'",
113
+ * })
114
+ * ```
115
+ * @example
116
+ * ```ts
117
+ * // Chain call
118
+ * await astGrep({
119
+ * id: "unique-id",
120
+ * rule: {
121
+ * pattern: {
122
+ * context: "import React from 'react'",
123
+ * strictness: "relaxed",
124
+ * },
125
+ * },
126
+ * fix: "import * as React from 'react'",
127
+ * })
128
+ * .astGrep({
129
+ * id: "another-unique-id",
130
+ * rule: {
131
+ * pattern: {
132
+ * context: "import { useState } from 'react'",
133
+ * strictness: "relaxed",
134
+ * },
135
+ * },
136
+ * fix: "import { useRef } from 'react'",
137
+ * })
138
+ * ```
139
+ */
140
+ export declare function astGrepLogic(apiQuery: AstGrepAPI): ReturnTypeAPI;
141
+ /**
142
+ * @description Search for a pattern in the file using [ast-grep](https://ast-grep.github.io/). There are 2 ways to use this function: controlled and uncontrolled. If you will provide `id` in the `query` object - it will be passed to ast-grep CLI (`uncontrolled` mode). In all other cases `controlled` mode will be used with Napi (Node.js bindings to Rust).
143
+ * @param query It could be a string, string literal, [NapiConfig object](https://ast-grep.github.io/reference/api.html#napiconfig)
144
+ * @param callback Function which will be called for each found node wich accepts one argument - object with helpers, which could be used to manipulate the found nodes. Callback will have all the helpers that `astGrep` returns, like `map`, `replace` etc...
145
+ * @example
146
+ * ```ts
147
+ * // Use callback
148
+ * await astGrep("console.log($$$ARGS)", async ({ map, replace }) => {
149
+ * console.log(`Found code occurencies: ${(await map(({ getNode }) => getNode().text())).join(", ")}`);
150
+ * await replace("console.error($$$ARGS)");
151
+ * })
152
+ * ```
153
+ * @see {@link map}
154
+ * @see {@link filter}
155
+ * @see {@link exists}
156
+ * @see {@link replace}
157
+ * @see {@link ai}
158
+ */
159
+ export declare function astGrepLogic(query: string | readonly string[] | NapiConfig, callback: (helpers: AstGrepHelpers) => Promise<void> | void): ReturnType;
160
+ export declare const astGrep: typeof astGrepLogic;
161
+ export type ReturnType = PLazy<AstGrepHelpers> & AstGrepHelpers;
162
+ export type ReturnTypeAPI = PLazy<AstGrepAPIHelpers> & AstGrepAPIHelpers;
163
+ declare const astGrepHelpers: {
164
+ replace: typeof import("./replace.js").replaceLogic;
165
+ map: typeof import("./map.js").mapLogic;
166
+ ai: typeof import("../ai/ai.js").aiLogic;
167
+ filter: typeof import("./filter.js").filterLogic;
168
+ exists: typeof import("./exists.js").existsLogic;
169
+ };
170
+ declare const astGrepAPIHelpers: {
171
+ astGrep: typeof astGrepLogic;
172
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @description Returns true if astGrep found at least one node that matches the given query.
3
+ * @example
4
+ * ```ts
5
+ * // Check if there is at least one console.log in the code
6
+ * const areConsoleLogExist = await astGrep`console.log($$$A)`
7
+ * .exists()
8
+ * ```
9
+ */
10
+ export declare function existsLogic(): Promise<boolean>;
11
+ export declare const exists: typeof existsLogic;
@@ -0,0 +1,35 @@
1
+ import type { PLazy } from "../PLazy.js";
2
+ declare const callbackHelpers: {
3
+ getNode: () => import("@ohos-ports/ast-grep-napi").SgNode;
4
+ getMatch: (m: string) => import("@ohos-ports/ast-grep-napi").SgNode | null;
5
+ getMultipleMatches: (m: string) => import("@ohos-ports/ast-grep-napi").SgNode[];
6
+ };
7
+ export type CallbackHelpers = typeof callbackHelpers;
8
+ export type FilterReturn = PLazy<Helpers> & Helpers;
9
+ /**
10
+ * @description Filter the nodes found with astGrep using callback function. If function returns true - node will be included in the result, otherwise - excluded.
11
+ * @param callback - Callback function that will be executed for each node found with astGrep. If function returns true - node will be included in the result, otherwise - excluded.
12
+ * @example
13
+ * ```ts
14
+ * // Replace all console.log calls with "2" where the first argument is "1"
15
+ * await astGrep`console.log($A)`
16
+ * .filter(({ getMatch }) => getMatch("A") === "1")
17
+ * .replace`console.log(2)`
18
+ * ```
19
+ * @see {@link map}
20
+ * @see {@link replace}
21
+ * @see {@link filter}
22
+ * @see {@link exists}
23
+ * @see {@link ai}
24
+ */
25
+ export declare function filterLogic(callback: (helpers: CallbackHelpers) => Promise<boolean> | boolean): FilterReturn;
26
+ export declare const filter: typeof filterLogic;
27
+ declare const helpers: {
28
+ map: typeof import("./map.js").mapLogic;
29
+ filter: typeof filterLogic;
30
+ replace: typeof import("./replace.js").replaceLogic;
31
+ ai: typeof import("../ai/ai.js").aiLogic;
32
+ exists: typeof import("./exists.js").existsLogic;
33
+ };
34
+ type Helpers = typeof helpers;
35
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Same as astGrep, but searches with single and double quotes
3
+ * @deprecated
4
+ * @example
5
+ * ```ts
6
+ * await getImports("import React from 'react'");
7
+ * // is equal to
8
+ * await astGrep("import React from 'react'");
9
+ * // and
10
+ * await astGrep('import React from "react"');
11
+ * ```
12
+ */
13
+ export declare function getImports(source: string): import("./astGrep.js").ReturnType;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @description Map each found with astGrep node and return resulting array. Could be used to retrieve some information from code.
3
+ * @param callback - Callback function that will be called for each found node.
4
+ * @example
5
+ * ```ts
6
+ * // Retrieve first argument for every console.log expression
7
+ * await astGrep`console.log($A)`
8
+ * .map(({ getMatch }) => getMatch('A'))
9
+ * ```
10
+ */
11
+ export declare function mapLogic<CALLBACK extends (helpers: Helpers) => ReturnType<CALLBACK> | Promise<ReturnType<CALLBACK>>, RETURN extends ReturnType<CALLBACK>>(callback: CALLBACK): Promise<RETURN[]>;
12
+ export declare const map: typeof mapLogic;
13
+ declare const helpers: {
14
+ getNode: () => import("@ohos-ports/ast-grep-napi").SgNode;
15
+ getMatch: (m: string) => import("@ohos-ports/ast-grep-napi").SgNode | null;
16
+ getMultipleMatches: (m: string) => import("@ohos-ports/ast-grep-napi").SgNode[];
17
+ };
18
+ export type Helpers = typeof helpers;
19
+ export {};
@@ -0,0 +1,43 @@
1
+ import type { PLazy } from "../PLazy.js";
2
+ declare const callbackHelpers: {
3
+ getNode: () => import("@ohos-ports/ast-grep-napi").SgNode;
4
+ getMatch: (m: string) => import("@ohos-ports/ast-grep-napi").SgNode | null;
5
+ getMultipleMatches: (m: string) => import("@ohos-ports/ast-grep-napi").SgNode[];
6
+ };
7
+ export type CallbackHelpers = typeof callbackHelpers;
8
+ export type ReplaceReturn = PLazy<Helpers> & Helpers;
9
+ /**
10
+ * @description Replace every found with astGrep node with the replacement string (or template literal). String can contain single match or multiple matches.
11
+ * @param replacement The replacement string or template literal
12
+ * @example
13
+ * ```ts
14
+ * // Replace every console.log with remove message
15
+ * await astGrep`console.log($$$A)`
16
+ * .replace('∕* removed console.log *∕')
17
+ * ```
18
+ * @example
19
+ * ```ts
20
+ * // Replace every console.log with console.error
21
+ * await astGrep`console.log($$$A)`
22
+ * .replace`console.error($$$A)`
23
+ * ```
24
+ */
25
+ export declare function replaceLogic(rawReplacement: string | Readonly<string[]>): ReplaceReturn;
26
+ /**
27
+ * @description Replace every found with astGrep node with the replacement string (or template literal) using callback.
28
+ * @param callback The callback function that returns the replacement string or template literal. First argument is the helpers object, which has getNode, getMatch and getMultipleMatches functions.
29
+ * @example
30
+ * ```ts
31
+ * // Replace every console.log with remove message
32
+ * await astGrep`console.log($$$A)`
33
+ * .replace(({ getMultipleMatches }) =>
34
+ * `console.error(${getMultipleMatches('A').join(', ')}`)
35
+ * ```
36
+ */
37
+ export declare function replaceLogic(callback: (helpers: CallbackHelpers) => Promise<string | undefined> | string | undefined): ReplaceReturn;
38
+ export declare const replace: typeof replaceLogic;
39
+ declare const helpers: {
40
+ map: typeof import("./map.js").mapLogic;
41
+ };
42
+ export type Helpers = typeof helpers;
43
+ export {};
@@ -0,0 +1,6 @@
1
+ export interface AuthServiceInterface {
2
+ getGithubAPIKey(): Promise<string | undefined>;
3
+ ensureGithubScopes(scopes?: string[]): Promise<boolean>;
4
+ }
5
+ export declare function setAuthService(service: AuthServiceInterface): void;
6
+ export declare function getAuthService(): AuthServiceInterface | undefined;
@@ -0,0 +1,35 @@
1
+ import type { PLazy } from "./PLazy.js";
2
+ export type CodemodReturn = PLazy<CodemodHelpers> & CodemodHelpers;
3
+ /**
4
+ * Run a codemod in current working directory
5
+ * @param name The name of the codemod (check for available codemods at https://codemod.com/registry)
6
+ * @param args Arguments to pass to the codemod, e.g. `{ dry: true }`, where `dry` is a flag that the codemod accepts
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // Simple run
11
+ * await codemod("valibot/upgrade-v0.31");
12
+ * ```
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // Run with arguments
17
+ * await codemod("valibot/upgrade-v0.31", { dry: true });
18
+ * ```
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // Chaining codemods
23
+ * await codemod("valibot/upgrade-v0.31")
24
+ * .codemod("valibot/upgrade-v0.32")
25
+ * .codemod("valibot/upgrade-v0.33");
26
+ * ```
27
+ */
28
+ export declare function codemodLogic(name: string, args?: Record<string, string | number | boolean | (string | number | boolean)[]>): CodemodReturn;
29
+ export declare const codemod: typeof codemodLogic;
30
+ declare const codemodHelpers: {
31
+ codemod: typeof codemodLogic;
32
+ exec: typeof import("./exec.js").execLogic;
33
+ };
34
+ type CodemodHelpers = typeof codemodHelpers;
35
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare class Context<T extends Record<string, any>> {
2
+ protected _context: T;
3
+ constructor(data: T);
4
+ set(key: keyof T, value: T[keyof T]): void;
5
+ get(key: keyof T): T[keyof T];
6
+ }
@@ -0,0 +1,28 @@
1
+ import MagicString from "magic-string";
2
+ import { Context } from "./Context.js";
3
+ export type FileContextData = {
4
+ file: string;
5
+ };
6
+ export declare class FileContext extends Context<FileContextData> {
7
+ private _contents;
8
+ private _magicString;
9
+ private _contentsChanged;
10
+ private _oldContents;
11
+ importsUpdates: {
12
+ type: "add" | "remove";
13
+ import: string;
14
+ }[];
15
+ get file(): string;
16
+ contents(): Promise<string>;
17
+ setContents(contents: string): void;
18
+ magicString(): Promise<MagicString>;
19
+ update({ start, end, replacement, }: {
20
+ start: number;
21
+ end: number;
22
+ replacement: string;
23
+ }): Promise<void>;
24
+ save({ format }?: {
25
+ format?: boolean;
26
+ }): Promise<void>;
27
+ get extension(): string | undefined;
28
+ }
@@ -0,0 +1,12 @@
1
+ import { Context } from "./Context.js";
2
+ export type GitContextData = {
3
+ repository: string;
4
+ id: string;
5
+ };
6
+ export declare class GitContext extends Context<GitContextData> {
7
+ get simpleGit(): import("simple-git").SimpleGit;
8
+ checkout({ branch, force }: {
9
+ branch: string;
10
+ force?: boolean;
11
+ }): Promise<void>;
12
+ }