Skip to content

Commit adaee5e

Browse files
KenAJohCopilot
andauthored
[Darkside] Interaktiv migrering (#3642)
* ✨ Setup darkside migration * ✨ Can now convert primitives spacing * 🧪 Added more tests * 📝 Docs for utils * 📝 Changeset * 📝 Typos * [Darkside] ✨ Added migration for css, less and scss (#3598) * ✨ Added migration for css, less and scsss * Update @navikt/aksel/src/codemod/migrations.ts * ✨ Make old px spacing space-1 * ✨ Use esbuild to inline local references * ✨ Added js migration to space-tokens (#3600) * ✨ Setup first iteration of token translation object * ✨ Started mapping old to new tokens * ♻️ Simplified repalcement logic * ✨ Added tests for token-migration * ✨ Replaces old token with new reference * ✨ Handle overrides of tokens * 🧪 Global messages storage * 📝 Added migration * 🐛 Initialize message list * ✨ Customizable results messaging * ✨ Customizable results messaging * 🐛 Use replacement, not ref * 📝 Only document found legacy-tokens, dont rename them * 📝 Better comments * ✨ Added context to remaining token updates * ✨ Added comments to unsupported token * ✨ Format comments better, remove duplicates * 📝 Success message if no legacy-tokens found * 🐛 Return updated source files * 🐛 Reference valid replacement * 🔥 Removed comments * ✨ Added better messaging * ✨ Better messaging structure * 🧪 Added more tests * 🧪 Tests for less, scss, css and js tokens * 🐛 CSS hits were shown as scss and less hits * 📝 Format messages better * 📝 Format messages better * ✨ Added js-migrations template * Update test runner * 🐛 Revert mistakes * 🐛 Resolve testing rig * ✨ Js token migration * 📝 Better docs for JS migration * 📝 Added missing lineshift * ✨ Tooling setup * ✨ Tooling setup with enquirer * ✨ Tooling setup with enquirer * ✨ Set up inquirier and enquirer to promt user for tasks * ✨ Get legacy-data * ✨ Now formats and prints progress * ✨ Now formats and prints progress * ⚡ Smarter scanning of updated tokens * ⚡ Refactored status-code * ✨ Now prints remaining files * ✨ Smarter tailwind-regex * 📝 Tell user we are scanning the files * ✨ Moved transforms to new darkside location * 🚚 Moved tests for js transforms * 📝 Updated prettier config to ignore new test-files * 📝 Moved css, less, scss tests * 🐛 Resolved tests not running properly on less,scss setup * WIP: tailwind config migration * 📝 Added tailwind config for border-radius * ✨ Strictly match tailwind-classes * ♻️ Convert status obj to class * ♻️ Compact regex parsing * ♻️ Simplified regex-handling for new token lookup * ✨ Added support for component tokens * ⚡ Optimize lineNumber task * 🐛 Inline regex-probe * 🐛 Remove old merged code * 🐛 Fix regex escape-characters * Update @navikt/aksel/src/darkside/index.ts Co-authored-by: Copilot <[email protected]> * 🐛 Fix token-tests * ✨ Now prints with token-name * ♻️ Move files * ♻️ Move printing to TokenStatus class * ✨ Add comments to printout * 🐛 Handle word boundaries * ⚡ Pre-generate the regexes * 🧪 More regex-tests * 🧪 More regex-tests * ⚡ Use built-in regexes * ⚡ Only run codeshift on relevant files * 🐛 No print for codemod status update * ⚡ Only run codeshift on relevant files * 📝 Added extra space * 📝 Exit after codemod * 📝 Removed temp logging * 🐛 Await codeshift execution * 🧪 Added tests for not imported JS-tokens * ✨ Implemented tailwind migration code * 🧪 @apply tests for tailwind transform * 🐛 Handle spaces better for tailwind config * 🐛 Handle prefixing of tailwind config correctly * 🐛 Handles cases where empty collection was passed * 🐛 makes sure to clean up match before parsing * 🧪 More tailwind-codemod tests * ⚰️ Removed moved code, renamed darkside -> spacing for migrations * ♻️ Config cleanup part 1 * ♻️ Config cleanup part 2 * ♻️ Refactored runner * ✨ Added run all migraitons task * 🐛 Use destrucutred taskname * 📝 Better naming * 📝 More spesific import docs * 🐛 Print filename correctly when token contains special characters * 🐛 Update spacing migrations paths * 🐛 Added new spacing-tokens to legacy config * ✨ Initialize status directly in constructor * ⬆️ yarn lock sync --------- Co-authored-by: Copilot <[email protected]>
1 parent e826eb7 commit adaee5e

File tree

80 files changed

+3335
-1780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3335
-1780
lines changed

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ module.exports = {
179179
"esm",
180180
"cjs",
181181
"dist",
182+
"@navikt/aksel/**/*.input.*",
183+
"@navikt/aksel/**/*.output.*",
182184
"**/codemod/**/*.js",
183185
"!.storybook",
184186
"**/playwright-report/**",

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
**/nais*.yaml
22
**/nais*.yml
33
**/codemod/**/tests/**/*.js
4+
**/@navikt/aksel/**/*.input.*
5+
**/@navikt/aksel/**/*.output.*
46
node_modules
57
.next
68
dist

@navikt/aksel/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
"homepage": "https://aksel.nav.no/grunnleggende/kode/kommandolinje",
3131
"dependencies": {
3232
"@navikt/ds-css": "^7.17.3",
33+
"@navikt/ds-tokens": "^7.17.3",
3334
"axios": "1.8.2",
3435
"chalk": "4.1.0",
36+
"cli-progress": "^3.12.0",
3537
"clipboardy": "^2.3.0",
3638
"commander": "10.0.1",
3739
"enquirer": "^2.3.6",
@@ -44,6 +46,7 @@
4446
"react-scanner": "^1.1.0"
4547
},
4648
"devDependencies": {
49+
"@types/cli-progress": "3.11.6",
4750
"rimraf": "6.0.1",
4851
"typescript": "5.5.4",
4952
"vitest": "^2.1.8"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const GLOB_IGNORE_PATTERNS = [
2+
"**/node_modules/**",
3+
"**/dist/**",
4+
"**/build/**",
5+
"**/lib/**",
6+
"**/.next/**",
7+
"**/__snapshots__/**",
8+
];
9+
10+
/**
11+
* Utility function to generate the default glob pattern
12+
*/
13+
function getDefaultGlob(ext: string): string {
14+
const defaultExt = "js,ts,jsx,tsx,css,scss,less";
15+
return `**/*.{${cleanExtensions(ext ?? defaultExt).join(",")}}`;
16+
}
17+
18+
/**
19+
* Utility function to clean file extensions
20+
*/
21+
function cleanExtensions(ext: string): string[] {
22+
return ext
23+
.split(",")
24+
.map((e) => e.trim())
25+
.map((e) => e.replace(".", ""));
26+
}
27+
28+
export { GLOB_IGNORE_PATTERNS, getDefaultGlob, cleanExtensions };

@navikt/aksel/src/codemod/migrations.ts

+4-15
Original file line numberDiff line numberDiff line change
@@ -97,35 +97,24 @@ export const migrations: {
9797
"Remember to update use of `variant`-prop to match previous use of colors. If needed the component exposes css-variables for custom overrides",
9898
},
9999
],
100-
darkside: [
100+
spacing: [
101101
{
102102
description:
103103
"Updates all Primitives to use new `space`-tokens. (Works with old and new system)",
104104
value: "primitive-spacing",
105-
path: "darkside/primitives-spacing/spacing",
105+
path: "spacing/primitives-spacing/spacing",
106106
},
107107
{
108108
description:
109109
"Updates css, scss and less-variables to use new `space`-tokens. (Works with old and new system)",
110110
value: "token-spacing",
111-
path: "darkside/token-spacing/spacing",
111+
path: "spacing/token-spacing/spacing",
112112
},
113113
{
114114
description:
115115
"Updates js-tokens to use new `space`-tokens. (Works with old and new system)",
116116
value: "token-spacing-js",
117-
path: "darkside/token-spacing-js/spacing",
118-
},
119-
{
120-
description:
121-
"Updates css, scss and less-variables to use new token-prefix",
122-
value: "token-update",
123-
path: "darkside/token-update/token-update",
124-
},
125-
{
126-
description: "Updates js tokens to use new token-prefix and names",
127-
value: "token-update-js",
128-
path: "darkside/token-update-js/token-update-js",
117+
path: "spacing/token-spacing-js/spacing",
129118
},
130119
],
131120
};

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

+2-25
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Command } from "commander";
33
import fg from "fast-glob";
44
import * as jscodeshift from "jscodeshift/src/Runner";
55
import path from "path";
6+
import { GLOB_IGNORE_PATTERNS, getDefaultGlob } from "./codeshift.utils";
67
import { getMigrationPath, getWarning } from "./migrations";
78

89
const ignoreNodeModules = [
@@ -13,14 +14,6 @@ const ignoreNodeModules = [
1314
"**/.next/**",
1415
];
1516

16-
export const messages = new Map<
17-
string,
18-
{
19-
format: (input: any) => void;
20-
data: any;
21-
}
22-
>();
23-
2417
export async function runCodeshift(
2518
input: string,
2619
options: any,
@@ -33,7 +26,7 @@ export async function runCodeshift(
3326

3427
const filepaths = fg.sync([options.glob ?? getDefaultGlob(options?.ext)], {
3528
cwd: process.cwd(),
36-
ignore: ignoreNodeModules,
29+
ignore: GLOB_IGNORE_PATTERNS,
3730
});
3831

3932
console.info("\nRunning migration:", chalk.green("input"));
@@ -58,23 +51,7 @@ export async function runCodeshift(
5851
});
5952

6053
warning && console.info(`\n${chalk.yellow(warning)}\n`);
61-
62-
messages.forEach((value) => {
63-
value.format(value.data);
64-
});
6554
} catch (error) {
6655
program.error(chalk.red("Error:", error.message));
6756
}
6857
}
69-
70-
function getDefaultGlob(ext: string): string {
71-
const defaultExt = "js,ts,jsx,tsx,css,scss,less";
72-
return `**/*.{${cleanExtensions(ext ?? defaultExt).join(",")}}`;
73-
}
74-
75-
function cleanExtensions(ext: string): string[] {
76-
return ext
77-
.split(",")
78-
.map((e) => e.trim())
79-
.map((e) => e.replace(".", ""));
80-
}

@navikt/aksel/src/codemod/transforms/darkside/darkside.test.ts

-23
This file was deleted.

@navikt/aksel/src/codemod/transforms/darkside/token-update-js/tests/token-update-js.test.ts

-12
This file was deleted.

@navikt/aksel/src/codemod/transforms/darkside/token-update-js/token-update-js.ts

-154
This file was deleted.

@navikt/aksel/src/codemod/transforms/darkside/token-update/tests/complete.input.less

-25
This file was deleted.

0 commit comments

Comments
 (0)