@elliemae/ds-codemods 3.0.0-next.49 → 3.0.0-next.52
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.
|
@@ -278,7 +278,7 @@ export const COMPONENT_MAP = {
|
|
|
278
278
|
// E.G. 2
|
|
279
279
|
// import { DSAccordion, DSAccordionItem} from '@elliemae/ds-accordion'
|
|
280
280
|
// catches: [] ( because @elliemae\/ds-basic is never matched )
|
|
281
|
-
// https://regex101.com/r/
|
|
281
|
+
// https://regex101.com/r/vcwW0S/1
|
|
282
282
|
export const problematicImportRegexp =
|
|
283
283
|
// /(?<=(import))(((?!import).)*?)(?<=(\s?from\s)?)(['"]@elliemae\/ds-basic(\/\S+)?['"])/gms;
|
|
284
|
-
/(import)\s?((?:(?!import).)*?)(\s?from\s)(['"]@elliemae\/ds-basic(
|
|
284
|
+
/(import)\s?((?:(?!import).)*?)(\s?from\s)(['"]@elliemae\/ds-basic(\/(?:(?!form)\S)+)?['"])/gms;
|
|
@@ -34,7 +34,7 @@ export const mapComponentsToImportStatement = (fullMatch, components) => {
|
|
|
34
34
|
if (entries.length > 0)
|
|
35
35
|
entries.forEach(([fromPackage, comps]) => {
|
|
36
36
|
if (fromPackage !== 'undefined') {
|
|
37
|
-
autoSolutions.push(`import { ${comps.join(', ')} } from '${fromPackage}'
|
|
37
|
+
autoSolutions.push(`import { ${comps.join(', ')} } from '${fromPackage}'`);
|
|
38
38
|
} else {
|
|
39
39
|
hasUnfixables = true;
|
|
40
40
|
unAutoFixables.push({ fromPackage, comps });
|
|
@@ -66,32 +66,41 @@ export const mapComponentsToImportStatement = (fullMatch, components) => {
|
|
|
66
66
|
return {
|
|
67
67
|
solution,
|
|
68
68
|
unfixable,
|
|
69
|
+
importStatementsMap,
|
|
69
70
|
};
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
export const getSubFolderSolution = (fullMatch, components, fullFromPack) => ({
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
solution: {
|
|
75
|
+
fullMatch,
|
|
76
|
+
solution: `import ${components} from '${SUGGESTABLE_MAP[fullFromPack]}'`,
|
|
77
|
+
solutionType: SOLUTIONS_TYPES.SUB_FOLDER,
|
|
78
|
+
},
|
|
79
|
+
fromPackage: SUGGESTABLE_MAP[fullFromPack],
|
|
76
80
|
});
|
|
77
81
|
|
|
78
82
|
export const getSolutions = (fileContent) => {
|
|
79
83
|
const matches = matchDsBasicImports(fileContent);
|
|
80
84
|
const solutions = [];
|
|
81
85
|
const unfixables = [];
|
|
86
|
+
let newPackagesMap = {};
|
|
82
87
|
let hasErrors = false;
|
|
83
88
|
if (matches.length > 0) {
|
|
84
89
|
hasErrors = true;
|
|
85
90
|
matches.forEach((match) => {
|
|
86
91
|
const { fullMatch, componentVariable, fullFromPack, optionalSubfolder } = match;
|
|
87
|
-
if (optionalSubfolder !== '')
|
|
88
|
-
|
|
92
|
+
if (optionalSubfolder !== '') {
|
|
93
|
+
const { solution, fromPackage } = getSubFolderSolution(fullMatch, componentVariable, fullFromPack);
|
|
94
|
+
solutions.push(solution);
|
|
95
|
+
newPackagesMap[fromPackage] = componentVariable;
|
|
96
|
+
} else {
|
|
89
97
|
const csvComponents = componentVariable.replace(/{+/g, '').replace(/}+/g, '').replace(/\s+/gms, '').split(',');
|
|
90
|
-
const { solution, unfixable } = mapComponentsToImportStatement(fullMatch, csvComponents);
|
|
98
|
+
const { solution, unfixable, importStatementsMap } = mapComponentsToImportStatement(fullMatch, csvComponents);
|
|
91
99
|
if (solution) solutions.push(solution);
|
|
92
100
|
if (unfixable) unfixables.push(unfixable);
|
|
101
|
+
newPackagesMap = { ...newPackagesMap, ...importStatementsMap };
|
|
93
102
|
}
|
|
94
103
|
});
|
|
95
104
|
}
|
|
96
|
-
return { solutions, unfixables, hasErrors };
|
|
105
|
+
return { solutions, unfixables, hasErrors, newPackages: Object.keys(newPackagesMap), newPackagesMap };
|
|
97
106
|
};
|
|
@@ -23,6 +23,7 @@ export const helpMigrateToV3 = (options) => {
|
|
|
23
23
|
listOfAllFilesWithErrors: [],
|
|
24
24
|
listOfFixedFiles: [],
|
|
25
25
|
listOfUnfixableFiles: [],
|
|
26
|
+
convertedPackagesMap: {},
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
pathToFileToProcess.forEach((path) => {
|
|
@@ -31,7 +32,7 @@ export const helpMigrateToV3 = (options) => {
|
|
|
31
32
|
flag: 'r',
|
|
32
33
|
});
|
|
33
34
|
if (fileContent && typeof fileContent === 'string') {
|
|
34
|
-
const { solutions, unfixables, hasErrors } = getSolutions(fileContent);
|
|
35
|
+
const { solutions, unfixables, hasErrors, newPackagesMap } = getSolutions(fileContent);
|
|
35
36
|
if (hasErrors) {
|
|
36
37
|
totals.listOfAllFilesWithErrors.push(path);
|
|
37
38
|
totals.hasErrors = true;
|
|
@@ -45,27 +46,39 @@ export const helpMigrateToV3 = (options) => {
|
|
|
45
46
|
totals.listOfFixedFiles.push(path);
|
|
46
47
|
totals.totalAppliedFixes += solutions.length;
|
|
47
48
|
}
|
|
49
|
+
if (Object.keys(newPackagesMap).length) {
|
|
50
|
+
totals.convertedPackagesMap = { ...totals.convertedPackagesMap, ...newPackagesMap };
|
|
51
|
+
}
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
});
|
|
51
55
|
if (totals.hasErrors) {
|
|
56
|
+
console.log('\n');
|
|
52
57
|
console.log(chalk.magentaBright('# Found outdated import statement in:'));
|
|
53
58
|
console.log('```');
|
|
54
59
|
console.log(totals.listOfAllFilesWithErrors);
|
|
55
60
|
console.log('```');
|
|
61
|
+
console.log('\n');
|
|
56
62
|
console.log(chalk.bold.green('## The following files were auto-fixed'));
|
|
57
63
|
console.log('```');
|
|
58
64
|
console.log(totals.listOfFixedFiles);
|
|
59
65
|
console.log('```');
|
|
60
66
|
console.log(chalk.bold.green(`a total of ${totals.totalAppliedFixes} fixes were applied`));
|
|
61
67
|
if (totals.hasUnfixables) {
|
|
68
|
+
console.log('\n');
|
|
62
69
|
console.log(chalk.redBright('## found some problems that can not be autofixed '));
|
|
63
70
|
console.log('```');
|
|
64
71
|
console.log(util.inspect(totals.listOfUnfixableFiles, { showHidden: false, depth: null, colors: true }));
|
|
65
72
|
console.log('```');
|
|
73
|
+
console.log('\n');
|
|
66
74
|
console.log(chalk.redBright('you must manually solve those import statements'));
|
|
67
75
|
console.log('check https://qa.dimsum.rd.elliemae.io/ documentation to find your new import statements');
|
|
68
76
|
}
|
|
69
77
|
}
|
|
78
|
+
console.log('\n');
|
|
79
|
+
console.log(chalk.yellowBright('# You must ensure following dependencies are present in your package.json:'));
|
|
80
|
+
console.log('```');
|
|
81
|
+
console.log(util.inspect(Object.keys(totals.convertedPackagesMap), { showHidden: false, depth: null, colors: true }));
|
|
82
|
+
console.log('```');
|
|
70
83
|
console.log(chalk.cyanBright('Done.'));
|
|
71
84
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-codemods",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.52",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Code Mods",
|
|
6
6
|
"files": [
|
|
@@ -29,6 +29,12 @@
|
|
|
29
29
|
"reportFile": "tests.xml",
|
|
30
30
|
"indent": 4
|
|
31
31
|
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"try-codemods": "npx ./",
|
|
34
|
+
"try-check-deprecated-packages": "npx ./ check-deprecated-packages --cwd=\"test-ables/check-deprecated-packages/with-deprecated\"",
|
|
35
|
+
"try-check-deprecated-packages-no-dimsum": "npx ./ check-deprecated-packages --cwd=\"test-ables/check-deprecated-packages/without-dimsum-packages\"",
|
|
36
|
+
"try-help-migrate-to-v3": "npx ./ help-migrate-to-v3 --globPattern=\"test-ables/help-migrate-to-v3/**/*.js,./**/*.jsx,./**/*.ts,./**/*.tsx\" --globPatternIgnore=\"**/node_modules/**/*\""
|
|
37
|
+
},
|
|
32
38
|
"dependencies": {
|
|
33
39
|
"arg": "~5.0.1",
|
|
34
40
|
"chalk": "~4.1.2",
|
|
@@ -44,11 +50,5 @@
|
|
|
44
50
|
"publishConfig": {
|
|
45
51
|
"access": "public",
|
|
46
52
|
"typeSafety": false
|
|
47
|
-
},
|
|
48
|
-
"scripts": {
|
|
49
|
-
"try-codemods": "npx ./",
|
|
50
|
-
"try-check-deprecated-packages": "npx ./ check-deprecated-packages --cwd=\"test-ables/check-deprecated-packages/with-deprecated\"",
|
|
51
|
-
"try-check-deprecated-packages-no-dimsum": "npx ./ check-deprecated-packages --cwd=\"test-ables/check-deprecated-packages/without-dimsum-packages\"",
|
|
52
|
-
"try-help-migrate-to-v3": "npx ./ help-migrate-to-v3 --globPattern=\"test-ables/help-migrate-to-v3/**/*.js,./**/*.jsx,./**/*.ts,./**/*.tsx\" --globPatternIgnore=\"**/node_modules/**/*\""
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
}
|