Skip to content

Commit 88624dd

Browse files
fix: types
1 parent 5ba7081 commit 88624dd

File tree

5 files changed

+55
-72
lines changed

5 files changed

+55
-72
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Each codemod resides in its own directory under `recipes/` and should include:
4040
**`src/workflow.ts` example:**
4141
```ts
4242
import type { SgRoot, Edit } from "@codemod.com/jssg-types/main";
43+
import type JS from "@codemod.com/jssg-types/langs/javascript";
44+
4345
/**
4446
* Transform function that converts deprecated api.fn calls
4547
* to the new api.fn syntax.
@@ -49,12 +51,15 @@ import type { SgRoot, Edit } from "@codemod.com/jssg-types/main";
4951
* 2. api.fn(<args>, { recursive: true })
5052
* ...
5153
*/
52-
export default function transform(root: SgRoot): string | null {
54+
export default function transform(root: SgRoot<JS>): string | null {
5355
const rootNode = root.root();
54-
let hasChanges = false;
5556
const edits: Edit[] = [];
57+
5658
// do some transformation
57-
if (!hasChanges) return null;
59+
edits.push(...);
60+
61+
if (edits.length === 0) return null;
62+
5863
return rootNode.commitEdits(edits);
5964
}
6065
```

package-lock.json

Lines changed: 39 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"pre-commit": "node --run lint:fix; node --run type-check; node --run test",
1010
"test": "npm run test --workspaces --if-present",
1111
"test-legacy": "npm run test-legacy --workspaces --if-present",
12-
"type-check": "tsgo"
12+
"type-check": "tsgo --noEmit"
1313
},
1414
"repository": {
1515
"type": "git",
@@ -29,7 +29,7 @@
2929
"devDependencies": {
3030
"@biomejs/biome": "2.1.4",
3131
"@types/node": "^24.2.1",
32-
"@typescript/native-preview": "^7.0.0-dev.20250825.1"
32+
"@typescript/native-preview": "^7.0.0-dev.20250916.1"
3333
},
3434
"workspaces": [
3535
"./recipes/*",

recipes/http-classes-with-new/src/workflow.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getNodeImportStatements } from '@nodejs/codemod-utils/ast-grep/import-s
22
import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call';
33
import { resolveBindingPath } from '@nodejs/codemod-utils/ast-grep/resolve-binding-path';
44
import type { SgRoot, Edit, SgNode } from '@codemod.com/jssg-types/main';
5+
import type JS from "@codemod.com/jssg-types/langs/javascript";
56

67
/**
78
* Classes of the http module
@@ -26,7 +27,7 @@ const CLASS_NAMES = [
2627
* 5. `http.Server()` → `new http.Server()`
2728
* 6. `http.ServerResponse() → `new http.ServerResponse()`
2829
*/
29-
export default function transform(root: SgRoot): string | null {
30+
export default function transform(root: SgRoot<JS>): string | null {
3031
const rootNode = root.root();
3132
const edits: Edit[] = [];
3233

@@ -59,7 +60,7 @@ export default function transform(root: SgRoot): string | null {
5960
* @param statements - The import & require statements to search for the http classes
6061
* @returns The base path of the http classes
6162
*/
62-
function* getHttpClassBasePaths(statements: SgNode[]) {
63+
function* getHttpClassBasePaths(statements: SgNode<JS>[]) {
6364
for (const cls of CLASS_NAMES) {
6465
for (const stmt of statements) {
6566
const resolvedPath = resolveBindingPath(stmt, `$.${cls}`);

recipes/types-is-native-error/src/workflow.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-s
44
import { resolveBindingPath } from "@nodejs/codemod-utils/ast-grep/resolve-binding-path";
55
import { removeLines } from "@nodejs/codemod-utils/ast-grep/remove-lines";
66
import { removeBinding } from "@nodejs/codemod-utils/ast-grep/remove-binding";
7+
import type JS from "@codemod.com/jssg-types/langs/javascript";
78

89
type Binding = {
910
path: string;
1011
lastPropertyAccess?: string;
1112
propertyAccess?: string;
1213
depth: number;
13-
node: SgNode;
14+
node: SgNode<JS>;
1415
};
1516

1617
/**
@@ -72,7 +73,7 @@ function createPropBinding(
7273
* isNativeError have been replaced
7374
*
7475
*/
75-
export default function transform(root: SgRoot): string | null {
76+
export default function transform(root: SgRoot<JS>): string | null {
7677
const rootNode = root.root();
7778
const bindings: Binding[] = [];
7879
const edits: Edit[] = [];

0 commit comments

Comments
 (0)