@dmitryrechkin/eslint-standard 1.1.2 ā 1.1.3
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/package.json +5 -3
- package/src/cli/check-deps.mjs +38 -6
- package/src/cli/index.mjs +5 -3
- package/src/cli/postinstall-check.mjs +54 -0
- package/src/cli/postinstall.mjs +31 -7
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dmitryrechkin/eslint-standard",
|
|
3
3
|
"description": "This package provides a shared ESLint configuration which includes TypeScript support and a set of specific linting rules designed to ensure high-quality and consistent code style across projects.",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.3",
|
|
5
5
|
"main": "eslint.config.mjs",
|
|
6
6
|
"bin": {
|
|
7
7
|
"eslint-standard": "./src/cli/index.mjs"
|
|
@@ -15,8 +15,10 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"postinstall": "node src/cli/postinstall.mjs",
|
|
17
17
|
"package:publish": "npm publish --access public",
|
|
18
|
-
"test": "npm run test:formatting",
|
|
19
|
-
"test:formatting": "node tests/test-runner.js"
|
|
18
|
+
"test": "npm run test:formatting && npm run test:cli",
|
|
19
|
+
"test:formatting": "node tests/test-runner.js",
|
|
20
|
+
"test:cli": "node tests/test-cli.js",
|
|
21
|
+
"test:install": "node tests/test-install-simulation.js"
|
|
20
22
|
},
|
|
21
23
|
"keywords": [],
|
|
22
24
|
"author": "",
|
package/src/cli/check-deps.mjs
CHANGED
|
@@ -3,20 +3,32 @@
|
|
|
3
3
|
import { readFileSync } from 'fs';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { dirname, join, resolve } from 'path';
|
|
6
|
+
import { spawn } from 'child_process';
|
|
6
7
|
|
|
7
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
9
|
const __dirname = dirname(__filename);
|
|
9
10
|
|
|
11
|
+
// Check for --install flag
|
|
12
|
+
const shouldInstall = process.argv.includes('--install');
|
|
13
|
+
|
|
10
14
|
// Get peer dependencies
|
|
11
15
|
const packageJsonPath = join(__dirname, '../../package.json');
|
|
12
16
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
13
17
|
const peerDeps = packageJson.peerDependencies || {};
|
|
14
18
|
|
|
15
|
-
// Check if running from node_modules
|
|
19
|
+
// Check if running from node_modules and find project root
|
|
16
20
|
const isInNodeModules = __dirname.includes('node_modules');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
let projectRoot;
|
|
22
|
+
|
|
23
|
+
if (isInNodeModules) {
|
|
24
|
+
// Handle different package manager structures
|
|
25
|
+
// pnpm: .pnpm/@org+pkg@version_deps/node_modules/@org/pkg
|
|
26
|
+
// npm/yarn: node_modules/@org/pkg
|
|
27
|
+
const parts = __dirname.split('node_modules');
|
|
28
|
+
projectRoot = parts[0].replace(/[\\/]$/, ''); // Remove trailing slash
|
|
29
|
+
} else {
|
|
30
|
+
projectRoot = process.cwd();
|
|
31
|
+
}
|
|
20
32
|
|
|
21
33
|
// Read project's package.json
|
|
22
34
|
let projectPackageJson;
|
|
@@ -56,13 +68,33 @@ if (missingDeps.length === 0 && outdatedDeps.length === 0) {
|
|
|
56
68
|
} else {
|
|
57
69
|
if (missingDeps.length > 0) {
|
|
58
70
|
console.log(`\nā Missing ${missingDeps.length} dependencies:`);
|
|
59
|
-
console.log(
|
|
71
|
+
missingDeps.forEach(dep => console.log(` - ${dep}`));
|
|
72
|
+
|
|
73
|
+
if (shouldInstall) {
|
|
74
|
+
console.log('\nš§ Auto-installing missing dependencies...\n');
|
|
75
|
+
|
|
76
|
+
// Import and run the install-deps script
|
|
77
|
+
try {
|
|
78
|
+
const installDepsModule = await import('./install-deps.mjs');
|
|
79
|
+
// The install-deps script will handle the installation
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('ā Failed to auto-install dependencies:', error.message);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
console.log('\nš” To install missing dependencies:');
|
|
86
|
+
console.log(' npx @dmitryrechkin/eslint-standard install-deps');
|
|
87
|
+
console.log(' or run this command with --install flag');
|
|
88
|
+
}
|
|
60
89
|
}
|
|
61
90
|
if (outdatedDeps.length > 0) {
|
|
62
91
|
console.log(`\nā ļø ${outdatedDeps.length} dependencies may be outdated:`);
|
|
63
92
|
outdatedDeps.forEach(dep => console.log(` - ${dep}`));
|
|
64
93
|
}
|
|
65
|
-
|
|
94
|
+
|
|
95
|
+
if (!shouldInstall && missingDeps.length > 0) {
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
66
98
|
}
|
|
67
99
|
|
|
68
100
|
export default function checkDeps() {
|
package/src/cli/index.mjs
CHANGED
|
@@ -20,13 +20,15 @@ Usage:
|
|
|
20
20
|
npx @dmitryrechkin/eslint-standard <command>
|
|
21
21
|
|
|
22
22
|
Commands:
|
|
23
|
-
install-deps
|
|
24
|
-
check-deps
|
|
25
|
-
|
|
23
|
+
install-deps Install all peer dependencies
|
|
24
|
+
check-deps Check if all peer dependencies are installed
|
|
25
|
+
check-deps --install Auto-install missing dependencies if any
|
|
26
|
+
help Show this help message
|
|
26
27
|
|
|
27
28
|
Examples:
|
|
28
29
|
npx @dmitryrechkin/eslint-standard install-deps
|
|
29
30
|
npx @dmitryrechkin/eslint-standard check-deps
|
|
31
|
+
npx @dmitryrechkin/eslint-standard check-deps --install
|
|
30
32
|
`);
|
|
31
33
|
break;
|
|
32
34
|
default:
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { readFileSync, existsSync } from 'fs';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname, join } from 'path';
|
|
6
|
+
import { execSync } from 'child_process';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
|
|
11
|
+
// Don't run during local development
|
|
12
|
+
if (!__dirname.includes('node_modules')) {
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Check if we're in CI environment
|
|
17
|
+
const isCI = process.env.CI || process.env.CONTINUOUS_INTEGRATION || process.env.GITHUB_ACTIONS;
|
|
18
|
+
|
|
19
|
+
// Check if scripts are disabled
|
|
20
|
+
const npmConfigIgnoreScripts = process.env.npm_config_ignore_scripts === 'true';
|
|
21
|
+
|
|
22
|
+
if (isCI || npmConfigIgnoreScripts) {
|
|
23
|
+
// Silent exit in CI or when scripts are disabled
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Simple check for missing dependencies
|
|
28
|
+
try {
|
|
29
|
+
const packageJsonPath = join(__dirname, '../../package.json');
|
|
30
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
31
|
+
const peerDeps = Object.keys(packageJson.peerDependencies || {});
|
|
32
|
+
|
|
33
|
+
// Quick check if any peer deps are missing
|
|
34
|
+
let missingCount = 0;
|
|
35
|
+
for (const dep of peerDeps) {
|
|
36
|
+
try {
|
|
37
|
+
// Try to resolve the dependency
|
|
38
|
+
require.resolve(dep, { paths: [process.cwd()] });
|
|
39
|
+
} catch {
|
|
40
|
+
missingCount++;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (missingCount > 0) {
|
|
45
|
+
console.log(`
|
|
46
|
+
ā ļø @dmitryrechkin/eslint-standard: ${missingCount} peer dependencies are missing!
|
|
47
|
+
|
|
48
|
+
Run this command to check and install them:
|
|
49
|
+
š ${'\x1b[36m'}npx @dmitryrechkin/eslint-standard check-deps --install${'\x1b[0m'}
|
|
50
|
+
`);
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
// Silent fail - don't break installation
|
|
54
|
+
}
|
package/src/cli/postinstall.mjs
CHANGED
|
@@ -11,6 +11,17 @@ if (!__dirname.includes('node_modules')) {
|
|
|
11
11
|
process.exit(0);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// Check environment variables for auto-install preference
|
|
15
|
+
const autoInstall = process.env.ESLINT_STANDARD_AUTO_INSTALL === 'true';
|
|
16
|
+
const skipInstall = process.env.ESLINT_STANDARD_SKIP_INSTALL === 'true';
|
|
17
|
+
|
|
18
|
+
// Check if we're in CI environment
|
|
19
|
+
const isCI = process.env.CI || process.env.CONTINUOUS_INTEGRATION || process.env.GITHUB_ACTIONS;
|
|
20
|
+
|
|
21
|
+
if (skipInstall || isCI) {
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
|
|
14
25
|
console.log(`
|
|
15
26
|
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
16
27
|
ā ā
|
|
@@ -21,9 +32,9 @@ console.log(`
|
|
|
21
32
|
š¦ This package requires peer dependencies to work properly.
|
|
22
33
|
|
|
23
34
|
š Quick install (auto-detects your package manager):
|
|
24
|
-
${'\x1b[36m'}npx @dmitryrechkin/eslint-standard
|
|
35
|
+
${'\x1b[36m'}npx @dmitryrechkin/eslint-standard check-deps --install${'\x1b[0m'}
|
|
25
36
|
|
|
26
|
-
š Or install
|
|
37
|
+
š Or install all dependencies directly:
|
|
27
38
|
${'\x1b[90m'}npm install -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-unused-imports @stylistic/eslint-plugin eslint-plugin-jsdoc eslint-plugin-simple-import-sort eslint-plugin-perfectionist${'\x1b[0m'}
|
|
28
39
|
|
|
29
40
|
š To check if all dependencies are installed:
|
|
@@ -32,9 +43,22 @@ console.log(`
|
|
|
32
43
|
š Documentation: https://github.com/dmitryrechkin/eslint-standard
|
|
33
44
|
`);
|
|
34
45
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
// Don't run check-deps in postinstall to avoid errors
|
|
47
|
+
// Users can run it manually with: npx @dmitryrechkin/eslint-standard check-deps
|
|
48
|
+
|
|
49
|
+
if (autoInstall) {
|
|
50
|
+
console.log('\nš¤ Auto-install enabled via ESLINT_STANDARD_AUTO_INSTALL=true');
|
|
51
|
+
console.log('š¦ Checking and installing peer dependencies...\n');
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
// Run check-deps with --install flag
|
|
55
|
+
const { execSync } = await import('child_process');
|
|
56
|
+
execSync('node ' + join(__dirname, 'index.mjs') + ' check-deps --install', {
|
|
57
|
+
stdio: 'inherit',
|
|
58
|
+
cwd: process.cwd()
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error('ā Auto-install failed. Please run manually:');
|
|
62
|
+
console.error(' npx @dmitryrechkin/eslint-standard check-deps --install');
|
|
63
|
+
}
|
|
40
64
|
}
|