@elliemae/ds-codemods 2.0.0-alpha.1 → 2.0.0-alpha.13
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/.eslintrc-backup.js +3 -3
- package/CHANGELOG.md +372 -280
- package/package.json +7 -4
- package/src/cli/code-mods/cli.js +6 -0
- package/src/cli/code-mods/command-arguments/promptCheckEmPackagesInconsistencies.js +3 -2
- package/src/cli/code-mods/command-arguments/promptFixLegacyImports.js +3 -2
- package/src/cli/code-mods/command-arguments/promptMissingPackages.js +29 -0
- package/src/cli/code-mods/command-logics/check-missing-packages/index.js +82 -0
- package/src/cli/code-mods/command-logics/execute-commands-map.js +4 -0
- package/src/cli/code-mods/commands.js +1 -0
- package/src/cli/code-mods/inquirer-questions-prompter.js +4 -0
- package/test-ables/fix-legacy-imports/{legacy-react-ts.tsx → legacy-react-ts.tsx.mock} +0 -0
- package/test-ables/fix-legacy-imports/{legacy-react-ts2.tsx → legacy-react-ts2.tsx.mock} +0 -0
- package/test-ables/fix-legacy-imports/{legacy-react.jsx → legacy-react.jsx.mock} +0 -0
- package/test-ables/fix-legacy-imports/{legacy-react2.jsx → legacy-react2.jsx.mock} +0 -0
- package/test-ables/fix-legacy-imports/{legacy-ts.ts → legacy-ts.ts.mock} +0 -0
- package/test-ables/fix-legacy-imports/{legacy-ts2.ts → legacy-ts2.ts.mock} +0 -0
- package/test-ables/fix-legacy-imports/{legacy1.js → legacy1.js.mock} +0 -0
- package/test-ables/fix-legacy-imports/{legacy2.js → legacy2.js.mock} +0 -0
- package/tsconfig.json +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-codemods",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Code Mods",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -31,11 +31,14 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"arg": "^5.0.1",
|
|
34
|
+
"chalk": "4.1.2",
|
|
35
|
+
"depcheck": "1.4.2",
|
|
34
36
|
"esm": "^3.2.25",
|
|
35
37
|
"fs": "0.0.1-security",
|
|
36
|
-
"fs-extra": "^
|
|
37
|
-
"glob": "^7.
|
|
38
|
-
"inquirer": "^8.0
|
|
38
|
+
"fs-extra": "^10.0.0",
|
|
39
|
+
"glob": "^7.2.0",
|
|
40
|
+
"inquirer": "^8.2.0",
|
|
41
|
+
"pacote": "12.0.2",
|
|
39
42
|
"path": "^0.12.7"
|
|
40
43
|
},
|
|
41
44
|
"publishConfig": {
|
package/src/cli/code-mods/cli.js
CHANGED
|
@@ -7,6 +7,9 @@ function parseArgumentsIntoOptions(rawArgs) {
|
|
|
7
7
|
{
|
|
8
8
|
'--globPattern': String,
|
|
9
9
|
'--globPatternIgnore': String,
|
|
10
|
+
'--projectFolderPath': String,
|
|
11
|
+
'--ignorePackagesGlobPattern': String,
|
|
12
|
+
'--ignoreFilesGlobPattern': String,
|
|
10
13
|
},
|
|
11
14
|
{
|
|
12
15
|
argv: rawArgs.slice(2),
|
|
@@ -15,6 +18,9 @@ function parseArgumentsIntoOptions(rawArgs) {
|
|
|
15
18
|
return {
|
|
16
19
|
globPattern: args['--globPattern'],
|
|
17
20
|
globPatternIgnore: args['--globPatternIgnore'],
|
|
21
|
+
projectFolderPath: args['--projectFolderPath'],
|
|
22
|
+
ignorePackagesGlobPattern: args['--ignorePackagesGlobPattern'],
|
|
23
|
+
ignoreFilesGlobPattern: args['--ignoreFilesGlobPattern'],
|
|
18
24
|
script: args._[0],
|
|
19
25
|
};
|
|
20
26
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const getPackagesInconsistenciesQuestions = (originalOptions) => {
|
|
2
2
|
const extraOptions = [];
|
|
3
|
-
|
|
3
|
+
const { globPattern, globPatternIgnore } = originalOptions;
|
|
4
|
+
if (!globPattern && globPattern !== '') {
|
|
4
5
|
extraOptions.push({
|
|
5
6
|
type: 'input',
|
|
6
7
|
name: 'globPattern',
|
|
@@ -9,7 +10,7 @@ export const getPackagesInconsistenciesQuestions = (originalOptions) => {
|
|
|
9
10
|
default: './package.json', // './packages/ds-codemods/test-ables/check-packages-inconsistencies/package.json.test',
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
|
-
if (!
|
|
13
|
+
if (!globPatternIgnore && globPatternIgnore !== '') {
|
|
13
14
|
extraOptions.push({
|
|
14
15
|
type: 'input',
|
|
15
16
|
name: 'globPatternIgnore',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const getLegacyImportsQuestions = (originalOptions) => {
|
|
2
2
|
const extraOptions = [];
|
|
3
|
-
|
|
3
|
+
const { globPattern, globPatternIgnore } = originalOptions;
|
|
4
|
+
if (!globPattern && globPattern !== '') {
|
|
4
5
|
extraOptions.push({
|
|
5
6
|
type: 'input',
|
|
6
7
|
name: 'globPattern',
|
|
@@ -8,7 +9,7 @@ export const getLegacyImportsQuestions = (originalOptions) => {
|
|
|
8
9
|
default: './**/*.js,./**/*.jsx,./**/*.ts,./**/*.tsx',
|
|
9
10
|
});
|
|
10
11
|
}
|
|
11
|
-
if (!
|
|
12
|
+
if (!globPatternIgnore && globPatternIgnore !== '') {
|
|
12
13
|
extraOptions.push({
|
|
13
14
|
type: 'input',
|
|
14
15
|
name: 'globPatternIgnore',
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const getMissingPackagesQuestions = (originalOptions) => {
|
|
2
|
+
const extraOptions = [];
|
|
3
|
+
const { projectFolderPath, ignorePackagesGlobPattern, ignoreFilesGlobPattern } = originalOptions;
|
|
4
|
+
if (!projectFolderPath && projectFolderPath !== '') {
|
|
5
|
+
extraOptions.push({
|
|
6
|
+
type: 'input',
|
|
7
|
+
name: 'projectFolderPath',
|
|
8
|
+
message: 'path to the project folder containing package.json file',
|
|
9
|
+
default: './',
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
if (!ignorePackagesGlobPattern && ignorePackagesGlobPattern !== '') {
|
|
13
|
+
extraOptions.push({
|
|
14
|
+
type: 'input',
|
|
15
|
+
name: 'ignorePackagesGlobPattern',
|
|
16
|
+
message: 'Please provide a comma separated list of globPatterns for ignored packages, if any.',
|
|
17
|
+
default: '',
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (!ignoreFilesGlobPattern && ignoreFilesGlobPattern !== '') {
|
|
21
|
+
extraOptions.push({
|
|
22
|
+
type: 'input',
|
|
23
|
+
name: 'ignoreFilesGlobPattern',
|
|
24
|
+
message: 'Please provide a comma separated list of globPatterns for ignored files, if any.',
|
|
25
|
+
default: '**/*.eslintrc.js',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return extraOptions;
|
|
29
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import depcheck from 'depcheck';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { generatePathFromCurrentFolder } from '../../../utils';
|
|
5
|
+
|
|
6
|
+
const logUnusedDep = (unused) => {
|
|
7
|
+
console.log(chalk.yellowBright('### Found unused dependencies :>>'));
|
|
8
|
+
console.log('```');
|
|
9
|
+
console.log(unused.dependencies);
|
|
10
|
+
console.log('```');
|
|
11
|
+
};
|
|
12
|
+
const logUnusedDevDep = (unused) => {
|
|
13
|
+
console.log(chalk.magentaBright('### Found unused dev dependencies :>>'));
|
|
14
|
+
console.log('```');
|
|
15
|
+
console.log(unused.devDependencies);
|
|
16
|
+
console.log('```');
|
|
17
|
+
};
|
|
18
|
+
const logMissing = (unused) => {
|
|
19
|
+
const missingString = [...Object.keys(unused.missing)].map((pack) => `\t${pack}`).join(',\n');
|
|
20
|
+
console.log(chalk.redBright('### Found missing dependencies :>>'));
|
|
21
|
+
console.log('```');
|
|
22
|
+
console.log('{');
|
|
23
|
+
console.log(missingString);
|
|
24
|
+
console.log('}');
|
|
25
|
+
console.log('```');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const checkMissingPackages = async (options) => {
|
|
29
|
+
const { projectFolderPath, ignorePackagesGlobPattern, ignoreFilesGlobPattern } = options;
|
|
30
|
+
const ignorePatterns = ignorePackagesGlobPattern
|
|
31
|
+
.split(',')
|
|
32
|
+
.map((pattern) => (pattern && pattern !== '' ? generatePathFromCurrentFolder(pattern) : ''));
|
|
33
|
+
const ignoreMatches = ignoreFilesGlobPattern
|
|
34
|
+
.split(',')
|
|
35
|
+
.map((pattern) => (pattern && pattern !== '' ? generatePathFromCurrentFolder(pattern) : ''));
|
|
36
|
+
const depCheckOptions = {
|
|
37
|
+
ignoreBinPackage: false, // ignore the packages with bin entry
|
|
38
|
+
skipMissing: false, // skip calculation of missing dependencies
|
|
39
|
+
parsers: {
|
|
40
|
+
// the target parsers
|
|
41
|
+
'**/*.js': depcheck.parser.jsx,
|
|
42
|
+
'**/*.jsx': depcheck.parser.jsx,
|
|
43
|
+
'**/*.ts': depcheck.parser.typescript,
|
|
44
|
+
'**/*.tsx': depcheck.parser.typescript,
|
|
45
|
+
},
|
|
46
|
+
detectors: [
|
|
47
|
+
depcheck.detector.requireCallExpression,
|
|
48
|
+
depcheck.detector.requireResolveCallExpression,
|
|
49
|
+
depcheck.detector.importDeclaration,
|
|
50
|
+
depcheck.detector.typescriptImportType,
|
|
51
|
+
depcheck.detector.exportDeclaration,
|
|
52
|
+
],
|
|
53
|
+
specials: [
|
|
54
|
+
// the target special parsers
|
|
55
|
+
depcheck.special.babel,
|
|
56
|
+
depcheck.special.bin,
|
|
57
|
+
depcheck.special.eslint,
|
|
58
|
+
depcheck.special.husky,
|
|
59
|
+
depcheck.special.jest,
|
|
60
|
+
depcheck.special.mocha,
|
|
61
|
+
depcheck.special.prettier,
|
|
62
|
+
depcheck.special.tslint,
|
|
63
|
+
depcheck.special.webpack,
|
|
64
|
+
],
|
|
65
|
+
ignorePatterns,
|
|
66
|
+
ignoreMatches,
|
|
67
|
+
};
|
|
68
|
+
const pathToRoot = generatePathFromCurrentFolder(projectFolderPath);
|
|
69
|
+
|
|
70
|
+
depcheck(pathToRoot, depCheckOptions).then((unused) => {
|
|
71
|
+
const unusedDep = Array.isArray(unused.dependencies) && unused.dependencies.length > 0;
|
|
72
|
+
const unusedDevDep = Array.isArray(unused.devDependencies) && unused.devDependencies.length > 0;
|
|
73
|
+
const missing = Object.keys(unused.missing).length > 0;
|
|
74
|
+
const hasErrors = unusedDep || unusedDevDep || missing;
|
|
75
|
+
console.log(chalk.bold.cyanBright(`# Dependencies results for ${pathToRoot}`));
|
|
76
|
+
console.log(chalk.bold.cyanBright(`[${pathToRoot}](${pathToRoot}package.json)`));
|
|
77
|
+
if (unusedDep) logUnusedDep(unused);
|
|
78
|
+
if (unusedDevDep) logUnusedDevDep(unused);
|
|
79
|
+
if (missing) logMissing(unused);
|
|
80
|
+
if (!hasErrors) console.log(chalk.bold.green(`no problems found!`));
|
|
81
|
+
});
|
|
82
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fixLegacyImports } from './fix-legacy-imports';
|
|
2
2
|
import { checkPackagesInconsistencies } from './check-packages-inconsistencies';
|
|
3
|
+
import { checkMissingPackages } from './check-missing-packages';
|
|
3
4
|
import { COMMANDS } from '../commands';
|
|
4
5
|
|
|
5
6
|
export async function executeCommandsMap(args, options) {
|
|
@@ -13,6 +14,9 @@ export async function executeCommandsMap(args, options) {
|
|
|
13
14
|
case COMMANDS.CHECK_PACKAGES_INCONSISTENCIES:
|
|
14
15
|
checkPackagesInconsistencies(options);
|
|
15
16
|
break;
|
|
17
|
+
case COMMANDS.CHECK_MISSING_PACKAGES:
|
|
18
|
+
checkMissingPackages(options);
|
|
19
|
+
break;
|
|
16
20
|
default:
|
|
17
21
|
break;
|
|
18
22
|
}
|
|
@@ -2,6 +2,7 @@ export const COMMANDS = {
|
|
|
2
2
|
FIX_LEGACY_IMPORTS: 'fix-legacy-imports',
|
|
3
3
|
FIX_LEGACY_IMPORTS_REVERT: 'fix-legacy-imports:revert',
|
|
4
4
|
CHECK_PACKAGES_INCONSISTENCIES: 'check-packages-inconsistencies',
|
|
5
|
+
CHECK_MISSING_PACKAGES: 'check-missing-packages',
|
|
5
6
|
EXIT: 'exit',
|
|
6
7
|
};
|
|
7
8
|
|
|
@@ -2,6 +2,7 @@ import inquirer from 'inquirer';
|
|
|
2
2
|
import { COMMANDS, COMMANDS_ARRAY } from './commands';
|
|
3
3
|
import { getLegacyImportsQuestions } from './command-arguments/promptFixLegacyImports';
|
|
4
4
|
import { getPackagesInconsistenciesQuestions } from './command-arguments/promptCheckEmPackagesInconsistencies';
|
|
5
|
+
import { getMissingPackagesQuestions } from './command-arguments/promptMissingPackages';
|
|
5
6
|
|
|
6
7
|
async function promptForMissingScriptSpecificOptions({ originalOptions, promptOptions }) {
|
|
7
8
|
const script = originalOptions.script || promptOptions.script;
|
|
@@ -14,6 +15,9 @@ async function promptForMissingScriptSpecificOptions({ originalOptions, promptOp
|
|
|
14
15
|
case COMMANDS.CHECK_PACKAGES_INCONSISTENCIES:
|
|
15
16
|
scriptQuestions.push(...getPackagesInconsistenciesQuestions(originalOptions));
|
|
16
17
|
break;
|
|
18
|
+
case COMMANDS.CHECK_MISSING_PACKAGES:
|
|
19
|
+
scriptQuestions.push(...getMissingPackagesQuestions(originalOptions));
|
|
20
|
+
break;
|
|
17
21
|
default:
|
|
18
22
|
break;
|
|
19
23
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/tsconfig.json
CHANGED