@kamaalio/codemod-kit 0.0.35 → 0.0.37
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 +17 -10
- package/dist/index.js +18 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -518,8 +518,9 @@ async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
|
518
518
|
const results = Object.fromEntries(await Promise.all(codemods.map(async (codemod)=>{
|
|
519
519
|
const codemodRepositories = codemodRepositoriesMappedByCodemodName[codemod.name];
|
|
520
520
|
kamaal_namespaceObject.asserts.invariant(null != codemodRepositories, 'Codemod repositories should be present');
|
|
521
|
+
const codemodWorkingDirectory = external_node_path_default().resolve(workingDirectory, codemod.name.replace(/\//g, '-'));
|
|
521
522
|
const failedRepositoryAddressesMappedByCodemodNames = {};
|
|
522
|
-
const result = await runCodemod(codemod,
|
|
523
|
+
const result = await runCodemod(codemod, codemodWorkingDirectory, {
|
|
523
524
|
rootPaths: codemodRepositories.map((repository)=>repository.path),
|
|
524
525
|
hooks: {
|
|
525
526
|
preCodemodRun: async (codemod)=>{
|
|
@@ -537,23 +538,29 @@ async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
|
537
538
|
return results;
|
|
538
539
|
}
|
|
539
540
|
async function prepareRepositoriesForCodemods(repositories, codemods, workingDirectory) {
|
|
540
|
-
const
|
|
541
|
+
const reposMappedByMainBranch = await Promise.all(repositories.map(async (repo)=>{
|
|
541
542
|
const mainBranchResult = await repo.getMainBranch();
|
|
542
543
|
if (mainBranchResult.isErr()) throw mainBranchResult.error;
|
|
543
|
-
return
|
|
544
|
-
mainBranchResult.value.name,
|
|
545
|
-
repo
|
|
546
|
-
|
|
547
|
-
}))
|
|
548
|
-
const updatedRepositories = await Promise.all(
|
|
549
|
-
const prepareResult = await
|
|
544
|
+
return {
|
|
545
|
+
mainBranchName: mainBranchResult.value.name,
|
|
546
|
+
repository: repo
|
|
547
|
+
};
|
|
548
|
+
}));
|
|
549
|
+
const updatedRepositories = await Promise.all(reposMappedByMainBranch.map(async ({ mainBranchName, repository })=>{
|
|
550
|
+
const prepareResult = await repository.prepareForUpdate(mainBranchName);
|
|
550
551
|
if (prepareResult.isErr()) throw prepareResult.error;
|
|
551
552
|
return prepareResult.value;
|
|
552
553
|
}));
|
|
554
|
+
console.log(`\u{1F4CB} prepared the following repos for codemods!
|
|
555
|
+
\xb7 ${updatedRepositories.map((repo)=>repo.address).join("\n\xb7 ")}`);
|
|
553
556
|
return Object.fromEntries(await Promise.all(codemods.map(async (codemod)=>{
|
|
554
557
|
const codemodWorkingDirectory = external_node_path_default().resolve(workingDirectory, codemod.name.replace(/\//g, '-'));
|
|
555
558
|
await (0, external_execa_namespaceObject.$)`mkdir -p ${codemodWorkingDirectory}`;
|
|
556
|
-
const codeRepositories = await Promise.all(updatedRepositories.map((repo)=>
|
|
559
|
+
const codeRepositories = await Promise.all(updatedRepositories.map((repo)=>{
|
|
560
|
+
const newPath = external_node_path_default().join(codemodWorkingDirectory, repo.name);
|
|
561
|
+
console.log(`\xa9\u{FE0F} copying ${repo.name} -> ${newPath}`);
|
|
562
|
+
return repo.copy(newPath);
|
|
563
|
+
}));
|
|
557
564
|
return [
|
|
558
565
|
codemod.name,
|
|
559
566
|
codeRepositories
|
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',
|
|
@@ -469,8 +469,9 @@ async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
|
469
469
|
const results = Object.fromEntries(await Promise.all(codemods.map(async (codemod)=>{
|
|
470
470
|
const codemodRepositories = codemodRepositoriesMappedByCodemodName[codemod.name];
|
|
471
471
|
asserts.invariant(null != codemodRepositories, 'Codemod repositories should be present');
|
|
472
|
+
const codemodWorkingDirectory = node_path.resolve(workingDirectory, codemod.name.replace(/\//g, '-'));
|
|
472
473
|
const failedRepositoryAddressesMappedByCodemodNames = {};
|
|
473
|
-
const result = await runCodemod(codemod,
|
|
474
|
+
const result = await runCodemod(codemod, codemodWorkingDirectory, {
|
|
474
475
|
rootPaths: codemodRepositories.map((repository)=>repository.path),
|
|
475
476
|
hooks: {
|
|
476
477
|
preCodemodRun: async (codemod)=>{
|
|
@@ -488,23 +489,29 @@ async function runCodemodRunner(codemods, repositories, workingDirectory) {
|
|
|
488
489
|
return results;
|
|
489
490
|
}
|
|
490
491
|
async function prepareRepositoriesForCodemods(repositories, codemods, workingDirectory) {
|
|
491
|
-
const
|
|
492
|
+
const reposMappedByMainBranch = await Promise.all(repositories.map(async (repo)=>{
|
|
492
493
|
const mainBranchResult = await repo.getMainBranch();
|
|
493
494
|
if (mainBranchResult.isErr()) throw mainBranchResult.error;
|
|
494
|
-
return
|
|
495
|
-
mainBranchResult.value.name,
|
|
496
|
-
repo
|
|
497
|
-
|
|
498
|
-
}))
|
|
499
|
-
const updatedRepositories = await Promise.all(
|
|
500
|
-
const prepareResult = await
|
|
495
|
+
return {
|
|
496
|
+
mainBranchName: mainBranchResult.value.name,
|
|
497
|
+
repository: repo
|
|
498
|
+
};
|
|
499
|
+
}));
|
|
500
|
+
const updatedRepositories = await Promise.all(reposMappedByMainBranch.map(async ({ mainBranchName, repository })=>{
|
|
501
|
+
const prepareResult = await repository.prepareForUpdate(mainBranchName);
|
|
501
502
|
if (prepareResult.isErr()) throw prepareResult.error;
|
|
502
503
|
return prepareResult.value;
|
|
503
504
|
}));
|
|
505
|
+
console.log(`\u{1F4CB} prepared the following repos for codemods!
|
|
506
|
+
\xb7 ${updatedRepositories.map((repo)=>repo.address).join("\n\xb7 ")}`);
|
|
504
507
|
return Object.fromEntries(await Promise.all(codemods.map(async (codemod)=>{
|
|
505
508
|
const codemodWorkingDirectory = node_path.resolve(workingDirectory, codemod.name.replace(/\//g, '-'));
|
|
506
509
|
await $`mkdir -p ${codemodWorkingDirectory}`;
|
|
507
|
-
const codeRepositories = await Promise.all(updatedRepositories.map((repo)=>
|
|
510
|
+
const codeRepositories = await Promise.all(updatedRepositories.map((repo)=>{
|
|
511
|
+
const newPath = node_path.join(codemodWorkingDirectory, repo.name);
|
|
512
|
+
console.log(`\xa9\u{FE0F} copying ${repo.name} -> ${newPath}`);
|
|
513
|
+
return repo.copy(newPath);
|
|
514
|
+
}));
|
|
508
515
|
return [
|
|
509
516
|
codemod.name,
|
|
510
517
|
codeRepositories
|