@navikt/aksel 7.18.0 → 7.19.1
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/codemod/migrations.js +6 -0
- package/dist/codemod/transforms/darkside/box-to-boxnew/box-to-boxnew.js +159 -0
- package/dist/codemod/transforms/darkside/prop-deprecate/prop-deprecate.js +1 -1
- package/dist/codemod/transforms/spacing/primitives-spacing/spacing.js +2 -2
- package/dist/codemod/transforms/spacing/token-spacing-js/spacing.js +1 -1
- package/dist/codemod/transforms/v3.0.0/copybutton/copybutton.js +2 -2
- package/dist/codemod/transforms/v4.0.0/internal-react/internal-react.js +4 -4
- package/dist/codemod/utils/ast.js +4 -4
- package/dist/codemod/utils/{moveAndRenameImport.js → packageImports.js} +14 -0
- package/dist/darkside/config/legacy.tokens.js +1 -1
- package/dist/darkside/transforms/darkside-tokens-js.js +2 -2
- package/package.json +4 -4
|
@@ -112,6 +112,12 @@ exports.migrations = {
|
|
|
112
112
|
value: "prop-deprecate",
|
|
113
113
|
path: "darkside/prop-deprecate/prop-deprecate",
|
|
114
114
|
},
|
|
115
|
+
{
|
|
116
|
+
description: "Update Box to to BoxNew (future Box) using the new token system",
|
|
117
|
+
value: "box-to-boxnew",
|
|
118
|
+
path: "darkside/box-to-boxnew/box-to-boxnew",
|
|
119
|
+
warning: "Remember to check if 'aksel box migration'-comment were added to any files after migration. This comment will help you find and update Box-instances where we could not resolve the update for you.",
|
|
120
|
+
},
|
|
115
121
|
],
|
|
116
122
|
};
|
|
117
123
|
function getMigrationPath(str) {
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.default = transformer;
|
|
27
|
+
const legacy_tokens_1 = require("../../../../darkside/config/legacy.tokens");
|
|
28
|
+
const ast_1 = require("../../../utils/ast");
|
|
29
|
+
const lineterminator_1 = require("../../../utils/lineterminator");
|
|
30
|
+
const packageImports_1 = __importStar(require("../../../utils/packageImports"));
|
|
31
|
+
const propsAffected = ["background", "borderColor", "shadow"];
|
|
32
|
+
function transformer(file, api) {
|
|
33
|
+
const j = api.jscodeshift;
|
|
34
|
+
const root = j(file.source);
|
|
35
|
+
const toSourceOptions = (0, lineterminator_1.getLineTerminator)(file.source);
|
|
36
|
+
if (file.source.includes("TODO: aksel box migration")) {
|
|
37
|
+
return root.toSource(toSourceOptions);
|
|
38
|
+
}
|
|
39
|
+
const localName = (0, ast_1.findComponentImport)({
|
|
40
|
+
root,
|
|
41
|
+
j,
|
|
42
|
+
name: "Box",
|
|
43
|
+
packageType: "react",
|
|
44
|
+
});
|
|
45
|
+
if (!localName) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const astElements = root.find(j.JSXElement, {
|
|
49
|
+
openingElement: {
|
|
50
|
+
name: {
|
|
51
|
+
type: "JSXIdentifier",
|
|
52
|
+
name: localName,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const tokenComments = [];
|
|
57
|
+
for (const astElement of astElements.paths()) {
|
|
58
|
+
let encounteredUnmigratableProp = false;
|
|
59
|
+
for (const prop of propsAffected) {
|
|
60
|
+
(0, ast_1.findProps)({ j, path: astElement, name: prop }).forEach((attr) => {
|
|
61
|
+
const attrvalue = attr.value.value;
|
|
62
|
+
if (attrvalue.type === "StringLiteral") {
|
|
63
|
+
const config = legacy_tokens_1.legacyTokenConfig[attrvalue.value];
|
|
64
|
+
if (config === null || config === void 0 ? void 0 : config.replacement) {
|
|
65
|
+
attrvalue.value = config.replacement;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
encounteredUnmigratableProp = true;
|
|
69
|
+
const tokenComment = {
|
|
70
|
+
prop,
|
|
71
|
+
token: attrvalue.value,
|
|
72
|
+
};
|
|
73
|
+
if (config === null || config === void 0 ? void 0 : config.comment) {
|
|
74
|
+
tokenComment.comment = config.comment;
|
|
75
|
+
}
|
|
76
|
+
tokenComments.push(tokenComment);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (!encounteredUnmigratableProp) {
|
|
82
|
+
// TODO: ?? Box -> BoxNew type fail? (but works)
|
|
83
|
+
astElement.node.openingElement.name.name = "BoxNew";
|
|
84
|
+
astElement.node.closingElement.name.name = "BoxNew";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const blockComment = createFileComments({ tokenComments });
|
|
88
|
+
const importAnalysis = analyzePartialMigration(j, root.toSource(toSourceOptions));
|
|
89
|
+
if (importAnalysis === "no new") {
|
|
90
|
+
// WHY: we do nothing to the import statements if we couldn't migrate any Box
|
|
91
|
+
}
|
|
92
|
+
if (importAnalysis === "mixed") {
|
|
93
|
+
// WHY: mixed Box and BoxNew == we keep old, and add the new import
|
|
94
|
+
(0, packageImports_1.addPackageImport)({
|
|
95
|
+
j,
|
|
96
|
+
root,
|
|
97
|
+
packageName: "@navikt/ds-react/Box",
|
|
98
|
+
specifiers: ["BoxNew"],
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (importAnalysis === "all new") {
|
|
102
|
+
// WHY: when we have only new boxes == we replace the old import with the new one
|
|
103
|
+
(0, packageImports_1.default)(j, root, {
|
|
104
|
+
fromImport: "@navikt/ds-react",
|
|
105
|
+
toImport: "@navikt/ds-react/Box",
|
|
106
|
+
fromName: "Box",
|
|
107
|
+
toName: "BoxNew",
|
|
108
|
+
ignoreAlias: localName !== "Box",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const output = `${blockComment ? blockComment + "\n\n" : ""}${root.toSource(toSourceOptions)}`;
|
|
112
|
+
return output;
|
|
113
|
+
}
|
|
114
|
+
const createFileComments = ({ tokenComments, }) => {
|
|
115
|
+
if (tokenComments.length === 0) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
let constructedComment = "/*\nTODO: aksel box migration:\nCould not migrate the following:\n";
|
|
119
|
+
for (const { prop, token, comment } of tokenComments.values()) {
|
|
120
|
+
constructedComment += ` - ${prop}=${token}\n`;
|
|
121
|
+
if (comment) {
|
|
122
|
+
constructedComment += ` - ${comment}\n`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
constructedComment += "*/";
|
|
126
|
+
return constructedComment;
|
|
127
|
+
};
|
|
128
|
+
const analyzePartialMigration = (j, source) => {
|
|
129
|
+
const root = j(source);
|
|
130
|
+
const astNewElements = (0, ast_1.findJSXElement)({
|
|
131
|
+
root,
|
|
132
|
+
j,
|
|
133
|
+
name: "BoxNew",
|
|
134
|
+
originalName: "BoxNew",
|
|
135
|
+
});
|
|
136
|
+
if (astNewElements.length === 0) {
|
|
137
|
+
return "no new";
|
|
138
|
+
}
|
|
139
|
+
const localName = (0, ast_1.findComponentImport)({
|
|
140
|
+
root,
|
|
141
|
+
j,
|
|
142
|
+
name: "Box",
|
|
143
|
+
packageType: "react",
|
|
144
|
+
});
|
|
145
|
+
if (!localName) {
|
|
146
|
+
// this should never happen
|
|
147
|
+
throw new Error('package imports have been tampered with before the package import "step" in the migration');
|
|
148
|
+
}
|
|
149
|
+
const astOldElements = (0, ast_1.findJSXElement)({
|
|
150
|
+
root,
|
|
151
|
+
j,
|
|
152
|
+
name: localName,
|
|
153
|
+
originalName: "Box",
|
|
154
|
+
});
|
|
155
|
+
if (astOldElements.length === 0) {
|
|
156
|
+
return "all new";
|
|
157
|
+
}
|
|
158
|
+
return "mixed";
|
|
159
|
+
};
|
|
@@ -18,7 +18,7 @@ function transformer(file, api) {
|
|
|
18
18
|
const toSourceOptions = (0, lineterminator_1.getLineTerminator)(file.source);
|
|
19
19
|
for (const [component, props] of Object.entries(deprecationMap)) {
|
|
20
20
|
const sourceName = (0, ast_1.findComponentImport)({
|
|
21
|
-
|
|
21
|
+
root,
|
|
22
22
|
j,
|
|
23
23
|
name: component,
|
|
24
24
|
packageType: "react",
|
|
@@ -35,7 +35,7 @@ function transformer(file, api) {
|
|
|
35
35
|
"gap",
|
|
36
36
|
];
|
|
37
37
|
for (const primitive of primitives) {
|
|
38
|
-
const name = (0, ast_1.findComponentImport)({
|
|
38
|
+
const name = (0, ast_1.findComponentImport)({ root, j, name: primitive });
|
|
39
39
|
if (!name) {
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
@@ -46,7 +46,7 @@ function transformer(file, api) {
|
|
|
46
46
|
originalName: primitive,
|
|
47
47
|
}).forEach((path) => {
|
|
48
48
|
for (const prop of affectedProps) {
|
|
49
|
-
(0, ast_1.
|
|
49
|
+
(0, ast_1.findProps)({ j, path, name: prop }).forEach((attr) => {
|
|
50
50
|
const attrValue = attr.value.value;
|
|
51
51
|
if (attrValue.type === "StringLiteral") {
|
|
52
52
|
/* padding="32" */
|
|
@@ -12,7 +12,7 @@ function transformer(file, api) {
|
|
|
12
12
|
const oldCSSVar = (0, translate_token_1.translateToken)(`--a-spacing-${oldVar}`, "js");
|
|
13
13
|
const newCSSVar = (0, translate_token_1.translateToken)(`--a-space-${newVar}`, "js");
|
|
14
14
|
const name = (0, ast_1.findComponentImport)({
|
|
15
|
-
|
|
15
|
+
root,
|
|
16
16
|
j,
|
|
17
17
|
name: oldCSSVar,
|
|
18
18
|
packageType: "tokens",
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = transformer;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const lineterminator_1 = require("../../../utils/lineterminator");
|
|
9
|
-
const
|
|
9
|
+
const packageImports_1 = __importDefault(require("../../../utils/packageImports"));
|
|
10
10
|
const removeProps_1 = __importDefault(require("../../../utils/removeProps"));
|
|
11
11
|
/**
|
|
12
12
|
* @param {import('jscodeshift').FileInfo} file
|
|
@@ -22,7 +22,7 @@ function transformer(file, api) {
|
|
|
22
22
|
return file.source;
|
|
23
23
|
}
|
|
24
24
|
const toName = "CopyButton";
|
|
25
|
-
const localName = (0,
|
|
25
|
+
const localName = (0, packageImports_1.default)(j, root, {
|
|
26
26
|
fromImport: "@navikt/ds-react-internal",
|
|
27
27
|
toImport: "@navikt/ds-react",
|
|
28
28
|
fromName: "CopyToClipboard",
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = transformer;
|
|
7
7
|
const lineterminator_1 = require("../../../utils/lineterminator");
|
|
8
|
-
const
|
|
8
|
+
const packageImports_1 = __importDefault(require("../../../utils/packageImports"));
|
|
9
9
|
/**
|
|
10
10
|
* @param {import('jscodeshift').FileInfo} file
|
|
11
11
|
* @param {import('jscodeshift').API} api
|
|
@@ -19,19 +19,19 @@ function transformer(file, api) {
|
|
|
19
19
|
catch (_a) {
|
|
20
20
|
return file.source;
|
|
21
21
|
}
|
|
22
|
-
(0,
|
|
22
|
+
(0, packageImports_1.default)(j, root, {
|
|
23
23
|
fromImport: "@navikt/ds-react-internal",
|
|
24
24
|
toImport: "@navikt/ds-react",
|
|
25
25
|
fromName: "Header",
|
|
26
26
|
toName: "InternalHeader",
|
|
27
27
|
});
|
|
28
|
-
(0,
|
|
28
|
+
(0, packageImports_1.default)(j, root, {
|
|
29
29
|
fromImport: "@navikt/ds-react-internal",
|
|
30
30
|
toImport: "@navikt/ds-react",
|
|
31
31
|
fromName: "Dropdown",
|
|
32
32
|
toName: "Dropdown",
|
|
33
33
|
});
|
|
34
|
-
(0,
|
|
34
|
+
(0, packageImports_1.default)(j, root, {
|
|
35
35
|
fromImport: "@navikt/ds-react-internal",
|
|
36
36
|
toImport: "@navikt/ds-react",
|
|
37
37
|
fromName: "Timeline",
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findComponentImport = findComponentImport;
|
|
4
4
|
exports.findJSXElement = findJSXElement;
|
|
5
|
-
exports.
|
|
5
|
+
exports.findProps = findProps;
|
|
6
6
|
/**
|
|
7
7
|
* Finds a component import, accounting for sub-components and aliases.
|
|
8
8
|
* Returns the local name of the component. If the component is not found, returns null.
|
|
9
|
+
* root should ideally be the root of the file in most cases (imports happen at top level)
|
|
9
10
|
*/
|
|
10
11
|
function findComponentImport(input) {
|
|
11
|
-
const { j,
|
|
12
|
+
const { j, root, name: _name, packageType = "react" } = input;
|
|
12
13
|
/* Account for sub-components */
|
|
13
14
|
const name = _name.includes(".") ? _name.split(".")[0] : _name;
|
|
14
|
-
const root = j(file.source);
|
|
15
15
|
let foundName = null;
|
|
16
16
|
root.find(j.ImportDeclaration).forEach((path) => {
|
|
17
17
|
if (packageType === "react" && !isAkselReactImport(path)) {
|
|
@@ -62,7 +62,7 @@ function findJSXElement(input) {
|
|
|
62
62
|
/**
|
|
63
63
|
* Finds a prop in a JSX element.
|
|
64
64
|
*/
|
|
65
|
-
function
|
|
65
|
+
function findProps(input) {
|
|
66
66
|
const { j, path, name } = input;
|
|
67
67
|
return j(path).find(j.JSXAttribute, {
|
|
68
68
|
name: {
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addPackageImport = void 0;
|
|
3
4
|
exports.default = moveAndRenameImport;
|
|
5
|
+
// add import declaration after first existing import declaration, or
|
|
6
|
+
// at the beginning of the file
|
|
7
|
+
const addPackageImport = ({ j, root, packageName, specifiers, }) => {
|
|
8
|
+
const existingImport = root.find(j.ImportDeclaration);
|
|
9
|
+
const importDecl = j.importDeclaration(specifiers.map((specifier) => j.importSpecifier(j.identifier(specifier))), j.stringLiteral(packageName));
|
|
10
|
+
if (existingImport.length === 0) {
|
|
11
|
+
root.get().node.program.body.unshift(importDecl);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
existingImport.insertBefore(importDecl);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.addPackageImport = addPackageImport;
|
|
4
18
|
function moveAndRenameImport(j, root, { fromImport, toImport, fromName, toName, ignoreAlias = false, }) {
|
|
5
19
|
var _a, _b;
|
|
6
20
|
/* Does package-name exist */
|
|
@@ -693,7 +693,7 @@ const colors = {
|
|
|
693
693
|
"surface-alt-3-strong": {
|
|
694
694
|
ref: "deepblue-800",
|
|
695
695
|
raw: "rgba(0, 52, 83, 1)",
|
|
696
|
-
comment: "Use 'bg-brand-blue-moderate' in theme 'dark'-mode.
|
|
696
|
+
comment: "Use 'bg-brand-blue-moderate' in theme 'dark'-mode.",
|
|
697
697
|
replacement: "",
|
|
698
698
|
},
|
|
699
699
|
"surface-alt-3-moderate": {
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.default = transformer;
|
|
7
7
|
const imports_1 = require("../../codemod/utils/imports");
|
|
8
8
|
const lineterminator_1 = require("../../codemod/utils/lineterminator");
|
|
9
|
-
const
|
|
9
|
+
const packageImports_1 = __importDefault(require("../../codemod/utils/packageImports"));
|
|
10
10
|
const translate_token_1 = require("../../codemod/utils/translate-token");
|
|
11
11
|
const legacy_tokens_1 = require("../config/legacy.tokens");
|
|
12
12
|
function transformer(file, api) {
|
|
@@ -32,7 +32,7 @@ function transformer(file, api) {
|
|
|
32
32
|
if (config.replacement.length > 0) {
|
|
33
33
|
/* We remove the prefix */
|
|
34
34
|
const jsToken = (0, translate_token_1.translateToken)(`--ax-${config.replacement}`, "js").slice(2);
|
|
35
|
-
const localName = (0,
|
|
35
|
+
const localName = (0, packageImports_1.default)(j, root, {
|
|
36
36
|
fromImport: "@navikt/ds-tokens/dist/tokens",
|
|
37
37
|
toImport: "@navikt/ds-tokens/darkside-js",
|
|
38
38
|
fromName: foundName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/aksel",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.19.1",
|
|
4
4
|
"description": "Aksel command line interface. Handles css-imports, codemods and more",
|
|
5
5
|
"author": "Aksel | Nav designsystem team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://aksel.nav.no/grunnleggende/kode/kommandolinje",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@navikt/ds-css": "^7.
|
|
33
|
-
"@navikt/ds-tokens": "^7.
|
|
32
|
+
"@navikt/ds-css": "^7.19.1",
|
|
33
|
+
"@navikt/ds-tokens": "^7.19.1",
|
|
34
34
|
"axios": "1.8.3",
|
|
35
35
|
"chalk": "4.1.0",
|
|
36
36
|
"cli-progress": "^3.12.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"commander": "10.0.1",
|
|
39
39
|
"enquirer": "^2.3.6",
|
|
40
40
|
"fast-glob": "3.2.11",
|
|
41
|
-
"figlet": "1.
|
|
41
|
+
"figlet": "1.8.0",
|
|
42
42
|
"is-git-clean": "1.1.0",
|
|
43
43
|
"jscodeshift": "^0.15.1",
|
|
44
44
|
"jscodeshift-add-imports": "1.0.11",
|