From 1f87608420e4c4593819ff78d66e54cb5d225bdb Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Tue, 29 Jul 2025 21:55:10 +0200 Subject: [PATCH 1/8] fix: add missing `tsconfig.json` --- .../create-require-from-path/tsconfig.json | 26 +++++++++++++++++++ recipes/process-main-module/tsconfig.json | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 recipes/create-require-from-path/tsconfig.json create mode 100644 recipes/process-main-module/tsconfig.json diff --git a/recipes/create-require-from-path/tsconfig.json b/recipes/create-require-from-path/tsconfig.json new file mode 100644 index 00000000..dbad0f78 --- /dev/null +++ b/recipes/create-require-from-path/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "allowImportingTsExtensions": true, + "allowJs": true, + "alwaysStrict": true, + "baseUrl": "./", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "lib": ["ESNext", "DOM"], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noImplicitThis": true, + "removeComments": true, + "strict": true, + "stripInternal": true, + "target": "esnext" + }, + "include": ["./"], + "exclude": [ + "node_modules", + "./node_modules", + "tests/expected/**", + "tests/input/**" + ] +} diff --git a/recipes/process-main-module/tsconfig.json b/recipes/process-main-module/tsconfig.json new file mode 100644 index 00000000..dbad0f78 --- /dev/null +++ b/recipes/process-main-module/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "allowImportingTsExtensions": true, + "allowJs": true, + "alwaysStrict": true, + "baseUrl": "./", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "lib": ["ESNext", "DOM"], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noImplicitThis": true, + "removeComments": true, + "strict": true, + "stripInternal": true, + "target": "esnext" + }, + "include": ["./"], + "exclude": [ + "node_modules", + "./node_modules", + "tests/expected/**", + "tests/input/**" + ] +} From 4bff43f8d9a914f2df72fcc5153240e131267e73 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Sun, 3 Aug 2025 11:38:40 +0200 Subject: [PATCH 2/8] update --- recipes/correct-ts-specifiers/tsconfig.json | 24 ++----------------- .../create-require-from-path/tsconfig.json | 24 +------------------ .../tsconfig.json | 24 +------------------ recipes/process-main-module/tsconfig.json | 24 +------------------ recipes/rmdir/tsconfig.json | 21 +--------------- tsconfig.json | 22 ++--------------- 6 files changed, 8 insertions(+), 131 deletions(-) diff --git a/recipes/correct-ts-specifiers/tsconfig.json b/recipes/correct-ts-specifiers/tsconfig.json index 3a850c68..940b62a6 100644 --- a/recipes/correct-ts-specifiers/tsconfig.json +++ b/recipes/correct-ts-specifiers/tsconfig.json @@ -1,27 +1,7 @@ { - "compilerOptions": { - "allowImportingTsExtensions": true, - "allowJs": true, - "alwaysStrict": true, - "baseUrl": "./", - "declaration": true, - "declarationMap": true, - "emitDeclarationOnly": true, - "lib": ["ESNext", "DOM"], - "module": "NodeNext", - "moduleResolution": "NodeNext", - "noImplicitThis": true, - "removeComments": true, - "strict": true, - "stripInternal": true, - "target": "esnext" - }, + "extends": ["../../tsconfig.json"], "include": ["./"], "exclude": [ - "node_modules", - "./node_modules", - "**/*.fixture.mjs", - "**/*.mock.mjs", - "**/*.test.mjs" + "**/*.test.ts" ] } diff --git a/recipes/create-require-from-path/tsconfig.json b/recipes/create-require-from-path/tsconfig.json index dbad0f78..b0428311 100644 --- a/recipes/create-require-from-path/tsconfig.json +++ b/recipes/create-require-from-path/tsconfig.json @@ -1,26 +1,4 @@ { - "compilerOptions": { - "allowImportingTsExtensions": true, - "allowJs": true, - "alwaysStrict": true, - "baseUrl": "./", - "declaration": true, - "declarationMap": true, - "emitDeclarationOnly": true, - "lib": ["ESNext", "DOM"], - "module": "NodeNext", - "moduleResolution": "NodeNext", - "noImplicitThis": true, - "removeComments": true, - "strict": true, - "stripInternal": true, - "target": "esnext" - }, + "extends": ["../../tsconfig.json"], "include": ["./"], - "exclude": [ - "node_modules", - "./node_modules", - "tests/expected/**", - "tests/input/**" - ] } diff --git a/recipes/import-assertions-to-attributes/tsconfig.json b/recipes/import-assertions-to-attributes/tsconfig.json index dbad0f78..b0428311 100644 --- a/recipes/import-assertions-to-attributes/tsconfig.json +++ b/recipes/import-assertions-to-attributes/tsconfig.json @@ -1,26 +1,4 @@ { - "compilerOptions": { - "allowImportingTsExtensions": true, - "allowJs": true, - "alwaysStrict": true, - "baseUrl": "./", - "declaration": true, - "declarationMap": true, - "emitDeclarationOnly": true, - "lib": ["ESNext", "DOM"], - "module": "NodeNext", - "moduleResolution": "NodeNext", - "noImplicitThis": true, - "removeComments": true, - "strict": true, - "stripInternal": true, - "target": "esnext" - }, + "extends": ["../../tsconfig.json"], "include": ["./"], - "exclude": [ - "node_modules", - "./node_modules", - "tests/expected/**", - "tests/input/**" - ] } diff --git a/recipes/process-main-module/tsconfig.json b/recipes/process-main-module/tsconfig.json index dbad0f78..b0428311 100644 --- a/recipes/process-main-module/tsconfig.json +++ b/recipes/process-main-module/tsconfig.json @@ -1,26 +1,4 @@ { - "compilerOptions": { - "allowImportingTsExtensions": true, - "allowJs": true, - "alwaysStrict": true, - "baseUrl": "./", - "declaration": true, - "declarationMap": true, - "emitDeclarationOnly": true, - "lib": ["ESNext", "DOM"], - "module": "NodeNext", - "moduleResolution": "NodeNext", - "noImplicitThis": true, - "removeComments": true, - "strict": true, - "stripInternal": true, - "target": "esnext" - }, + "extends": ["../../tsconfig.json"], "include": ["./"], - "exclude": [ - "node_modules", - "./node_modules", - "tests/expected/**", - "tests/input/**" - ] } diff --git a/recipes/rmdir/tsconfig.json b/recipes/rmdir/tsconfig.json index 92c12497..b0428311 100644 --- a/recipes/rmdir/tsconfig.json +++ b/recipes/rmdir/tsconfig.json @@ -1,23 +1,4 @@ { - "compilerOptions": { - "allowImportingTsExtensions": true, - "allowJs": true, - "alwaysStrict": true, - "baseUrl": "./", - "declaration": true, - "declarationMap": true, - "emitDeclarationOnly": true, - "lib": ["ESNext", "DOM"], - "module": "NodeNext", - "moduleResolution": "NodeNext", - "noImplicitThis": true, - "removeComments": true, - "strict": true, - "stripInternal": true, - "target": "esnext" - }, + "extends": ["../../tsconfig.json"], "include": ["./"], - "exclude": [ - "tests/**" - ] } diff --git a/tsconfig.json b/tsconfig.json index 583490d9..f6874e3d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -44,27 +44,9 @@ "./utils" ], "exclude": [ - "node_modules", - "**/build/**", - "**/fixtures/**", - "**/expected/**", "**/tests/**", - "**/*.fixture.mjs", - "**/*.fixture.mts", - "**/*.fixture.js", - "**/*.fixture.ts", - "**/*.mock.mjs", - "**/*.e2e.mjs", - "**/*.e2e.mts", - "**/*.e2e.js", - "**/*.e2e.ts", - "**/*.spec.mjs", - "**/*.spec.mts", - "**/*.spec.js", - "**/*.spec.ts", - "**/*.test.mjs", - "**/*.test.mts", - "**/*.test.js", + // For correct-ts-specifiers "**/*.test.ts", + "**/fixtures/**" ], } From 72fbd700c0a64cb4877df0f5b970457aa31fcbe8 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Mon, 25 Aug 2025 11:55:18 +0200 Subject: [PATCH 3/8] update --- .vscode/settings.json | 3 +- package-lock.json | 166 ++++++++++++++++-- package.json | 4 +- .../src/fixtures/e2e/test.ts | 10 +- recipes/correct-ts-specifiers/tsconfig.json | 24 ++- .../create-require-from-path/src/workflow.ts | 3 +- .../create-require-from-path/tsconfig.json | 4 - .../fs-access-mode-constants/src/workflow.ts | 6 +- .../src/workflow.ts | 3 +- .../tsconfig.json | 4 - recipes/process-main-module/src/workflow.ts | 5 +- recipes/process-main-module/tsconfig.json | 4 - recipes/rmdir/src/workflow.ts | 3 +- recipes/rmdir/tsconfig.json | 4 - recipes/tmpdir-to-tmpdir/src/workflow.ts | 3 +- .../util-log-to-console-log/src/workflow.ts | 19 +- .../util-print-to-console-log/src/workflow.ts | 19 +- tsconfig.json | 1 - utils/src/ast-grep/import-statement.ts | 29 +-- utils/src/ast-grep/remove-binding.ts | 9 +- utils/src/ast-grep/require-call.ts | 137 ++++++++------- utils/src/ast-grep/resolve-binding-path.ts | 9 +- 22 files changed, 307 insertions(+), 162 deletions(-) delete mode 100644 recipes/create-require-from-path/tsconfig.json delete mode 100644 recipes/import-assertions-to-attributes/tsconfig.json delete mode 100644 recipes/process-main-module/tsconfig.json delete mode 100644 recipes/rmdir/tsconfig.json diff --git a/.vscode/settings.json b/.vscode/settings.json index d3d7b2b1..c08b234d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,6 @@ "editor.wordWrapColumn": 100, "[markdown]": { "editor.wordWrap": "off" - } + }, + "typescript.experimental.useTsgo": true } diff --git a/package-lock.json b/package-lock.json index 4c7e22d5..bda48042 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "devDependencies": { "@biomejs/biome": "2.1.4", "@types/node": "^24.2.1", - "typescript": "^5.9.2" + "@typescript/native-preview": "^7.0.0-dev.20250825.1" } }, "node_modules/@ampproject/remapping": { @@ -196,6 +196,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -212,6 +213,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -228,6 +230,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -244,6 +247,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -260,6 +264,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -276,6 +281,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -292,6 +298,7 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -308,6 +315,7 @@ "cpu": [ "ia32" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -324,6 +332,7 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ @@ -1664,6 +1673,147 @@ "form-data": "^4.0.0" } }, + "node_modules/@typescript/native-preview": { + "version": "7.0.0-dev.20250825.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview/-/native-preview-7.0.0-dev.20250825.1.tgz", + "integrity": "sha512-DQB0+7nluvRjON/qc/4k6eYxbHII5sMCvMzUX1OOyT6h8nBXATfogBtqQ/NJ3193p+U/9cEgN0uIR+WBcBOuDw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsgo": "bin/tsgo.js" + }, + "engines": { + "node": ">=20.6.0" + }, + "optionalDependencies": { + "@typescript/native-preview-darwin-arm64": "7.0.0-dev.20250825.1", + "@typescript/native-preview-darwin-x64": "7.0.0-dev.20250825.1", + "@typescript/native-preview-linux-arm": "7.0.0-dev.20250825.1", + "@typescript/native-preview-linux-arm64": "7.0.0-dev.20250825.1", + "@typescript/native-preview-linux-x64": "7.0.0-dev.20250825.1", + "@typescript/native-preview-win32-arm64": "7.0.0-dev.20250825.1", + "@typescript/native-preview-win32-x64": "7.0.0-dev.20250825.1" + } + }, + "node_modules/@typescript/native-preview-darwin-arm64": { + "version": "7.0.0-dev.20250825.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-arm64/-/native-preview-darwin-arm64-7.0.0-dev.20250825.1.tgz", + "integrity": "sha512-RT1IMIimoSK4xlcRVDtEwN3m1T5a9FDgdRZSDYlZsQr9e09GkaIAJgPv5yLkpFbAAq57BiBonNM8+hFJcYyH0A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.6.0" + } + }, + "node_modules/@typescript/native-preview-darwin-x64": { + "version": "7.0.0-dev.20250825.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-x64/-/native-preview-darwin-x64-7.0.0-dev.20250825.1.tgz", + "integrity": "sha512-k8/wn0POmMoXczdgywN9gTGiTql3ICJBoKIvdiE3yjJHSipjQcX9WbQ0HSCfX2cliVNFRANfoKArsJUIk9fN3w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=20.6.0" + } + }, + "node_modules/@typescript/native-preview-linux-arm": { + "version": "7.0.0-dev.20250825.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm/-/native-preview-linux-arm-7.0.0-dev.20250825.1.tgz", + "integrity": "sha512-7EqleheGT7N4V5eGNT2n9ZDMoesi190pnYjbolwbIPSZqklZ/4AXApZhYz8vqqALt+TzGBUQ8MWjX/alzDpl5A==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.6.0" + } + }, + "node_modules/@typescript/native-preview-linux-arm64": { + "version": "7.0.0-dev.20250825.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm64/-/native-preview-linux-arm64-7.0.0-dev.20250825.1.tgz", + "integrity": "sha512-VfiMRCipZY5i+PwgNDFHH8/Sm5w5/9U7Uf/Jb69ZgSdgZGpYev++6CAnWhl7wzJBAI72kNK1hD2s870j0RiNyw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.6.0" + } + }, + "node_modules/@typescript/native-preview-linux-x64": { + "version": "7.0.0-dev.20250825.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-x64/-/native-preview-linux-x64-7.0.0-dev.20250825.1.tgz", + "integrity": "sha512-da+bqP2uOD3BrQZgt5fdgvinkekNMh+9enOmjQkv0tdb53PZ5Sf3xEl+yC43TrLfJAFpYHDBU5WTVnSorryZ2Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=20.6.0" + } + }, + "node_modules/@typescript/native-preview-win32-arm64": { + "version": "7.0.0-dev.20250825.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-arm64/-/native-preview-win32-arm64-7.0.0-dev.20250825.1.tgz", + "integrity": "sha512-jivNNnPdc/9OFbMXvCwpwVhwU5gDGb95ER9G5tDhs3zUwynw/Z4pp5DJXDYBqj0oaZBeYDWOyxBKh+TiKYk9qQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.6.0" + } + }, + "node_modules/@typescript/native-preview-win32-x64": { + "version": "7.0.0-dev.20250825.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-x64/-/native-preview-win32-x64-7.0.0-dev.20250825.1.tgz", + "integrity": "sha512-G6bnjriPrsTQ3ZkUg4wzxv8rP7BJ/lrecTMS97BJuHorJCOqF3uoAGFHZRTnlnanxNr2Akm+hD0d77neOZpgFA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20.6.0" + } + }, "node_modules/abort-controller": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", @@ -3852,20 +4002,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/typescript": { - "version": "5.9.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.2.tgz", - "integrity": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/undici-types": { "version": "7.10.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.10.0.tgz", diff --git a/package.json b/package.json index 803157c5..71b4d6a2 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "lint": "biome lint ./", "pre-commit": "node --run lint:fix; node --run type-check; node --run test", "test": "npm run test --workspaces", - "type-check": "tsc" + "type-check": "tsgo" }, "repository": { "type": "git", @@ -28,7 +28,7 @@ "devDependencies": { "@biomejs/biome": "2.1.4", "@types/node": "^24.2.1", - "typescript": "^5.9.2" + "@typescript/native-preview": "^7.0.0-dev.20250825.1" }, "workspaces": [ "./recipes/*", diff --git a/recipes/correct-ts-specifiers/src/fixtures/e2e/test.ts b/recipes/correct-ts-specifiers/src/fixtures/e2e/test.ts index 34df1387..8ce2f40b 100644 --- a/recipes/correct-ts-specifiers/src/fixtures/e2e/test.ts +++ b/recipes/correct-ts-specifiers/src/fixtures/e2e/test.ts @@ -3,17 +3,17 @@ import { URL } from 'node:url'; import { bar } from '@dep/bar'; import { foo } from 'foo'; -import { Bird } from './Bird'; +import { Bird } from './Bird/index.ts'; import { Cat } from './Cat.ts'; -import { Dog } from '…/Dog/index.mjs'; +import { Dog } from '…/Dog/index.mts'; import { baseUrl } from '#config.js'; -import { qux } from './qux.js'; +import { qux } from './qux.js/index.ts'; -export { Zed } from './zed'; +export type { Zed } from './zed.d.ts'; // should.js be unchanged -const nil = await import('./nil.js'); +const nil = await import('./nil.ts'); const bird = new Bird('Tweety'); const cat = new Cat('Milo'); diff --git a/recipes/correct-ts-specifiers/tsconfig.json b/recipes/correct-ts-specifiers/tsconfig.json index 940b62a6..3a850c68 100644 --- a/recipes/correct-ts-specifiers/tsconfig.json +++ b/recipes/correct-ts-specifiers/tsconfig.json @@ -1,7 +1,27 @@ { - "extends": ["../../tsconfig.json"], + "compilerOptions": { + "allowImportingTsExtensions": true, + "allowJs": true, + "alwaysStrict": true, + "baseUrl": "./", + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "lib": ["ESNext", "DOM"], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noImplicitThis": true, + "removeComments": true, + "strict": true, + "stripInternal": true, + "target": "esnext" + }, "include": ["./"], "exclude": [ - "**/*.test.ts" + "node_modules", + "./node_modules", + "**/*.fixture.mjs", + "**/*.mock.mjs", + "**/*.test.mjs" ] } diff --git a/recipes/create-require-from-path/src/workflow.ts b/recipes/create-require-from-path/src/workflow.ts index e8672590..30401693 100644 --- a/recipes/create-require-from-path/src/workflow.ts +++ b/recipes/create-require-from-path/src/workflow.ts @@ -1,6 +1,7 @@ import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement"; import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call"; import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; +import type JS from "@codemod.com/jssg-types/langs/javascript"; /** * Transform function that updates code to replace deprecated `createRequireFromPath` usage @@ -20,7 +21,7 @@ import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; * * 3. Preserves original variable names and declaration types. */ -export default function transform(root: SgRoot): string | null { +export default function transform(root: SgRoot): string | null { const rootNode = root.root(); const edits: Edit[] = []; let hasChanges = false; diff --git a/recipes/create-require-from-path/tsconfig.json b/recipes/create-require-from-path/tsconfig.json deleted file mode 100644 index b0428311..00000000 --- a/recipes/create-require-from-path/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": ["../../tsconfig.json"], - "include": ["./"], -} diff --git a/recipes/fs-access-mode-constants/src/workflow.ts b/recipes/fs-access-mode-constants/src/workflow.ts index f50ceb0f..9fd22096 100644 --- a/recipes/fs-access-mode-constants/src/workflow.ts +++ b/recipes/fs-access-mode-constants/src/workflow.ts @@ -1,13 +1,12 @@ +import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call" +import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement"; import type { Edit, SgRoot } from "@codemod.com/jssg-types/main"; -import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call"; import type Js from "@codemod.com/jssg-types/langs/javascript"; -import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement"; export default function tranform(root: SgRoot): string | null { const rootNode = root.root(); const edits: Edit[] = []; - // @ts-expect-error - ast-grep types are not fully compatible with JSSG types const requireStatements = getNodeRequireCalls(root, "fs"); for (const statement of requireStatements) { @@ -27,7 +26,6 @@ export default function tranform(root: SgRoot): string | null { }; } - // @ts-expect-error - ast-grep types are not fully compatible with JSSG types const importStatements = getNodeImportStatements(root, "fs"); let promisesImportName = ''; diff --git a/recipes/import-assertions-to-attributes/src/workflow.ts b/recipes/import-assertions-to-attributes/src/workflow.ts index 28d34d32..e15aed28 100644 --- a/recipes/import-assertions-to-attributes/src/workflow.ts +++ b/recipes/import-assertions-to-attributes/src/workflow.ts @@ -1,4 +1,5 @@ import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; +import type Js from "@codemod.com/jssg-types/langs/javascript"; /** * Transform function that converts import assertions to import attributes @@ -11,7 +12,7 @@ import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; * 1. import { something } from './module.json' with { type: 'json' }; * 2. import('./module.json', { with: { type: 'json' } }) */ -export default async function transform(root: SgRoot): Promise { +export default async function transform(root: SgRoot): Promise { const rootNode = root.root(); const edits: Edit[] = []; diff --git a/recipes/import-assertions-to-attributes/tsconfig.json b/recipes/import-assertions-to-attributes/tsconfig.json deleted file mode 100644 index b0428311..00000000 --- a/recipes/import-assertions-to-attributes/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": ["../../tsconfig.json"], - "include": ["./"], -} diff --git a/recipes/process-main-module/src/workflow.ts b/recipes/process-main-module/src/workflow.ts index b53a14b7..2b0c86ee 100644 --- a/recipes/process-main-module/src/workflow.ts +++ b/recipes/process-main-module/src/workflow.ts @@ -1,7 +1,8 @@ -import type { Edit, SgRoot, Range } from "@codemod.com/jssg-types/main"; import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call"; import { removeLines } from "@nodejs/codemod-utils/ast-grep/remove-lines"; import { removeBinding } from "@nodejs/codemod-utils/ast-grep/remove-binding"; +import type { Edit, SgRoot, Range } from "@codemod.com/jssg-types/main"; +import type Js from "@codemod.com/jssg-types/langs/javascript"; /** * Transforms `process.mainModule` usage to `require.main`. Handles direct global access @@ -19,7 +20,7 @@ import { removeBinding } from "@nodejs/codemod-utils/ast-grep/remove-binding"; * - Change 'mainModule' → 'require.main' * - Change 'process.mainModule' → 'require.main' */ -export default function transform(root: SgRoot): string | null { +export default function transform(root: SgRoot): string | null { const rootNode = root.root(); const edits: Edit[] = []; const linesToRemove: Range[] = []; diff --git a/recipes/process-main-module/tsconfig.json b/recipes/process-main-module/tsconfig.json deleted file mode 100644 index b0428311..00000000 --- a/recipes/process-main-module/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": ["../../tsconfig.json"], - "include": ["./"], -} diff --git a/recipes/rmdir/src/workflow.ts b/recipes/rmdir/src/workflow.ts index d989c044..6d583d2d 100644 --- a/recipes/rmdir/src/workflow.ts +++ b/recipes/rmdir/src/workflow.ts @@ -2,6 +2,7 @@ import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-s import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call"; import { resolveBindingPath } from "@nodejs/codemod-utils/ast-grep/resolve-binding-path"; import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; +import type Js from "@codemod.com/jssg-types/langs/javascript"; /** * Transform function that converts deprecated fs.rmdir calls @@ -13,7 +14,7 @@ import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; * 3. fs.rmdirSync(path, { recursive: true }) -> fs.rmSync(path, { recursive: true, force: true }) * 4. fs.promises.rmdir(path, { recursive: true }) -> fs.promises.rm(path, { recursive: true, force: true }) */ -export default function transform(root: SgRoot): string | null { +export default function transform(root: SgRoot): string | null { const rootNode = root.root(); let hasChanges = false; const edits: Edit[] = []; diff --git a/recipes/rmdir/tsconfig.json b/recipes/rmdir/tsconfig.json deleted file mode 100644 index b0428311..00000000 --- a/recipes/rmdir/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": ["../../tsconfig.json"], - "include": ["./"], -} diff --git a/recipes/tmpdir-to-tmpdir/src/workflow.ts b/recipes/tmpdir-to-tmpdir/src/workflow.ts index 7fe80386..f366af7e 100644 --- a/recipes/tmpdir-to-tmpdir/src/workflow.ts +++ b/recipes/tmpdir-to-tmpdir/src/workflow.ts @@ -1,6 +1,7 @@ import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement"; import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call"; import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; +import type Js from "@codemod.com/jssg-types/langs/javascript"; /** * Transform function that updates code to replace deprecated `tmpDir` usage @@ -20,7 +21,7 @@ import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; * * 3. Preserves original variable names and declaration types. */ -export default function transform(root: SgRoot): string | null { +export default function transform(root: SgRoot): string | null { const rootNode = root.root(); const edits: Edit[] = []; let hasChanges = false; diff --git a/recipes/util-log-to-console-log/src/workflow.ts b/recipes/util-log-to-console-log/src/workflow.ts index 2221f4f4..1c8dc719 100644 --- a/recipes/util-log-to-console-log/src/workflow.ts +++ b/recipes/util-log-to-console-log/src/workflow.ts @@ -1,21 +1,20 @@ +import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call"; +import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement"; +import { resolveBindingPath } from "@nodejs/codemod-utils/ast-grep/resolve-binding-path"; +import { removeBinding } from "@nodejs/codemod-utils/ast-grep/remove-binding"; +import { removeLines } from "@nodejs/codemod-utils/ast-grep/remove-lines"; import type { Edit, - Kinds, Range, Rule, SgNode, SgRoot, - TypesMap, } from "@codemod.com/jssg-types/main"; -import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call"; -import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement"; -import { resolveBindingPath } from "@nodejs/codemod-utils/ast-grep/resolve-binding-path"; -import { removeBinding } from "@nodejs/codemod-utils/ast-grep/remove-binding"; -import { removeLines } from "@nodejs/codemod-utils/ast-grep/remove-lines"; +import type Js from "@codemod.com/jssg-types/langs/javascript"; type BindingToReplace = { - rule: Rule; - node: SgNode>; + rule: Rule; + node: SgNode; binding: string; }; @@ -31,7 +30,7 @@ type BindingToReplace = { * * Apply all changes, removing or updating the import line as needed. */ -export default function transform(root: SgRoot): string | null { +export default function transform(root: SgRoot): string | null { const rootNode = root.root(); const edits: Edit[] = []; const linesToRemove: Range[] = []; diff --git a/recipes/util-print-to-console-log/src/workflow.ts b/recipes/util-print-to-console-log/src/workflow.ts index b0ccd038..8d7ca4fc 100644 --- a/recipes/util-print-to-console-log/src/workflow.ts +++ b/recipes/util-print-to-console-log/src/workflow.ts @@ -1,21 +1,20 @@ +import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call"; +import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement"; +import { resolveBindingPath } from "@nodejs/codemod-utils/ast-grep/resolve-binding-path"; +import { removeBinding } from "@nodejs/codemod-utils/ast-grep/remove-binding"; +import { removeLines } from "@nodejs/codemod-utils/ast-grep/remove-lines"; import type { Edit, - Kinds, Range, Rule, SgNode, SgRoot, - TypesMap, } from "@codemod.com/jssg-types/main"; -import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call"; -import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement"; -import { resolveBindingPath } from "@nodejs/codemod-utils/ast-grep/resolve-binding-path"; -import { removeBinding } from "@nodejs/codemod-utils/ast-grep/remove-binding"; -import { removeLines } from "@nodejs/codemod-utils/ast-grep/remove-lines"; +import type Js from "@codemod.com/jssg-types/langs/javascript"; type BindingToReplace = { - rule: Rule; - node: SgNode>; + rule: Rule; + node: SgNode; binding: string; replaceFn: (arg: string) => string; }; @@ -54,7 +53,7 @@ const updates = [ * * Apply all changes, removing or updating the import line as needed. */ -export default function transform(root: SgRoot): string | null { +export default function transform(root: SgRoot): string | null { const rootNode = root.root(); const edits: Edit[] = []; const linesToRemove: Range[] = []; diff --git a/tsconfig.json b/tsconfig.json index f6874e3d..35384337 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "baseUrl": "./", "rootDir": "./", "target": "ESNext", diff --git a/utils/src/ast-grep/import-statement.ts b/utils/src/ast-grep/import-statement.ts index 364a11b9..552abf56 100644 --- a/utils/src/ast-grep/import-statement.ts +++ b/utils/src/ast-grep/import-statement.ts @@ -1,18 +1,19 @@ -import type { SgRoot, SgNode } from '@codemod.com/jssg-types/main'; +import type { SgNode, SgRoot } from '@codemod.com/jssg-types/main'; +import type Js from "@codemod.com/jssg-types/langs/javascript"; -export const getNodeImportStatements = (rootNode: SgRoot, nodeModuleName: string): SgNode[] => +export const getNodeImportStatements = (rootNode: SgRoot, nodeModuleName: string): SgNode[] => rootNode - .root() - .findAll({ - rule: { - kind: "import_statement", - has: { - field: "source", - kind: "string", - regex: `^['"](node:)?${nodeModuleName}['"]$` - } + .root() + .findAll({ + rule: { + kind: "import_statement", + has: { + field: "source", + kind: "string", + regex: `^['"](node:)?${nodeModuleName}['"]$` } - }); + } + }); /** * We just catch `variable_declarator` nodes that use `import` to import a module @@ -22,8 +23,8 @@ export const getNodeImportStatements = (rootNode: SgRoot, nodeModuleName: string * We also don't catch pending promises, like `const pending = import("node:module");` * because it's will became to complex to handle in codemod context. (storing var name, checking is method is used, etc.) */ -export const getNodeImportCalls = (rootNode: SgRoot, nodeModuleName: string): SgNode[] => - rootNode +export const getNodeImportCalls = (node: SgRoot, nodeModuleName: string): SgNode[] => + node .root() .findAll({ rule: { diff --git a/utils/src/ast-grep/remove-binding.ts b/utils/src/ast-grep/remove-binding.ts index 04c1f44e..d617fe19 100644 --- a/utils/src/ast-grep/remove-binding.ts +++ b/utils/src/ast-grep/remove-binding.ts @@ -1,4 +1,5 @@ -import type { SgNode, Edit, Range, Kinds, TypesMap } from "@codemod.com/jssg-types/main"; +import type { SgNode, Edit, Range } from "@codemod.com/jssg-types/main"; +import type Js from "@codemod.com/jssg-types/langs/javascript"; const requireKinds = ["lexical_declaration", "variable_declarator"]; const importKinds = ["import_statement", "import_clause"]; @@ -41,7 +42,7 @@ type RemoveBindingReturnType = { * ``` */ export function removeBinding( - node: SgNode>, + node: SgNode, binding: string, ): RemoveBindingReturnType | undefined { const nodeKind = node.kind().toString(); @@ -81,7 +82,7 @@ export function removeBinding( } function handleNamedImportBindings( - node: SgNode>, + node: SgNode, binding: string, ): RemoveBindingReturnType | undefined { const namespaceImport = node.find({ @@ -171,7 +172,7 @@ function handleNamedImportBindings( } function handleNamedRequireBindings( - node: SgNode>, + node: SgNode, binding: string, ): RemoveBindingReturnType | undefined { const objectPattern = node.find({ diff --git a/utils/src/ast-grep/require-call.ts b/utils/src/ast-grep/require-call.ts index 9a8a273f..609de9f6 100644 --- a/utils/src/ast-grep/require-call.ts +++ b/utils/src/ast-grep/require-call.ts @@ -1,4 +1,5 @@ -import type { SgRoot, SgNode } from '@codemod.com/jssg-types/main'; +import type { SgNode, SgRoot } from '@codemod.com/jssg-types/main'; +import type Js from "@codemod.com/jssg-types/langs/javascript"; /** * We just catch `variable_declarator` nodes that use `require` to import a module @@ -6,82 +7,82 @@ import type { SgRoot, SgNode } from '@codemod.com/jssg-types/main'; * catch those. * We also catch `require` calls that are not assigned to a variable, like `const fs = require('fs');` */ -export const getNodeRequireCalls = (rootNode: SgRoot, nodeModuleName: string): SgNode[] => +export const getNodeRequireCalls = (rootNode: SgRoot, nodeModuleName: string): SgNode[] => rootNode - .root() - .findAll({ - rule: { - kind: "variable_declarator", - all: [ - { - has: { - field: "name", - any: [ - { kind: "object_pattern" }, - { kind: "identifier" } - ] - } - }, - { - has: { - field: "value", - any: [ - { - kind: "call_expression", - all: [ - { + .root() + .findAll({ + rule: { + kind: "variable_declarator", + all: [ + { + has: { + field: "name", + any: [ + { kind: "object_pattern" }, + { kind: "identifier" } + ] + } + }, + { + has: { + field: "value", + any: [ + { + kind: "call_expression", + all: [ + { + has: { + field: "function", + kind: "identifier", + regex: "^require$" + } + }, + { + has: { + field: "arguments", + kind: "arguments", has: { - field: "function", - kind: "identifier", - regex: "^require$" + kind: "string", + regex: `^['"](node:)?${nodeModuleName}['"]$` } - }, - { - has: { - field: "arguments", - kind: "arguments", + } + } + ] + }, + { + kind: "member_expression", + all: [ + { + has: { + field: "object", + kind: "call_expression", + all: [ + { has: { - kind: "string", - regex: `^['"](node:)?${nodeModuleName}['"]$` + field: "function", + kind: "identifier", + regex: "^require$" } - } - } - ] - }, - { - kind: "member_expression", - all: [ - { - has: { - field: "object", - kind: "call_expression", - all: [ - { - has: { - field: "function", - kind: "identifier", - regex: "^require$" - } - }, - { + }, + { + has: { + field: "arguments", + kind: "arguments", has: { - field: "arguments", - kind: "arguments", - has: { - kind: "string", - regex: `^['"](node:)?${nodeModuleName}['"]$` - } + kind: "string", + regex: `^['"](node:)?${nodeModuleName}['"]$` } } - ] } + ] } - ] - } - ] - } + } + ] + } + ] } - ] - } - }); + } + ] + } + }); diff --git a/utils/src/ast-grep/resolve-binding-path.ts b/utils/src/ast-grep/resolve-binding-path.ts index 4974b4fd..55d9c4a4 100644 --- a/utils/src/ast-grep/resolve-binding-path.ts +++ b/utils/src/ast-grep/resolve-binding-path.ts @@ -1,4 +1,5 @@ -import type { SgNode, Kinds, TypesMap } from "@codemod.com/jssg-types/main"; +import type { SgNode } from "@codemod.com/jssg-types/main"; +import type Js from "@codemod.com/jssg-types/langs/javascript"; const requireKinds = ["lexical_declaration", "variable_declarator"]; const importKinds = ["import_statement", "import_clause"]; @@ -35,7 +36,7 @@ const supportedKinds = [...requireKinds, ...importKinds]; * // Returns: "utilTypes.isNativeError" * ``` */ -export function resolveBindingPath(node: SgNode>, path: string) { +export function resolveBindingPath(node: SgNode, path: string) { const activeNode = node; const rootKind = activeNode.kind().toString(); @@ -54,7 +55,7 @@ export function resolveBindingPath(node: SgNode>, path } } -function resolveBindingPathRequire(node: SgNode>, path: string) { +function resolveBindingPathRequire(node: SgNode, path: string) { const pathArr = path.split("."); let activeNode = node; const rootKind = node.kind(); @@ -125,7 +126,7 @@ function resolveBindingPathRequire(node: SgNode>, path } } -function resolveBindingPathImport(node: SgNode>, path: string) { +function resolveBindingPathImport(node: SgNode, path: string) { const pathArr = path.split("."); let activeNode = node; const rootKind = node.kind(); From e917650c9c0d054bcbeddc5c66a227e4aa24481d Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Wed, 17 Sep 2025 09:22:40 +0200 Subject: [PATCH 4/8] Update package.json --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 71b4d6a2..20bbfef9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "lint:fix": "biome lint --fix ./", "lint": "biome lint ./", "pre-commit": "node --run lint:fix; node --run type-check; node --run test", - "test": "npm run test --workspaces", + "test": "npm run test --workspaces --if-present", + "test-legacy": "npm run test-legacy --workspaces --if-present", "type-check": "tsgo" }, "repository": { From 5ba70810848fdcd2b205070942653cf92c49bd88 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Wed, 17 Sep 2025 09:24:45 +0200 Subject: [PATCH 5/8] Update package-lock.json --- package-lock.json | 157 +++++++++++++++++++++++++++------------------- 1 file changed, 93 insertions(+), 64 deletions(-) diff --git a/package-lock.json b/package-lock.json index bda48042..3ea71fb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -169,30 +169,30 @@ } }, "node_modules/@ast-grep/napi": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi/-/napi-0.39.3.tgz", - "integrity": "sha512-Y+16O9AbeR+yr5qnVpXHXHv/3EG2IPGCIbvxYo4MZpFSAmUBYibiLP0GljK5TWkQz6y4u5eHso3F13evyww4rw==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi/-/napi-0.39.5.tgz", + "integrity": "sha512-/qEPYdY0+Mg4fdS06CY4Jptzbd6NDvdkKRBL1vTnpY8BO4t6j1q9sbNobgm74pr2xPv13Z4Lq2hVNzAYJNy9dw==", "dev": true, "license": "MIT", "engines": { "node": ">= 10" }, "optionalDependencies": { - "@ast-grep/napi-darwin-arm64": "0.39.3", - "@ast-grep/napi-darwin-x64": "0.39.3", - "@ast-grep/napi-linux-arm64-gnu": "0.39.3", - "@ast-grep/napi-linux-arm64-musl": "0.39.3", - "@ast-grep/napi-linux-x64-gnu": "0.39.3", - "@ast-grep/napi-linux-x64-musl": "0.39.3", - "@ast-grep/napi-win32-arm64-msvc": "0.39.3", - "@ast-grep/napi-win32-ia32-msvc": "0.39.3", - "@ast-grep/napi-win32-x64-msvc": "0.39.3" + "@ast-grep/napi-darwin-arm64": "0.39.5", + "@ast-grep/napi-darwin-x64": "0.39.5", + "@ast-grep/napi-linux-arm64-gnu": "0.39.5", + "@ast-grep/napi-linux-arm64-musl": "0.39.5", + "@ast-grep/napi-linux-x64-gnu": "0.39.5", + "@ast-grep/napi-linux-x64-musl": "0.39.5", + "@ast-grep/napi-win32-arm64-msvc": "0.39.5", + "@ast-grep/napi-win32-ia32-msvc": "0.39.5", + "@ast-grep/napi-win32-x64-msvc": "0.39.5" } }, "node_modules/@ast-grep/napi-darwin-arm64": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi-darwin-arm64/-/napi-darwin-arm64-0.39.3.tgz", - "integrity": "sha512-XfTqyDOOyYzAJo0ZOLowrWKnwIB2q6PpFJG1EZFWLkMB54nHub+XDseLxA33uy3O4TpereMaJwUYBDFmOlDqtg==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-darwin-arm64/-/napi-darwin-arm64-0.39.5.tgz", + "integrity": "sha512-UqIUjowAcXTJ00R5+bIi+2nQStzbpBeFEsXe0G1hXZVsWytaa69W4/Ewnr84IdeIo7IcpbFY/Y35PdYIDR36eQ==", "cpu": [ "arm64" ], @@ -207,9 +207,9 @@ } }, "node_modules/@ast-grep/napi-darwin-x64": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi-darwin-x64/-/napi-darwin-x64-0.39.3.tgz", - "integrity": "sha512-uncDaz0wJWPHRSB76cllFzVVqJJoN2KisbJKvoBoX7yTCtQtOloWpLf+V+RM7KLzk9sruhDZeWqV2929MgUGTw==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-darwin-x64/-/napi-darwin-x64-0.39.5.tgz", + "integrity": "sha512-TZLIFoGbVUD9iCQmYTv2isLUBVRPu9kd+q1ifkdQ4iaSlit5UEqvvgluU0NHhWeAg1pW5EuN2COlSbvlcr/RKQ==", "cpu": [ "x64" ], @@ -224,9 +224,9 @@ } }, "node_modules/@ast-grep/napi-linux-arm64-gnu": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-arm64-gnu/-/napi-linux-arm64-gnu-0.39.3.tgz", - "integrity": "sha512-ciNe9s54JUtttFtsdkBmexdZroX0WwgYgj8CE0qscGs5u1fjaEaQghgwR8l9DnckAm556S6KpszFhscTj69vNA==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-arm64-gnu/-/napi-linux-arm64-gnu-0.39.5.tgz", + "integrity": "sha512-QPoVTfRzIyQRI7lNRMsuOTr8OfFLw8iLQSOHwAqa64Cb5AnjJIfLZEBIJhWj+z62ZWcFiX9sn2c8HlCp+58lAg==", "cpu": [ "arm64" ], @@ -241,9 +241,9 @@ } }, "node_modules/@ast-grep/napi-linux-arm64-musl": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-arm64-musl/-/napi-linux-arm64-musl-0.39.3.tgz", - "integrity": "sha512-K5rXJmaQ06H5PGCeSRTTiqszkFcEgRSryJYVs/5r/xj5scZwM7Xme+D6gc7FD/x2CuQ5cPQAJeH698zGbPV2Zg==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-arm64-musl/-/napi-linux-arm64-musl-0.39.5.tgz", + "integrity": "sha512-pk756OgZxienyktNJqiYHVF11zWR/zmOQRiFEzN70W+rWI6wQFRvdi4JPaezKScR524AKuSAeWXR7PUglBnoaA==", "cpu": [ "arm64" ], @@ -258,9 +258,9 @@ } }, "node_modules/@ast-grep/napi-linux-x64-gnu": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-x64-gnu/-/napi-linux-x64-gnu-0.39.3.tgz", - "integrity": "sha512-5xHCVTYj2sOsv0FriSpymrNx9FX5qOxjFKYkDwmJsTiAiENmmFyELNyfAN3ONeEpsV3kBJAZ0BBmd1KcBVOwRQ==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-x64-gnu/-/napi-linux-x64-gnu-0.39.5.tgz", + "integrity": "sha512-UcQSD5A10isLk1TqvFzp4MfPZhAUc0Ehraf3ytsgaIjs9GUxjEc4uI6aKVesXd0Y1DDE/SjakgNfcAcizokjPw==", "cpu": [ "x64" ], @@ -275,9 +275,9 @@ } }, "node_modules/@ast-grep/napi-linux-x64-musl": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-x64-musl/-/napi-linux-x64-musl-0.39.3.tgz", - "integrity": "sha512-6sD1YRKhios38r0muRX2AMIZDinaiRfF31rE4L2gMP0IeJm5s4uJKqVa6eoBAMyGgZlhne1ySNwJ06HBxgIqRw==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-x64-musl/-/napi-linux-x64-musl-0.39.5.tgz", + "integrity": "sha512-aJyiF57bA8Pa6H5hPNq5qz/hh6Q/NQ3f0cAe0oE09KW09lLGK3CWWInENq8QiK+nhO1aAaFvxGhUKUDwroA9ow==", "cpu": [ "x64" ], @@ -292,9 +292,9 @@ } }, "node_modules/@ast-grep/napi-win32-arm64-msvc": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi-win32-arm64-msvc/-/napi-win32-arm64-msvc-0.39.3.tgz", - "integrity": "sha512-3f5jrd6ar7RfD+djCxgf4QCRjVVOsyuU4lnwzFpdEcuZPVdI6jTzCoXg7D5bDkHeml8ZO6ojezkty74PbJZm4g==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-win32-arm64-msvc/-/napi-win32-arm64-msvc-0.39.5.tgz", + "integrity": "sha512-FfluwNw+oItFVMr7o26lnK9euFU6084JSBLFsbIhTdfZO2xiTRrxPXFm5A3jvr0grv669GBLJKfp9DNxcsoYsg==", "cpu": [ "arm64" ], @@ -309,9 +309,9 @@ } }, "node_modules/@ast-grep/napi-win32-ia32-msvc": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi-win32-ia32-msvc/-/napi-win32-ia32-msvc-0.39.3.tgz", - "integrity": "sha512-h5qtHRnV8KaAFRQWff1PkRctFueRTEDSrBnr18xQTShbRdUEzQApoEPsGRWnpuOJzBDgTYkkX3XDEQy8tVFJyg==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-win32-ia32-msvc/-/napi-win32-ia32-msvc-0.39.5.tgz", + "integrity": "sha512-pmx8Zfdv8qEgoepDB+XqV+nThnBioxvsDQT+q310RmeP4cRuSEHI13U3eb5Bgy/E0tGFzTSnQSKifZHuonp7YA==", "cpu": [ "ia32" ], @@ -326,9 +326,9 @@ } }, "node_modules/@ast-grep/napi-win32-x64-msvc": { - "version": "0.39.3", - "resolved": "https://registry.npmjs.org/@ast-grep/napi-win32-x64-msvc/-/napi-win32-x64-msvc-0.39.3.tgz", - "integrity": "sha512-syA3xRMS25RiSCJ1JWP5D00UwFvJSoQgHP4O5BGreouRqRpQlJr4CD4Sdf+UuHHwGbDYb652SoEKsi1rHo0M/Q==", + "version": "0.39.5", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-win32-x64-msvc/-/napi-win32-x64-msvc-0.39.5.tgz", + "integrity": "sha512-bffrn4aF7Tu7hN6qPfZ6PCcbfwRokamUst32ZyJIxBJRAuVua1+CDBXeBug6UHj96tSt0Oh6h2cvh+1mEqL1jg==", "cpu": [ "x64" ], @@ -1041,9 +1041,9 @@ } }, "node_modules/@codemod.com/jssg-types": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@codemod.com/jssg-types/-/jssg-types-1.0.3.tgz", - "integrity": "sha512-spr0WkE2cRliMiz1pDO5xWaCWH6dZuq1QRqbnVSPj6gqKN/26LY7Sk5k/Xm5hJEZaOgy8GqEpX4BPUeOOqVlEw==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@codemod.com/jssg-types/-/jssg-types-1.0.8.tgz", + "integrity": "sha512-bhKGpNAu9/bd4L35xRRNi6xebmnUehkSFRY4fMAd1MwTLZbmIrrYKRYnblImXea8m+ZrbAUBhHKG5qNh1/1KhA==", "dev": true, "license": "Apache-2.0" }, @@ -1424,6 +1424,10 @@ "resolved": "recipes/fs-access-mode-constants", "link": true }, + "node_modules/@nodejs/http-classes-with-new": { + "resolved": "recipes/http-classes-with-new", + "link": true + }, "node_modules/@nodejs/import-assertions-to-attributes": { "resolved": "recipes/import-assertions-to-attributes", "link": true @@ -1440,6 +1444,10 @@ "resolved": "recipes/tmpdir-to-tmpdir", "link": true }, + "node_modules/@nodejs/types-is-native-error": { + "resolved": "recipes/types-is-native-error", + "link": true + }, "node_modules/@nodejs/util-log-to-console-log": { "resolved": "recipes/util-log-to-console-log", "link": true @@ -1655,12 +1663,12 @@ } }, "node_modules/@types/node": { - "version": "24.2.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.2.1.tgz", - "integrity": "sha512-DRh5K+ka5eJic8CjH7td8QpYEV6Zo10gfRkjHCO3weqZHWDtAaSTFtl4+VMqOJ4N5jcuhZ9/l+yy8rVgw7BQeQ==", + "version": "24.5.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.5.1.tgz", + "integrity": "sha512-/SQdmUP2xa+1rdx7VwB9yPq8PaKej8TD5cQ+XfKDPWWC+VDJU4rvVVagXqKUzhKjtFoNA8rXDJAkCxQPAe00+Q==", "license": "MIT", "dependencies": { - "undici-types": "~7.10.0" + "undici-types": "~7.12.0" } }, "node_modules/@types/node-fetch": { @@ -2256,9 +2264,9 @@ } }, "node_modules/dedent": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.6.0.tgz", - "integrity": "sha512-F1Z+5UCFpmQUzJa11agbyPVMbpgT/qA3/SKyJ1jyBgm7dUcUEa8v9JwDkerSQXfakBwFljIxhOJqGkjUwZ9FSA==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.7.0.tgz", + "integrity": "sha512-HGFtf8yhuhGhqO07SV79tRp+br4MnbdjeVxotpn1QBl30pcLLCQjX5b2295ll0fv8RKDKsmWYrl05usHM9CewQ==", "dev": true, "license": "MIT", "peerDependencies": { @@ -4003,9 +4011,9 @@ } }, "node_modules/undici-types": { - "version": "7.10.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.10.0.tgz", - "integrity": "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==", + "version": "7.12.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.12.0.tgz", + "integrity": "sha512-goOacqME2GYyOZZfb5Lgtu+1IDmAlAEu5xnD3+xTzS10hT0vzpf0SPjkXwAw9Jm+4n/mQGDP3LO8CPbYROeBfQ==", "license": "MIT" }, "node_modules/universal-user-agent": { @@ -4194,7 +4202,7 @@ }, "devDependencies": { "@nodejs/codemod-utils": "*", - "@types/node": "^24.2.1" + "@types/node": "^24.5.0" }, "engines": { "node": ">=22.15.0" @@ -4208,7 +4216,7 @@ "@nodejs/codemod-utils": "*" }, "devDependencies": { - "@codemod.com/jssg-types": "^1.0.3" + "@codemod.com/jssg-types": "^1.0.8" } }, "recipes/fs-access-mode-constants": { @@ -4219,7 +4227,18 @@ "@nodejs/codemod-utils": "*" }, "devDependencies": { - "@codemod.com/jssg-types": "^1.0.3" + "@codemod.com/jssg-types": "^1.0.8" + } + }, + "recipes/http-classes-with-new": { + "name": "@nodejs/http-classes-with-new", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "@nodejs/codemod-utils": "*" + }, + "devDependencies": { + "@codemod.com/jssg-types": "^1.0.8" } }, "recipes/import-assertions-to-attributes": { @@ -4227,7 +4246,7 @@ "version": "1.0.0", "license": "MIT", "devDependencies": { - "@codemod.com/jssg-types": "^1.0.3" + "@codemod.com/jssg-types": "^1.0.8" } }, "recipes/process-main-module": { @@ -4238,7 +4257,7 @@ "@nodejs/codemod-utils": "*" }, "devDependencies": { - "@codemod.com/jssg-types": "^1.0.3" + "@codemod.com/jssg-types": "^1.0.8" } }, "recipes/rmdir": { @@ -4249,7 +4268,7 @@ "@nodejs/codemod-utils": "*" }, "devDependencies": { - "@codemod.com/jssg-types": "^1.0.3" + "@codemod.com/jssg-types": "^1.0.8" } }, "recipes/tmpdir-to-tmpdir": { @@ -4260,7 +4279,17 @@ "@nodejs/codemod-utils": "*" }, "devDependencies": { - "@codemod.com/jssg-types": "^1.0.3" + "@codemod.com/jssg-types": "^1.0.8" + } + }, + "recipes/types-is-native-error": { + "name": "@nodejs/types-is-native-error", + "version": "1.0.0", + "dependencies": { + "@nodejs/codemod-utils": "*" + }, + "devDependencies": { + "@codemod.com/jssg-types": "^1.0.8" } }, "recipes/util-log-to-console-log": { @@ -4271,7 +4300,7 @@ "@nodejs/codemod-utils": "*" }, "devDependencies": { - "@codemod.com/jssg-types": "^1.0.3" + "@codemod.com/jssg-types": "^1.0.8" } }, "recipes/util-print-to-console-log": { @@ -4282,7 +4311,7 @@ "@nodejs/codemod-utils": "*" }, "devDependencies": { - "@codemod.com/jssg-types": "^1.0.3" + "@codemod.com/jssg-types": "^1.0.8" } }, "utils": { @@ -4290,9 +4319,9 @@ "version": "0.0.0", "license": "MIT", "devDependencies": { - "@ast-grep/napi": "^0.39.3", - "@codemod.com/jssg-types": "^1.0.3", - "dedent": "^1.6.0" + "@ast-grep/napi": "^0.39.5", + "@codemod.com/jssg-types": "^1.0.8", + "dedent": "^1.7.0" } } } From 88624dd87441b95a29570a9270bf402fbbcc11d6 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Wed, 17 Sep 2025 09:34:38 +0200 Subject: [PATCH 6/8] fix: types --- CONTRIBUTING.md | 11 +- package-lock.json | 102 +++++++----------- package.json | 4 +- recipes/http-classes-with-new/src/workflow.ts | 5 +- recipes/types-is-native-error/src/workflow.ts | 5 +- 5 files changed, 55 insertions(+), 72 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea1cfc39..19ce6450 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,6 +40,8 @@ Each codemod resides in its own directory under `recipes/` and should include: **`src/workflow.ts` example:** ```ts import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; +import type JS from "@codemod.com/jssg-types/langs/javascript"; + /** * Transform function that converts deprecated api.fn calls * to the new api.fn syntax. @@ -49,12 +51,15 @@ import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; * 2. api.fn(, { recursive: true }) * ... */ -export default function transform(root: SgRoot): string | null { +export default function transform(root: SgRoot): string | null { const rootNode = root.root(); - let hasChanges = false; const edits: Edit[] = []; + // do some transformation - if (!hasChanges) return null; + edits.push(...); + + if (edits.length === 0) return null; + return rootNode.commitEdits(edits); } ``` diff --git a/package-lock.json b/package-lock.json index 3ea71fb9..df0d2833 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "devDependencies": { "@biomejs/biome": "2.1.4", "@types/node": "^24.2.1", - "@typescript/native-preview": "^7.0.0-dev.20250825.1" + "@typescript/native-preview": "^7.0.0-dev.20250916.1" } }, "node_modules/@ampproject/remapping": { @@ -1682,31 +1682,28 @@ } }, "node_modules/@typescript/native-preview": { - "version": "7.0.0-dev.20250825.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview/-/native-preview-7.0.0-dev.20250825.1.tgz", - "integrity": "sha512-DQB0+7nluvRjON/qc/4k6eYxbHII5sMCvMzUX1OOyT6h8nBXATfogBtqQ/NJ3193p+U/9cEgN0uIR+WBcBOuDw==", + "version": "7.0.0-dev.20250916.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview/-/native-preview-7.0.0-dev.20250916.1.tgz", + "integrity": "sha512-i9FKJWV1SMpc9YtTYimB23ERduB/udyijD2XAeOjOCV+5gzBWPc2A6lQrfhRDGHDV2NEMKRr4bTSuQ8Ptnh2EQ==", "dev": true, "license": "Apache-2.0", "bin": { "tsgo": "bin/tsgo.js" }, - "engines": { - "node": ">=20.6.0" - }, "optionalDependencies": { - "@typescript/native-preview-darwin-arm64": "7.0.0-dev.20250825.1", - "@typescript/native-preview-darwin-x64": "7.0.0-dev.20250825.1", - "@typescript/native-preview-linux-arm": "7.0.0-dev.20250825.1", - "@typescript/native-preview-linux-arm64": "7.0.0-dev.20250825.1", - "@typescript/native-preview-linux-x64": "7.0.0-dev.20250825.1", - "@typescript/native-preview-win32-arm64": "7.0.0-dev.20250825.1", - "@typescript/native-preview-win32-x64": "7.0.0-dev.20250825.1" + "@typescript/native-preview-darwin-arm64": "7.0.0-dev.20250916.1", + "@typescript/native-preview-darwin-x64": "7.0.0-dev.20250916.1", + "@typescript/native-preview-linux-arm": "7.0.0-dev.20250916.1", + "@typescript/native-preview-linux-arm64": "7.0.0-dev.20250916.1", + "@typescript/native-preview-linux-x64": "7.0.0-dev.20250916.1", + "@typescript/native-preview-win32-arm64": "7.0.0-dev.20250916.1", + "@typescript/native-preview-win32-x64": "7.0.0-dev.20250916.1" } }, "node_modules/@typescript/native-preview-darwin-arm64": { - "version": "7.0.0-dev.20250825.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-arm64/-/native-preview-darwin-arm64-7.0.0-dev.20250825.1.tgz", - "integrity": "sha512-RT1IMIimoSK4xlcRVDtEwN3m1T5a9FDgdRZSDYlZsQr9e09GkaIAJgPv5yLkpFbAAq57BiBonNM8+hFJcYyH0A==", + "version": "7.0.0-dev.20250916.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-arm64/-/native-preview-darwin-arm64-7.0.0-dev.20250916.1.tgz", + "integrity": "sha512-h0OMrJItE0KH0jXsrFcLSFpbLGUxkQ09oXrcvX9h93G2T1zxKVCl1i56ukDq4NT68qOBHwMIVqflttbTWRxN2g==", "cpu": [ "arm64" ], @@ -1715,15 +1712,12 @@ "optional": true, "os": [ "darwin" - ], - "engines": { - "node": ">=20.6.0" - } + ] }, "node_modules/@typescript/native-preview-darwin-x64": { - "version": "7.0.0-dev.20250825.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-x64/-/native-preview-darwin-x64-7.0.0-dev.20250825.1.tgz", - "integrity": "sha512-k8/wn0POmMoXczdgywN9gTGiTql3ICJBoKIvdiE3yjJHSipjQcX9WbQ0HSCfX2cliVNFRANfoKArsJUIk9fN3w==", + "version": "7.0.0-dev.20250916.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-x64/-/native-preview-darwin-x64-7.0.0-dev.20250916.1.tgz", + "integrity": "sha512-6Bxu3jvisyW/TiWKk2p3lbqVI/WzMcK5wIjzzfInketZRtS9ENQpkZ9Yw5Yx4JuOw7m/j69YCM9YPEQzqVh5Yw==", "cpu": [ "x64" ], @@ -1732,15 +1726,12 @@ "optional": true, "os": [ "darwin" - ], - "engines": { - "node": ">=20.6.0" - } + ] }, "node_modules/@typescript/native-preview-linux-arm": { - "version": "7.0.0-dev.20250825.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm/-/native-preview-linux-arm-7.0.0-dev.20250825.1.tgz", - "integrity": "sha512-7EqleheGT7N4V5eGNT2n9ZDMoesi190pnYjbolwbIPSZqklZ/4AXApZhYz8vqqALt+TzGBUQ8MWjX/alzDpl5A==", + "version": "7.0.0-dev.20250916.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm/-/native-preview-linux-arm-7.0.0-dev.20250916.1.tgz", + "integrity": "sha512-f2kxgRQe2FIAUQVmJT7/r4RJfxyj3mjfV747OkWqH/sIJNOj4JnVl4RIsY+JL8r99zlJidm/FuiBUeDcyp7qyA==", "cpu": [ "arm" ], @@ -1749,15 +1740,12 @@ "optional": true, "os": [ "linux" - ], - "engines": { - "node": ">=20.6.0" - } + ] }, "node_modules/@typescript/native-preview-linux-arm64": { - "version": "7.0.0-dev.20250825.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm64/-/native-preview-linux-arm64-7.0.0-dev.20250825.1.tgz", - "integrity": "sha512-VfiMRCipZY5i+PwgNDFHH8/Sm5w5/9U7Uf/Jb69ZgSdgZGpYev++6CAnWhl7wzJBAI72kNK1hD2s870j0RiNyw==", + "version": "7.0.0-dev.20250916.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm64/-/native-preview-linux-arm64-7.0.0-dev.20250916.1.tgz", + "integrity": "sha512-tEON0Hn5CTyB3GbMLxzlzl3gyIHO4Qj4gyfj327q27lCyZxQrANZRJidhUP57RBxejAQdTj/bLQMm30/py7SDw==", "cpu": [ "arm64" ], @@ -1766,15 +1754,12 @@ "optional": true, "os": [ "linux" - ], - "engines": { - "node": ">=20.6.0" - } + ] }, "node_modules/@typescript/native-preview-linux-x64": { - "version": "7.0.0-dev.20250825.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-x64/-/native-preview-linux-x64-7.0.0-dev.20250825.1.tgz", - "integrity": "sha512-da+bqP2uOD3BrQZgt5fdgvinkekNMh+9enOmjQkv0tdb53PZ5Sf3xEl+yC43TrLfJAFpYHDBU5WTVnSorryZ2Q==", + "version": "7.0.0-dev.20250916.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-x64/-/native-preview-linux-x64-7.0.0-dev.20250916.1.tgz", + "integrity": "sha512-xIN1NNZhnp8CywGbjv2sMy/Y9yqiUrLPhaa1oK3aL8GFFDc56i2a9kHspy6sL60VZmqUizDMS4qsofavL63nbw==", "cpu": [ "x64" ], @@ -1783,15 +1768,12 @@ "optional": true, "os": [ "linux" - ], - "engines": { - "node": ">=20.6.0" - } + ] }, "node_modules/@typescript/native-preview-win32-arm64": { - "version": "7.0.0-dev.20250825.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-arm64/-/native-preview-win32-arm64-7.0.0-dev.20250825.1.tgz", - "integrity": "sha512-jivNNnPdc/9OFbMXvCwpwVhwU5gDGb95ER9G5tDhs3zUwynw/Z4pp5DJXDYBqj0oaZBeYDWOyxBKh+TiKYk9qQ==", + "version": "7.0.0-dev.20250916.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-arm64/-/native-preview-win32-arm64-7.0.0-dev.20250916.1.tgz", + "integrity": "sha512-lt4OgcGId11iDXghb3+sAP0U6BWtaJeKyAIs7d0BMBzF/wdR5isjnSDD1zLR/tqLom7WoupIkKMAoaVNO5GTmw==", "cpu": [ "arm64" ], @@ -1800,15 +1782,12 @@ "optional": true, "os": [ "win32" - ], - "engines": { - "node": ">=20.6.0" - } + ] }, "node_modules/@typescript/native-preview-win32-x64": { - "version": "7.0.0-dev.20250825.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-x64/-/native-preview-win32-x64-7.0.0-dev.20250825.1.tgz", - "integrity": "sha512-G6bnjriPrsTQ3ZkUg4wzxv8rP7BJ/lrecTMS97BJuHorJCOqF3uoAGFHZRTnlnanxNr2Akm+hD0d77neOZpgFA==", + "version": "7.0.0-dev.20250916.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-x64/-/native-preview-win32-x64-7.0.0-dev.20250916.1.tgz", + "integrity": "sha512-xL2kkfgxljnNIQHuL5ENNF2K8weUJi5gY/BEdCwe5kpfeVljc+rq4V39X1LjEnj4NAU39h6O9zFImRdcghFnkQ==", "cpu": [ "x64" ], @@ -1817,10 +1796,7 @@ "optional": true, "os": [ "win32" - ], - "engines": { - "node": ">=20.6.0" - } + ] }, "node_modules/abort-controller": { "version": "3.0.0", diff --git a/package.json b/package.json index 20bbfef9..6fe00eb3 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "pre-commit": "node --run lint:fix; node --run type-check; node --run test", "test": "npm run test --workspaces --if-present", "test-legacy": "npm run test-legacy --workspaces --if-present", - "type-check": "tsgo" + "type-check": "tsgo --noEmit" }, "repository": { "type": "git", @@ -29,7 +29,7 @@ "devDependencies": { "@biomejs/biome": "2.1.4", "@types/node": "^24.2.1", - "@typescript/native-preview": "^7.0.0-dev.20250825.1" + "@typescript/native-preview": "^7.0.0-dev.20250916.1" }, "workspaces": [ "./recipes/*", diff --git a/recipes/http-classes-with-new/src/workflow.ts b/recipes/http-classes-with-new/src/workflow.ts index 67af8c76..5976267e 100644 --- a/recipes/http-classes-with-new/src/workflow.ts +++ b/recipes/http-classes-with-new/src/workflow.ts @@ -2,6 +2,7 @@ import { getNodeImportStatements } from '@nodejs/codemod-utils/ast-grep/import-s import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call'; import { resolveBindingPath } from '@nodejs/codemod-utils/ast-grep/resolve-binding-path'; import type { SgRoot, Edit, SgNode } from '@codemod.com/jssg-types/main'; +import type JS from "@codemod.com/jssg-types/langs/javascript"; /** * Classes of the http module @@ -26,7 +27,7 @@ const CLASS_NAMES = [ * 5. `http.Server()` → `new http.Server()` * 6. `http.ServerResponse() → `new http.ServerResponse()` */ -export default function transform(root: SgRoot): string | null { +export default function transform(root: SgRoot): string | null { const rootNode = root.root(); const edits: Edit[] = []; @@ -59,7 +60,7 @@ export default function transform(root: SgRoot): string | null { * @param statements - The import & require statements to search for the http classes * @returns The base path of the http classes */ -function* getHttpClassBasePaths(statements: SgNode[]) { +function* getHttpClassBasePaths(statements: SgNode[]) { for (const cls of CLASS_NAMES) { for (const stmt of statements) { const resolvedPath = resolveBindingPath(stmt, `$.${cls}`); diff --git a/recipes/types-is-native-error/src/workflow.ts b/recipes/types-is-native-error/src/workflow.ts index e3437a8e..a6f1bd16 100644 --- a/recipes/types-is-native-error/src/workflow.ts +++ b/recipes/types-is-native-error/src/workflow.ts @@ -4,13 +4,14 @@ import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-s import { resolveBindingPath } from "@nodejs/codemod-utils/ast-grep/resolve-binding-path"; import { removeLines } from "@nodejs/codemod-utils/ast-grep/remove-lines"; import { removeBinding } from "@nodejs/codemod-utils/ast-grep/remove-binding"; +import type JS from "@codemod.com/jssg-types/langs/javascript"; type Binding = { path: string; lastPropertyAccess?: string; propertyAccess?: string; depth: number; - node: SgNode; + node: SgNode; }; /** @@ -72,7 +73,7 @@ function createPropBinding( * isNativeError have been replaced * */ -export default function transform(root: SgRoot): string | null { +export default function transform(root: SgRoot): string | null { const rootNode = root.root(); const bindings: Binding[] = []; const edits: Edit[] = []; From ff5bb6e5ab5f84c192dee14b03caa74b8239bbd1 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Wed, 17 Sep 2025 09:36:50 +0200 Subject: [PATCH 7/8] fixup!: undo erroneous change to test file --- recipes/correct-ts-specifiers/src/fixtures/e2e/test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/recipes/correct-ts-specifiers/src/fixtures/e2e/test.ts b/recipes/correct-ts-specifiers/src/fixtures/e2e/test.ts index 8ce2f40b..34df1387 100644 --- a/recipes/correct-ts-specifiers/src/fixtures/e2e/test.ts +++ b/recipes/correct-ts-specifiers/src/fixtures/e2e/test.ts @@ -3,17 +3,17 @@ import { URL } from 'node:url'; import { bar } from '@dep/bar'; import { foo } from 'foo'; -import { Bird } from './Bird/index.ts'; +import { Bird } from './Bird'; import { Cat } from './Cat.ts'; -import { Dog } from '…/Dog/index.mts'; +import { Dog } from '…/Dog/index.mjs'; import { baseUrl } from '#config.js'; -import { qux } from './qux.js/index.ts'; +import { qux } from './qux.js'; -export type { Zed } from './zed.d.ts'; +export { Zed } from './zed'; // should.js be unchanged -const nil = await import('./nil.ts'); +const nil = await import('./nil.js'); const bird = new Bird('Tweety'); const cat = new Cat('Milo'); From 9ba690f3164dce26b19b8eab0bbbeac7ede466d7 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Wed, 17 Sep 2025 13:09:57 +0200 Subject: [PATCH 8/8] revert change/conflict --- .../fs-access-mode-constants/src/workflow.ts | 134 ++++++++++-------- .../src/workflow.ts | 25 ++-- 2 files changed, 83 insertions(+), 76 deletions(-) diff --git a/recipes/fs-access-mode-constants/src/workflow.ts b/recipes/fs-access-mode-constants/src/workflow.ts index 9fd22096..8e320ca7 100644 --- a/recipes/fs-access-mode-constants/src/workflow.ts +++ b/recipes/fs-access-mode-constants/src/workflow.ts @@ -1,74 +1,82 @@ -import { getNodeRequireCalls } from "@nodejs/codemod-utils/ast-grep/require-call" -import { getNodeImportStatements } from "@nodejs/codemod-utils/ast-grep/import-statement"; -import type { Edit, SgRoot } from "@codemod.com/jssg-types/main"; -import type Js from "@codemod.com/jssg-types/langs/javascript"; +import type { Edit, SgRoot } from '@codemod.com/jssg-types/main'; +import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call'; +import type Js from '@codemod.com/jssg-types/langs/javascript'; +import { getNodeImportStatements } from '@nodejs/codemod-utils/ast-grep/import-statement'; export default function tranform(root: SgRoot): string | null { - const rootNode = root.root(); - const edits: Edit[] = []; + const rootNode = root.root(); + const edits: Edit[] = []; + const patterns = ['F_OK', 'R_OK', 'W_OK', 'X_OK']; - const requireStatements = getNodeRequireCalls(root, "fs"); + const requireStatements = getNodeRequireCalls(root, 'fs'); - for (const statement of requireStatements) { - const objectPattern = statement.find({ - rule: - { kind: 'object_pattern' }, - }); + for (const statement of requireStatements) { + const objectPattern = statement.find({ + rule: { kind: 'object_pattern' }, + }); - if (objectPattern) { - let objPatArr = objectPattern.findAll({ - rule: - { kind: 'shorthand_property_identifier_pattern' }, - }).map((v) => v.text()); - objPatArr = objPatArr.filter((v) => !['F_OK', 'R_OK', 'W_OK', 'X_OK'].includes(v)); - objPatArr.push('constants'); - edits.push(objectPattern.replace(`{ ${objPatArr.join(', ')} }`)); - }; - } + if (objectPattern) { + let objPatArr = objectPattern + .findAll({ + rule: { kind: 'shorthand_property_identifier_pattern' }, + }) + .map((v) => v.text()); + objPatArr = objPatArr.filter( + (v) => !patterns.includes(v), + ); + objPatArr.push('constants'); + edits.push(objectPattern.replace(`{ ${objPatArr.join(', ')} }`)); + } + } - const importStatements = getNodeImportStatements(root, "fs"); - let promisesImportName = ''; + const importStatements = getNodeImportStatements(root, 'fs'); + let promisesImportName = ''; - for (const statement of importStatements) { - const objectPattern = statement.find({ - rule: - { kind: 'named_imports' }, - }); + for (const statement of importStatements) { + const objectPattern = statement.find({ + rule: { kind: 'named_imports' }, + }); - if (objectPattern) { - let objPatArr = objectPattern.findAll({ - rule: - { kind: 'import_specifier' }, - }).map((v) => v.text()); - objPatArr = objPatArr.filter((v) => !['F_OK', 'R_OK', 'W_OK', 'X_OK'].includes(v)); - const promisesImport = objPatArr.find((v) => v.startsWith('promises')); - if (promisesImport) { - if (promisesImport.includes('as')) { - const m = promisesImport.matchAll((/promises as (\w+)/g)); - m.forEach((v) => promisesImportName = v[1] ?? 'promises'); - } else { - promisesImportName = promisesImport; - } - promisesImportName = `${promisesImportName}.` - } else { - objPatArr.push('constants'); - } - edits.push(objectPattern.replace(`{ ${objPatArr.join(', ')} }`)); - } - } + if (objectPattern) { + let objPatArr = objectPattern + .findAll({ + rule: { kind: 'import_specifier' }, + }) + .map((v) => v.text()); + objPatArr = objPatArr.filter( + (v) => !patterns.includes(v), + ); + const promisesImport = objPatArr.find((v) => v.startsWith('promises')); + if (promisesImport) { + if (promisesImport.includes('as')) { + const m = promisesImport.matchAll(/promises as (\w+)/g); + m.forEach((v) => { + promisesImportName = v[1] ?? 'promises'; + }); + } else { + promisesImportName = promisesImport; + } + promisesImportName = `${promisesImportName}.`; + } else { + objPatArr.push('constants'); + } + edits.push(objectPattern.replace(`{ ${objPatArr.join(', ')} }`)); + } + } - for (const _OK of ['F_OK', 'R_OK', 'W_OK', 'X_OK']) { - for (const [prefix, replacement] of [['fs.', 'fs.constants.'], ['', `${promisesImportName ? promisesImportName : ''}constants.`]]) { - const patterns = rootNode.findAll({ - rule: { - pattern: `${prefix}${_OK}` - } - }); - for (const pattern of patterns) { - edits.push(pattern.replace(`${replacement}${_OK}`)); - } - } - } + for (const _OK of patterns) { + for (const [prefix, replacement] of [ + ['fs.', 'fs.constants.'], + ['', `${promisesImportName ? promisesImportName : ''}constants.`], + ]) { + const patterns = rootNode.findAll({ + rule: { pattern: `${prefix}${_OK}` }, + }); + for (const pattern of patterns) { + edits.push(pattern.replace(`${replacement}${_OK}`)); + } + } + } - return rootNode.commitEdits(edits); + return rootNode.commitEdits(edits); } diff --git a/recipes/import-assertions-to-attributes/src/workflow.ts b/recipes/import-assertions-to-attributes/src/workflow.ts index e15aed28..03a2514e 100644 --- a/recipes/import-assertions-to-attributes/src/workflow.ts +++ b/recipes/import-assertions-to-attributes/src/workflow.ts @@ -1,5 +1,5 @@ -import type { SgRoot, Edit } from "@codemod.com/jssg-types/main"; -import type Js from "@codemod.com/jssg-types/langs/javascript"; +import type { SgRoot, Edit } from '@codemod.com/jssg-types/main'; +import type JS from "@codemod.com/jssg-types/langs/javascript"; /** * Transform function that converts import assertions to import attributes @@ -12,7 +12,7 @@ import type Js from "@codemod.com/jssg-types/langs/javascript"; * 1. import { something } from './module.json' with { type: 'json' }; * 2. import('./module.json', { with: { type: 'json' } }) */ -export default async function transform(root: SgRoot): Promise { +export default async function transform(root: SgRoot): Promise { const rootNode = root.root(); const edits: Edit[] = []; @@ -20,17 +20,17 @@ export default async function transform(root: SgRoot): Promise { rule: { kind: 'import_attribute', regex: '^assert\\s*\\{', - } + }, }); for (const importNode of importStatements) { // Replace 'assert' with 'with' in the import statement - importNode.children().map(child => { + importNode.children().forEach((child) => { if (child.kind() === 'assert' && child.text() === 'assert') { //return child.replace('with'); edits.push(child.replace('with')); } - }) + }); } // Handle dynamic import call expressions with assert attributes @@ -47,12 +47,12 @@ export default async function transform(root: SgRoot): Promise { kind: 'arguments', inside: { kind: 'call_expression', - pattern: "import($_SPECIFIER, $_ARGS)" - } - } - } - } - } + pattern: 'import($_SPECIFIER, $_ARGS)', + }, + }, + }, + }, + }, }); for (const assertNode of assertIdentifiers) { @@ -61,4 +61,3 @@ export default async function transform(root: SgRoot): Promise { return rootNode.commitEdits(edits); } -