@kamaalio/codemod-kit 0.0.36 → 0.0.38
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.
- package/dist/index.cjs +13 -10
- package/dist/index.js +14 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -516,6 +516,7 @@ async function codemodPostTransform(transformedContent) {
|
|
|
516
516
|
async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
517
517
|
const codemodRepositoriesMappedByCodemodName = await prepareRepositoriesForCodemods(repositories, codemods, workingDirectory);
|
|
518
518
|
const results = Object.fromEntries(await Promise.all(codemods.map(async (codemod)=>{
|
|
519
|
+
const start = performance.now();
|
|
519
520
|
const codemodRepositories = codemodRepositoriesMappedByCodemodName[codemod.name];
|
|
520
521
|
kamaal_namespaceObject.asserts.invariant(null != codemodRepositories, 'Codemod repositories should be present');
|
|
521
522
|
const codemodWorkingDirectory = external_node_path_default().resolve(workingDirectory, codemod.name.replace(/\//g, '-'));
|
|
@@ -530,6 +531,8 @@ async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
|
530
531
|
postTransform: codemodPostTransform
|
|
531
532
|
}
|
|
532
533
|
});
|
|
534
|
+
const end = performance.now();
|
|
535
|
+
console.log(`\u{2728} '${codemod.name}' codemod took ${((end - start) / 1000).toFixed(2)} seconds`);
|
|
533
536
|
return [
|
|
534
537
|
codemod.name,
|
|
535
538
|
result
|
|
@@ -538,21 +541,21 @@ async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
|
538
541
|
return results;
|
|
539
542
|
}
|
|
540
543
|
async function prepareRepositoriesForCodemods(repositories, codemods, workingDirectory) {
|
|
541
|
-
const
|
|
544
|
+
const reposMappedByMainBranch = await Promise.all(repositories.map(async (repo)=>{
|
|
542
545
|
const mainBranchResult = await repo.getMainBranch();
|
|
543
546
|
if (mainBranchResult.isErr()) throw mainBranchResult.error;
|
|
544
|
-
return
|
|
545
|
-
mainBranchResult.value.name,
|
|
546
|
-
repo
|
|
547
|
-
|
|
548
|
-
}))
|
|
549
|
-
const updatedRepositories = await Promise.all(
|
|
550
|
-
const prepareResult = await
|
|
547
|
+
return {
|
|
548
|
+
mainBranchName: mainBranchResult.value.name,
|
|
549
|
+
repository: repo
|
|
550
|
+
};
|
|
551
|
+
}));
|
|
552
|
+
const updatedRepositories = await Promise.all(reposMappedByMainBranch.map(async ({ mainBranchName, repository })=>{
|
|
553
|
+
const prepareResult = await repository.prepareForUpdate(mainBranchName);
|
|
551
554
|
if (prepareResult.isErr()) throw prepareResult.error;
|
|
552
555
|
return prepareResult.value;
|
|
553
556
|
}));
|
|
554
|
-
console.log(`\u{1F4CB} prepared the following repos for codemods
|
|
555
|
-
${updatedRepositories.map((repo)=>repo.address).join(
|
|
557
|
+
console.log(`\u{1F4CB} prepared the following repos for codemods:
|
|
558
|
+
\xb7 ${updatedRepositories.map((repo)=>repo.address).join("\n\xb7 ")}`);
|
|
556
559
|
return Object.fromEntries(await Promise.all(codemods.map(async (codemod)=>{
|
|
557
560
|
const codemodWorkingDirectory = external_node_path_default().resolve(workingDirectory, codemod.name.replace(/\//g, '-'));
|
|
558
561
|
await (0, external_execa_namespaceObject.$)`mkdir -p ${codemodWorkingDirectory}`;
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { $ } from "execa";
|
|
|
4
4
|
import fast_glob from "fast-glob";
|
|
5
5
|
import { ResultAsync, err, ok } from "neverthrow";
|
|
6
6
|
import { Lang, parseAsync } from "@ast-grep/napi";
|
|
7
|
-
import { arrays, asserts
|
|
7
|
+
import { arrays, asserts } from "@kamaalio/kamaal";
|
|
8
8
|
import zod from "zod";
|
|
9
9
|
const JAVASCRIPT_EXTENSIONS = [
|
|
10
10
|
'.js',
|
|
@@ -467,6 +467,7 @@ async function codemodPostTransform(transformedContent) {
|
|
|
467
467
|
async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
468
468
|
const codemodRepositoriesMappedByCodemodName = await prepareRepositoriesForCodemods(repositories, codemods, workingDirectory);
|
|
469
469
|
const results = Object.fromEntries(await Promise.all(codemods.map(async (codemod)=>{
|
|
470
|
+
const start = performance.now();
|
|
470
471
|
const codemodRepositories = codemodRepositoriesMappedByCodemodName[codemod.name];
|
|
471
472
|
asserts.invariant(null != codemodRepositories, 'Codemod repositories should be present');
|
|
472
473
|
const codemodWorkingDirectory = node_path.resolve(workingDirectory, codemod.name.replace(/\//g, '-'));
|
|
@@ -481,6 +482,8 @@ async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
|
481
482
|
postTransform: codemodPostTransform
|
|
482
483
|
}
|
|
483
484
|
});
|
|
485
|
+
const end = performance.now();
|
|
486
|
+
console.log(`\u{2728} '${codemod.name}' codemod took ${((end - start) / 1000).toFixed(2)} seconds`);
|
|
484
487
|
return [
|
|
485
488
|
codemod.name,
|
|
486
489
|
result
|
|
@@ -489,21 +492,21 @@ async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
|
489
492
|
return results;
|
|
490
493
|
}
|
|
491
494
|
async function prepareRepositoriesForCodemods(repositories, codemods, workingDirectory) {
|
|
492
|
-
const
|
|
495
|
+
const reposMappedByMainBranch = await Promise.all(repositories.map(async (repo)=>{
|
|
493
496
|
const mainBranchResult = await repo.getMainBranch();
|
|
494
497
|
if (mainBranchResult.isErr()) throw mainBranchResult.error;
|
|
495
|
-
return
|
|
496
|
-
mainBranchResult.value.name,
|
|
497
|
-
repo
|
|
498
|
-
|
|
499
|
-
}))
|
|
500
|
-
const updatedRepositories = await Promise.all(
|
|
501
|
-
const prepareResult = await
|
|
498
|
+
return {
|
|
499
|
+
mainBranchName: mainBranchResult.value.name,
|
|
500
|
+
repository: repo
|
|
501
|
+
};
|
|
502
|
+
}));
|
|
503
|
+
const updatedRepositories = await Promise.all(reposMappedByMainBranch.map(async ({ mainBranchName, repository })=>{
|
|
504
|
+
const prepareResult = await repository.prepareForUpdate(mainBranchName);
|
|
502
505
|
if (prepareResult.isErr()) throw prepareResult.error;
|
|
503
506
|
return prepareResult.value;
|
|
504
507
|
}));
|
|
505
|
-
console.log(`\u{1F4CB} prepared the following repos for codemods
|
|
506
|
-
${updatedRepositories.map((repo)=>repo.address).join(
|
|
508
|
+
console.log(`\u{1F4CB} prepared the following repos for codemods:
|
|
509
|
+
\xb7 ${updatedRepositories.map((repo)=>repo.address).join("\n\xb7 ")}`);
|
|
507
510
|
return Object.fromEntries(await Promise.all(codemods.map(async (codemod)=>{
|
|
508
511
|
const codemodWorkingDirectory = node_path.resolve(workingDirectory, codemod.name.replace(/\//g, '-'));
|
|
509
512
|
await $`mkdir -p ${codemodWorkingDirectory}`;
|