Skip to content

Commit 94764fe

Browse files
[CLI] v8-tokens codemod update (#4341)
* 🎉 Support ext * ⚡ Optimize file indexing * ⚡ Optimize file-indexing * ⚡ Optimize regex creation * 🐛 Optimize indexing, add js and some tailwind-support * ⚡ Optimize tailwind codemod * 🧪 More tests * ⚡ Optimize css codemod * 📝 Better status reports * 📝 Better printouts * 📝 Improve printouts * ⚡ Avoid re-running status-update * 📝 Update summary * 🔥 Removed waitfor keypress * 📝 Changeset * ♻️ Avoid inline assignment * 📝 Added comments * ♻️ Small refactor, extracting complexity into functions * 🔥 Removed commented code * Update @navikt/aksel/src/codemod/run-codeshift.ts Co-authored-by: Halvor Haugan <[email protected]> * Update @navikt/aksel/src/codemod/run-codeshift.ts Co-authored-by: Halvor Haugan <[email protected]> * ♻️ No array for glob-list * ♻️ getWordPositionInFile -> getCharacterPositionInFile * ♻️ Only comment once for grouped tokens * ⚡ Always update status on print * Revert "⚡ Always update status on print" This reverts commit 65b1d9c. * ⚡ Always update status on print --------- Co-authored-by: Halvor Haugan <[email protected]>
1 parent 97e4e69 commit 94764fe

17 files changed

+897
-181
lines changed

.changeset/legal-hands-switch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@navikt/aksel": patch
3+
---
4+
5+
CLI: Improvements to v8-tokens codemod.

@navikt/aksel/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"axios": "1.13.2",
3838
"chalk": "4.1.0",
3939
"cli-progress": "^3.12.0",
40+
"clipboardy": "^2.3.0",
4041
"commander": "10.0.1",
4142
"enquirer": "^2.3.6",
4243
"fast-glob": "3.2.11",

@navikt/aksel/src/codemod/codeshift.utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ type SupportedCodemodExtensions =
2121
*/
2222
function getDefaultGlob(ext: string): string {
2323
const defaultExt = "js,ts,jsx,tsx,css,scss,less";
24+
const extensions = cleanExtensions(ext ?? defaultExt);
2425

25-
return `**/*.{${cleanExtensions(ext ?? defaultExt).join(",")}}`;
26+
/**
27+
* Single-item braces are treated as a literal string by some globbing libraries,
28+
* so we only use them when there are multiple extensions
29+
*/
30+
if (extensions.length > 1) {
31+
return `**/*.{${extensions.join(",")}}`;
32+
}
33+
34+
return `**/*.${extensions[0]}`;
2635
}
2736

2837
/**

@navikt/aksel/src/codemod/run-codeshift.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,31 @@ export async function runCodeshift(
2828
`./transforms/${getMigrationPath(input)}.js`,
2929
);
3030

31-
const filepaths = fg.sync([options.glob ?? getDefaultGlob(options?.ext)], {
31+
console.info(chalk.greenBright.bold("\nWelcome to Aksel codemods!"));
32+
console.info("\nRunning migration:", chalk.green(input));
33+
34+
const globList = options.glob ?? getDefaultGlob(options?.ext);
35+
36+
console.info(
37+
chalk.gray(
38+
`Using glob pattern(s): ${globList}\nWorking directory: ${process.cwd()}\n`,
39+
),
40+
);
41+
42+
const filepaths = fg.sync(globList, {
3243
cwd: process.cwd(),
3344
ignore: GLOB_IGNORE_PATTERNS,
45+
/**
46+
* When globbing, do not follow symlinks to avoid processing files outside the directory.
47+
* This is most likely to happen in monorepos where node_modules may contain symlinks to packages
48+
* in other parts of the repo.
49+
*
50+
* While node_modules is already ignored via GLOB_IGNORE_PATTERNS, if user globs upwards (e.g., using '../src/**'),
51+
* that ignore-pattern may be ignored, leading to unintended file processing.
52+
*/
53+
followSymbolicLinks: false,
3454
});
3555

36-
console.info("\nRunning migration:", chalk.green("input"));
37-
38-
options?.glob && console.info(`Using glob: ${chalk.green(options.glob)}\n`);
39-
4056
const warning = getWarning(input);
4157

4258
const unsafeExtensions = getIgnoredFileExtensions(input);
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
import chalk from "chalk";
22
import { Command } from "commander";
3-
import { validateGit } from "../codemod/validation.js";
4-
// import figlet from "figlet";
5-
// import { getMigrationString } from "./migrations.js";
63
import { runTooling } from "./run-tooling.js";
74

85
const program = new Command();
96

107
export function darksideCommand() {
11-
program.name(`${chalk.blueBright(`npx @navikt/aksel`)}`);
8+
program.name(`${chalk.blueBright(`npx @navikt/aksel v8-tokens`)}`);
129

1310
program
1411
.option(
1512
"-g, --glob [glob]",
1613
"Globbing pattern, overrides --ext! Run with 'noglob' if using zsh-terminal. ",
1714
)
15+
.option(
16+
"-e, --ext [ext]",
17+
"File extensions to include, defaults to 'js,ts,jsx,tsx,css,scss,less'",
18+
)
1819
.option("-d, --dry-run", "Dry run, no changes will be made")
1920
.option("-f, --force", "Forcibly run updates without checking git-changes")
20-
.description("Update tool for darkside token updates");
21+
.description("Update tool for v8 token updates");
2122

2223
program.parse();
2324
const options = program.opts();
2425

25-
/* Makes sure that you don't migrate lots of files while having other uncommitted changes */
26-
if (!options.force) {
27-
validateGit(options, program);
28-
}
29-
3026
runTooling(options as Parameters<typeof runTooling>["0"], program);
3127
}

0 commit comments

Comments
 (0)