Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion recipes/chalk-to-util-styletext/codemod.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
schema_version: "1.0"
name: "@nodejs/chalk-to-util-styletext"
version: 1.0.0
version: 1.0.1
capabilities:
- fs
- child_process
Expand Down
2 changes: 1 addition & 1 deletion recipes/chalk-to-util-styletext/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nodejs/chalk-to-util-styletext",
"version": "1.0.0",
"version": "1.0.1",
"description": "Migrate from the chalk package to Node.js's built-in util.styleText API",
"type": "module",
"scripts": {
Expand Down
12 changes: 2 additions & 10 deletions recipes/chalk-to-util-styletext/src/workflow.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call';
import {
getNodeImportCalls,
getNodeImportStatements,
} from '@nodejs/codemod-utils/ast-grep/import-statement';
import { resolveBindingPath } from '@nodejs/codemod-utils/ast-grep/resolve-binding-path';
import type { Edit, SgNode, SgRoot } from '@codemod.com/jssg-types/main';
import type Js from '@codemod.com/jssg-types/langs/javascript';
import { getModuleDependencies } from '@nodejs/codemod-utils/ast-grep/module-dependencies';

const chalkBinding = 'chalk';
const chalkStdErrBinding = 'chalkStderr';
Expand All @@ -22,11 +18,7 @@ export default function transform(root: SgRoot<Js>): string | null {
const edits: Edit[] = [];

// This actually catches `node:chalk` import but we don't care as it shouldn't append
const statements = [
...getNodeImportStatements(root, chalkBinding),
...getNodeRequireCalls(root, chalkBinding),
...getNodeImportCalls(root, chalkBinding),
];
const statements = getModuleDependencies(root, chalkBinding);

// If there aren't any imports then we don't process the file
if (!statements.length) return null;
Expand Down
2 changes: 1 addition & 1 deletion recipes/crypto-fips-to-getFips/codemod.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
schema_version: "1.0"
name: "@nodejs/crypto-fips-to-getFips"
version: "1.0.1"
version: "1.0.2"
description: Handle DEP0093 via transforming `crypto.fips` to `crypto.getFips()` and `crypto.setFips()`
author: Usman S.
license: MIT
Expand Down
2 changes: 1 addition & 1 deletion recipes/crypto-fips-to-getFips/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nodejs/crypto-fips-to-getFips",
"version": "1.0.1",
"version": "1.0.2",
"description": "Handle DEP0093 via transforming `crypto.fips` to `crypto.getFips()` and `crypto.setFips()`",
"type": "module",
"scripts": {
Expand Down
12 changes: 2 additions & 10 deletions recipes/crypto-fips-to-getFips/src/workflow.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {
getNodeImportCalls,
getNodeImportStatements,
} from '@nodejs/codemod-utils/ast-grep/import-statement';
import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call';
import { resolveBindingPath } from '@nodejs/codemod-utils/ast-grep/resolve-binding-path';
import { updateBinding } from '@nodejs/codemod-utils/ast-grep/update-binding';
import { removeLines } from '@nodejs/codemod-utils/ast-grep/remove-lines';
import type { SgRoot, SgNode, Edit, Range } from '@codemod.com/jssg-types/main';
import type Js from '@codemod.com/jssg-types/langs/javascript';
import { getModuleDependencies } from '@nodejs/codemod-utils/ast-grep/module-dependencies';

type Binding = {
type: 'namespace' | 'destructured';
Expand Down Expand Up @@ -68,11 +64,7 @@ export default function transform(root: SgRoot<Js>): string | null {
*/
function collectCryptoFipsBindings(root: SgRoot<Js>): Binding[] {
const bindings: Binding[] = [];
const allStatements = [
...getNodeImportStatements(root, 'crypto'),
...getNodeImportCalls(root, 'crypto'),
...getNodeRequireCalls(root, 'crypto'),
];
const allStatements = getModuleDependencies(root, 'crypto');

// If no statements found, skip transformation
if (!allStatements.length) return bindings;
Expand Down
2 changes: 1 addition & 1 deletion recipes/crypto-rsa-pss-update/codemod.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
schema_version: "1.0"
name: "@nodejs/crypto-rsa-pss-update"
version: 1.0.1
version: 1.0.2
description: >-
Handle DEP0154 via transforming deprecated RSA-PSS crypto options `hash` to
`hashAlgorithm` and `mgf1Hash` to `mgf1HashAlgorithm`
Expand Down
2 changes: 1 addition & 1 deletion recipes/crypto-rsa-pss-update/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nodejs/crypto-rsa-pss-update",
"version": "1.0.1",
"version": "1.0.2",
"description": "Handle DEP0154 via transforming deprecated RSA-PSS crypto options `hash` to `hashAlgorithm` and `mgf1Hash` to `mgf1HashAlgorithm`.",
"type": "module",
"scripts": {
Expand Down
17 changes: 3 additions & 14 deletions recipes/crypto-rsa-pss-update/src/workflow.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { SgRoot, SgNode, Edit } from '@codemod.com/jssg-types/main';
import type JS from '@codemod.com/jssg-types/langs/javascript';
import { getNodeImportStatements } from '@nodejs/codemod-utils/ast-grep/import-statement';
import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call';
import { resolveBindingPath } from '@nodejs/codemod-utils/ast-grep/resolve-binding-path';
import { getModuleDependencies } from '@nodejs/codemod-utils/ast-grep/module-dependencies';

const RSA_PSS_REGEX = /^['"]rsa-pss['"]$/;
const IDENTIFIER_REGEX = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
Expand Down Expand Up @@ -61,7 +60,7 @@ function transformRsaPssCalls(
}

function getCryptoBindings(root: SgRoot<JS>): string[] {
const bindings = resolveBindings(getModuleStatements(root, 'crypto'), [
const bindings = resolveBindings(getModuleDependencies(root, 'crypto'), [
'$.generateKeyPair',
'$.generateKeyPairSync',
]);
Expand All @@ -72,7 +71,7 @@ function getPromisifiedBindings(
root: SgRoot<JS>,
existingBindings: string[],
): string[] {
const utilStatements = getModuleStatements(root, 'util');
const utilStatements = getModuleDependencies(root, 'util');
const promisifyBindings = resolveBindings(utilStatements, '$.promisify');

if (promisifyBindings.length === 0 && utilStatements.length > 0) {
Expand Down Expand Up @@ -109,15 +108,6 @@ function getText(node: SgNode<JS> | undefined): string | null {
return text || null;
}

function getModuleStatements(
root: SgRoot<JS>,
moduleName: string,
): SgNode<JS>[] {
const importStatements = getNodeImportStatements(root, moduleName);
const requireCalls = getNodeRequireCalls(root, moduleName);
return [...importStatements, ...requireCalls];
}

function resolveBindings(
statements: SgNode<JS>[],
paths: string | string[],
Expand Down Expand Up @@ -374,4 +364,3 @@ function findAndTransformVariableDeclarations(
.map((decl) => decl.replace(decl.text().replace(from, to))),
);
}

2 changes: 1 addition & 1 deletion recipes/dirent-path-to-parent-path/codemod.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
schema_version: "1.0"
name: "@nodejs/dirent-path-to-parent-path"
version: 1.0.0
version: 1.0.1
description: Handle DEP0178 via transforming `dirent.path` to `dirent.parentPath`.
author: Bruno Rodrigues
license: MIT
Expand Down
5 changes: 2 additions & 3 deletions recipes/dirent-path-to-parent-path/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "@nodejs/dirent-path-to-parent-path",
"version": "1.0.0",
"version": "1.0.1",
"description": "Handle DEP0178 via transforming `dirent.path` to `dirent.parentPath`",
"type": "module",
"scripts": {
"test": "npx codemod jssg test -l typescript ./src/workflow.ts ./",
"testu": "npx codemod jssg test -l typescript -u ./src/workflow.ts ./"
"test": "npx codemod jssg test -l typescript ./src/workflow.ts ./"
},
"repository": {
"type": "git",
Expand Down
16 changes: 6 additions & 10 deletions recipes/dirent-path-to-parent-path/src/workflow.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { getNodeRequireCalls } from '@nodejs/codemod-utils/ast-grep/require-call';
import {
getNodeImportCalls,
getNodeImportStatements,
} from '@nodejs/codemod-utils/ast-grep/import-statement';
import { resolveBindingPath } from '@nodejs/codemod-utils/ast-grep/resolve-binding-path';
import { removeLines } from '@nodejs/codemod-utils/ast-grep/remove-lines';
import { getScope } from '@nodejs/codemod-utils/ast-grep/get-scope';
import type { Edit, Range, SgNode, SgRoot } from '@codemod.com/jssg-types/main';
import type Js from '@codemod.com/jssg-types/langs/javascript';
import { getModuleDependencies } from '@nodejs/codemod-utils/ast-grep/module-dependencies';

type BindingToReplace = {
node: SgNode<Js>;
Expand Down Expand Up @@ -56,9 +52,7 @@ export default function transform(root: SgRoot<Js>): string | null {

const importRequireStatement: SgNode<Js>[] = [];
for (const mod of handledModules) {
importRequireStatement.push(...getNodeRequireCalls(root, mod));
importRequireStatement.push(...getNodeImportStatements(root, mod));
importRequireStatement.push(...getNodeImportCalls(root, mod));
importRequireStatement.push(...getModuleDependencies(root, mod));
}

if (!importRequireStatement.length) return null;
Expand Down Expand Up @@ -166,7 +160,8 @@ export default function transform(root: SgRoot<Js>): string | null {
}

for (const dirArray of dirArrays) {
const pattern = dirArray.node.kind() === 'variable_declarator'
const pattern =
dirArray.node.kind() === 'variable_declarator'
? (dirArray.node as SgNode<Js, 'variable_declarator'>)
.field('name')
.text()
Expand Down Expand Up @@ -256,7 +251,8 @@ export default function transform(root: SgRoot<Js>): string | null {
});

for (const arrowFn of arrowFns) {
const parameters = arrowFn.field('parameters') || arrowFn.field('parameter');
const parameters =
arrowFn.field('parameters') || arrowFn.field('parameter');
const fnBody = arrowFn.field('body');

const param = parameters?.find<'identifier'>({
Expand Down
2 changes: 1 addition & 1 deletion recipes/fs-truncate-fd-deprecation/codemod.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
schema_version: "1.0"
name: "@nodejs/fs-truncate-fd-deprecation"
version: "1.0.1"
version: "1.0.2"
description: Handle DEP0081 via transforming `truncate` to `ftruncateSync` when using a file descriptor.
author: Augustin Mauroy
license: MIT
Expand Down
2 changes: 1 addition & 1 deletion recipes/fs-truncate-fd-deprecation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nodejs/fs-truncate-fd-deprecation",
"version": "1.0.1",
"version": "1.0.2",
"description": "Handle DEP0081 via transforming `truncate` to `ftruncateSync` when using a file descriptor.",
"type": "module",
"scripts": {
Expand Down
Loading
Loading